blob: b8132e8a89d01840e4ef6c3182a3b1db72f774ec [file] [log] [blame]
robertphillips76948d42016-05-04 12:47:41 -07001/*
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 "GrSurfaceProxy.h"
Robert Phillipsb726d582017-03-09 16:36:32 -05009#include "GrSurfaceProxyPriv.h"
robertphillips76948d42016-05-04 12:47:41 -070010
Robert Phillips784b7bf2016-12-09 13:35:02 -050011#include "GrCaps.h"
Robert Phillipse2f7d182016-12-15 09:23:05 -050012#include "GrContext.h"
13#include "GrContextPriv.h"
Robert Phillipsc7635fa2016-10-28 13:25:24 -040014#include "GrGpuResourcePriv.h"
Robert Phillipsf2361d22016-10-25 14:20:06 -040015#include "GrOpList.h"
Robert Phillips1afd4cd2018-01-08 13:40:32 -050016#include "GrProxyProvider.h"
Robert Phillipse2f7d182016-12-15 09:23:05 -050017#include "GrSurfaceContext.h"
Robert Phillipsa4c41b32017-03-15 13:02:45 -040018#include "GrTexturePriv.h"
Robert Phillips37430132016-11-09 06:50:43 -050019#include "GrTextureRenderTargetProxy.h"
Robert Phillipsf2361d22016-10-25 14:20:06 -040020
Robert Phillips93f16332016-11-23 19:37:13 -050021#include "SkMathPriv.h"
Greg Daniele1da1d92017-10-06 15:59:27 -040022#include "SkMipMap.h"
Robert Phillips93f16332016-11-23 19:37:13 -050023
Greg Daniel65fa8ca2018-01-10 17:06:31 -050024#ifdef SK_DEBUG
25static bool is_valid_fully_lazy(const GrSurfaceDesc& desc, SkBackingFit fit) {
26 return desc.fWidth <= 0 &&
27 desc.fHeight <= 0 &&
28 desc.fConfig != kUnknown_GrPixelConfig &&
Brian Salomonbdecacf2018-02-02 20:32:49 -050029 desc.fSampleCnt == 1 &&
Greg Daniel65fa8ca2018-01-10 17:06:31 -050030 SkBackingFit::kApprox == fit;
31}
32
33static bool is_valid_partially_lazy(const GrSurfaceDesc& desc) {
34 return ((desc.fWidth > 0 && desc.fHeight > 0) ||
35 (desc.fWidth <= 0 && desc.fHeight <= 0)) &&
36 desc.fConfig != kUnknown_GrPixelConfig;
37}
38
39static bool is_valid_non_lazy(const GrSurfaceDesc& desc) {
40 return desc.fWidth > 0 &&
41 desc.fHeight > 0 &&
42 desc.fConfig != kUnknown_GrPixelConfig;
43}
44#endif
45
Chris Dalton706a6ff2017-11-29 22:01:06 -070046// Lazy-callback version
Greg Daniel457469c2018-02-08 15:05:44 -050047GrSurfaceProxy::GrSurfaceProxy(LazyInstantiateCallback&& callback, LazyInstantiationType lazyType,
Brian Salomon2a4f9832018-03-03 22:43:43 -050048 const GrSurfaceDesc& desc, GrSurfaceOrigin origin, SkBackingFit fit,
49 SkBudgeted budgeted, uint32_t flags)
Greg Daniel65fa8ca2018-01-10 17:06:31 -050050 : fConfig(desc.fConfig)
51 , fWidth(desc.fWidth)
52 , fHeight(desc.fHeight)
Brian Salomon2a4f9832018-03-03 22:43:43 -050053 , fOrigin(origin)
Greg Daniel65fa8ca2018-01-10 17:06:31 -050054 , fFit(fit)
55 , fBudgeted(budgeted)
56 , fFlags(flags)
Chris Dalton706a6ff2017-11-29 22:01:06 -070057 , fLazyInstantiateCallback(std::move(callback))
Greg Daniel457469c2018-02-08 15:05:44 -050058 , fLazyInstantiationType(lazyType)
Greg Daniel65fa8ca2018-01-10 17:06:31 -050059 , fNeedsClear(SkToBool(desc.fFlags & kPerformInitialClear_GrSurfaceFlag))
Chris Dalton706a6ff2017-11-29 22:01:06 -070060 , fGpuMemorySize(kInvalidGpuMemorySize)
61 , fLastOpList(nullptr) {
62 // NOTE: the default fUniqueID ctor pulls a value from the same pool as the GrGpuResources.
Greg Daniel65fa8ca2018-01-10 17:06:31 -050063 if (fLazyInstantiateCallback) {
64 SkASSERT(is_valid_fully_lazy(desc, fit) || is_valid_partially_lazy(desc));
65 } else {
66 SkASSERT(is_valid_non_lazy(desc));
67 }
Chris Dalton706a6ff2017-11-29 22:01:06 -070068}
69
70// Wrapped version
Robert Phillips066f0202017-07-25 10:16:35 -040071GrSurfaceProxy::GrSurfaceProxy(sk_sp<GrSurface> surface, GrSurfaceOrigin origin, SkBackingFit fit)
Brian Salomonbb5711a2017-05-17 13:49:59 -040072 : INHERITED(std::move(surface))
73 , fConfig(fTarget->config())
74 , fWidth(fTarget->width())
75 , fHeight(fTarget->height())
Robert Phillips066f0202017-07-25 10:16:35 -040076 , fOrigin(origin)
Brian Salomonbb5711a2017-05-17 13:49:59 -040077 , fFit(fit)
78 , fBudgeted(fTarget->resourcePriv().isBudgeted())
79 , fFlags(0)
80 , fUniqueID(fTarget->uniqueID()) // Note: converting from unique resource ID to a proxy ID!
Brian Salomond17b4a62017-05-23 16:53:47 -040081 , fNeedsClear(false)
Brian Salomonbb5711a2017-05-17 13:49:59 -040082 , fGpuMemorySize(kInvalidGpuMemorySize)
Robert Phillips019ff272017-07-24 14:47:57 -040083 , fLastOpList(nullptr) {
Robert Phillips019ff272017-07-24 14:47:57 -040084}
Robert Phillipsc7635fa2016-10-28 13:25:24 -040085
Robert Phillipsf2361d22016-10-25 14:20:06 -040086GrSurfaceProxy::~GrSurfaceProxy() {
Greg Daniel94a6ce82018-01-16 16:14:41 -050087 if (fLazyInstantiateCallback) {
Greg Daniel0a375db2018-02-01 12:21:39 -050088 // We call the callback with a null GrResourceProvider to signal that the lambda should
89 // clean itself up if it is holding onto any captured objects.
Robert Phillipsce5209a2018-02-13 11:13:51 -050090 this->fLazyInstantiateCallback(nullptr);
Greg Daniel94a6ce82018-01-16 16:14:41 -050091 }
Robert Phillips6cdc22c2017-05-11 16:29:14 -040092 // For this to be deleted the opList that held a ref on it (if there was one) must have been
93 // deleted. Which would have cleared out this back pointer.
94 SkASSERT(!fLastOpList);
Robert Phillipsf2361d22016-10-25 14:20:06 -040095}
96
Robert Phillipseafd48a2017-11-16 07:52:08 -050097bool GrSurfaceProxyPriv::AttachStencilIfNeeded(GrResourceProvider* resourceProvider,
98 GrSurface* surface, bool needsStencil) {
Robert Phillips65048132017-08-10 08:44:49 -040099 if (needsStencil) {
100 GrRenderTarget* rt = surface->asRenderTarget();
101 if (!rt) {
102 SkASSERT(0);
103 return false;
104 }
105
106 if (!resourceProvider->attachStencilAttachment(rt)) {
107 return false;
108 }
109 }
110
111 return true;
112}
113
Robert Phillips5af44de2017-07-18 14:49:38 -0400114sk_sp<GrSurface> GrSurfaceProxy::createSurfaceImpl(
Robert Phillips65048132017-08-10 08:44:49 -0400115 GrResourceProvider* resourceProvider,
116 int sampleCnt, bool needsStencil,
Greg Danield2d8e922018-02-12 12:07:39 -0500117 GrSurfaceFlags flags, GrMipMapped mipMapped) const {
Greg Daniel65fa8ca2018-01-10 17:06:31 -0500118 SkASSERT(GrSurfaceProxy::LazyState::kNot == this->lazyInstantiationState());
Greg Danield2d8e922018-02-12 12:07:39 -0500119 SkASSERT(!fTarget);
Brian Salomonbb5711a2017-05-17 13:49:59 -0400120 GrSurfaceDesc desc;
Brian Salomonbb5711a2017-05-17 13:49:59 -0400121 desc.fFlags = flags;
Brian Salomond17b4a62017-05-23 16:53:47 -0400122 if (fNeedsClear) {
123 desc.fFlags |= kPerformInitialClear_GrSurfaceFlag;
124 }
Robert Phillips16d8ec62017-07-27 16:16:25 -0400125 desc.fWidth = fWidth;
126 desc.fHeight = fHeight;
127 desc.fConfig = fConfig;
128 desc.fSampleCnt = sampleCnt;
Robert Phillipseaa86252016-11-08 13:49:39 +0000129
Robert Phillips5af44de2017-07-18 14:49:38 -0400130 sk_sp<GrSurface> surface;
Greg Danielf6f7b672018-02-15 13:06:26 -0500131 if (GrMipMapped::kYes == mipMapped) {
132 SkASSERT(SkBackingFit::kExact == fFit);
133
134 // SkMipMap doesn't include the base level in the level count so we have to add 1
135 int mipCount = SkMipMap::ComputeLevelCount(desc.fWidth, desc.fHeight) + 1;
136 // We should have caught the case where mipCount == 1 when making the proxy and instead
137 // created a non-mipmapped proxy.
138 SkASSERT(mipCount > 1);
139 std::unique_ptr<GrMipLevel[]> texels(new GrMipLevel[mipCount]);
140
141 // We don't want to upload any texel data
142 for (int i = 0; i < mipCount; i++) {
143 texels[i].fPixels = nullptr;
144 texels[i].fRowBytes = 0;
145 }
146
Brian Salomon2a4f9832018-03-03 22:43:43 -0500147 surface = resourceProvider->createTexture(desc, fBudgeted, fOrigin, texels.get(), mipCount,
Greg Danielf6f7b672018-02-15 13:06:26 -0500148 SkDestinationSurfaceColorMode::kLegacy);
149 if (surface) {
150 SkASSERT(surface->asTexture());
151 SkASSERT(GrMipMapped::kYes == surface->asTexture()->texturePriv().mipMapped());
152 }
Robert Phillipseaa86252016-11-08 13:49:39 +0000153 } else {
Greg Danielf6f7b672018-02-15 13:06:26 -0500154 if (SkBackingFit::kApprox == fFit) {
155 surface = resourceProvider->createApproxTexture(desc, fFlags);
156 } else {
157 surface = resourceProvider->createTexture(desc, fBudgeted, fFlags);
158 }
Robert Phillipseaa86252016-11-08 13:49:39 +0000159 }
Robert Phillips65048132017-08-10 08:44:49 -0400160 if (!surface) {
161 return nullptr;
162 }
163
Robert Phillipseafd48a2017-11-16 07:52:08 -0500164 if (!GrSurfaceProxyPriv::AttachStencilIfNeeded(resourceProvider, surface.get(), needsStencil)) {
Robert Phillips65048132017-08-10 08:44:49 -0400165 return nullptr;
Robert Phillipseaa86252016-11-08 13:49:39 +0000166 }
167
Robert Phillips5af44de2017-07-18 14:49:38 -0400168 return surface;
169}
170
171void GrSurfaceProxy::assign(sk_sp<GrSurface> surface) {
172 SkASSERT(!fTarget && surface);
173 fTarget = surface.release();
robertphillips1125a032016-11-16 11:17:17 -0800174 this->INHERITED::transferRefs();
175
Robert Phillipseaa86252016-11-08 13:49:39 +0000176#ifdef SK_DEBUG
177 if (kInvalidGpuMemorySize != this->getRawGpuMemorySize_debugOnly()) {
Robert Phillips784b7bf2016-12-09 13:35:02 -0500178 SkASSERT(fTarget->gpuMemorySize() <= this->getRawGpuMemorySize_debugOnly());
Robert Phillipseaa86252016-11-08 13:49:39 +0000179 }
180#endif
Robert Phillips5af44de2017-07-18 14:49:38 -0400181}
Robert Phillipseaa86252016-11-08 13:49:39 +0000182
Robert Phillips5af44de2017-07-18 14:49:38 -0400183bool GrSurfaceProxy::instantiateImpl(GrResourceProvider* resourceProvider, int sampleCnt,
Greg Daniele252f082017-10-23 16:05:23 -0400184 bool needsStencil, GrSurfaceFlags flags, GrMipMapped mipMapped,
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400185 const GrUniqueKey* uniqueKey) {
Greg Daniel65fa8ca2018-01-10 17:06:31 -0500186 SkASSERT(LazyState::kNot == this->lazyInstantiationState());
Robert Phillips5af44de2017-07-18 14:49:38 -0400187 if (fTarget) {
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400188 if (uniqueKey) {
189 SkASSERT(fTarget->getUniqueKey() == *uniqueKey);
190 }
Robert Phillipseafd48a2017-11-16 07:52:08 -0500191 return GrSurfaceProxyPriv::AttachStencilIfNeeded(resourceProvider, fTarget, needsStencil);
Robert Phillips5af44de2017-07-18 14:49:38 -0400192 }
193
Robert Phillips65048132017-08-10 08:44:49 -0400194 sk_sp<GrSurface> surface = this->createSurfaceImpl(resourceProvider, sampleCnt, needsStencil,
Greg Danield2d8e922018-02-12 12:07:39 -0500195 flags, mipMapped);
Robert Phillips5af44de2017-07-18 14:49:38 -0400196 if (!surface) {
197 return false;
198 }
199
Brian Osman28c434b2017-09-27 13:11:16 -0400200 // If there was an invalidation message pending for this key, we might have just processed it,
201 // causing the key (stored on this proxy) to become invalid.
202 if (uniqueKey && uniqueKey->isValid()) {
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400203 resourceProvider->assignUniqueKeyToResource(*uniqueKey, surface.get());
204 }
205
Robert Phillips5af44de2017-07-18 14:49:38 -0400206 this->assign(std::move(surface));
Robert Phillipseee4d6e2017-06-05 09:26:07 -0400207 return true;
Robert Phillipseaa86252016-11-08 13:49:39 +0000208}
209
Robert Phillips4bc70112018-03-01 10:24:02 -0500210void GrSurfaceProxy::deInstantiate() {
211 SkASSERT(this->priv().isInstantiated());
212
213 this->release();
214}
215
216
Robert Phillips57aa3672017-07-21 11:38:13 -0400217void GrSurfaceProxy::computeScratchKey(GrScratchKey* key) const {
Greg Daniel65fa8ca2018-01-10 17:06:31 -0500218 SkASSERT(LazyState::kFully != this->lazyInstantiationState());
Robert Phillips57aa3672017-07-21 11:38:13 -0400219 const GrRenderTargetProxy* rtp = this->asRenderTargetProxy();
Brian Salomonbdecacf2018-02-02 20:32:49 -0500220 int sampleCount = 1;
Robert Phillips57aa3672017-07-21 11:38:13 -0400221 if (rtp) {
222 sampleCount = rtp->numStencilSamples();
223 }
224
225 const GrTextureProxy* tp = this->asTextureProxy();
Greg Daniele252f082017-10-23 16:05:23 -0400226 GrMipMapped mipMapped = GrMipMapped::kNo;
Robert Phillips57aa3672017-07-21 11:38:13 -0400227 if (tp) {
Greg Daniele252f082017-10-23 16:05:23 -0400228 mipMapped = tp->mipMapped();
Robert Phillips57aa3672017-07-21 11:38:13 -0400229 }
230
Robert Phillipsa108c922017-10-10 10:42:19 -0400231 int width = this->worstCaseWidth();
232 int height = this->worstCaseHeight();
Robert Phillips57aa3672017-07-21 11:38:13 -0400233
Robert Phillipsb0e93a22017-08-29 08:26:54 -0400234 GrTexturePriv::ComputeScratchKey(this->config(), width, height, SkToBool(rtp), sampleCount,
Greg Daniele252f082017-10-23 16:05:23 -0400235 mipMapped, key);
Robert Phillips57aa3672017-07-21 11:38:13 -0400236}
237
Robert Phillipsf2361d22016-10-25 14:20:06 -0400238void GrSurfaceProxy::setLastOpList(GrOpList* opList) {
Robert Phillips6cdc22c2017-05-11 16:29:14 -0400239#ifdef SK_DEBUG
Robert Phillipsf2361d22016-10-25 14:20:06 -0400240 if (fLastOpList) {
Robert Phillipsf2361d22016-10-25 14:20:06 -0400241 SkASSERT(fLastOpList->isClosed());
Robert Phillips4a395042017-04-24 16:27:17 +0000242 }
Robert Phillips6cdc22c2017-05-11 16:29:14 -0400243#endif
Robert Phillipsf2361d22016-10-25 14:20:06 -0400244
Robert Phillips6cdc22c2017-05-11 16:29:14 -0400245 // Un-reffed
246 fLastOpList = opList;
Robert Phillipsf2361d22016-10-25 14:20:06 -0400247}
Robert Phillips37430132016-11-09 06:50:43 -0500248
Brian Osman45580d32016-11-23 09:37:01 -0500249GrRenderTargetOpList* GrSurfaceProxy::getLastRenderTargetOpList() {
250 return fLastOpList ? fLastOpList->asRenderTargetOpList() : nullptr;
251}
252
253GrTextureOpList* GrSurfaceProxy::getLastTextureOpList() {
254 return fLastOpList ? fLastOpList->asTextureOpList() : nullptr;
255}
256
Robert Phillipsa108c922017-10-10 10:42:19 -0400257int GrSurfaceProxy::worstCaseWidth() const {
Greg Daniel65fa8ca2018-01-10 17:06:31 -0500258 SkASSERT(LazyState::kFully != this->lazyInstantiationState());
Robert Phillipsa108c922017-10-10 10:42:19 -0400259 if (fTarget) {
260 return fTarget->width();
261 }
262
263 if (SkBackingFit::kExact == fFit) {
264 return fWidth;
265 }
266 return SkTMax(GrResourceProvider::kMinScratchTextureSize, GrNextPow2(fWidth));
267}
268
269int GrSurfaceProxy::worstCaseHeight() const {
Greg Daniel65fa8ca2018-01-10 17:06:31 -0500270 SkASSERT(LazyState::kFully != this->lazyInstantiationState());
Robert Phillipsa108c922017-10-10 10:42:19 -0400271 if (fTarget) {
272 return fTarget->height();
273 }
274
275 if (SkBackingFit::kExact == fFit) {
276 return fHeight;
277 }
278 return SkTMax(GrResourceProvider::kMinScratchTextureSize, GrNextPow2(fHeight));
279}
280
Brian Osman45580d32016-11-23 09:37:01 -0500281#ifdef SK_DEBUG
282void GrSurfaceProxy::validate(GrContext* context) const {
283 if (fTarget) {
284 SkASSERT(fTarget->getContext() == context);
285 }
286
287 INHERITED::validate();
288}
289#endif
Robert Phillipse2f7d182016-12-15 09:23:05 -0500290
Robert Phillips63c67462017-02-15 14:19:01 -0500291sk_sp<GrTextureProxy> GrSurfaceProxy::Copy(GrContext* context,
Robert Phillipse2f7d182016-12-15 09:23:05 -0500292 GrSurfaceProxy* src,
Greg Daniel65c7f662017-10-30 13:39:09 -0400293 GrMipMapped mipMapped,
Robert Phillipse2f7d182016-12-15 09:23:05 -0500294 SkIRect srcRect,
295 SkBudgeted budgeted) {
Greg Daniel65fa8ca2018-01-10 17:06:31 -0500296 SkASSERT(LazyState::kFully != src->lazyInstantiationState());
Robert Phillipse2f7d182016-12-15 09:23:05 -0500297 if (!srcRect.intersect(SkIRect::MakeWH(src->width(), src->height()))) {
298 return nullptr;
299 }
300
Brian Salomon63e79732017-05-15 21:23:13 -0400301 GrSurfaceDesc dstDesc;
Robert Phillipse2f7d182016-12-15 09:23:05 -0500302 dstDesc.fWidth = srcRect.width();
303 dstDesc.fHeight = srcRect.height();
Robert Phillips16d8ec62017-07-27 16:16:25 -0400304 dstDesc.fConfig = src->config();
Robert Phillipse2f7d182016-12-15 09:23:05 -0500305
Brian Salomon366093f2018-02-13 09:25:22 -0500306 // We use an ephemeral surface context to make the copy. Here it isn't clear what color space
307 // to tag it with. That's ok because GrSurfaceContext::copy doesn't do any color space
308 // conversions. However, if the pixel config is sRGB then the passed color space here must
309 // have sRGB gamma or GrSurfaceContext creation fails. See skbug.com/7611 about making this
310 // with the correct color space information and returning the context to the caller.
311 sk_sp<SkColorSpace> colorSpace;
312 if (GrPixelConfigIsSRGB(dstDesc.fConfig)) {
313 colorSpace = SkColorSpace::MakeSRGB();
314 }
Robert Phillipse2f7d182016-12-15 09:23:05 -0500315 sk_sp<GrSurfaceContext> dstContext(context->contextPriv().makeDeferredSurfaceContext(
Brian Salomon2a4f9832018-03-03 22:43:43 -0500316 dstDesc, src->origin(), mipMapped, SkBackingFit::kExact, budgeted,
317 std::move(colorSpace)));
Robert Phillipse2f7d182016-12-15 09:23:05 -0500318 if (!dstContext) {
319 return nullptr;
320 }
321
322 if (!dstContext->copy(src, srcRect, SkIPoint::Make(0, 0))) {
323 return nullptr;
324 }
325
Robert Phillips63c67462017-02-15 14:19:01 -0500326 return dstContext->asTextureProxyRef();
327}
328
329sk_sp<GrTextureProxy> GrSurfaceProxy::Copy(GrContext* context, GrSurfaceProxy* src,
Greg Daniel65c7f662017-10-30 13:39:09 -0400330 GrMipMapped mipMapped, SkBudgeted budgeted) {
Greg Daniel65fa8ca2018-01-10 17:06:31 -0500331 SkASSERT(LazyState::kFully != src->lazyInstantiationState());
Greg Daniel65c7f662017-10-30 13:39:09 -0400332 return Copy(context, src, mipMapped, SkIRect::MakeWH(src->width(), src->height()), budgeted);
Robert Phillipse2f7d182016-12-15 09:23:05 -0500333}
334
Robert Phillipsd46697a2017-01-25 12:10:37 -0500335sk_sp<GrSurfaceContext> GrSurfaceProxy::TestCopy(GrContext* context, const GrSurfaceDesc& dstDesc,
Brian Salomon2a4f9832018-03-03 22:43:43 -0500336 GrSurfaceOrigin origin, GrSurfaceProxy* srcProxy) {
Greg Daniel65fa8ca2018-01-10 17:06:31 -0500337 SkASSERT(LazyState::kFully != srcProxy->lazyInstantiationState());
Robert Phillipse2f7d182016-12-15 09:23:05 -0500338 sk_sp<GrSurfaceContext> dstContext(context->contextPriv().makeDeferredSurfaceContext(
Brian Salomon2a4f9832018-03-03 22:43:43 -0500339 dstDesc, origin, GrMipMapped::kNo, SkBackingFit::kExact, SkBudgeted::kYes));
Robert Phillipse2f7d182016-12-15 09:23:05 -0500340 if (!dstContext) {
341 return nullptr;
342 }
343
Robert Phillipsd46697a2017-01-25 12:10:37 -0500344 if (!dstContext->copy(srcProxy)) {
Robert Phillipse2f7d182016-12-15 09:23:05 -0500345 return nullptr;
346 }
347
Robert Phillipsd46697a2017-01-25 12:10:37 -0500348 return dstContext;
Robert Phillipse2f7d182016-12-15 09:23:05 -0500349}
Robert Phillipsb726d582017-03-09 16:36:32 -0500350
Robert Phillips0ae6faa2017-03-21 16:22:00 -0400351void GrSurfaceProxyPriv::exactify() {
Greg Daniel65fa8ca2018-01-10 17:06:31 -0500352 SkASSERT(GrSurfaceProxy::LazyState::kFully != fProxy->lazyInstantiationState());
Robert Phillips0ae6faa2017-03-21 16:22:00 -0400353 if (this->isExact()) {
354 return;
355 }
356
357 SkASSERT(SkBackingFit::kApprox == fProxy->fFit);
358
359 if (fProxy->fTarget) {
360 // The kApprox but already instantiated case. Setting the proxy's width & height to
361 // the instantiated width & height could have side-effects going forward, since we're
Ben Wagner63fd7602017-10-09 15:45:33 -0400362 // obliterating the area of interest information. This call (exactify) only used
Robert Phillips0ae6faa2017-03-21 16:22:00 -0400363 // when converting an SkSpecialImage to an SkImage so the proxy shouldn't be
364 // used for additional draws.
Brian Salomonbb5711a2017-05-17 13:49:59 -0400365 fProxy->fWidth = fProxy->fTarget->width();
366 fProxy->fHeight = fProxy->fTarget->height();
Robert Phillips0ae6faa2017-03-21 16:22:00 -0400367 return;
368 }
369
370 // The kApprox uninstantiated case. Making this proxy be exact should be okay.
371 // It could mess things up if prior decisions were based on the approximate size.
372 fProxy->fFit = SkBackingFit::kExact;
373 // If fGpuMemorySize is used when caching specialImages for the image filter DAG. If it has
Robert Phillips6cdc22c2017-05-11 16:29:14 -0400374 // already been computed we want to leave it alone so that amount will be removed when
Robert Phillips0ae6faa2017-03-21 16:22:00 -0400375 // the special image goes away. If it hasn't been computed yet it might as well compute the
376 // exact amount.
377}
378
Greg Danielbddcc952018-01-24 13:22:24 -0500379bool GrSurfaceProxyPriv::doLazyInstantiation(GrResourceProvider* resourceProvider) {
Greg Daniel0a375db2018-02-01 12:21:39 -0500380 SkASSERT(GrSurfaceProxy::LazyState::kNot != fProxy->lazyInstantiationState());
Chris Dalton706a6ff2017-11-29 22:01:06 -0700381
Robert Phillipsce5209a2018-02-13 11:13:51 -0500382 sk_sp<GrSurface> surface = fProxy->fLazyInstantiateCallback(resourceProvider);
Greg Daniel457469c2018-02-08 15:05:44 -0500383 if (GrSurfaceProxy::LazyInstantiationType::kSingleUse == fProxy->fLazyInstantiationType) {
Robert Phillipsce5209a2018-02-13 11:13:51 -0500384 fProxy->fLazyInstantiateCallback(nullptr);
Greg Daniel457469c2018-02-08 15:05:44 -0500385 fProxy->fLazyInstantiateCallback = nullptr;
386 }
Robert Phillipse8fabb22018-02-04 14:33:21 -0500387 if (!surface) {
Chris Dalton706a6ff2017-11-29 22:01:06 -0700388 fProxy->fWidth = 0;
389 fProxy->fHeight = 0;
Greg Danielbddcc952018-01-24 13:22:24 -0500390 return false;
Chris Dalton706a6ff2017-11-29 22:01:06 -0700391 }
392
Robert Phillipse8fabb22018-02-04 14:33:21 -0500393 fProxy->fWidth = surface->width();
394 fProxy->fHeight = surface->height();
Chris Dalton706a6ff2017-11-29 22:01:06 -0700395
Robert Phillipse8fabb22018-02-04 14:33:21 -0500396 SkASSERT(surface->config() == fProxy->fConfig);
397 SkDEBUGCODE(fProxy->validateLazySurface(surface.get());)
398 this->assign(std::move(surface));
Greg Danielbddcc952018-01-24 13:22:24 -0500399 return true;
Chris Dalton706a6ff2017-11-29 22:01:06 -0700400}
401