| 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 | |
| commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 19 | void GrRenderTarget::discard() { |
| 20 | // go through context so that all necessary flushing occurs |
| 21 | GrContext* context = this->getContext(); |
| robertphillips | c9a3706 | 2015-09-01 08:34:28 -0700 | [diff] [blame] | 22 | if (!context) { |
| 23 | return; |
| 24 | } |
| 25 | |
| robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 26 | SkAutoTUnref<GrDrawContext> drawContext(context->drawContext(this)); |
| robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 27 | if (!drawContext) { |
| commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 28 | return; |
| 29 | } |
| robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 30 | |
| robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 31 | drawContext->discard(); |
| commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 32 | } |
| 33 | |
| commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 34 | void GrRenderTarget::flagAsNeedingResolve(const SkIRect* rect) { |
| bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 35 | if (kCanResolve_ResolveType == getResolveType()) { |
| bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 36 | if (rect) { |
| bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 37 | fResolveRect.join(*rect); |
| 38 | if (!fResolveRect.intersect(0, 0, this->width(), this->height())) { |
| 39 | fResolveRect.setEmpty(); |
| 40 | } |
| 41 | } else { |
| 42 | fResolveRect.setLTRB(0, 0, this->width(), this->height()); |
| 43 | } |
| 44 | } |
| 45 | } |
| 46 | |
| commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 47 | void GrRenderTarget::overrideResolveRect(const SkIRect rect) { |
| bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 48 | fResolveRect = rect; |
| 49 | if (fResolveRect.isEmpty()) { |
| 50 | fResolveRect.setLargestInverted(); |
| 51 | } else { |
| 52 | if (!fResolveRect.intersect(0, 0, this->width(), this->height())) { |
| 53 | fResolveRect.setLargestInverted(); |
| 54 | } |
| 55 | } |
| bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 56 | } |
| 57 | |
| robertphillips@google.com | d6bbbf8 | 2012-09-05 15:46:34 +0000 | [diff] [blame] | 58 | void GrRenderTarget::onRelease() { |
| egdaniel | ec00d94 | 2015-09-14 12:56:10 -0700 | [diff] [blame] | 59 | SkSafeSetNull(fStencilAttachment); |
| robertphillips | a352b14 | 2015-10-22 05:31:32 -0700 | [diff] [blame] | 60 | fLastDrawTarget = nullptr; |
| robertphillips@google.com | d364554 | 2012-09-05 18:37:39 +0000 | [diff] [blame] | 61 | |
| 62 | INHERITED::onRelease(); |
| robertphillips@google.com | d6bbbf8 | 2012-09-05 15:46:34 +0000 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | void GrRenderTarget::onAbandon() { |
| egdaniel | ec00d94 | 2015-09-14 12:56:10 -0700 | [diff] [blame] | 66 | SkSafeSetNull(fStencilAttachment); |
| robertphillips | a352b14 | 2015-10-22 05:31:32 -0700 | [diff] [blame] | 67 | fLastDrawTarget = nullptr; |
| robertphillips@google.com | d364554 | 2012-09-05 18:37:39 +0000 | [diff] [blame] | 68 | |
| 69 | INHERITED::onAbandon(); |
| robertphillips@google.com | d6bbbf8 | 2012-09-05 15:46:34 +0000 | [diff] [blame] | 70 | } |
| bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 71 | |
| robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 72 | void GrRenderTarget::setLastDrawTarget(GrDrawTarget* dt) { |
| 73 | if (fLastDrawTarget) { |
| 74 | SkASSERT(fLastDrawTarget->isClosed()); |
| 75 | } |
| 76 | |
| robertphillips | a352b14 | 2015-10-22 05:31:32 -0700 | [diff] [blame] | 77 | fLastDrawTarget = dt; |
| robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 78 | } |
| 79 | |
| bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 80 | /////////////////////////////////////////////////////////////////////////////// |
| 81 | |
| egdaniel | ec00d94 | 2015-09-14 12:56:10 -0700 | [diff] [blame] | 82 | bool GrRenderTargetPriv::attachStencilAttachment(GrStencilAttachment* stencil) { |
| egdaniel | 79bd2ae | 2015-09-15 08:46:13 -0700 | [diff] [blame] | 83 | if (!stencil && !fRenderTarget->fStencilAttachment) { |
| 84 | // No need to do any work since we currently don't have a stencil attachment and |
| 85 | // we're not acctually adding one. |
| 86 | return true; |
| 87 | } |
| egdaniel | ec00d94 | 2015-09-14 12:56:10 -0700 | [diff] [blame] | 88 | fRenderTarget->fStencilAttachment = stencil; |
| 89 | if (!fRenderTarget->completeStencilAttachment()) { |
| 90 | SkSafeSetNull(fRenderTarget->fStencilAttachment); |
| 91 | return false; |
| 92 | } |
| 93 | return true; |
| bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 94 | } |