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