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" | |
12 #include "GrGpu.h" | 11 #include "GrGpu.h" |
13 | 12 |
14 static inline GrResourceCache2* get_resource_cache2(GrGpu* gpu) { | |
15 SkASSERT(NULL != gpu); | |
16 SkASSERT(NULL != gpu->getContext()); | |
17 SkASSERT(NULL != gpu->getContext()->getResourceCache2()); | |
18 return gpu->getContext()->getResourceCache2(); | |
19 } | |
20 | |
21 GrGpuResource::GrGpuResource(GrGpu* gpu, bool isWrapped) | 13 GrGpuResource::GrGpuResource(GrGpu* gpu, bool isWrapped) |
22 : fGpu(gpu) | 14 : fRefCnt(1) |
23 , fRefCnt(1) | |
24 , fCacheEntry(NULL) | 15 , fCacheEntry(NULL) |
25 , fUniqueID(CreateUniqueID()) { | 16 , fUniqueID(CreateUniqueID()) { |
| 17 fGpu = gpu; |
26 if (isWrapped) { | 18 if (isWrapped) { |
27 fFlags = kWrapped_FlagBit; | 19 fFlags = kWrapped_FlagBit; |
28 } else { | 20 } else { |
29 fFlags = 0; | 21 fFlags = 0; |
30 } | 22 } |
31 get_resource_cache2(fGpu)->insertResource(this); | 23 fGpu->insertObject(this); |
32 } | 24 } |
33 | 25 |
34 GrGpuResource::~GrGpuResource() { | 26 GrGpuResource::~GrGpuResource() { |
35 SkASSERT(0 == fRefCnt); | 27 SkASSERT(0 == fRefCnt); |
36 // subclass should have released this. | 28 // subclass should have released this. |
37 SkASSERT(this->wasDestroyed()); | 29 SkASSERT(this->wasDestroyed()); |
38 } | 30 } |
39 | 31 |
40 void GrGpuResource::release() { | 32 void GrGpuResource::release() { |
41 if (NULL != fGpu) { | 33 if (NULL != fGpu) { |
42 this->onRelease(); | 34 this->onRelease(); |
43 get_resource_cache2(fGpu)->removeResource(this); | 35 fGpu->removeObject(this); |
44 fGpu = NULL; | 36 fGpu = NULL; |
45 } | 37 } |
46 } | 38 } |
47 | 39 |
48 void GrGpuResource::abandon() { | 40 void GrGpuResource::abandon() { |
49 if (NULL != fGpu) { | 41 if (NULL != fGpu) { |
50 this->onAbandon(); | 42 this->onAbandon(); |
51 get_resource_cache2(fGpu)->removeResource(this); | 43 fGpu->removeObject(this); |
52 fGpu = NULL; | 44 fGpu = NULL; |
53 } | 45 } |
54 } | 46 } |
55 | 47 |
56 const GrContext* GrGpuResource::getContext() const { | 48 const GrContext* GrGpuResource::getContext() const { |
57 if (NULL != fGpu) { | 49 if (NULL != fGpu) { |
58 return fGpu->getContext(); | 50 return fGpu->getContext(); |
59 } else { | 51 } else { |
60 return NULL; | 52 return NULL; |
61 } | 53 } |
62 } | 54 } |
63 | 55 |
64 GrContext* GrGpuResource::getContext() { | 56 GrContext* GrGpuResource::getContext() { |
65 if (NULL != fGpu) { | 57 if (NULL != fGpu) { |
66 return fGpu->getContext(); | 58 return fGpu->getContext(); |
67 } else { | 59 } else { |
68 return NULL; | 60 return NULL; |
69 } | 61 } |
70 } | 62 } |
71 | 63 |
72 uint32_t GrGpuResource::CreateUniqueID() { | 64 uint32_t GrGpuResource::CreateUniqueID() { |
73 static int32_t gUniqueID = SK_InvalidUniqueID; | 65 static int32_t gUniqueID = SK_InvalidUniqueID; |
74 uint32_t id; | 66 uint32_t id; |
75 do { | 67 do { |
76 id = static_cast<uint32_t>(sk_atomic_inc(&gUniqueID) + 1); | 68 id = static_cast<uint32_t>(sk_atomic_inc(&gUniqueID) + 1); |
77 } while (id == SK_InvalidUniqueID); | 69 } while (id == SK_InvalidUniqueID); |
78 return id; | 70 return id; |
79 } | 71 } |
OLD | NEW |