1cb93a386Sopenharmony_ci/* 2cb93a386Sopenharmony_ci * Copyright 2011 Google Inc. 3cb93a386Sopenharmony_ci * 4cb93a386Sopenharmony_ci * Use of this source code is governed by a BSD-style license that can be 5cb93a386Sopenharmony_ci * found in the LICENSE file. 6cb93a386Sopenharmony_ci */ 7cb93a386Sopenharmony_ci 8cb93a386Sopenharmony_ci 9cb93a386Sopenharmony_ci#include "src/gpu/GrRenderTarget.h" 10cb93a386Sopenharmony_ci 11cb93a386Sopenharmony_ci#include "src/core/SkRectPriv.h" 12cb93a386Sopenharmony_ci#include "src/gpu/GrAttachment.h" 13cb93a386Sopenharmony_ci#include "src/gpu/GrBackendUtils.h" 14cb93a386Sopenharmony_ci#include "src/gpu/GrGpu.h" 15cb93a386Sopenharmony_ci#include "src/gpu/GrStencilSettings.h" 16cb93a386Sopenharmony_ci 17cb93a386Sopenharmony_ciGrRenderTarget::GrRenderTarget(GrGpu* gpu, 18cb93a386Sopenharmony_ci const SkISize& dimensions, 19cb93a386Sopenharmony_ci int sampleCount, 20cb93a386Sopenharmony_ci GrProtected isProtected, 21cb93a386Sopenharmony_ci sk_sp<GrAttachment> stencil) 22cb93a386Sopenharmony_ci : INHERITED(gpu, dimensions, isProtected) 23cb93a386Sopenharmony_ci , fSampleCnt(sampleCount) { 24cb93a386Sopenharmony_ci if (this->numSamples() > 1) { 25cb93a386Sopenharmony_ci fMSAAStencilAttachment = std::move(stencil); 26cb93a386Sopenharmony_ci } else { 27cb93a386Sopenharmony_ci fStencilAttachment = std::move(stencil); 28cb93a386Sopenharmony_ci } 29cb93a386Sopenharmony_ci} 30cb93a386Sopenharmony_ci 31cb93a386Sopenharmony_ciGrRenderTarget::~GrRenderTarget() = default; 32cb93a386Sopenharmony_ci 33cb93a386Sopenharmony_civoid GrRenderTarget::onRelease() { 34cb93a386Sopenharmony_ci fStencilAttachment = nullptr; 35cb93a386Sopenharmony_ci fMSAAStencilAttachment = nullptr; 36cb93a386Sopenharmony_ci 37cb93a386Sopenharmony_ci INHERITED::onRelease(); 38cb93a386Sopenharmony_ci} 39cb93a386Sopenharmony_ci 40cb93a386Sopenharmony_civoid GrRenderTarget::onAbandon() { 41cb93a386Sopenharmony_ci fStencilAttachment = nullptr; 42cb93a386Sopenharmony_ci fMSAAStencilAttachment = nullptr; 43cb93a386Sopenharmony_ci 44cb93a386Sopenharmony_ci INHERITED::onAbandon(); 45cb93a386Sopenharmony_ci} 46cb93a386Sopenharmony_ci 47cb93a386Sopenharmony_civoid GrRenderTarget::attachStencilAttachment(sk_sp<GrAttachment> stencil, bool useMSAASurface) { 48cb93a386Sopenharmony_ci auto stencilAttachment = (useMSAASurface) ? &GrRenderTarget::fMSAAStencilAttachment 49cb93a386Sopenharmony_ci : &GrRenderTarget::fStencilAttachment; 50cb93a386Sopenharmony_ci if (!stencil && !(this->*stencilAttachment)) { 51cb93a386Sopenharmony_ci // No need to do any work since we currently don't have a stencil attachment and 52cb93a386Sopenharmony_ci // we're not actually adding one. 53cb93a386Sopenharmony_ci return; 54cb93a386Sopenharmony_ci } 55cb93a386Sopenharmony_ci 56cb93a386Sopenharmony_ci if (!this->completeStencilAttachment(stencil.get(), useMSAASurface)) { 57cb93a386Sopenharmony_ci return; 58cb93a386Sopenharmony_ci } 59cb93a386Sopenharmony_ci 60cb93a386Sopenharmony_ci this->*stencilAttachment = std::move(stencil); 61cb93a386Sopenharmony_ci} 62cb93a386Sopenharmony_ci 63cb93a386Sopenharmony_ciint GrRenderTarget::numStencilBits(bool useMSAASurface) const { 64cb93a386Sopenharmony_ci return GrBackendFormatStencilBits(this->getStencilAttachment(useMSAASurface)->backendFormat()); 65cb93a386Sopenharmony_ci} 66