| 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 |
| 11 #include "effects/GrConfigConversionEffect.h" | 11 #include "effects/GrConfigConversionEffect.h" |
| 12 #include "effects/GrDashingEffect.h" | 12 #include "effects/GrDashingEffect.h" |
| 13 #include "effects/GrSingleTextureEffect.h" | 13 #include "effects/GrSingleTextureEffect.h" |
| 14 | 14 |
| 15 #include "GrAARectRenderer.h" | 15 #include "GrAARectRenderer.h" |
| 16 #include "GrBufferAllocPool.h" | 16 #include "GrBufferAllocPool.h" |
| 17 #include "GrGpu.h" | 17 #include "GrGpu.h" |
| 18 #include "GrGpuResource.h" | 18 #include "GrGpuResource.h" |
| 19 #include "GrGpuResourceCacheAccess.h" | 19 #include "GrGpuResourceCacheAccess.h" |
| 20 #include "GrDistanceFieldTextContext.h" | 20 #include "GrDistanceFieldTextContext.h" |
| 21 #include "GrDrawTargetCaps.h" | 21 #include "GrDrawTargetCaps.h" |
| 22 #include "GrIndexBuffer.h" | 22 #include "GrIndexBuffer.h" |
| 23 #include "GrInOrderDrawBuffer.h" | 23 #include "GrInOrderDrawBuffer.h" |
| 24 #include "GrLayerCache.h" | 24 #include "GrLayerCache.h" |
| 25 #include "GrOvalRenderer.h" | 25 #include "GrOvalRenderer.h" |
| 26 #include "GrPathRenderer.h" | 26 #include "GrPathRenderer.h" |
| 27 #include "GrPathUtils.h" | 27 #include "GrPathUtils.h" |
| 28 #include "GrResourceCache.h" |
| 28 #include "GrResourceCache2.h" | 29 #include "GrResourceCache2.h" |
| 29 #include "GrSoftwarePathRenderer.h" | 30 #include "GrSoftwarePathRenderer.h" |
| 30 #include "GrStencilBuffer.h" | 31 #include "GrStencilBuffer.h" |
| 31 #include "GrStencilAndCoverTextContext.h" | 32 #include "GrStencilAndCoverTextContext.h" |
| 32 #include "GrStrokeInfo.h" | 33 #include "GrStrokeInfo.h" |
| 33 #include "GrSurfacePriv.h" | 34 #include "GrSurfacePriv.h" |
| 34 #include "GrTextStrike.h" | 35 #include "GrTextStrike.h" |
| 35 #include "GrTexturePriv.h" | 36 #include "GrTexturePriv.h" |
| 36 #include "GrTraceMarker.h" | 37 #include "GrTraceMarker.h" |
| 37 #include "GrTracing.h" | 38 #include "GrTracing.h" |
| 38 #include "SkDashPathPriv.h" | 39 #include "SkDashPathPriv.h" |
| 39 #include "SkConfig8888.h" | 40 #include "SkConfig8888.h" |
| 40 #include "SkGr.h" | 41 #include "SkGr.h" |
| 41 #include "SkRRect.h" | 42 #include "SkRRect.h" |
| 42 #include "SkStrokeRec.h" | 43 #include "SkStrokeRec.h" |
| 43 #include "SkTLazy.h" | 44 #include "SkTLazy.h" |
| 44 #include "SkTLS.h" | 45 #include "SkTLS.h" |
| 45 #include "SkTraceEvent.h" | 46 #include "SkTraceEvent.h" |
| 46 | 47 |
| 47 #ifdef SK_DEBUG | 48 #ifdef SK_DEBUG |
| 48 // change this to a 1 to see notifications when partial coverage fails | 49 // change this to a 1 to see notifications when partial coverage fails |
| 49 #define GR_DEBUG_PARTIAL_COVERAGE_CHECK 0 | 50 #define GR_DEBUG_PARTIAL_COVERAGE_CHECK 0 |
| 50 #else | 51 #else |
| 51 #define GR_DEBUG_PARTIAL_COVERAGE_CHECK 0 | 52 #define GR_DEBUG_PARTIAL_COVERAGE_CHECK 0 |
| 52 #endif | 53 #endif |
| 53 | 54 |
| 55 static const size_t MAX_RESOURCE_CACHE_COUNT = GR_DEFAULT_RESOURCE_CACHE_COUNT_L
IMIT; |
| 56 static const size_t MAX_RESOURCE_CACHE_BYTES = GR_DEFAULT_RESOURCE_CACHE_MB_LIMI
T * 1024 * 1024; |
| 57 |
| 54 static const size_t DRAW_BUFFER_VBPOOL_BUFFER_SIZE = 1 << 15; | 58 static const size_t DRAW_BUFFER_VBPOOL_BUFFER_SIZE = 1 << 15; |
| 55 static const int DRAW_BUFFER_VBPOOL_PREALLOC_BUFFERS = 4; | 59 static const int DRAW_BUFFER_VBPOOL_PREALLOC_BUFFERS = 4; |
| 56 | 60 |
| 57 static const size_t DRAW_BUFFER_IBPOOL_BUFFER_SIZE = 1 << 11; | 61 static const size_t DRAW_BUFFER_IBPOOL_BUFFER_SIZE = 1 << 11; |
| 58 static const int DRAW_BUFFER_IBPOOL_PREALLOC_BUFFERS = 4; | 62 static const int DRAW_BUFFER_IBPOOL_PREALLOC_BUFFERS = 4; |
| 59 | 63 |
| 60 #define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == this) | 64 #define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == this) |
| 61 | 65 |
| 62 // Glorified typedef to avoid including GrDrawState.h in GrContext.h | 66 // Glorified typedef to avoid including GrDrawState.h in GrContext.h |
| 63 class GrContext::AutoRestoreEffects : public GrDrawState::AutoRestoreEffects {}; | 67 class GrContext::AutoRestoreEffects : public GrDrawState::AutoRestoreEffects {}; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 92 return NULL; | 96 return NULL; |
| 93 } | 97 } |
| 94 } | 98 } |
| 95 | 99 |
| 96 GrContext::GrContext(const Options& opts) : fOptions(opts) { | 100 GrContext::GrContext(const Options& opts) : fOptions(opts) { |
| 97 fDrawState = NULL; | 101 fDrawState = NULL; |
| 98 fGpu = NULL; | 102 fGpu = NULL; |
| 99 fClip = NULL; | 103 fClip = NULL; |
| 100 fPathRendererChain = NULL; | 104 fPathRendererChain = NULL; |
| 101 fSoftwarePathRenderer = NULL; | 105 fSoftwarePathRenderer = NULL; |
| 106 fResourceCache = NULL; |
| 102 fResourceCache2 = NULL; | 107 fResourceCache2 = NULL; |
| 103 fFontCache = NULL; | 108 fFontCache = NULL; |
| 104 fDrawBuffer = NULL; | 109 fDrawBuffer = NULL; |
| 105 fDrawBufferVBAllocPool = NULL; | 110 fDrawBufferVBAllocPool = NULL; |
| 106 fDrawBufferIBAllocPool = NULL; | 111 fDrawBufferIBAllocPool = NULL; |
| 107 fFlushToReduceCacheSize = false; | 112 fFlushToReduceCacheSize = false; |
| 108 fAARectRenderer = NULL; | 113 fAARectRenderer = NULL; |
| 109 fOvalRenderer = NULL; | 114 fOvalRenderer = NULL; |
| 110 fViewMatrix.reset(); | 115 fViewMatrix.reset(); |
| 111 fMaxTextureSizeOverride = 1 << 20; | 116 fMaxTextureSizeOverride = 1 << 20; |
| 112 } | 117 } |
| 113 | 118 |
| 114 bool GrContext::init(GrBackend backend, GrBackendContext backendContext) { | 119 bool GrContext::init(GrBackend backend, GrBackendContext backendContext) { |
| 115 SkASSERT(NULL == fGpu); | 120 SkASSERT(NULL == fGpu); |
| 116 | 121 |
| 117 fGpu = GrGpu::Create(backend, backendContext, this); | 122 fGpu = GrGpu::Create(backend, backendContext, this); |
| 118 if (NULL == fGpu) { | 123 if (NULL == fGpu) { |
| 119 return false; | 124 return false; |
| 120 } | 125 } |
| 121 this->initCommon(); | 126 this->initCommon(); |
| 122 return true; | 127 return true; |
| 123 } | 128 } |
| 124 | 129 |
| 125 void GrContext::initCommon() { | 130 void GrContext::initCommon() { |
| 126 fDrawState = SkNEW(GrDrawState); | 131 fDrawState = SkNEW(GrDrawState); |
| 127 | 132 |
| 133 fResourceCache = SkNEW_ARGS(GrResourceCache, (fGpu->caps(), |
| 134 MAX_RESOURCE_CACHE_COUNT, |
| 135 MAX_RESOURCE_CACHE_BYTES)); |
| 136 fResourceCache->setOverbudgetCallback(OverbudgetCB, this); |
| 128 fResourceCache2 = SkNEW(GrResourceCache2); | 137 fResourceCache2 = SkNEW(GrResourceCache2); |
| 129 fResourceCache2->setOverBudgetCallback(OverBudgetCB, this); | |
| 130 | 138 |
| 131 fFontCache = SkNEW_ARGS(GrFontCache, (fGpu)); | 139 fFontCache = SkNEW_ARGS(GrFontCache, (fGpu)); |
| 132 | 140 |
| 133 fLayerCache.reset(SkNEW_ARGS(GrLayerCache, (this))); | 141 fLayerCache.reset(SkNEW_ARGS(GrLayerCache, (this))); |
| 134 | 142 |
| 135 fAARectRenderer = SkNEW_ARGS(GrAARectRenderer, (fGpu)); | 143 fAARectRenderer = SkNEW_ARGS(GrAARectRenderer, (fGpu)); |
| 136 fOvalRenderer = SkNEW(GrOvalRenderer); | 144 fOvalRenderer = SkNEW(GrOvalRenderer); |
| 137 | 145 |
| 138 fDidTestPMConversions = false; | 146 fDidTestPMConversions = false; |
| 139 | 147 |
| 140 this->setupDrawBuffer(); | 148 this->setupDrawBuffer(); |
| 141 } | 149 } |
| 142 | 150 |
| 143 GrContext::~GrContext() { | 151 GrContext::~GrContext() { |
| 144 if (NULL == fGpu) { | 152 if (NULL == fGpu) { |
| 145 return; | 153 return; |
| 146 } | 154 } |
| 147 | 155 |
| 148 this->flush(); | 156 this->flush(); |
| 149 | 157 |
| 150 for (int i = 0; i < fCleanUpData.count(); ++i) { | 158 for (int i = 0; i < fCleanUpData.count(); ++i) { |
| 151 (*fCleanUpData[i].fFunc)(this, fCleanUpData[i].fInfo); | 159 (*fCleanUpData[i].fFunc)(this, fCleanUpData[i].fInfo); |
| 152 } | 160 } |
| 153 | 161 |
| 154 SkDELETE(fResourceCache2); | 162 SkDELETE(fResourceCache2); |
| 163 fResourceCache2 = NULL; |
| 164 SkDELETE(fResourceCache); |
| 165 fResourceCache = NULL; |
| 155 SkDELETE(fFontCache); | 166 SkDELETE(fFontCache); |
| 156 SkDELETE(fDrawBuffer); | 167 SkDELETE(fDrawBuffer); |
| 157 SkDELETE(fDrawBufferVBAllocPool); | 168 SkDELETE(fDrawBufferVBAllocPool); |
| 158 SkDELETE(fDrawBufferIBAllocPool); | 169 SkDELETE(fDrawBufferIBAllocPool); |
| 159 | 170 |
| 160 fAARectRenderer->unref(); | 171 fAARectRenderer->unref(); |
| 161 fOvalRenderer->unref(); | 172 fOvalRenderer->unref(); |
| 162 | 173 |
| 163 fGpu->unref(); | 174 fGpu->unref(); |
| 164 SkSafeUnref(fPathRendererChain); | 175 SkSafeUnref(fPathRendererChain); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 183 | 194 |
| 184 delete fDrawBufferVBAllocPool; | 195 delete fDrawBufferVBAllocPool; |
| 185 fDrawBufferVBAllocPool = NULL; | 196 fDrawBufferVBAllocPool = NULL; |
| 186 | 197 |
| 187 delete fDrawBufferIBAllocPool; | 198 delete fDrawBufferIBAllocPool; |
| 188 fDrawBufferIBAllocPool = NULL; | 199 fDrawBufferIBAllocPool = NULL; |
| 189 | 200 |
| 190 fAARectRenderer->reset(); | 201 fAARectRenderer->reset(); |
| 191 fOvalRenderer->reset(); | 202 fOvalRenderer->reset(); |
| 192 | 203 |
| 204 fResourceCache->purgeAllUnlocked(); |
| 205 |
| 193 fFontCache->freeAll(); | 206 fFontCache->freeAll(); |
| 194 fLayerCache->freeAll(); | 207 fLayerCache->freeAll(); |
| 195 } | 208 } |
| 196 | 209 |
| 197 void GrContext::resetContext(uint32_t state) { | 210 void GrContext::resetContext(uint32_t state) { |
| 198 fGpu->markContextDirty(state); | 211 fGpu->markContextDirty(state); |
| 199 } | 212 } |
| 200 | 213 |
| 201 void GrContext::freeGpuResources() { | 214 void GrContext::freeGpuResources() { |
| 202 this->flush(); | 215 this->flush(); |
| 203 | 216 |
| 204 if (fDrawBuffer) { | 217 if (fDrawBuffer) { |
| 205 fDrawBuffer->purgeResources(); | 218 fDrawBuffer->purgeResources(); |
| 206 } | 219 } |
| 207 | 220 |
| 208 fAARectRenderer->reset(); | 221 fAARectRenderer->reset(); |
| 209 fOvalRenderer->reset(); | 222 fOvalRenderer->reset(); |
| 210 | 223 |
| 224 fResourceCache->purgeAllUnlocked(); |
| 211 fFontCache->freeAll(); | 225 fFontCache->freeAll(); |
| 212 fLayerCache->freeAll(); | 226 fLayerCache->freeAll(); |
| 213 // a path renderer may be holding onto resources | 227 // a path renderer may be holding onto resources |
| 214 SkSafeSetNull(fPathRendererChain); | 228 SkSafeSetNull(fPathRendererChain); |
| 215 SkSafeSetNull(fSoftwarePathRenderer); | 229 SkSafeSetNull(fSoftwarePathRenderer); |
| 216 } | 230 } |
| 217 | 231 |
| 218 void GrContext::getResourceCacheUsage(int* resourceCount, size_t* resourceBytes)
const { | 232 void GrContext::getResourceCacheUsage(int* resourceCount, size_t* resourceBytes)
const { |
| 219 if (resourceCount) { | 233 if (resourceCount) { |
| 220 *resourceCount = fResourceCache2->getResourceCount(); | 234 *resourceCount = fResourceCache->getCachedResourceCount(); |
| 221 } | 235 } |
| 222 if (resourceBytes) { | 236 if (resourceBytes) { |
| 223 *resourceBytes = fResourceCache2->getResourceBytes(); | 237 *resourceBytes = fResourceCache->getCachedResourceBytes(); |
| 224 } | 238 } |
| 225 } | 239 } |
| 226 | 240 |
| 227 GrTextContext* GrContext::createTextContext(GrRenderTarget* renderTarget, | 241 GrTextContext* GrContext::createTextContext(GrRenderTarget* renderTarget, |
| 228 const SkDeviceProperties& | 242 const SkDeviceProperties& |
| 229 leakyProperties, | 243 leakyProperties, |
| 230 bool enableDistanceFieldFonts) { | 244 bool enableDistanceFieldFonts) { |
| 231 if (fGpu->caps()->pathRenderingSupport() && renderTarget->getStencilBuffer()
&& | 245 if (fGpu->caps()->pathRenderingSupport() && renderTarget->getStencilBuffer()
&& |
| 232 renderTarget->isMultisampled())
{ | 246 renderTarget->isMultisampled())
{ |
| 233 return GrStencilAndCoverTextContext::Create(this, leakyProperties); | 247 return GrStencilAndCoverTextContext::Create(this, leakyProperties); |
| 234 } | 248 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 252 } | 266 } |
| 253 | 267 |
| 254 bool GrContext::isTextureInCache(const GrSurfaceDesc& desc, | 268 bool GrContext::isTextureInCache(const GrSurfaceDesc& desc, |
| 255 const GrCacheID& cacheID, | 269 const GrCacheID& cacheID, |
| 256 const GrTextureParams* params) const { | 270 const GrTextureParams* params) const { |
| 257 GrResourceKey resourceKey = GrTexturePriv::ComputeKey(fGpu, params, desc, ca
cheID); | 271 GrResourceKey resourceKey = GrTexturePriv::ComputeKey(fGpu, params, desc, ca
cheID); |
| 258 return fResourceCache2->hasContentKey(resourceKey); | 272 return fResourceCache2->hasContentKey(resourceKey); |
| 259 } | 273 } |
| 260 | 274 |
| 261 void GrContext::addStencilBuffer(GrStencilBuffer* sb) { | 275 void GrContext::addStencilBuffer(GrStencilBuffer* sb) { |
| 262 // TODO: Make GrStencilBuffers use the scratch mechanism rather than content
keys. | |
| 263 ASSERT_OWNED_RESOURCE(sb); | 276 ASSERT_OWNED_RESOURCE(sb); |
| 264 | 277 |
| 265 GrResourceKey resourceKey = GrStencilBuffer::ComputeKey(sb->width(), | 278 GrResourceKey resourceKey = GrStencilBuffer::ComputeKey(sb->width(), |
| 266 sb->height(), | 279 sb->height(), |
| 267 sb->numSamples()); | 280 sb->numSamples()); |
| 268 SkAssertResult(sb->cacheAccess().setContentKey(resourceKey)); | 281 fResourceCache->addResource(resourceKey, sb); |
| 269 } | 282 } |
| 270 | 283 |
| 271 GrStencilBuffer* GrContext::findAndRefStencilBuffer(int width, int height, int s
ampleCnt) { | 284 GrStencilBuffer* GrContext::findAndRefStencilBuffer(int width, int height, int s
ampleCnt) { |
| 272 GrResourceKey resourceKey = GrStencilBuffer::ComputeKey(width, height, sampl
eCnt); | 285 GrResourceKey resourceKey = GrStencilBuffer::ComputeKey(width, height, sampl
eCnt); |
| 273 GrGpuResource* resource = this->findAndRefCachedResource(resourceKey); | 286 GrGpuResource* resource = this->findAndRefCachedResource(resourceKey); |
| 274 return static_cast<GrStencilBuffer*>(resource); | 287 return static_cast<GrStencilBuffer*>(resource); |
| 275 } | 288 } |
| 276 | 289 |
| 277 static void stretch_image(void* dst, | 290 static void stretch_image(void* dst, |
| 278 int dstW, | 291 int dstW, |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 SkASSERT(!GrPixelConfigIsCompressed(desc.fConfig)); | 413 SkASSERT(!GrPixelConfigIsCompressed(desc.fConfig)); |
| 401 | 414 |
| 402 texture = this->createResizedTexture(desc, cacheID, | 415 texture = this->createResizedTexture(desc, cacheID, |
| 403 srcData, rowBytes, | 416 srcData, rowBytes, |
| 404 GrTexturePriv::NeedsBilerp(resource
Key)); | 417 GrTexturePriv::NeedsBilerp(resource
Key)); |
| 405 } else { | 418 } else { |
| 406 texture = fGpu->createTexture(desc, srcData, rowBytes); | 419 texture = fGpu->createTexture(desc, srcData, rowBytes); |
| 407 } | 420 } |
| 408 | 421 |
| 409 if (texture) { | 422 if (texture) { |
| 410 if (texture->cacheAccess().setContentKey(resourceKey)) { | 423 fResourceCache->addResource(resourceKey, texture); |
| 411 if (cacheKey) { | 424 |
| 412 *cacheKey = resourceKey; | 425 if (cacheKey) { |
| 413 } | 426 *cacheKey = resourceKey; |
| 414 } else { | |
| 415 texture->unref(); | |
| 416 texture = NULL; | |
| 417 } | 427 } |
| 418 } | 428 } |
| 419 | 429 |
| 420 return texture; | 430 return texture; |
| 421 } | 431 } |
| 422 | 432 |
| 433 GrTexture* GrContext::createNewScratchTexture(const GrSurfaceDesc& desc) { |
| 434 GrTexture* texture = fGpu->createTexture(desc, NULL, 0); |
| 435 if (!texture) { |
| 436 return NULL; |
| 437 } |
| 438 fResourceCache->addResource(texture->cacheAccess().getScratchKey(), texture)
; |
| 439 return texture; |
| 440 } |
| 441 |
| 423 GrTexture* GrContext::refScratchTexture(const GrSurfaceDesc& inDesc, ScratchTexM
atch match, | 442 GrTexture* GrContext::refScratchTexture(const GrSurfaceDesc& inDesc, ScratchTexM
atch match, |
| 424 bool calledDuringFlush) { | 443 bool calledDuringFlush) { |
| 425 // kNoStencil has no meaning if kRT isn't set. | 444 // kNoStencil has no meaning if kRT isn't set. |
| 426 SkASSERT((inDesc.fFlags & kRenderTarget_GrSurfaceFlag) || | 445 SkASSERT((inDesc.fFlags & kRenderTarget_GrSurfaceFlag) || |
| 427 !(inDesc.fFlags & kNoStencil_GrSurfaceFlag)); | 446 !(inDesc.fFlags & kNoStencil_GrSurfaceFlag)); |
| 428 | 447 |
| 429 // Make sure caller has checked for renderability if kRT is set. | 448 // Make sure caller has checked for renderability if kRT is set. |
| 430 SkASSERT(!(inDesc.fFlags & kRenderTarget_GrSurfaceFlag) || | 449 SkASSERT(!(inDesc.fFlags & kRenderTarget_GrSurfaceFlag) || |
| 431 this->isConfigRenderable(inDesc.fConfig, inDesc.fSampleCnt > 0)); | 450 this->isConfigRenderable(inDesc.fConfig, inDesc.fSampleCnt > 0)); |
| 432 | 451 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 447 uint32_t scratchFlags = 0; | 466 uint32_t scratchFlags = 0; |
| 448 if (calledDuringFlush) { | 467 if (calledDuringFlush) { |
| 449 scratchFlags = GrResourceCache2::kRequireNoPendingIO_ScratchFlag
; | 468 scratchFlags = GrResourceCache2::kRequireNoPendingIO_ScratchFlag
; |
| 450 } else if (!(desc->fFlags & kRenderTarget_GrSurfaceFlag)) { | 469 } else if (!(desc->fFlags & kRenderTarget_GrSurfaceFlag)) { |
| 451 // If it is not a render target then it will most likely be popu
lated by | 470 // If it is not a render target then it will most likely be popu
lated by |
| 452 // writePixels() which will trigger a flush if the texture has p
ending IO. | 471 // writePixels() which will trigger a flush if the texture has p
ending IO. |
| 453 scratchFlags = GrResourceCache2::kPreferNoPendingIO_ScratchFlag; | 472 scratchFlags = GrResourceCache2::kPreferNoPendingIO_ScratchFlag; |
| 454 } | 473 } |
| 455 GrGpuResource* resource = fResourceCache2->findAndRefScratchResource
(key, scratchFlags); | 474 GrGpuResource* resource = fResourceCache2->findAndRefScratchResource
(key, scratchFlags); |
| 456 if (resource) { | 475 if (resource) { |
| 476 fResourceCache->makeResourceMRU(resource); |
| 457 return static_cast<GrSurface*>(resource)->asTexture(); | 477 return static_cast<GrSurface*>(resource)->asTexture(); |
| 458 } | 478 } |
| 459 | 479 |
| 460 if (kExact_ScratchTexMatch == match) { | 480 if (kExact_ScratchTexMatch == match) { |
| 461 break; | 481 break; |
| 462 } | 482 } |
| 463 // We had a cache miss and we are in approx mode, relax the fit of t
he flags. | 483 // We had a cache miss and we are in approx mode, relax the fit of t
he flags. |
| 464 | 484 |
| 465 // We no longer try to reuse textures that were previously used as r
ender targets in | 485 // We no longer try to reuse textures that were previously used as r
ender targets in |
| 466 // situations where no RT is needed; doing otherwise can confuse the
video driver and | 486 // situations where no RT is needed; doing otherwise can confuse the
video driver and |
| 467 // cause significant performance problems in some cases. | 487 // cause significant performance problems in some cases. |
| 468 if (desc->fFlags & kNoStencil_GrSurfaceFlag) { | 488 if (desc->fFlags & kNoStencil_GrSurfaceFlag) { |
| 469 desc.writable()->fFlags = desc->fFlags & ~kNoStencil_GrSurfaceFl
ag; | 489 desc.writable()->fFlags = desc->fFlags & ~kNoStencil_GrSurfaceFl
ag; |
| 470 } else { | 490 } else { |
| 471 break; | 491 break; |
| 472 } | 492 } |
| 473 | 493 |
| 474 } while (true); | 494 } while (true); |
| 475 | 495 |
| 476 desc.writable()->fFlags = origFlags; | 496 desc.writable()->fFlags = origFlags; |
| 477 } | 497 } |
| 478 | 498 |
| 479 GrTexture* texture = fGpu->createTexture(*desc, NULL, 0); | 499 GrTexture* texture = this->createNewScratchTexture(*desc); |
| 480 SkASSERT(NULL == texture || | 500 SkASSERT(NULL == texture || |
| 481 texture->cacheAccess().getScratchKey() == GrTexturePriv::ComputeScr
atchKey(*desc)); | 501 texture->cacheAccess().getScratchKey() == GrTexturePriv::ComputeScr
atchKey(*desc)); |
| 482 return texture; | 502 return texture; |
| 483 } | 503 } |
| 484 | 504 |
| 485 void GrContext::OverBudgetCB(void* data) { | 505 bool GrContext::OverbudgetCB(void* data) { |
| 486 SkASSERT(data); | 506 SkASSERT(data); |
| 487 | 507 |
| 488 GrContext* context = reinterpret_cast<GrContext*>(data); | 508 GrContext* context = reinterpret_cast<GrContext*>(data); |
| 489 | 509 |
| 490 // Flush the InOrderDrawBuffer to possibly free up some textures | 510 // Flush the InOrderDrawBuffer to possibly free up some textures |
| 491 context->fFlushToReduceCacheSize = true; | 511 context->fFlushToReduceCacheSize = true; |
| 512 |
| 513 return true; |
| 492 } | 514 } |
| 493 | 515 |
| 494 | 516 |
| 495 GrTexture* GrContext::createUncachedTexture(const GrSurfaceDesc& descIn, | 517 GrTexture* GrContext::createUncachedTexture(const GrSurfaceDesc& descIn, |
| 496 void* srcData, | 518 void* srcData, |
| 497 size_t rowBytes) { | 519 size_t rowBytes) { |
| 498 GrSurfaceDesc descCopy = descIn; | 520 GrSurfaceDesc descCopy = descIn; |
| 499 return fGpu->createTexture(descCopy, srcData, rowBytes); | 521 return fGpu->createTexture(descCopy, srcData, rowBytes); |
| 500 } | 522 } |
| 501 | 523 |
| 502 void GrContext::getResourceCacheLimits(int* maxTextures, size_t* maxTextureBytes
) const { | 524 void GrContext::getResourceCacheLimits(int* maxTextures, size_t* maxTextureBytes
) const { |
| 503 if (maxTextures) { | 525 fResourceCache->getLimits(maxTextures, maxTextureBytes); |
| 504 *maxTextures = fResourceCache2->getMaxResourceCount(); | |
| 505 } | |
| 506 if (maxTextureBytes) { | |
| 507 *maxTextureBytes = fResourceCache2->getMaxResourceBytes(); | |
| 508 } | |
| 509 } | 526 } |
| 510 | 527 |
| 511 void GrContext::setResourceCacheLimits(int maxTextures, size_t maxTextureBytes)
{ | 528 void GrContext::setResourceCacheLimits(int maxTextures, size_t maxTextureBytes)
{ |
| 512 fResourceCache2->setLimits(maxTextures, maxTextureBytes); | 529 fResourceCache->setLimits(maxTextures, maxTextureBytes); |
| 513 } | 530 } |
| 514 | 531 |
| 515 int GrContext::getMaxTextureSize() const { | 532 int GrContext::getMaxTextureSize() const { |
| 516 return SkTMin(fGpu->caps()->maxTextureSize(), fMaxTextureSizeOverride); | 533 return SkTMin(fGpu->caps()->maxTextureSize(), fMaxTextureSizeOverride); |
| 517 } | 534 } |
| 518 | 535 |
| 519 int GrContext::getMaxRenderTargetSize() const { | 536 int GrContext::getMaxRenderTargetSize() const { |
| 520 return fGpu->caps()->maxRenderTargetSize(); | 537 return fGpu->caps()->maxRenderTargetSize(); |
| 521 } | 538 } |
| 522 | 539 |
| (...skipping 695 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1218 void GrContext::flush(int flagsBitfield) { | 1235 void GrContext::flush(int flagsBitfield) { |
| 1219 if (NULL == fDrawBuffer) { | 1236 if (NULL == fDrawBuffer) { |
| 1220 return; | 1237 return; |
| 1221 } | 1238 } |
| 1222 | 1239 |
| 1223 if (kDiscard_FlushBit & flagsBitfield) { | 1240 if (kDiscard_FlushBit & flagsBitfield) { |
| 1224 fDrawBuffer->reset(); | 1241 fDrawBuffer->reset(); |
| 1225 } else { | 1242 } else { |
| 1226 fDrawBuffer->flush(); | 1243 fDrawBuffer->flush(); |
| 1227 } | 1244 } |
| 1245 fResourceCache->purgeAsNeeded(); |
| 1228 fFlushToReduceCacheSize = false; | 1246 fFlushToReduceCacheSize = false; |
| 1229 } | 1247 } |
| 1230 | 1248 |
| 1231 bool sw_convert_to_premul(GrPixelConfig srcConfig, int width, int height, size_t
inRowBytes, | 1249 bool sw_convert_to_premul(GrPixelConfig srcConfig, int width, int height, size_t
inRowBytes, |
| 1232 const void* inPixels, size_t outRowBytes, void* outPix
els) { | 1250 const void* inPixels, size_t outRowBytes, void* outPix
els) { |
| 1233 SkSrcPixelInfo srcPI; | 1251 SkSrcPixelInfo srcPI; |
| 1234 if (!GrPixelConfig2ColorType(srcConfig, &srcPI.fColorType)) { | 1252 if (!GrPixelConfig2ColorType(srcConfig, &srcPI.fColorType)) { |
| 1235 return false; | 1253 return false; |
| 1236 } | 1254 } |
| 1237 srcPI.fAlphaType = kUnpremul_SkAlphaType; | 1255 srcPI.fAlphaType = kUnpremul_SkAlphaType; |
| (...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1721 GrConfigConversionEffect::PMConversion upmToPM = | 1739 GrConfigConversionEffect::PMConversion upmToPM = |
| 1722 static_cast<GrConfigConversionEffect::PMConversion>(fUPMToPMConversion); | 1740 static_cast<GrConfigConversionEffect::PMConversion>(fUPMToPMConversion); |
| 1723 if (GrConfigConversionEffect::kNone_PMConversion != upmToPM) { | 1741 if (GrConfigConversionEffect::kNone_PMConversion != upmToPM) { |
| 1724 return GrConfigConversionEffect::Create(texture, swapRAndB, upmToPM, mat
rix); | 1742 return GrConfigConversionEffect::Create(texture, swapRAndB, upmToPM, mat
rix); |
| 1725 } else { | 1743 } else { |
| 1726 return NULL; | 1744 return NULL; |
| 1727 } | 1745 } |
| 1728 } | 1746 } |
| 1729 | 1747 |
| 1730 void GrContext::addResourceToCache(const GrResourceKey& resourceKey, GrGpuResour
ce* resource) { | 1748 void GrContext::addResourceToCache(const GrResourceKey& resourceKey, GrGpuResour
ce* resource) { |
| 1731 resource->cacheAccess().setContentKey(resourceKey); | 1749 fResourceCache->addResource(resourceKey, resource); |
| 1732 } | 1750 } |
| 1733 | 1751 |
| 1734 GrGpuResource* GrContext::findAndRefCachedResource(const GrResourceKey& resource
Key) { | 1752 GrGpuResource* GrContext::findAndRefCachedResource(const GrResourceKey& resource
Key) { |
| 1735 return fResourceCache2->findAndRefContentResource(resourceKey); | 1753 GrGpuResource* resource = fResourceCache2->findAndRefContentResource(resourc
eKey); |
| 1754 if (resource) { |
| 1755 fResourceCache->makeResourceMRU(resource); |
| 1756 } |
| 1757 return resource; |
| 1736 } | 1758 } |
| 1737 | 1759 |
| 1738 void GrContext::addGpuTraceMarker(const GrGpuTraceMarker* marker) { | 1760 void GrContext::addGpuTraceMarker(const GrGpuTraceMarker* marker) { |
| 1739 fGpu->addGpuTraceMarker(marker); | 1761 fGpu->addGpuTraceMarker(marker); |
| 1740 if (fDrawBuffer) { | 1762 if (fDrawBuffer) { |
| 1741 fDrawBuffer->addGpuTraceMarker(marker); | 1763 fDrawBuffer->addGpuTraceMarker(marker); |
| 1742 } | 1764 } |
| 1743 } | 1765 } |
| 1744 | 1766 |
| 1745 void GrContext::removeGpuTraceMarker(const GrGpuTraceMarker* marker) { | 1767 void GrContext::removeGpuTraceMarker(const GrGpuTraceMarker* marker) { |
| 1746 fGpu->removeGpuTraceMarker(marker); | 1768 fGpu->removeGpuTraceMarker(marker); |
| 1747 if (fDrawBuffer) { | 1769 if (fDrawBuffer) { |
| 1748 fDrawBuffer->removeGpuTraceMarker(marker); | 1770 fDrawBuffer->removeGpuTraceMarker(marker); |
| 1749 } | 1771 } |
| 1750 } | 1772 } |
| 1751 | 1773 |
| 1752 /////////////////////////////////////////////////////////////////////////////// | 1774 /////////////////////////////////////////////////////////////////////////////// |
| 1753 #if GR_CACHE_STATS | 1775 #if GR_CACHE_STATS |
| 1754 void GrContext::printCacheStats() const { | 1776 void GrContext::printCacheStats() const { |
| 1755 fResourceCache2->printStats(); | 1777 fResourceCache->printStats(); |
| 1756 } | 1778 } |
| 1757 #endif | 1779 #endif |
| 1758 | 1780 |
| 1759 #if GR_GPU_STATS | 1781 #if GR_GPU_STATS |
| 1760 const GrContext::GPUStats* GrContext::gpuStats() const { | 1782 const GrContext::GPUStats* GrContext::gpuStats() const { |
| 1761 return fGpu->gpuStats(); | 1783 return fGpu->gpuStats(); |
| 1762 } | 1784 } |
| 1763 #endif | 1785 #endif |
| 1764 | 1786 |
| OLD | NEW |