robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 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 | #include "GrRenderTargetProxy.h" |
| 9 | |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 10 | #include "GrCaps.h" |
Robert Phillips | e2f7d18 | 2016-12-15 09:23:05 -0500 | [diff] [blame] | 11 | #include "GrGpuResourcePriv.h" |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 12 | #include "GrRenderTargetOpList.h" |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 13 | #include "GrRenderTargetPriv.h" |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 14 | #include "GrResourceProvider.h" |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 15 | #include "GrTextureRenderTargetProxy.h" |
Brian Salomon | bb5711a | 2017-05-17 13:49:59 -0400 | [diff] [blame] | 16 | #include "SkMathPriv.h" |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 17 | |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 18 | // Deferred version |
| 19 | // TODO: we can probably munge the 'desc' in both the wrapped and deferred |
| 20 | // cases to make the sampleConfig/numSamples stuff more rational. |
| 21 | GrRenderTargetProxy::GrRenderTargetProxy(const GrCaps& caps, const GrSurfaceDesc& desc, |
Robert Phillips | c787e49 | 2017-02-28 11:26:32 -0500 | [diff] [blame] | 22 | SkBackingFit fit, SkBudgeted budgeted, uint32_t flags) |
Brian Salomon | bb5711a | 2017-05-17 13:49:59 -0400 | [diff] [blame] | 23 | : INHERITED(desc, fit, budgeted, flags) |
| 24 | , fSampleCnt(desc.fSampleCnt) |
Robert Phillips | 6504813 | 2017-08-10 08:44:49 -0400 | [diff] [blame] | 25 | , fNeedsStencil(false) |
Robert Phillips | c4f0a82 | 2017-06-13 08:11:36 -0400 | [diff] [blame] | 26 | , fRenderTargetFlags(GrRenderTargetFlags::kNone) { |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 27 | // Since we know the newly created render target will be internal, we are able to precompute |
| 28 | // what the flags will ultimately end up being. |
Brian Salomon | bb5711a | 2017-05-17 13:49:59 -0400 | [diff] [blame] | 29 | if (caps.usesMixedSamples() && fSampleCnt > 0) { |
Robert Phillips | c4f0a82 | 2017-06-13 08:11:36 -0400 | [diff] [blame] | 30 | fRenderTargetFlags |= GrRenderTargetFlags::kMixedSampled; |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 31 | } |
| 32 | if (caps.maxWindowRectangles() > 0) { |
Robert Phillips | c4f0a82 | 2017-06-13 08:11:36 -0400 | [diff] [blame] | 33 | fRenderTargetFlags |= GrRenderTargetFlags::kWindowRectsSupport; |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 34 | } |
| 35 | } |
| 36 | |
| 37 | // Wrapped version |
Robert Phillips | 066f020 | 2017-07-25 10:16:35 -0400 | [diff] [blame] | 38 | GrRenderTargetProxy::GrRenderTargetProxy(sk_sp<GrSurface> surf, GrSurfaceOrigin origin) |
| 39 | : INHERITED(std::move(surf), origin, SkBackingFit::kExact) |
Robert Phillips | c4f0a82 | 2017-06-13 08:11:36 -0400 | [diff] [blame] | 40 | , fSampleCnt(fTarget->asRenderTarget()->numStencilSamples()) |
Robert Phillips | 6504813 | 2017-08-10 08:44:49 -0400 | [diff] [blame] | 41 | , fNeedsStencil(false) |
Robert Phillips | c4f0a82 | 2017-06-13 08:11:36 -0400 | [diff] [blame] | 42 | , fRenderTargetFlags(fTarget->asRenderTarget()->renderTargetPriv().flags()) { |
| 43 | } |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 44 | |
Robert Phillips | ec2249f | 2016-11-09 08:54:35 -0500 | [diff] [blame] | 45 | int GrRenderTargetProxy::maxWindowRectangles(const GrCaps& caps) const { |
Robert Phillips | c4f0a82 | 2017-06-13 08:11:36 -0400 | [diff] [blame] | 46 | return (fRenderTargetFlags & GrRenderTargetFlags::kWindowRectsSupport) |
Brian Salomon | dac5f6b | 2017-02-28 16:11:04 -0500 | [diff] [blame] | 47 | ? caps.maxWindowRectangles() |
| 48 | : 0; |
Robert Phillips | ec2249f | 2016-11-09 08:54:35 -0500 | [diff] [blame] | 49 | } |
| 50 | |
Robert Phillips | eee4d6e | 2017-06-05 09:26:07 -0400 | [diff] [blame] | 51 | bool GrRenderTargetProxy::instantiate(GrResourceProvider* resourceProvider) { |
Brian Salomon | bb5711a | 2017-05-17 13:49:59 -0400 | [diff] [blame] | 52 | static constexpr GrSurfaceFlags kFlags = kRenderTarget_GrSurfaceFlag; |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 53 | |
Robert Phillips | 6504813 | 2017-08-10 08:44:49 -0400 | [diff] [blame] | 54 | if (!this->instantiateImpl(resourceProvider, fSampleCnt, fNeedsStencil, kFlags, |
Robert Phillips | eee4d6e | 2017-06-05 09:26:07 -0400 | [diff] [blame] | 55 | /* isMipped = */ false, |
| 56 | SkDestinationSurfaceColorMode::kLegacy)) { |
| 57 | return false; |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 58 | } |
Robert Phillips | eee4d6e | 2017-06-05 09:26:07 -0400 | [diff] [blame] | 59 | SkASSERT(fTarget->asRenderTarget()); |
Leon Scroggins | 7d7d7d1 | 2016-11-07 21:26:31 +0000 | [diff] [blame] | 60 | // Check that our a priori computation matched the ultimate reality |
Robert Phillips | eee4d6e | 2017-06-05 09:26:07 -0400 | [diff] [blame] | 61 | SkASSERT(fRenderTargetFlags == fTarget->asRenderTarget()->renderTargetPriv().flags()); |
Leon Scroggins | 7d7d7d1 | 2016-11-07 21:26:31 +0000 | [diff] [blame] | 62 | |
Robert Phillips | eee4d6e | 2017-06-05 09:26:07 -0400 | [diff] [blame] | 63 | return true; |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 64 | } |
| 65 | |
Robert Phillips | 5af44de | 2017-07-18 14:49:38 -0400 | [diff] [blame] | 66 | sk_sp<GrSurface> GrRenderTargetProxy::createSurface(GrResourceProvider* resourceProvider) const { |
| 67 | static constexpr GrSurfaceFlags kFlags = kRenderTarget_GrSurfaceFlag; |
| 68 | |
Robert Phillips | 6504813 | 2017-08-10 08:44:49 -0400 | [diff] [blame] | 69 | sk_sp<GrSurface> surface = this->createSurfaceImpl(resourceProvider, fSampleCnt, fNeedsStencil, |
| 70 | kFlags, /* isMipped = */ false, |
Robert Phillips | 5af44de | 2017-07-18 14:49:38 -0400 | [diff] [blame] | 71 | SkDestinationSurfaceColorMode::kLegacy); |
| 72 | if (!surface) { |
| 73 | return nullptr; |
| 74 | } |
| 75 | SkASSERT(surface->asRenderTarget()); |
| 76 | // Check that our a priori computation matched the ultimate reality |
| 77 | SkASSERT(fRenderTargetFlags == surface->asRenderTarget()->renderTargetPriv().flags()); |
| 78 | |
| 79 | return surface; |
| 80 | } |
| 81 | |
Brian Salomon | bb5711a | 2017-05-17 13:49:59 -0400 | [diff] [blame] | 82 | int GrRenderTargetProxy::worstCaseWidth() const { |
Robert Phillips | 8bc06d0 | 2016-11-01 17:28:40 -0400 | [diff] [blame] | 83 | if (fTarget) { |
Brian Salomon | bb5711a | 2017-05-17 13:49:59 -0400 | [diff] [blame] | 84 | return fTarget->width(); |
Robert Phillips | 8bc06d0 | 2016-11-01 17:28:40 -0400 | [diff] [blame] | 85 | } |
| 86 | |
Brian Salomon | bb5711a | 2017-05-17 13:49:59 -0400 | [diff] [blame] | 87 | if (SkBackingFit::kExact == fFit) { |
| 88 | return fWidth; |
| 89 | } |
| 90 | return SkTMax(GrResourceProvider::kMinScratchTextureSize, GrNextPow2(fWidth)); |
| 91 | } |
| 92 | |
| 93 | int GrRenderTargetProxy::worstCaseHeight() const { |
| 94 | if (fTarget) { |
| 95 | return fTarget->height(); |
| 96 | } |
| 97 | |
| 98 | if (SkBackingFit::kExact == fFit) { |
| 99 | return fHeight; |
| 100 | } |
| 101 | return SkTMax(GrResourceProvider::kMinScratchTextureSize, GrNextPow2(fHeight)); |
| 102 | } |
| 103 | |
| 104 | size_t GrRenderTargetProxy::onUninstantiatedGpuMemorySize() const { |
| 105 | int colorSamplesPerPixel = this->numColorSamples() + 1; |
Robert Phillips | 8bc06d0 | 2016-11-01 17:28:40 -0400 | [diff] [blame] | 106 | // TODO: do we have enough information to improve this worst case estimate? |
Brian Salomon | bb5711a | 2017-05-17 13:49:59 -0400 | [diff] [blame] | 107 | return GrSurface::ComputeSize(fConfig, fWidth, fHeight, colorSamplesPerPixel, false, |
| 108 | SkBackingFit::kApprox == fFit); |
Robert Phillips | 8bc06d0 | 2016-11-01 17:28:40 -0400 | [diff] [blame] | 109 | } |
| 110 | |
Robert Phillips | e2f7d18 | 2016-12-15 09:23:05 -0500 | [diff] [blame] | 111 | bool GrRenderTargetProxy::refsWrappedObjects() const { |
| 112 | if (!fTarget) { |
| 113 | return false; |
| 114 | } |
| 115 | |
| 116 | return fTarget->resourcePriv().refsWrappedObjects(); |
| 117 | } |