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 | |
| 8 | #ifndef GrSurfaceProxy_DEFINED |
| 9 | #define GrSurfaceProxy_DEFINED |
| 10 | |
| 11 | #include "GrGpuResource.h" |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 12 | #include "GrSurface.h" |
Robert Phillips | 93f1633 | 2016-11-23 19:37:13 -0500 | [diff] [blame] | 13 | |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 14 | #include "SkRect.h" |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 15 | |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 16 | class GrCaps; |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 17 | class GrRenderTargetOpList; |
| 18 | class GrRenderTargetProxy; |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 19 | class GrResourceProvider; |
Robert Phillips | d46697a | 2017-01-25 12:10:37 -0500 | [diff] [blame] | 20 | class GrSurfaceContext; |
Robert Phillips | 757914d | 2017-01-25 15:48:30 -0500 | [diff] [blame] | 21 | class GrSurfaceProxyPriv; |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 22 | class GrTextureOpList; |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 23 | class GrTextureProxy; |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 24 | |
Robert Phillips | 123b7b8 | 2017-04-11 09:09:24 -0400 | [diff] [blame^] | 25 | //#define SK_DISABLE_DEFERRED_PROXIES 1 |
| 26 | |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 27 | // 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 |
| 30 | class GrIORefProxy : public SkNoncopyable { |
| 31 | public: |
| 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 | |
| 48 | if (!(--fRefCnt)) { |
| 49 | delete this; |
| 50 | return; |
| 51 | } |
| 52 | |
| 53 | this->validate(); |
| 54 | } |
| 55 | |
| 56 | void validate() const { |
| 57 | #ifdef SK_DEBUG |
robertphillips | 1125a03 | 2016-11-16 11:17:17 -0800 | [diff] [blame] | 58 | SkASSERT(fRefCnt >= 1); |
| 59 | SkASSERT(fPendingReads >= 0); |
| 60 | SkASSERT(fPendingWrites >= 0); |
| 61 | SkASSERT(fRefCnt + fPendingReads + fPendingWrites >= 1); |
| 62 | |
| 63 | if (fTarget) { |
| 64 | SkASSERT(!fPendingReads && !fPendingWrites); |
| 65 | // The backing GrSurface can have more refs than the proxy if the proxy |
| 66 | // started off wrapping an external resource (that came in with refs). |
| 67 | // The GrSurface should never have fewer refs than the proxy however. |
| 68 | SkASSERT(fTarget->fRefCnt >= fRefCnt); |
| 69 | } |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 70 | #endif |
| 71 | } |
| 72 | |
robertphillips | 1125a03 | 2016-11-16 11:17:17 -0800 | [diff] [blame] | 73 | int32_t getProxyRefCnt_TestOnly() const; |
| 74 | int32_t getBackingRefCnt_TestOnly() const; |
| 75 | int32_t getPendingReadCnt_TestOnly() const; |
| 76 | int32_t getPendingWriteCnt_TestOnly() const; |
| 77 | |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 78 | protected: |
robertphillips | 1125a03 | 2016-11-16 11:17:17 -0800 | [diff] [blame] | 79 | GrIORefProxy() : fTarget(nullptr), fRefCnt(1), fPendingReads(0), fPendingWrites(0) {} |
| 80 | GrIORefProxy(sk_sp<GrSurface> surface) : fRefCnt(1), fPendingReads(0), fPendingWrites(0) { |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 81 | // Since we're manually forwarding on refs & unrefs we don't want sk_sp doing |
| 82 | // anything extra. |
| 83 | fTarget = surface.release(); |
| 84 | } |
| 85 | virtual ~GrIORefProxy() { |
| 86 | // We don't unref 'fTarget' here since the 'unref' method will already |
| 87 | // have forwarded on the unref call that got use here. |
| 88 | } |
| 89 | |
robertphillips | 1125a03 | 2016-11-16 11:17:17 -0800 | [diff] [blame] | 90 | // This GrIORefProxy was deferred before but has just been instantiated. To |
| 91 | // make all the reffing & unreffing work out we now need to transfer any deferred |
| 92 | // refs & unrefs to the new GrSurface |
| 93 | void transferRefs() { |
| 94 | SkASSERT(fTarget); |
| 95 | |
| 96 | fTarget->fRefCnt += (fRefCnt-1); // don't xfer the proxy's creation ref |
| 97 | fTarget->fPendingReads += fPendingReads; |
| 98 | fTarget->fPendingWrites += fPendingWrites; |
| 99 | |
| 100 | fPendingReads = 0; |
| 101 | fPendingWrites = 0; |
| 102 | } |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 103 | |
Robert Phillips | 757914d | 2017-01-25 15:48:30 -0500 | [diff] [blame] | 104 | bool internalHasPendingIO() const { |
| 105 | if (fTarget) { |
| 106 | return fTarget->internalHasPendingIO(); |
| 107 | } |
| 108 | |
| 109 | return SkToBool(fPendingWrites | fPendingReads); |
| 110 | } |
| 111 | |
Robert Phillips | 7ee385e | 2017-03-30 08:02:11 -0400 | [diff] [blame] | 112 | bool internalHasPendingWrite() const { |
| 113 | if (fTarget) { |
| 114 | return fTarget->internalHasPendingWrite(); |
| 115 | } |
| 116 | |
| 117 | return SkToBool(fPendingWrites); |
| 118 | } |
| 119 | |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 120 | // For deferred proxies this will be null. For wrapped proxies it will point to the |
| 121 | // wrapped resource. |
| 122 | GrSurface* fTarget; |
robertphillips | 1125a03 | 2016-11-16 11:17:17 -0800 | [diff] [blame] | 123 | |
| 124 | private: |
| 125 | // This class is used to manage conversion of refs to pending reads/writes. |
| 126 | friend class GrGpuResourceRef; |
| 127 | template <typename, GrIOType> friend class GrPendingIOResource; |
| 128 | |
| 129 | void addPendingRead() const { |
| 130 | this->validate(); |
| 131 | |
| 132 | if (fTarget) { |
| 133 | fTarget->addPendingRead(); |
| 134 | return; |
| 135 | } |
| 136 | |
| 137 | ++fPendingReads; |
| 138 | } |
| 139 | |
| 140 | void completedRead() const { |
| 141 | this->validate(); |
| 142 | |
| 143 | if (fTarget) { |
| 144 | fTarget->completedRead(); |
| 145 | return; |
| 146 | } |
| 147 | |
| 148 | SkFAIL("How was the read completed if the Proxy hasn't been instantiated?"); |
| 149 | } |
| 150 | |
| 151 | void addPendingWrite() const { |
| 152 | this->validate(); |
| 153 | |
| 154 | if (fTarget) { |
| 155 | fTarget->addPendingWrite(); |
| 156 | return; |
| 157 | } |
| 158 | |
| 159 | ++fPendingWrites; |
| 160 | } |
| 161 | |
| 162 | void completedWrite() const { |
| 163 | this->validate(); |
| 164 | |
| 165 | if (fTarget) { |
| 166 | fTarget->completedWrite(); |
| 167 | return; |
| 168 | } |
| 169 | |
| 170 | SkFAIL("How was the write completed if the Proxy hasn't been instantiated?"); |
| 171 | } |
| 172 | |
| 173 | mutable int32_t fRefCnt; |
| 174 | mutable int32_t fPendingReads; |
| 175 | mutable int32_t fPendingWrites; |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 176 | }; |
| 177 | |
| 178 | class GrSurfaceProxy : public GrIORefProxy { |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 179 | public: |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 180 | static sk_sp<GrSurfaceProxy> MakeWrapped(sk_sp<GrSurface>); |
Robert Phillips | 63c6746 | 2017-02-15 14:19:01 -0500 | [diff] [blame] | 181 | static sk_sp<GrTextureProxy> MakeWrapped(sk_sp<GrTexture>); |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 182 | |
Robert Phillips | 26c90e0 | 2017-03-14 14:39:29 -0400 | [diff] [blame] | 183 | static sk_sp<GrTextureProxy> MakeDeferred(GrResourceProvider*, |
Robert Phillips | 7928e76 | 2017-02-28 16:30:28 -0500 | [diff] [blame] | 184 | const GrSurfaceDesc&, SkBackingFit, |
| 185 | SkBudgeted, uint32_t flags = 0); |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 186 | |
| 187 | // TODO: need to refine ownership semantics of 'srcData' if we're in completely |
| 188 | // deferred mode |
Robert Phillips | 26c90e0 | 2017-03-14 14:39:29 -0400 | [diff] [blame] | 189 | static sk_sp<GrTextureProxy> MakeDeferred(GrResourceProvider*, |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 190 | const GrSurfaceDesc&, SkBudgeted, |
| 191 | const void* srcData, size_t rowBytes); |
| 192 | |
Robert Phillips | d374948 | 2017-03-14 09:17:43 -0400 | [diff] [blame] | 193 | static sk_sp<GrSurfaceProxy> MakeWrappedBackend(GrContext*, GrBackendTextureDesc&); |
Robert Phillips | 26caf89 | 2017-01-27 10:58:31 -0500 | [diff] [blame] | 194 | |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 195 | const GrSurfaceDesc& desc() const { return fDesc; } |
| 196 | |
| 197 | GrSurfaceOrigin origin() const { |
| 198 | SkASSERT(kTopLeft_GrSurfaceOrigin == fDesc.fOrigin || |
| 199 | kBottomLeft_GrSurfaceOrigin == fDesc.fOrigin); |
| 200 | return fDesc.fOrigin; |
| 201 | } |
| 202 | int width() const { return fDesc.fWidth; } |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 203 | int height() const { return fDesc.fHeight; } |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 204 | GrPixelConfig config() const { return fDesc.fConfig; } |
| 205 | |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 206 | class UniqueID { |
| 207 | public: |
Robert Phillips | 7ee385e | 2017-03-30 08:02:11 -0400 | [diff] [blame] | 208 | static UniqueID InvalidID() { |
| 209 | return UniqueID(uint32_t(SK_InvalidUniqueID)); |
| 210 | } |
| 211 | |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 212 | // wrapped |
| 213 | explicit UniqueID(const GrGpuResource::UniqueID& id) : fID(id.asUInt()) { } |
| 214 | // deferred |
| 215 | UniqueID() : fID(GrGpuResource::CreateUniqueID()) { } |
| 216 | |
| 217 | uint32_t asUInt() const { return fID; } |
| 218 | |
| 219 | bool operator==(const UniqueID& other) const { |
| 220 | return fID == other.fID; |
| 221 | } |
| 222 | bool operator!=(const UniqueID& other) const { |
| 223 | return !(*this == other); |
| 224 | } |
| 225 | |
Robert Phillips | 7ee385e | 2017-03-30 08:02:11 -0400 | [diff] [blame] | 226 | void makeInvalid() { fID = SK_InvalidUniqueID; } |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 227 | bool isInvalid() const { return SK_InvalidUniqueID == fID; } |
| 228 | |
| 229 | private: |
Robert Phillips | 7ee385e | 2017-03-30 08:02:11 -0400 | [diff] [blame] | 230 | explicit UniqueID(uint32_t id) : fID(id) {} |
| 231 | |
| 232 | uint32_t fID; |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 233 | }; |
| 234 | |
| 235 | /* |
| 236 | * The contract for the uniqueID is: |
| 237 | * for wrapped resources: |
| 238 | * the uniqueID will match that of the wrapped resource |
| 239 | * |
| 240 | * for deferred resources: |
| 241 | * the uniqueID will be different from the real resource, when it is allocated |
| 242 | * the proxy's uniqueID will not change across the instantiate call |
| 243 | * |
| 244 | * the uniqueIDs of the proxies and the resources draw from the same pool |
| 245 | * |
| 246 | * What this boils down to is that the uniqueID of a proxy can be used to consistently |
| 247 | * track/identify a proxy but should never be used to distinguish between |
| 248 | * resources and proxies - beware! |
| 249 | */ |
| 250 | UniqueID uniqueID() const { return fUniqueID; } |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 251 | |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 252 | GrSurface* instantiate(GrResourceProvider* resourceProvider); |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 253 | |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 254 | /** |
robertphillips | 13a7eee | 2016-08-31 15:06:24 -0700 | [diff] [blame] | 255 | * Helper that gets the width and height of the surface as a bounding rectangle. |
| 256 | */ |
| 257 | SkRect getBoundsRect() const { return SkRect::MakeIWH(this->width(), this->height()); } |
Robert Phillips | 784b7bf | 2016-12-09 13:35:02 -0500 | [diff] [blame] | 258 | |
| 259 | int worstCaseWidth(const GrCaps& caps) const; |
| 260 | int worstCaseHeight(const GrCaps& caps) const; |
Robert Phillips | 93f1633 | 2016-11-23 19:37:13 -0500 | [diff] [blame] | 261 | |
robertphillips | 13a7eee | 2016-08-31 15:06:24 -0700 | [diff] [blame] | 262 | /** |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 263 | * @return the texture proxy associated with the surface proxy, may be NULL. |
| 264 | */ |
| 265 | virtual GrTextureProxy* asTextureProxy() { return nullptr; } |
| 266 | virtual const GrTextureProxy* asTextureProxy() const { return nullptr; } |
| 267 | |
| 268 | /** |
| 269 | * @return the render target proxy associated with the surface proxy, may be NULL. |
| 270 | */ |
| 271 | virtual GrRenderTargetProxy* asRenderTargetProxy() { return nullptr; } |
| 272 | virtual const GrRenderTargetProxy* asRenderTargetProxy() const { return nullptr; } |
| 273 | |
robertphillips | 13a7eee | 2016-08-31 15:06:24 -0700 | [diff] [blame] | 274 | /** |
| 275 | * Does the resource count against the resource budget? |
| 276 | */ |
| 277 | SkBudgeted isBudgeted() const { return fBudgeted; } |
| 278 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 279 | void setLastOpList(GrOpList* opList); |
| 280 | GrOpList* getLastOpList() { return fLastOpList; } |
| 281 | |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 282 | GrRenderTargetOpList* getLastRenderTargetOpList(); |
| 283 | GrTextureOpList* getLastTextureOpList(); |
| 284 | |
Robert Phillips | 8bc06d0 | 2016-11-01 17:28:40 -0400 | [diff] [blame] | 285 | /** |
| 286 | * Retrieves the amount of GPU memory that will be or currently is used by this resource |
| 287 | * in bytes. It is approximate since we aren't aware of additional padding or copies made |
| 288 | * by the driver. |
| 289 | * |
| 290 | * @return the amount of GPU memory used in bytes |
| 291 | */ |
| 292 | size_t gpuMemorySize() const { |
Robert Phillips | 8bc06d0 | 2016-11-01 17:28:40 -0400 | [diff] [blame] | 293 | if (kInvalidGpuMemorySize == fGpuMemorySize) { |
| 294 | fGpuMemorySize = this->onGpuMemorySize(); |
| 295 | SkASSERT(kInvalidGpuMemorySize != fGpuMemorySize); |
| 296 | } |
| 297 | return fGpuMemorySize; |
| 298 | } |
| 299 | |
Robert Phillips | e2f7d18 | 2016-12-15 09:23:05 -0500 | [diff] [blame] | 300 | // Helper function that creates a temporary SurfaceContext to perform the copy |
Robert Phillips | 0ae6faa | 2017-03-21 16:22:00 -0400 | [diff] [blame] | 301 | // It always returns a kExact-backed proxy bc it is used when converting an SkSpecialImage |
| 302 | // to an SkImage. |
Robert Phillips | 63c6746 | 2017-02-15 14:19:01 -0500 | [diff] [blame] | 303 | static sk_sp<GrTextureProxy> Copy(GrContext*, GrSurfaceProxy* src, |
Robert Phillips | e2f7d18 | 2016-12-15 09:23:05 -0500 | [diff] [blame] | 304 | SkIRect srcRect, SkBudgeted); |
| 305 | |
| 306 | // Copy the entire 'src' |
Robert Phillips | 0ae6faa | 2017-03-21 16:22:00 -0400 | [diff] [blame] | 307 | // It always returns a kExact-backed proxy bc it is used in SkGpuDevice::snapSpecial |
Robert Phillips | 63c6746 | 2017-02-15 14:19:01 -0500 | [diff] [blame] | 308 | static sk_sp<GrTextureProxy> Copy(GrContext* context, GrSurfaceProxy* src, |
| 309 | SkBudgeted budgeted); |
Robert Phillips | e2f7d18 | 2016-12-15 09:23:05 -0500 | [diff] [blame] | 310 | |
| 311 | // Test-only entry point - should decrease in use as proxies propagate |
Robert Phillips | d46697a | 2017-01-25 12:10:37 -0500 | [diff] [blame] | 312 | static sk_sp<GrSurfaceContext> TestCopy(GrContext* context, const GrSurfaceDesc& dstDesc, |
| 313 | GrSurfaceProxy* srcProxy); |
Robert Phillips | e2f7d18 | 2016-12-15 09:23:05 -0500 | [diff] [blame] | 314 | |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 315 | bool isWrapped_ForTesting() const; |
| 316 | |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 317 | SkDEBUGCODE(void validate(GrContext*) const;) |
| 318 | |
Robert Phillips | 757914d | 2017-01-25 15:48:30 -0500 | [diff] [blame] | 319 | // Provides access to functions that aren't part of the public API. |
| 320 | GrSurfaceProxyPriv priv(); |
| 321 | const GrSurfaceProxyPriv priv() const; |
| 322 | |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 323 | protected: |
robertphillips | 8abb370 | 2016-08-31 14:04:06 -0700 | [diff] [blame] | 324 | // Deferred version |
Robert Phillips | c787e49 | 2017-02-28 11:26:32 -0500 | [diff] [blame] | 325 | GrSurfaceProxy(const GrSurfaceDesc& desc, SkBackingFit fit, SkBudgeted budgeted, uint32_t flags) |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 326 | : fDesc(desc) |
| 327 | , fFit(fit) |
| 328 | , fBudgeted(budgeted) |
Robert Phillips | c787e49 | 2017-02-28 11:26:32 -0500 | [diff] [blame] | 329 | , fFlags(flags) |
Robert Phillips | a4c41b3 | 2017-03-15 13:02:45 -0400 | [diff] [blame] | 330 | // fMipColorMode is only valid for texturable proxies |
| 331 | , fMipColorMode(SkDestinationSurfaceColorMode::kLegacy) |
Robert Phillips | 8bc06d0 | 2016-11-01 17:28:40 -0400 | [diff] [blame] | 332 | , fGpuMemorySize(kInvalidGpuMemorySize) |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 333 | , fLastOpList(nullptr) { |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 334 | // Note: this ctor pulls a new uniqueID from the same pool at the GrGpuResources |
robertphillips | 8abb370 | 2016-08-31 14:04:06 -0700 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | // Wrapped version |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 338 | GrSurfaceProxy(sk_sp<GrSurface> surface, SkBackingFit fit); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 339 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 340 | virtual ~GrSurfaceProxy(); |
| 341 | |
Robert Phillips | 757914d | 2017-01-25 15:48:30 -0500 | [diff] [blame] | 342 | friend class GrSurfaceProxyPriv; |
| 343 | |
| 344 | // Methods made available via GrSurfaceProxyPriv |
| 345 | bool hasPendingIO() const { |
| 346 | return this->internalHasPendingIO(); |
| 347 | } |
| 348 | |
Robert Phillips | 7ee385e | 2017-03-30 08:02:11 -0400 | [diff] [blame] | 349 | bool hasPendingWrite() const { |
| 350 | return this->internalHasPendingWrite(); |
| 351 | } |
| 352 | |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 353 | // For wrapped resources, 'fDesc' will always be filled in from the wrapped resource. |
Robert Phillips | 0ae6faa | 2017-03-21 16:22:00 -0400 | [diff] [blame] | 354 | GrSurfaceDesc fDesc; |
| 355 | SkBackingFit fFit; // always exact for wrapped resources |
Robert Phillips | b726d58 | 2017-03-09 16:36:32 -0500 | [diff] [blame] | 356 | mutable SkBudgeted fBudgeted; // set from the backing resource for wrapped resources |
| 357 | // mutable bc of SkSurface/SkImage wishy-washiness |
Robert Phillips | c787e49 | 2017-02-28 11:26:32 -0500 | [diff] [blame] | 358 | const uint32_t fFlags; |
Robert Phillips | a4c41b3 | 2017-03-15 13:02:45 -0400 | [diff] [blame] | 359 | |
| 360 | SkDestinationSurfaceColorMode fMipColorMode; |
| 361 | |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 362 | const UniqueID fUniqueID; // set from the backing resource for wrapped resources |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 363 | |
Robert Phillips | 8bc06d0 | 2016-11-01 17:28:40 -0400 | [diff] [blame] | 364 | static const size_t kInvalidGpuMemorySize = ~static_cast<size_t>(0); |
Robert Phillips | 29e52f1 | 2016-11-03 10:19:14 -0400 | [diff] [blame] | 365 | SkDEBUGCODE(size_t getRawGpuMemorySize_debugOnly() const { return fGpuMemorySize; }) |
| 366 | |
| 367 | private: |
| 368 | virtual size_t onGpuMemorySize() const = 0; |
| 369 | |
Robert Phillips | 8bc06d0 | 2016-11-01 17:28:40 -0400 | [diff] [blame] | 370 | // This entry is lazily evaluated so, when the proxy wraps a resource, the resource |
| 371 | // will be called but, when the proxy is deferred, it will compute the answer itself. |
| 372 | // If the proxy computes its own answer that answer is checked (in debug mode) in |
| 373 | // the instantiation method. |
| 374 | mutable size_t fGpuMemorySize; |
| 375 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 376 | // The last opList that wrote to or is currently going to write to this surface |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 377 | // The opList can be closed (e.g., no render target context is currently bound |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 378 | // to this renderTarget). |
| 379 | // This back-pointer is required so that we can add a dependancy between |
| 380 | // the opList used to create the current contents of this surface |
| 381 | // and the opList of a destination surface to which this one is being drawn or copied. |
| 382 | GrOpList* fLastOpList; |
| 383 | |
Robert Phillips | 29e52f1 | 2016-11-03 10:19:14 -0400 | [diff] [blame] | 384 | |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 385 | typedef GrIORefProxy INHERITED; |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 386 | }; |
| 387 | |
| 388 | #endif |