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