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

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

Issue 275563005: cleanup GrContext resource cache api (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Fix use of SK_ATTR_DEPRECATED Created 6 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « samplecode/SampleApp.cpp ('k') | src/gpu/GrTest.cpp » ('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 9
10 #include "GrContext.h" 10 #include "GrContext.h"
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 return NULL; 87 return NULL;
88 } 88 }
89 } 89 }
90 90
91 GrContext::GrContext() { 91 GrContext::GrContext() {
92 fDrawState = NULL; 92 fDrawState = NULL;
93 fGpu = NULL; 93 fGpu = NULL;
94 fClip = NULL; 94 fClip = NULL;
95 fPathRendererChain = NULL; 95 fPathRendererChain = NULL;
96 fSoftwarePathRenderer = NULL; 96 fSoftwarePathRenderer = NULL;
97 fTextureCache = NULL; 97 fResourceCache = NULL;
98 fFontCache = NULL; 98 fFontCache = NULL;
99 fDrawBuffer = NULL; 99 fDrawBuffer = NULL;
100 fDrawBufferVBAllocPool = NULL; 100 fDrawBufferVBAllocPool = NULL;
101 fDrawBufferIBAllocPool = NULL; 101 fDrawBufferIBAllocPool = NULL;
102 fFlushToReduceCacheSize = false; 102 fFlushToReduceCacheSize = false;
103 fAARectRenderer = NULL; 103 fAARectRenderer = NULL;
104 fOvalRenderer = NULL; 104 fOvalRenderer = NULL;
105 fViewMatrix.reset(); 105 fViewMatrix.reset();
106 fMaxTextureSizeOverride = 1 << 20; 106 fMaxTextureSizeOverride = 1 << 20;
107 fGpuTracingEnabled = false; 107 fGpuTracingEnabled = false;
108 } 108 }
109 109
110 bool GrContext::init(GrBackend backend, GrBackendContext backendContext) { 110 bool GrContext::init(GrBackend backend, GrBackendContext backendContext) {
111 SkASSERT(NULL == fGpu); 111 SkASSERT(NULL == fGpu);
112 112
113 fGpu = GrGpu::Create(backend, backendContext, this); 113 fGpu = GrGpu::Create(backend, backendContext, this);
114 if (NULL == fGpu) { 114 if (NULL == fGpu) {
115 return false; 115 return false;
116 } 116 }
117 117
118 fDrawState = SkNEW(GrDrawState); 118 fDrawState = SkNEW(GrDrawState);
119 fGpu->setDrawState(fDrawState); 119 fGpu->setDrawState(fDrawState);
120 120
121 fTextureCache = SkNEW_ARGS(GrResourceCache, 121 fResourceCache = SkNEW_ARGS(GrResourceCache, (MAX_RESOURCE_CACHE_COUNT,
122 (MAX_RESOURCE_CACHE_COUNT, 122 MAX_RESOURCE_CACHE_BYTES));
123 MAX_RESOURCE_CACHE_BYTES)); 123 fResourceCache->setOverbudgetCallback(OverbudgetCB, this);
124 fTextureCache->setOverbudgetCallback(OverbudgetCB, this);
125 124
126 fFontCache = SkNEW_ARGS(GrFontCache, (fGpu)); 125 fFontCache = SkNEW_ARGS(GrFontCache, (fGpu));
127 126
128 fLayerCache.reset(SkNEW_ARGS(GrLayerCache, (fGpu))); 127 fLayerCache.reset(SkNEW_ARGS(GrLayerCache, (fGpu)));
129 128
130 fLastDrawWasBuffered = kNo_BufferedDraw; 129 fLastDrawWasBuffered = kNo_BufferedDraw;
131 130
132 fAARectRenderer = SkNEW(GrAARectRenderer); 131 fAARectRenderer = SkNEW(GrAARectRenderer);
133 fOvalRenderer = SkNEW(GrOvalRenderer); 132 fOvalRenderer = SkNEW(GrOvalRenderer);
134 133
(...skipping 12 matching lines...) Expand all
147 this->flush(); 146 this->flush();
148 147
149 for (int i = 0; i < fCleanUpData.count(); ++i) { 148 for (int i = 0; i < fCleanUpData.count(); ++i) {
150 (*fCleanUpData[i].fFunc)(this, fCleanUpData[i].fInfo); 149 (*fCleanUpData[i].fFunc)(this, fCleanUpData[i].fInfo);
151 } 150 }
152 151
153 // Since the gpu can hold scratch textures, give it a chance to let go 152 // Since the gpu can hold scratch textures, give it a chance to let go
154 // of them before freeing the texture cache 153 // of them before freeing the texture cache
155 fGpu->purgeResources(); 154 fGpu->purgeResources();
156 155
157 delete fTextureCache; 156 delete fResourceCache;
158 fTextureCache = NULL; 157 fResourceCache = NULL;
159 delete fFontCache; 158 delete fFontCache;
160 delete fDrawBuffer; 159 delete fDrawBuffer;
161 delete fDrawBufferVBAllocPool; 160 delete fDrawBufferVBAllocPool;
162 delete fDrawBufferIBAllocPool; 161 delete fDrawBufferIBAllocPool;
163 162
164 fAARectRenderer->unref(); 163 fAARectRenderer->unref();
165 fOvalRenderer->unref(); 164 fOvalRenderer->unref();
166 165
167 fGpu->unref(); 166 fGpu->unref();
168 SkSafeUnref(fPathRendererChain); 167 SkSafeUnref(fPathRendererChain);
(...skipping 21 matching lines...) Expand all
190 189
191 delete fDrawBufferVBAllocPool; 190 delete fDrawBufferVBAllocPool;
192 fDrawBufferVBAllocPool = NULL; 191 fDrawBufferVBAllocPool = NULL;
193 192
194 delete fDrawBufferIBAllocPool; 193 delete fDrawBufferIBAllocPool;
195 fDrawBufferIBAllocPool = NULL; 194 fDrawBufferIBAllocPool = NULL;
196 195
197 fAARectRenderer->reset(); 196 fAARectRenderer->reset();
198 fOvalRenderer->reset(); 197 fOvalRenderer->reset();
199 198
200 fTextureCache->purgeAllUnlocked(); 199 fResourceCache->purgeAllUnlocked();
201 200
202 fFontCache->freeAll(); 201 fFontCache->freeAll();
203 fLayerCache->freeAll(); 202 fLayerCache->freeAll();
204 fGpu->markContextDirty(); 203 fGpu->markContextDirty();
205 } 204 }
206 205
207 void GrContext::resetContext(uint32_t state) { 206 void GrContext::resetContext(uint32_t state) {
208 fGpu->markContextDirty(state); 207 fGpu->markContextDirty(state);
209 } 208 }
210 209
211 void GrContext::freeGpuResources() { 210 void GrContext::freeGpuResources() {
212 this->flush(); 211 this->flush();
213 212
214 fGpu->purgeResources(); 213 fGpu->purgeResources();
215 214
216 fAARectRenderer->reset(); 215 fAARectRenderer->reset();
217 fOvalRenderer->reset(); 216 fOvalRenderer->reset();
218 217
219 fTextureCache->purgeAllUnlocked(); 218 fResourceCache->purgeAllUnlocked();
220 fFontCache->freeAll(); 219 fFontCache->freeAll();
221 fLayerCache->freeAll(); 220 fLayerCache->freeAll();
222 // a path renderer may be holding onto resources 221 // a path renderer may be holding onto resources
223 SkSafeSetNull(fPathRendererChain); 222 SkSafeSetNull(fPathRendererChain);
224 SkSafeSetNull(fSoftwarePathRenderer); 223 SkSafeSetNull(fSoftwarePathRenderer);
225 } 224 }
226 225
227 size_t GrContext::getGpuTextureCacheBytes() const { 226 void GrContext::getResourceCacheUsage(int* resourceCount, size_t* resourceBytes) const {
228 return fTextureCache->getCachedResourceBytes(); 227 if (NULL != resourceCount) {
229 } 228 *resourceCount = fResourceCache->getCachedResourceCount();
230 229 }
231 int GrContext::getGpuTextureCacheResourceCount() const { 230 if (NULL != resourceBytes) {
232 return fTextureCache->getCachedResourceCount(); 231 *resourceBytes = fResourceCache->getCachedResourceBytes();
232 }
233 } 233 }
234 234
235 //////////////////////////////////////////////////////////////////////////////// 235 ////////////////////////////////////////////////////////////////////////////////
236 236
237 GrTexture* GrContext::findAndRefTexture(const GrTextureDesc& desc, 237 GrTexture* GrContext::findAndRefTexture(const GrTextureDesc& desc,
238 const GrCacheID& cacheID, 238 const GrCacheID& cacheID,
239 const GrTextureParams* params) { 239 const GrTextureParams* params) {
240 GrResourceKey resourceKey = GrTexture::ComputeKey(fGpu, params, desc, cacheI D); 240 GrResourceKey resourceKey = GrTexture::ComputeKey(fGpu, params, desc, cacheI D);
241 GrCacheable* resource = fTextureCache->find(resourceKey); 241 GrCacheable* resource = fResourceCache->find(resourceKey);
242 SkSafeRef(resource); 242 SkSafeRef(resource);
243 return static_cast<GrTexture*>(resource); 243 return static_cast<GrTexture*>(resource);
244 } 244 }
245 245
246 bool GrContext::isTextureInCache(const GrTextureDesc& desc, 246 bool GrContext::isTextureInCache(const GrTextureDesc& desc,
247 const GrCacheID& cacheID, 247 const GrCacheID& cacheID,
248 const GrTextureParams* params) const { 248 const GrTextureParams* params) const {
249 GrResourceKey resourceKey = GrTexture::ComputeKey(fGpu, params, desc, cacheI D); 249 GrResourceKey resourceKey = GrTexture::ComputeKey(fGpu, params, desc, cacheI D);
250 return fTextureCache->hasKey(resourceKey); 250 return fResourceCache->hasKey(resourceKey);
251 } 251 }
252 252
253 void GrContext::addStencilBuffer(GrStencilBuffer* sb) { 253 void GrContext::addStencilBuffer(GrStencilBuffer* sb) {
254 ASSERT_OWNED_RESOURCE(sb); 254 ASSERT_OWNED_RESOURCE(sb);
255 255
256 GrResourceKey resourceKey = GrStencilBuffer::ComputeKey(sb->width(), 256 GrResourceKey resourceKey = GrStencilBuffer::ComputeKey(sb->width(),
257 sb->height(), 257 sb->height(),
258 sb->numSamples()); 258 sb->numSamples());
259 fTextureCache->addResource(resourceKey, sb); 259 fResourceCache->addResource(resourceKey, sb);
260 } 260 }
261 261
262 GrStencilBuffer* GrContext::findStencilBuffer(int width, int height, 262 GrStencilBuffer* GrContext::findStencilBuffer(int width, int height,
263 int sampleCnt) { 263 int sampleCnt) {
264 GrResourceKey resourceKey = GrStencilBuffer::ComputeKey(width, 264 GrResourceKey resourceKey = GrStencilBuffer::ComputeKey(width,
265 height, 265 height,
266 sampleCnt); 266 sampleCnt);
267 GrCacheable* resource = fTextureCache->find(resourceKey); 267 GrCacheable* resource = fResourceCache->find(resourceKey);
268 return static_cast<GrStencilBuffer*>(resource); 268 return static_cast<GrStencilBuffer*>(resource);
269 } 269 }
270 270
271 static void stretchImage(void* dst, 271 static void stretchImage(void* dst,
272 int dstW, 272 int dstW,
273 int dstH, 273 int dstH,
274 void* src, 274 void* src,
275 int srcW, 275 int srcW,
276 int srcH, 276 int srcH,
277 size_t bpp) { 277 size_t bpp) {
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 texture = this->createResizedTexture(desc, cacheID, 390 texture = this->createResizedTexture(desc, cacheID,
391 srcData, rowBytes, 391 srcData, rowBytes,
392 GrTexture::NeedsBilerp(resourceKey) ); 392 GrTexture::NeedsBilerp(resourceKey) );
393 } else { 393 } else {
394 texture= fGpu->createTexture(desc, srcData, rowBytes); 394 texture= fGpu->createTexture(desc, srcData, rowBytes);
395 } 395 }
396 396
397 if (NULL != texture) { 397 if (NULL != texture) {
398 // Adding a resource could put us overbudget. Try to free up the 398 // Adding a resource could put us overbudget. Try to free up the
399 // necessary space before adding it. 399 // necessary space before adding it.
400 fTextureCache->purgeAsNeeded(1, texture->gpuMemorySize()); 400 fResourceCache->purgeAsNeeded(1, texture->gpuMemorySize());
401 fTextureCache->addResource(resourceKey, texture); 401 fResourceCache->addResource(resourceKey, texture);
402 402
403 if (NULL != cacheKey) { 403 if (NULL != cacheKey) {
404 *cacheKey = resourceKey; 404 *cacheKey = resourceKey;
405 } 405 }
406 } 406 }
407 407
408 return texture; 408 return texture;
409 } 409 }
410 410
411 static GrTexture* create_scratch_texture(GrGpu* gpu, 411 static GrTexture* create_scratch_texture(GrGpu* gpu,
412 GrResourceCache* textureCache, 412 GrResourceCache* resourceCache,
413 const GrTextureDesc& desc) { 413 const GrTextureDesc& desc) {
414 GrTexture* texture = gpu->createTexture(desc, NULL, 0); 414 GrTexture* texture = gpu->createTexture(desc, NULL, 0);
415 if (NULL != texture) { 415 if (NULL != texture) {
416 GrResourceKey key = GrTexture::ComputeScratchKey(texture->desc()); 416 GrResourceKey key = GrTexture::ComputeScratchKey(texture->desc());
417 // Adding a resource could put us overbudget. Try to free up the 417 // Adding a resource could put us overbudget. Try to free up the
418 // necessary space before adding it. 418 // necessary space before adding it.
419 textureCache->purgeAsNeeded(1, texture->gpuMemorySize()); 419 resourceCache->purgeAsNeeded(1, texture->gpuMemorySize());
420 // Make the resource exclusive so future 'find' calls don't return it 420 // Make the resource exclusive so future 'find' calls don't return it
421 textureCache->addResource(key, texture, GrResourceCache::kHide_Ownership Flag); 421 resourceCache->addResource(key, texture, GrResourceCache::kHide_Ownershi pFlag);
422 } 422 }
423 return texture; 423 return texture;
424 } 424 }
425 425
426 GrTexture* GrContext::lockAndRefScratchTexture(const GrTextureDesc& inDesc, Scra tchTexMatch match) { 426 GrTexture* GrContext::lockAndRefScratchTexture(const GrTextureDesc& inDesc, Scra tchTexMatch match) {
427 427
428 SkASSERT((inDesc.fFlags & kRenderTarget_GrTextureFlagBit) || 428 SkASSERT((inDesc.fFlags & kRenderTarget_GrTextureFlagBit) ||
429 !(inDesc.fFlags & kNoStencil_GrTextureFlagBit)); 429 !(inDesc.fFlags & kNoStencil_GrTextureFlagBit));
430 430
431 // Renderable A8 targets are not universally supported (e.g., not on ANGLE) 431 // Renderable A8 targets are not universally supported (e.g., not on ANGLE)
432 SkASSERT(this->isConfigRenderable(kAlpha_8_GrPixelConfig, inDesc.fSampleCnt > 0) || 432 SkASSERT(this->isConfigRenderable(kAlpha_8_GrPixelConfig, inDesc.fSampleCnt > 0) ||
433 !(inDesc.fFlags & kRenderTarget_GrTextureFlagBit) || 433 !(inDesc.fFlags & kRenderTarget_GrTextureFlagBit) ||
434 (inDesc.fConfig != kAlpha_8_GrPixelConfig)); 434 (inDesc.fConfig != kAlpha_8_GrPixelConfig));
435 435
436 if (!fGpu->caps()->reuseScratchTextures() && 436 if (!fGpu->caps()->reuseScratchTextures() &&
437 !(inDesc.fFlags & kRenderTarget_GrTextureFlagBit)) { 437 !(inDesc.fFlags & kRenderTarget_GrTextureFlagBit)) {
438 // If we're never recycling this texture we can always make it the right size 438 // If we're never recycling this texture we can always make it the right size
439 return create_scratch_texture(fGpu, fTextureCache, inDesc); 439 return create_scratch_texture(fGpu, fResourceCache, inDesc);
440 } 440 }
441 441
442 GrTextureDesc desc = inDesc; 442 GrTextureDesc desc = inDesc;
443 443
444 if (kApprox_ScratchTexMatch == match) { 444 if (kApprox_ScratchTexMatch == match) {
445 // bin by pow2 with a reasonable min 445 // bin by pow2 with a reasonable min
446 static const int MIN_SIZE = 16; 446 static const int MIN_SIZE = 16;
447 desc.fWidth = SkTMax(MIN_SIZE, GrNextPow2(desc.fWidth)); 447 desc.fWidth = SkTMax(MIN_SIZE, GrNextPow2(desc.fWidth));
448 desc.fHeight = SkTMax(MIN_SIZE, GrNextPow2(desc.fHeight)); 448 desc.fHeight = SkTMax(MIN_SIZE, GrNextPow2(desc.fHeight));
449 } 449 }
450 450
451 GrCacheable* resource = NULL; 451 GrCacheable* resource = NULL;
452 int origWidth = desc.fWidth; 452 int origWidth = desc.fWidth;
453 int origHeight = desc.fHeight; 453 int origHeight = desc.fHeight;
454 454
455 do { 455 do {
456 GrResourceKey key = GrTexture::ComputeScratchKey(desc); 456 GrResourceKey key = GrTexture::ComputeScratchKey(desc);
457 // Ensure we have exclusive access to the texture so future 'find' calls don't return it 457 // Ensure we have exclusive access to the texture so future 'find' calls don't return it
458 resource = fTextureCache->find(key, GrResourceCache::kHide_OwnershipFlag ); 458 resource = fResourceCache->find(key, GrResourceCache::kHide_OwnershipFla g);
459 if (NULL != resource) { 459 if (NULL != resource) {
460 resource->ref(); 460 resource->ref();
461 break; 461 break;
462 } 462 }
463 if (kExact_ScratchTexMatch == match) { 463 if (kExact_ScratchTexMatch == match) {
464 break; 464 break;
465 } 465 }
466 // We had a cache miss and we are in approx mode, relax the fit of the f lags. 466 // We had a cache miss and we are in approx mode, relax the fit of the f lags.
467 467
468 // We no longer try to reuse textures that were previously used as rende r targets in 468 // We no longer try to reuse textures that were previously used as rende r targets in
469 // situations where no RT is needed; doing otherwise can confuse the vid eo driver and 469 // situations where no RT is needed; doing otherwise can confuse the vid eo driver and
470 // cause significant performance problems in some cases. 470 // cause significant performance problems in some cases.
471 if (desc.fFlags & kNoStencil_GrTextureFlagBit) { 471 if (desc.fFlags & kNoStencil_GrTextureFlagBit) {
472 desc.fFlags = desc.fFlags & ~kNoStencil_GrTextureFlagBit; 472 desc.fFlags = desc.fFlags & ~kNoStencil_GrTextureFlagBit;
473 } else { 473 } else {
474 break; 474 break;
475 } 475 }
476 476
477 } while (true); 477 } while (true);
478 478
479 if (NULL == resource) { 479 if (NULL == resource) {
480 desc.fFlags = inDesc.fFlags; 480 desc.fFlags = inDesc.fFlags;
481 desc.fWidth = origWidth; 481 desc.fWidth = origWidth;
482 desc.fHeight = origHeight; 482 desc.fHeight = origHeight;
483 resource = create_scratch_texture(fGpu, fTextureCache, desc); 483 resource = create_scratch_texture(fGpu, fResourceCache, desc);
484 } 484 }
485 485
486 return static_cast<GrTexture*>(resource); 486 return static_cast<GrTexture*>(resource);
487 } 487 }
488 488
489 void GrContext::addExistingTextureToCache(GrTexture* texture) { 489 void GrContext::addExistingTextureToCache(GrTexture* texture) {
490 490
491 if (NULL == texture) { 491 if (NULL == texture) {
492 return; 492 return;
493 } 493 }
494 494
495 // This texture should already have a cache entry since it was once 495 // This texture should already have a cache entry since it was once
496 // attached 496 // attached
497 SkASSERT(NULL != texture->getCacheEntry()); 497 SkASSERT(NULL != texture->getCacheEntry());
498 498
499 // Conceptually, the cache entry is going to assume responsibility 499 // Conceptually, the cache entry is going to assume responsibility
500 // for the creation ref. Assert refcnt == 1. 500 // for the creation ref. Assert refcnt == 1.
501 SkASSERT(texture->unique()); 501 SkASSERT(texture->unique());
502 502
503 if (fGpu->caps()->reuseScratchTextures() || NULL != texture->asRenderTarget( )) { 503 if (fGpu->caps()->reuseScratchTextures() || NULL != texture->asRenderTarget( )) {
504 // Since this texture came from an AutoScratchTexture it should 504 // Since this texture came from an AutoScratchTexture it should
505 // still be in the exclusive pile. Recycle it. 505 // still be in the exclusive pile. Recycle it.
506 fTextureCache->makeNonExclusive(texture->getCacheEntry()); 506 fResourceCache->makeNonExclusive(texture->getCacheEntry());
507 this->purgeCache(); 507 this->purgeCache();
508 } else if (texture->getDeferredRefCount() <= 0) { 508 } else if (texture->getDeferredRefCount() <= 0) {
509 // When we aren't reusing textures we know this scratch texture 509 // When we aren't reusing textures we know this scratch texture
510 // will never be reused and would be just wasting time in the cache 510 // will never be reused and would be just wasting time in the cache
511 fTextureCache->makeNonExclusive(texture->getCacheEntry()); 511 fResourceCache->makeNonExclusive(texture->getCacheEntry());
512 fTextureCache->deleteResource(texture->getCacheEntry()); 512 fResourceCache->deleteResource(texture->getCacheEntry());
513 } else { 513 } else {
514 // In this case (fDeferredRefCount > 0) but the cache is the only 514 // In this case (fDeferredRefCount > 0) but the cache is the only
515 // one holding a real ref. Mark the object so when the deferred 515 // one holding a real ref. Mark the object so when the deferred
516 // ref count goes to 0 the texture will be deleted (remember 516 // ref count goes to 0 the texture will be deleted (remember
517 // in this code path scratch textures aren't getting reused). 517 // in this code path scratch textures aren't getting reused).
518 texture->setNeedsDeferredUnref(); 518 texture->setNeedsDeferredUnref();
519 } 519 }
520 } 520 }
521 521
522 522
523 void GrContext::unlockScratchTexture(GrTexture* texture) { 523 void GrContext::unlockScratchTexture(GrTexture* texture) {
524 ASSERT_OWNED_RESOURCE(texture); 524 ASSERT_OWNED_RESOURCE(texture);
525 SkASSERT(NULL != texture->getCacheEntry()); 525 SkASSERT(NULL != texture->getCacheEntry());
526 526
527 // If this is a scratch texture we detached it from the cache 527 // If this is a scratch texture we detached it from the cache
528 // while it was locked (to avoid two callers simultaneously getting 528 // while it was locked (to avoid two callers simultaneously getting
529 // the same texture). 529 // the same texture).
530 if (texture->getCacheEntry()->key().isScratch()) { 530 if (texture->getCacheEntry()->key().isScratch()) {
531 if (fGpu->caps()->reuseScratchTextures() || NULL != texture->asRenderTar get()) { 531 if (fGpu->caps()->reuseScratchTextures() || NULL != texture->asRenderTar get()) {
532 fTextureCache->makeNonExclusive(texture->getCacheEntry()); 532 fResourceCache->makeNonExclusive(texture->getCacheEntry());
533 this->purgeCache(); 533 this->purgeCache();
534 } else if (texture->unique() && texture->getDeferredRefCount() <= 0) { 534 } else if (texture->unique() && texture->getDeferredRefCount() <= 0) {
535 // Only the cache now knows about this texture. Since we're never 535 // Only the cache now knows about this texture. Since we're never
536 // reusing scratch textures (in this code path) it would just be 536 // reusing scratch textures (in this code path) it would just be
537 // wasting time sitting in the cache. 537 // wasting time sitting in the cache.
538 fTextureCache->makeNonExclusive(texture->getCacheEntry()); 538 fResourceCache->makeNonExclusive(texture->getCacheEntry());
539 fTextureCache->deleteResource(texture->getCacheEntry()); 539 fResourceCache->deleteResource(texture->getCacheEntry());
540 } else { 540 } else {
541 // In this case (fRefCnt > 1 || defRefCnt > 0) but we don't really 541 // In this case (fRefCnt > 1 || defRefCnt > 0) but we don't really
542 // want to readd it to the cache (since it will never be reused). 542 // want to readd it to the cache (since it will never be reused).
543 // Instead, give up the cache's ref and leave the decision up to 543 // Instead, give up the cache's ref and leave the decision up to
544 // addExistingTextureToCache once its ref count reaches 0. For 544 // addExistingTextureToCache once its ref count reaches 0. For
545 // this to work we need to leave it in the exclusive list. 545 // this to work we need to leave it in the exclusive list.
546 texture->setFlag((GrTextureFlags) GrTexture::kReturnToCache_FlagBit) ; 546 texture->setFlag((GrTextureFlags) GrTexture::kReturnToCache_FlagBit) ;
547 // Give up the cache's ref to the texture 547 // Give up the cache's ref to the texture
548 texture->unref(); 548 texture->unref();
549 } 549 }
550 } 550 }
551 } 551 }
552 552
553 void GrContext::purgeCache() { 553 void GrContext::purgeCache() {
554 if (NULL != fTextureCache) { 554 if (NULL != fResourceCache) {
555 fTextureCache->purgeAsNeeded(); 555 fResourceCache->purgeAsNeeded();
556 } 556 }
557 } 557 }
558 558
559 bool GrContext::OverbudgetCB(void* data) { 559 bool GrContext::OverbudgetCB(void* data) {
560 SkASSERT(NULL != data); 560 SkASSERT(NULL != data);
561 561
562 GrContext* context = reinterpret_cast<GrContext*>(data); 562 GrContext* context = reinterpret_cast<GrContext*>(data);
563 563
564 // Flush the InOrderDrawBuffer to possibly free up some textures 564 // Flush the InOrderDrawBuffer to possibly free up some textures
565 context->fFlushToReduceCacheSize = true; 565 context->fFlushToReduceCacheSize = true;
566 566
567 return true; 567 return true;
568 } 568 }
569 569
570 570
571 GrTexture* GrContext::createUncachedTexture(const GrTextureDesc& descIn, 571 GrTexture* GrContext::createUncachedTexture(const GrTextureDesc& descIn,
572 void* srcData, 572 void* srcData,
573 size_t rowBytes) { 573 size_t rowBytes) {
574 GrTextureDesc descCopy = descIn; 574 GrTextureDesc descCopy = descIn;
575 return fGpu->createTexture(descCopy, srcData, rowBytes); 575 return fGpu->createTexture(descCopy, srcData, rowBytes);
576 } 576 }
577 577
578 void GrContext::getTextureCacheLimits(int* maxTextures, 578 void GrContext::getResourceCacheLimits(int* maxTextures, size_t* maxTextureBytes ) const {
579 size_t* maxTextureBytes) const { 579 fResourceCache->getLimits(maxTextures, maxTextureBytes);
580 fTextureCache->getLimits(maxTextures, maxTextureBytes);
581 } 580 }
582 581
583 void GrContext::setTextureCacheLimits(int maxTextures, size_t maxTextureBytes) { 582 void GrContext::setResourceCacheLimits(int maxTextures, size_t maxTextureBytes) {
584 fTextureCache->setLimits(maxTextures, maxTextureBytes); 583 fResourceCache->setLimits(maxTextures, maxTextureBytes);
585 } 584 }
586 585
587 int GrContext::getMaxTextureSize() const { 586 int GrContext::getMaxTextureSize() const {
588 return SkTMin(fGpu->caps()->maxTextureSize(), fMaxTextureSizeOverride); 587 return SkTMin(fGpu->caps()->maxTextureSize(), fMaxTextureSizeOverride);
589 } 588 }
590 589
591 int GrContext::getMaxRenderTargetSize() const { 590 int GrContext::getMaxRenderTargetSize() const {
592 return fGpu->caps()->maxRenderTargetSize(); 591 return fGpu->caps()->maxRenderTargetSize();
593 } 592 }
594 593
(...skipping 1210 matching lines...) Expand 10 before | Expand all | Expand 10 after
1805 if (GrConfigConversionEffect::kNone_PMConversion != upmToPM) { 1804 if (GrConfigConversionEffect::kNone_PMConversion != upmToPM) {
1806 return GrConfigConversionEffect::Create(texture, swapRAndB, upmToPM, mat rix); 1805 return GrConfigConversionEffect::Create(texture, swapRAndB, upmToPM, mat rix);
1807 } else { 1806 } else {
1808 return NULL; 1807 return NULL;
1809 } 1808 }
1810 } 1809 }
1811 1810
1812 GrPath* GrContext::createPath(const SkPath& inPath, const SkStrokeRec& stroke) { 1811 GrPath* GrContext::createPath(const SkPath& inPath, const SkStrokeRec& stroke) {
1813 SkASSERT(fGpu->caps()->pathRenderingSupport()); 1812 SkASSERT(fGpu->caps()->pathRenderingSupport());
1814 1813
1815 // TODO: now we add to fTextureCache. This should change to fResourceCache. 1814 // TODO: now we add to fResourceCache. This should change to fResourceCache.
1816 GrResourceKey resourceKey = GrPath::ComputeKey(inPath, stroke); 1815 GrResourceKey resourceKey = GrPath::ComputeKey(inPath, stroke);
1817 GrPath* path = static_cast<GrPath*>(fTextureCache->find(resourceKey)); 1816 GrPath* path = static_cast<GrPath*>(fResourceCache->find(resourceKey));
1818 if (NULL != path && path->isEqualTo(inPath, stroke)) { 1817 if (NULL != path && path->isEqualTo(inPath, stroke)) {
1819 path->ref(); 1818 path->ref();
1820 } else { 1819 } else {
1821 path = fGpu->createPath(inPath, stroke); 1820 path = fGpu->createPath(inPath, stroke);
1822 fTextureCache->purgeAsNeeded(1, path->gpuMemorySize()); 1821 fResourceCache->purgeAsNeeded(1, path->gpuMemorySize());
1823 fTextureCache->addResource(resourceKey, path); 1822 fResourceCache->addResource(resourceKey, path);
1824 } 1823 }
1825 return path; 1824 return path;
1826 } 1825 }
1827 1826
1828 void GrContext::addResourceToCache(const GrResourceKey& resourceKey, GrCacheable * resource) { 1827 void GrContext::addResourceToCache(const GrResourceKey& resourceKey, GrCacheable * resource) {
1829 fTextureCache->purgeAsNeeded(1, resource->gpuMemorySize()); 1828 fResourceCache->purgeAsNeeded(1, resource->gpuMemorySize());
1830 fTextureCache->addResource(resourceKey, resource); 1829 fResourceCache->addResource(resourceKey, resource);
1831 } 1830 }
1832 1831
1833 GrCacheable* GrContext::findAndRefCachedResource(const GrResourceKey& resourceKe y) { 1832 GrCacheable* GrContext::findAndRefCachedResource(const GrResourceKey& resourceKe y) {
1834 GrCacheable* resource = fTextureCache->find(resourceKey); 1833 GrCacheable* resource = fResourceCache->find(resourceKey);
1835 SkSafeRef(resource); 1834 SkSafeRef(resource);
1836 return resource; 1835 return resource;
1837 } 1836 }
1838 1837
1839 /////////////////////////////////////////////////////////////////////////////// 1838 ///////////////////////////////////////////////////////////////////////////////
1840 #if GR_CACHE_STATS 1839 #if GR_CACHE_STATS
1841 void GrContext::printCacheStats() const { 1840 void GrContext::printCacheStats() const {
1842 fTextureCache->printStats(); 1841 fResourceCache->printStats();
1843 } 1842 }
1844 #endif 1843 #endif
OLDNEW
« no previous file with comments | « samplecode/SampleApp.cpp ('k') | src/gpu/GrTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698