Home | History | Annotate | Download | only in gpu
      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 
      8 
      9 #include "GrRenderTarget.h"
     10 
     11 #include "GrContext.h"
     12 #include "GrContextPriv.h"
     13 #include "GrRenderTargetContext.h"
     14 #include "GrGpu.h"
     15 #include "GrRenderTargetOpList.h"
     16 #include "GrRenderTargetPriv.h"
     17 #include "GrStencilAttachment.h"
     18 #include "GrStencilSettings.h"
     19 #include "SkRectPriv.h"
     20 
     21 GrRenderTarget::GrRenderTarget(GrGpu* gpu, const GrSurfaceDesc& desc,
     22                                GrStencilAttachment* stencil)
     23         : INHERITED(gpu, desc)
     24         , fSampleCnt(desc.fSampleCnt)
     25         , fStencilAttachment(stencil) {
     26     SkASSERT(desc.fFlags & kRenderTarget_GrSurfaceFlag);
     27     SkASSERT(!this->hasMixedSamples() || fSampleCnt > 1);
     28     fResolveRect = SkRectPriv::MakeILargestInverted();
     29 }
     30 
     31 GrRenderTarget::~GrRenderTarget() = default;
     32 
     33 void GrRenderTarget::flagAsNeedingResolve(const SkIRect* rect) {
     34     if (kCanResolve_ResolveType == getResolveType()) {
     35         if (rect) {
     36             fResolveRect.join(*rect);
     37             if (!fResolveRect.intersect(0, 0, this->width(), this->height())) {
     38                 fResolveRect.setEmpty();
     39             }
     40         } else {
     41             fResolveRect.setLTRB(0, 0, this->width(), this->height());
     42         }
     43     }
     44 }
     45 
     46 void GrRenderTarget::overrideResolveRect(const SkIRect rect) {
     47     fResolveRect = rect;
     48     if (fResolveRect.isEmpty()) {
     49         fResolveRect = SkRectPriv::MakeILargestInverted();
     50     } else {
     51         if (!fResolveRect.intersect(0, 0, this->width(), this->height())) {
     52             fResolveRect = SkRectPriv::MakeILargestInverted();
     53         }
     54     }
     55 }
     56 
     57 void GrRenderTarget::flagAsResolved() {
     58     fResolveRect = SkRectPriv::MakeILargestInverted();
     59 }
     60 
     61 void GrRenderTarget::onRelease() {
     62     fStencilAttachment = nullptr;
     63 
     64     INHERITED::onRelease();
     65 }
     66 
     67 void GrRenderTarget::onAbandon() {
     68     fStencilAttachment = nullptr;
     69 
     70     INHERITED::onAbandon();
     71 }
     72 
     73 ///////////////////////////////////////////////////////////////////////////////
     74 
     75 void GrRenderTargetPriv::attachStencilAttachment(sk_sp<GrStencilAttachment> stencil) {
     76     if (!stencil && !fRenderTarget->fStencilAttachment) {
     77         // No need to do any work since we currently don't have a stencil attachment and
     78         // we're not actually adding one.
     79         return;
     80     }
     81     fRenderTarget->fStencilAttachment = std::move(stencil);
     82     if (!fRenderTarget->completeStencilAttachment()) {
     83         fRenderTarget->fStencilAttachment = nullptr;
     84     }
     85 }
     86 
     87 int GrRenderTargetPriv::numStencilBits() const {
     88     SkASSERT(this->getStencilAttachment());
     89     return this->getStencilAttachment()->bits();
     90 }
     91