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