1 /*
2 * Copyright 2011 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 #include "src/gpu/ganesh/GrRenderTarget.h"
8
9 #include "src/gpu/ganesh/GrAttachment.h"
10 #include "src/gpu/ganesh/GrBackendUtils.h"
11
12 #include <utility>
13
14 class GrGpu;
15 struct SkISize;
16
GrRenderTarget(GrGpu * gpu,const SkISize & dimensions,int sampleCount,GrProtected isProtected,std::string_view label,sk_sp<GrAttachment> stencil)17 GrRenderTarget::GrRenderTarget(GrGpu* gpu,
18 const SkISize& dimensions,
19 int sampleCount,
20 GrProtected isProtected,
21 std::string_view label,
22 sk_sp<GrAttachment> stencil)
23 : INHERITED(gpu, dimensions, isProtected, label)
24 , fSampleCnt(sampleCount) {
25 if (this->numSamples() > 1) {
26 fMSAAStencilAttachment = std::move(stencil);
27 } else {
28 fStencilAttachment = std::move(stencil);
29 }
30 }
31
32 GrRenderTarget::~GrRenderTarget() = default;
33
onRelease()34 void GrRenderTarget::onRelease() {
35 fStencilAttachment = nullptr;
36 fMSAAStencilAttachment = nullptr;
37
38 INHERITED::onRelease();
39 }
40
onAbandon()41 void GrRenderTarget::onAbandon() {
42 fStencilAttachment = nullptr;
43 fMSAAStencilAttachment = nullptr;
44
45 INHERITED::onAbandon();
46 }
47
attachStencilAttachment(sk_sp<GrAttachment> stencil,bool useMSAASurface)48 void GrRenderTarget::attachStencilAttachment(sk_sp<GrAttachment> stencil, bool useMSAASurface) {
49 auto stencilAttachment = (useMSAASurface) ? &GrRenderTarget::fMSAAStencilAttachment
50 : &GrRenderTarget::fStencilAttachment;
51 if (!stencil && !(this->*stencilAttachment)) {
52 // No need to do any work since we currently don't have a stencil attachment and
53 // we're not actually adding one.
54 return;
55 }
56
57 if (!this->completeStencilAttachment(stencil.get(), useMSAASurface)) {
58 return;
59 }
60
61 this->*stencilAttachment = std::move(stencil);
62 }
63
numStencilBits(bool useMSAASurface) const64 int GrRenderTarget::numStencilBits(bool useMSAASurface) const {
65 return GrBackendFormatStencilBits(this->getStencilAttachment(useMSAASurface)->backendFormat());
66 }
67