| 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" |
| 11 #include "GrResourceCache2.h" | 11 #include "GrResourceCache2.h" |
| 12 #include "GrGpu.h" | 12 #include "GrGpu.h" |
| 13 | 13 |
| 14 GrGpuRef::~GrGpuRef() { |
| 15 SkASSERT(0 == fRefCnt); |
| 16 SkASSERT(0 == fPendingReads); |
| 17 SkASSERT(0 == fPendingWrites); |
| 18 // Set to invalid values. |
| 19 SkDEBUGCODE(fRefCnt = fPendingReads = fPendingWrites = -10;) |
| 20 } |
| 21 |
| 22 /////////////////////////////////////////////////////////////////////////////// |
| 23 |
| 14 static inline GrResourceCache2* get_resource_cache2(GrGpu* gpu) { | 24 static inline GrResourceCache2* get_resource_cache2(GrGpu* gpu) { |
| 15 SkASSERT(NULL != gpu); | 25 SkASSERT(NULL != gpu); |
| 16 SkASSERT(NULL != gpu->getContext()); | 26 SkASSERT(NULL != gpu->getContext()); |
| 17 SkASSERT(NULL != gpu->getContext()->getResourceCache2()); | 27 SkASSERT(NULL != gpu->getContext()->getResourceCache2()); |
| 18 return gpu->getContext()->getResourceCache2(); | 28 return gpu->getContext()->getResourceCache2(); |
| 19 } | 29 } |
| 20 | 30 |
| 21 GrGpuResource::GrGpuResource(GrGpu* gpu, bool isWrapped) | 31 GrGpuResource::GrGpuResource(GrGpu* gpu, bool isWrapped) |
| 22 : fGpu(gpu) | 32 : fGpu(gpu) |
| 23 , fRefCnt(1) | |
| 24 , fCacheEntry(NULL) | 33 , fCacheEntry(NULL) |
| 25 , fUniqueID(CreateUniqueID()) | 34 , fUniqueID(CreateUniqueID()) |
| 26 , fScratchKey(GrResourceKey::NullScratchKey()) { | 35 , fScratchKey(GrResourceKey::NullScratchKey()) { |
| 27 if (isWrapped) { | 36 if (isWrapped) { |
| 28 fFlags = kWrapped_FlagBit; | 37 fFlags = kWrapped_FlagBit; |
| 29 } else { | 38 } else { |
| 30 fFlags = 0; | 39 fFlags = 0; |
| 31 } | 40 } |
| 32 } | 41 } |
| 33 | 42 |
| 34 void GrGpuResource::registerWithCache() { | 43 void GrGpuResource::registerWithCache() { |
| 35 get_resource_cache2(fGpu)->insertResource(this); | 44 get_resource_cache2(fGpu)->insertResource(this); |
| 36 } | 45 } |
| 37 | 46 |
| 38 GrGpuResource::~GrGpuResource() { | 47 GrGpuResource::~GrGpuResource() { |
| 39 SkASSERT(0 == fRefCnt); | |
| 40 // subclass should have released this. | 48 // subclass should have released this. |
| 41 SkASSERT(this->wasDestroyed()); | 49 SkASSERT(this->wasDestroyed()); |
| 42 } | 50 } |
| 43 | 51 |
| 44 void GrGpuResource::release() { | 52 void GrGpuResource::release() { |
| 45 if (NULL != fGpu) { | 53 if (NULL != fGpu) { |
| 46 this->onRelease(); | 54 this->onRelease(); |
| 47 get_resource_cache2(fGpu)->removeResource(this); | 55 get_resource_cache2(fGpu)->removeResource(this); |
| 48 fGpu = NULL; | 56 fGpu = NULL; |
| 49 } | 57 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 } | 89 } |
| 82 | 90 |
| 83 uint32_t GrGpuResource::CreateUniqueID() { | 91 uint32_t GrGpuResource::CreateUniqueID() { |
| 84 static int32_t gUniqueID = SK_InvalidUniqueID; | 92 static int32_t gUniqueID = SK_InvalidUniqueID; |
| 85 uint32_t id; | 93 uint32_t id; |
| 86 do { | 94 do { |
| 87 id = static_cast<uint32_t>(sk_atomic_inc(&gUniqueID) + 1); | 95 id = static_cast<uint32_t>(sk_atomic_inc(&gUniqueID) + 1); |
| 88 } while (id == SK_InvalidUniqueID); | 96 } while (id == SK_InvalidUniqueID); |
| 89 return id; | 97 return id; |
| 90 } | 98 } |
| OLD | NEW |