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

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

Issue 703303003: Add GrGpuResource::CacheAccess (Closed) Base URL: https://skia.googlesource.com/skia.git@nohash
Patch Set: fix warning 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/GrGpuResourceCacheAccess.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"
11 #include "GrGpuResourceCacheAccess.h"
11 #include "GrTexturePriv.h" 12 #include "GrTexturePriv.h"
12 13
13 DECLARE_SKMESSAGEBUS_MESSAGE(GrResourceInvalidatedMessage); 14 DECLARE_SKMESSAGEBUS_MESSAGE(GrResourceInvalidatedMessage);
14 15
15 /////////////////////////////////////////////////////////////////////////////// 16 ///////////////////////////////////////////////////////////////////////////////
16 17
17 void GrGpuResource::didChangeGpuMemorySize() const { 18 void GrGpuResource::didChangeGpuMemorySize() const {
18 if (this->isInCache()) { 19 if (this->cacheAccess().isInCache()) {
19 fCacheEntry->didChangeResourceSize(); 20 fCacheEntry->didChangeResourceSize();
20 } 21 }
21 } 22 }
22 23
23 /////////////////////////////////////////////////////////////////////////////// 24 ///////////////////////////////////////////////////////////////////////////////
24 25
25 GrResourceKey::ResourceType GrResourceKey::GenerateResourceType() { 26 GrResourceKey::ResourceType GrResourceKey::GenerateResourceType() {
26 static int32_t gNextType = 0; 27 static int32_t gNextType = 0;
27 28
28 int32_t type = sk_atomic_inc(&gNextType); 29 int32_t type = sk_atomic_inc(&gNextType);
(...skipping 18 matching lines...) Expand all
47 GrResourceCacheEntry::~GrResourceCacheEntry() { 48 GrResourceCacheEntry::~GrResourceCacheEntry() {
48 // We're relying on having the cache entry to remove this from GrResourceCac he2's content hash. 49 // We're relying on having the cache entry to remove this from GrResourceCac he2's content hash.
49 // fResource->setCacheEntry(NULL); 50 // fResource->setCacheEntry(NULL);
50 fResource->unref(); 51 fResource->unref();
51 } 52 }
52 53
53 #ifdef SK_DEBUG 54 #ifdef SK_DEBUG
54 void GrResourceCacheEntry::validate() const { 55 void GrResourceCacheEntry::validate() const {
55 SkASSERT(fResourceCache); 56 SkASSERT(fResourceCache);
56 SkASSERT(fResource); 57 SkASSERT(fResource);
57 SkASSERT(fResource->getCacheEntry() == this); 58 SkASSERT(fResource->cacheAccess().getCacheEntry() == this);
58 SkASSERT(fResource->gpuMemorySize() == fCachedSize); 59 SkASSERT(fResource->gpuMemorySize() == fCachedSize);
59 fResource->validate(); 60 fResource->validate();
60 } 61 }
61 #endif 62 #endif
62 63
63 void GrResourceCacheEntry::didChangeResourceSize() { 64 void GrResourceCacheEntry::didChangeResourceSize() {
64 size_t oldSize = fCachedSize; 65 size_t oldSize = fCachedSize;
65 fCachedSize = fResource->gpuMemorySize(); 66 fCachedSize = fResource->gpuMemorySize();
66 if (fCachedSize > oldSize) { 67 if (fCachedSize > oldSize) {
67 fResourceCache->didIncreaseResourceSize(this, fCachedSize - oldSize); 68 fResourceCache->didIncreaseResourceSize(this, fCachedSize - oldSize);
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 fHighWaterEntryCount = fEntryCount; 144 fHighWaterEntryCount = fEntryCount;
144 } 145 }
145 if (fHighWaterEntryBytes < fEntryBytes) { 146 if (fHighWaterEntryBytes < fEntryBytes) {
146 fHighWaterEntryBytes = fEntryBytes; 147 fHighWaterEntryBytes = fEntryBytes;
147 } 148 }
148 #endif 149 #endif
149 } 150 }
150 151
151 152
152 void GrResourceCache::makeResourceMRU(GrGpuResource* resource) { 153 void GrResourceCache::makeResourceMRU(GrGpuResource* resource) {
153 GrResourceCacheEntry* entry = resource->getCacheEntry(); 154 GrResourceCacheEntry* entry = resource->cacheAccess().getCacheEntry();
154 if (entry) { 155 if (entry) {
155 this->internalDetach(entry); 156 this->internalDetach(entry);
156 this->attachToHead(entry); 157 this->attachToHead(entry);
157 } 158 }
158 } 159 }
159 160
160 void GrResourceCache::notifyPurgable(const GrGpuResource* resource) { 161 void GrResourceCache::notifyPurgable(const GrGpuResource* resource) {
161 // Remove scratch textures from the cache the moment they become purgeable i f 162 // Remove scratch textures from the cache the moment they become purgeable i f
162 // scratch texture reuse is turned off. 163 // scratch texture reuse is turned off.
163 SkASSERT(resource->getCacheEntry()); 164 SkASSERT(resource->cacheAccess().getCacheEntry());
164 if (resource->isScratch()) { 165 if (resource->cacheAccess().isScratch()) {
165 const GrResourceKey& key = resource->getScratchKey(); 166 const GrResourceKey& key = resource->cacheAccess().getScratchKey();
166 if (key.getResourceType() == GrTexturePriv::ResourceType() && 167 if (key.getResourceType() == GrTexturePriv::ResourceType() &&
167 !fCaps->reuseScratchTextures() && 168 !fCaps->reuseScratchTextures() &&
168 !(static_cast<const GrSurface*>(resource)->desc().fFlags & kRenderTa rget_GrSurfaceFlag)) { 169 !(static_cast<const GrSurface*>(resource)->desc().fFlags & kRenderTa rget_GrSurfaceFlag)) {
169 this->deleteResource(resource->getCacheEntry()); 170 this->deleteResource(resource->cacheAccess().getCacheEntry());
170 } 171 }
171 } 172 }
172 } 173 }
173 174
174 bool GrResourceCache::addResource(const GrResourceKey& key, GrGpuResource* resou rce) { 175 bool GrResourceCache::addResource(const GrResourceKey& key, GrGpuResource* resou rce) {
175 if (NULL != resource->getCacheEntry()) { 176 if (NULL != resource->cacheAccess().getCacheEntry()) {
176 return false; 177 return false;
177 } 178 }
178 179
179 if (key.isScratch()) { 180 if (key.isScratch()) {
180 SkASSERT(resource->isScratch() && key == resource->getScratchKey()); 181 SkASSERT(resource->cacheAccess().isScratch());
182 SkASSERT(key == resource->cacheAccess().getScratchKey());
181 } else { 183 } else {
182 if (!resource->setContentKey(key)) { 184 if (!resource->cacheAccess().setContentKey(key)) {
183 return false; 185 return false;
184 } 186 }
185 } 187 }
186 188
187 // we don't expect to create new resources during a purge. In theory 189 // we don't expect to create new resources during a purge. In theory
188 // this could cause purgeAsNeeded() into an infinite loop (e.g. 190 // this could cause purgeAsNeeded() into an infinite loop (e.g.
189 // each resource destroyed creates and locks 2 resources and 191 // each resource destroyed creates and locks 2 resources and
190 // unlocks 1 thereby causing a new purge). 192 // unlocks 1 thereby causing a new purge).
191 SkASSERT(!fPurging); 193 SkASSERT(!fPurging);
192 GrAutoResourceCacheValidate atcv(this); 194 GrAutoResourceCacheValidate atcv(this);
193 195
194 GrResourceCacheEntry* entry = SkNEW_ARGS(GrResourceCacheEntry, (this, resour ce)); 196 GrResourceCacheEntry* entry = SkNEW_ARGS(GrResourceCacheEntry, (this, resour ce));
195 resource->setCacheEntry(entry); 197 resource->cacheAccess().setCacheEntry(entry);
196 198
197 this->attachToHead(entry); 199 this->attachToHead(entry);
198 this->purgeAsNeeded(); 200 this->purgeAsNeeded();
199 return true; 201 return true;
200 } 202 }
201 203
202 void GrResourceCache::didIncreaseResourceSize(const GrResourceCacheEntry* entry, size_t amountInc) { 204 void GrResourceCache::didIncreaseResourceSize(const GrResourceCacheEntry* entry, size_t amountInc) {
203 fEntryBytes += amountInc; 205 fEntryBytes += amountInc;
204 this->purgeAsNeeded(); 206 this->purgeAsNeeded();
205 } 207 }
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 int scratch = 0; 365 int scratch = 0;
364 366
365 EntryList::Iter iter; 367 EntryList::Iter iter;
366 368
367 GrResourceCacheEntry* entry = iter.init(fList, EntryList::Iter::kTail_IterSt art); 369 GrResourceCacheEntry* entry = iter.init(fList, EntryList::Iter::kTail_IterSt art);
368 370
369 for ( ; entry; entry = iter.prev()) { 371 for ( ; entry; entry = iter.prev()) {
370 if (!entry->fResource->isPurgable()) { 372 if (!entry->fResource->isPurgable()) {
371 ++locked; 373 ++locked;
372 } 374 }
373 if (entry->fResource->isScratch()) { 375 if (entry->fResource->cacheAccess().isScratch()) {
374 ++scratch; 376 ++scratch;
375 } 377 }
376 } 378 }
377 379
378 float countUtilization = (100.f * fEntryCount) / fMaxCount; 380 float countUtilization = (100.f * fEntryCount) / fMaxCount;
379 float byteUtilization = (100.f * fEntryBytes) / fMaxBytes; 381 float byteUtilization = (100.f * fEntryBytes) / fMaxBytes;
380 382
381 SkDebugf("Budget: %d items %d bytes\n", fMaxCount, fMaxBytes); 383 SkDebugf("Budget: %d items %d bytes\n", fMaxCount, fMaxBytes);
382 SkDebugf("\t\tEntry Count: current %d (%d locked, %d scratch %.2g%% full), h igh %d\n", 384 SkDebugf("\t\tEntry Count: current %d (%d locked, %d scratch %.2g%% full), h igh %d\n",
383 fEntryCount, locked, scratch, countUtilization, fHighWaterEntryC ount); 385 fEntryCount, locked, scratch, countUtilization, fHighWaterEntryC ount);
384 SkDebugf("\t\tEntry Bytes: current %d (%.2g%% full) high %d\n", 386 SkDebugf("\t\tEntry Bytes: current %d (%.2g%% full) high %d\n",
385 fEntryBytes, byteUtilization, fHighWaterEntryBytes); 387 fEntryBytes, byteUtilization, fHighWaterEntryBytes);
386 } 388 }
387 389
388 #endif 390 #endif
389 391
390 /////////////////////////////////////////////////////////////////////////////// 392 ///////////////////////////////////////////////////////////////////////////////
OLDNEW
« no previous file with comments | « src/gpu/GrGpuResourceCacheAccess.h ('k') | src/gpu/GrResourceCache2.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698