| 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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 } | 71 } |
| 72 | 72 |
| 73 GrContext* GrGpuResource::getContext() { | 73 GrContext* GrGpuResource::getContext() { |
| 74 if (fGpu) { | 74 if (fGpu) { |
| 75 return fGpu->getContext(); | 75 return fGpu->getContext(); |
| 76 } else { | 76 } else { |
| 77 return NULL; | 77 return NULL; |
| 78 } | 78 } |
| 79 } | 79 } |
| 80 | 80 |
| 81 bool GrGpuResource::setCacheEntry(GrResourceCacheEntry* cacheEntry) { |
| 82 // GrResourceCache never changes the cacheEntry once one has been added. |
| 83 SkASSERT(NULL == cacheEntry || NULL == fCacheEntry); |
| 84 |
| 85 fCacheEntry = cacheEntry; |
| 86 if (this->wasDestroyed() || NULL == cacheEntry) { |
| 87 return true; |
| 88 } |
| 89 |
| 90 if (!cacheEntry->key().isScratch()) { |
| 91 if (!get_resource_cache2(fGpu)->didAddContentKey(this)) { |
| 92 fCacheEntry = NULL; |
| 93 return false; |
| 94 } |
| 95 } |
| 96 return true; |
| 97 } |
| 98 |
| 81 void GrGpuResource::notifyIsPurgable() const { | 99 void GrGpuResource::notifyIsPurgable() const { |
| 82 if (fCacheEntry && !this->wasDestroyed()) { | 100 if (fCacheEntry && !this->wasDestroyed()) { |
| 83 get_resource_cache(fGpu)->notifyPurgable(this); | 101 get_resource_cache(fGpu)->notifyPurgable(this); |
| 84 } | 102 } |
| 85 } | 103 } |
| 86 | 104 |
| 87 void GrGpuResource::setScratchKey(const GrResourceKey& scratchKey) { | 105 void GrGpuResource::setScratchKey(const GrResourceKey& scratchKey) { |
| 88 SkASSERT(fScratchKey.isNullScratch()); | 106 SkASSERT(fScratchKey.isNullScratch()); |
| 89 SkASSERT(scratchKey.isScratch()); | 107 SkASSERT(scratchKey.isScratch()); |
| 90 SkASSERT(!scratchKey.isNullScratch()); | 108 SkASSERT(!scratchKey.isNullScratch()); |
| 91 fScratchKey = scratchKey; | 109 fScratchKey = scratchKey; |
| 92 } | 110 } |
| 93 | 111 |
| 94 const GrResourceKey* GrGpuResource::getContentKey() const { | 112 const GrResourceKey* GrGpuResource::getContentKey() const { |
| 113 // Currently scratch resources have a cache entry in GrResourceCache with a
scratch key. |
| 95 if (fCacheEntry && !fCacheEntry->key().isScratch()) { | 114 if (fCacheEntry && !fCacheEntry->key().isScratch()) { |
| 96 return &fCacheEntry->key(); | 115 return &fCacheEntry->key(); |
| 97 } | 116 } |
| 98 return NULL; | 117 return NULL; |
| 99 } | 118 } |
| 100 | 119 |
| 101 bool GrGpuResource::isScratch() const { | 120 bool GrGpuResource::isScratch() const { |
| 102 // Currently scratch resources have a cache entry in GrResourceCache with a
scratch key. | 121 SkASSERT(fScratchKey.isScratch()); |
| 103 return NULL != fCacheEntry && fCacheEntry->key().isScratch(); | 122 return NULL == this->getContentKey() && !fScratchKey.isNullScratch(); |
| 104 } | 123 } |
| 105 | 124 |
| 106 uint32_t GrGpuResource::CreateUniqueID() { | 125 uint32_t GrGpuResource::CreateUniqueID() { |
| 107 static int32_t gUniqueID = SK_InvalidUniqueID; | 126 static int32_t gUniqueID = SK_InvalidUniqueID; |
| 108 uint32_t id; | 127 uint32_t id; |
| 109 do { | 128 do { |
| 110 id = static_cast<uint32_t>(sk_atomic_inc(&gUniqueID) + 1); | 129 id = static_cast<uint32_t>(sk_atomic_inc(&gUniqueID) + 1); |
| 111 } while (id == SK_InvalidUniqueID); | 130 } while (id == SK_InvalidUniqueID); |
| 112 return id; | 131 return id; |
| 113 } | 132 } |
| OLD | NEW |