aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--include/core/SkImageGenerator.h3
-rw-r--r--src/core/SkPictureImageGenerator.h1
-rw-r--r--src/image/SkImage_Base.h4
-rw-r--r--src/image/SkImage_Gpu.cpp18
-rw-r--r--src/image/SkImage_Lazy.cpp10
5 files changed, 30 insertions, 6 deletions
diff --git a/include/core/SkImageGenerator.h b/include/core/SkImageGenerator.h
index 348f281965..3e433a376f 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<GrTextureProxy> 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 ed5e87cfe5..95eeb88236 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<GrTextureProxy> onGenerateTexture(GrContext*, const SkImageInfo&,
const SkIPoint&) override;
#endif
diff --git a/src/image/SkImage_Base.h b/src/image/SkImage_Base.h
index 64c075daeb..95ad67af10 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 dcf4b1cb63..1fdd084fa2 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<SkData> 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 4bf61eaa90..e94041beda 100644
--- a/src/image/SkImage_Lazy.cpp
+++ b/src/image/SkImage_Lazy.cpp
@@ -82,6 +82,7 @@ public:
sk_sp<SkImage> 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<SkImage> onMakeColorSpace(sk_sp<SkColorSpace>, 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