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() { | 14 GrGpuRef::~GrGpuRef() { |
15 SkASSERT(0 == fRefCnt); | 15 SkASSERT(0 == fRefCnt); |
16 SkASSERT(0 == fPendingReads); | 16 SkASSERT(0 == fPendingReads); |
17 SkASSERT(0 == fPendingWrites); | 17 SkASSERT(0 == fPendingWrites); |
18 // Set to invalid values. | 18 // Set to invalid values. |
19 SkDEBUGCODE(fRefCnt = fPendingReads = fPendingWrites = -10;) | 19 SkDEBUGCODE(fRefCnt = fPendingReads = fPendingWrites = -10;) |
20 } | 20 } |
21 | 21 |
22 /////////////////////////////////////////////////////////////////////////////// | 22 /////////////////////////////////////////////////////////////////////////////// |
23 | 23 |
24 static inline GrResourceCache2* get_resource_cache2(GrGpu* gpu) { | 24 static inline GrResourceCache2* get_resource_cache2(GrGpu* gpu) { |
25 SkASSERT(NULL != gpu); | 25 SkASSERT(gpu); |
26 SkASSERT(NULL != gpu->getContext()); | 26 SkASSERT(gpu->getContext()); |
27 SkASSERT(NULL != gpu->getContext()->getResourceCache2()); | 27 SkASSERT(gpu->getContext()->getResourceCache2()); |
28 return gpu->getContext()->getResourceCache2(); | 28 return gpu->getContext()->getResourceCache2(); |
29 } | 29 } |
30 | 30 |
31 GrGpuResource::GrGpuResource(GrGpu* gpu, bool isWrapped) | 31 GrGpuResource::GrGpuResource(GrGpu* gpu, bool isWrapped) |
32 : fGpu(gpu) | 32 : fGpu(gpu) |
33 , fCacheEntry(NULL) | 33 , fCacheEntry(NULL) |
34 , fUniqueID(CreateUniqueID()) | 34 , fUniqueID(CreateUniqueID()) |
35 , fScratchKey(GrResourceKey::NullScratchKey()) { | 35 , fScratchKey(GrResourceKey::NullScratchKey()) { |
36 if (isWrapped) { | 36 if (isWrapped) { |
37 fFlags = kWrapped_FlagBit; | 37 fFlags = kWrapped_FlagBit; |
38 } else { | 38 } else { |
39 fFlags = 0; | 39 fFlags = 0; |
40 } | 40 } |
41 } | 41 } |
42 | 42 |
43 void GrGpuResource::registerWithCache() { | 43 void GrGpuResource::registerWithCache() { |
44 get_resource_cache2(fGpu)->insertResource(this); | 44 get_resource_cache2(fGpu)->insertResource(this); |
45 } | 45 } |
46 | 46 |
47 GrGpuResource::~GrGpuResource() { | 47 GrGpuResource::~GrGpuResource() { |
48 // subclass should have released this. | 48 // subclass should have released this. |
49 SkASSERT(this->wasDestroyed()); | 49 SkASSERT(this->wasDestroyed()); |
50 } | 50 } |
51 | 51 |
52 void GrGpuResource::release() { | 52 void GrGpuResource::release() { |
53 if (NULL != fGpu) { | 53 if (fGpu) { |
54 this->onRelease(); | 54 this->onRelease(); |
55 get_resource_cache2(fGpu)->removeResource(this); | 55 get_resource_cache2(fGpu)->removeResource(this); |
56 fGpu = NULL; | 56 fGpu = NULL; |
57 } | 57 } |
58 } | 58 } |
59 | 59 |
60 void GrGpuResource::abandon() { | 60 void GrGpuResource::abandon() { |
61 if (NULL != fGpu) { | 61 if (fGpu) { |
62 this->onAbandon(); | 62 this->onAbandon(); |
63 get_resource_cache2(fGpu)->removeResource(this); | 63 get_resource_cache2(fGpu)->removeResource(this); |
64 fGpu = NULL; | 64 fGpu = NULL; |
65 } | 65 } |
66 } | 66 } |
67 | 67 |
68 const GrContext* GrGpuResource::getContext() const { | 68 const GrContext* GrGpuResource::getContext() const { |
69 if (NULL != fGpu) { | 69 if (fGpu) { |
70 return fGpu->getContext(); | 70 return fGpu->getContext(); |
71 } else { | 71 } else { |
72 return NULL; | 72 return NULL; |
73 } | 73 } |
74 } | 74 } |
75 | 75 |
76 GrContext* GrGpuResource::getContext() { | 76 GrContext* GrGpuResource::getContext() { |
77 if (NULL != fGpu) { | 77 if (fGpu) { |
78 return fGpu->getContext(); | 78 return fGpu->getContext(); |
79 } else { | 79 } else { |
80 return NULL; | 80 return NULL; |
81 } | 81 } |
82 } | 82 } |
83 | 83 |
84 void GrGpuResource::setScratchKey(const GrResourceKey& scratchKey) { | 84 void GrGpuResource::setScratchKey(const GrResourceKey& scratchKey) { |
85 SkASSERT(fScratchKey.isNullScratch()); | 85 SkASSERT(fScratchKey.isNullScratch()); |
86 SkASSERT(scratchKey.isScratch()); | 86 SkASSERT(scratchKey.isScratch()); |
87 SkASSERT(!scratchKey.isNullScratch()); | 87 SkASSERT(!scratchKey.isNullScratch()); |
88 fScratchKey = scratchKey; | 88 fScratchKey = scratchKey; |
89 } | 89 } |
90 | 90 |
91 uint32_t GrGpuResource::CreateUniqueID() { | 91 uint32_t GrGpuResource::CreateUniqueID() { |
92 static int32_t gUniqueID = SK_InvalidUniqueID; | 92 static int32_t gUniqueID = SK_InvalidUniqueID; |
93 uint32_t id; | 93 uint32_t id; |
94 do { | 94 do { |
95 id = static_cast<uint32_t>(sk_atomic_inc(&gUniqueID) + 1); | 95 id = static_cast<uint32_t>(sk_atomic_inc(&gUniqueID) + 1); |
96 } while (id == SK_InvalidUniqueID); | 96 } while (id == SK_InvalidUniqueID); |
97 return id; | 97 return id; |
98 } | 98 } |
OLD | NEW |