From d2a6f4e419393d3c8d8fe332f11c4c6f88382e1d Mon Sep 17 00:00:00 2001 From: bsalomon Date: Wed, 4 Feb 2015 10:55:54 -0800 Subject: [PATCH] More cleanup around GrContext, textures, and SkGr.cpp Review URL: https://codereview.chromium.org/880983008 --- include/gpu/GrContext.h | 9 +++++++-- src/gpu/GrContext.cpp | 21 +++++++++++++-------- src/gpu/GrTexture.cpp | 2 +- src/gpu/SkGr.cpp | 39 +++++++++++++++------------------------ 4 files changed, 36 insertions(+), 35 deletions(-) diff --git a/include/gpu/GrContext.h b/include/gpu/GrContext.h index e47ad15..d8d061a 100644 --- a/include/gpu/GrContext.h +++ b/include/gpu/GrContext.h @@ -274,9 +274,14 @@ public: bool internalFlag = false); /** - * Returns true if index8 textures are supported. + * Can the provided configuration act as a texture? */ - bool supportsIndex8PixelConfig() const; + bool isConfigTexturable(GrPixelConfig) const; + + /** + * Can non-power-of-two textures be used with tile modes other than clamp? + */ + bool npotTextureTileSupport() const; /** * Return the max width or height of a texture supported by the current GPU. diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp index bcd84dd..5b157d2 100755 --- a/src/gpu/GrContext.cpp +++ b/src/gpu/GrContext.cpp @@ -223,6 +223,14 @@ GrTextContext* GrContext::createTextContext(GrRenderTarget* renderTarget, //////////////////////////////////////////////////////////////////////////////// +bool GrContext::isConfigTexturable(GrPixelConfig config) const { + return fGpu->caps()->isConfigTexturable(config); +} + +bool GrContext::npotTextureTileSupport() const { + return fGpu->caps()->npotTextureTileSupport(); +} + GrTexture* GrContext::createTexture(const GrSurfaceDesc& desc, const void* srcData, size_t rowBytes) { return fGpu->createTexture(desc, true, srcData, rowBytes); @@ -230,6 +238,11 @@ GrTexture* GrContext::createTexture(const GrSurfaceDesc& desc, const void* srcDa GrTexture* GrContext::refScratchTexture(const GrSurfaceDesc& inDesc, ScratchTexMatch match, bool calledDuringFlush) { + // Currently we don't recycle compressed textures as scratch. + if (GrPixelConfigIsCompressed(inDesc.fConfig)) { + return NULL; + } + // kNoStencil has no meaning if kRT isn't set. SkASSERT((inDesc.fFlags & kRenderTarget_GrSurfaceFlag) || !(inDesc.fFlags & kNoStencil_GrSurfaceFlag)); @@ -338,14 +351,6 @@ GrRenderTarget* GrContext::wrapBackendRenderTarget(const GrBackendRenderTargetDe return fGpu->wrapBackendRenderTarget(desc); } -/////////////////////////////////////////////////////////////////////////////// - -bool GrContext::supportsIndex8PixelConfig() const { - const GrDrawTargetCaps* caps = fGpu->caps(); - return caps->isConfigTexturable(kIndex_8_GrPixelConfig); -} - - //////////////////////////////////////////////////////////////////////////////// void GrContext::clear(const SkIRect* rect, diff --git a/src/gpu/GrTexture.cpp b/src/gpu/GrTexture.cpp index 6bd4586..4b43fc8 100644 --- a/src/gpu/GrTexture.cpp +++ b/src/gpu/GrTexture.cpp @@ -87,7 +87,7 @@ GrTexture::GrTexture(GrGpu* gpu, LifeCycle lifeCycle, const GrSurfaceDesc& desc) : INHERITED(gpu, lifeCycle, desc) , fMipMapsStatus(kNotAllocated_MipMapsStatus) { - if (kWrapped_LifeCycle != lifeCycle) { + if (kWrapped_LifeCycle != lifeCycle && !GrPixelConfigIsCompressed(desc.fConfig)) { GrScratchKey key; GrTexturePriv::ComputeScratchKey(desc, &key); this->setScratchKey(key); diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp index f4d51b3..f1c4d20 100644 --- a/src/gpu/SkGr.cpp +++ b/src/gpu/SkGr.cpp @@ -7,9 +7,6 @@ #include "SkGr.h" -#include "GrDrawTargetCaps.h" -#include "GrGpu.h" -#include "GrGpuResourceCacheAccess.h" #include "GrXferProcessor.h" #include "SkColorFilter.h" #include "SkConfig8888.h" @@ -96,8 +93,7 @@ enum Stretch { static Stretch get_stretch_type(const GrContext* ctx, int width, int height, const GrTextureParams* params) { if (params && params->isTiled()) { - const GrDrawTargetCaps* caps = ctx->getGpu()->caps(); - if (!caps->npotTextureTileSupport() && (!SkIsPow2(width) || !SkIsPow2(height))) { + if (!ctx->npotTextureTileSupport() && (!SkIsPow2(width) || !SkIsPow2(height))) { switch(params->filterMode()) { case GrTextureParams::kNone_FilterMode: return kNearest_Stretch; @@ -184,7 +180,7 @@ static GrTexture* create_texture_for_bmp(GrContext* ctx, const void* pixels, size_t rowBytes) { GrTexture* result; - if (optionalKey.isValid()) { + if (optionalKey.isValid() || GrPixelConfigIsCompressed(desc.fConfig)) { result = ctx->createTexture(desc, pixels, rowBytes); if (result) { SkAssertResult(ctx->addResourceToCache(optionalKey, result)); @@ -426,7 +422,7 @@ static GrTexture* create_unstretched_bitmap_texture(GrContext* ctx, generate_bitmap_texture_desc(*bitmap, &desc); if (kIndex_8_SkColorType == bitmap->colorType()) { - if (ctx->supportsIndex8PixelConfig()) { + if (ctx->isConfigTexturable(kIndex_8_GrPixelConfig)) { size_t imageSize = GrCompressedFormatDataSize(kIndex_8_GrPixelConfig, bitmap->width(), bitmap->height()); SkAutoMalloc storage(imageSize); @@ -445,18 +441,14 @@ static GrTexture* create_unstretched_bitmap_texture(GrContext* ctx, // Is this an ETC1 encoded texture? #ifndef SK_IGNORE_ETC1_SUPPORT - else if ( - // We do not support scratch ETC1 textures, hence they should all be at least - // trying to go to the cache. - optionalKey.isValid() - // Make sure that the underlying device supports ETC1 textures before we go ahead - // and check the data. - && ctx->getGpu()->caps()->isConfigTexturable(kETC1_GrPixelConfig) - // If the bitmap had compressed data and was then uncompressed, it'll still return - // compressed data on 'refEncodedData' and upload it. Probably not good, since if - // the bitmap has available pixels, then they might not be what the decompressed - // data is. - && !(bitmap->readyToDraw())) { + // Make sure that the underlying device supports ETC1 textures before we go ahead + // and check the data. + else if (ctx->isConfigTexturable(kETC1_GrPixelConfig) + // If the bitmap had compressed data and was then uncompressed, it'll still return + // compressed data on 'refEncodedData' and upload it. Probably not good, since if + // the bitmap has available pixels, then they might not be what the decompressed + // data is. + && !(bitmap->readyToDraw())) { GrTexture *texture = load_etc1_texture(ctx, optionalKey, *bitmap, desc); if (texture) { return texture; @@ -464,12 +456,11 @@ static GrTexture* create_unstretched_bitmap_texture(GrContext* ctx, } #endif // SK_IGNORE_ETC1_SUPPORT - else { - GrTexture *texture = load_yuv_texture(ctx, optionalKey, *bitmap, desc); - if (texture) { - return texture; - } + GrTexture *texture = load_yuv_texture(ctx, optionalKey, *bitmap, desc); + if (texture) { + return texture; } + SkAutoLockPixels alp(*bitmap); if (!bitmap->readyToDraw()) { return NULL; -- 2.7.4