bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 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" |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame] | 12 | #include "GrContextPriv.h" |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 13 | #include "GrRenderTargetContext.h" |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 14 | #include "GrGpu.h" |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 15 | #include "GrRenderTargetOpList.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 | |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 19 | GrRenderTarget::GrRenderTarget(GrGpu* gpu, const GrSurfaceDesc& desc, Flags flags, |
| 20 | GrStencilAttachment* stencil) |
| 21 | : INHERITED(gpu, desc) |
| 22 | , fStencilAttachment(stencil) |
| 23 | , fMultisampleSpecsID(0) |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 24 | , fFlags(flags) { |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 25 | SkASSERT(!(fFlags & Flags::kMixedSampled) || fDesc.fSampleCnt > 0); |
| 26 | SkASSERT(!(fFlags & Flags::kWindowRectsSupport) || gpu->caps()->maxWindowRectangles() > 0); |
| 27 | fResolveRect.setLargestInverted(); |
| 28 | } |
| 29 | |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 30 | void GrRenderTarget::discard() { |
| 31 | // go through context so that all necessary flushing occurs |
| 32 | GrContext* context = this->getContext(); |
robertphillips | c9a3706 | 2015-09-01 08:34:28 -0700 | [diff] [blame] | 33 | if (!context) { |
| 34 | return; |
| 35 | } |
| 36 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 37 | sk_sp<GrRenderTargetContext> renderTargetContext( |
| 38 | context->contextPriv().makeWrappedRenderTargetContext(sk_ref_sp(this), nullptr)); |
| 39 | if (!renderTargetContext) { |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 40 | return; |
| 41 | } |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 42 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 43 | renderTargetContext->discard(); |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 44 | } |
| 45 | |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 46 | void GrRenderTarget::flagAsNeedingResolve(const SkIRect* rect) { |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 47 | if (kCanResolve_ResolveType == getResolveType()) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 48 | if (rect) { |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 49 | fResolveRect.join(*rect); |
| 50 | if (!fResolveRect.intersect(0, 0, this->width(), this->height())) { |
| 51 | fResolveRect.setEmpty(); |
| 52 | } |
| 53 | } else { |
| 54 | fResolveRect.setLTRB(0, 0, this->width(), this->height()); |
| 55 | } |
| 56 | } |
| 57 | } |
| 58 | |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 59 | void GrRenderTarget::overrideResolveRect(const SkIRect rect) { |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 60 | fResolveRect = rect; |
| 61 | if (fResolveRect.isEmpty()) { |
| 62 | fResolveRect.setLargestInverted(); |
| 63 | } else { |
| 64 | if (!fResolveRect.intersect(0, 0, this->width(), this->height())) { |
| 65 | fResolveRect.setLargestInverted(); |
| 66 | } |
| 67 | } |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 68 | } |
| 69 | |
robertphillips@google.com | d6bbbf8 | 2012-09-05 15:46:34 +0000 | [diff] [blame] | 70 | void GrRenderTarget::onRelease() { |
egdaniel | ec00d94 | 2015-09-14 12:56:10 -0700 | [diff] [blame] | 71 | SkSafeSetNull(fStencilAttachment); |
robertphillips@google.com | d364554 | 2012-09-05 18:37:39 +0000 | [diff] [blame] | 72 | |
| 73 | INHERITED::onRelease(); |
robertphillips@google.com | d6bbbf8 | 2012-09-05 15:46:34 +0000 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | void GrRenderTarget::onAbandon() { |
egdaniel | ec00d94 | 2015-09-14 12:56:10 -0700 | [diff] [blame] | 77 | SkSafeSetNull(fStencilAttachment); |
robertphillips | 498d7ac | 2015-10-30 10:11:30 -0700 | [diff] [blame] | 78 | |
| 79 | // The contents of this renderTarget are gone/invalid. It isn't useful to point back |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 80 | // the creating opList. |
| 81 | this->setLastOpList(nullptr); |
robertphillips@google.com | d364554 | 2012-09-05 18:37:39 +0000 | [diff] [blame] | 82 | |
| 83 | INHERITED::onAbandon(); |
robertphillips@google.com | d6bbbf8 | 2012-09-05 15:46:34 +0000 | [diff] [blame] | 84 | } |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 85 | |
| 86 | /////////////////////////////////////////////////////////////////////////////// |
| 87 | |
egdaniel | ec00d94 | 2015-09-14 12:56:10 -0700 | [diff] [blame] | 88 | bool GrRenderTargetPriv::attachStencilAttachment(GrStencilAttachment* stencil) { |
egdaniel | 79bd2ae | 2015-09-15 08:46:13 -0700 | [diff] [blame] | 89 | if (!stencil && !fRenderTarget->fStencilAttachment) { |
| 90 | // No need to do any work since we currently don't have a stencil attachment and |
| 91 | // we're not acctually adding one. |
| 92 | return true; |
| 93 | } |
egdaniel | ec00d94 | 2015-09-14 12:56:10 -0700 | [diff] [blame] | 94 | fRenderTarget->fStencilAttachment = stencil; |
| 95 | if (!fRenderTarget->completeStencilAttachment()) { |
| 96 | SkSafeSetNull(fRenderTarget->fStencilAttachment); |
| 97 | return false; |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 98 | } |
egdaniel | ec00d94 | 2015-09-14 12:56:10 -0700 | [diff] [blame] | 99 | return true; |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 100 | } |
cdalton | 28f45b9 | 2016-03-07 13:58:26 -0800 | [diff] [blame] | 101 | |
cdalton | 193d9cf | 2016-05-12 11:52:02 -0700 | [diff] [blame] | 102 | int GrRenderTargetPriv::numStencilBits() const { |
| 103 | return fRenderTarget->fStencilAttachment ? fRenderTarget->fStencilAttachment->bits() : 0; |
| 104 | } |
| 105 | |
cdalton | 28f45b9 | 2016-03-07 13:58:26 -0800 | [diff] [blame] | 106 | const GrGpu::MultisampleSpecs& |
| 107 | GrRenderTargetPriv::getMultisampleSpecs(const GrStencilSettings& stencil) const { |
| 108 | return fRenderTarget->getGpu()->getMultisampleSpecs(fRenderTarget, stencil); |
| 109 | } |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 110 | |
| 111 | int GrRenderTargetPriv::maxWindowRectangles() const { |
| 112 | return (this->flags() & Flags::kWindowRectsSupport) ? |
| 113 | fRenderTarget->getGpu()->caps()->maxWindowRectangles() : 0; |
| 114 | } |