aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/image/SkImage_Lazy.cpp
diff options
context:
space:
mode:
authorGravatar Brian Osman <brianosman@google.com>2018-06-26 19:19:49 +0000
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-06-26 19:19:53 +0000
commite269310a09646c7df63039392782a078cc5256c6 (patch)
tree353eef4da4898666744a59724fdd9d53445c71df /src/image/SkImage_Lazy.cpp
parent3627d2ebbba3415f815167842369d28ec5cfeecb (diff)
Revert "Temporary fix for SkImage_Lazy handling of color spaces"
This reverts commit 439b99451445a9d61f0670bbe3f588f5b08f59fa. Reason for revert: Chrome tests failing. Original change's description: > Temporary fix for SkImage_Lazy handling of color spaces > > The aim is to always decode in the generator's color space, > with nonlinear blending. Eventually, we want to decode into > the destination color space, but that requires changing API > and caching flow. For now, this prevents linear premul when > decoding, and stops decoding to formats like F16 and sBGRA. > > Bug: skia: > Change-Id: I9efd909fa6a56df2547ad5955f109e113527f815 > Reviewed-on: https://skia-review.googlesource.com/136791 > Commit-Queue: Mike Klein <mtklein@google.com> > Reviewed-by: Mike Klein <mtklein@google.com> TBR=mtklein@google.com,brianosman@google.com Change-Id: Ie15c585b69e4309c090c8aafbe3c2d20191caa4d No-Presubmit: true No-Tree-Checks: true No-Try: true Bug: skia: Reviewed-on: https://skia-review.googlesource.com/137720 Reviewed-by: Brian Osman <brianosman@google.com> Commit-Queue: Brian Osman <brianosman@google.com>
Diffstat (limited to 'src/image/SkImage_Lazy.cpp')
-rw-r--r--src/image/SkImage_Lazy.cpp137
1 files changed, 133 insertions, 4 deletions
diff --git a/src/image/SkImage_Lazy.cpp b/src/image/SkImage_Lazy.cpp
index 0d5c4e811c..f06c963f37 100644
--- a/src/image/SkImage_Lazy.cpp
+++ b/src/image/SkImage_Lazy.cpp
@@ -297,14 +297,129 @@ struct CacheCaps {
SkImageCacherator::CachedFormat SkImage_Lazy::chooseCacheFormat(SkColorSpace* dstColorSpace,
const GrCaps* grCaps) const {
+ SkColorSpace* cs = fInfo.colorSpace();
+ if (!cs || !dstColorSpace) {
+ return kLegacy_CachedFormat;
+ }
+
+ CacheCaps caps(grCaps);
+ switch (fInfo.colorType()) {
+ case kUnknown_SkColorType:
+ case kAlpha_8_SkColorType:
+ case kRGB_565_SkColorType:
+ case kARGB_4444_SkColorType:
+ case kRGB_888x_SkColorType:
+ case kRGBA_1010102_SkColorType:
+ case kRGB_101010x_SkColorType:
+ // We don't support color space on these formats, so always decode in legacy mode:
+ // TODO: Ask the codec to decode these to something else (at least sRGB 8888)?
+ return kLegacy_CachedFormat;
+
+ case kGray_8_SkColorType:
+ // TODO: What do we do with grayscale sources that have strange color spaces attached?
+ // The codecs and color space xform don't handle this correctly (yet), so drop it on
+ // the floor. (Also, inflating by a factor of 8 is going to be unfortunate).
+ // As it is, we don't directly support sRGB grayscale, so ask the codec to convert
+ // it for us. This bypasses some really sketchy code GrUploadPixmapToTexture.
+ if (cs->gammaCloseToSRGB() && caps.supportsSRGB()) {
+ return kSRGB8888_CachedFormat;
+ } else {
+ return kLegacy_CachedFormat;
+ }
+
+ case kRGBA_8888_SkColorType:
+ if (cs->gammaCloseToSRGB()) {
+ if (caps.supportsSRGB()) {
+ return kSRGB8888_CachedFormat;
+ } else if (caps.supportsHalfFloat()) {
+ return kLinearF16_CachedFormat;
+ } else {
+ return kLegacy_CachedFormat;
+ }
+ } else {
+ if (caps.supportsHalfFloat()) {
+ return kLinearF16_CachedFormat;
+ } else if (caps.supportsSRGB()) {
+ return kSRGB8888_CachedFormat;
+ } else {
+ return kLegacy_CachedFormat;
+ }
+ }
+
+ case kBGRA_8888_SkColorType:
+ // Odd case. sBGRA isn't a real thing, so we may not have this texturable.
+ if (caps.supportsSBGR()) {
+ if (cs->gammaCloseToSRGB()) {
+ return kSBGR8888_CachedFormat;
+ } else if (caps.supportsHalfFloat()) {
+ return kLinearF16_CachedFormat;
+ } else if (caps.supportsSRGB()) {
+ return kSRGB8888_CachedFormat;
+ } else {
+ // sBGRA support without sRGBA is highly unlikely (impossible?) Nevertheless.
+ return kLegacy_CachedFormat;
+ }
+ } else {
+ if (cs->gammaCloseToSRGB()) {
+ if (caps.supportsSRGB()) {
+ return kSRGB8888_CachedFormat;
+ } else if (caps.supportsHalfFloat()) {
+ return kLinearF16_CachedFormat;
+ } else {
+ return kLegacy_CachedFormat;
+ }
+ } else {
+ if (caps.supportsHalfFloat()) {
+ return kLinearF16_CachedFormat;
+ } else if (caps.supportsSRGB()) {
+ return kSRGB8888_CachedFormat;
+ } else {
+ return kLegacy_CachedFormat;
+ }
+ }
+ }
+
+ case kRGBA_F16_SkColorType:
+ if (caps.supportsHalfFloat()) {
+ return kLinearF16_CachedFormat;
+ } else if (caps.supportsSRGB()) {
+ return kSRGB8888_CachedFormat;
+ } else {
+ return kLegacy_CachedFormat;
+ }
+ }
+ SkDEBUGFAIL("Unreachable");
return kLegacy_CachedFormat;
}
SkImageInfo SkImage_Lazy::buildCacheInfo(CachedFormat format) const {
- if (kGray_8_SkColorType == fInfo.colorType()) {
- return fInfo.makeColorSpace(nullptr);
- } else {
- return fInfo;
+ switch (format) {
+ case kLegacy_CachedFormat:
+ return fInfo.makeColorSpace(nullptr);
+ case kLinearF16_CachedFormat:
+ return fInfo.makeColorType(kRGBA_F16_SkColorType)
+ .makeColorSpace(fInfo.colorSpace()->makeLinearGamma());
+ case kSRGB8888_CachedFormat:
+ // If the transfer function is nearly (but not exactly) sRGB, we don't want the codec
+ // to bother trans-coding. It would be slow, and do more harm than good visually,
+ // so we make sure to leave the colorspace as-is.
+ if (fInfo.colorSpace()->gammaCloseToSRGB()) {
+ return fInfo.makeColorType(kRGBA_8888_SkColorType);
+ } else {
+ return fInfo.makeColorType(kRGBA_8888_SkColorType)
+ .makeColorSpace(fInfo.colorSpace()->makeSRGBGamma());
+ }
+ case kSBGR8888_CachedFormat:
+ // See note above about not-quite-sRGB transfer functions.
+ if (fInfo.colorSpace()->gammaCloseToSRGB()) {
+ return fInfo.makeColorType(kBGRA_8888_SkColorType);
+ } else {
+ return fInfo.makeColorType(kBGRA_8888_SkColorType)
+ .makeColorSpace(fInfo.colorSpace()->makeSRGBGamma());
+ }
+ default:
+ SkDEBUGFAIL("Invalid cached format");
+ return fInfo;
}
}
@@ -486,6 +601,20 @@ bool SkImage_Lazy::onCanLazyGenerateOnGPU() const {
}
SkTransferFunctionBehavior SkImage_Lazy::getGeneratorBehaviorAndInfo(SkImageInfo* generatorImageInfo) const {
+ if (generatorImageInfo->colorSpace()) {
+ return SkTransferFunctionBehavior::kRespect;
+ }
+ // Only specify an output color space if color conversion can be done on the color type.
+ switch (generatorImageInfo->colorType()) {
+ case kRGBA_8888_SkColorType:
+ case kBGRA_8888_SkColorType:
+ case kRGBA_F16_SkColorType:
+ case kRGB_565_SkColorType:
+ *generatorImageInfo = generatorImageInfo->makeColorSpace(fInfo.refColorSpace());
+ break;
+ default:
+ break;
+ }
return SkTransferFunctionBehavior::kIgnore;
}