| 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 #include "GrContext.h" | 9 #include "GrContext.h" |
| 10 | 10 |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 return GrDistanceFieldTextContext::Create(this, leakyProperties, enableDista
nceFieldFonts); | 259 return GrDistanceFieldTextContext::Create(this, leakyProperties, enableDista
nceFieldFonts); |
| 260 } | 260 } |
| 261 | 261 |
| 262 //////////////////////////////////////////////////////////////////////////////// | 262 //////////////////////////////////////////////////////////////////////////////// |
| 263 | 263 |
| 264 GrTexture* GrContext::findAndRefTexture(const GrSurfaceDesc& desc, | 264 GrTexture* GrContext::findAndRefTexture(const GrSurfaceDesc& desc, |
| 265 const GrCacheID& cacheID, | 265 const GrCacheID& cacheID, |
| 266 const GrTextureParams* params) { | 266 const GrTextureParams* params) { |
| 267 GrResourceKey resourceKey = GrTexturePriv::ComputeKey(fGpu, params, desc, ca
cheID); | 267 GrResourceKey resourceKey = GrTexturePriv::ComputeKey(fGpu, params, desc, ca
cheID); |
| 268 GrGpuResource* resource = fResourceCache->find(resourceKey); | 268 GrGpuResource* resource = fResourceCache->find(resourceKey); |
| 269 SkSafeRef(resource); | 269 if (resource) { |
| 270 return static_cast<GrTexture*>(resource); | 270 resource->ref(); |
| 271 return static_cast<GrSurface*>(resource)->asTexture(); |
| 272 } else { |
| 273 return NULL; |
| 274 } |
| 271 } | 275 } |
| 272 | 276 |
| 273 bool GrContext::isTextureInCache(const GrSurfaceDesc& desc, | 277 bool GrContext::isTextureInCache(const GrSurfaceDesc& desc, |
| 274 const GrCacheID& cacheID, | 278 const GrCacheID& cacheID, |
| 275 const GrTextureParams* params) const { | 279 const GrTextureParams* params) const { |
| 276 GrResourceKey resourceKey = GrTexturePriv::ComputeKey(fGpu, params, desc, ca
cheID); | 280 GrResourceKey resourceKey = GrTexturePriv::ComputeKey(fGpu, params, desc, ca
cheID); |
| 277 return fResourceCache->hasKey(resourceKey); | 281 return fResourceCache->hasKey(resourceKey); |
| 278 } | 282 } |
| 279 | 283 |
| 280 void GrContext::addStencilBuffer(GrStencilBuffer* sb) { | 284 void GrContext::addStencilBuffer(GrStencilBuffer* sb) { |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 474 if (calledDuringFlush) { | 478 if (calledDuringFlush) { |
| 475 scratchFlags = GrResourceCache2::kRequireNoPendingIO_ScratchFlag
; | 479 scratchFlags = GrResourceCache2::kRequireNoPendingIO_ScratchFlag
; |
| 476 } else if (!(desc->fFlags & kRenderTarget_GrSurfaceFlag)) { | 480 } else if (!(desc->fFlags & kRenderTarget_GrSurfaceFlag)) { |
| 477 // If it is not a render target then it will most likely be popu
lated by | 481 // If it is not a render target then it will most likely be popu
lated by |
| 478 // writePixels() which will trigger a flush if the texture has p
ending IO. | 482 // writePixels() which will trigger a flush if the texture has p
ending IO. |
| 479 scratchFlags = GrResourceCache2::kPreferNoPendingIO_ScratchFlag; | 483 scratchFlags = GrResourceCache2::kPreferNoPendingIO_ScratchFlag; |
| 480 } | 484 } |
| 481 GrGpuResource* resource = fResourceCache2->findAndRefScratchResource
(key, scratchFlags); | 485 GrGpuResource* resource = fResourceCache2->findAndRefScratchResource
(key, scratchFlags); |
| 482 if (resource) { | 486 if (resource) { |
| 483 fResourceCache->makeResourceMRU(resource); | 487 fResourceCache->makeResourceMRU(resource); |
| 484 return static_cast<GrTexture*>(resource); | 488 return static_cast<GrSurface*>(resource)->asTexture(); |
| 485 } | 489 } |
| 486 | 490 |
| 487 if (kExact_ScratchTexMatch == match) { | 491 if (kExact_ScratchTexMatch == match) { |
| 488 break; | 492 break; |
| 489 } | 493 } |
| 490 // We had a cache miss and we are in approx mode, relax the fit of t
he flags. | 494 // We had a cache miss and we are in approx mode, relax the fit of t
he flags. |
| 491 | 495 |
| 492 // We no longer try to reuse textures that were previously used as r
ender targets in | 496 // We no longer try to reuse textures that were previously used as r
ender targets in |
| 493 // situations where no RT is needed; doing otherwise can confuse the
video driver and | 497 // situations where no RT is needed; doing otherwise can confuse the
video driver and |
| 494 // cause significant performance problems in some cases. | 498 // cause significant performance problems in some cases. |
| (...skipping 1306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1801 fResourceCache->printStats(); | 1805 fResourceCache->printStats(); |
| 1802 } | 1806 } |
| 1803 #endif | 1807 #endif |
| 1804 | 1808 |
| 1805 #if GR_GPU_STATS | 1809 #if GR_GPU_STATS |
| 1806 const GrContext::GPUStats* GrContext::gpuStats() const { | 1810 const GrContext::GPUStats* GrContext::gpuStats() const { |
| 1807 return fGpu->gpuStats(); | 1811 return fGpu->gpuStats(); |
| 1808 } | 1812 } |
| 1809 #endif | 1813 #endif |
| 1810 | 1814 |
| OLD | NEW |