| 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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 if (this->wasDestroyed()) { | 77 if (this->wasDestroyed()) { |
| 78 return; | 78 return; |
| 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::removeContentKey() { | 87 void GrGpuResource::removeUniqueKey() { |
| 88 SkASSERT(fContentKey.isValid()); | 88 SkASSERT(fUniqueKey.isValid()); |
| 89 get_resource_cache(fGpu)->resourceAccess().willRemoveContentKey(this); | 89 get_resource_cache(fGpu)->resourceAccess().willRemoveUniqueKey(this); |
| 90 fContentKey.reset(); | 90 fUniqueKey.reset(); |
| 91 } | 91 } |
| 92 | 92 |
| 93 bool GrGpuResource::setContentKey(const GrContentKey& key) { | 93 bool GrGpuResource::setUniqueKey(const GrUniqueKey& key) { |
| 94 // Currently this can only be called once and can't be called when the resou
rce is scratch. | 94 // Currently this can only be called once and can't be called when the resou
rce is scratch. |
| 95 SkASSERT(this->internalHasRef()); | 95 SkASSERT(this->internalHasRef()); |
| 96 SkASSERT(key.isValid()); | 96 SkASSERT(key.isValid()); |
| 97 | 97 |
| 98 // Wrapped and uncached resources can never have a content key. | 98 // Wrapped and uncached resources can never have a unique key. |
| 99 if (!this->resourcePriv().isBudgeted()) { | 99 if (!this->resourcePriv().isBudgeted()) { |
| 100 return false; | 100 return false; |
| 101 } | 101 } |
| 102 | 102 |
| 103 if (fContentKey.isValid() || this->wasDestroyed()) { | 103 if (fUniqueKey.isValid() || this->wasDestroyed()) { |
| 104 return false; | 104 return false; |
| 105 } | 105 } |
| 106 | 106 |
| 107 fContentKey = key; | 107 fUniqueKey = key; |
| 108 | 108 |
| 109 if (!get_resource_cache(fGpu)->resourceAccess().didSetContentKey(this)) { | 109 if (!get_resource_cache(fGpu)->resourceAccess().didSetUniqueKey(this)) { |
| 110 fContentKey.reset(); | 110 fUniqueKey.reset(); |
| 111 return false; | 111 return false; |
| 112 } | 112 } |
| 113 return true; | 113 return true; |
| 114 } | 114 } |
| 115 | 115 |
| 116 void GrGpuResource::notifyIsPurgeable() const { | 116 void GrGpuResource::notifyIsPurgeable() const { |
| 117 if (this->wasDestroyed()) { | 117 if (this->wasDestroyed()) { |
| 118 // We've already been removed from the cache. Goodbye cruel world! | 118 // We've already been removed from the cache. Goodbye cruel world! |
| 119 SkDELETE(this); | 119 SkDELETE(this); |
| 120 } else { | 120 } else { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 141 } | 141 } |
| 142 | 142 |
| 143 void GrGpuResource::makeBudgeted() { | 143 void GrGpuResource::makeBudgeted() { |
| 144 if (GrGpuResource::kUncached_LifeCycle == fLifeCycle) { | 144 if (GrGpuResource::kUncached_LifeCycle == fLifeCycle) { |
| 145 fLifeCycle = kCached_LifeCycle; | 145 fLifeCycle = kCached_LifeCycle; |
| 146 get_resource_cache(fGpu)->resourceAccess().didChangeBudgetStatus(this); | 146 get_resource_cache(fGpu)->resourceAccess().didChangeBudgetStatus(this); |
| 147 } | 147 } |
| 148 } | 148 } |
| 149 | 149 |
| 150 void GrGpuResource::makeUnbudgeted() { | 150 void GrGpuResource::makeUnbudgeted() { |
| 151 if (GrGpuResource::kCached_LifeCycle == fLifeCycle && !fContentKey.isValid()
) { | 151 if (GrGpuResource::kCached_LifeCycle == fLifeCycle && !fUniqueKey.isValid())
{ |
| 152 fLifeCycle = kUncached_LifeCycle; | 152 fLifeCycle = kUncached_LifeCycle; |
| 153 get_resource_cache(fGpu)->resourceAccess().didChangeBudgetStatus(this); | 153 get_resource_cache(fGpu)->resourceAccess().didChangeBudgetStatus(this); |
| 154 } | 154 } |
| 155 } | 155 } |
| 156 | 156 |
| 157 uint32_t GrGpuResource::CreateUniqueID() { | 157 uint32_t GrGpuResource::CreateUniqueID() { |
| 158 static int32_t gUniqueID = SK_InvalidUniqueID; | 158 static int32_t gUniqueID = SK_InvalidUniqueID; |
| 159 uint32_t id; | 159 uint32_t id; |
| 160 do { | 160 do { |
| 161 id = static_cast<uint32_t>(sk_atomic_inc(&gUniqueID) + 1); | 161 id = static_cast<uint32_t>(sk_atomic_inc(&gUniqueID) + 1); |
| 162 } while (id == SK_InvalidUniqueID); | 162 } while (id == SK_InvalidUniqueID); |
| 163 return id; | 163 return id; |
| 164 } | 164 } |
| OLD | NEW |