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 | |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 8 | #include "src/gpu/GrSurfaceProxy.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 9 | #include "src/gpu/GrSurfaceProxyPriv.h" |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 10 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "include/gpu/GrContext.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 12 | #include "include/private/GrRecordingContext.h" |
| 13 | #include "src/gpu/GrCaps.h" |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 14 | #include "src/gpu/GrClip.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 15 | #include "src/gpu/GrContextPriv.h" |
| 16 | #include "src/gpu/GrGpuResourcePriv.h" |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 17 | #include "src/gpu/GrOpList.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 18 | #include "src/gpu/GrProxyProvider.h" |
| 19 | #include "src/gpu/GrRecordingContextPriv.h" |
Chris Dalton | effee20 | 2019-07-01 22:28:03 -0600 | [diff] [blame] | 20 | #include "src/gpu/GrStencilAttachment.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 21 | #include "src/gpu/GrSurfaceContext.h" |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 22 | #include "src/gpu/GrSurfaceContextPriv.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 23 | #include "src/gpu/GrSurfacePriv.h" |
| 24 | #include "src/gpu/GrTexturePriv.h" |
| 25 | #include "src/gpu/GrTextureRenderTargetProxy.h" |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 26 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 27 | #include "src/core/SkMathPriv.h" |
| 28 | #include "src/core/SkMipMap.h" |
Robert Phillips | 93f1633 | 2016-11-23 19:37:13 -0500 | [diff] [blame] | 29 | |
Greg Daniel | 65fa8ca | 2018-01-10 17:06:31 -0500 | [diff] [blame] | 30 | #ifdef SK_DEBUG |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 31 | #include "include/gpu/GrRenderTarget.h" |
| 32 | #include "src/gpu/GrRenderTargetPriv.h" |
Robert Phillips | c7c2baf | 2018-03-08 09:51:04 -0500 | [diff] [blame] | 33 | |
Greg Daniel | 65fa8ca | 2018-01-10 17:06:31 -0500 | [diff] [blame] | 34 | static bool is_valid_fully_lazy(const GrSurfaceDesc& desc, SkBackingFit fit) { |
| 35 | return desc.fWidth <= 0 && |
| 36 | desc.fHeight <= 0 && |
| 37 | desc.fConfig != kUnknown_GrPixelConfig && |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 38 | desc.fSampleCnt == 1 && |
Greg Daniel | 65fa8ca | 2018-01-10 17:06:31 -0500 | [diff] [blame] | 39 | SkBackingFit::kApprox == fit; |
| 40 | } |
| 41 | |
| 42 | static bool is_valid_partially_lazy(const GrSurfaceDesc& desc) { |
| 43 | return ((desc.fWidth > 0 && desc.fHeight > 0) || |
| 44 | (desc.fWidth <= 0 && desc.fHeight <= 0)) && |
| 45 | desc.fConfig != kUnknown_GrPixelConfig; |
| 46 | } |
| 47 | |
| 48 | static bool is_valid_non_lazy(const GrSurfaceDesc& desc) { |
| 49 | return desc.fWidth > 0 && |
| 50 | desc.fHeight > 0 && |
| 51 | desc.fConfig != kUnknown_GrPixelConfig; |
| 52 | } |
| 53 | #endif |
| 54 | |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 55 | // Lazy-callback version |
Greg Daniel | 457469c | 2018-02-08 15:05:44 -0500 | [diff] [blame] | 56 | GrSurfaceProxy::GrSurfaceProxy(LazyInstantiateCallback&& callback, LazyInstantiationType lazyType, |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 57 | const GrBackendFormat& format, const GrSurfaceDesc& desc, |
Greg Daniel | 2c19e7f | 2019-06-18 13:29:21 -0400 | [diff] [blame] | 58 | GrSurfaceOrigin origin, const GrSwizzle& textureSwizzle, |
| 59 | SkBackingFit fit, SkBudgeted budgeted, |
| 60 | GrInternalSurfaceFlags surfaceFlags) |
Greg Daniel | e320486 | 2018-04-16 11:24:10 -0400 | [diff] [blame] | 61 | : fSurfaceFlags(surfaceFlags) |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 62 | , fFormat(format) |
Greg Daniel | e320486 | 2018-04-16 11:24:10 -0400 | [diff] [blame] | 63 | , fConfig(desc.fConfig) |
Greg Daniel | 65fa8ca | 2018-01-10 17:06:31 -0500 | [diff] [blame] | 64 | , fWidth(desc.fWidth) |
| 65 | , fHeight(desc.fHeight) |
Brian Salomon | 2a4f983 | 2018-03-03 22:43:43 -0500 | [diff] [blame] | 66 | , fOrigin(origin) |
Greg Daniel | 2c19e7f | 2019-06-18 13:29:21 -0400 | [diff] [blame] | 67 | , fTextureSwizzle(textureSwizzle) |
Greg Daniel | 65fa8ca | 2018-01-10 17:06:31 -0500 | [diff] [blame] | 68 | , fFit(fit) |
| 69 | , fBudgeted(budgeted) |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 70 | , fLazyInstantiateCallback(std::move(callback)) |
Greg Daniel | 457469c | 2018-02-08 15:05:44 -0500 | [diff] [blame] | 71 | , fLazyInstantiationType(lazyType) |
Greg Daniel | 65fa8ca | 2018-01-10 17:06:31 -0500 | [diff] [blame] | 72 | , fNeedsClear(SkToBool(desc.fFlags & kPerformInitialClear_GrSurfaceFlag)) |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 73 | , fIsProtected(desc.fIsProtected) |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 74 | , fGpuMemorySize(kInvalidGpuMemorySize) |
| 75 | , fLastOpList(nullptr) { |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 76 | SkASSERT(fFormat.isValid()); |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 77 | // NOTE: the default fUniqueID ctor pulls a value from the same pool as the GrGpuResources. |
Greg Daniel | 65fa8ca | 2018-01-10 17:06:31 -0500 | [diff] [blame] | 78 | if (fLazyInstantiateCallback) { |
| 79 | SkASSERT(is_valid_fully_lazy(desc, fit) || is_valid_partially_lazy(desc)); |
| 80 | } else { |
| 81 | SkASSERT(is_valid_non_lazy(desc)); |
| 82 | } |
Jim Van Verth | 1676cb9 | 2019-01-15 13:24:45 -0500 | [diff] [blame] | 83 | |
| 84 | if (GrPixelConfigIsCompressed(desc.fConfig)) { |
| 85 | SkASSERT(!SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag)); |
| 86 | fSurfaceFlags |= GrInternalSurfaceFlags::kReadOnly; |
| 87 | } |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | // Wrapped version |
Greg Daniel | 2c19e7f | 2019-06-18 13:29:21 -0400 | [diff] [blame] | 91 | GrSurfaceProxy::GrSurfaceProxy(sk_sp<GrSurface> surface, GrSurfaceOrigin origin, |
| 92 | const GrSwizzle& textureSwizzle, SkBackingFit fit) |
Robert Phillips | b520476 | 2019-06-19 14:12:13 -0400 | [diff] [blame] | 93 | : fTarget(std::move(surface)) |
Greg Daniel | e320486 | 2018-04-16 11:24:10 -0400 | [diff] [blame] | 94 | , fSurfaceFlags(fTarget->surfacePriv().flags()) |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 95 | , fFormat(fTarget->backendFormat()) |
Brian Salomon | bb5711a | 2017-05-17 13:49:59 -0400 | [diff] [blame] | 96 | , fConfig(fTarget->config()) |
| 97 | , fWidth(fTarget->width()) |
| 98 | , fHeight(fTarget->height()) |
Robert Phillips | 066f020 | 2017-07-25 10:16:35 -0400 | [diff] [blame] | 99 | , fOrigin(origin) |
Greg Daniel | 2c19e7f | 2019-06-18 13:29:21 -0400 | [diff] [blame] | 100 | , fTextureSwizzle(textureSwizzle) |
Brian Salomon | bb5711a | 2017-05-17 13:49:59 -0400 | [diff] [blame] | 101 | , fFit(fit) |
Brian Salomon | fa2ebea | 2019-01-24 15:58:58 -0500 | [diff] [blame] | 102 | , fBudgeted(fTarget->resourcePriv().budgetedType() == GrBudgetedType::kBudgeted |
| 103 | ? SkBudgeted::kYes |
| 104 | : SkBudgeted::kNo) |
Brian Salomon | bb5711a | 2017-05-17 13:49:59 -0400 | [diff] [blame] | 105 | , fUniqueID(fTarget->uniqueID()) // Note: converting from unique resource ID to a proxy ID! |
Brian Salomon | d17b4a6 | 2017-05-23 16:53:47 -0400 | [diff] [blame] | 106 | , fNeedsClear(false) |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 107 | , fIsProtected(fTarget->isProtected() ? GrProtected::kYes : GrProtected::kNo) |
Brian Salomon | bb5711a | 2017-05-17 13:49:59 -0400 | [diff] [blame] | 108 | , fGpuMemorySize(kInvalidGpuMemorySize) |
Robert Phillips | 019ff27 | 2017-07-24 14:47:57 -0400 | [diff] [blame] | 109 | , fLastOpList(nullptr) { |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 110 | SkASSERT(fFormat.isValid()); |
Robert Phillips | 019ff27 | 2017-07-24 14:47:57 -0400 | [diff] [blame] | 111 | } |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 112 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 113 | GrSurfaceProxy::~GrSurfaceProxy() { |
Robert Phillips | 6cdc22c | 2017-05-11 16:29:14 -0400 | [diff] [blame] | 114 | // For this to be deleted the opList that held a ref on it (if there was one) must have been |
| 115 | // deleted. Which would have cleared out this back pointer. |
| 116 | SkASSERT(!fLastOpList); |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 117 | } |
| 118 | |
Robert Phillips | eafd48a | 2017-11-16 07:52:08 -0500 | [diff] [blame] | 119 | bool GrSurfaceProxyPriv::AttachStencilIfNeeded(GrResourceProvider* resourceProvider, |
Chris Dalton | effee20 | 2019-07-01 22:28:03 -0600 | [diff] [blame] | 120 | GrSurface* surface, int minStencilSampleCount) { |
| 121 | if (minStencilSampleCount) { |
Robert Phillips | 6504813 | 2017-08-10 08:44:49 -0400 | [diff] [blame] | 122 | GrRenderTarget* rt = surface->asRenderTarget(); |
| 123 | if (!rt) { |
| 124 | SkASSERT(0); |
| 125 | return false; |
| 126 | } |
| 127 | |
Chris Dalton | effee20 | 2019-07-01 22:28:03 -0600 | [diff] [blame] | 128 | if (!resourceProvider->attachStencilAttachment(rt, minStencilSampleCount)) { |
Robert Phillips | 6504813 | 2017-08-10 08:44:49 -0400 | [diff] [blame] | 129 | return false; |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | return true; |
| 134 | } |
| 135 | |
Robert Phillips | ba5c439 | 2018-07-25 12:37:14 -0400 | [diff] [blame] | 136 | sk_sp<GrSurface> GrSurfaceProxy::createSurfaceImpl(GrResourceProvider* resourceProvider, |
Chris Dalton | effee20 | 2019-07-01 22:28:03 -0600 | [diff] [blame] | 137 | int sampleCnt, int minStencilSampleCount, |
Robert Phillips | ba5c439 | 2018-07-25 12:37:14 -0400 | [diff] [blame] | 138 | GrSurfaceDescFlags descFlags, |
Robert Phillips | 10d1721 | 2019-04-24 14:09:10 -0400 | [diff] [blame] | 139 | GrMipMapped mipMapped) const { |
Greg Daniel | 65fa8ca | 2018-01-10 17:06:31 -0500 | [diff] [blame] | 140 | SkASSERT(GrSurfaceProxy::LazyState::kNot == this->lazyInstantiationState()); |
Greg Daniel | d2d8e92 | 2018-02-12 12:07:39 -0500 | [diff] [blame] | 141 | SkASSERT(!fTarget); |
Brian Salomon | bb5711a | 2017-05-17 13:49:59 -0400 | [diff] [blame] | 142 | GrSurfaceDesc desc; |
Robert Phillips | fe0253f | 2018-03-16 16:47:25 -0400 | [diff] [blame] | 143 | desc.fFlags = descFlags; |
Brian Salomon | d17b4a6 | 2017-05-23 16:53:47 -0400 | [diff] [blame] | 144 | if (fNeedsClear) { |
| 145 | desc.fFlags |= kPerformInitialClear_GrSurfaceFlag; |
| 146 | } |
Robert Phillips | 16d8ec6 | 2017-07-27 16:16:25 -0400 | [diff] [blame] | 147 | desc.fWidth = fWidth; |
| 148 | desc.fHeight = fHeight; |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 149 | desc.fIsProtected = fIsProtected; |
Robert Phillips | 16d8ec6 | 2017-07-27 16:16:25 -0400 | [diff] [blame] | 150 | desc.fConfig = fConfig; |
| 151 | desc.fSampleCnt = sampleCnt; |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 152 | |
Robert Phillips | 10d1721 | 2019-04-24 14:09:10 -0400 | [diff] [blame] | 153 | // The explicit resource allocator requires that any resources it pulls out of the |
| 154 | // cache have no pending IO. |
| 155 | GrResourceProvider::Flags resourceProviderFlags = GrResourceProvider::Flags::kNoPendingIO; |
Robert Phillips | fe0253f | 2018-03-16 16:47:25 -0400 | [diff] [blame] | 156 | |
Robert Phillips | 5af44de | 2017-07-18 14:49:38 -0400 | [diff] [blame] | 157 | sk_sp<GrSurface> surface; |
Greg Daniel | f6f7b67 | 2018-02-15 13:06:26 -0500 | [diff] [blame] | 158 | if (GrMipMapped::kYes == mipMapped) { |
| 159 | SkASSERT(SkBackingFit::kExact == fFit); |
| 160 | |
| 161 | // SkMipMap doesn't include the base level in the level count so we have to add 1 |
| 162 | int mipCount = SkMipMap::ComputeLevelCount(desc.fWidth, desc.fHeight) + 1; |
| 163 | // We should have caught the case where mipCount == 1 when making the proxy and instead |
| 164 | // created a non-mipmapped proxy. |
| 165 | SkASSERT(mipCount > 1); |
| 166 | std::unique_ptr<GrMipLevel[]> texels(new GrMipLevel[mipCount]); |
| 167 | |
| 168 | // We don't want to upload any texel data |
| 169 | for (int i = 0; i < mipCount; i++) { |
| 170 | texels[i].fPixels = nullptr; |
| 171 | texels[i].fRowBytes = 0; |
| 172 | } |
| 173 | |
Brian Osman | 2b23c4b | 2018-06-01 12:25:08 -0400 | [diff] [blame] | 174 | surface = resourceProvider->createTexture(desc, fBudgeted, texels.get(), mipCount); |
Greg Daniel | f6f7b67 | 2018-02-15 13:06:26 -0500 | [diff] [blame] | 175 | if (surface) { |
| 176 | SkASSERT(surface->asTexture()); |
| 177 | SkASSERT(GrMipMapped::kYes == surface->asTexture()->texturePriv().mipMapped()); |
| 178 | } |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 179 | } else { |
Greg Daniel | f6f7b67 | 2018-02-15 13:06:26 -0500 | [diff] [blame] | 180 | if (SkBackingFit::kApprox == fFit) { |
Robert Phillips | fe0253f | 2018-03-16 16:47:25 -0400 | [diff] [blame] | 181 | surface = resourceProvider->createApproxTexture(desc, resourceProviderFlags); |
Greg Daniel | f6f7b67 | 2018-02-15 13:06:26 -0500 | [diff] [blame] | 182 | } else { |
Robert Phillips | fe0253f | 2018-03-16 16:47:25 -0400 | [diff] [blame] | 183 | surface = resourceProvider->createTexture(desc, fBudgeted, resourceProviderFlags); |
Greg Daniel | f6f7b67 | 2018-02-15 13:06:26 -0500 | [diff] [blame] | 184 | } |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 185 | } |
Robert Phillips | 6504813 | 2017-08-10 08:44:49 -0400 | [diff] [blame] | 186 | if (!surface) { |
| 187 | return nullptr; |
| 188 | } |
| 189 | |
Robert Phillips | e5f7328 | 2019-06-18 17:15:04 -0400 | [diff] [blame] | 190 | if (!GrSurfaceProxyPriv::AttachStencilIfNeeded(resourceProvider, surface.get(), |
Chris Dalton | effee20 | 2019-07-01 22:28:03 -0600 | [diff] [blame] | 191 | minStencilSampleCount)) { |
Robert Phillips | 6504813 | 2017-08-10 08:44:49 -0400 | [diff] [blame] | 192 | return nullptr; |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 193 | } |
| 194 | |
Robert Phillips | 5af44de | 2017-07-18 14:49:38 -0400 | [diff] [blame] | 195 | return surface; |
| 196 | } |
| 197 | |
Brian Salomon | 7d94bb5 | 2018-10-12 14:37:19 -0400 | [diff] [blame] | 198 | bool GrSurfaceProxy::canSkipResourceAllocator() const { |
Robert Phillips | 5f78adf | 2019-04-22 12:41:39 -0400 | [diff] [blame] | 199 | if (this->ignoredByResourceAllocator()) { |
| 200 | // Usually an atlas or onFlush proxy |
| 201 | return true; |
| 202 | } |
| 203 | |
Brian Salomon | 7d94bb5 | 2018-10-12 14:37:19 -0400 | [diff] [blame] | 204 | auto peek = this->peekSurface(); |
| 205 | if (!peek) { |
| 206 | return false; |
| 207 | } |
| 208 | // If this resource is already allocated and not recyclable then the resource allocator does |
| 209 | // not need to do anything with it. |
| 210 | return !peek->resourcePriv().getScratchKey().isValid(); |
| 211 | } |
| 212 | |
Robert Phillips | 5af44de | 2017-07-18 14:49:38 -0400 | [diff] [blame] | 213 | void GrSurfaceProxy::assign(sk_sp<GrSurface> surface) { |
| 214 | SkASSERT(!fTarget && surface); |
Robert Phillips | abf7b76 | 2018-03-21 12:13:37 -0400 | [diff] [blame] | 215 | |
Greg Daniel | 849dce1 | 2018-04-24 14:32:53 -0400 | [diff] [blame] | 216 | SkDEBUGCODE(this->validateSurface(surface.get());) |
Robert Phillips | abf7b76 | 2018-03-21 12:13:37 -0400 | [diff] [blame] | 217 | |
Robert Phillips | e5f7328 | 2019-06-18 17:15:04 -0400 | [diff] [blame] | 218 | fTarget = std::move(surface); |
robertphillips | 1125a03 | 2016-11-16 11:17:17 -0800 | [diff] [blame] | 219 | |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 220 | #ifdef SK_DEBUG |
Robert Phillips | c7c2baf | 2018-03-08 09:51:04 -0500 | [diff] [blame] | 221 | if (this->asRenderTargetProxy()) { |
| 222 | SkASSERT(fTarget->asRenderTarget()); |
Chris Dalton | effee20 | 2019-07-01 22:28:03 -0600 | [diff] [blame] | 223 | if (int minStencilSampleCount = this->asRenderTargetProxy()->numStencilSamples()) { |
| 224 | auto* stencil = fTarget->asRenderTarget()->renderTargetPriv().getStencilAttachment(); |
| 225 | SkASSERT(stencil); |
| 226 | SkASSERT(stencil->numSamples() >= minStencilSampleCount); |
Robert Phillips | c7c2baf | 2018-03-08 09:51:04 -0500 | [diff] [blame] | 227 | } |
| 228 | } |
| 229 | |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 230 | if (kInvalidGpuMemorySize != this->getRawGpuMemorySize_debugOnly()) { |
Robert Phillips | 784b7bf | 2016-12-09 13:35:02 -0500 | [diff] [blame] | 231 | SkASSERT(fTarget->gpuMemorySize() <= this->getRawGpuMemorySize_debugOnly()); |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 232 | } |
| 233 | #endif |
Robert Phillips | 5af44de | 2017-07-18 14:49:38 -0400 | [diff] [blame] | 234 | } |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 235 | |
Robert Phillips | 5af44de | 2017-07-18 14:49:38 -0400 | [diff] [blame] | 236 | bool GrSurfaceProxy::instantiateImpl(GrResourceProvider* resourceProvider, int sampleCnt, |
Chris Dalton | effee20 | 2019-07-01 22:28:03 -0600 | [diff] [blame] | 237 | int minStencilSampleCount, GrSurfaceDescFlags descFlags, |
Robert Phillips | 10d1721 | 2019-04-24 14:09:10 -0400 | [diff] [blame] | 238 | GrMipMapped mipMapped, const GrUniqueKey* uniqueKey) { |
Greg Daniel | 65fa8ca | 2018-01-10 17:06:31 -0500 | [diff] [blame] | 239 | SkASSERT(LazyState::kNot == this->lazyInstantiationState()); |
Robert Phillips | 5af44de | 2017-07-18 14:49:38 -0400 | [diff] [blame] | 240 | if (fTarget) { |
Brian Salomon | 5790420 | 2018-12-17 14:45:00 -0500 | [diff] [blame] | 241 | if (uniqueKey && uniqueKey->isValid()) { |
| 242 | SkASSERT(fTarget->getUniqueKey().isValid() && fTarget->getUniqueKey() == *uniqueKey); |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 243 | } |
Robert Phillips | e5f7328 | 2019-06-18 17:15:04 -0400 | [diff] [blame] | 244 | return GrSurfaceProxyPriv::AttachStencilIfNeeded(resourceProvider, fTarget.get(), |
Chris Dalton | effee20 | 2019-07-01 22:28:03 -0600 | [diff] [blame] | 245 | minStencilSampleCount); |
Robert Phillips | 5af44de | 2017-07-18 14:49:38 -0400 | [diff] [blame] | 246 | } |
| 247 | |
Chris Dalton | effee20 | 2019-07-01 22:28:03 -0600 | [diff] [blame] | 248 | sk_sp<GrSurface> surface = this->createSurfaceImpl( |
| 249 | resourceProvider, sampleCnt, minStencilSampleCount, descFlags, mipMapped); |
Robert Phillips | 5af44de | 2017-07-18 14:49:38 -0400 | [diff] [blame] | 250 | if (!surface) { |
| 251 | return false; |
| 252 | } |
| 253 | |
Brian Osman | 28c434b | 2017-09-27 13:11:16 -0400 | [diff] [blame] | 254 | // If there was an invalidation message pending for this key, we might have just processed it, |
| 255 | // causing the key (stored on this proxy) to become invalid. |
| 256 | if (uniqueKey && uniqueKey->isValid()) { |
Robert Phillips | ae7d3f3 | 2017-09-21 08:26:08 -0400 | [diff] [blame] | 257 | resourceProvider->assignUniqueKeyToResource(*uniqueKey, surface.get()); |
| 258 | } |
| 259 | |
Robert Phillips | 5af44de | 2017-07-18 14:49:38 -0400 | [diff] [blame] | 260 | this->assign(std::move(surface)); |
Robert Phillips | fe0253f | 2018-03-16 16:47:25 -0400 | [diff] [blame] | 261 | |
Robert Phillips | eee4d6e | 2017-06-05 09:26:07 -0400 | [diff] [blame] | 262 | return true; |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 263 | } |
| 264 | |
Brian Salomon | 967df20 | 2018-12-07 11:15:53 -0500 | [diff] [blame] | 265 | void GrSurfaceProxy::deinstantiate() { |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 266 | SkASSERT(this->isInstantiated()); |
Robert Phillips | e5f7328 | 2019-06-18 17:15:04 -0400 | [diff] [blame] | 267 | fTarget = nullptr; |
Robert Phillips | 4bc7011 | 2018-03-01 10:24:02 -0500 | [diff] [blame] | 268 | } |
| 269 | |
Robert Phillips | 57aa367 | 2017-07-21 11:38:13 -0400 | [diff] [blame] | 270 | void GrSurfaceProxy::computeScratchKey(GrScratchKey* key) const { |
Greg Daniel | 65fa8ca | 2018-01-10 17:06:31 -0500 | [diff] [blame] | 271 | SkASSERT(LazyState::kFully != this->lazyInstantiationState()); |
Robert Phillips | 57aa367 | 2017-07-21 11:38:13 -0400 | [diff] [blame] | 272 | const GrRenderTargetProxy* rtp = this->asRenderTargetProxy(); |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 273 | int sampleCount = 1; |
Robert Phillips | 57aa367 | 2017-07-21 11:38:13 -0400 | [diff] [blame] | 274 | if (rtp) { |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 275 | sampleCount = rtp->numSamples(); |
Robert Phillips | 57aa367 | 2017-07-21 11:38:13 -0400 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | const GrTextureProxy* tp = this->asTextureProxy(); |
Greg Daniel | e252f08 | 2017-10-23 16:05:23 -0400 | [diff] [blame] | 279 | GrMipMapped mipMapped = GrMipMapped::kNo; |
Robert Phillips | 57aa367 | 2017-07-21 11:38:13 -0400 | [diff] [blame] | 280 | if (tp) { |
Greg Daniel | e252f08 | 2017-10-23 16:05:23 -0400 | [diff] [blame] | 281 | mipMapped = tp->mipMapped(); |
Robert Phillips | 57aa367 | 2017-07-21 11:38:13 -0400 | [diff] [blame] | 282 | } |
| 283 | |
Robert Phillips | a108c92 | 2017-10-10 10:42:19 -0400 | [diff] [blame] | 284 | int width = this->worstCaseWidth(); |
| 285 | int height = this->worstCaseHeight(); |
Robert Phillips | 57aa367 | 2017-07-21 11:38:13 -0400 | [diff] [blame] | 286 | |
Robert Phillips | b0e93a2 | 2017-08-29 08:26:54 -0400 | [diff] [blame] | 287 | GrTexturePriv::ComputeScratchKey(this->config(), width, height, SkToBool(rtp), sampleCount, |
Greg Daniel | e252f08 | 2017-10-23 16:05:23 -0400 | [diff] [blame] | 288 | mipMapped, key); |
Robert Phillips | 57aa367 | 2017-07-21 11:38:13 -0400 | [diff] [blame] | 289 | } |
| 290 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 291 | void GrSurfaceProxy::setLastOpList(GrOpList* opList) { |
Robert Phillips | 6cdc22c | 2017-05-11 16:29:14 -0400 | [diff] [blame] | 292 | #ifdef SK_DEBUG |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 293 | if (fLastOpList) { |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 294 | SkASSERT(fLastOpList->isClosed()); |
Robert Phillips | 4a39504 | 2017-04-24 16:27:17 +0000 | [diff] [blame] | 295 | } |
Robert Phillips | 6cdc22c | 2017-05-11 16:29:14 -0400 | [diff] [blame] | 296 | #endif |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 297 | |
Robert Phillips | 6cdc22c | 2017-05-11 16:29:14 -0400 | [diff] [blame] | 298 | // Un-reffed |
| 299 | fLastOpList = opList; |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 300 | } |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 301 | |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 302 | GrRenderTargetOpList* GrSurfaceProxy::getLastRenderTargetOpList() { |
| 303 | return fLastOpList ? fLastOpList->asRenderTargetOpList() : nullptr; |
| 304 | } |
| 305 | |
| 306 | GrTextureOpList* GrSurfaceProxy::getLastTextureOpList() { |
| 307 | return fLastOpList ? fLastOpList->asTextureOpList() : nullptr; |
| 308 | } |
| 309 | |
Robert Phillips | a108c92 | 2017-10-10 10:42:19 -0400 | [diff] [blame] | 310 | int GrSurfaceProxy::worstCaseWidth() const { |
Greg Daniel | 65fa8ca | 2018-01-10 17:06:31 -0500 | [diff] [blame] | 311 | SkASSERT(LazyState::kFully != this->lazyInstantiationState()); |
Robert Phillips | a108c92 | 2017-10-10 10:42:19 -0400 | [diff] [blame] | 312 | if (fTarget) { |
| 313 | return fTarget->width(); |
| 314 | } |
| 315 | |
| 316 | if (SkBackingFit::kExact == fFit) { |
| 317 | return fWidth; |
| 318 | } |
Robert Phillips | f9fcf7f | 2019-07-11 09:03:27 -0400 | [diff] [blame^] | 319 | return GrResourceProvider::MakeApprox(fWidth); |
Robert Phillips | a108c92 | 2017-10-10 10:42:19 -0400 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | int GrSurfaceProxy::worstCaseHeight() const { |
Greg Daniel | 65fa8ca | 2018-01-10 17:06:31 -0500 | [diff] [blame] | 323 | SkASSERT(LazyState::kFully != this->lazyInstantiationState()); |
Robert Phillips | a108c92 | 2017-10-10 10:42:19 -0400 | [diff] [blame] | 324 | if (fTarget) { |
| 325 | return fTarget->height(); |
| 326 | } |
| 327 | |
| 328 | if (SkBackingFit::kExact == fFit) { |
| 329 | return fHeight; |
| 330 | } |
Robert Phillips | f9fcf7f | 2019-07-11 09:03:27 -0400 | [diff] [blame^] | 331 | return GrResourceProvider::MakeApprox(fHeight); |
Robert Phillips | a108c92 | 2017-10-10 10:42:19 -0400 | [diff] [blame] | 332 | } |
| 333 | |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 334 | #ifdef SK_DEBUG |
Robert Phillips | 292a6b2 | 2019-02-14 14:49:02 -0500 | [diff] [blame] | 335 | void GrSurfaceProxy::validate(GrContext_Base* context) const { |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 336 | if (fTarget) { |
| 337 | SkASSERT(fTarget->getContext() == context); |
| 338 | } |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 339 | } |
| 340 | #endif |
Robert Phillips | e2f7d18 | 2016-12-15 09:23:05 -0500 | [diff] [blame] | 341 | |
Robert Phillips | d44146b | 2019-02-15 14:44:28 -0500 | [diff] [blame] | 342 | sk_sp<GrTextureProxy> GrSurfaceProxy::Copy(GrRecordingContext* context, |
Robert Phillips | e2f7d18 | 2016-12-15 09:23:05 -0500 | [diff] [blame] | 343 | GrSurfaceProxy* src, |
Greg Daniel | 65c7f66 | 2017-10-30 13:39:09 -0400 | [diff] [blame] | 344 | GrMipMapped mipMapped, |
Robert Phillips | e2f7d18 | 2016-12-15 09:23:05 -0500 | [diff] [blame] | 345 | SkIRect srcRect, |
Brian Salomon | fee3f9b | 2018-12-19 12:34:12 -0500 | [diff] [blame] | 346 | SkBackingFit fit, |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 347 | SkBudgeted budgeted, |
| 348 | RectsMustMatch rectsMustMatch) { |
Greg Daniel | 65fa8ca | 2018-01-10 17:06:31 -0500 | [diff] [blame] | 349 | SkASSERT(LazyState::kFully != src->lazyInstantiationState()); |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 350 | GrSurfaceDesc dstDesc; |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 351 | dstDesc.fIsProtected = src->isProtected() ? GrProtected::kYes : GrProtected::kNo; |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 352 | dstDesc.fConfig = src->config(); |
| 353 | |
| 354 | SkIPoint dstPoint; |
| 355 | if (rectsMustMatch == RectsMustMatch::kYes) { |
| 356 | dstDesc.fWidth = src->width(); |
| 357 | dstDesc.fHeight = src->height(); |
| 358 | dstPoint = {srcRect.fLeft, srcRect.fTop}; |
| 359 | } else { |
| 360 | dstDesc.fWidth = srcRect.width(); |
| 361 | dstDesc.fHeight = srcRect.height(); |
| 362 | dstPoint = {0, 0}; |
| 363 | } |
| 364 | |
Robert Phillips | e2f7d18 | 2016-12-15 09:23:05 -0500 | [diff] [blame] | 365 | if (!srcRect.intersect(SkIRect::MakeWH(src->width(), src->height()))) { |
| 366 | return nullptr; |
| 367 | } |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 368 | auto colorType = GrPixelConfigToColorType(src->config()); |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 369 | if (src->backendFormat().textureType() != GrTextureType::kExternal) { |
| 370 | sk_sp<GrSurfaceContext> dstContext(context->priv().makeDeferredSurfaceContext( |
| 371 | src->backendFormat().makeTexture2D(), dstDesc, src->origin(), mipMapped, fit, |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 372 | budgeted, colorType, kUnknown_SkAlphaType)); |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 373 | if (!dstContext) { |
| 374 | return nullptr; |
| 375 | } |
| 376 | if (dstContext->copy(src, srcRect, dstPoint)) { |
| 377 | return dstContext->asTextureProxyRef(); |
| 378 | } |
Greg Daniel | c5167c0 | 2019-06-05 17:36:53 +0000 | [diff] [blame] | 379 | } |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 380 | if (src->asTextureProxy()) { |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 381 | sk_sp<GrRenderTargetContext> dstContext = context->priv().makeDeferredRenderTargetContext( |
Brian Salomon | 27ae52c | 2019-07-03 11:27:44 -0400 | [diff] [blame] | 382 | fit, dstDesc.fWidth, dstDesc.fHeight, colorType, nullptr, 1, mipMapped, |
| 383 | src->origin(), nullptr, budgeted); |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 384 | |
| 385 | if (dstContext && dstContext->blitTexture(src->asTextureProxy(), srcRect, dstPoint)) { |
| 386 | return dstContext->asTextureProxyRef(); |
| 387 | } |
Greg Daniel | 4c6f9b7 | 2019-06-06 13:40:59 -0400 | [diff] [blame] | 388 | } |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 389 | // Can't use backend copies or draws. |
| 390 | return nullptr; |
Robert Phillips | 63c6746 | 2017-02-15 14:19:01 -0500 | [diff] [blame] | 391 | } |
| 392 | |
Robert Phillips | d44146b | 2019-02-15 14:44:28 -0500 | [diff] [blame] | 393 | sk_sp<GrTextureProxy> GrSurfaceProxy::Copy(GrRecordingContext* context, GrSurfaceProxy* src, |
Brian Salomon | fee3f9b | 2018-12-19 12:34:12 -0500 | [diff] [blame] | 394 | GrMipMapped mipMapped, SkBackingFit fit, |
| 395 | SkBudgeted budgeted) { |
Greg Daniel | 65fa8ca | 2018-01-10 17:06:31 -0500 | [diff] [blame] | 396 | SkASSERT(LazyState::kFully != src->lazyInstantiationState()); |
Brian Salomon | fee3f9b | 2018-12-19 12:34:12 -0500 | [diff] [blame] | 397 | return Copy(context, src, mipMapped, SkIRect::MakeWH(src->width(), src->height()), fit, |
| 398 | budgeted); |
Robert Phillips | e2f7d18 | 2016-12-15 09:23:05 -0500 | [diff] [blame] | 399 | } |
| 400 | |
Robert Phillips | b520476 | 2019-06-19 14:12:13 -0400 | [diff] [blame] | 401 | #if GR_TEST_UTILS |
| 402 | int32_t GrSurfaceProxy::testingOnly_getBackingRefCnt() const { |
| 403 | if (fTarget) { |
| 404 | return fTarget->testingOnly_getRefCnt(); |
| 405 | } |
| 406 | |
| 407 | return -1; // no backing GrSurface |
| 408 | } |
| 409 | |
| 410 | GrInternalSurfaceFlags GrSurfaceProxy::testingOnly_getFlags() const { |
| 411 | return fSurfaceFlags; |
| 412 | } |
| 413 | #endif |
| 414 | |
Robert Phillips | 0ae6faa | 2017-03-21 16:22:00 -0400 | [diff] [blame] | 415 | void GrSurfaceProxyPriv::exactify() { |
Greg Daniel | 65fa8ca | 2018-01-10 17:06:31 -0500 | [diff] [blame] | 416 | SkASSERT(GrSurfaceProxy::LazyState::kFully != fProxy->lazyInstantiationState()); |
Robert Phillips | 0ae6faa | 2017-03-21 16:22:00 -0400 | [diff] [blame] | 417 | if (this->isExact()) { |
| 418 | return; |
| 419 | } |
| 420 | |
| 421 | SkASSERT(SkBackingFit::kApprox == fProxy->fFit); |
| 422 | |
| 423 | if (fProxy->fTarget) { |
| 424 | // The kApprox but already instantiated case. Setting the proxy's width & height to |
| 425 | // the instantiated width & height could have side-effects going forward, since we're |
Ben Wagner | 63fd760 | 2017-10-09 15:45:33 -0400 | [diff] [blame] | 426 | // obliterating the area of interest information. This call (exactify) only used |
Robert Phillips | 0ae6faa | 2017-03-21 16:22:00 -0400 | [diff] [blame] | 427 | // when converting an SkSpecialImage to an SkImage so the proxy shouldn't be |
| 428 | // used for additional draws. |
Brian Salomon | bb5711a | 2017-05-17 13:49:59 -0400 | [diff] [blame] | 429 | fProxy->fWidth = fProxy->fTarget->width(); |
| 430 | fProxy->fHeight = fProxy->fTarget->height(); |
Robert Phillips | 0ae6faa | 2017-03-21 16:22:00 -0400 | [diff] [blame] | 431 | return; |
| 432 | } |
| 433 | |
| 434 | // The kApprox uninstantiated case. Making this proxy be exact should be okay. |
| 435 | // It could mess things up if prior decisions were based on the approximate size. |
| 436 | fProxy->fFit = SkBackingFit::kExact; |
| 437 | // If fGpuMemorySize is used when caching specialImages for the image filter DAG. If it has |
Robert Phillips | 6cdc22c | 2017-05-11 16:29:14 -0400 | [diff] [blame] | 438 | // already been computed we want to leave it alone so that amount will be removed when |
Robert Phillips | 0ae6faa | 2017-03-21 16:22:00 -0400 | [diff] [blame] | 439 | // the special image goes away. If it hasn't been computed yet it might as well compute the |
| 440 | // exact amount. |
| 441 | } |
| 442 | |
Greg Daniel | bddcc95 | 2018-01-24 13:22:24 -0500 | [diff] [blame] | 443 | bool GrSurfaceProxyPriv::doLazyInstantiation(GrResourceProvider* resourceProvider) { |
Greg Daniel | 0a375db | 2018-02-01 12:21:39 -0500 | [diff] [blame] | 444 | SkASSERT(GrSurfaceProxy::LazyState::kNot != fProxy->lazyInstantiationState()); |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 445 | |
Robert Phillips | 0790f8a | 2018-09-18 13:11:03 -0400 | [diff] [blame] | 446 | sk_sp<GrSurface> surface; |
| 447 | if (fProxy->asTextureProxy() && fProxy->asTextureProxy()->getUniqueKey().isValid()) { |
| 448 | // First try to reattach to a cached version if the proxy is uniquely keyed |
| 449 | surface = resourceProvider->findByUniqueKey<GrSurface>( |
| 450 | fProxy->asTextureProxy()->getUniqueKey()); |
| 451 | } |
| 452 | |
Brian Salomon | b6a3a3b | 2019-04-01 12:29:34 -0400 | [diff] [blame] | 453 | bool syncKey = true; |
Robert Phillips | 0790f8a | 2018-09-18 13:11:03 -0400 | [diff] [blame] | 454 | if (!surface) { |
Brian Salomon | b6a3a3b | 2019-04-01 12:29:34 -0400 | [diff] [blame] | 455 | auto result = fProxy->fLazyInstantiateCallback(resourceProvider); |
| 456 | surface = std::move(result.fSurface); |
| 457 | syncKey = result.fKeyMode == GrSurfaceProxy::LazyInstantiationKeyMode::kSynced; |
Robert Phillips | 0790f8a | 2018-09-18 13:11:03 -0400 | [diff] [blame] | 458 | } |
Greg Daniel | 457469c | 2018-02-08 15:05:44 -0500 | [diff] [blame] | 459 | if (GrSurfaceProxy::LazyInstantiationType::kSingleUse == fProxy->fLazyInstantiationType) { |
Greg Daniel | 457469c | 2018-02-08 15:05:44 -0500 | [diff] [blame] | 460 | fProxy->fLazyInstantiateCallback = nullptr; |
| 461 | } |
Robert Phillips | e8fabb2 | 2018-02-04 14:33:21 -0500 | [diff] [blame] | 462 | if (!surface) { |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 463 | fProxy->fWidth = 0; |
| 464 | fProxy->fHeight = 0; |
Greg Daniel | bddcc95 | 2018-01-24 13:22:24 -0500 | [diff] [blame] | 465 | return false; |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 466 | } |
| 467 | |
Robert Phillips | c1b6066 | 2018-06-26 10:20:08 -0400 | [diff] [blame] | 468 | if (fProxy->fWidth <= 0 || fProxy->fHeight <= 0) { |
| 469 | // This was a fully lazy proxy. We need to fill in the width & height. For partially |
| 470 | // lazy proxies we must preserve the original width & height since that indicates |
| 471 | // the content area. |
| 472 | SkASSERT(fProxy->fWidth <= 0 && fProxy->fHeight <= 0); |
| 473 | fProxy->fWidth = surface->width(); |
| 474 | fProxy->fHeight = surface->height(); |
| 475 | } |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 476 | |
Chris Dalton | f91b755 | 2019-04-29 16:21:18 -0600 | [diff] [blame] | 477 | SkASSERT(fProxy->fWidth <= surface->width()); |
| 478 | SkASSERT(fProxy->fHeight <= surface->height()); |
| 479 | |
Chris Dalton | effee20 | 2019-07-01 22:28:03 -0600 | [diff] [blame] | 480 | int minStencilSampleCount = (fProxy->asRenderTargetProxy()) |
| 481 | ? fProxy->asRenderTargetProxy()->numSamples() |
| 482 | : 0; |
Robert Phillips | c7c2baf | 2018-03-08 09:51:04 -0500 | [diff] [blame] | 483 | |
Chris Dalton | effee20 | 2019-07-01 22:28:03 -0600 | [diff] [blame] | 484 | if (!GrSurfaceProxyPriv::AttachStencilIfNeeded( |
| 485 | resourceProvider, surface.get(), minStencilSampleCount)) { |
Robert Phillips | 01a9128 | 2018-07-26 08:03:04 -0400 | [diff] [blame] | 486 | return false; |
| 487 | } |
Robert Phillips | c7c2baf | 2018-03-08 09:51:04 -0500 | [diff] [blame] | 488 | |
Greg Daniel | 303e83e | 2018-09-10 14:10:19 -0400 | [diff] [blame] | 489 | if (GrTextureProxy* texProxy = fProxy->asTextureProxy()) { |
Brian Salomon | b6a3a3b | 2019-04-01 12:29:34 -0400 | [diff] [blame] | 490 | texProxy->setTargetKeySync(syncKey); |
| 491 | if (syncKey) { |
| 492 | const GrUniqueKey& key = texProxy->getUniqueKey(); |
| 493 | if (key.isValid()) { |
| 494 | if (!surface->asTexture()->getUniqueKey().isValid()) { |
| 495 | // If 'surface' is newly created, attach the unique key |
| 496 | resourceProvider->assignUniqueKeyToResource(key, surface.get()); |
| 497 | } else { |
| 498 | // otherwise we had better have reattached to a cached version |
| 499 | SkASSERT(surface->asTexture()->getUniqueKey() == key); |
| 500 | } |
Robert Phillips | 0790f8a | 2018-09-18 13:11:03 -0400 | [diff] [blame] | 501 | } else { |
Brian Salomon | b6a3a3b | 2019-04-01 12:29:34 -0400 | [diff] [blame] | 502 | SkASSERT(!surface->getUniqueKey().isValid()); |
Robert Phillips | 0790f8a | 2018-09-18 13:11:03 -0400 | [diff] [blame] | 503 | } |
Greg Daniel | 303e83e | 2018-09-10 14:10:19 -0400 | [diff] [blame] | 504 | } |
| 505 | } |
| 506 | |
Robert Phillips | e8fabb2 | 2018-02-04 14:33:21 -0500 | [diff] [blame] | 507 | this->assign(std::move(surface)); |
Greg Daniel | bddcc95 | 2018-01-24 13:22:24 -0500 | [diff] [blame] | 508 | return true; |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 509 | } |
| 510 | |
Greg Daniel | 849dce1 | 2018-04-24 14:32:53 -0400 | [diff] [blame] | 511 | #ifdef SK_DEBUG |
| 512 | void GrSurfaceProxy::validateSurface(const GrSurface* surface) { |
| 513 | SkASSERT(surface->config() == fConfig); |
| 514 | |
Greg Daniel | 849dce1 | 2018-04-24 14:32:53 -0400 | [diff] [blame] | 515 | this->onValidateSurface(surface); |
| 516 | } |
| 517 | #endif |