blob: 493140b9dd588c90b760ac2669e9ecab04e83e2d [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
11#include "GrGpuResource.h"
Robert Phillipsc7635fa2016-10-28 13:25:24 -040012#include "GrSurface.h"
Robert Phillips93f16332016-11-23 19:37:13 -050013
csmartdaltonbf4a8f92016-09-06 10:01:06 -070014#include "SkRect.h"
robertphillips76948d42016-05-04 12:47:41 -070015
Greg Daniel7ef28f32017-04-20 16:41:55 +000016class GrBackendTexture;
Robert Phillips37430132016-11-09 06:50:43 -050017class GrCaps;
Robert Phillipsc589b0b2017-04-17 07:53:07 -040018class GrOpList;
Brian Osman45580d32016-11-23 09:37:01 -050019class GrRenderTargetOpList;
20class GrRenderTargetProxy;
Brian Osman32342f02017-03-04 08:12:46 -050021class GrResourceProvider;
Robert Phillipsd46697a2017-01-25 12:10:37 -050022class GrSurfaceContext;
Robert Phillips757914d2017-01-25 15:48:30 -050023class GrSurfaceProxyPriv;
Brian Osman45580d32016-11-23 09:37:01 -050024class GrTextureOpList;
robertphillips76948d42016-05-04 12:47:41 -070025class GrTextureProxy;
robertphillips76948d42016-05-04 12:47:41 -070026
Robert Phillipsc7635fa2016-10-28 13:25:24 -040027// This class replicates the functionality GrIORef<GrSurface> but tracks the
28// utilitization for later resource allocation (for the deferred case) and
29// forwards on the utilization in the wrapped case
30class GrIORefProxy : public SkNoncopyable {
31public:
32 void ref() const {
33 this->validate();
34
35 ++fRefCnt;
36 if (fTarget) {
37 fTarget->ref();
38 }
39 }
40
41 void unref() const {
42 this->validate();
43
44 if (fTarget) {
45 fTarget->unref();
46 }
47
Robert Phillipsb6deea82017-05-11 14:14:30 -040048 --fRefCnt;
49 this->didRemoveRefOrPendingIO();
Robert Phillipsc7635fa2016-10-28 13:25:24 -040050 }
51
Chris Daltona32a3c32017-12-05 10:05:21 -070052#ifdef SK_DEBUG
53 bool isUnique_debugOnly() const { // For asserts.
54 SkASSERT(fRefCnt >= 0 && fPendingWrites >= 0 && fPendingReads >= 0);
55 return 1 == fRefCnt + fPendingWrites + fPendingReads;
56 }
57#endif
58
Robert Phillipsc7635fa2016-10-28 13:25:24 -040059 void validate() const {
Robert Phillipsb6deea82017-05-11 14:14:30 -040060#ifdef SK_DEBUG
61 SkASSERT(fRefCnt >= 0);
robertphillips1125a032016-11-16 11:17:17 -080062 SkASSERT(fPendingReads >= 0);
63 SkASSERT(fPendingWrites >= 0);
64 SkASSERT(fRefCnt + fPendingReads + fPendingWrites >= 1);
65
66 if (fTarget) {
robertphillips1125a032016-11-16 11:17:17 -080067 // The backing GrSurface can have more refs than the proxy if the proxy
68 // started off wrapping an external resource (that came in with refs).
69 // The GrSurface should never have fewer refs than the proxy however.
70 SkASSERT(fTarget->fRefCnt >= fRefCnt);
Robert Phillipsb6deea82017-05-11 14:14:30 -040071 SkASSERT(fTarget->fPendingReads >= fPendingReads);
72 SkASSERT(fTarget->fPendingWrites >= fPendingWrites);
robertphillips1125a032016-11-16 11:17:17 -080073 }
Robert Phillipsc7635fa2016-10-28 13:25:24 -040074#endif
75 }
76
robertphillips1125a032016-11-16 11:17:17 -080077 int32_t getProxyRefCnt_TestOnly() const;
78 int32_t getBackingRefCnt_TestOnly() const;
79 int32_t getPendingReadCnt_TestOnly() const;
80 int32_t getPendingWriteCnt_TestOnly() const;
81
Brian Salomoncf75b002017-08-16 10:42:09 -040082 void addPendingRead() const {
83 this->validate();
84
85 ++fPendingReads;
86 if (fTarget) {
87 fTarget->addPendingRead();
88 }
89 }
90
91 void completedRead() const {
92 this->validate();
93
94 if (fTarget) {
95 fTarget->completedRead();
96 }
97
98 --fPendingReads;
99 this->didRemoveRefOrPendingIO();
100 }
101
102 void addPendingWrite() const {
103 this->validate();
104
105 ++fPendingWrites;
106 if (fTarget) {
107 fTarget->addPendingWrite();
108 }
109 }
110
111 void completedWrite() const {
112 this->validate();
113
114 if (fTarget) {
115 fTarget->completedWrite();
116 }
117
118 --fPendingWrites;
119 this->didRemoveRefOrPendingIO();
120 }
121
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400122protected:
robertphillips1125a032016-11-16 11:17:17 -0800123 GrIORefProxy() : fTarget(nullptr), fRefCnt(1), fPendingReads(0), fPendingWrites(0) {}
124 GrIORefProxy(sk_sp<GrSurface> surface) : fRefCnt(1), fPendingReads(0), fPendingWrites(0) {
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400125 // Since we're manually forwarding on refs & unrefs we don't want sk_sp doing
126 // anything extra.
127 fTarget = surface.release();
128 }
129 virtual ~GrIORefProxy() {
130 // We don't unref 'fTarget' here since the 'unref' method will already
131 // have forwarded on the unref call that got use here.
132 }
133
robertphillips1125a032016-11-16 11:17:17 -0800134 // This GrIORefProxy was deferred before but has just been instantiated. To
135 // make all the reffing & unreffing work out we now need to transfer any deferred
136 // refs & unrefs to the new GrSurface
137 void transferRefs() {
138 SkASSERT(fTarget);
139
Robert Phillipsf8e25022017-11-08 15:24:31 -0500140 SkASSERT(fTarget->fRefCnt > 0);
Robert Phillips2d9cb572017-11-13 13:38:05 +0000141 fTarget->fRefCnt += (fRefCnt-1); // don't xfer the proxy's creation ref
robertphillips1125a032016-11-16 11:17:17 -0800142 fTarget->fPendingReads += fPendingReads;
143 fTarget->fPendingWrites += fPendingWrites;
robertphillips1125a032016-11-16 11:17:17 -0800144 }
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400145
Robert Phillips757914d2017-01-25 15:48:30 -0500146 bool internalHasPendingIO() const {
147 if (fTarget) {
148 return fTarget->internalHasPendingIO();
149 }
150
151 return SkToBool(fPendingWrites | fPendingReads);
152 }
153
Robert Phillips7ee385e2017-03-30 08:02:11 -0400154 bool internalHasPendingWrite() const {
155 if (fTarget) {
156 return fTarget->internalHasPendingWrite();
157 }
158
159 return SkToBool(fPendingWrites);
160 }
161
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400162 // For deferred proxies this will be null. For wrapped proxies it will point to the
163 // wrapped resource.
164 GrSurface* fTarget;
robertphillips1125a032016-11-16 11:17:17 -0800165
166private:
167 // This class is used to manage conversion of refs to pending reads/writes.
Robert Phillipsb6deea82017-05-11 14:14:30 -0400168 friend class GrSurfaceProxyRef;
robertphillips1125a032016-11-16 11:17:17 -0800169 template <typename, GrIOType> friend class GrPendingIOResource;
170
Robert Phillipsb6deea82017-05-11 14:14:30 -0400171 void didRemoveRefOrPendingIO() const {
172 if (0 == fPendingReads && 0 == fPendingWrites && 0 == fRefCnt) {
173 delete this;
174 }
robertphillips1125a032016-11-16 11:17:17 -0800175 }
176
177 mutable int32_t fRefCnt;
178 mutable int32_t fPendingReads;
179 mutable int32_t fPendingWrites;
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400180};
181
182class GrSurfaceProxy : public GrIORefProxy {
robertphillips76948d42016-05-04 12:47:41 -0700183public:
Robert Phillips066f0202017-07-25 10:16:35 -0400184 static sk_sp<GrSurfaceProxy> MakeWrapped(sk_sp<GrSurface>, GrSurfaceOrigin);
185 static sk_sp<GrTextureProxy> MakeWrapped(sk_sp<GrTexture>, GrSurfaceOrigin);
Robert Phillips37430132016-11-09 06:50:43 -0500186
Robert Phillips26c90e02017-03-14 14:39:29 -0400187 static sk_sp<GrTextureProxy> MakeDeferred(GrResourceProvider*,
Robert Phillips7928e762017-02-28 16:30:28 -0500188 const GrSurfaceDesc&, SkBackingFit,
189 SkBudgeted, uint32_t flags = 0);
Robert Phillips37430132016-11-09 06:50:43 -0500190
Robert Phillips8e8c7552017-07-10 12:06:05 -0400191 /**
192 * Creates a proxy that will be mipmapped.
193 *
194 * @param desc Description of the texture properties.
195 * @param budgeted Does the texture count against the resource cache budget?
196 * @param texels A contiguous array of mipmap levels
197 * @param mipLevelCount The amount of elements in the texels array
198 */
199 static sk_sp<GrTextureProxy> MakeDeferredMipMap(GrResourceProvider*,
200 const GrSurfaceDesc& desc, SkBudgeted budgeted,
Robert Phillips590533f2017-07-11 14:22:35 -0400201 const GrMipLevel texels[], int mipLevelCount,
Robert Phillips8e8c7552017-07-10 12:06:05 -0400202 SkDestinationSurfaceColorMode mipColorMode =
203 SkDestinationSurfaceColorMode::kLegacy);
204
Greg Daniele1da1d92017-10-06 15:59:27 -0400205 /**
206 * Like the call above but there are no texels to upload. A texture proxy is returned that
207 * simply has space allocated for the mips. We will allocated the full amount of mip levels
208 * based on the width and height in the GrSurfaceDesc.
209 */
210 static sk_sp<GrTextureProxy> MakeDeferredMipMap(GrResourceProvider*,
211 const GrSurfaceDesc& desc, SkBudgeted budgeted);
212
213
Robert Phillips37430132016-11-09 06:50:43 -0500214 // TODO: need to refine ownership semantics of 'srcData' if we're in completely
215 // deferred mode
Robert Phillips26c90e02017-03-14 14:39:29 -0400216 static sk_sp<GrTextureProxy> MakeDeferred(GrResourceProvider*,
Robert Phillips37430132016-11-09 06:50:43 -0500217 const GrSurfaceDesc&, SkBudgeted,
218 const void* srcData, size_t rowBytes);
219
Robert Phillipsc25db632017-12-13 09:22:45 -0500220 static sk_sp<GrTextureProxy> MakeWrappedBackend(GrContext*, const GrBackendTexture&,
221 GrSurfaceOrigin);
Robert Phillips26caf892017-01-27 10:58:31 -0500222
Chris Dalton706a6ff2017-11-29 22:01:06 -0700223 using LazyInstantiateCallback = std::function<sk_sp<GrTexture>(GrResourceProvider*,
224 GrSurfaceOrigin* outOrigin)>;
225
226 enum class Renderable : bool {
227 kNo = false,
228 kYes = true
229 };
230
231 /**
232 * Creates a texture proxy that will be instantiated by a user-supplied callback during flush.
233 * (Mipmapping, MSAA, and stencil are not supported by this method.)
234 */
235 static sk_sp<GrTextureProxy> MakeLazy(LazyInstantiateCallback&&, Renderable, GrPixelConfig);
236
237 GrPixelConfig config() const { return fConfig; }
238 int width() const { SkASSERT(!this->isPendingLazyInstantiation()); return fWidth; }
239 int height() const { SkASSERT(!this->isPendingLazyInstantiation()); return fHeight; }
240 int worstCaseWidth() const;
241 int worstCaseHeight() const;
robertphillips76948d42016-05-04 12:47:41 -0700242 GrSurfaceOrigin origin() const {
Chris Dalton706a6ff2017-11-29 22:01:06 -0700243 SkASSERT(!this->isPendingLazyInstantiation());
Brian Salomonbb5711a2017-05-17 13:49:59 -0400244 SkASSERT(kTopLeft_GrSurfaceOrigin == fOrigin || kBottomLeft_GrSurfaceOrigin == fOrigin);
245 return fOrigin;
robertphillips76948d42016-05-04 12:47:41 -0700246 }
Chris Dalton706a6ff2017-11-29 22:01:06 -0700247
248 // If the client gave us a LazyInstantiateCallback (via MakeLazy), then we will invoke that
249 // callback during flush. fWidth, fHeight, and fOrigin will be undefined until that time.
250 bool isPendingLazyInstantiation() const { return SkToBool(fLazyInstantiateCallback); }
robertphillips76948d42016-05-04 12:47:41 -0700251
Robert Phillips294870f2016-11-11 12:38:40 -0500252 class UniqueID {
253 public:
Robert Phillips7ee385e2017-03-30 08:02:11 -0400254 static UniqueID InvalidID() {
255 return UniqueID(uint32_t(SK_InvalidUniqueID));
256 }
257
Robert Phillips294870f2016-11-11 12:38:40 -0500258 // wrapped
259 explicit UniqueID(const GrGpuResource::UniqueID& id) : fID(id.asUInt()) { }
Chris Dalton706a6ff2017-11-29 22:01:06 -0700260 // deferred and lazy-callback
Robert Phillips294870f2016-11-11 12:38:40 -0500261 UniqueID() : fID(GrGpuResource::CreateUniqueID()) { }
262
263 uint32_t asUInt() const { return fID; }
264
265 bool operator==(const UniqueID& other) const {
266 return fID == other.fID;
267 }
268 bool operator!=(const UniqueID& other) const {
269 return !(*this == other);
270 }
271
Robert Phillips7ee385e2017-03-30 08:02:11 -0400272 void makeInvalid() { fID = SK_InvalidUniqueID; }
Robert Phillips294870f2016-11-11 12:38:40 -0500273 bool isInvalid() const { return SK_InvalidUniqueID == fID; }
274
275 private:
Robert Phillips7ee385e2017-03-30 08:02:11 -0400276 explicit UniqueID(uint32_t id) : fID(id) {}
277
278 uint32_t fID;
Robert Phillips294870f2016-11-11 12:38:40 -0500279 };
280
281 /*
282 * The contract for the uniqueID is:
283 * for wrapped resources:
284 * the uniqueID will match that of the wrapped resource
285 *
286 * for deferred resources:
287 * the uniqueID will be different from the real resource, when it is allocated
288 * the proxy's uniqueID will not change across the instantiate call
289 *
290 * the uniqueIDs of the proxies and the resources draw from the same pool
291 *
292 * What this boils down to is that the uniqueID of a proxy can be used to consistently
293 * track/identify a proxy but should never be used to distinguish between
294 * resources and proxies - beware!
295 */
296 UniqueID uniqueID() const { return fUniqueID; }
robertphillips76948d42016-05-04 12:47:41 -0700297
Robert Phillips159e3c62017-06-19 12:02:00 -0400298 UniqueID underlyingUniqueID() const {
299 if (fTarget) {
300 return UniqueID(fTarget->uniqueID());
301 }
302
303 return fUniqueID;
304 }
305
Robert Phillipseee4d6e2017-06-05 09:26:07 -0400306 virtual bool instantiate(GrResourceProvider* resourceProvider) = 0;
Robert Phillips37430132016-11-09 06:50:43 -0500307
robertphillips76948d42016-05-04 12:47:41 -0700308 /**
robertphillips13a7eee2016-08-31 15:06:24 -0700309 * Helper that gets the width and height of the surface as a bounding rectangle.
310 */
Chris Dalton706a6ff2017-11-29 22:01:06 -0700311 SkRect getBoundsRect() const {
312 SkASSERT(!this->isPendingLazyInstantiation());
313 return SkRect::MakeIWH(this->width(), this->height());
314 }
Robert Phillips784b7bf2016-12-09 13:35:02 -0500315
robertphillips13a7eee2016-08-31 15:06:24 -0700316 /**
robertphillips76948d42016-05-04 12:47:41 -0700317 * @return the texture proxy associated with the surface proxy, may be NULL.
318 */
319 virtual GrTextureProxy* asTextureProxy() { return nullptr; }
320 virtual const GrTextureProxy* asTextureProxy() const { return nullptr; }
321
322 /**
323 * @return the render target proxy associated with the surface proxy, may be NULL.
324 */
325 virtual GrRenderTargetProxy* asRenderTargetProxy() { return nullptr; }
326 virtual const GrRenderTargetProxy* asRenderTargetProxy() const { return nullptr; }
327
robertphillips13a7eee2016-08-31 15:06:24 -0700328 /**
329 * Does the resource count against the resource budget?
330 */
331 SkBudgeted isBudgeted() const { return fBudgeted; }
332
Robert Phillipsf2361d22016-10-25 14:20:06 -0400333 void setLastOpList(GrOpList* opList);
334 GrOpList* getLastOpList() { return fLastOpList; }
335
Brian Osman45580d32016-11-23 09:37:01 -0500336 GrRenderTargetOpList* getLastRenderTargetOpList();
337 GrTextureOpList* getLastTextureOpList();
338
Robert Phillips8bc06d02016-11-01 17:28:40 -0400339 /**
Robert Phillipsf5442bb2017-04-17 14:18:34 -0400340 * Retrieves the amount of GPU memory that will be or currently is used by this resource
Robert Phillips8bc06d02016-11-01 17:28:40 -0400341 * in bytes. It is approximate since we aren't aware of additional padding or copies made
342 * by the driver.
343 *
344 * @return the amount of GPU memory used in bytes
345 */
346 size_t gpuMemorySize() const {
Chris Dalton706a6ff2017-11-29 22:01:06 -0700347 SkASSERT(!this->isPendingLazyInstantiation());
Brian Salomonbb5711a2017-05-17 13:49:59 -0400348 if (fTarget) {
349 return fTarget->gpuMemorySize();
350 }
Robert Phillips8bc06d02016-11-01 17:28:40 -0400351 if (kInvalidGpuMemorySize == fGpuMemorySize) {
Brian Salomonbb5711a2017-05-17 13:49:59 -0400352 fGpuMemorySize = this->onUninstantiatedGpuMemorySize();
Robert Phillips8bc06d02016-11-01 17:28:40 -0400353 SkASSERT(kInvalidGpuMemorySize != fGpuMemorySize);
354 }
355 return fGpuMemorySize;
356 }
357
Robert Phillipse2f7d182016-12-15 09:23:05 -0500358 // Helper function that creates a temporary SurfaceContext to perform the copy
Robert Phillips0ae6faa2017-03-21 16:22:00 -0400359 // It always returns a kExact-backed proxy bc it is used when converting an SkSpecialImage
Brian Salomon63e79732017-05-15 21:23:13 -0400360 // to an SkImage. The copy is is not a render target and not multisampled.
Greg Daniel65c7f662017-10-30 13:39:09 -0400361 static sk_sp<GrTextureProxy> Copy(GrContext*, GrSurfaceProxy* src, GrMipMapped,
Robert Phillipse2f7d182016-12-15 09:23:05 -0500362 SkIRect srcRect, SkBudgeted);
363
364 // Copy the entire 'src'
Robert Phillips0ae6faa2017-03-21 16:22:00 -0400365 // It always returns a kExact-backed proxy bc it is used in SkGpuDevice::snapSpecial
Greg Daniel65c7f662017-10-30 13:39:09 -0400366 static sk_sp<GrTextureProxy> Copy(GrContext* context, GrSurfaceProxy* src, GrMipMapped,
Robert Phillips63c67462017-02-15 14:19:01 -0500367 SkBudgeted budgeted);
Robert Phillipse2f7d182016-12-15 09:23:05 -0500368
369 // Test-only entry point - should decrease in use as proxies propagate
Robert Phillipsd46697a2017-01-25 12:10:37 -0500370 static sk_sp<GrSurfaceContext> TestCopy(GrContext* context, const GrSurfaceDesc& dstDesc,
371 GrSurfaceProxy* srcProxy);
Robert Phillipse2f7d182016-12-15 09:23:05 -0500372
Robert Phillipseaa86252016-11-08 13:49:39 +0000373 bool isWrapped_ForTesting() const;
374
Brian Osman45580d32016-11-23 09:37:01 -0500375 SkDEBUGCODE(void validate(GrContext*) const;)
376
Robert Phillips757914d2017-01-25 15:48:30 -0500377 // Provides access to functions that aren't part of the public API.
Robert Phillips420c4cf2017-09-28 09:00:45 -0400378 inline GrSurfaceProxyPriv priv();
379 inline const GrSurfaceProxyPriv priv() const;
Robert Phillips757914d2017-01-25 15:48:30 -0500380
robertphillips76948d42016-05-04 12:47:41 -0700381protected:
robertphillips8abb3702016-08-31 14:04:06 -0700382 // Deferred version
Robert Phillipsc787e492017-02-28 11:26:32 -0500383 GrSurfaceProxy(const GrSurfaceDesc& desc, SkBackingFit fit, SkBudgeted budgeted, uint32_t flags)
Brian Salomonbb5711a2017-05-17 13:49:59 -0400384 : fConfig(desc.fConfig)
385 , fWidth(desc.fWidth)
386 , fHeight(desc.fHeight)
387 , fOrigin(desc.fOrigin)
388 , fFit(fit)
389 , fBudgeted(budgeted)
390 , fFlags(flags)
Brian Salomond17b4a62017-05-23 16:53:47 -0400391 , fNeedsClear(SkToBool(desc.fFlags & kPerformInitialClear_GrSurfaceFlag))
Brian Salomonbb5711a2017-05-17 13:49:59 -0400392 , fGpuMemorySize(kInvalidGpuMemorySize)
393 , fLastOpList(nullptr) {
Robert Phillips294870f2016-11-11 12:38:40 -0500394 // Note: this ctor pulls a new uniqueID from the same pool at the GrGpuResources
robertphillips8abb3702016-08-31 14:04:06 -0700395 }
396
Chris Dalton706a6ff2017-11-29 22:01:06 -0700397 // Lazy-callback version
398 GrSurfaceProxy(LazyInstantiateCallback&& callback, GrPixelConfig config);
399
robertphillips8abb3702016-08-31 14:04:06 -0700400 // Wrapped version
Robert Phillips066f0202017-07-25 10:16:35 -0400401 GrSurfaceProxy(sk_sp<GrSurface> surface, GrSurfaceOrigin origin, SkBackingFit fit);
robertphillips76948d42016-05-04 12:47:41 -0700402
Robert Phillipsf2361d22016-10-25 14:20:06 -0400403 virtual ~GrSurfaceProxy();
404
Robert Phillips757914d2017-01-25 15:48:30 -0500405 friend class GrSurfaceProxyPriv;
406
407 // Methods made available via GrSurfaceProxyPriv
408 bool hasPendingIO() const {
409 return this->internalHasPendingIO();
410 }
411
Robert Phillips7ee385e2017-03-30 08:02:11 -0400412 bool hasPendingWrite() const {
413 return this->internalHasPendingWrite();
414 }
415
Robert Phillips57aa3672017-07-21 11:38:13 -0400416 void computeScratchKey(GrScratchKey*) const;
417
Robert Phillips5af44de2017-07-18 14:49:38 -0400418 virtual sk_sp<GrSurface> createSurface(GrResourceProvider*) const = 0;
419 void assign(sk_sp<GrSurface> surface);
420
Robert Phillips65048132017-08-10 08:44:49 -0400421 sk_sp<GrSurface> createSurfaceImpl(GrResourceProvider*, int sampleCnt, bool needsStencil,
Greg Daniele252f082017-10-23 16:05:23 -0400422 GrSurfaceFlags flags, GrMipMapped mipMapped,
Robert Phillips5af44de2017-07-18 14:49:38 -0400423 SkDestinationSurfaceColorMode mipColorMode) const;
424
Robert Phillips65048132017-08-10 08:44:49 -0400425 bool instantiateImpl(GrResourceProvider* resourceProvider, int sampleCnt, bool needsStencil,
Greg Daniele252f082017-10-23 16:05:23 -0400426 GrSurfaceFlags flags, GrMipMapped mipMapped,
Robert Phillipsae7d3f32017-09-21 08:26:08 -0400427 SkDestinationSurfaceColorMode mipColorMode, const GrUniqueKey*);
Brian Salomonbb5711a2017-05-17 13:49:59 -0400428
Chris Dalton706a6ff2017-11-29 22:01:06 -0700429private:
Brian Salomonbb5711a2017-05-17 13:49:59 -0400430 // For wrapped resources, 'fConfig', 'fWidth', 'fHeight', and 'fOrigin; will always be filled in
431 // from the wrapped resource.
432 GrPixelConfig fConfig;
433 int fWidth;
434 int fHeight;
435 GrSurfaceOrigin fOrigin;
Chris Dalton706a6ff2017-11-29 22:01:06 -0700436 SkBackingFit fFit; // always kApprox for lazy-callback resources
437 // always kExact for wrapped resources
438 mutable SkBudgeted fBudgeted; // always kYes for lazy-callback resources
439 // set from the backing resource for wrapped resources
Robert Phillipsb726d582017-03-09 16:36:32 -0500440 // mutable bc of SkSurface/SkImage wishy-washiness
Robert Phillipsc787e492017-02-28 11:26:32 -0500441 const uint32_t fFlags;
Robert Phillipsa4c41b32017-03-15 13:02:45 -0400442
Robert Phillips294870f2016-11-11 12:38:40 -0500443 const UniqueID fUniqueID; // set from the backing resource for wrapped resources
robertphillips76948d42016-05-04 12:47:41 -0700444
Chris Dalton706a6ff2017-11-29 22:01:06 -0700445 LazyInstantiateCallback fLazyInstantiateCallback;
446 SkDEBUGCODE(virtual void validateLazyTexture(const GrTexture*) = 0;)
447
Robert Phillips8bc06d02016-11-01 17:28:40 -0400448 static const size_t kInvalidGpuMemorySize = ~static_cast<size_t>(0);
Robert Phillips29e52f12016-11-03 10:19:14 -0400449 SkDEBUGCODE(size_t getRawGpuMemorySize_debugOnly() const { return fGpuMemorySize; })
450
Brian Salomonbb5711a2017-05-17 13:49:59 -0400451 virtual size_t onUninstantiatedGpuMemorySize() const = 0;
Robert Phillips29e52f12016-11-03 10:19:14 -0400452
Brian Salomond17b4a62017-05-23 16:53:47 -0400453 bool fNeedsClear;
454
Robert Phillips8bc06d02016-11-01 17:28:40 -0400455 // This entry is lazily evaluated so, when the proxy wraps a resource, the resource
456 // will be called but, when the proxy is deferred, it will compute the answer itself.
457 // If the proxy computes its own answer that answer is checked (in debug mode) in
458 // the instantiation method.
459 mutable size_t fGpuMemorySize;
460
Robert Phillipsf2361d22016-10-25 14:20:06 -0400461 // The last opList that wrote to or is currently going to write to this surface
Robert Phillipsb6deea82017-05-11 14:14:30 -0400462 // The opList can be closed (e.g., no surface context is currently bound
463 // to this proxy).
Robert Phillipsf2361d22016-10-25 14:20:06 -0400464 // This back-pointer is required so that we can add a dependancy between
465 // the opList used to create the current contents of this surface
466 // and the opList of a destination surface to which this one is being drawn or copied.
Robert Phillips6cdc22c2017-05-11 16:29:14 -0400467 // This pointer is unreffed. OpLists own a ref on their surface proxies.
Robert Phillipsf2361d22016-10-25 14:20:06 -0400468 GrOpList* fLastOpList;
469
Robert Phillipsc7635fa2016-10-28 13:25:24 -0400470 typedef GrIORefProxy INHERITED;
robertphillips76948d42016-05-04 12:47:41 -0700471};
472
473#endif