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

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

Issue 707493002: Use GrResourceCache2 to service content key lookups (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: move #ifdef SK_SUPPORT_GPU Created 6 years, 1 month 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/GrResourceCache.h ('k') | src/gpu/GrResourceCache2.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 2010 Google Inc. 3 * Copyright 2010 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 "GrResourceCache.h" 9 #include "GrResourceCache.h"
10 #include "GrGpuResource.h" 10 #include "GrGpuResource.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 fKey(key), 42 fKey(key),
43 fResource(resource), 43 fResource(resource),
44 fCachedSize(resource->gpuMemorySize()), 44 fCachedSize(resource->gpuMemorySize()),
45 fIsExclusive(false) { 45 fIsExclusive(false) {
46 // we assume ownership of the resource, and will unref it when we die 46 // we assume ownership of the resource, and will unref it when we die
47 SkASSERT(resource); 47 SkASSERT(resource);
48 resource->ref(); 48 resource->ref();
49 } 49 }
50 50
51 GrResourceCacheEntry::~GrResourceCacheEntry() { 51 GrResourceCacheEntry::~GrResourceCacheEntry() {
52 fResource->setCacheEntry(NULL); 52 // We're relying on having the cache entry to remove this from GrResourceCac he2's content hash.
53 // fResource->setCacheEntry(NULL);
53 fResource->unref(); 54 fResource->unref();
54 } 55 }
55 56
56 #ifdef SK_DEBUG 57 #ifdef SK_DEBUG
57 void GrResourceCacheEntry::validate() const { 58 void GrResourceCacheEntry::validate() const {
58 SkASSERT(fResourceCache); 59 SkASSERT(fResourceCache);
59 SkASSERT(fResource); 60 SkASSERT(fResource);
60 SkASSERT(fResource->getCacheEntry() == this); 61 SkASSERT(fResource->getCacheEntry() == this);
61 SkASSERT(fResource->gpuMemorySize() == fCachedSize); 62 SkASSERT(fResource->gpuMemorySize() == fCachedSize);
62 fResource->validate(); 63 fResource->validate();
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 // scratch texture reuse is turned off. 179 // scratch texture reuse is turned off.
179 SkASSERT(resource->getCacheEntry()); 180 SkASSERT(resource->getCacheEntry());
180 if (resource->getCacheEntry()->key().getResourceType() == GrTexturePriv::Res ourceType() && 181 if (resource->getCacheEntry()->key().getResourceType() == GrTexturePriv::Res ourceType() &&
181 resource->getCacheEntry()->key().isScratch() && 182 resource->getCacheEntry()->key().isScratch() &&
182 !fCaps->reuseScratchTextures() && 183 !fCaps->reuseScratchTextures() &&
183 !(static_cast<const GrSurface*>(resource)->desc().fFlags & kRenderTarget _GrSurfaceFlag)) { 184 !(static_cast<const GrSurface*>(resource)->desc().fFlags & kRenderTarget _GrSurfaceFlag)) {
184 this->deleteResource(resource->getCacheEntry()); 185 this->deleteResource(resource->getCacheEntry());
185 } 186 }
186 } 187 }
187 188
188 GrGpuResource* GrResourceCache::find(const GrResourceKey& key) { 189 bool GrResourceCache::addResource(const GrResourceKey& key, GrGpuResource* resou rce) {
189 // GrResourceCache2 is responsible for scratch resources. 190 if (NULL != resource->getCacheEntry()) {
190 SkASSERT(!key.isScratch()); 191 return false;
191
192 GrAutoResourceCacheValidate atcv(this);
193
194 GrResourceCacheEntry* entry = fCache.find(key);
195 if (NULL == entry) {
196 return NULL;
197 } 192 }
198 193
199 // Make this resource MRU
200 this->internalDetach(entry);
201 this->attachToHead(entry);
202
203 return entry->fResource;
204 }
205
206 void GrResourceCache::addResource(const GrResourceKey& key, GrGpuResource* resou rce) {
207 SkASSERT(NULL == resource->getCacheEntry());
208 // we don't expect to create new resources during a purge. In theory 194 // we don't expect to create new resources during a purge. In theory
209 // this could cause purgeAsNeeded() into an infinite loop (e.g. 195 // this could cause purgeAsNeeded() into an infinite loop (e.g.
210 // each resource destroyed creates and locks 2 resources and 196 // each resource destroyed creates and locks 2 resources and
211 // unlocks 1 thereby causing a new purge). 197 // unlocks 1 thereby causing a new purge).
212 SkASSERT(!fPurging); 198 SkASSERT(!fPurging);
213 GrAutoResourceCacheValidate atcv(this); 199 GrAutoResourceCacheValidate atcv(this);
214 200
215 GrResourceCacheEntry* entry = SkNEW_ARGS(GrResourceCacheEntry, (this, key, r esource)); 201 GrResourceCacheEntry* entry = SkNEW_ARGS(GrResourceCacheEntry, (this, key, r esource));
216 resource->setCacheEntry(entry); 202 if (!resource->setCacheEntry(entry)) {
203 SkDELETE(entry);
204 this->purgeAsNeeded();
205 return false;
206 }
217 207
218 this->attachToHead(entry); 208 this->attachToHead(entry);
219 fCache.insert(key, entry); 209 fCache.insert(key, entry);
220
221 this->purgeAsNeeded(); 210 this->purgeAsNeeded();
211 return true;
222 } 212 }
223 213
224 void GrResourceCache::didIncreaseResourceSize(const GrResourceCacheEntry* entry, size_t amountInc) { 214 void GrResourceCache::didIncreaseResourceSize(const GrResourceCacheEntry* entry, size_t amountInc) {
225 fEntryBytes += amountInc; 215 fEntryBytes += amountInc;
226 this->purgeAsNeeded(); 216 this->purgeAsNeeded();
227 } 217 }
228 218
229 void GrResourceCache::didDecreaseResourceSize(const GrResourceCacheEntry* entry, size_t amountDec) { 219 void GrResourceCache::didDecreaseResourceSize(const GrResourceCacheEntry* entry, size_t amountDec) {
230 fEntryBytes -= amountDec; 220 fEntryBytes -= amountDec;
231 #ifdef SK_DEBUG 221 #ifdef SK_DEBUG
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 SkDebugf("Budget: %d items %d bytes\n", fMaxCount, fMaxBytes); 414 SkDebugf("Budget: %d items %d bytes\n", fMaxCount, fMaxBytes);
425 SkDebugf("\t\tEntry Count: current %d (%d locked, %d scratch %.2g%% full), h igh %d\n", 415 SkDebugf("\t\tEntry Count: current %d (%d locked, %d scratch %.2g%% full), h igh %d\n",
426 fEntryCount, locked, scratch, countUtilization, fHighWaterEntryC ount); 416 fEntryCount, locked, scratch, countUtilization, fHighWaterEntryC ount);
427 SkDebugf("\t\tEntry Bytes: current %d (%.2g%% full) high %d\n", 417 SkDebugf("\t\tEntry Bytes: current %d (%.2g%% full) high %d\n",
428 fEntryBytes, byteUtilization, fHighWaterEntryBytes); 418 fEntryBytes, byteUtilization, fHighWaterEntryBytes);
429 } 419 }
430 420
431 #endif 421 #endif
432 422
433 /////////////////////////////////////////////////////////////////////////////// 423 ///////////////////////////////////////////////////////////////////////////////
OLDNEW
« no previous file with comments | « src/gpu/GrResourceCache.h ('k') | src/gpu/GrResourceCache2.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698