aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/image
diff options
context:
space:
mode:
authorGravatar Mike Reed <reed@google.com>2017-05-08 16:13:39 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-05-09 03:52:03 +0000
commit7f1d020bbfde245281fac88ff09b55366155be16 (patch)
tree12c5db2328c927802b441f026f1cd88e14f8e036 /src/image
parent090fbf86cf90dd326b3b3b59cde0a46b63a594a6 (diff)
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 <reed@google.com> Reviewed-by: Leon Scroggins <scroggo@google.com> Reviewed-by: Brian Salomon <bsalomon@google.com>
Diffstat (limited to 'src/image')
-rw-r--r--src/image/SkImage_Base.h4
-rw-r--r--src/image/SkImage_Gpu.cpp18
-rw-r--r--src/image/SkImage_Lazy.cpp10
3 files changed, 27 insertions, 5 deletions
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