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 | |
Robert Phillips | c4f0a82 | 2017-06-13 08:11:36 -0400 | [diff] [blame] | 20 | GrRenderTarget::GrRenderTarget(GrGpu* gpu, const GrSurfaceDesc& desc, |
| 21 | GrRenderTargetFlags flags, |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 22 | GrStencilAttachment* stencil) |
Brian Salomon | d34edf3 | 2017-05-19 15:45:48 -0400 | [diff] [blame] | 23 | : INHERITED(gpu, desc) |
| 24 | , fSampleCnt(desc.fSampleCnt) |
| 25 | , fStencilAttachment(stencil) |
| 26 | , fMultisampleSpecsID(0) |
| 27 | , fFlags(flags) { |
| 28 | SkASSERT(desc.fFlags & kRenderTarget_GrSurfaceFlag); |
Robert Phillips | c4f0a82 | 2017-06-13 08:11:36 -0400 | [diff] [blame] | 29 | SkASSERT(!(fFlags & GrRenderTargetFlags::kMixedSampled) || fSampleCnt > 0); |
| 30 | SkASSERT(!(fFlags & GrRenderTargetFlags::kWindowRectsSupport) || |
| 31 | gpu->caps()->maxWindowRectangles() > 0); |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 32 | fResolveRect.setLargestInverted(); |
| 33 | } |
| 34 | |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 35 | void GrRenderTarget::flagAsNeedingResolve(const SkIRect* rect) { |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 36 | if (kCanResolve_ResolveType == getResolveType()) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 37 | if (rect) { |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 38 | fResolveRect.join(*rect); |
| 39 | if (!fResolveRect.intersect(0, 0, this->width(), this->height())) { |
| 40 | fResolveRect.setEmpty(); |
| 41 | } |
| 42 | } else { |
| 43 | fResolveRect.setLTRB(0, 0, this->width(), this->height()); |
| 44 | } |
| 45 | } |
| 46 | } |
| 47 | |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 48 | void GrRenderTarget::overrideResolveRect(const SkIRect rect) { |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 49 | fResolveRect = rect; |
| 50 | if (fResolveRect.isEmpty()) { |
| 51 | fResolveRect.setLargestInverted(); |
| 52 | } else { |
| 53 | if (!fResolveRect.intersect(0, 0, this->width(), this->height())) { |
| 54 | fResolveRect.setLargestInverted(); |
| 55 | } |
| 56 | } |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 57 | } |
| 58 | |
robertphillips@google.com | d6bbbf8 | 2012-09-05 15:46:34 +0000 | [diff] [blame] | 59 | void GrRenderTarget::onRelease() { |
egdaniel | ec00d94 | 2015-09-14 12:56:10 -0700 | [diff] [blame] | 60 | SkSafeSetNull(fStencilAttachment); |
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 | 498d7ac | 2015-10-30 10:11:30 -0700 | [diff] [blame] | 67 | |
robertphillips@google.com | d364554 | 2012-09-05 18:37:39 +0000 | [diff] [blame] | 68 | INHERITED::onAbandon(); |
robertphillips@google.com | d6bbbf8 | 2012-09-05 15:46:34 +0000 | [diff] [blame] | 69 | } |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 70 | |
| 71 | /////////////////////////////////////////////////////////////////////////////// |
| 72 | |
egdaniel | ec00d94 | 2015-09-14 12:56:10 -0700 | [diff] [blame] | 73 | bool GrRenderTargetPriv::attachStencilAttachment(GrStencilAttachment* stencil) { |
egdaniel | 79bd2ae | 2015-09-15 08:46:13 -0700 | [diff] [blame] | 74 | if (!stencil && !fRenderTarget->fStencilAttachment) { |
| 75 | // 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] | 76 | // we're not actually adding one. |
egdaniel | 79bd2ae | 2015-09-15 08:46:13 -0700 | [diff] [blame] | 77 | return true; |
| 78 | } |
egdaniel | ec00d94 | 2015-09-14 12:56:10 -0700 | [diff] [blame] | 79 | fRenderTarget->fStencilAttachment = stencil; |
| 80 | if (!fRenderTarget->completeStencilAttachment()) { |
| 81 | SkSafeSetNull(fRenderTarget->fStencilAttachment); |
| 82 | return false; |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 83 | } |
egdaniel | ec00d94 | 2015-09-14 12:56:10 -0700 | [diff] [blame] | 84 | return true; |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 85 | } |
cdalton | 28f45b9 | 2016-03-07 13:58:26 -0800 | [diff] [blame] | 86 | |
cdalton | 193d9cf | 2016-05-12 11:52:02 -0700 | [diff] [blame] | 87 | int GrRenderTargetPriv::numStencilBits() const { |
csmartdalton | c633abb | 2016-11-01 08:55:55 -0700 | [diff] [blame] | 88 | SkASSERT(this->getStencilAttachment()); |
| 89 | return this->getStencilAttachment()->bits(); |
cdalton | 193d9cf | 2016-05-12 11:52:02 -0700 | [diff] [blame] | 90 | } |
| 91 | |
cdalton | 28f45b9 | 2016-03-07 13:58:26 -0800 | [diff] [blame] | 92 | const GrGpu::MultisampleSpecs& |
csmartdalton | c633abb | 2016-11-01 08:55:55 -0700 | [diff] [blame] | 93 | GrRenderTargetPriv::getMultisampleSpecs(const GrPipeline& pipeline) const { |
Robert Phillips | 2890fbf | 2017-07-26 15:48:41 -0400 | [diff] [blame] | 94 | SkASSERT(fRenderTarget == pipeline.renderTarget()); // TODO: remove RT from pipeline. |
csmartdalton | c25c5d7 | 2016-11-01 07:03:59 -0700 | [diff] [blame] | 95 | GrGpu* gpu = fRenderTarget->getGpu(); |
| 96 | if (auto id = fRenderTarget->fMultisampleSpecsID) { |
csmartdalton | c633abb | 2016-11-01 08:55:55 -0700 | [diff] [blame] | 97 | SkASSERT(gpu->queryMultisampleSpecs(pipeline).fUniqueID == id); |
csmartdalton | c25c5d7 | 2016-11-01 07:03:59 -0700 | [diff] [blame] | 98 | return gpu->getMultisampleSpecs(id); |
| 99 | } |
csmartdalton | c633abb | 2016-11-01 08:55:55 -0700 | [diff] [blame] | 100 | const GrGpu::MultisampleSpecs& specs = gpu->queryMultisampleSpecs(pipeline); |
csmartdalton | c25c5d7 | 2016-11-01 07:03:59 -0700 | [diff] [blame] | 101 | fRenderTarget->fMultisampleSpecsID = specs.fUniqueID; |
| 102 | return specs; |
cdalton | 28f45b9 | 2016-03-07 13:58:26 -0800 | [diff] [blame] | 103 | } |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 104 | |