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 | |
robertphillips
2014/11/07 20:32:13
Delete this next line ?
bsalomon
2014/11/07 21:48:44
Done.
| |
90 fCacheEntry = cacheEntry; | |
91 if (!cacheEntry->key().isScratch()) { | |
92 if (!get_resource_cache2(fGpu)->didAddContentKey(this)) { | |
93 fCacheEntry = NULL; | |
94 return false; | |
95 } | |
96 } | |
97 return true; | |
98 } | |
99 | |
81 void GrGpuResource::notifyIsPurgable() const { | 100 void GrGpuResource::notifyIsPurgable() const { |
82 if (fCacheEntry && !this->wasDestroyed()) { | 101 if (fCacheEntry && !this->wasDestroyed()) { |
83 get_resource_cache(fGpu)->notifyPurgable(this); | 102 get_resource_cache(fGpu)->notifyPurgable(this); |
84 } | 103 } |
85 } | 104 } |
86 | 105 |
87 void GrGpuResource::setScratchKey(const GrResourceKey& scratchKey) { | 106 void GrGpuResource::setScratchKey(const GrResourceKey& scratchKey) { |
88 SkASSERT(fScratchKey.isNullScratch()); | 107 SkASSERT(fScratchKey.isNullScratch()); |
89 SkASSERT(scratchKey.isScratch()); | 108 SkASSERT(scratchKey.isScratch()); |
90 SkASSERT(!scratchKey.isNullScratch()); | 109 SkASSERT(!scratchKey.isNullScratch()); |
91 fScratchKey = scratchKey; | 110 fScratchKey = scratchKey; |
92 } | 111 } |
93 | 112 |
94 const GrResourceKey* GrGpuResource::getContentKey() const { | 113 const GrResourceKey* GrGpuResource::getContentKey() const { |
114 // Currently scratch resources have a cache entry in GrResourceCache with a scratch key. | |
95 if (fCacheEntry && !fCacheEntry->key().isScratch()) { | 115 if (fCacheEntry && !fCacheEntry->key().isScratch()) { |
96 return &fCacheEntry->key(); | 116 return &fCacheEntry->key(); |
97 } | 117 } |
98 return NULL; | 118 return NULL; |
99 } | 119 } |
100 | 120 |
101 bool GrGpuResource::isScratch() const { | 121 bool GrGpuResource::isScratch() const { |
102 // Currently scratch resources have a cache entry in GrResourceCache with a scratch key. | 122 SkASSERT(fScratchKey.isScratch()); |
103 return NULL != fCacheEntry && fCacheEntry->key().isScratch(); | 123 return NULL == this->getContentKey() && !fScratchKey.isNullScratch(); |
104 } | 124 } |
105 | 125 |
106 uint32_t GrGpuResource::CreateUniqueID() { | 126 uint32_t GrGpuResource::CreateUniqueID() { |
107 static int32_t gUniqueID = SK_InvalidUniqueID; | 127 static int32_t gUniqueID = SK_InvalidUniqueID; |
108 uint32_t id; | 128 uint32_t id; |
109 do { | 129 do { |
110 id = static_cast<uint32_t>(sk_atomic_inc(&gUniqueID) + 1); | 130 id = static_cast<uint32_t>(sk_atomic_inc(&gUniqueID) + 1); |
111 } while (id == SK_InvalidUniqueID); | 131 } while (id == SK_InvalidUniqueID); |
112 return id; | 132 return id; |
113 } | 133 } |
OLD | NEW |