From 9ed7f573491217079cccf1d81792cf4520a3c0d0 Mon Sep 17 00:00:00 2001 From: bsalomon Date: Fri, 19 Dec 2014 12:26:37 -0800 Subject: When bitmap is texture backed, don't download and reupload pixels Review URL: https://codereview.chromium.org/820683002 --- src/gpu/SkGr.cpp | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp index e311ae2ace..ff74fe92ca 100644 --- a/src/gpu/SkGr.cpp +++ b/src/gpu/SkGr.cpp @@ -360,9 +360,29 @@ static GrTexture* sk_gr_create_bitmap_texture(GrContext* ctx, bitmap->getPixels(), bitmap->rowBytes()); } +static GrTexture* get_texture_backing_bmp(const SkBitmap& bitmap, const GrContext* context, + const GrTextureParams* params) { + if (GrTexture* texture = bitmap.getTexture()) { + // Our texture-resizing-for-tiling used to upscale NPOT textures for tiling only works with + // content-key cached resources. Rather than invest in that legacy code path, we'll just + // take the horribly slow route of causing a cache miss which will cause the pixels to be + // read and reuploaded to a texture with a content key. + if (params && !context->getGpu()->caps()->npotTextureTileSupport() && + (params->isTiled() || GrTextureParams::kMipMap_FilterMode == params->filterMode())) { + return NULL; + } + return texture; + } + return NULL; +} + bool GrIsBitmapInCache(const GrContext* ctx, const SkBitmap& bitmap, const GrTextureParams* params) { + if (get_texture_backing_bmp(bitmap, ctx, params)) { + return true; + } + GrCacheID cacheID; generate_bitmap_cache_id(bitmap, &cacheID); @@ -374,7 +394,10 @@ bool GrIsBitmapInCache(const GrContext* ctx, GrTexture* GrRefCachedBitmapTexture(GrContext* ctx, const SkBitmap& bitmap, const GrTextureParams* params) { - GrTexture* result = NULL; + GrTexture* result = get_texture_backing_bmp(bitmap, ctx, params); + if (result) { + return SkRef(result); + } bool cache = !bitmap.isVolatile(); -- cgit v1.2.3