| 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 GrGpuObject_DEFINED | 8 #ifndef GrGpuResource_DEFINED |
| 9 #define GrGpuObject_DEFINED | 9 #define GrGpuResource_DEFINED |
| 10 | 10 |
| 11 #include "SkInstCnt.h" | 11 #include "SkInstCnt.h" |
| 12 #include "SkTInternalLList.h" | 12 #include "SkTInternalLList.h" |
| 13 | 13 |
| 14 class GrResourceCacheEntry; | 14 class GrResourceCacheEntry; |
| 15 class GrGpu; | 15 class GrGpu; |
| 16 class GrContext; | 16 class GrContext; |
| 17 | 17 |
| 18 /** | 18 /** |
| 19 * Base class for objects that can be kept in the GrResourceCache. | 19 * Base class for objects that can be kept in the GrResourceCache. |
| 20 */ | 20 */ |
| 21 class GrGpuObject : public SkNoncopyable { | 21 class GrGpuResource : public SkNoncopyable { |
| 22 public: | 22 public: |
| 23 SK_DECLARE_INST_COUNT_ROOT(GrGpuObject) | 23 SK_DECLARE_INST_COUNT_ROOT(GrGpuResource) |
| 24 | 24 |
| 25 // These method signatures are written to mirror SkRefCnt. However, we don't
require | 25 // These method signatures are written to mirror SkRefCnt. However, we don't
require |
| 26 // thread safety as GrCacheable objects are not intended to cross thread bou
ndaries. | 26 // thread safety as GrCacheable objects are not intended to cross thread bou
ndaries. |
| 27 // internal_dispose() exists because of GrTexture's reliance on it. It will
be removed | 27 // internal_dispose() exists because of GrTexture's reliance on it. It will
be removed |
| 28 // soon. | 28 // soon. |
| 29 void ref() const { ++fRefCnt; } | 29 void ref() const { ++fRefCnt; } |
| 30 void unref() const { --fRefCnt; if (0 == fRefCnt) { this->internal_dispose()
; } } | 30 void unref() const { --fRefCnt; if (0 == fRefCnt) { this->internal_dispose()
; } } |
| 31 virtual void internal_dispose() const { SkDELETE(this); } | 31 virtual void internal_dispose() const { SkDELETE(this); } |
| 32 bool unique() const { return 1 == fRefCnt; } | 32 bool unique() const { return 1 == fRefCnt; } |
| 33 #ifdef SK_DEBUG | 33 #ifdef SK_DEBUG |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 GrResourceCacheEntry* getCacheEntry() { return fCacheEntry; } | 82 GrResourceCacheEntry* getCacheEntry() { return fCacheEntry; } |
| 83 | 83 |
| 84 /** | 84 /** |
| 85 * Gets an id that is unique for this GrCacheable object. It is static in th
at it does | 85 * Gets an id that is unique for this GrCacheable object. It is static in th
at it does |
| 86 * not change when the content of the GrCacheable object changes. This will
never return | 86 * not change when the content of the GrCacheable object changes. This will
never return |
| 87 * 0. | 87 * 0. |
| 88 */ | 88 */ |
| 89 uint32_t getUniqueID() const { return fUniqueID; } | 89 uint32_t getUniqueID() const { return fUniqueID; } |
| 90 | 90 |
| 91 protected: | 91 protected: |
| 92 GrGpuObject(GrGpu*, bool isWrapped); | 92 GrGpuResource(GrGpu*, bool isWrapped); |
| 93 virtual ~GrGpuObject(); | 93 virtual ~GrGpuResource(); |
| 94 | 94 |
| 95 bool isInCache() const { return NULL != fCacheEntry; } | 95 bool isInCache() const { return NULL != fCacheEntry; } |
| 96 | 96 |
| 97 GrGpu* getGpu() const { return fGpu; } | 97 GrGpu* getGpu() const { return fGpu; } |
| 98 | 98 |
| 99 // Derived classes should always call their parent class' onRelease | 99 // Derived classes should always call their parent class' onRelease |
| 100 // and onAbandon methods in their overrides. | 100 // and onAbandon methods in their overrides. |
| 101 virtual void onRelease() {}; | 101 virtual void onRelease() {}; |
| 102 virtual void onAbandon() {}; | 102 virtual void onAbandon() {}; |
| 103 | 103 |
| 104 bool isWrapped() const { return kWrapped_FlagBit & fFlags; } | 104 bool isWrapped() const { return kWrapped_FlagBit & fFlags; } |
| 105 | 105 |
| 106 /** | 106 /** |
| 107 * This entry point should be called whenever gpuMemorySize() begins | 107 * This entry point should be called whenever gpuMemorySize() begins |
| 108 * reporting a different size. If the object is in the cache, it will call | 108 * reporting a different size. If the object is in the cache, it will call |
| 109 * gpuMemorySize() immediately and pass the new size on to the resource | 109 * gpuMemorySize() immediately and pass the new size on to the resource |
| 110 * cache. | 110 * cache. |
| 111 */ | 111 */ |
| 112 void didChangeGpuMemorySize() const; | 112 void didChangeGpuMemorySize() const; |
| 113 | 113 |
| 114 private: | 114 private: |
| 115 #ifdef SK_DEBUG | 115 #ifdef SK_DEBUG |
| 116 friend class GrGpu; // for assert in GrGpu to access getGpu | 116 friend class GrGpu; // for assert in GrGpu to access getGpu |
| 117 #endif | 117 #endif |
| 118 | 118 |
| 119 static uint32_t CreateUniqueID(); | 119 static uint32_t CreateUniqueID(); |
| 120 | 120 |
| 121 // We're in an internal doubly linked list | 121 // We're in an internal doubly linked list |
| 122 SK_DECLARE_INTERNAL_LLIST_INTERFACE(GrGpuObject); | 122 SK_DECLARE_INTERNAL_LLIST_INTERFACE(GrGpuResource); |
| 123 | 123 |
| 124 GrGpu* fGpu; // not reffed. The GrGpu can be dele
ted while there | 124 GrGpu* fGpu; // not reffed. The GrGpu can be dele
ted while there |
| 125 // are still live GrGpuObjects. It w
ill call | 125 // are still live GrGpuResources. It
will call |
| 126 // release() on all such objects in
its destructor. | 126 // release() on all such objects in
its destructor. |
| 127 enum Flags { | 127 enum Flags { |
| 128 /** | 128 /** |
| 129 * This object wraps a GPU object given to us by the user. | 129 * This object wraps a GPU object given to us by the user. |
| 130 * Lifetime management is left up to the user (i.e., we will not | 130 * Lifetime management is left up to the user (i.e., we will not |
| 131 * free it). | 131 * free it). |
| 132 */ | 132 */ |
| 133 kWrapped_FlagBit = 0x1, | 133 kWrapped_FlagBit = 0x1, |
| 134 }; | 134 }; |
| 135 | 135 |
| 136 uint32_t fFlags; | 136 uint32_t fFlags; |
| 137 | 137 |
| 138 mutable int32_t fRefCnt; | 138 mutable int32_t fRefCnt; |
| 139 GrResourceCacheEntry* fCacheEntry; // NULL if not in cache | 139 GrResourceCacheEntry* fCacheEntry; // NULL if not in cache |
| 140 const uint32_t fUniqueID; | 140 const uint32_t fUniqueID; |
| 141 | 141 |
| 142 typedef SkNoncopyable INHERITED; | 142 typedef SkNoncopyable INHERITED; |
| 143 }; | 143 }; |
| 144 | 144 |
| 145 #endif | 145 #endif |
| OLD | NEW |