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

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

Issue 1810323002: Cache render targets that render to wrapped textures Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 9 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
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 "GrContext.h" 10 #include "GrContext.h"
11 #include "GrResourceCache.h" 11 #include "GrResourceCache.h"
12 #include "GrGpu.h" 12 #include "GrGpu.h"
13 #include "GrGpuResourcePriv.h" 13 #include "GrGpuResourcePriv.h"
14 #include "SkTraceMemoryDump.h" 14 #include "SkTraceMemoryDump.h"
15 15
16 static inline GrResourceCache* get_resource_cache(GrGpu* gpu) { 16 static inline GrResourceCache* get_resource_cache(GrGpu* gpu) {
17 SkASSERT(gpu); 17 SkASSERT(gpu);
18 SkASSERT(gpu->getContext()); 18 SkASSERT(gpu->getContext());
19 SkASSERT(gpu->getContext()->getResourceCache()); 19 SkASSERT(gpu->getContext()->getResourceCache());
20 return gpu->getContext()->getResourceCache(); 20 return gpu->getContext()->getResourceCache();
21 } 21 }
22 22
23 GrGpuResource::GrGpuResource(GrGpu* gpu, LifeCycle lifeCycle) 23 GrGpuResource::GrGpuResource(GrGpu* gpu, SkBudgeted budgeted)
24 : fGpu(gpu) 24 : fGpu(gpu)
25 , fGpuMemorySize(kInvalidGpuMemorySize) 25 , fGpuMemorySize(kInvalidGpuMemorySize)
26 , fLifeCycle(lifeCycle) 26 , fBudgeted(budgeted)
27 , fUniqueID(CreateUniqueID()) { 27 , fUniqueID(CreateUniqueID()) {
28 SkDEBUGCODE(fCacheArrayIndex = -1); 28 SkDEBUGCODE(fCacheArrayIndex = -1);
29 } 29 }
30 30
31 void GrGpuResource::registerWithCache() { 31 void GrGpuResource::registerWithCache() {
32 get_resource_cache(fGpu)->resourceAccess().insertResource(this); 32 get_resource_cache(fGpu)->resourceAccess().insertResource(this);
33 } 33 }
34 34
35 GrGpuResource::~GrGpuResource() { 35 GrGpuResource::~GrGpuResource() {
36 // The cache should have released or destroyed this resource. 36 // The cache should have released or destroyed this resource.
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 162
163 // There is no need to call our notifyAllCntsAreZero function at this point since we already 163 // There is no need to call our notifyAllCntsAreZero function at this point since we already
164 // told the cache about the state of cnts. 164 // told the cache about the state of cnts.
165 return false; 165 return false;
166 } 166 }
167 167
168 void GrGpuResource::setScratchKey(const GrScratchKey& scratchKey) { 168 void GrGpuResource::setScratchKey(const GrScratchKey& scratchKey) {
169 SkASSERT(!fScratchKey.isValid()); 169 SkASSERT(!fScratchKey.isValid());
170 SkASSERT(scratchKey.isValid()); 170 SkASSERT(scratchKey.isValid());
171 // Wrapped resources can never have a scratch key. 171 // Wrapped resources can never have a scratch key.
172 if (this->resourcePriv().isExternal()) { 172 if (this->resourcePriv().refsWrappedResources()) {
173 SkASSERT(false);
173 return; 174 return;
174 } 175 }
175 fScratchKey = scratchKey; 176 fScratchKey = scratchKey;
176 } 177 }
177 178
178 void GrGpuResource::removeScratchKey() { 179 void GrGpuResource::removeScratchKey() {
179 if (!this->wasDestroyed() && fScratchKey.isValid()) { 180 if (!this->wasDestroyed() && fScratchKey.isValid()) {
180 get_resource_cache(fGpu)->resourceAccess().willRemoveScratchKey(this); 181 get_resource_cache(fGpu)->resourceAccess().willRemoveScratchKey(this);
181 fScratchKey.reset(); 182 fScratchKey.reset();
182 } 183 }
183 } 184 }
184 185
185 void GrGpuResource::makeBudgeted() { 186 void GrGpuResource::makeBudgeted() {
186 if (!this->wasDestroyed() && GrGpuResource::kUncached_LifeCycle == fLifeCycl e) { 187 if (!this->wasDestroyed() && SkBudgeted::kNo == fBudgeted) {
187 fLifeCycle = kCached_LifeCycle; 188 fBudgeted = SkBudgeted::kYes;
188 get_resource_cache(fGpu)->resourceAccess().didChangeBudgetStatus(this); 189 get_resource_cache(fGpu)->resourceAccess().didChangeBudgetStatus(this);
189 } 190 }
190 } 191 }
191 192
192 void GrGpuResource::makeUnbudgeted() { 193 void GrGpuResource::makeUnbudgeted() {
193 if (!this->wasDestroyed() && GrGpuResource::kCached_LifeCycle == fLifeCycle && 194 if (!this->wasDestroyed() && SkBudgeted::kYes == fBudgeted &&
194 !fUniqueKey.isValid()) { 195 !fUniqueKey.isValid()) {
195 fLifeCycle = kUncached_LifeCycle; 196 fBudgeted = SkBudgeted::kNo;
196 get_resource_cache(fGpu)->resourceAccess().didChangeBudgetStatus(this); 197 get_resource_cache(fGpu)->resourceAccess().didChangeBudgetStatus(this);
197 } 198 }
198 } 199 }
199 200
200 uint32_t GrGpuResource::CreateUniqueID() { 201 uint32_t GrGpuResource::CreateUniqueID() {
201 static int32_t gUniqueID = SK_InvalidUniqueID; 202 static int32_t gUniqueID = SK_InvalidUniqueID;
202 uint32_t id; 203 uint32_t id;
203 do { 204 do {
204 id = static_cast<uint32_t>(sk_atomic_inc(&gUniqueID) + 1); 205 id = static_cast<uint32_t>(sk_atomic_inc(&gUniqueID) + 1);
205 } while (id == SK_InvalidUniqueID); 206 } while (id == SK_InvalidUniqueID);
206 return id; 207 return id;
207 } 208 }
OLDNEW
« no previous file with comments | « src/gpu/GrGpu.cpp ('k') | src/gpu/GrGpuResourceCacheAccess.h » ('j') | src/gpu/gl/GrGLGpu.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698