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 #include "GrGpuResource.h" | 9 #include "GrGpuResource.h" |
10 #include "GrResourceCache.h" | 10 #include "GrResourceCache.h" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 } | 79 } |
80 | 80 |
81 size_t oldSize = fGpuMemorySize; | 81 size_t oldSize = fGpuMemorySize; |
82 SkASSERT(kInvalidGpuMemorySize != oldSize); | 82 SkASSERT(kInvalidGpuMemorySize != oldSize); |
83 fGpuMemorySize = kInvalidGpuMemorySize; | 83 fGpuMemorySize = kInvalidGpuMemorySize; |
84 get_resource_cache(fGpu)->resourceAccess().didChangeGpuMemorySize(this, oldS
ize); | 84 get_resource_cache(fGpu)->resourceAccess().didChangeGpuMemorySize(this, oldS
ize); |
85 } | 85 } |
86 | 86 |
87 void GrGpuResource::removeUniqueKey() { | 87 void GrGpuResource::removeUniqueKey() { |
88 SkASSERT(fUniqueKey.isValid()); | 88 SkASSERT(fUniqueKey.isValid()); |
89 get_resource_cache(fGpu)->resourceAccess().willRemoveUniqueKey(this); | 89 get_resource_cache(fGpu)->resourceAccess().removeUniqueKey(this); |
90 fUniqueKey.reset(); | |
91 } | 90 } |
92 | 91 |
93 bool GrGpuResource::setUniqueKey(const GrUniqueKey& key) { | 92 void GrGpuResource::setUniqueKey(const GrUniqueKey& key) { |
94 // Currently this can only be called once and can't be called when the resou
rce is scratch. | |
95 SkASSERT(this->internalHasRef()); | 93 SkASSERT(this->internalHasRef()); |
96 SkASSERT(key.isValid()); | 94 SkASSERT(key.isValid()); |
97 | 95 |
98 // Wrapped and uncached resources can never have a unique key. | 96 // Wrapped and uncached resources can never have a unique key. |
99 if (!this->resourcePriv().isBudgeted()) { | 97 if (!this->resourcePriv().isBudgeted()) { |
100 return false; | 98 return; |
101 } | 99 } |
102 | 100 |
103 if (fUniqueKey.isValid() || this->wasDestroyed()) { | 101 if (this->wasDestroyed()) { |
104 return false; | 102 return; |
105 } | 103 } |
106 | 104 |
107 fUniqueKey = key; | 105 get_resource_cache(fGpu)->resourceAccess().changeUniqueKey(this, key); |
108 | |
109 if (!get_resource_cache(fGpu)->resourceAccess().didSetUniqueKey(this)) { | |
110 fUniqueKey.reset(); | |
111 return false; | |
112 } | |
113 return true; | |
114 } | 106 } |
115 | 107 |
116 void GrGpuResource::notifyIsPurgeable() const { | 108 void GrGpuResource::notifyIsPurgeable() const { |
117 if (this->wasDestroyed()) { | 109 if (this->wasDestroyed()) { |
118 // We've already been removed from the cache. Goodbye cruel world! | 110 // We've already been removed from the cache. Goodbye cruel world! |
119 SkDELETE(this); | 111 SkDELETE(this); |
120 } else { | 112 } else { |
121 GrGpuResource* mutableThis = const_cast<GrGpuResource*>(this); | 113 GrGpuResource* mutableThis = const_cast<GrGpuResource*>(this); |
122 get_resource_cache(fGpu)->resourceAccess().notifyPurgeable(mutableThis); | 114 get_resource_cache(fGpu)->resourceAccess().notifyPurgeable(mutableThis); |
123 } | 115 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 } | 147 } |
156 | 148 |
157 uint32_t GrGpuResource::CreateUniqueID() { | 149 uint32_t GrGpuResource::CreateUniqueID() { |
158 static int32_t gUniqueID = SK_InvalidUniqueID; | 150 static int32_t gUniqueID = SK_InvalidUniqueID; |
159 uint32_t id; | 151 uint32_t id; |
160 do { | 152 do { |
161 id = static_cast<uint32_t>(sk_atomic_inc(&gUniqueID) + 1); | 153 id = static_cast<uint32_t>(sk_atomic_inc(&gUniqueID) + 1); |
162 } while (id == SK_InvalidUniqueID); | 154 } while (id == SK_InvalidUniqueID); |
163 return id; | 155 return id; |
164 } | 156 } |
OLD | NEW |