/* * Copyright 2011 Google Inc. * * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ #include "GrRenderTarget.h" #include "GrContext.h" #include "GrDrawContext.h" #include "GrDrawTarget.h" #include "GrGpu.h" #include "GrRenderTargetPriv.h" #include "GrStencilAttachment.h" void GrRenderTarget::discard() { // go through context so that all necessary flushing occurs GrContext* context = this->getContext(); if (!context) { return; } SkAutoTUnref drawContext(context->drawContext(this)); if (!drawContext) { return; } drawContext->discard(); } void GrRenderTarget::flagAsNeedingResolve(const SkIRect* rect) { if (kCanResolve_ResolveType == getResolveType()) { if (rect) { fResolveRect.join(*rect); if (!fResolveRect.intersect(0, 0, this->width(), this->height())) { fResolveRect.setEmpty(); } } else { fResolveRect.setLTRB(0, 0, this->width(), this->height()); } } } void GrRenderTarget::overrideResolveRect(const SkIRect rect) { fResolveRect = rect; if (fResolveRect.isEmpty()) { fResolveRect.setLargestInverted(); } else { if (!fResolveRect.intersect(0, 0, this->width(), this->height())) { fResolveRect.setLargestInverted(); } } } void GrRenderTarget::onRelease() { SkSafeSetNull(fStencilAttachment); fLastDrawTarget = nullptr; INHERITED::onRelease(); } void GrRenderTarget::onAbandon() { SkSafeSetNull(fStencilAttachment); fLastDrawTarget = nullptr; INHERITED::onAbandon(); } void GrRenderTarget::setLastDrawTarget(GrDrawTarget* dt) { if (fLastDrawTarget) { // The non-MDB world never closes so we can't check this condition #ifdef ENABLE_MDB SkASSERT(fLastDrawTarget->isClosed()); #endif } fLastDrawTarget = dt; } /////////////////////////////////////////////////////////////////////////////// bool GrRenderTargetPriv::attachStencilAttachment(GrStencilAttachment* stencil) { if (!stencil && !fRenderTarget->fStencilAttachment) { // No need to do any work since we currently don't have a stencil attachment and // we're not acctually adding one. return true; } fRenderTarget->fStencilAttachment = stencil; if (!fRenderTarget->completeStencilAttachment()) { SkSafeSetNull(fRenderTarget->fStencilAttachment); return false; } return true; }