centralize default src/dst colorspace policy
We've long interpreted null source colorspaces as sRGB.
We've also been treating null destination colorspaces as legacy,
non-color-managed drawing. Assigning dst=src in this situation
is the best way to express that.
I have reverted the changes to SkImageShader and SkBlitter_Sprite,
where we had very slightly different logic.
Change-Id: I90e5ab424aea534d83cfbecd282b6cf48b56d056
Reviewed-on: https://skia-review.googlesource.com/148996
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
diff --git a/src/core/SkColorSpaceXformSteps.cpp b/src/core/SkColorSpaceXformSteps.cpp
index ef59a2d..8e53bc6 100644
--- a/src/core/SkColorSpaceXformSteps.cpp
+++ b/src/core/SkColorSpaceXformSteps.cpp
@@ -6,6 +6,7 @@
*/
#include "SkColorSpaceXformSteps.h"
+#include "SkColorSpacePriv.h"
#include "SkRasterPipeline.h"
// TODO: explain
@@ -22,7 +23,9 @@
memset(this, 0, sizeof(*this));
// We have some options about what to do with null src or dst here.
- SkASSERT(src && dst);
+ // This pair seems to be the most consistent with legacy expectations.
+ if (!src) { src = sk_srgb_singleton(); }
+ if (!dst) { dst = src; }
this->flags.unpremul = srcAT == kPremul_SkAlphaType;
this->flags.linearize = !src->gammaIsLinear();
diff --git a/src/core/SkConvertPixels.cpp b/src/core/SkConvertPixels.cpp
index 57afa0a..cd96e7f 100644
--- a/src/core/SkConvertPixels.cpp
+++ b/src/core/SkConvertPixels.cpp
@@ -220,15 +220,8 @@
break;
}
- // Interpret any untagged source as sRGB.
- auto srcCS = srcInfo.colorSpace() ? srcInfo.colorSpace() : sk_srgb_singleton();
-
- // An untagged destination implies no color space transform is needed,
- // but SkColorSpaceXformSteps may still do premul/unpremul conversion.
- auto dstCS = dstInfo.colorSpace() ? dstInfo.colorSpace() : srcCS;
-
- SkColorSpaceXformSteps steps{srcCS, srcInfo.alphaType(),
- dstCS, dstInfo.alphaType()};
+ SkColorSpaceXformSteps steps{srcInfo.colorSpace(), srcInfo.alphaType(),
+ dstInfo.colorSpace(), dstInfo.alphaType()};
steps.apply(&pipeline);
// We'll dither if we're decreasing precision below 32-bit.
diff --git a/src/core/SkPM4fPriv.h b/src/core/SkPM4fPriv.h
index 6dbc535..5c02e90 100644
--- a/src/core/SkPM4fPriv.h
+++ b/src/core/SkPM4fPriv.h
@@ -39,12 +39,6 @@
static inline SkPM4f premul_in_dst_colorspace(SkColor4f color4f,
SkColorSpace* srcCS, SkColorSpace* dstCS) {
- // We treat untagged sources as sRGB.
- if (!srcCS) { srcCS = sk_srgb_singleton(); }
-
- // If dstCS is null, no color space transformation is needed (and apply() will just premul).
- if (!dstCS) { dstCS = srcCS; }
-
// TODO: In the very common case of srcCS being sRGB,
// can we precompute an sRGB -> dstCS SkColorSpaceXformSteps for each device and use it here?
SkColorSpaceXformSteps(srcCS, kUnpremul_SkAlphaType,
diff --git a/src/core/SkRasterPipelineBlitter.cpp b/src/core/SkRasterPipelineBlitter.cpp
index d1eedae..3e8399e 100644
--- a/src/core/SkRasterPipelineBlitter.cpp
+++ b/src/core/SkRasterPipelineBlitter.cpp
@@ -13,7 +13,6 @@
#include "SkColorFilter.h"
#include "SkColorSpacePriv.h"
#include "SkColorSpaceXformer.h"
-#include "SkColorSpaceXformSteps.h"
#include "SkOpts.h"
#include "SkPM4f.h"
#include "SkPM4fPriv.h"
diff --git a/src/gpu/GrColorSpaceXform.cpp b/src/gpu/GrColorSpaceXform.cpp
index 7bb8a56..484654f 100644
--- a/src/gpu/GrColorSpaceXform.cpp
+++ b/src/gpu/GrColorSpaceXform.cpp
@@ -15,16 +15,6 @@
sk_sp<GrColorSpaceXform> GrColorSpaceXform::Make(SkColorSpace* src, SkAlphaType srcAT,
SkColorSpace* dst, SkAlphaType dstAT) {
- // No transformation is performed in legacy mode, until SkColorSpaceXformCanvas is gone
- if (!dst) {
- return nullptr;
- }
-
- // Treat null sources as sRGB.
- if (!src) {
- src = sk_srgb_singleton();
- }
-
SkColorSpaceXformSteps steps(src, srcAT, dst, dstAT);
return steps.flags.mask() == 0 ? nullptr /* Noop transform */
: sk_make_sp<GrColorSpaceXform>(steps);
diff --git a/src/shaders/SkColorShader.cpp b/src/shaders/SkColorShader.cpp
index a6df8f1..bcced85 100644
--- a/src/shaders/SkColorShader.cpp
+++ b/src/shaders/SkColorShader.cpp
@@ -106,11 +106,9 @@
}
static SkColor to_skcolor(SkColor4f color, SkColorSpace* cs) {
- if (cs) {
- SkColorSpaceXformSteps steps{cs , kUnpremul_SkAlphaType,
- sk_srgb_singleton(), kUnpremul_SkAlphaType};
- steps.apply(color.vec());
- }
+ SkColorSpaceXformSteps steps{cs , kUnpremul_SkAlphaType,
+ sk_srgb_singleton(), kUnpremul_SkAlphaType};
+ steps.apply(color.vec());
color = color.pin();
return SkColorSetARGB(unit_to_byte(color.fA), unit_to_byte(color.fR),
unit_to_byte(color.fG), unit_to_byte(color.fB));