| 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 18 matching lines...) Expand all Loading... |
| 29 } else { | 29 } else { |
| 30 fFlags = 0; | 30 fFlags = 0; |
| 31 } | 31 } |
| 32 } | 32 } |
| 33 | 33 |
| 34 void GrGpuResource::registerWithCache() { | 34 void GrGpuResource::registerWithCache() { |
| 35 get_resource_cache2(fGpu)->resourceAccess().insertResource(this); | 35 get_resource_cache2(fGpu)->resourceAccess().insertResource(this); |
| 36 } | 36 } |
| 37 | 37 |
| 38 GrGpuResource::~GrGpuResource() { | 38 GrGpuResource::~GrGpuResource() { |
| 39 // subclass should have released this. | 39 // The cache should have released or destroyed this resource. |
| 40 SkASSERT(this->wasDestroyed()); | 40 SkASSERT(this->wasDestroyed()); |
| 41 } | 41 } |
| 42 | 42 |
| 43 void GrGpuResource::release() { | 43 void GrGpuResource::release() { |
| 44 if (fGpu) { | 44 SkASSERT(fGpu); |
| 45 this->onRelease(); | 45 this->onRelease(); |
| 46 get_resource_cache2(fGpu)->resourceAccess().removeResource(this); | 46 get_resource_cache2(fGpu)->resourceAccess().removeResource(this); |
| 47 fGpu = NULL; | 47 fGpu = NULL; |
| 48 fGpuMemorySize = 0; | 48 fGpuMemorySize = 0; |
| 49 } | |
| 50 } | 49 } |
| 51 | 50 |
| 52 void GrGpuResource::abandon() { | 51 void GrGpuResource::abandon() { |
| 53 if (fGpu) { | 52 SkASSERT(fGpu); |
| 54 this->onAbandon(); | 53 this->onAbandon(); |
| 55 get_resource_cache2(fGpu)->resourceAccess().removeResource(this); | 54 get_resource_cache2(fGpu)->resourceAccess().removeResource(this); |
| 56 fGpu = NULL; | 55 fGpu = NULL; |
| 57 fGpuMemorySize = 0; | 56 fGpuMemorySize = 0; |
| 58 } | |
| 59 } | 57 } |
| 60 | 58 |
| 61 const GrContext* GrGpuResource::getContext() const { | 59 const GrContext* GrGpuResource::getContext() const { |
| 62 if (fGpu) { | 60 if (fGpu) { |
| 63 return fGpu->getContext(); | 61 return fGpu->getContext(); |
| 64 } else { | 62 } else { |
| 65 return NULL; | 63 return NULL; |
| 66 } | 64 } |
| 67 } | 65 } |
| 68 | 66 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 83 SkASSERT(kInvalidGpuMemorySize != oldSize); | 81 SkASSERT(kInvalidGpuMemorySize != oldSize); |
| 84 fGpuMemorySize = kInvalidGpuMemorySize; | 82 fGpuMemorySize = kInvalidGpuMemorySize; |
| 85 get_resource_cache2(fGpu)->resourceAccess().didChangeGpuMemorySize(this, old
Size); | 83 get_resource_cache2(fGpu)->resourceAccess().didChangeGpuMemorySize(this, old
Size); |
| 86 } | 84 } |
| 87 | 85 |
| 88 bool GrGpuResource::setContentKey(const GrResourceKey& contentKey) { | 86 bool GrGpuResource::setContentKey(const GrResourceKey& contentKey) { |
| 89 // 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. |
| 90 SkASSERT(!contentKey.isScratch()); | 88 SkASSERT(!contentKey.isScratch()); |
| 91 SkASSERT(this->internalHasRef()); | 89 SkASSERT(this->internalHasRef()); |
| 92 | 90 |
| 93 if (fContentKeySet) { | 91 if (fContentKeySet || this->wasDestroyed()) { |
| 94 return false; | 92 return false; |
| 95 } | 93 } |
| 96 | 94 |
| 97 fContentKey = contentKey; | 95 fContentKey = contentKey; |
| 98 fContentKeySet = true; | 96 fContentKeySet = true; |
| 99 | 97 |
| 100 if (!get_resource_cache2(fGpu)->resourceAccess().didSetContentKey(this)) { | 98 if (!get_resource_cache2(fGpu)->resourceAccess().didSetContentKey(this)) { |
| 101 fContentKeySet = false; | 99 fContentKeySet = false; |
| 102 return false; | 100 return false; |
| 103 } | 101 } |
| 104 return true; | 102 return true; |
| 105 } | 103 } |
| 106 | 104 |
| 107 void GrGpuResource::notifyIsPurgable() const { | 105 void GrGpuResource::notifyIsPurgable() const { |
| 108 if (!this->wasDestroyed()) { | 106 if (this->wasDestroyed()) { |
| 109 get_resource_cache2(fGpu)->resourceAccess().notifyPurgable(this); | 107 // We've already been removed from the cache. Goodbye cruel world! |
| 108 SkDELETE(this); |
| 109 } else { |
| 110 GrGpuResource* mutableThis = const_cast<GrGpuResource*>(this); |
| 111 get_resource_cache2(fGpu)->resourceAccess().notifyPurgable(mutableThis); |
| 110 } | 112 } |
| 111 } | 113 } |
| 112 | 114 |
| 113 void GrGpuResource::setScratchKey(const GrResourceKey& scratchKey) { | 115 void GrGpuResource::setScratchKey(const GrResourceKey& scratchKey) { |
| 114 SkASSERT(fScratchKey.isNullScratch()); | 116 SkASSERT(fScratchKey.isNullScratch()); |
| 115 SkASSERT(scratchKey.isScratch()); | 117 SkASSERT(scratchKey.isScratch()); |
| 116 SkASSERT(!scratchKey.isNullScratch()); | 118 SkASSERT(!scratchKey.isNullScratch()); |
| 117 fScratchKey = scratchKey; | 119 fScratchKey = scratchKey; |
| 118 } | 120 } |
| 119 | 121 |
| 120 uint32_t GrGpuResource::CreateUniqueID() { | 122 uint32_t GrGpuResource::CreateUniqueID() { |
| 121 static int32_t gUniqueID = SK_InvalidUniqueID; | 123 static int32_t gUniqueID = SK_InvalidUniqueID; |
| 122 uint32_t id; | 124 uint32_t id; |
| 123 do { | 125 do { |
| 124 id = static_cast<uint32_t>(sk_atomic_inc(&gUniqueID) + 1); | 126 id = static_cast<uint32_t>(sk_atomic_inc(&gUniqueID) + 1); |
| 125 } while (id == SK_InvalidUniqueID); | 127 } while (id == SK_InvalidUniqueID); |
| 126 return id; | 128 return id; |
| 127 } | 129 } |
| OLD | NEW |