 Chromium Code Reviews
 Chromium Code Reviews Issue 552843004:
  Adding texture uploads without cache for YUV and ETC1  (Closed) 
  Base URL: https://skia.googlesource.com/skia.git@master
    
  
    Issue 552843004:
  Adding texture uploads without cache for YUV and ETC1  (Closed) 
  Base URL: https://skia.googlesource.com/skia.git@master| Index: src/gpu/SkGr.cpp | 
| diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp | 
| index f1fd40759969ebb646e5e2292f21ea55b75fafdb..73773b00d144c532b802af8b99d1e91f991d70d2 100644 | 
| --- a/src/gpu/SkGr.cpp | 
| +++ b/src/gpu/SkGr.cpp | 
| @@ -135,8 +135,40 @@ static void add_genID_listener(GrResourceKey key, SkPixelRef* pixelRef) { | 
| pixelRef->addGenIDChangeListener(SkNEW_ARGS(GrResourceInvalidator, (key))); | 
| } | 
| +static GrTexture* sk_gr_allocate_texture(GrContext* ctx, | 
| + bool cache, | 
| + const GrTextureParams* params, | 
| + const SkBitmap& bm, | 
| 
robertphillips
2014/09/10 14:18:12
const GrTextureDesc&
 | 
| + GrTextureDesc desc, | 
| + const void* pixels, | 
| + size_t rowBytes) { | 
| + GrTexture* result; | 
| + if (cache) { | 
| + // This texture is likely to be used again so leave it in the cache | 
| + GrCacheID cacheID; | 
| + generate_bitmap_cache_id(bm, &cacheID); | 
| + | 
| + GrResourceKey key; | 
| + result = ctx->createTexture(params, desc, cacheID, pixels, rowBytes, &key); | 
| + if (result) { | 
| + add_genID_listener(key, bm.pixelRef()); | 
| + } | 
| + } else { | 
| + // This texture is unlikely to be used again (in its present form) so | 
| + // just use a scratch texture. This will remove the texture from the | 
| + // cache so no one else can find it. Additionally, once unlocked, the | 
| + // scratch texture will go to the end of the list for purging so will | 
| + // likely be available for this volatile bitmap the next time around. | 
| + result = ctx->lockAndRefScratchTexture(desc, GrContext::kExact_ScratchTexMatch); | 
| + if (pixels) { | 
| + result->writePixels(0, 0, bm.width(), bm.height(), desc.fConfig, pixels, rowBytes); | 
| + } | 
| + } | 
| + return result; | 
| +} | 
| + | 
| #ifndef SK_IGNORE_ETC1_SUPPORT | 
| -static GrTexture *load_etc1_texture(GrContext* ctx, | 
| +static GrTexture *load_etc1_texture(GrContext* ctx, bool cache, | 
| const GrTextureParams* params, | 
| const SkBitmap &bm, GrTextureDesc desc) { | 
| SkAutoTUnref<SkData> data(bm.pixelRef()->refEncodedData()); | 
| @@ -182,23 +214,12 @@ static GrTexture *load_etc1_texture(GrContext* ctx, | 
| return NULL; | 
| } | 
| - // This texture is likely to be used again so leave it in the cache | 
| - GrCacheID cacheID; | 
| - generate_bitmap_cache_id(bm, &cacheID); | 
| - | 
| - GrResourceKey key; | 
| - GrTexture* result = ctx->createTexture(params, desc, cacheID, bytes, 0, &key); | 
| - if (result) { | 
| - add_genID_listener(key, bm.pixelRef()); | 
| - } | 
| - return result; | 
| + return sk_gr_allocate_texture(ctx, cache, params, bm, desc, bytes, 0); | 
| } | 
| #endif // SK_IGNORE_ETC1_SUPPORT | 
| -static GrTexture *load_yuv_texture(GrContext* ctx, const GrTextureParams* params, | 
| +static GrTexture *load_yuv_texture(GrContext* ctx, bool cache, const GrTextureParams* params, | 
| const SkBitmap& bm, const GrTextureDesc& desc) { | 
| - GrTexture* result = NULL; | 
| - | 
| SkPixelRef* pixelRef = bm.pixelRef(); | 
| SkISize yuvSizes[3]; | 
| if ((NULL == pixelRef) || !pixelRef->getYUV8Planes(yuvSizes, NULL, NULL)) { | 
| @@ -243,15 +264,10 @@ static GrTexture *load_yuv_texture(GrContext* ctx, const GrTextureParams* params | 
| kRenderTarget_GrTextureFlagBit | | 
| kNoStencil_GrTextureFlagBit; | 
| - // This texture is likely to be used again so leave it in the cache | 
| - GrCacheID cacheID; | 
| - generate_bitmap_cache_id(bm, &cacheID); | 
| + GrTexture* result = sk_gr_allocate_texture(ctx, cache, params, bm, rtDesc, NULL, 0); | 
| - GrResourceKey key; | 
| - result = ctx->createTexture(params, rtDesc, cacheID, NULL, 0, &key); | 
| GrRenderTarget* renderTarget = result ? result->asRenderTarget() : NULL; | 
| if (renderTarget) { | 
| - add_genID_listener(key, bm.pixelRef()); | 
| SkAutoTUnref<GrEffect> yuvToRgbEffect(GrYUVtoRGBEffect::Create( | 
| yuvTextures[0].texture(), yuvTextures[1].texture(), yuvTextures[2].texture())); | 
| GrPaint paint; | 
| @@ -293,26 +309,8 @@ static GrTexture* sk_gr_create_bitmap_texture(GrContext* ctx, | 
| // our compressed data will be trimmed, so pass width() for its | 
| // "rowBytes", since they are the same now. | 
| - | 
| - if (cache) { | 
| - GrCacheID cacheID; | 
| - generate_bitmap_cache_id(origBitmap, &cacheID); | 
| - | 
| - GrResourceKey key; | 
| - GrTexture* result = ctx->createTexture(params, desc, cacheID, | 
| - storage.get(), bitmap->width(), &key); | 
| - if (result) { | 
| - add_genID_listener(key, origBitmap.pixelRef()); | 
| - } | 
| - return result; | 
| - } else { | 
| - GrTexture* result = ctx->lockAndRefScratchTexture(desc, | 
| - GrContext::kExact_ScratchTexMatch); | 
| - result->writePixels(0, 0, bitmap->width(), | 
| - bitmap->height(), desc.fConfig, | 
| - storage.get()); | 
| - return result; | 
| - } | 
| + return sk_gr_allocate_texture(ctx, cache, params, origBitmap, | 
| + desc, storage.get(), bitmap->width()); | 
| } else { | 
| origBitmap.copyTo(&tmpBitmap, kN32_SkColorType); | 
| // now bitmap points to our temp, which has been promoted to 32bits | 
| @@ -335,7 +333,7 @@ static GrTexture* sk_gr_create_bitmap_texture(GrContext* ctx, | 
| // the bitmap has available pixels, then they might not be what the decompressed | 
| // data is. | 
| && !(bitmap->readyToDraw())) { | 
| - GrTexture *texture = load_etc1_texture(ctx, params, *bitmap, desc); | 
| + GrTexture *texture = load_etc1_texture(ctx, cache, params, *bitmap, desc); | 
| if (texture) { | 
| return texture; | 
| } | 
| @@ -343,7 +341,7 @@ static GrTexture* sk_gr_create_bitmap_texture(GrContext* ctx, | 
| #endif // SK_IGNORE_ETC1_SUPPORT | 
| else { | 
| - GrTexture *texture = load_yuv_texture(ctx, params, *bitmap, desc); | 
| + GrTexture *texture = load_yuv_texture(ctx, cache, params, *bitmap, desc); | 
| if (texture) { | 
| return texture; | 
| } | 
| @@ -352,32 +350,9 @@ static GrTexture* sk_gr_create_bitmap_texture(GrContext* ctx, | 
| if (!bitmap->readyToDraw()) { | 
| return NULL; | 
| } | 
| - if (cache) { | 
| - // This texture is likely to be used again so leave it in the cache | 
| - GrCacheID cacheID; | 
| - generate_bitmap_cache_id(origBitmap, &cacheID); | 
| - GrResourceKey key; | 
| - GrTexture* result = ctx->createTexture(params, desc, cacheID, | 
| - bitmap->getPixels(), bitmap->rowBytes(), &key); | 
| - if (result) { | 
| - add_genID_listener(key, origBitmap.pixelRef()); | 
| - } | 
| - return result; | 
| - } else { | 
| - // This texture is unlikely to be used again (in its present form) so | 
| - // just use a scratch texture. This will remove the texture from the | 
| - // cache so no one else can find it. Additionally, once unlocked, the | 
| - // scratch texture will go to the end of the list for purging so will | 
| - // likely be available for this volatile bitmap the next time around. | 
| - GrTexture* result = ctx->lockAndRefScratchTexture(desc, GrContext::kExact_ScratchTexMatch); | 
| - result->writePixels(0, 0, | 
| - bitmap->width(), bitmap->height(), | 
| - desc.fConfig, | 
| - bitmap->getPixels(), | 
| - bitmap->rowBytes()); | 
| - return result; | 
| - } | 
| + return sk_gr_allocate_texture(ctx, cache, params, origBitmap, desc, | 
| + bitmap->getPixels(), bitmap->rowBytes()); | 
| } | 
| bool GrIsBitmapInCache(const GrContext* ctx, |