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 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 } | 421 } |
422 | 422 |
423 GrTexture* GrContext::lockAndRefScratchTexture(const GrTextureDesc& inDesc, Scra
tchTexMatch match) { | 423 GrTexture* GrContext::lockAndRefScratchTexture(const GrTextureDesc& inDesc, Scra
tchTexMatch match) { |
424 GrTextureDesc desc = inDesc; | 424 GrTextureDesc desc = inDesc; |
425 | 425 |
426 GrAssert((desc.fFlags & kRenderTarget_GrTextureFlagBit) || | 426 GrAssert((desc.fFlags & kRenderTarget_GrTextureFlagBit) || |
427 !(desc.fFlags & kNoStencil_GrTextureFlagBit)); | 427 !(desc.fFlags & kNoStencil_GrTextureFlagBit)); |
428 | 428 |
429 if (kApprox_ScratchTexMatch == match) { | 429 if (kApprox_ScratchTexMatch == match) { |
430 // bin by pow2 with a reasonable min | 430 // bin by pow2 with a reasonable min |
431 static const int MIN_SIZE = 256; | 431 static const int MIN_SIZE = 16; |
432 desc.fWidth = GrMax(MIN_SIZE, GrNextPow2(desc.fWidth)); | 432 desc.fWidth = GrMax(MIN_SIZE, GrNextPow2(desc.fWidth)); |
433 desc.fHeight = GrMax(MIN_SIZE, GrNextPow2(desc.fHeight)); | 433 desc.fHeight = GrMax(MIN_SIZE, GrNextPow2(desc.fHeight)); |
434 } | 434 } |
435 | 435 |
436 // Renderable A8 targets are not universally supported (e.g., not on ANGLE) | 436 // Renderable A8 targets are not universally supported (e.g., not on ANGLE) |
437 GrAssert(this->isConfigRenderable(kAlpha_8_GrPixelConfig) || | 437 GrAssert(this->isConfigRenderable(kAlpha_8_GrPixelConfig) || |
438 !(desc.fFlags & kRenderTarget_GrTextureFlagBit) || | 438 !(desc.fFlags & kRenderTarget_GrTextureFlagBit) || |
439 (desc.fConfig != kAlpha_8_GrPixelConfig)); | 439 (desc.fConfig != kAlpha_8_GrPixelConfig)); |
440 | 440 |
441 GrResource* resource = NULL; | 441 GrResource* resource = NULL; |
442 int origWidth = desc.fWidth; | 442 int origWidth = desc.fWidth; |
443 int origHeight = desc.fHeight; | 443 int origHeight = desc.fHeight; |
444 bool doubledW = false; | 444 bool doubledW = false; |
445 bool doubledH = false; | 445 bool doubledH = false; |
446 | 446 |
447 do { | 447 do { |
448 GrResourceKey key = GrTexture::ComputeScratchKey(desc); | 448 GrResourceKey key = GrTexture::ComputeScratchKey(desc); |
449 // Ensure we have exclusive access to the texture so future 'find' calls
don't return it | 449 // Ensure we have exclusive access to the texture so future 'find' calls
don't return it |
450 resource = fTextureCache->find(key, GrResourceCache::kHide_OwnershipFlag
); | 450 resource = fTextureCache->find(key, GrResourceCache::kHide_OwnershipFlag
); |
451 if (NULL != resource) { | 451 if (NULL != resource) { |
452 resource->ref(); | 452 resource->ref(); |
453 break; | 453 break; |
454 } | 454 } |
455 if (kExact_ScratchTexMatch == match) { | 455 if (kExact_ScratchTexMatch == match) { |
456 break; | 456 break; |
457 } | 457 } |
458 // We had a cache miss and we are in approx mode, relax the fit of the f
lags... then try | 458 // We had a cache miss and we are in approx mode, relax the fit of the f
lags. |
459 // doubling width... then the height. | |
460 | 459 |
461 // We no longer try to reuse textures that were previously used as rende
r targets in | 460 // We no longer try to reuse textures that were previously used as rende
r targets in |
462 // situations where no RT is needed; doing otherwise can confuse the vid
eo driver and | 461 // situations where no RT is needed; doing otherwise can confuse the vid
eo driver and |
463 // cause significant performance problems in some cases. | 462 // cause significant performance problems in some cases. |
464 if (desc.fFlags & kNoStencil_GrTextureFlagBit) { | 463 if (desc.fFlags & kNoStencil_GrTextureFlagBit) { |
465 desc.fFlags = desc.fFlags & ~kNoStencil_GrTextureFlagBit; | 464 desc.fFlags = desc.fFlags & ~kNoStencil_GrTextureFlagBit; |
466 } else if (!doubledW) { | |
467 desc.fFlags = inDesc.fFlags; | |
468 desc.fWidth *= 2; | |
469 doubledW = true; | |
470 } else if (!doubledH) { | |
471 desc.fFlags = inDesc.fFlags; | |
472 desc.fWidth = origWidth; | |
473 desc.fHeight *= 2; | |
474 doubledH = true; | |
475 } else { | 465 } else { |
476 break; | 466 break; |
477 } | 467 } |
478 | 468 |
479 } while (true); | 469 } while (true); |
480 | 470 |
481 if (NULL == resource) { | 471 if (NULL == resource) { |
482 desc.fFlags = inDesc.fFlags; | 472 desc.fFlags = inDesc.fFlags; |
483 desc.fWidth = origWidth; | 473 desc.fWidth = origWidth; |
484 desc.fHeight = origHeight; | 474 desc.fHeight = origHeight; |
(...skipping 1507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1992 return srcTexture; | 1982 return srcTexture; |
1993 } | 1983 } |
1994 } | 1984 } |
1995 | 1985 |
1996 /////////////////////////////////////////////////////////////////////////////// | 1986 /////////////////////////////////////////////////////////////////////////////// |
1997 #if GR_CACHE_STATS | 1987 #if GR_CACHE_STATS |
1998 void GrContext::printCacheStats() const { | 1988 void GrContext::printCacheStats() const { |
1999 fTextureCache->printStats(); | 1989 fTextureCache->printStats(); |
2000 } | 1990 } |
2001 #endif | 1991 #endif |
OLD | NEW |