From 4447b64a88ea141161fca772c2fec28b6141bbc3 Mon Sep 17 00:00:00 2001 From: Robert Phillips Date: Fri, 3 Mar 2017 11:10:18 -0500 Subject: Switch SkImageGenerator over to generating GrTextureProxies It does not seem irrational for generateTexture to always receive a valid GrContext. lockAsBitmap can do as it pleases. This is split out of: https://skia-review.googlesource.com/c/8823/ (Remove GrFragmentProcessor-derived class' GrTexture-based ctors) Change-Id: I8aebc813a8a3a7d694b7369c2c9810e2164fe16e Reviewed-on: https://skia-review.googlesource.com/9191 Commit-Queue: Robert Phillips Reviewed-by: Brian Salomon --- gm/image_pict.cpp | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) (limited to 'gm/image_pict.cpp') diff --git a/gm/image_pict.cpp b/gm/image_pict.cpp index 387ceb8d41..1f273dc615 100644 --- a/gm/image_pict.cpp +++ b/gm/image_pict.cpp @@ -231,11 +231,10 @@ public: } } protected: - GrTexture* onGenerateTexture(GrContext* ctx, const SkImageInfo& info, - const SkIPoint& origin) override { - if (ctx) { - SkASSERT(ctx == fCtx.get()); - } + sk_sp onGenerateTexture(GrContext* ctx, const SkImageInfo& info, + const SkIPoint& origin) override { + SkASSERT(ctx); + SkASSERT(ctx == fCtx.get()); if (!fProxy) { return nullptr; @@ -243,7 +242,7 @@ protected: if (origin.fX == 0 && origin.fY == 0 && info.width() == fProxy->width() && info.height() == fProxy->height()) { - return SkSafeRef(fProxy->instantiate(fCtx->textureProvider())->asTexture()); + return fProxy; } // need to copy the subset into a new texture @@ -266,17 +265,14 @@ protected: return nullptr; } - GrSurface* dstSurf = dstContext->asSurfaceProxy()->instantiate(fCtx->textureProvider()); - if (!dstSurf) { - return nullptr; - } - - return SkRef(dstSurf->asTexture()); + return dstContext->asTextureProxyRef(); } + private: sk_sp fCtx; - sk_sp fProxy; + sk_sp fProxy; }; + static std::unique_ptr make_tex_generator(GrContext* ctx, sk_sp pic) { const SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100); @@ -340,7 +336,8 @@ protected: static void draw_as_bitmap(SkCanvas* canvas, SkImageCacherator* cache, SkScalar x, SkScalar y) { SkBitmap bitmap; - cache->lockAsBitmap(&bitmap, nullptr, canvas->imageInfo().colorSpace()); + cache->lockAsBitmap(canvas->getGrContext(), &bitmap, nullptr, + canvas->imageInfo().colorSpace()); canvas->drawBitmap(bitmap, x, y); } -- cgit v1.2.3