bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2011 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
| 8 | |
| 9 | |
| 10 | #include "GrRenderTarget.h" |
| 11 | |
| 12 | #include "GrContext.h" |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 13 | #include "GrDrawContext.h" |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 14 | #include "GrDrawTarget.h" |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 15 | #include "GrGpu.h" |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 16 | #include "GrRenderTargetPriv.h" |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 17 | #include "GrStencilAttachment.h" |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 18 | |
robertphillips | 498d7ac | 2015-10-30 10:11:30 -0700 | [diff] [blame] | 19 | GrRenderTarget::~GrRenderTarget() { |
| 20 | if (fLastDrawTarget) { |
| 21 | fLastDrawTarget->clearRT(); |
| 22 | } |
| 23 | SkSafeUnref(fLastDrawTarget); |
| 24 | } |
| 25 | |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 26 | void GrRenderTarget::discard() { |
| 27 | // go through context so that all necessary flushing occurs |
| 28 | GrContext* context = this->getContext(); |
robertphillips | c9a3706 | 2015-09-01 08:34:28 -0700 | [diff] [blame] | 29 | if (!context) { |
| 30 | return; |
| 31 | } |
| 32 | |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 33 | SkAutoTUnref<GrDrawContext> drawContext(context->drawContext(this)); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 34 | if (!drawContext) { |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 35 | return; |
| 36 | } |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 37 | |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 38 | drawContext->discard(); |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 39 | } |
| 40 | |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 41 | void GrRenderTarget::flagAsNeedingResolve(const SkIRect* rect) { |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 42 | if (kCanResolve_ResolveType == getResolveType()) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 43 | if (rect) { |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 44 | fResolveRect.join(*rect); |
| 45 | if (!fResolveRect.intersect(0, 0, this->width(), this->height())) { |
| 46 | fResolveRect.setEmpty(); |
| 47 | } |
| 48 | } else { |
| 49 | fResolveRect.setLTRB(0, 0, this->width(), this->height()); |
| 50 | } |
| 51 | } |
| 52 | } |
| 53 | |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 54 | void GrRenderTarget::overrideResolveRect(const SkIRect rect) { |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 55 | fResolveRect = rect; |
| 56 | if (fResolveRect.isEmpty()) { |
| 57 | fResolveRect.setLargestInverted(); |
| 58 | } else { |
| 59 | if (!fResolveRect.intersect(0, 0, this->width(), this->height())) { |
| 60 | fResolveRect.setLargestInverted(); |
| 61 | } |
| 62 | } |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 63 | } |
| 64 | |
robertphillips@google.com | d6bbbf8 | 2012-09-05 15:46:34 +0000 | [diff] [blame] | 65 | void GrRenderTarget::onRelease() { |
egdaniel | ec00d94 | 2015-09-14 12:56:10 -0700 | [diff] [blame] | 66 | SkSafeSetNull(fStencilAttachment); |
robertphillips@google.com | d364554 | 2012-09-05 18:37:39 +0000 | [diff] [blame] | 67 | |
| 68 | INHERITED::onRelease(); |
robertphillips@google.com | d6bbbf8 | 2012-09-05 15:46:34 +0000 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | void GrRenderTarget::onAbandon() { |
egdaniel | ec00d94 | 2015-09-14 12:56:10 -0700 | [diff] [blame] | 72 | SkSafeSetNull(fStencilAttachment); |
robertphillips | 498d7ac | 2015-10-30 10:11:30 -0700 | [diff] [blame] | 73 | |
| 74 | // The contents of this renderTarget are gone/invalid. It isn't useful to point back |
| 75 | // the creating drawTarget. |
| 76 | this->setLastDrawTarget(nullptr); |
robertphillips@google.com | d364554 | 2012-09-05 18:37:39 +0000 | [diff] [blame] | 77 | |
| 78 | INHERITED::onAbandon(); |
robertphillips@google.com | d6bbbf8 | 2012-09-05 15:46:34 +0000 | [diff] [blame] | 79 | } |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 80 | |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 81 | void GrRenderTarget::setLastDrawTarget(GrDrawTarget* dt) { |
| 82 | if (fLastDrawTarget) { |
robertphillips | 498d7ac | 2015-10-30 10:11:30 -0700 | [diff] [blame] | 83 | // The non-MDB world never closes so we can't check this condition |
| 84 | #ifdef ENABLE_MDB |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 85 | SkASSERT(fLastDrawTarget->isClosed()); |
robertphillips | 498d7ac | 2015-10-30 10:11:30 -0700 | [diff] [blame] | 86 | #endif |
| 87 | fLastDrawTarget->clearRT(); |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 88 | } |
| 89 | |
robertphillips | 498d7ac | 2015-10-30 10:11:30 -0700 | [diff] [blame] | 90 | SkRefCnt_SafeAssign(fLastDrawTarget, dt); |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 91 | } |
| 92 | |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 93 | /////////////////////////////////////////////////////////////////////////////// |
| 94 | |
egdaniel | ec00d94 | 2015-09-14 12:56:10 -0700 | [diff] [blame] | 95 | bool GrRenderTargetPriv::attachStencilAttachment(GrStencilAttachment* stencil) { |
egdaniel | 79bd2ae | 2015-09-15 08:46:13 -0700 | [diff] [blame] | 96 | if (!stencil && !fRenderTarget->fStencilAttachment) { |
| 97 | // No need to do any work since we currently don't have a stencil attachment and |
| 98 | // we're not acctually adding one. |
| 99 | return true; |
| 100 | } |
egdaniel | ec00d94 | 2015-09-14 12:56:10 -0700 | [diff] [blame] | 101 | fRenderTarget->fStencilAttachment = stencil; |
| 102 | if (!fRenderTarget->completeStencilAttachment()) { |
| 103 | SkSafeSetNull(fRenderTarget->fStencilAttachment); |
| 104 | return false; |
| 105 | } |
| 106 | return true; |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 107 | } |