1/*
2 * Copyright 2019 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "src/gpu/dawn/GrDawnRenderTarget.h"
9
10#include "include/gpu/GrBackendSurface.h"
11#include "src/gpu/dawn/GrDawnGpu.h"
12#include "src/gpu/dawn/GrDawnUtil.h"
13
14GrDawnRenderTarget::GrDawnRenderTarget(GrDawnGpu* gpu,
15                                       SkISize dimensions,
16                                       int sampleCnt,
17                                       const GrDawnRenderTargetInfo& info)
18        : GrSurface(gpu, dimensions, GrProtected::kNo)
19        , GrRenderTarget(gpu, dimensions, sampleCnt, GrProtected::kNo)
20        , fInfo(info) {}
21
22sk_sp<GrDawnRenderTarget> GrDawnRenderTarget::MakeWrapped(GrDawnGpu* gpu,
23                                                          SkISize dimensions,
24                                                          int sampleCnt,
25                                                          const GrDawnRenderTargetInfo& info) {
26    sk_sp<GrDawnRenderTarget> rt(new GrDawnRenderTarget(gpu, dimensions, sampleCnt, info));
27    rt->registerWithCacheWrapped(GrWrapCacheable::kNo);
28    return rt;
29}
30
31size_t GrDawnRenderTarget::onGpuMemorySize() const {
32    // The plus 1 is to account for the resolve texture or if not using msaa the RT itself
33    int numSamples = this->numSamples() + 1;
34    return GrSurface::ComputeSize(this->backendFormat(), this->dimensions(), numSamples,
35                                  GrMipmapped::kNo);
36}
37
38bool GrDawnRenderTarget::completeStencilAttachment(GrAttachment* stencil, bool useMSAASurface) {
39    SkASSERT(useMSAASurface == (this->numSamples() > 1));
40    return true;
41}
42
43GrDawnRenderTarget::~GrDawnRenderTarget() {
44}
45
46void GrDawnRenderTarget::onRelease() {
47    INHERITED::onRelease();
48}
49
50void GrDawnRenderTarget::onAbandon() {
51    INHERITED::onAbandon();
52}
53
54GrBackendRenderTarget GrDawnRenderTarget::getBackendRenderTarget() const {
55    return GrBackendRenderTarget(this->width(), this->height(), this->numSamples(),
56                                 this->numSamples(), fInfo);
57}
58
59GrBackendFormat GrDawnRenderTarget::backendFormat() const {
60    return GrBackendFormat::MakeDawn(fInfo.fFormat);
61}
62