diff options
author | bsalomon <bsalomon@google.com> | 2015-02-06 08:49:24 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-02-06 08:49:24 -0800 |
commit | d0423587ac56ae84d3f1eb796d5c1e2dfba9646e (patch) | |
tree | 1bbbc8adbc1b63dc7dd19ffc08889be9a80b89c5 /src | |
parent | 02c8fd0ad5e5279004dd49ec49fbae00f8522ec0 (diff) |
One createTexture function, attempt to recycle scratch in createTexture.
Review URL: https://codereview.chromium.org/864383003
Diffstat (limited to 'src')
-rw-r--r-- | src/effects/SkBlurMaskFilter.cpp | 4 | ||||
-rw-r--r-- | src/effects/SkColorCubeFilter.cpp | 2 | ||||
-rwxr-xr-x | src/gpu/GrContext.cpp | 79 | ||||
-rw-r--r-- | src/gpu/SkGpuDevice.cpp | 8 | ||||
-rw-r--r-- | src/gpu/SkGr.cpp | 14 | ||||
-rw-r--r-- | src/gpu/SkGrPixelRef.cpp | 2 | ||||
-rw-r--r-- | src/gpu/effects/GrConfigConversionEffect.cpp | 6 | ||||
-rw-r--r-- | src/gpu/effects/GrTextureStripAtlas.cpp | 2 |
8 files changed, 66 insertions, 51 deletions
diff --git a/src/effects/SkBlurMaskFilter.cpp b/src/effects/SkBlurMaskFilter.cpp index c33edc2ee1..b521546a80 100644 --- a/src/effects/SkBlurMaskFilter.cpp +++ b/src/effects/SkBlurMaskFilter.cpp @@ -771,7 +771,7 @@ bool GrRectBlurEffect::CreateBlurProfileTexture(GrContext *context, float sigma, SkBlurMask::ComputeBlurProfile(sigma, &profile); ada.reset(profile); - *blurProfileTexture = context->createTexture(texDesc, profile, 0); + *blurProfileTexture = context->createTexture(texDesc, true, profile, 0); if (NULL == *blurProfileTexture) { return false; @@ -959,7 +959,7 @@ GrFragmentProcessor* GrRRectBlurEffect::Create(GrContext* context, float sigma, texDesc.fHeight = texSide; texDesc.fConfig = kAlpha_8_GrPixelConfig; - blurNinePatchTexture = context->createTexture(texDesc, blurred_mask.fImage, 0); + blurNinePatchTexture = context->createTexture(texDesc, true, blurred_mask.fImage, 0); SkAssertResult(context->addResourceToCache(key, blurNinePatchTexture)); SkMask::FreeImage(blurred_mask.fImage); diff --git a/src/effects/SkColorCubeFilter.cpp b/src/effects/SkColorCubeFilter.cpp index f4ffefc889..df9f5ea6ef 100644 --- a/src/effects/SkColorCubeFilter.cpp +++ b/src/effects/SkColorCubeFilter.cpp @@ -356,7 +356,7 @@ GrFragmentProcessor* SkColorCubeFilter::asFragmentProcessor(GrContext* context) SkAutoTUnref<GrTexture> textureCube(context->findAndRefCachedTexture(key)); if (!textureCube) { - textureCube.reset(context->createTexture(desc, fCubeData->data(), 0)); + textureCube.reset(context->createTexture(desc, true, fCubeData->data(), 0)); if (textureCube) { SkAssertResult(context->addResourceToCache(key, textureCube)); } diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp index 5b157d2a8e..7a910c5744 100755 --- a/src/gpu/GrContext.cpp +++ b/src/gpu/GrContext.cpp @@ -222,6 +222,11 @@ GrTextContext* GrContext::createTextContext(GrRenderTarget* renderTarget, } //////////////////////////////////////////////////////////////////////////////// +enum ScratchTextureFlags { + kExact_ScratchTextureFlag = 0x1, + kNoPendingIO_ScratchTextureFlag = 0x2, + kNoCreate_ScratchTextureFlag = 0x4, +}; bool GrContext::isConfigTexturable(GrPixelConfig config) const { return fGpu->caps()->isConfigTexturable(config); @@ -231,31 +236,57 @@ bool GrContext::npotTextureTileSupport() const { return fGpu->caps()->npotTextureTileSupport(); } -GrTexture* GrContext::createTexture(const GrSurfaceDesc& desc, const void* srcData, +GrTexture* GrContext::createTexture(const GrSurfaceDesc& desc, bool budgeted, const void* srcData, size_t rowBytes) { - return fGpu->createTexture(desc, true, srcData, rowBytes); + if ((desc.fFlags & kRenderTarget_GrSurfaceFlag) && + !this->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) { + return NULL; + } + if (!GrPixelConfigIsCompressed(desc.fConfig)) { + static const uint32_t kFlags = kExact_ScratchTextureFlag | + kNoCreate_ScratchTextureFlag; + if (GrTexture* texture = this->internalRefScratchTexture(desc, kFlags)) { + if (!srcData || texture->writePixels(0, 0, desc.fWidth, desc.fHeight, desc.fConfig, + srcData, rowBytes)) { + if (!budgeted) { + texture->cacheAccess().makeUnbudgeted(); + } + return texture; + } + texture->unref(); + } + } + return fGpu->createTexture(desc, budgeted, srcData, rowBytes); } -GrTexture* GrContext::refScratchTexture(const GrSurfaceDesc& inDesc, ScratchTexMatch match, +GrTexture* GrContext::refScratchTexture(const GrSurfaceDesc& desc, ScratchTexMatch match, bool calledDuringFlush) { // Currently we don't recycle compressed textures as scratch. - if (GrPixelConfigIsCompressed(inDesc.fConfig)) { + if (GrPixelConfigIsCompressed(desc.fConfig)) { return NULL; + } else { + uint32_t flags = 0; + if (kExact_ScratchTexMatch == match) { + flags |= kExact_ScratchTextureFlag; + } + if (calledDuringFlush) { + flags |= kNoPendingIO_ScratchTextureFlag; + } + return this->internalRefScratchTexture(desc, flags); } +} +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)); - // Make sure caller has checked for renderability if kRT is set. - SkASSERT(!(inDesc.fFlags & kRenderTarget_GrSurfaceFlag) || - this->isConfigRenderable(inDesc.fConfig, inDesc.fSampleCnt > 0)); - SkTCopyOnFirstWrite<GrSurfaceDesc> desc(inDesc); if (fGpu->caps()->reuseScratchTextures() || (desc->fFlags & kRenderTarget_GrSurfaceFlag)) { GrSurfaceFlags origFlags = desc->fFlags; - if (kApprox_ScratchTexMatch == match) { + if (!(kExact_ScratchTextureFlag & flags)) { // bin by pow2 with a reasonable min static const int MIN_SIZE = 16; GrSurfaceDesc* wdesc = desc.writable(); @@ -267,7 +298,7 @@ GrTexture* GrContext::refScratchTexture(const GrSurfaceDesc& inDesc, ScratchTexM GrScratchKey key; GrTexturePriv::ComputeScratchKey(*desc, &key); uint32_t scratchFlags = 0; - if (calledDuringFlush) { + if (kNoPendingIO_ScratchTextureFlag & flags) { scratchFlags = GrResourceCache2::kRequireNoPendingIO_ScratchFlag; } else if (!(desc->fFlags & kRenderTarget_GrSurfaceFlag)) { // If it is not a render target then it will most likely be populated by @@ -284,7 +315,7 @@ GrTexture* GrContext::refScratchTexture(const GrSurfaceDesc& inDesc, ScratchTexM return surface->asTexture(); } - if (kExact_ScratchTexMatch == match) { + if (kExact_ScratchTextureFlag & flags) { break; } // We had a cache miss and we are in approx mode, relax the fit of the flags. @@ -303,15 +334,19 @@ GrTexture* GrContext::refScratchTexture(const GrSurfaceDesc& inDesc, ScratchTexM desc.writable()->fFlags = origFlags; } - GrTexture* texture = fGpu->createTexture(*desc, true, NULL, 0); -#ifdef SK_DEBUG - if (fGpu->caps()->reuseScratchTextures() || (desc->fFlags & kRenderTarget_GrSurfaceFlag)) { - GrScratchKey key; - GrTexturePriv::ComputeScratchKey(*desc, &key); - SkASSERT(NULL == texture || texture->cacheAccess().getScratchKey() == key); + if (!(kNoCreate_ScratchTextureFlag & flags)) { + GrTexture* texture = fGpu->createTexture(*desc, true, NULL, 0); + #ifdef SK_DEBUG + if (fGpu->caps()->reuseScratchTextures() || (desc->fFlags & kRenderTarget_GrSurfaceFlag)) { + GrScratchKey key; + GrTexturePriv::ComputeScratchKey(*desc, &key); + SkASSERT(NULL == texture || texture->cacheAccess().getScratchKey() == key); + } + #endif + return texture; } -#endif - return texture; + + return NULL; } void GrContext::OverBudgetCB(void* data) { @@ -323,12 +358,6 @@ void GrContext::OverBudgetCB(void* data) { context->fFlushToReduceCacheSize = true; } -GrTexture* GrContext::createUncachedTexture(const GrSurfaceDesc& desc, - void* srcData, - size_t rowBytes) { - return fGpu->createTexture(desc, false, srcData, rowBytes); -} - int GrContext::getMaxTextureSize() const { return SkTMin(fGpu->caps()->maxTextureSize(), fMaxTextureSizeOverride); } diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp index 1695f5d681..8912851d8f 100644 --- a/src/gpu/SkGpuDevice.cpp +++ b/src/gpu/SkGpuDevice.cpp @@ -197,13 +197,7 @@ SkGpuDevice* SkGpuDevice::Create(GrContext* context, SkSurface::Budgeted budgete desc.fConfig = SkImageInfo2GrPixelConfig(info); desc.fSampleCnt = sampleCount; - SkAutoTUnref<GrTexture> texture; - if (SkSurface::kYes_Budgeted == budgeted) { - texture.reset(context->refScratchTexture(desc, GrContext::kExact_ScratchTexMatch)); - } else { - texture.reset(context->createUncachedTexture(desc, NULL, 0)); - } - + SkAutoTUnref<GrTexture> texture(context->createTexture(desc, SkToBool(budgeted), NULL, 0)); if (!texture) { return NULL; } diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp index f1c4d2052d..2209ea465a 100644 --- a/src/gpu/SkGr.cpp +++ b/src/gpu/SkGr.cpp @@ -179,17 +179,9 @@ static GrTexture* create_texture_for_bmp(GrContext* ctx, GrSurfaceDesc desc, const void* pixels, size_t rowBytes) { - GrTexture* result; - if (optionalKey.isValid() || GrPixelConfigIsCompressed(desc.fConfig)) { - result = ctx->createTexture(desc, pixels, rowBytes); - if (result) { - SkAssertResult(ctx->addResourceToCache(optionalKey, result)); - } - } else { - result = ctx->refScratchTexture(desc, GrContext::kExact_ScratchTexMatch); - if (pixels && result) { - result->writePixels(0, 0, desc.fWidth, desc.fHeight, desc.fConfig, pixels, rowBytes); - } + GrTexture* result = ctx->createTexture(desc, true, pixels, rowBytes); + if (result && optionalKey.isValid()) { + SkAssertResult(ctx->addResourceToCache(optionalKey, result)); } return result; } diff --git a/src/gpu/SkGrPixelRef.cpp b/src/gpu/SkGrPixelRef.cpp index f752bf0001..bc17879967 100644 --- a/src/gpu/SkGrPixelRef.cpp +++ b/src/gpu/SkGrPixelRef.cpp @@ -80,7 +80,7 @@ static SkGrPixelRef* copy_to_new_texture_pixelref(GrTexture* texture, SkColorTyp desc.fFlags = kRenderTarget_GrSurfaceFlag | kNoStencil_GrSurfaceFlag; desc.fConfig = SkImageInfo2GrPixelConfig(dstCT, kPremul_SkAlphaType, dstPT); - GrTexture* dst = context->createUncachedTexture(desc, NULL, 0); + GrTexture* dst = context->createTexture(desc, false, NULL, 0); if (NULL == dst) { return NULL; } diff --git a/src/gpu/effects/GrConfigConversionEffect.cpp b/src/gpu/effects/GrConfigConversionEffect.cpp index 4412c43736..ec44d08b01 100644 --- a/src/gpu/effects/GrConfigConversionEffect.cpp +++ b/src/gpu/effects/GrConfigConversionEffect.cpp @@ -185,16 +185,16 @@ void GrConfigConversionEffect::TestForPreservingPMConversions(GrContext* context desc.fHeight = 256; desc.fConfig = kRGBA_8888_GrPixelConfig; - SkAutoTUnref<GrTexture> readTex(context->createUncachedTexture(desc, NULL, 0)); + SkAutoTUnref<GrTexture> readTex(context->createTexture(desc, true, NULL, 0)); if (!readTex.get()) { return; } - SkAutoTUnref<GrTexture> tempTex(context->createUncachedTexture(desc, NULL, 0)); + SkAutoTUnref<GrTexture> tempTex(context->createTexture(desc, true, NULL, 0)); if (!tempTex.get()) { return; } desc.fFlags = kNone_GrSurfaceFlags; - SkAutoTUnref<GrTexture> dataTex(context->createUncachedTexture(desc, data, 0)); + SkAutoTUnref<GrTexture> dataTex(context->createTexture(desc, true, data, 0)); if (!dataTex.get()) { return; } diff --git a/src/gpu/effects/GrTextureStripAtlas.cpp b/src/gpu/effects/GrTextureStripAtlas.cpp index 880a739525..dfee607c0c 100644 --- a/src/gpu/effects/GrTextureStripAtlas.cpp +++ b/src/gpu/effects/GrTextureStripAtlas.cpp @@ -203,7 +203,7 @@ void GrTextureStripAtlas::lockTexture() { fTexture = fDesc.fContext->findAndRefCachedTexture(key); if (NULL == fTexture) { - fTexture = fDesc.fContext->createTexture(texDesc, NULL, 0); + fTexture = fDesc.fContext->createTexture(texDesc, true, NULL, 0); SkAssertResult(fDesc.fContext->addResourceToCache(key, fTexture)); // This is a new texture, so all of our cache info is now invalid this->initLRU(); |