OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #include "GrGpuResource.h" | 10 #include "GrGpuResource.h" |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 fContentKey = contentKey; | 91 fContentKey = contentKey; |
92 fContentKeySet = true; | 92 fContentKeySet = true; |
93 | 93 |
94 if (!get_resource_cache2(fGpu)->didSetContentKey(this)) { | 94 if (!get_resource_cache2(fGpu)->didSetContentKey(this)) { |
95 fContentKeySet = false; | 95 fContentKeySet = false; |
96 return false; | 96 return false; |
97 } | 97 } |
98 return true; | 98 return true; |
99 } | 99 } |
100 | 100 |
101 void GrGpuResource::setCacheEntry(GrResourceCacheEntry* cacheEntry) { | |
102 // GrResourceCache never changes the cacheEntry once one has been added. | |
103 SkASSERT(NULL == cacheEntry || NULL == fCacheEntry); | |
104 fCacheEntry = cacheEntry; | |
105 } | |
106 | |
107 void GrGpuResource::notifyIsPurgable() const { | 101 void GrGpuResource::notifyIsPurgable() const { |
108 if (fCacheEntry && !this->wasDestroyed()) { | 102 if (fCacheEntry && !this->wasDestroyed()) { |
109 get_resource_cache(fGpu)->notifyPurgable(this); | 103 get_resource_cache(fGpu)->notifyPurgable(this); |
110 } | 104 } |
111 } | 105 } |
112 | 106 |
113 void GrGpuResource::setScratchKey(const GrResourceKey& scratchKey) { | 107 void GrGpuResource::setScratchKey(const GrResourceKey& scratchKey) { |
114 SkASSERT(fScratchKey.isNullScratch()); | 108 SkASSERT(fScratchKey.isNullScratch()); |
115 SkASSERT(scratchKey.isScratch()); | 109 SkASSERT(scratchKey.isScratch()); |
116 SkASSERT(!scratchKey.isNullScratch()); | 110 SkASSERT(!scratchKey.isNullScratch()); |
117 fScratchKey = scratchKey; | 111 fScratchKey = scratchKey; |
118 } | 112 } |
119 | 113 |
120 const GrResourceKey* GrGpuResource::getContentKey() const { | |
121 if (fContentKeySet) { | |
122 return &fContentKey; | |
123 } | |
124 return NULL; | |
125 } | |
126 | |
127 bool GrGpuResource::isScratch() const { | |
128 SkASSERT(fScratchKey.isScratch()); | |
129 return NULL == this->getContentKey() && !fScratchKey.isNullScratch(); | |
130 } | |
131 | |
132 uint32_t GrGpuResource::CreateUniqueID() { | 114 uint32_t GrGpuResource::CreateUniqueID() { |
133 static int32_t gUniqueID = SK_InvalidUniqueID; | 115 static int32_t gUniqueID = SK_InvalidUniqueID; |
134 uint32_t id; | 116 uint32_t id; |
135 do { | 117 do { |
136 id = static_cast<uint32_t>(sk_atomic_inc(&gUniqueID) + 1); | 118 id = static_cast<uint32_t>(sk_atomic_inc(&gUniqueID) + 1); |
137 } while (id == SK_InvalidUniqueID); | 119 } while (id == SK_InvalidUniqueID); |
138 return id; | 120 return id; |
139 } | 121 } |
OLD | NEW |