diff options
author | 2015-02-23 09:06:38 -0800 | |
---|---|---|
committer | 2015-02-23 09:06:38 -0800 | |
commit | 6bc1b5fab8554a9cb643277b4867965dd4535cd6 (patch) | |
tree | 3179261534d7db7a8264735b327daa59593e1dd0 /src/gpu/GrContext.cpp | |
parent | 42380174ca509e78ab932fa8c6dae953e1eaaa5a (diff) |
Dynamically create stencil buffer when needed.
Review URL: https://codereview.chromium.org/938383004
Diffstat (limited to 'src/gpu/GrContext.cpp')
-rwxr-xr-x | src/gpu/GrContext.cpp | 68 |
1 files changed, 24 insertions, 44 deletions
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp index a4679a923c..98e78d9926 100755 --- a/src/gpu/GrContext.cpp +++ b/src/gpu/GrContext.cpp @@ -23,6 +23,7 @@ #include "GrOvalRenderer.h" #include "GrPathRenderer.h" #include "GrPathUtils.h" +#include "GrRenderTargetPriv.h" #include "GrResourceCache.h" #include "GrSoftwarePathRenderer.h" #include "GrStencilAndCoverTextContext.h" @@ -213,9 +214,11 @@ GrTextContext* GrContext::createTextContext(GrRenderTarget* renderTarget, const SkDeviceProperties& leakyProperties, bool enableDistanceFieldFonts) { - if (fGpu->caps()->pathRenderingSupport() && renderTarget->getStencilBuffer() && - renderTarget->isMultisampled()) { - return GrStencilAndCoverTextContext::Create(this, leakyProperties); + if (fGpu->caps()->pathRenderingSupport() && renderTarget->isMultisampled()) { + GrStencilBuffer* sb = renderTarget->renderTargetPriv().attachStencilBuffer(); + if (sb) { + return GrStencilAndCoverTextContext::Create(this, leakyProperties); + } } return GrDistanceFieldTextContext::Create(this, leakyProperties, enableDistanceFieldFonts); @@ -278,14 +281,10 @@ GrTexture* GrContext::refScratchTexture(const GrSurfaceDesc& desc, ScratchTexMat GrTexture* GrContext::internalRefScratchTexture(const GrSurfaceDesc& inDesc, uint32_t flags) { SkASSERT(!GrPixelConfigIsCompressed(inDesc.fConfig)); - // kNoStencil has no meaning if kRT isn't set. - SkASSERT((inDesc.fFlags & kRenderTarget_GrSurfaceFlag) || - !(inDesc.fFlags & kNoStencil_GrSurfaceFlag)); SkTCopyOnFirstWrite<GrSurfaceDesc> desc(inDesc); if (fGpu->caps()->reuseScratchTextures() || (desc->fFlags & kRenderTarget_GrSurfaceFlag)) { - GrSurfaceFlags origFlags = desc->fFlags; if (!(kExact_ScratchTextureFlag & flags)) { // bin by pow2 with a reasonable min static const int MIN_SIZE = 16; @@ -294,44 +293,25 @@ GrTexture* GrContext::internalRefScratchTexture(const GrSurfaceDesc& inDesc, uin wdesc->fHeight = SkTMax(MIN_SIZE, GrNextPow2(desc->fHeight)); } - do { - GrScratchKey key; - GrTexturePriv::ComputeScratchKey(*desc, &key); - uint32_t scratchFlags = 0; - if (kNoPendingIO_ScratchTextureFlag & flags) { - scratchFlags = GrResourceCache::kRequireNoPendingIO_ScratchFlag; - } else if (!(desc->fFlags & kRenderTarget_GrSurfaceFlag)) { - // If it is not a render target then it will most likely be populated by - // writePixels() which will trigger a flush if the texture has pending IO. - scratchFlags = GrResourceCache::kPreferNoPendingIO_ScratchFlag; - } - GrGpuResource* resource = fResourceCache->findAndRefScratchResource(key, scratchFlags); - if (resource) { - GrSurface* surface = static_cast<GrSurface*>(resource); - GrRenderTarget* rt = surface->asRenderTarget(); - if (rt && fGpu->caps()->discardRenderTargetSupport()) { - rt->discard(); - } - return surface->asTexture(); - } - - if (kExact_ScratchTextureFlag & flags) { - break; - } - // We had a cache miss and we are in approx mode, relax the fit of the flags. - - // We no longer try to reuse textures that were previously used as render targets in - // situations where no RT is needed; doing otherwise can confuse the video driver and - // cause significant performance problems in some cases. - if (desc->fFlags & kNoStencil_GrSurfaceFlag) { - desc.writable()->fFlags = desc->fFlags & ~kNoStencil_GrSurfaceFlag; - } else { - break; + GrScratchKey key; + GrTexturePriv::ComputeScratchKey(*desc, &key); + uint32_t scratchFlags = 0; + if (kNoPendingIO_ScratchTextureFlag & flags) { + scratchFlags = GrResourceCache::kRequireNoPendingIO_ScratchFlag; + } else if (!(desc->fFlags & kRenderTarget_GrSurfaceFlag)) { + // If it is not a render target then it will most likely be populated by + // writePixels() which will trigger a flush if the texture has pending IO. + scratchFlags = GrResourceCache::kPreferNoPendingIO_ScratchFlag; + } + GrGpuResource* resource = fResourceCache->findAndRefScratchResource(key, scratchFlags); + if (resource) { + GrSurface* surface = static_cast<GrSurface*>(resource); + GrRenderTarget* rt = surface->asRenderTarget(); + if (rt && fGpu->caps()->discardRenderTargetSupport()) { + rt->discard(); } - - } while (true); - - desc.writable()->fFlags = origFlags; + return surface->asTexture(); + } } if (!(kNoCreate_ScratchTextureFlag & flags)) { |