blob: d8359574cbc9e50594794a9e13753093dad04a0e [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#ifndef GrSurfaceProxy_DEFINED
9#define GrSurfaceProxy_DEFINED
10
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "include/core/SkRect.h"
12#include "include/gpu/GrBackendSurface.h"
13#include "include/gpu/GrGpuResource.h"
14#include "include/gpu/GrSurface.h"
15#include "include/gpu/GrTexture.h"
16#include "include/private/SkNoncopyable.h"
Brian Salomona036f0d2019-08-29 11:16:04 -040017#include "src/gpu/GrNonAtomicRef.h"
Greg Daniel2c19e7f2019-06-18 13:29:21 -040018#include "src/gpu/GrSwizzle.h"
robertphillips76948d42016-05-04 12:47:41 -070019
Robert Phillips37430132016-11-09 06:50:43 -050020class GrCaps;
Robert Phillips292a6b22019-02-14 14:49:02 -050021class GrContext_Base;
Greg Danielf41b2bd2019-08-22 16:19:24 -040022class GrOpsTask;
Robert Phillipsd44146b2019-02-15 14:44:28 -050023class GrRecordingContext;
Brian Osman45580d32016-11-23 09:37:01 -050024class GrRenderTargetProxy;
Chris Dalton6b498102019-08-01 14:14:52 -060025class GrRenderTask;
Brian Osman32342f02017-03-04 08:12:46 -050026class GrResourceProvider;
Robert Phillipsd46697a2017-01-25 12:10:37 -050027class GrSurfaceContext;
Robert Phillips757914d2017-01-25 15:48:30 -050028class GrSurfaceProxyPriv;
robertphillips76948d42016-05-04 12:47:41 -070029class GrTextureProxy;
robertphillips76948d42016-05-04 12:47:41 -070030
Brian Salomon557e8122019-10-24 10:37:08 -040031class GrSurfaceProxy : public SkNVRefCnt<GrSurfaceProxy> {
Robert Phillipsc7635fa2016-10-28 13:25:24 -040032public:
Brian Salomona036f0d2019-08-29 11:16:04 -040033 virtual ~GrSurfaceProxy();
Robert Phillipsb5204762019-06-19 14:12:13 -040034
Brian Salomonb6a3a3b2019-04-01 12:29:34 -040035 /**
Chris Dalton4ece96d2019-08-30 11:26:39 -060036 * Indicates "resolutions" that need to be done on a surface before its pixels can be accessed.
37 * If both types of resolve are requested, the MSAA resolve will happen first.
38 */
39 enum class ResolveFlags {
40 kNone = 0,
41 kMSAA = 1 << 0, // Blit and resolve an internal MSAA render buffer into the texture.
42 kMipMaps = 1 << 1, // Regenerate all mipmap levels.
43 };
44
45 /**
Brian Salomonb6a3a3b2019-04-01 12:29:34 -040046 * Some lazy proxy callbacks want to set their own (or no key) on the GrSurfaces they return.
47 * Others want the GrSurface's key to be kept in sync with the proxy's key. This enum controls
48 * the key relationship between proxies and their targets.
49 */
50 enum class LazyInstantiationKeyMode {
51 /**
52 * Don't key the GrSurface with the proxy's key. The lazy instantiation callback is free to
53 * return a GrSurface that already has a unique key unrelated to the proxy's key.
54 */
55 kUnsynced,
56 /**
57 * Keep the GrSurface's unique key in sync with the proxy's unique key. The GrSurface
58 * returned from the lazy instantiation callback must not have a unique key or have the same
59 * same unique key as the proxy. If the proxy is later assigned a key it is in turn assigned
60 * to the GrSurface.
61 */
62 kSynced
63 };
64
Brian Salomonbeb7f522019-08-30 16:19:42 -040065 struct LazyCallbackResult {
66 LazyCallbackResult() = default;
67 LazyCallbackResult(const LazyCallbackResult&) = default;
68 LazyCallbackResult(LazyCallbackResult&& that) = default;
69 LazyCallbackResult(sk_sp<GrSurface> surf,
70 bool releaseCallback = true,
71 LazyInstantiationKeyMode mode = LazyInstantiationKeyMode::kSynced)
72 : fSurface(std::move(surf)), fKeyMode(mode), fReleaseCallback(releaseCallback) {}
73 LazyCallbackResult(sk_sp<GrTexture> tex)
74 : LazyCallbackResult(sk_sp<GrSurface>(std::move(tex))) {}
Brian Salomonb6a3a3b2019-04-01 12:29:34 -040075
Brian Salomonbeb7f522019-08-30 16:19:42 -040076 LazyCallbackResult& operator=(const LazyCallbackResult&) = default;
77 LazyCallbackResult& operator=(LazyCallbackResult&&) = default;
Brian Salomonb6a3a3b2019-04-01 12:29:34 -040078
79 sk_sp<GrSurface> fSurface;
80 LazyInstantiationKeyMode fKeyMode = LazyInstantiationKeyMode::kSynced;
Brian Salomonbeb7f522019-08-30 16:19:42 -040081 /**
82 * Should the callback be disposed of after it has returned or preserved until the proxy
83 * is freed. Only honored if fSurface is not-null. If it is null the callback is preserved.
84 */
85 bool fReleaseCallback = true;
Brian Salomonb6a3a3b2019-04-01 12:29:34 -040086 };
87
Brian Salomonbeb7f522019-08-30 16:19:42 -040088 using LazyInstantiateCallback = std::function<LazyCallbackResult(GrResourceProvider*)>;
Brian Salomonb6a3a3b2019-04-01 12:29:34 -040089
Brian Salomonbeb7f522019-08-30 16:19:42 -040090 enum class UseAllocator {
91 /**
92 * This proxy will be instantiated outside the allocator (e.g. for proxies that are
93 * instantiated in on-flush callbacks).
94 */
95 kNo = false,
96 /**
97 * GrResourceAllocator should instantiate this proxy.
98 */
99 kYes = true,
Greg Daniel457469c2018-02-08 15:05:44 -0500100 };
101
Brian Salomonbeb7f522019-08-30 16:19:42 -0400102 bool isLazy() const { return !this->isInstantiated() && SkToBool(fLazyInstantiateCallback); }
Greg Daniel65fa8ca2018-01-10 17:06:31 -0500103
Brian Salomonbeb7f522019-08-30 16:19:42 -0400104 bool isFullyLazy() const {
Brian Salomon9f2b86c2019-10-22 10:37:46 -0400105 bool result = fDimensions.width() < 0;
106 SkASSERT(result == (fDimensions.height() < 0));
Brian Salomonbeb7f522019-08-30 16:19:42 -0400107 SkASSERT(!result || this->isLazy());
108 return result;
Greg Daniel65fa8ca2018-01-10 17:06:31 -0500109 }
Chris Dalton706a6ff2017-11-29 22:01:06 -0700110
111 GrPixelConfig config() const { return fConfig; }
Brian Salomonbeb7f522019-08-30 16:19:42 -0400112
Brian Salomon9f2b86c2019-10-22 10:37:46 -0400113 SkISize dimensions() const {
Brian Salomonbeb7f522019-08-30 16:19:42 -0400114 SkASSERT(!this->isFullyLazy());
Brian Salomon9f2b86c2019-10-22 10:37:46 -0400115 return fDimensions;
Greg Daniel65fa8ca2018-01-10 17:06:31 -0500116 }
Brian Salomon9f2b86c2019-10-22 10:37:46 -0400117 int width() const { return this->dimensions().width(); }
118 int height() const { return this->dimensions().height(); }
Brian Salomonbeb7f522019-08-30 16:19:42 -0400119
Robert Phillipse9462dd2019-10-23 12:41:29 -0400120 SkISize backingStoreDimensions() const;
Brian Salomon7eae3e02018-08-07 14:02:38 +0000121
Brian Salomond8eb7b62018-05-25 10:08:05 -0400122 /**
Robert Phillipse9462dd2019-10-23 12:41:29 -0400123 * Helper that gets the width and height of the proxy as a bounding rectangle.
Brian Salomond8eb7b62018-05-25 10:08:05 -0400124 */
Brian Salomon9f2b86c2019-10-22 10:37:46 -0400125 SkRect getBoundsRect() const { return SkRect::Make(this->dimensions()); }
126
Brian Salomond8eb7b62018-05-25 10:08:05 -0400127 /**
Robert Phillipse9462dd2019-10-23 12:41:29 -0400128 * Helper that gets the dimensions the backing GrSurface will have as a bounding rectangle.
Brian Salomond8eb7b62018-05-25 10:08:05 -0400129 */
Robert Phillipse9462dd2019-10-23 12:41:29 -0400130 SkRect backingStoreBoundsRect() const {
131 return SkRect::Make(this->backingStoreDimensions());
132 }
Brian Salomond8eb7b62018-05-25 10:08:05 -0400133
robertphillips76948d42016-05-04 12:47:41 -0700134 GrSurfaceOrigin origin() const {
Brian Salomonbb5711a2017-05-17 13:49:59 -0400135 SkASSERT(kTopLeft_GrSurfaceOrigin == fOrigin || kBottomLeft_GrSurfaceOrigin == fOrigin);
136 return fOrigin;
robertphillips76948d42016-05-04 12:47:41 -0700137 }
Chris Dalton706a6ff2017-11-29 22:01:06 -0700138
Greg Daniel2c19e7f2019-06-18 13:29:21 -0400139 const GrSwizzle& textureSwizzle() const { return fTextureSwizzle; }
140
Greg Daniel4065d452018-11-16 15:43:41 -0500141 const GrBackendFormat& backendFormat() const { return fFormat; }
142
Robert Phillips294870f2016-11-11 12:38:40 -0500143 class UniqueID {
144 public:
Robert Phillips7ee385e2017-03-30 08:02:11 -0400145 static UniqueID InvalidID() {
146 return UniqueID(uint32_t(SK_InvalidUniqueID));
147 }
148
Robert Phillips294870f2016-11-11 12:38:40 -0500149 // wrapped
150 explicit UniqueID(const GrGpuResource::UniqueID& id) : fID(id.asUInt()) { }
Chris Dalton706a6ff2017-11-29 22:01:06 -0700151 // deferred and lazy-callback
Robert Phillips294870f2016-11-11 12:38:40 -0500152 UniqueID() : fID(GrGpuResource::CreateUniqueID()) { }
153
154 uint32_t asUInt() const { return fID; }
155
156 bool operator==(const UniqueID& other) const {
157 return fID == other.fID;
158 }
159 bool operator!=(const UniqueID& other) const {
160 return !(*this == other);
161 }
162
Robert Phillips7ee385e2017-03-30 08:02:11 -0400163 void makeInvalid() { fID = SK_InvalidUniqueID; }
Robert Phillips294870f2016-11-11 12:38:40 -0500164 bool isInvalid() const { return SK_InvalidUniqueID == fID; }
165
166 private:
Robert Phillips7ee385e2017-03-30 08:02:11 -0400167 explicit UniqueID(uint32_t id) : fID(id) {}
168
169 uint32_t fID;
Robert Phillips294870f2016-11-11 12:38:40 -0500170 };
171
172 /*
173 * The contract for the uniqueID is:
174 * for wrapped resources:
175 * the uniqueID will match that of the wrapped resource
176 *
177 * for deferred resources:
178 * the uniqueID will be different from the real resource, when it is allocated
179 * the proxy's uniqueID will not change across the instantiate call
180 *
181 * the uniqueIDs of the proxies and the resources draw from the same pool
182 *
183 * What this boils down to is that the uniqueID of a proxy can be used to consistently
184 * track/identify a proxy but should never be used to distinguish between
185 * resources and proxies - beware!
186 */
187 UniqueID uniqueID() const { return fUniqueID; }
robertphillips76948d42016-05-04 12:47:41 -0700188
Robert Phillips159e3c62017-06-19 12:02:00 -0400189 UniqueID underlyingUniqueID() const {
190 if (fTarget) {
191 return UniqueID(fTarget->uniqueID());
192 }
193
194 return fUniqueID;
195 }
196
Robert Phillips10d17212019-04-24 14:09:10 -0400197 virtual bool instantiate(GrResourceProvider*) = 0;
Robert Phillips37430132016-11-09 06:50:43 -0500198
Brian Salomon967df202018-12-07 11:15:53 -0500199 void deinstantiate();
Robert Phillips4bc70112018-03-01 10:24:02 -0500200
robertphillips76948d42016-05-04 12:47:41 -0700201 /**
Brian Salomon7d94bb52018-10-12 14:37:19 -0400202 * Proxies that are already instantiated and whose backing surface cannot be recycled to
203 * instantiate other proxies do not need to be considered by GrResourceAllocator.
204 */
205 bool canSkipResourceAllocator() const;
206
207 /**
robertphillips76948d42016-05-04 12:47:41 -0700208 * @return the texture proxy associated with the surface proxy, may be NULL.
209 */
210 virtual GrTextureProxy* asTextureProxy() { return nullptr; }
211 virtual const GrTextureProxy* asTextureProxy() const { return nullptr; }
212
213 /**
214 * @return the render target proxy associated with the surface proxy, may be NULL.
215 */
216 virtual GrRenderTargetProxy* asRenderTargetProxy() { return nullptr; }
217 virtual const GrRenderTargetProxy* asRenderTargetProxy() const { return nullptr; }
218
Brian Salomonfd98c2c2018-07-31 17:25:29 -0400219 bool isInstantiated() const { return SkToBool(fTarget); }
220
221 // If the proxy is already instantiated, return its backing GrTexture; if not, return null.
Robert Phillipse5f73282019-06-18 17:15:04 -0400222 GrSurface* peekSurface() const { return fTarget.get(); }
Brian Salomonfd98c2c2018-07-31 17:25:29 -0400223
224 // If this is a texture proxy and the proxy is already instantiated, return its backing
225 // GrTexture; if not, return null.
226 GrTexture* peekTexture() const { return fTarget ? fTarget->asTexture() : nullptr; }
227
228 // If this is a render target proxy and the proxy is already instantiated, return its backing
229 // GrRenderTarget; if not, return null.
230 GrRenderTarget* peekRenderTarget() const {
231 return fTarget ? fTarget->asRenderTarget() : nullptr;
232 }
233
robertphillips13a7eee2016-08-31 15:06:24 -0700234 /**
235 * Does the resource count against the resource budget?
236 */
237 SkBudgeted isBudgeted() const { return fBudgeted; }
238
Brian Salomonc67c31c2018-12-06 10:00:03 -0500239 /**
240 * The pixel values of this proxy's surface cannot be modified (e.g. doesn't support write
Brian Salomon9cadc312018-12-05 15:09:19 -0500241 * pixels or MIP map level regen). Read-only proxies also bypass interval tracking and
242 * assignment in GrResourceAllocator.
Brian Salomonc67c31c2018-12-06 10:00:03 -0500243 */
244 bool readOnly() const { return fSurfaceFlags & GrInternalSurfaceFlags::kReadOnly; }
245
Chris Dalton3f7932e2019-08-19 00:39:13 -0600246 /**
247 * This means surface is a multisampled render target, and internally holds a non-msaa texture
248 * for resolving into. The render target resolves itself by blitting into this internal texture.
249 * (asTexture() might or might not return the internal texture, but if it does, we always
250 * resolve the render target before accessing this texture's data.)
251 */
252 bool requiresManualMSAAResolve() const {
253 return fSurfaceFlags & GrInternalSurfaceFlags::kRequiresManualMSAAResolve;
254 }
255
Chris Dalton6b498102019-08-01 14:14:52 -0600256 void setLastRenderTask(GrRenderTask*);
257 GrRenderTask* getLastRenderTask() { return fLastRenderTask; }
Robert Phillipsf2361d22016-10-25 14:20:06 -0400258
Greg Danielf41b2bd2019-08-22 16:19:24 -0400259 GrOpsTask* getLastOpsTask();
Brian Osman45580d32016-11-23 09:37:01 -0500260
Robert Phillips8bc06d02016-11-01 17:28:40 -0400261 /**
Robert Phillipsf5442bb2017-04-17 14:18:34 -0400262 * Retrieves the amount of GPU memory that will be or currently is used by this resource
Robert Phillips8bc06d02016-11-01 17:28:40 -0400263 * in bytes. It is approximate since we aren't aware of additional padding or copies made
264 * by the driver.
265 *
266 * @return the amount of GPU memory used in bytes
267 */
Greg Daniel7fd7a8a2019-10-10 16:10:31 -0400268 size_t gpuMemorySize(const GrCaps& caps) const {
Brian Salomonbeb7f522019-08-30 16:19:42 -0400269 SkASSERT(!this->isFullyLazy());
Brian Salomonbb5711a2017-05-17 13:49:59 -0400270 if (fTarget) {
271 return fTarget->gpuMemorySize();
272 }
Robert Phillips8bc06d02016-11-01 17:28:40 -0400273 if (kInvalidGpuMemorySize == fGpuMemorySize) {
Greg Daniel7fd7a8a2019-10-10 16:10:31 -0400274 fGpuMemorySize = this->onUninstantiatedGpuMemorySize(caps);
Robert Phillips8bc06d02016-11-01 17:28:40 -0400275 SkASSERT(kInvalidGpuMemorySize != fGpuMemorySize);
276 }
277 return fGpuMemorySize;
278 }
279
Greg Daniel46cfbc62019-06-07 11:43:30 -0400280 enum class RectsMustMatch : bool {
281 kNo = false,
282 kYes = true
283 };
284
Robert Phillipse2f7d182016-12-15 09:23:05 -0500285 // Helper function that creates a temporary SurfaceContext to perform the copy
Brian Salomonfee3f9b2018-12-19 12:34:12 -0500286 // The copy is is not a render target and not multisampled.
Brian Salomon078e8fa2019-11-22 04:10:18 +0000287 static sk_sp<GrTextureProxy> Copy(GrRecordingContext*, GrSurfaceProxy* src,
288 GrColorType srcColorType, GrMipMapped,
Greg Daniel46cfbc62019-06-07 11:43:30 -0400289 SkIRect srcRect, SkBackingFit, SkBudgeted,
290 RectsMustMatch = RectsMustMatch::kNo);
Robert Phillipse2f7d182016-12-15 09:23:05 -0500291
292 // Copy the entire 'src'
Brian Salomon078e8fa2019-11-22 04:10:18 +0000293 static sk_sp<GrTextureProxy> Copy(GrRecordingContext*, GrSurfaceProxy* src,
294 GrColorType srcColortype, GrMipMapped, SkBackingFit,
295 SkBudgeted);
Robert Phillipse2f7d182016-12-15 09:23:05 -0500296
Robert Phillipsb5204762019-06-19 14:12:13 -0400297#if GR_TEST_UTILS
298 int32_t testingOnly_getBackingRefCnt() const;
299 GrInternalSurfaceFlags testingOnly_getFlags() const;
300#endif
Robert Phillipseaa86252016-11-08 13:49:39 +0000301
Robert Phillips292a6b22019-02-14 14:49:02 -0500302 SkDEBUGCODE(void validate(GrContext_Base*) const;)
Brian Osman45580d32016-11-23 09:37:01 -0500303
Robert Phillips757914d2017-01-25 15:48:30 -0500304 // Provides access to functions that aren't part of the public API.
Robert Phillips420c4cf2017-09-28 09:00:45 -0400305 inline GrSurfaceProxyPriv priv();
306 inline const GrSurfaceProxyPriv priv() const;
Robert Phillips757914d2017-01-25 15:48:30 -0500307
Emircan Uysaler23ca4e72019-06-24 10:53:09 -0400308 // Returns true if we are working with protected content.
309 bool isProtected() const { return fIsProtected == GrProtected::kYes; }
310
robertphillips76948d42016-05-04 12:47:41 -0700311protected:
Brian Salomonbeb7f522019-08-30 16:19:42 -0400312 // Deferred version - takes a new UniqueID from the shared resource/proxy pool.
313 GrSurfaceProxy(const GrBackendFormat&,
314 const GrSurfaceDesc&,
315 GrRenderable,
316 GrSurfaceOrigin,
317 const GrSwizzle& textureSwizzle,
318 SkBackingFit,
319 SkBudgeted,
320 GrProtected,
321 GrInternalSurfaceFlags,
322 UseAllocator);
323 // Lazy-callback version - takes a new UniqueID from the shared resource/proxy pool.
324 GrSurfaceProxy(LazyInstantiateCallback&&,
325 const GrBackendFormat&,
326 const GrSurfaceDesc&,
327 GrRenderable,
328 GrSurfaceOrigin,
329 const GrSwizzle& textureSwizzle,
330 SkBackingFit,
331 SkBudgeted,
332 GrProtected,
333 GrInternalSurfaceFlags,
334 UseAllocator);
robertphillips8abb3702016-08-31 14:04:06 -0700335
Brian Salomonbeb7f522019-08-30 16:19:42 -0400336 // Wrapped version - shares the UniqueID of the passed surface.
337 // Takes UseAllocator because even though this is already instantiated it still can participate
338 // in allocation by having its backing resource recycled to other uninstantiated proxies or
339 // not depending on UseAllocator.
340 GrSurfaceProxy(sk_sp<GrSurface>,
341 GrSurfaceOrigin,
342 const GrSwizzle& textureSwizzle,
343 SkBackingFit,
344 UseAllocator);
robertphillips76948d42016-05-04 12:47:41 -0700345
Robert Phillips757914d2017-01-25 15:48:30 -0500346 friend class GrSurfaceProxyPriv;
347
348 // Methods made available via GrSurfaceProxyPriv
Robert Phillips5f78adf2019-04-22 12:41:39 -0400349 bool ignoredByResourceAllocator() const { return fIgnoredByResourceAllocator; }
350 void setIgnoredByResourceAllocator() { fIgnoredByResourceAllocator = true; }
351
Robert Phillips57aa3672017-07-21 11:38:13 -0400352 void computeScratchKey(GrScratchKey*) const;
353
Robert Phillips5af44de2017-07-18 14:49:38 -0400354 virtual sk_sp<GrSurface> createSurface(GrResourceProvider*) const = 0;
355 void assign(sk_sp<GrSurface> surface);
356
Chris Dalton0b68dda2019-11-07 21:08:03 -0700357 sk_sp<GrSurface> createSurfaceImpl(GrResourceProvider*, int sampleCnt, GrRenderable,
358 GrMipMapped) const;
Robert Phillips5af44de2017-07-18 14:49:38 -0400359
Brian Salomon9f2b86c2019-10-22 10:37:46 -0400360 // Once the dimensions of a fully-lazy proxy are decided, and before it gets instantiated, the
361 // client can use this optional method to specify the proxy's dimensions. (A proxy's dimensions
362 // can be less than the GPU surface that backs it. e.g., SkBackingFit::kApprox.) Otherwise,
363 // the proxy's dimensions will be set to match the underlying GPU surface upon instantiation.
364 void setLazyDimensions(SkISize dimensions) {
Brian Salomonbeb7f522019-08-30 16:19:42 -0400365 SkASSERT(this->isFullyLazy());
Brian Salomon9f2b86c2019-10-22 10:37:46 -0400366 SkASSERT(!dimensions.isEmpty());
367 fDimensions = dimensions;
Chris Daltonf91b7552019-04-29 16:21:18 -0600368 }
369
Chris Dalton0b68dda2019-11-07 21:08:03 -0700370 bool instantiateImpl(GrResourceProvider* resourceProvider, int sampleCnt, GrRenderable,
371 GrMipMapped, const GrUniqueKey*);
Robert Phillipsfe0253f2018-03-16 16:47:25 -0400372
Robert Phillipsb5204762019-06-19 14:12:13 -0400373 // For deferred proxies this will be null until the proxy is instantiated.
374 // For wrapped proxies it will point to the wrapped resource.
375 sk_sp<GrSurface> fTarget;
376
Greg Daniele3204862018-04-16 11:24:10 -0400377 // In many cases these flags aren't actually known until the proxy has been instantiated.
378 // However, Ganesh frequently needs to change its behavior based on these settings. For
379 // internally create proxies we will know these properties ahead of time. For wrapped
380 // proxies we will copy the properties off of the GrSurface. For lazy proxies we force the
381 // call sites to provide the required information ahead of time. At instantiation time
382 // we verify that the assumed properties match the actual properties.
383 GrInternalSurfaceFlags fSurfaceFlags;
384
Chris Dalton706a6ff2017-11-29 22:01:06 -0700385private:
Greg Daniel4065d452018-11-16 15:43:41 -0500386 // For wrapped resources, 'fFormat', 'fConfig', 'fWidth', 'fHeight', and 'fOrigin; will always
387 // be filled in from the wrapped resource.
Chris Dalton16a33c62019-09-24 22:19:17 -0600388 const GrBackendFormat fFormat;
389 const GrPixelConfig fConfig;
Brian Salomon9f2b86c2019-10-22 10:37:46 -0400390 SkISize fDimensions;
Chris Dalton16a33c62019-09-24 22:19:17 -0600391 const GrSurfaceOrigin fOrigin;
392 const GrSwizzle fTextureSwizzle;
Greg Daniel2c19e7f2019-06-18 13:29:21 -0400393
Robert Phillipsfe0253f2018-03-16 16:47:25 -0400394 SkBackingFit fFit; // always kApprox for lazy-callback resources
395 // always kExact for wrapped resources
396 mutable SkBudgeted fBudgeted; // always kYes for lazy-callback resources
397 // set from the backing resource for wrapped resources
398 // mutable bc of SkSurface/SkImage wishy-washiness
Brian Salomonbeb7f522019-08-30 16:19:42 -0400399 // Only meaningful if fLazyInstantiateCallback is non-null.
400 UseAllocator fUseAllocator;
Robert Phillipsa4c41b32017-03-15 13:02:45 -0400401
Robert Phillipsfe0253f2018-03-16 16:47:25 -0400402 const UniqueID fUniqueID; // set from the backing resource for wrapped resources
robertphillips76948d42016-05-04 12:47:41 -0700403
Chris Dalton706a6ff2017-11-29 22:01:06 -0700404 LazyInstantiateCallback fLazyInstantiateCallback;
Greg Daniel849dce12018-04-24 14:32:53 -0400405
406 SkDEBUGCODE(void validateSurface(const GrSurface*);)
407 SkDEBUGCODE(virtual void onValidateSurface(const GrSurface*) = 0;)
Chris Dalton706a6ff2017-11-29 22:01:06 -0700408
Robert Phillips8bc06d02016-11-01 17:28:40 -0400409 static const size_t kInvalidGpuMemorySize = ~static_cast<size_t>(0);
Robert Phillips29e52f12016-11-03 10:19:14 -0400410 SkDEBUGCODE(size_t getRawGpuMemorySize_debugOnly() const { return fGpuMemorySize; })
411
Greg Daniel7fd7a8a2019-10-10 16:10:31 -0400412 virtual size_t onUninstantiatedGpuMemorySize(const GrCaps&) const = 0;
Robert Phillips29e52f12016-11-03 10:19:14 -0400413
Robert Phillips5f78adf2019-04-22 12:41:39 -0400414 bool fIgnoredByResourceAllocator = false;
Emircan Uysaler23ca4e72019-06-24 10:53:09 -0400415 GrProtected fIsProtected;
Brian Salomond17b4a62017-05-23 16:53:47 -0400416
Robert Phillips8bc06d02016-11-01 17:28:40 -0400417 // This entry is lazily evaluated so, when the proxy wraps a resource, the resource
418 // will be called but, when the proxy is deferred, it will compute the answer itself.
419 // If the proxy computes its own answer that answer is checked (in debug mode) in
420 // the instantiation method.
Robert Phillipsfe0253f2018-03-16 16:47:25 -0400421 mutable size_t fGpuMemorySize;
Robert Phillips8bc06d02016-11-01 17:28:40 -0400422
Greg Danielf41b2bd2019-08-22 16:19:24 -0400423 // The last GrRenderTask that wrote to or is currently going to write to this surface
424 // The GrRenderTask can be closed (e.g., no surface context is currently bound
Robert Phillipsb6deea82017-05-11 14:14:30 -0400425 // to this proxy).
Robert Phillipsf2361d22016-10-25 14:20:06 -0400426 // This back-pointer is required so that we can add a dependancy between
Greg Danielf41b2bd2019-08-22 16:19:24 -0400427 // the GrRenderTask used to create the current contents of this surface
428 // and the GrRenderTask of a destination surface to which this one is being drawn or copied.
Chris Dalton6b498102019-08-01 14:14:52 -0600429 // This pointer is unreffed. GrRenderTasks own a ref on their surface proxies.
Brian Salomonbeb7f522019-08-30 16:19:42 -0400430 GrRenderTask* fLastRenderTask = nullptr;
robertphillips76948d42016-05-04 12:47:41 -0700431};
432
Chris Dalton4ece96d2019-08-30 11:26:39 -0600433GR_MAKE_BITFIELD_CLASS_OPS(GrSurfaceProxy::ResolveFlags)
434
robertphillips76948d42016-05-04 12:47:41 -0700435#endif