Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(181)

Side by Side Diff: src/gpu/GrGpuResource.cpp

Issue 921453002: Rename GrResourceCache2 to GrResourceCache (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/GrGpu.cpp ('k') | src/gpu/GrResourceCache.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "GrGpuResource.h" 9 #include "GrGpuResource.h"
10 #include "GrResourceCache2.h" 10 #include "GrResourceCache.h"
11 #include "GrGpu.h" 11 #include "GrGpu.h"
12 12
13 static inline GrResourceCache2* get_resource_cache2(GrGpu* gpu) { 13 static inline GrResourceCache* get_resource_cache(GrGpu* gpu) {
14 SkASSERT(gpu); 14 SkASSERT(gpu);
15 SkASSERT(gpu->getContext()); 15 SkASSERT(gpu->getContext());
16 SkASSERT(gpu->getContext()->getResourceCache2()); 16 SkASSERT(gpu->getContext()->getResourceCache());
17 return gpu->getContext()->getResourceCache2(); 17 return gpu->getContext()->getResourceCache();
18 } 18 }
19 19
20 GrGpuResource::GrGpuResource(GrGpu* gpu, LifeCycle lifeCycle) 20 GrGpuResource::GrGpuResource(GrGpu* gpu, LifeCycle lifeCycle)
21 : fGpu(gpu) 21 : fGpu(gpu)
22 , fGpuMemorySize(kInvalidGpuMemorySize) 22 , fGpuMemorySize(kInvalidGpuMemorySize)
23 , fLifeCycle(lifeCycle) 23 , fLifeCycle(lifeCycle)
24 , fUniqueID(CreateUniqueID()) { 24 , fUniqueID(CreateUniqueID()) {
25 } 25 }
26 26
27 void GrGpuResource::registerWithCache() { 27 void GrGpuResource::registerWithCache() {
28 get_resource_cache2(fGpu)->resourceAccess().insertResource(this); 28 get_resource_cache(fGpu)->resourceAccess().insertResource(this);
29 } 29 }
30 30
31 GrGpuResource::~GrGpuResource() { 31 GrGpuResource::~GrGpuResource() {
32 // The cache should have released or destroyed this resource. 32 // The cache should have released or destroyed this resource.
33 SkASSERT(this->wasDestroyed()); 33 SkASSERT(this->wasDestroyed());
34 } 34 }
35 35
36 void GrGpuResource::release() { 36 void GrGpuResource::release() {
37 SkASSERT(fGpu); 37 SkASSERT(fGpu);
38 this->onRelease(); 38 this->onRelease();
39 get_resource_cache2(fGpu)->resourceAccess().removeResource(this); 39 get_resource_cache(fGpu)->resourceAccess().removeResource(this);
40 fGpu = NULL; 40 fGpu = NULL;
41 fGpuMemorySize = 0; 41 fGpuMemorySize = 0;
42 } 42 }
43 43
44 void GrGpuResource::abandon() { 44 void GrGpuResource::abandon() {
45 SkASSERT(fGpu); 45 SkASSERT(fGpu);
46 this->onAbandon(); 46 this->onAbandon();
47 get_resource_cache2(fGpu)->resourceAccess().removeResource(this); 47 get_resource_cache(fGpu)->resourceAccess().removeResource(this);
48 fGpu = NULL; 48 fGpu = NULL;
49 fGpuMemorySize = 0; 49 fGpuMemorySize = 0;
50 } 50 }
51 51
52 const SkData* GrGpuResource::setCustomData(const SkData* data) { 52 const SkData* GrGpuResource::setCustomData(const SkData* data) {
53 SkSafeRef(data); 53 SkSafeRef(data);
54 fData.reset(data); 54 fData.reset(data);
55 return data; 55 return data;
56 } 56 }
57 57
(...skipping 14 matching lines...) Expand all
72 } 72 }
73 73
74 void GrGpuResource::didChangeGpuMemorySize() const { 74 void GrGpuResource::didChangeGpuMemorySize() const {
75 if (this->wasDestroyed()) { 75 if (this->wasDestroyed()) {
76 return; 76 return;
77 } 77 }
78 78
79 size_t oldSize = fGpuMemorySize; 79 size_t oldSize = fGpuMemorySize;
80 SkASSERT(kInvalidGpuMemorySize != oldSize); 80 SkASSERT(kInvalidGpuMemorySize != oldSize);
81 fGpuMemorySize = kInvalidGpuMemorySize; 81 fGpuMemorySize = kInvalidGpuMemorySize;
82 get_resource_cache2(fGpu)->resourceAccess().didChangeGpuMemorySize(this, old Size); 82 get_resource_cache(fGpu)->resourceAccess().didChangeGpuMemorySize(this, oldS ize);
83 } 83 }
84 84
85 void GrGpuResource::removeContentKey() { 85 void GrGpuResource::removeContentKey() {
86 SkASSERT(fContentKey.isValid()); 86 SkASSERT(fContentKey.isValid());
87 get_resource_cache2(fGpu)->resourceAccess().willRemoveContentKey(this); 87 get_resource_cache(fGpu)->resourceAccess().willRemoveContentKey(this);
88 fContentKey.reset(); 88 fContentKey.reset();
89 } 89 }
90 90
91 bool GrGpuResource::setContentKey(const GrContentKey& key) { 91 bool GrGpuResource::setContentKey(const GrContentKey& key) {
92 // Currently this can only be called once and can't be called when the resou rce is scratch. 92 // Currently this can only be called once and can't be called when the resou rce is scratch.
93 SkASSERT(this->internalHasRef()); 93 SkASSERT(this->internalHasRef());
94 SkASSERT(key.isValid()); 94 SkASSERT(key.isValid());
95 95
96 // Wrapped and uncached resources can never have a content key. 96 // Wrapped and uncached resources can never have a content key.
97 if (!this->cacheAccess().isBudgeted()) { 97 if (!this->cacheAccess().isBudgeted()) {
98 return false; 98 return false;
99 } 99 }
100 100
101 if (fContentKey.isValid() || this->wasDestroyed()) { 101 if (fContentKey.isValid() || this->wasDestroyed()) {
102 return false; 102 return false;
103 } 103 }
104 104
105 fContentKey = key; 105 fContentKey = key;
106 106
107 if (!get_resource_cache2(fGpu)->resourceAccess().didSetContentKey(this)) { 107 if (!get_resource_cache(fGpu)->resourceAccess().didSetContentKey(this)) {
108 fContentKey.reset(); 108 fContentKey.reset();
109 return false; 109 return false;
110 } 110 }
111 return true; 111 return true;
112 } 112 }
113 113
114 void GrGpuResource::notifyIsPurgeable() const { 114 void GrGpuResource::notifyIsPurgeable() const {
115 if (this->wasDestroyed()) { 115 if (this->wasDestroyed()) {
116 // We've already been removed from the cache. Goodbye cruel world! 116 // We've already been removed from the cache. Goodbye cruel world!
117 SkDELETE(this); 117 SkDELETE(this);
118 } else { 118 } else {
119 GrGpuResource* mutableThis = const_cast<GrGpuResource*>(this); 119 GrGpuResource* mutableThis = const_cast<GrGpuResource*>(this);
120 get_resource_cache2(fGpu)->resourceAccess().notifyPurgeable(mutableThis) ; 120 get_resource_cache(fGpu)->resourceAccess().notifyPurgeable(mutableThis);
121 } 121 }
122 } 122 }
123 123
124 void GrGpuResource::setScratchKey(const GrScratchKey& scratchKey) { 124 void GrGpuResource::setScratchKey(const GrScratchKey& scratchKey) {
125 SkASSERT(!fScratchKey.isValid()); 125 SkASSERT(!fScratchKey.isValid());
126 SkASSERT(scratchKey.isValid()); 126 SkASSERT(scratchKey.isValid());
127 // Wrapped resources can never have a scratch key. 127 // Wrapped resources can never have a scratch key.
128 if (this->isWrapped()) { 128 if (this->isWrapped()) {
129 return; 129 return;
130 } 130 }
131 fScratchKey = scratchKey; 131 fScratchKey = scratchKey;
132 } 132 }
133 133
134 void GrGpuResource::removeScratchKey() { 134 void GrGpuResource::removeScratchKey() {
135 if (!this->wasDestroyed() && fScratchKey.isValid()) { 135 if (!this->wasDestroyed() && fScratchKey.isValid()) {
136 get_resource_cache2(fGpu)->resourceAccess().willRemoveScratchKey(this); 136 get_resource_cache(fGpu)->resourceAccess().willRemoveScratchKey(this);
137 fScratchKey.reset(); 137 fScratchKey.reset();
138 } 138 }
139 } 139 }
140 140
141 void GrGpuResource::makeBudgeted() { 141 void GrGpuResource::makeBudgeted() {
142 if (GrGpuResource::kUncached_LifeCycle == fLifeCycle) { 142 if (GrGpuResource::kUncached_LifeCycle == fLifeCycle) {
143 fLifeCycle = kCached_LifeCycle; 143 fLifeCycle = kCached_LifeCycle;
144 get_resource_cache2(fGpu)->resourceAccess().didChangeBudgetStatus(this); 144 get_resource_cache(fGpu)->resourceAccess().didChangeBudgetStatus(this);
145 } 145 }
146 } 146 }
147 147
148 void GrGpuResource::makeUnbudgeted() { 148 void GrGpuResource::makeUnbudgeted() {
149 if (GrGpuResource::kCached_LifeCycle == fLifeCycle && !fContentKey.isValid() ) { 149 if (GrGpuResource::kCached_LifeCycle == fLifeCycle && !fContentKey.isValid() ) {
150 fLifeCycle = kUncached_LifeCycle; 150 fLifeCycle = kUncached_LifeCycle;
151 get_resource_cache2(fGpu)->resourceAccess().didChangeBudgetStatus(this); 151 get_resource_cache(fGpu)->resourceAccess().didChangeBudgetStatus(this);
152 } 152 }
153 } 153 }
154 154
155 uint32_t GrGpuResource::CreateUniqueID() { 155 uint32_t GrGpuResource::CreateUniqueID() {
156 static int32_t gUniqueID = SK_InvalidUniqueID; 156 static int32_t gUniqueID = SK_InvalidUniqueID;
157 uint32_t id; 157 uint32_t id;
158 do { 158 do {
159 id = static_cast<uint32_t>(sk_atomic_inc(&gUniqueID) + 1); 159 id = static_cast<uint32_t>(sk_atomic_inc(&gUniqueID) + 1);
160 } while (id == SK_InvalidUniqueID); 160 } while (id == SK_InvalidUniqueID);
161 return id; 161 return id;
162 } 162 }
OLDNEW
« no previous file with comments | « src/gpu/GrGpu.cpp ('k') | src/gpu/GrResourceCache.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698