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 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 fResourceCache->addResource(resourceKey, texture); | 400 fResourceCache->addResource(resourceKey, texture); |
401 | 401 |
402 if (NULL != cacheKey) { | 402 if (NULL != cacheKey) { |
403 *cacheKey = resourceKey; | 403 *cacheKey = resourceKey; |
404 } | 404 } |
405 } | 405 } |
406 | 406 |
407 return texture; | 407 return texture; |
408 } | 408 } |
409 | 409 |
| 410 GrTexture* GrContext::createCompressedTexture(const GrTextureParams* params, |
| 411 const GrTextureDesc& desc, |
| 412 const GrCacheID& cacheID, |
| 413 const void* srcData, |
| 414 GrCompressedFormat format, |
| 415 GrResourceKey* cacheKey) { |
| 416 GrResourceKey resourceKey = GrTextureImpl::ComputeKey(fGpu, params, desc, ca
cheID); |
| 417 |
| 418 GrTexture* texture = NULL; |
| 419 if (!GrTextureImpl::NeedsResizing(resourceKey)) { |
| 420 texture = fGpu->createCompressedTexture(desc, srcData, format); |
| 421 } |
| 422 |
| 423 if (NULL != texture) { |
| 424 // Adding a resource could put us overbudget. Try to free up the |
| 425 // necessary space before adding it. |
| 426 fResourceCache->purgeAsNeeded(1, texture->gpuMemorySize()); |
| 427 fResourceCache->addResource(resourceKey, texture); |
| 428 |
| 429 if (NULL != cacheKey) { |
| 430 *cacheKey = resourceKey; |
| 431 } |
| 432 } |
| 433 |
| 434 return texture; |
| 435 } |
| 436 |
410 static GrTexture* create_scratch_texture(GrGpu* gpu, | 437 static GrTexture* create_scratch_texture(GrGpu* gpu, |
411 GrResourceCache* resourceCache, | 438 GrResourceCache* resourceCache, |
412 const GrTextureDesc& desc) { | 439 const GrTextureDesc& desc) { |
413 GrTexture* texture = gpu->createTexture(desc, NULL, 0); | 440 GrTexture* texture = gpu->createTexture(desc, NULL, 0); |
414 if (NULL != texture) { | 441 if (NULL != texture) { |
415 GrResourceKey key = GrTextureImpl::ComputeScratchKey(texture->desc()); | 442 GrResourceKey key = GrTextureImpl::ComputeScratchKey(texture->desc()); |
416 // Adding a resource could put us overbudget. Try to free up the | 443 // Adding a resource could put us overbudget. Try to free up the |
417 // necessary space before adding it. | 444 // necessary space before adding it. |
418 resourceCache->purgeAsNeeded(1, texture->gpuMemorySize()); | 445 resourceCache->purgeAsNeeded(1, texture->gpuMemorySize()); |
419 // Make the resource exclusive so future 'find' calls don't return it | 446 // Make the resource exclusive so future 'find' calls don't return it |
(...skipping 1413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1833 SkSafeRef(resource); | 1860 SkSafeRef(resource); |
1834 return resource; | 1861 return resource; |
1835 } | 1862 } |
1836 | 1863 |
1837 /////////////////////////////////////////////////////////////////////////////// | 1864 /////////////////////////////////////////////////////////////////////////////// |
1838 #if GR_CACHE_STATS | 1865 #if GR_CACHE_STATS |
1839 void GrContext::printCacheStats() const { | 1866 void GrContext::printCacheStats() const { |
1840 fResourceCache->printStats(); | 1867 fResourceCache->printStats(); |
1841 } | 1868 } |
1842 #endif | 1869 #endif |
OLD | NEW |