OLD | NEW |
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 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 if (NULL != resourceBytes) { | 230 if (NULL != resourceBytes) { |
231 *resourceBytes = fResourceCache->getCachedResourceBytes(); | 231 *resourceBytes = fResourceCache->getCachedResourceBytes(); |
232 } | 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 = GrTextureImpl::ComputeKey(fGpu, params, desc, ca
cheID); | 240 GrResourceKey resourceKey = GrTexture::ComputeKey(fGpu, params, desc, cacheI
D); |
241 GrCacheable* resource = fResourceCache->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 = GrTextureImpl::ComputeKey(fGpu, params, desc, ca
cheID); | 249 GrResourceKey resourceKey = GrTexture::ComputeKey(fGpu, params, desc, cacheI
D); |
250 return fResourceCache->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 fResourceCache->addResource(resourceKey, sb); | 259 fResourceCache->addResource(resourceKey, sb); |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 | 376 |
377 return texture; | 377 return texture; |
378 } | 378 } |
379 | 379 |
380 GrTexture* GrContext::createTexture(const GrTextureParams* params, | 380 GrTexture* GrContext::createTexture(const GrTextureParams* params, |
381 const GrTextureDesc& desc, | 381 const GrTextureDesc& desc, |
382 const GrCacheID& cacheID, | 382 const GrCacheID& cacheID, |
383 void* srcData, | 383 void* srcData, |
384 size_t rowBytes, | 384 size_t rowBytes, |
385 GrResourceKey* cacheKey) { | 385 GrResourceKey* cacheKey) { |
386 GrResourceKey resourceKey = GrTextureImpl::ComputeKey(fGpu, params, desc, ca
cheID); | 386 GrResourceKey resourceKey = GrTexture::ComputeKey(fGpu, params, desc, cacheI
D); |
387 | 387 |
388 GrTexture* texture; | 388 GrTexture* texture; |
389 if (GrTextureImpl::NeedsResizing(resourceKey)) { | 389 if (GrTexture::NeedsResizing(resourceKey)) { |
390 texture = this->createResizedTexture(desc, cacheID, | 390 texture = this->createResizedTexture(desc, cacheID, |
391 srcData, rowBytes, | 391 srcData, rowBytes, |
392 GrTextureImpl::NeedsBilerp(resource
Key)); | 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 fResourceCache->purgeAsNeeded(1, texture->gpuMemorySize()); | 400 fResourceCache->purgeAsNeeded(1, texture->gpuMemorySize()); |
401 fResourceCache->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* resourceCache, | 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 = GrTextureImpl::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 resourceCache->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 resourceCache->addResource(key, texture, GrResourceCache::kHide_Ownershi
pFlag); | 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) { |
(...skipping 19 matching lines...) Expand all Loading... |
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 = GrTextureImpl::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 = fResourceCache->find(key, GrResourceCache::kHide_OwnershipFla
g); | 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. |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 fResourceCache->makeNonExclusive(texture->getCacheEntry()); | 538 fResourceCache->makeNonExclusive(texture->getCacheEntry()); |
539 fResourceCache->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->impl()->setFlag((GrTextureFlags) GrTextureImpl::kReturnToCa
che_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 != fResourceCache) { | 554 if (NULL != fResourceCache) { |
555 fResourceCache->purgeAsNeeded(); | 555 fResourceCache->purgeAsNeeded(); |
556 } | 556 } |
(...skipping 1277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1834 SkSafeRef(resource); | 1834 SkSafeRef(resource); |
1835 return resource; | 1835 return resource; |
1836 } | 1836 } |
1837 | 1837 |
1838 /////////////////////////////////////////////////////////////////////////////// | 1838 /////////////////////////////////////////////////////////////////////////////// |
1839 #if GR_CACHE_STATS | 1839 #if GR_CACHE_STATS |
1840 void GrContext::printCacheStats() const { | 1840 void GrContext::printCacheStats() const { |
1841 fResourceCache->printStats(); | 1841 fResourceCache->printStats(); |
1842 } | 1842 } |
1843 #endif | 1843 #endif |
OLD | NEW |