From 041f7dfc577822f1e97721a865f86a9a02660cf9 Mon Sep 17 00:00:00 2001 From: Brian Osman Date: Tue, 7 Feb 2017 11:23:28 -0500 Subject: Bring back SkImage::makeTextureImage Ensures that an image is GPU backed on the passed-in GrContxt. The new version requires a destination color space (intended usage of the image), so we can make a proper decision about decoded format. This reverts commit d263413a2a92cafe3fd3b051c67d00206c9a0e4d. BUG=skia: Change-Id: Ibccddbafc301779559592045ed5a5fa9264e7432 Reviewed-on: https://skia-review.googlesource.com/8116 Commit-Queue: Brian Osman Reviewed-by: Brian Salomon --- src/image/SkImage_Gpu.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'src/image/SkImage_Gpu.cpp') diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp index ef25844a0f..98a7101e6b 100644 --- a/src/image/SkImage_Gpu.cpp +++ b/src/image/SkImage_Gpu.cpp @@ -350,6 +350,38 @@ sk_sp SkImage::MakeFromNV12TexturesCopy(GrContext* ctx, SkYUVColorSpace std::move(imageColorSpace)); } +static sk_sp create_image_from_maker(GrTextureMaker* maker, SkAlphaType at, uint32_t id, + SkColorSpace* dstColorSpace) { + sk_sp texColorSpace; + sk_sp texture(maker->refTextureForParams(GrSamplerParams::ClampNoFilter(), + dstColorSpace, &texColorSpace, nullptr)); + if (!texture) { + return nullptr; + } + return sk_make_sp(texture->width(), texture->height(), id, at, std::move(texture), + std::move(texColorSpace), SkBudgeted::kNo); +} + +sk_sp SkImage::makeTextureImage(GrContext *context, SkColorSpace* dstColorSpace) const { + if (!context) { + return nullptr; + } + if (GrTexture* peek = as_IB(this)->peekTexture()) { + return peek->getContext() == context ? sk_ref_sp(const_cast(this)) : nullptr; + } + + if (SkImageCacherator* cacher = as_IB(this)->peekCacherator()) { + GrImageTextureMaker maker(context, cacher, this, kDisallow_CachingHint); + return create_image_from_maker(&maker, this->alphaType(), this->uniqueID(), dstColorSpace); + } + + if (const SkBitmap* bmp = as_IB(this)->onPeekBitmap()) { + GrBitmapTextureMaker maker(context, *bmp); + return create_image_from_maker(&maker, this->alphaType(), this->uniqueID(), dstColorSpace); + } + return nullptr; +} + sk_sp SkImage::makeNonTextureImage() const { if (!this->isTextureBacked()) { return sk_ref_sp(const_cast(this)); -- cgit v1.2.3