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