OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef GrGpuResource_DEFINED | 8 #ifndef GrGpuResource_DEFINED |
9 #define GrGpuResource_DEFINED | 9 #define GrGpuResource_DEFINED |
10 | 10 |
(...skipping 16 matching lines...) Expand all Loading... |
27 * 1) Normal ref (+ by ref(), - by unref()): These are used by code that is is
suing draw calls | 27 * 1) Normal ref (+ by ref(), - by unref()): These are used by code that is is
suing draw calls |
28 * that read and write the resource via GrDrawTarget and by any object that
must own a | 28 * that read and write the resource via GrDrawTarget and by any object that
must own a |
29 * GrGpuResource and is itself owned (directly or indirectly) by Skia-clien
t code. | 29 * GrGpuResource and is itself owned (directly or indirectly) by Skia-clien
t code. |
30 * 2) Pending read (+ by addPendingRead(), - by completedRead()): GrContext ha
s scheduled a read | 30 * 2) Pending read (+ by addPendingRead(), - by completedRead()): GrContext ha
s scheduled a read |
31 * of the resource by the GPU as a result of a skia API call but hasn't exe
cuted it yet. | 31 * of the resource by the GPU as a result of a skia API call but hasn't exe
cuted it yet. |
32 * 3) Pending write (+ by addPendingWrite(), - by completedWrite()): GrContext
has scheduled a | 32 * 3) Pending write (+ by addPendingWrite(), - by completedWrite()): GrContext
has scheduled a |
33 * write to the resource by the GPU as a result of a skia API call but hasn
't executed it yet. | 33 * write to the resource by the GPU as a result of a skia API call but hasn
't executed it yet. |
34 * | 34 * |
35 * The latter two ref types are private and intended only for Gr core code. | 35 * The latter two ref types are private and intended only for Gr core code. |
36 * | 36 * |
37 * When an item is purgable DERIVED:notifyIsPurgable() will be called (static po
ly morphism using | 37 * When an item is purgeable DERIVED:notifyIsPurgeable() will be called (static
poly morphism using |
38 * CRTP). GrIORef and GrGpuResource are separate classes for organizational reas
ons and to be | 38 * CRTP). GrIORef and GrGpuResource are separate classes for organizational reas
ons and to be |
39 * able to give access via friendship to only the functions related to pending I
O operations. | 39 * able to give access via friendship to only the functions related to pending I
O operations. |
40 */ | 40 */ |
41 template <typename DERIVED> class GrIORef : public SkNoncopyable { | 41 template <typename DERIVED> class GrIORef : public SkNoncopyable { |
42 public: | 42 public: |
43 SK_DECLARE_INST_COUNT(GrIORef) | 43 SK_DECLARE_INST_COUNT(GrIORef) |
44 | 44 |
45 // Some of the signatures are written to mirror SkRefCnt so that GrGpuResour
ce can work with | 45 // Some of the signatures are written to mirror SkRefCnt so that GrGpuResour
ce can work with |
46 // templated helper classes (e.g. SkAutoTUnref). However, we have different
categories of | 46 // templated helper classes (e.g. SkAutoTUnref). However, we have different
categories of |
47 // refs (e.g. pending reads). We also don't require thread safety as GrCache
able objects are | 47 // refs (e.g. pending reads). We also don't require thread safety as GrCache
able objects are |
(...skipping 14 matching lines...) Expand all Loading... |
62 SkASSERT(fRefCnt >= 0); | 62 SkASSERT(fRefCnt >= 0); |
63 SkASSERT(fPendingReads >= 0); | 63 SkASSERT(fPendingReads >= 0); |
64 SkASSERT(fPendingWrites >= 0); | 64 SkASSERT(fPendingWrites >= 0); |
65 SkASSERT(fRefCnt + fPendingReads + fPendingWrites >= 0); | 65 SkASSERT(fRefCnt + fPendingReads + fPendingWrites >= 0); |
66 #endif | 66 #endif |
67 } | 67 } |
68 | 68 |
69 protected: | 69 protected: |
70 GrIORef() : fRefCnt(1), fPendingReads(0), fPendingWrites(0) { } | 70 GrIORef() : fRefCnt(1), fPendingReads(0), fPendingWrites(0) { } |
71 | 71 |
72 bool isPurgable() const { return !this->internalHasRef() && !this->internalH
asPendingIO(); } | 72 bool isPurgeable() const { return !this->internalHasRef() && !this->internal
HasPendingIO(); } |
73 | 73 |
74 bool internalHasPendingRead() const { return SkToBool(fPendingReads); } | 74 bool internalHasPendingRead() const { return SkToBool(fPendingReads); } |
75 bool internalHasPendingWrite() const { return SkToBool(fPendingWrites); } | 75 bool internalHasPendingWrite() const { return SkToBool(fPendingWrites); } |
76 bool internalHasPendingIO() const { return SkToBool(fPendingWrites | fPendin
gReads); } | 76 bool internalHasPendingIO() const { return SkToBool(fPendingWrites | fPendin
gReads); } |
77 | 77 |
78 bool internalHasRef() const { return SkToBool(fRefCnt); } | 78 bool internalHasRef() const { return SkToBool(fRefCnt); } |
79 | 79 |
80 private: | 80 private: |
81 void addPendingRead() const { | 81 void addPendingRead() const { |
82 this->validate(); | 82 this->validate(); |
(...skipping 13 matching lines...) Expand all Loading... |
96 | 96 |
97 void completedWrite() const { | 97 void completedWrite() const { |
98 this->validate(); | 98 this->validate(); |
99 --fPendingWrites; | 99 --fPendingWrites; |
100 this->didUnref(); | 100 this->didUnref(); |
101 } | 101 } |
102 | 102 |
103 private: | 103 private: |
104 void didUnref() const { | 104 void didUnref() const { |
105 if (0 == fPendingReads && 0 == fPendingWrites && 0 == fRefCnt) { | 105 if (0 == fPendingReads && 0 == fPendingWrites && 0 == fRefCnt) { |
106 static_cast<const DERIVED*>(this)->notifyIsPurgable(); | 106 static_cast<const DERIVED*>(this)->notifyIsPurgeable(); |
107 } | 107 } |
108 } | 108 } |
109 | 109 |
110 mutable int32_t fRefCnt; | 110 mutable int32_t fRefCnt; |
111 mutable int32_t fPendingReads; | 111 mutable int32_t fPendingReads; |
112 mutable int32_t fPendingWrites; | 112 mutable int32_t fPendingWrites; |
113 | 113 |
114 // This class is used to manage conversion of refs to pending reads/writes. | 114 // This class is used to manage conversion of refs to pending reads/writes. |
115 friend class GrGpuResourceRef; | 115 friend class GrGpuResourceRef; |
116 friend class GrResourceCache2; // to check IO ref counts. | 116 friend class GrResourceCache2; // to check IO ref counts. |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 private: | 253 private: |
254 /** | 254 /** |
255 * Frees the object in the underlying 3D API. Called by CacheAccess. | 255 * Frees the object in the underlying 3D API. Called by CacheAccess. |
256 */ | 256 */ |
257 void release(); | 257 void release(); |
258 | 258 |
259 virtual size_t onGpuMemorySize() const = 0; | 259 virtual size_t onGpuMemorySize() const = 0; |
260 | 260 |
261 // See comments in CacheAccess. | 261 // See comments in CacheAccess. |
262 bool setContentKey(const GrContentKey& contentKey); | 262 bool setContentKey(const GrContentKey& contentKey); |
263 void notifyIsPurgable() const; | 263 void notifyIsPurgeable() const; |
264 void removeScratchKey(); | 264 void removeScratchKey(); |
265 void makeBudgeted(); | 265 void makeBudgeted(); |
266 void makeUnbudgeted(); | 266 void makeUnbudgeted(); |
267 | 267 |
268 #ifdef SK_DEBUG | 268 #ifdef SK_DEBUG |
269 friend class GrGpu; // for assert in GrGpu to access getGpu | 269 friend class GrGpu; // for assert in GrGpu to access getGpu |
270 #endif | 270 #endif |
271 | 271 |
272 static uint32_t CreateUniqueID(); | 272 static uint32_t CreateUniqueID(); |
273 | 273 |
274 // We're in an internal doubly linked list owned by GrResourceCache2 | 274 // We're in an internal doubly linked list owned by GrResourceCache2 |
275 SK_DECLARE_INTERNAL_LLIST_INTERFACE(GrGpuResource); | 275 SK_DECLARE_INTERNAL_LLIST_INTERFACE(GrGpuResource); |
276 | 276 |
277 | 277 |
278 static const size_t kInvalidGpuMemorySize = ~static_cast<size_t>(0); | 278 static const size_t kInvalidGpuMemorySize = ~static_cast<size_t>(0); |
279 GrScratchKey fScratchKey; | 279 GrScratchKey fScratchKey; |
280 GrContentKey fContentKey; | 280 GrContentKey fContentKey; |
281 | 281 |
282 // This is not ref'ed but abandon() or release() will be called before the G
rGpu object | 282 // This is not ref'ed but abandon() or release() will be called before the G
rGpu object |
283 // is destroyed. Those calls set will this to NULL. | 283 // is destroyed. Those calls set will this to NULL. |
284 GrGpu* fGpu; | 284 GrGpu* fGpu; |
285 mutable size_t fGpuMemorySize; | 285 mutable size_t fGpuMemorySize; |
286 | 286 |
287 LifeCycle fLifeCycle; | 287 LifeCycle fLifeCycle; |
288 const uint32_t fUniqueID; | 288 const uint32_t fUniqueID; |
289 | 289 |
290 SkAutoTUnref<const SkData> fData; | 290 SkAutoTUnref<const SkData> fData; |
291 | 291 |
292 typedef GrIORef<GrGpuResource> INHERITED; | 292 typedef GrIORef<GrGpuResource> INHERITED; |
293 friend class GrIORef<GrGpuResource>; // to access notifyIsPurgable. | 293 friend class GrIORef<GrGpuResource>; // to access notifyIsPurgeable. |
294 }; | 294 }; |
295 | 295 |
296 #endif | 296 #endif |
OLD | NEW |