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 11 matching lines...) Expand all Loading... | |
22 SkASSERT(gpu); | 22 SkASSERT(gpu); |
23 SkASSERT(gpu->getContext()); | 23 SkASSERT(gpu->getContext()); |
24 SkASSERT(gpu->getContext()->getResourceCache()); | 24 SkASSERT(gpu->getContext()->getResourceCache()); |
25 return gpu->getContext()->getResourceCache(); | 25 return gpu->getContext()->getResourceCache(); |
26 } | 26 } |
27 | 27 |
28 GrGpuResource::GrGpuResource(GrGpu* gpu, bool isWrapped) | 28 GrGpuResource::GrGpuResource(GrGpu* gpu, bool isWrapped) |
29 : fGpu(gpu) | 29 : fGpu(gpu) |
30 , fCacheEntry(NULL) | 30 , fCacheEntry(NULL) |
31 , fUniqueID(CreateUniqueID()) | 31 , fUniqueID(CreateUniqueID()) |
32 , fScratchKey(GrResourceKey::NullScratchKey()) { | 32 , fScratchKey(GrResourceKey::NullScratchKey()) |
33 , fContentKeySet(false) { | |
33 if (isWrapped) { | 34 if (isWrapped) { |
34 fFlags = kWrapped_FlagBit; | 35 fFlags = kWrapped_FlagBit; |
35 } else { | 36 } else { |
36 fFlags = 0; | 37 fFlags = 0; |
37 } | 38 } |
38 } | 39 } |
39 | 40 |
40 void GrGpuResource::registerWithCache() { | 41 void GrGpuResource::registerWithCache() { |
41 get_resource_cache2(fGpu)->insertResource(this); | 42 get_resource_cache2(fGpu)->insertResource(this); |
42 } | 43 } |
(...skipping 28 matching lines...) Expand all Loading... | |
71 } | 72 } |
72 | 73 |
73 GrContext* GrGpuResource::getContext() { | 74 GrContext* GrGpuResource::getContext() { |
74 if (fGpu) { | 75 if (fGpu) { |
75 return fGpu->getContext(); | 76 return fGpu->getContext(); |
76 } else { | 77 } else { |
77 return NULL; | 78 return NULL; |
78 } | 79 } |
79 } | 80 } |
80 | 81 |
81 bool GrGpuResource::setCacheEntry(GrResourceCacheEntry* cacheEntry) { | 82 bool GrGpuResource::setContentKey(const GrResourceKey& contentKey) { |
83 SkASSERT(!contentKey.isScratch()); | |
84 // Currently this can only be called once and can't be called when the resou rce is scratch. | |
85 SkASSERT(this->internalHasRef()); | |
86 SkASSERT(!this->internalHasPendingIO()); | |
87 | |
88 if (fContentKeySet) { | |
robertphillips
2014/11/11 15:04:44
Assert in here?
bsalomon
2014/11/11 15:17:22
Unit tests exercise this behavior.
| |
89 return false; | |
90 } | |
91 | |
92 fContentKey = contentKey; | |
93 fContentKeySet = true; | |
94 | |
95 if (!get_resource_cache2(fGpu)->didSetContentKey(this)) { | |
96 fContentKeySet = false; | |
97 return false; | |
98 } | |
99 return true; | |
100 } | |
101 | |
102 void GrGpuResource::setCacheEntry(GrResourceCacheEntry* cacheEntry) { | |
82 // GrResourceCache never changes the cacheEntry once one has been added. | 103 // GrResourceCache never changes the cacheEntry once one has been added. |
83 SkASSERT(NULL == cacheEntry || NULL == fCacheEntry); | 104 SkASSERT(NULL == cacheEntry || NULL == fCacheEntry); |
84 | |
85 fCacheEntry = cacheEntry; | 105 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 } | 106 } |
98 | 107 |
99 void GrGpuResource::notifyIsPurgable() const { | 108 void GrGpuResource::notifyIsPurgable() const { |
100 if (fCacheEntry && !this->wasDestroyed()) { | 109 if (fCacheEntry && !this->wasDestroyed()) { |
101 get_resource_cache(fGpu)->notifyPurgable(this); | 110 get_resource_cache(fGpu)->notifyPurgable(this); |
102 } | 111 } |
103 } | 112 } |
104 | 113 |
105 void GrGpuResource::setScratchKey(const GrResourceKey& scratchKey) { | 114 void GrGpuResource::setScratchKey(const GrResourceKey& scratchKey) { |
106 SkASSERT(fScratchKey.isNullScratch()); | 115 SkASSERT(fScratchKey.isNullScratch()); |
107 SkASSERT(scratchKey.isScratch()); | 116 SkASSERT(scratchKey.isScratch()); |
108 SkASSERT(!scratchKey.isNullScratch()); | 117 SkASSERT(!scratchKey.isNullScratch()); |
109 fScratchKey = scratchKey; | 118 fScratchKey = scratchKey; |
110 } | 119 } |
111 | 120 |
112 const GrResourceKey* GrGpuResource::getContentKey() const { | 121 const GrResourceKey* GrGpuResource::getContentKey() const { |
113 // Currently scratch resources have a cache entry in GrResourceCache with a scratch key. | 122 if (fContentKeySet) { |
114 if (fCacheEntry && !fCacheEntry->key().isScratch()) { | 123 return &fContentKey; |
115 return &fCacheEntry->key(); | |
116 } | 124 } |
117 return NULL; | 125 return NULL; |
118 } | 126 } |
119 | 127 |
120 bool GrGpuResource::isScratch() const { | 128 bool GrGpuResource::isScratch() const { |
121 SkASSERT(fScratchKey.isScratch()); | 129 SkASSERT(fScratchKey.isScratch()); |
122 return NULL == this->getContentKey() && !fScratchKey.isNullScratch(); | 130 return NULL == this->getContentKey() && !fScratchKey.isNullScratch(); |
123 } | 131 } |
124 | 132 |
125 uint32_t GrGpuResource::CreateUniqueID() { | 133 uint32_t GrGpuResource::CreateUniqueID() { |
126 static int32_t gUniqueID = SK_InvalidUniqueID; | 134 static int32_t gUniqueID = SK_InvalidUniqueID; |
127 uint32_t id; | 135 uint32_t id; |
128 do { | 136 do { |
129 id = static_cast<uint32_t>(sk_atomic_inc(&gUniqueID) + 1); | 137 id = static_cast<uint32_t>(sk_atomic_inc(&gUniqueID) + 1); |
130 } while (id == SK_InvalidUniqueID); | 138 } while (id == SK_InvalidUniqueID); |
131 return id; | 139 return id; |
132 } | 140 } |
OLD | NEW |