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" |
Chris Dalton | d7291ba | 2019-03-07 14:17:03 -0700 | [diff] [blame] | 17 | #include "GrSamplePatternDictionary.h" |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 18 | #include "GrStencilAttachment.h" |
csmartdalton | c633abb | 2016-11-01 08:55:55 -0700 | [diff] [blame] | 19 | #include "GrStencilSettings.h" |
Mike Reed | 274218e | 2018-01-08 15:05:02 -0500 | [diff] [blame] | 20 | #include "SkRectPriv.h" |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 21 | |
Robert Phillips | c4f0a82 | 2017-06-13 08:11:36 -0400 | [diff] [blame] | 22 | GrRenderTarget::GrRenderTarget(GrGpu* gpu, const GrSurfaceDesc& desc, |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 23 | GrStencilAttachment* stencil) |
Brian Salomon | d34edf3 | 2017-05-19 15:45:48 -0400 | [diff] [blame] | 24 | : INHERITED(gpu, desc) |
| 25 | , fSampleCnt(desc.fSampleCnt) |
Chris Dalton | d7291ba | 2019-03-07 14:17:03 -0700 | [diff] [blame] | 26 | , fSamplePatternKey(GrSamplePatternDictionary::kInvalidSamplePatternKey) |
Robert Phillips | fe0253f | 2018-03-16 16:47:25 -0400 | [diff] [blame] | 27 | , fStencilAttachment(stencil) { |
Brian Salomon | d34edf3 | 2017-05-19 15:45:48 -0400 | [diff] [blame] | 28 | SkASSERT(desc.fFlags & kRenderTarget_GrSurfaceFlag); |
Robert Phillips | fe0253f | 2018-03-16 16:47:25 -0400 | [diff] [blame] | 29 | SkASSERT(!this->hasMixedSamples() || fSampleCnt > 1); |
Mike Reed | 274218e | 2018-01-08 15:05:02 -0500 | [diff] [blame] | 30 | fResolveRect = SkRectPriv::MakeILargestInverted(); |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 31 | } |
| 32 | |
Ben Wagner | 9ec70c6 | 2018-07-12 13:30:47 -0400 | [diff] [blame] | 33 | GrRenderTarget::~GrRenderTarget() = default; |
| 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()) { |
Mike Reed | 274218e | 2018-01-08 15:05:02 -0500 | [diff] [blame] | 51 | fResolveRect = SkRectPriv::MakeILargestInverted(); |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 52 | } else { |
| 53 | if (!fResolveRect.intersect(0, 0, this->width(), this->height())) { |
Mike Reed | 274218e | 2018-01-08 15:05:02 -0500 | [diff] [blame] | 54 | fResolveRect = SkRectPriv::MakeILargestInverted(); |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 55 | } |
| 56 | } |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 57 | } |
| 58 | |
Mike Reed | 274218e | 2018-01-08 15:05:02 -0500 | [diff] [blame] | 59 | void GrRenderTarget::flagAsResolved() { |
| 60 | fResolveRect = SkRectPriv::MakeILargestInverted(); |
| 61 | } |
| 62 | |
robertphillips@google.com | d6bbbf8 | 2012-09-05 15:46:34 +0000 | [diff] [blame] | 63 | void GrRenderTarget::onRelease() { |
Ben Wagner | 9ec70c6 | 2018-07-12 13:30:47 -0400 | [diff] [blame] | 64 | fStencilAttachment = nullptr; |
robertphillips@google.com | d364554 | 2012-09-05 18:37:39 +0000 | [diff] [blame] | 65 | |
| 66 | INHERITED::onRelease(); |
robertphillips@google.com | d6bbbf8 | 2012-09-05 15:46:34 +0000 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | void GrRenderTarget::onAbandon() { |
Ben Wagner | 9ec70c6 | 2018-07-12 13:30:47 -0400 | [diff] [blame] | 70 | fStencilAttachment = nullptr; |
robertphillips | 498d7ac | 2015-10-30 10:11:30 -0700 | [diff] [blame] | 71 | |
robertphillips@google.com | d364554 | 2012-09-05 18:37:39 +0000 | [diff] [blame] | 72 | INHERITED::onAbandon(); |
robertphillips@google.com | d6bbbf8 | 2012-09-05 15:46:34 +0000 | [diff] [blame] | 73 | } |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 74 | |
| 75 | /////////////////////////////////////////////////////////////////////////////// |
| 76 | |
Greg Daniel | cfa3935 | 2018-10-05 12:01:59 -0400 | [diff] [blame] | 77 | void GrRenderTargetPriv::attachStencilAttachment(sk_sp<GrStencilAttachment> stencil) { |
egdaniel | 79bd2ae | 2015-09-15 08:46:13 -0700 | [diff] [blame] | 78 | if (!stencil && !fRenderTarget->fStencilAttachment) { |
| 79 | // 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] | 80 | // we're not actually adding one. |
Greg Daniel | cfa3935 | 2018-10-05 12:01:59 -0400 | [diff] [blame] | 81 | return; |
egdaniel | 79bd2ae | 2015-09-15 08:46:13 -0700 | [diff] [blame] | 82 | } |
Ben Wagner | 9ec70c6 | 2018-07-12 13:30:47 -0400 | [diff] [blame] | 83 | fRenderTarget->fStencilAttachment = std::move(stencil); |
egdaniel | ec00d94 | 2015-09-14 12:56:10 -0700 | [diff] [blame] | 84 | if (!fRenderTarget->completeStencilAttachment()) { |
Ben Wagner | 9ec70c6 | 2018-07-12 13:30:47 -0400 | [diff] [blame] | 85 | fRenderTarget->fStencilAttachment = nullptr; |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 86 | } |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 87 | } |
cdalton | 28f45b9 | 2016-03-07 13:58:26 -0800 | [diff] [blame] | 88 | |
cdalton | 193d9cf | 2016-05-12 11:52:02 -0700 | [diff] [blame] | 89 | int GrRenderTargetPriv::numStencilBits() const { |
csmartdalton | c633abb | 2016-11-01 08:55:55 -0700 | [diff] [blame] | 90 | SkASSERT(this->getStencilAttachment()); |
| 91 | return this->getStencilAttachment()->bits(); |
cdalton | 193d9cf | 2016-05-12 11:52:02 -0700 | [diff] [blame] | 92 | } |
Chris Dalton | d7291ba | 2019-03-07 14:17:03 -0700 | [diff] [blame] | 93 | |
Chris Dalton | 8c4cafd | 2019-04-15 19:14:36 -0600 | [diff] [blame^] | 94 | int GrRenderTargetPriv::getSamplePatternKey() const { |
Chris Dalton | d7291ba | 2019-03-07 14:17:03 -0700 | [diff] [blame] | 95 | SkASSERT(fRenderTarget->fSampleCnt > 1); |
| 96 | if (GrSamplePatternDictionary::kInvalidSamplePatternKey == fRenderTarget->fSamplePatternKey) { |
| 97 | fRenderTarget->fSamplePatternKey = |
Chris Dalton | 8c4cafd | 2019-04-15 19:14:36 -0600 | [diff] [blame^] | 98 | fRenderTarget->getGpu()->findOrAssignSamplePatternKey(fRenderTarget); |
Chris Dalton | d7291ba | 2019-03-07 14:17:03 -0700 | [diff] [blame] | 99 | } |
| 100 | SkASSERT(GrSamplePatternDictionary::kInvalidSamplePatternKey |
| 101 | != fRenderTarget->fSamplePatternKey); |
Chris Dalton | d7291ba | 2019-03-07 14:17:03 -0700 | [diff] [blame] | 102 | return fRenderTarget->fSamplePatternKey; |
| 103 | } |