| 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" |
| 11 #include "GrGpu.h" | 11 #include "GrGpu.h" |
| 12 #include "GrGpuResourcePriv.h" |
| 12 | 13 |
| 13 static inline GrResourceCache* get_resource_cache(GrGpu* gpu) { | 14 static inline GrResourceCache* get_resource_cache(GrGpu* gpu) { |
| 14 SkASSERT(gpu); | 15 SkASSERT(gpu); |
| 15 SkASSERT(gpu->getContext()); | 16 SkASSERT(gpu->getContext()); |
| 16 SkASSERT(gpu->getContext()->getResourceCache()); | 17 SkASSERT(gpu->getContext()->getResourceCache()); |
| 17 return gpu->getContext()->getResourceCache(); | 18 return gpu->getContext()->getResourceCache(); |
| 18 } | 19 } |
| 19 | 20 |
| 20 GrGpuResource::GrGpuResource(GrGpu* gpu, LifeCycle lifeCycle) | 21 GrGpuResource::GrGpuResource(GrGpu* gpu, LifeCycle lifeCycle) |
| 21 : fGpu(gpu) | 22 : fGpu(gpu) |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 get_resource_cache(fGpu)->resourceAccess().willRemoveContentKey(this); | 88 get_resource_cache(fGpu)->resourceAccess().willRemoveContentKey(this); |
| 88 fContentKey.reset(); | 89 fContentKey.reset(); |
| 89 } | 90 } |
| 90 | 91 |
| 91 bool GrGpuResource::setContentKey(const GrContentKey& key) { | 92 bool GrGpuResource::setContentKey(const GrContentKey& key) { |
| 92 // Currently this can only be called once and can't be called when the resou
rce is scratch. | 93 // Currently this can only be called once and can't be called when the resou
rce is scratch. |
| 93 SkASSERT(this->internalHasRef()); | 94 SkASSERT(this->internalHasRef()); |
| 94 SkASSERT(key.isValid()); | 95 SkASSERT(key.isValid()); |
| 95 | 96 |
| 96 // Wrapped and uncached resources can never have a content key. | 97 // Wrapped and uncached resources can never have a content key. |
| 97 if (!this->cacheAccess().isBudgeted()) { | 98 if (!this->resourcePriv().isBudgeted()) { |
| 98 return false; | 99 return false; |
| 99 } | 100 } |
| 100 | 101 |
| 101 if (fContentKey.isValid() || this->wasDestroyed()) { | 102 if (fContentKey.isValid() || this->wasDestroyed()) { |
| 102 return false; | 103 return false; |
| 103 } | 104 } |
| 104 | 105 |
| 105 fContentKey = key; | 106 fContentKey = key; |
| 106 | 107 |
| 107 if (!get_resource_cache(fGpu)->resourceAccess().didSetContentKey(this)) { | 108 if (!get_resource_cache(fGpu)->resourceAccess().didSetContentKey(this)) { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 } | 154 } |
| 154 | 155 |
| 155 uint32_t GrGpuResource::CreateUniqueID() { | 156 uint32_t GrGpuResource::CreateUniqueID() { |
| 156 static int32_t gUniqueID = SK_InvalidUniqueID; | 157 static int32_t gUniqueID = SK_InvalidUniqueID; |
| 157 uint32_t id; | 158 uint32_t id; |
| 158 do { | 159 do { |
| 159 id = static_cast<uint32_t>(sk_atomic_inc(&gUniqueID) + 1); | 160 id = static_cast<uint32_t>(sk_atomic_inc(&gUniqueID) + 1); |
| 160 } while (id == SK_InvalidUniqueID); | 161 } while (id == SK_InvalidUniqueID); |
| 161 return id; | 162 return id; |
| 162 } | 163 } |
| OLD | NEW |