Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 GrResource_DEFINED | 8 #ifndef GrResource_DEFINED |
| 9 #define GrResource_DEFINED | 9 #define GrResource_DEFINED |
| 10 | 10 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 77 if (0 == fDeferredRefCount && this->needsDeferredUnref()) { | 77 if (0 == fDeferredRefCount && this->needsDeferredUnref()) { |
| 78 SkASSERT(this->getRefCnt() > 1); | 78 SkASSERT(this->getRefCnt() > 1); |
| 79 this->unref(); | 79 this->unref(); |
| 80 } | 80 } |
| 81 } | 81 } |
| 82 | 82 |
| 83 int getDeferredRefCount() const { return fDeferredRefCount; } | 83 int getDeferredRefCount() const { return fDeferredRefCount; } |
| 84 | 84 |
| 85 void setNeedsDeferredUnref() { fFlags |= kDeferredUnref_FlagBit; } | 85 void setNeedsDeferredUnref() { fFlags |= kDeferredUnref_FlagBit; } |
| 86 | 86 |
| 87 SK_DECLARE_NAMED_INTERNAL_LLIST_INTERFACE(GrResource, CacheLRU); | |
| 88 SK_DECLARE_NAMED_INTERNAL_LLIST_INTERFACE(GrResource, CacheEntryResources); | |
| 87 protected: | 89 protected: |
| 88 /** | 90 /** |
| 89 * isWrapped indicates we have wrapped a client-created backend resource in a GrResource. If it | 91 * isWrapped indicates we have wrapped a client-created backend resource in a GrResource. If it |
| 90 * is true then the client is responsible for the lifetime of the underlying backend resource. | 92 * is true then the client is responsible for the lifetime of the underlying backend resource. |
| 91 * Otherwise, our onRelease() should free the resource. | 93 * Otherwise, our onRelease() should free the resource. |
| 92 */ | 94 */ |
| 93 GrResource(GrGpu* gpu, bool isWrapped); | 95 GrResource(GrGpu* gpu, bool isWrapped); |
| 94 virtual ~GrResource(); | 96 virtual ~GrResource(); |
| 95 | 97 |
| 96 GrGpu* getGpu() const { return fGpu; } | 98 GrGpu* getGpu() const { return fGpu; } |
| 97 | 99 |
| 98 // Derived classes should always call their parent class' onRelease | 100 // Derived classes should always call their parent class' onRelease |
| 99 // and onAbandon methods in their overrides. | 101 // and onAbandon methods in their overrides. |
| 100 virtual void onRelease() {}; | 102 virtual void onRelease() {}; |
| 101 virtual void onAbandon() {}; | 103 virtual void onAbandon() {}; |
| 102 | 104 |
| 103 bool isInCache() const { return NULL != fCacheEntry; } | 105 bool isInCache() const { return NULL != fCacheEntry; } |
| 104 bool isWrapped() const { return kWrapped_FlagBit & fFlags; } | 106 bool isWrapped() const { return kWrapped_FlagBit & fFlags; } |
| 105 bool needsDeferredUnref() const { return SkToBool(kDeferredUnref_FlagBit & f Flags); } | 107 bool needsDeferredUnref() const { return SkToBool(kDeferredUnref_FlagBit & f Flags); } |
| 106 | 108 |
| 107 private: | 109 private: |
| 108 #ifdef SK_DEBUG | 110 #ifdef SK_DEBUG |
| 109 friend class GrGpu; // for assert in GrGpu to access getGpu | 111 friend class GrGpu; // for assert in GrGpu to access getGpu |
| 110 #endif | 112 #endif |
| 111 | 113 |
| 112 // We're in an internal doubly linked list | 114 // We're in an internal doubly linked list |
| 113 SK_DECLARE_INTERNAL_LLIST_INTERFACE(GrResource); | 115 SK_DECLARE_INTERNAL_LLIST_INTERFACE(GrResource); |
|
mtklein
2013/12/03 19:02:02
It seems weird to have one default and two named l
| |
| 116 SK_DECLARE_NAMED_INTERNAL_LLIST_INTERFACE_DATA(GrResource, CacheLRU); | |
| 117 SK_DECLARE_NAMED_INTERNAL_LLIST_INTERFACE_DATA(GrResource, CacheEntryResourc es); | |
| 118 | |
| 114 | 119 |
| 115 GrGpu* fGpu; // not reffed. The GrGpu can be dele ted while there | 120 GrGpu* fGpu; // not reffed. The GrGpu can be dele ted while there |
| 116 // are still live GrResources. It wi ll call | 121 // are still live GrResources. It wi ll call |
| 117 // release() on all such resources i n its | 122 // release() on all such resources i n its |
| 118 // destructor. | 123 // destructor. |
| 119 GrResourceEntry* fCacheEntry; // NULL if not in cache | 124 GrResourceEntry* fCacheEntry; // NULL if not in cache |
| 120 mutable int fDeferredRefCount; // How many references in deferred d rawing buffers. | 125 mutable int fDeferredRefCount; // How many references in deferred d rawing buffers. |
| 121 | 126 |
| 122 enum Flags { | 127 enum Flags { |
| 123 /** | 128 /** |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 134 * no one else wants to) but doesn't really want to keep it around. | 139 * no one else wants to) but doesn't really want to keep it around. |
| 135 */ | 140 */ |
| 136 kDeferredUnref_FlagBit = 0x2, | 141 kDeferredUnref_FlagBit = 0x2, |
| 137 }; | 142 }; |
| 138 uint32_t fFlags; | 143 uint32_t fFlags; |
| 139 | 144 |
| 140 typedef SkRefCnt INHERITED; | 145 typedef SkRefCnt INHERITED; |
| 141 }; | 146 }; |
| 142 | 147 |
| 143 #endif | 148 #endif |
| OLD | NEW |