| 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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 size_t oldSize = fGpuMemorySize; | 80 size_t oldSize = fGpuMemorySize; |
| 81 SkASSERT(kInvalidGpuMemorySize != oldSize); | 81 SkASSERT(kInvalidGpuMemorySize != oldSize); |
| 82 fGpuMemorySize = kInvalidGpuMemorySize; | 82 fGpuMemorySize = kInvalidGpuMemorySize; |
| 83 get_resource_cache2(fGpu)->resourceAccess().didChangeGpuMemorySize(this, old
Size); | 83 get_resource_cache2(fGpu)->resourceAccess().didChangeGpuMemorySize(this, old
Size); |
| 84 } | 84 } |
| 85 | 85 |
| 86 bool GrGpuResource::setContentKey(const GrResourceKey& contentKey) { | 86 bool GrGpuResource::setContentKey(const GrResourceKey& contentKey) { |
| 87 // Currently this can only be called once and can't be called when the resou
rce is scratch. | 87 // Currently this can only be called once and can't be called when the resou
rce is scratch. |
| 88 SkASSERT(!contentKey.isScratch()); | 88 SkASSERT(!contentKey.isScratch()); |
| 89 SkASSERT(this->internalHasRef()); | 89 SkASSERT(this->internalHasRef()); |
| 90 |
| 91 // Wrapped resources can never have a key. |
| 92 if (this->isWrapped()) { |
| 93 return false; |
| 94 } |
| 90 | 95 |
| 91 if (fContentKeySet || this->wasDestroyed()) { | 96 if (fContentKeySet || this->wasDestroyed()) { |
| 92 return false; | 97 return false; |
| 93 } | 98 } |
| 94 | 99 |
| 95 fContentKey = contentKey; | 100 fContentKey = contentKey; |
| 96 fContentKeySet = true; | 101 fContentKeySet = true; |
| 97 | 102 |
| 98 if (!get_resource_cache2(fGpu)->resourceAccess().didSetContentKey(this)) { | 103 if (!get_resource_cache2(fGpu)->resourceAccess().didSetContentKey(this)) { |
| 99 fContentKeySet = false; | 104 fContentKeySet = false; |
| 100 return false; | 105 return false; |
| 101 } | 106 } |
| 102 return true; | 107 return true; |
| 103 } | 108 } |
| 104 | 109 |
| 105 void GrGpuResource::notifyIsPurgable() const { | 110 void GrGpuResource::notifyIsPurgable() const { |
| 106 if (this->wasDestroyed()) { | 111 if (this->wasDestroyed()) { |
| 107 // We've already been removed from the cache. Goodbye cruel world! | 112 // We've already been removed from the cache. Goodbye cruel world! |
| 108 SkDELETE(this); | 113 SkDELETE(this); |
| 109 } else { | 114 } else { |
| 110 GrGpuResource* mutableThis = const_cast<GrGpuResource*>(this); | 115 GrGpuResource* mutableThis = const_cast<GrGpuResource*>(this); |
| 111 get_resource_cache2(fGpu)->resourceAccess().notifyPurgable(mutableThis); | 116 get_resource_cache2(fGpu)->resourceAccess().notifyPurgable(mutableThis); |
| 112 } | 117 } |
| 113 } | 118 } |
| 114 | 119 |
| 115 void GrGpuResource::setScratchKey(const GrResourceKey& scratchKey) { | 120 void GrGpuResource::setScratchKey(const GrResourceKey& scratchKey) { |
| 116 SkASSERT(fScratchKey.isNullScratch()); | 121 SkASSERT(fScratchKey.isNullScratch()); |
| 117 SkASSERT(scratchKey.isScratch()); | 122 SkASSERT(scratchKey.isScratch()); |
| 118 SkASSERT(!scratchKey.isNullScratch()); | 123 SkASSERT(!scratchKey.isNullScratch()); |
| 124 // Wrapped resources can never have a key. |
| 125 if (this->isWrapped()) { |
| 126 return; |
| 127 } |
| 119 fScratchKey = scratchKey; | 128 fScratchKey = scratchKey; |
| 120 } | 129 } |
| 121 | 130 |
| 122 uint32_t GrGpuResource::CreateUniqueID() { | 131 uint32_t GrGpuResource::CreateUniqueID() { |
| 123 static int32_t gUniqueID = SK_InvalidUniqueID; | 132 static int32_t gUniqueID = SK_InvalidUniqueID; |
| 124 uint32_t id; | 133 uint32_t id; |
| 125 do { | 134 do { |
| 126 id = static_cast<uint32_t>(sk_atomic_inc(&gUniqueID) + 1); | 135 id = static_cast<uint32_t>(sk_atomic_inc(&gUniqueID) + 1); |
| 127 } while (id == SK_InvalidUniqueID); | 136 } while (id == SK_InvalidUniqueID); |
| 128 return id; | 137 return id; |
| 129 } | 138 } |
| OLD | NEW |