| 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 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 int GrContext::getGpuTextureCacheResourceCount() const { | 231 int GrContext::getGpuTextureCacheResourceCount() const { |
| 232 return fTextureCache->getCachedResourceCount(); | 232 return fTextureCache->getCachedResourceCount(); |
| 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 GrResource* resource = fTextureCache->find(resourceKey); | 241 GrCacheable* resource = fTextureCache->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 fTextureCache->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 fTextureCache->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 GrResource* resource = fTextureCache->find(resourceKey); | 267 GrCacheable* resource = fTextureCache->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 Loading... |
| 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->sizeInBytes()); | 400 fTextureCache->purgeAsNeeded(1, texture->gpuMemorySize()); |
| 401 fTextureCache->addResource(resourceKey, texture); | 401 fTextureCache->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* textureCache, |
| 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->sizeInBytes()); | 419 textureCache->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 textureCache->addResource(key, texture, GrResourceCache::kHide_Ownership
Flag); |
| 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)); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 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 GrResource* 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 = fTextureCache->find(key, GrResourceCache::kHide_OwnershipFlag
); |
| 459 if (NULL != resource) { | 459 if (NULL != resource) { |
| 460 resource->ref(); | 460 resource->ref(); |
| 461 break; | 461 break; |
| (...skipping 1350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1812 GrPath* GrContext::createPath(const SkPath& inPath, const SkStrokeRec& stroke) { | 1812 GrPath* GrContext::createPath(const SkPath& inPath, const SkStrokeRec& stroke) { |
| 1813 SkASSERT(fGpu->caps()->pathRenderingSupport()); | 1813 SkASSERT(fGpu->caps()->pathRenderingSupport()); |
| 1814 | 1814 |
| 1815 // TODO: now we add to fTextureCache. This should change to fResourceCache. | 1815 // TODO: now we add to fTextureCache. This should change to fResourceCache. |
| 1816 GrResourceKey resourceKey = GrPath::ComputeKey(inPath, stroke); | 1816 GrResourceKey resourceKey = GrPath::ComputeKey(inPath, stroke); |
| 1817 GrPath* path = static_cast<GrPath*>(fTextureCache->find(resourceKey)); | 1817 GrPath* path = static_cast<GrPath*>(fTextureCache->find(resourceKey)); |
| 1818 if (NULL != path && path->isEqualTo(inPath, stroke)) { | 1818 if (NULL != path && path->isEqualTo(inPath, stroke)) { |
| 1819 path->ref(); | 1819 path->ref(); |
| 1820 } else { | 1820 } else { |
| 1821 path = fGpu->createPath(inPath, stroke); | 1821 path = fGpu->createPath(inPath, stroke); |
| 1822 fTextureCache->purgeAsNeeded(1, path->sizeInBytes()); | 1822 fTextureCache->purgeAsNeeded(1, path->gpuMemorySize()); |
| 1823 fTextureCache->addResource(resourceKey, path); | 1823 fTextureCache->addResource(resourceKey, path); |
| 1824 } | 1824 } |
| 1825 return path; | 1825 return path; |
| 1826 } | 1826 } |
| 1827 | 1827 |
| 1828 /////////////////////////////////////////////////////////////////////////////// | 1828 /////////////////////////////////////////////////////////////////////////////// |
| 1829 #if GR_CACHE_STATS | 1829 #if GR_CACHE_STATS |
| 1830 void GrContext::printCacheStats() const { | 1830 void GrContext::printCacheStats() const { |
| 1831 fTextureCache->printStats(); | 1831 fTextureCache->printStats(); |
| 1832 } | 1832 } |
| 1833 #endif | 1833 #endif |
| OLD | NEW |