From 677da9d4af2558ddd50a900e90a093d1b522bd5f Mon Sep 17 00:00:00 2001 From: robertphillips Date: Wed, 11 May 2016 05:15:55 -0700 Subject: [PATCH] Minor GrRenderTarget retraction GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1967743003 Review-Url: https://codereview.chromium.org/1967743003 --- gm/texdata.cpp | 4 +--- src/core/SkImageCacherator.cpp | 4 ++-- src/gpu/GrYUVProvider.cpp | 24 ++++++++---------------- src/gpu/GrYUVProvider.h | 2 +- src/gpu/SkGr.cpp | 13 +++++++------ 5 files changed, 19 insertions(+), 28 deletions(-) diff --git a/gm/texdata.cpp b/gm/texdata.cpp index 977947b..494a932 100644 --- a/gm/texdata.cpp +++ b/gm/texdata.cpp @@ -69,9 +69,7 @@ DEF_SIMPLE_GM_BG(texdata, canvas, 2 * S, 2 * S, SK_ColorBLACK) { } GrSurfaceDesc desc; - // use RT flag bit because in GL it makes the texture be bottom-up - desc.fFlags = i ? kRenderTarget_GrSurfaceFlag : - kNone_GrSurfaceFlags; + desc.fOrigin = i ? kBottomLeft_GrSurfaceOrigin : kTopLeft_GrSurfaceOrigin; desc.fConfig = kSkia8888_GrPixelConfig; desc.fWidth = 2 * S; desc.fHeight = 2 * S; diff --git a/src/core/SkImageCacherator.cpp b/src/core/SkImageCacherator.cpp index 7b5ff22..0df14df 100644 --- a/src/core/SkImageCacherator.cpp +++ b/src/core/SkImageCacherator.cpp @@ -291,11 +291,11 @@ GrTexture* SkImageCacherator::lockTexture(GrContext* ctx, const GrUniqueKey& key { ScopedGenerator generator(this); Generator_GrYUVProvider provider(generator); - GrTexture* tex = provider.refAsTexture(ctx, desc, true); + sk_sp tex = provider.refAsTexture(ctx, desc, true); if (tex) { SK_HISTOGRAM_ENUMERATION("LockTexturePath", kYUV_LockTexturePath, kLockTexturePathCount); - return set_key_and_return(tex, key); + return set_key_and_return(tex.release(), key); } } diff --git a/src/gpu/GrYUVProvider.cpp b/src/gpu/GrYUVProvider.cpp index 6cd7c95..b4320d0 100644 --- a/src/gpu/GrYUVProvider.cpp +++ b/src/gpu/GrYUVProvider.cpp @@ -80,7 +80,9 @@ bool YUVScoper::init(GrYUVProvider* provider, SkYUVPlanesCache::Info* yuvInfo, v return true; } -GrTexture* GrYUVProvider::refAsTexture(GrContext* ctx, const GrSurfaceDesc& desc, bool useCache) { +sk_sp GrYUVProvider::refAsTexture(GrContext* ctx, + const GrSurfaceDesc& desc, + bool useCache) { SkYUVPlanesCache::Info yuvInfo; void* planes[3]; YUVScoper scoper; @@ -110,18 +112,13 @@ GrTexture* GrYUVProvider::refAsTexture(GrContext* ctx, const GrSurfaceDesc& desc } } - GrSurfaceDesc rtDesc = desc; - rtDesc.fFlags = rtDesc.fFlags | kRenderTarget_GrSurfaceFlag; - - SkAutoTUnref result(ctx->textureProvider()->createTexture(rtDesc, SkBudgeted::kYes, - nullptr, 0)); - if (!result) { + sk_sp drawContext(ctx->newDrawContext(SkBackingFit::kExact, + desc.fWidth, desc.fHeight, + desc.fConfig, desc.fSampleCnt)); + if (!drawContext) { return nullptr; } - GrRenderTarget* renderTarget = result->asRenderTarget(); - SkASSERT(renderTarget); - GrPaint paint; // We may be decoding an sRGB image, but the result of our linear math on the YUV planes // is already in sRGB in that case. Don't convert (which will make the image too bright). @@ -137,12 +134,7 @@ GrTexture* GrYUVProvider::refAsTexture(GrContext* ctx, const GrSurfaceDesc& desc const SkRect r = SkRect::MakeIWH(yuvInfo.fSizeInfo.fSizes[SkYUVSizeInfo::kY].fWidth, yuvInfo.fSizeInfo.fSizes[SkYUVSizeInfo::kY].fHeight); - sk_sp drawContext(ctx->drawContext(sk_ref_sp(renderTarget))); - if (!drawContext) { - return nullptr; - } - drawContext->drawRect(GrClip::WideOpen(), paint, SkMatrix::I(), r); - return result.release(); + return drawContext->asTexture(); } diff --git a/src/gpu/GrYUVProvider.h b/src/gpu/GrYUVProvider.h index 85b238d..c32af15 100644 --- a/src/gpu/GrYUVProvider.h +++ b/src/gpu/GrYUVProvider.h @@ -35,7 +35,7 @@ public: * * On failure (e.g. the provider had no data), this returns NULL. */ - GrTexture* refAsTexture(GrContext*, const GrSurfaceDesc&, bool useCache); + sk_sp refAsTexture(GrContext*, const GrSurfaceDesc&, bool useCache); virtual uint32_t onGetID() = 0; diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp index f1f48bc..120db13 100644 --- a/src/gpu/SkGr.cpp +++ b/src/gpu/SkGr.cpp @@ -181,8 +181,8 @@ public: } }; -static GrTexture* create_texture_from_yuv(GrContext* ctx, const SkBitmap& bm, - const GrSurfaceDesc& desc) { +static sk_sp create_texture_from_yuv(GrContext* ctx, const SkBitmap& bm, + const GrSurfaceDesc& desc) { // Subsets are not supported, the whole pixelRef is loaded when using YUV decoding SkPixelRef* pixelRef = bm.pixelRef(); if ((nullptr == pixelRef) || @@ -218,8 +218,9 @@ GrTexture* GrUploadBitmapToTexture(GrContext* ctx, const SkBitmap& bitmap) { return texture; } - if (GrTexture* texture = create_texture_from_yuv(ctx, bitmap, desc)) { - return texture; + sk_sp texture(create_texture_from_yuv(ctx, bitmap, desc)); + if (texture) { + return texture.release(); } SkAutoLockPixels alp(bitmap); @@ -339,9 +340,9 @@ GrTexture* GrGenerateMipMapsAndUploadToTexture(GrContext* ctx, const SkBitmap& b } } - GrTexture* texture = create_texture_from_yuv(ctx, bitmap, desc); + sk_sp texture(create_texture_from_yuv(ctx, bitmap, desc)); if (texture) { - return texture; + return texture.release(); } // SkMipMap::Build doesn't handle sRGB data correctly (yet). -- 2.7.4