aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/image/SkImage_Generator.cpp
diff options
context:
space:
mode:
authorGravatar Brian Osman <brianosman@google.com>2016-11-14 15:09:56 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2016-11-15 15:27:14 +0000
commitc73a1ecbed64652b3d7aa8dc6face9a2205ce830 (patch)
tree59e66c879ca0d1ab68720ccae740cecb2d5660ef /src/image/SkImage_Generator.cpp
parentfd01ce05ef7902c49b0272b3524a389693c72b35 (diff)
Support decoding images to multiple formats, depending on usage
Our codec generator will now preserve any asked-for color space, and convert the encoded data to that representation. Cacherator now allows decoding an image to both legacy (nullptr color space), and color-correct formats. In color-correct mode, we choose the best decoded format, based on the original properties, and our backend's capabilities. Preference is given to the native format, when it's already texturable (sRGB 8888 or F16 linear). Otherwise, we prefer linear F16, and fall back to sRGB when that's not an option. BUG=skia:5907 GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=4438 Change-Id: I847c243dcfb72d8c0f1f6fc73c09547adea933f0 Reviewed-on: https://skia-review.googlesource.com/4438 Reviewed-by: Matt Sarett <msarett@google.com> Commit-Queue: Brian Osman <brianosman@google.com>
Diffstat (limited to 'src/image/SkImage_Generator.cpp')
-rw-r--r--src/image/SkImage_Generator.cpp15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/image/SkImage_Generator.cpp b/src/image/SkImage_Generator.cpp
index 03dda91e5e..43d26d0083 100644
--- a/src/image/SkImage_Generator.cpp
+++ b/src/image/SkImage_Generator.cpp
@@ -30,7 +30,7 @@ public:
SkImageCacherator* peekCacherator() const override { return &fCache; }
SkData* onRefEncoded(GrContext*) const override;
sk_sp<SkImage> onMakeSubset(const SkIRect&) const override;
- bool getROPixels(SkBitmap*, CachingHint) const override;
+ bool getROPixels(SkBitmap*, SkDestinationSurfaceColorMode, CachingHint) const override;
GrTexture* asTextureRef(GrContext*, const GrTextureParams&,
SkDestinationSurfaceColorMode) const override;
bool onIsLazyGenerated() const override { return true; }
@@ -45,9 +45,13 @@ private:
bool SkImage_Generator::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRB,
int srcX, int srcY, CachingHint chint) const {
+ SkDestinationSurfaceColorMode decodeColorMode = dstInfo.colorSpace()
+ ? SkDestinationSurfaceColorMode::kGammaAndColorSpaceAware
+ : SkDestinationSurfaceColorMode::kLegacy;
SkBitmap bm;
if (kDisallow_CachingHint == chint) {
- if (fCache.lockAsBitmapOnlyIfAlreadyCached(&bm)) {
+ SkImageCacherator::CachedFormat cacheFormat = fCache.chooseCacheFormat(decodeColorMode);
+ if (fCache.lockAsBitmapOnlyIfAlreadyCached(&bm, cacheFormat)) {
return bm.readPixels(dstInfo, dstPixels, dstRB, srcX, srcY);
} else {
// Try passing the caller's buffer directly down to the generator. If this fails we
@@ -60,7 +64,7 @@ bool SkImage_Generator::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels
}
}
- if (this->getROPixels(&bm, chint)) {
+ if (this->getROPixels(&bm, decodeColorMode, chint)) {
return bm.readPixels(dstInfo, dstPixels, dstRB, srcX, srcY);
}
return false;
@@ -70,8 +74,9 @@ SkData* SkImage_Generator::onRefEncoded(GrContext* ctx) const {
return fCache.refEncoded(ctx);
}
-bool SkImage_Generator::getROPixels(SkBitmap* bitmap, CachingHint chint) const {
- return fCache.lockAsBitmap(bitmap, this, chint);
+bool SkImage_Generator::getROPixels(SkBitmap* bitmap, SkDestinationSurfaceColorMode colorMode,
+ CachingHint chint) const {
+ return fCache.lockAsBitmap(bitmap, this, colorMode, chint);
}
GrTexture* SkImage_Generator::asTextureRef(GrContext* ctx, const GrTextureParams& params,