diff options
author | 2015-02-04 09:12:46 -0800 | |
---|---|---|
committer | 2015-02-04 09:12:46 -0800 | |
commit | 88425565259809bc1b0aac116d87f3fc8d212f43 (patch) | |
tree | 2b8c2e4a9f799b7c6c394e8bdc40e6c00b736858 /src | |
parent | b0df8be137d8fb49436e46d1fd1a5aec8b7ab562 (diff) |
Make npot resizing work properly for bmps that are explicitly texture backed.
Review URL: https://codereview.chromium.org/890223003
Diffstat (limited to 'src')
-rw-r--r-- | src/gpu/SkGr.cpp | 69 |
1 files changed, 39 insertions, 30 deletions
diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp index 885b453df5..2a153af5be 100644 --- a/src/gpu/SkGr.cpp +++ b/src/gpu/SkGr.cpp @@ -492,27 +492,28 @@ static GrTexture* create_bitmap_texture(GrContext* ctx, } -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; + Stretch stretch = get_stretch_type(ctx, bitmap.width(), bitmap.height(), params); + + // Handle the case where the bitmap is explicitly texture backed. + GrTexture* texture = bitmap.getTexture(); + if (texture) { + if (kNo_Stretch == stretch) { + return true; + } + // No keys for volatile bitmaps. + if (bitmap.isVolatile()) { + return false; + } + const GrContentKey& key = texture->getContentKey(); + if (!key.isValid()) { + return false; + } + GrContentKey resizedKey; + make_resize_key(key, stretch, &resizedKey); + return ctx->isResourceInCache(resizedKey); } // We don't cache volatile bitmaps @@ -520,29 +521,37 @@ bool GrIsBitmapInCache(const GrContext* ctx, return false; } - // If it is inherently texture backed, consider it in the cache - if (bitmap.getTexture()) { - return true; - } - - Stretch stretch = get_stretch_type(ctx, bitmap.width(), bitmap.height(), params); GrContentKey key, resizedKey; generate_bitmap_keys(bitmap, stretch, &key, &resizedKey); - - GrSurfaceDesc desc; - generate_bitmap_texture_desc(bitmap, &desc); return ctx->isResourceInCache((kNo_Stretch == stretch) ? key : resizedKey); } GrTexture* GrRefCachedBitmapTexture(GrContext* ctx, const SkBitmap& bitmap, const GrTextureParams* params) { - GrTexture* result = get_texture_backing_bmp(bitmap, ctx, params); + + Stretch stretch = get_stretch_type(ctx, bitmap.width(), bitmap.height(), params); + + GrTexture* result = bitmap.getTexture(); if (result) { - return SkRef(result); + if (kNo_Stretch == stretch) { + return SkRef(result); + } + GrContentKey resizedKey; + // Don't create a key for the resized version if the bmp is volatile. + if (!bitmap.isVolatile()) { + const GrContentKey& key = result->getContentKey(); + if (key.isValid()) { + make_resize_key(key, stretch, &resizedKey); + GrTexture* stretched = ctx->findAndRefCachedTexture(resizedKey); + if (stretched) { + return stretched; + } + } + } + return resize_texture(result, stretch, resizedKey); } - Stretch stretch = get_stretch_type(ctx, bitmap.width(), bitmap.height(), params); GrContentKey key, resizedKey; if (!bitmap.isVolatile()) { |