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.
Re-land (and fix) of:
https://skia-review.googlesource.com/c/4438/
https://skia-review.googlesource.com/c/4796/
BUG=skia:5907
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=4838
Change-Id: I20ff972ffe1c7e6535ddc501e2a8ab8c246e4061
Reviewed-on: https://skia-review.googlesource.com/4838
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Matt Sarett <msarett@google.com>
diff --git a/src/gpu/GrImageIDTextureAdjuster.cpp b/src/gpu/GrImageIDTextureAdjuster.cpp
index cc869ba..645d1c2 100644
--- a/src/gpu/GrImageIDTextureAdjuster.cpp
+++ b/src/gpu/GrImageIDTextureAdjuster.cpp
@@ -52,7 +52,9 @@
return tex;
}
-void GrBitmapTextureMaker::makeCopyKey(const CopyParams& copyParams, GrUniqueKey* copyKey) {
+void GrBitmapTextureMaker::makeCopyKey(const CopyParams& copyParams, GrUniqueKey* copyKey,
+ SkDestinationSurfaceColorMode colorMode) {
+ // Color mode is irrelevant in this case - we always upload the bitmap's contents as-is
if (fOriginalKey.isValid()) {
MakeCopyKeyFromOrigKey(fOriginalKey, copyParams, copyKey);
}
@@ -66,8 +68,9 @@
return fBitmap.alphaType();
}
-SkColorSpace* GrBitmapTextureMaker::getColorSpace() {
- return fBitmap.colorSpace();
+sk_sp<SkColorSpace> GrBitmapTextureMaker::getColorSpace(SkDestinationSurfaceColorMode colorMode) {
+ // Color space doesn't depend on mode - it's just whatever is in the bitmap
+ return sk_ref_sp(fBitmap.colorSpace());
}
//////////////////////////////////////////////////////////////////////////////
@@ -93,9 +96,14 @@
colorMode);
}
-void GrImageTextureMaker::makeCopyKey(const CopyParams& stretch, GrUniqueKey* paramsCopyKey) {
+void GrImageTextureMaker::makeCopyKey(const CopyParams& stretch, GrUniqueKey* paramsCopyKey,
+ SkDestinationSurfaceColorMode colorMode) {
if (fOriginalKey.isValid() && SkImage::kAllow_CachingHint == fCachingHint) {
- MakeCopyKeyFromOrigKey(fOriginalKey, stretch, paramsCopyKey);
+ SkImageCacherator::CachedFormat cacheFormat =
+ fCacher->chooseCacheFormat(colorMode, this->context()->caps());
+ GrUniqueKey cacheKey;
+ fCacher->makeCacheKeyFromOrigKey(fOriginalKey, cacheFormat, &cacheKey);
+ MakeCopyKeyFromOrigKey(cacheKey, stretch, paramsCopyKey);
}
}
@@ -108,7 +116,6 @@
SkAlphaType GrImageTextureMaker::alphaType() const {
return fCacher->info().alphaType();
}
-
-SkColorSpace* GrImageTextureMaker::getColorSpace() {
- return fCacher->info().colorSpace();
+sk_sp<SkColorSpace> GrImageTextureMaker::getColorSpace(SkDestinationSurfaceColorMode colorMode) {
+ return fCacher->getColorSpace(this->context(), colorMode);
}