From 7f1d020bbfde245281fac88ff09b55366155be16 Mon Sep 17 00:00:00 2001 From: Mike Reed Date: Mon, 8 May 2017 16:13:39 -0400 Subject: [PATCH] remove (possibly slow) call to refEncoded in getDeferredTextureImageData - explicitly reject already-texture-backed and picture-backed Needed to add a virtual to image_base and generator to distinguish generators that can (or cannot) natively "generate" on the gpu (e.g. pictures) Bug: 646089 Change-Id: I3aea22f89b31009ecbb3bd50d88512e6532f0a0f Change-Id: I3aea22f89b31009ecbb3bd50d88512e6532f0a0f Reviewed-on: https://skia-review.googlesource.com/15765 Commit-Queue: Mike Reed Reviewed-by: Leon Scroggins Reviewed-by: Brian Salomon --- include/core/SkImageGenerator.h | 3 ++- src/core/SkPictureImageGenerator.h | 1 + src/image/SkImage_Base.h | 4 ++++ src/image/SkImage_Gpu.cpp | 18 +++++++++++++----- src/image/SkImage_Lazy.cpp | 10 ++++++++++ 5 files changed, 30 insertions(+), 6 deletions(-) diff --git a/include/core/SkImageGenerator.h b/include/core/SkImageGenerator.h index 348f281..3e433a3 100644 --- a/include/core/SkImageGenerator.h +++ b/include/core/SkImageGenerator.h @@ -201,8 +201,9 @@ protected: } #if SK_SUPPORT_GPU + virtual bool onCanGenerateTexture() const { return false; } virtual sk_sp onGenerateTexture(GrContext*, const SkImageInfo&, - const SkIPoint&); + const SkIPoint&); // returns nullptr #endif private: diff --git a/src/core/SkPictureImageGenerator.h b/src/core/SkPictureImageGenerator.h index ed5e87c..95eeb88 100644 --- a/src/core/SkPictureImageGenerator.h +++ b/src/core/SkPictureImageGenerator.h @@ -23,6 +23,7 @@ protected: override; #if SK_SUPPORT_GPU + bool onCanGenerateTexture() const override { return true; } sk_sp onGenerateTexture(GrContext*, const SkImageInfo&, const SkIPoint&) override; #endif diff --git a/src/image/SkImage_Base.h b/src/image/SkImage_Base.h index 64c075d..95ad67a 100644 --- a/src/image/SkImage_Base.h +++ b/src/image/SkImage_Base.h @@ -74,8 +74,12 @@ public: virtual bool onAsLegacyBitmap(SkBitmap*, LegacyBitmapMode) const; + // True for picture-backed and codec-backed virtual bool onIsLazyGenerated() const { return false; } + // True only for generators that operate directly on gpu (e.g. picture-generators) + virtual bool onCanLazyGenerateOnGPU() const { return false; } + // Call when this image is part of the key to a resourcecache entry. This allows the cache // to know automatically those entries can be purged when this SkImage deleted. void notifyAddedToCache() const { diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp index dcf4b1c..1fdd084 100644 --- a/src/image/SkImage_Gpu.cpp +++ b/src/image/SkImage_Gpu.cpp @@ -598,6 +598,18 @@ size_t SkImage::getDeferredTextureImageData(const GrContextThreadSafeProxy& prox const DeferredTextureImageUsageParams params[], int paramCnt, void* buffer, SkColorSpace* dstColorSpace) const { + // Some quick-rejects where is makes no sense to return CPU data + // e.g. + // - texture backed + // - picture backed + // + if (this->isTextureBacked()) { + return 0; + } + if (as_IB(this)->onCanLazyGenerateOnGPU()) { + return 0; + } + // Extract relevant min/max values from the params array. int lowestPreScaleMipLevel = params[0].fPreScaleMipLevel; SkFilterQuality highestFilterQuality = params[0].fQuality; @@ -650,11 +662,7 @@ size_t SkImage::getDeferredTextureImageData(const GrContextThreadSafeProxy& prox info = info.makeColorSpace(nullptr); } } else { - // Here we're just using presence of data to know whether there is a codec behind the image. - // In the future we will access the cacherator and get the exact data that we want to (e.g. - // yuv planes) upload. - sk_sp data(this->refEncoded()); - if (!data && !this->peekPixels(nullptr)) { + if (!this->isLazyGenerated() && !this->peekPixels(nullptr)) { return 0; } if (SkImageCacherator* cacher = as_IB(this)->peekCacherator()) { diff --git a/src/image/SkImage_Lazy.cpp b/src/image/SkImage_Lazy.cpp index 4bf61ea..e94041b 100644 --- a/src/image/SkImage_Lazy.cpp +++ b/src/image/SkImage_Lazy.cpp @@ -82,6 +82,7 @@ public: sk_sp onMakeSubset(const SkIRect&) const override; bool getROPixels(SkBitmap*, SkColorSpace* dstColorSpace, CachingHint) const override; bool onIsLazyGenerated() const override { return true; } + bool onCanLazyGenerateOnGPU() const override; sk_sp onMakeColorSpace(sk_sp, SkColorType, SkTransferFunctionBehavior) const override; @@ -556,6 +557,15 @@ bool SkImage_Lazy::onIsValid(GrContext* context) const { return generator->isValid(context); } +bool SkImage_Lazy::onCanLazyGenerateOnGPU() const { +#if SK_SUPPORT_GPU + ScopedGenerator generator(fSharedGenerator); + return generator->onCanGenerateTexture(); +#else + return false; +#endif +} + /////////////////////////////////////////////////////////////////////////////////////////////////// #if SK_SUPPORT_GPU -- 2.7.4