New helpers for converting SkColor to GrColor4f
These versions will eliminate lots of copy-pasting in various fragment
processor creation code.
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=3787
Change-Id: I3ada2d4866e92cfc0507beeea11e05790d73757d
Reviewed-on: https://skia-review.googlesource.com/3787
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp
index 7c008be..7d4d678 100644
--- a/src/gpu/SkGr.cpp
+++ b/src/gpu/SkGr.cpp
@@ -438,6 +438,21 @@
///////////////////////////////////////////////////////////////////////////////
+GrColor4f SkColorToPremulGrColor4f(SkColor c, SkColorSpace* dstColorSpace) {
+ // We want to premultiply after linearizing, so this is easy:
+ return SkColorToUnpremulGrColor4f(c, dstColorSpace).premul();
+}
+
+GrColor4f SkColorToUnpremulGrColor4f(SkColor c, SkColorSpace* dstColorSpace) {
+ if (dstColorSpace) {
+ auto srgbColorSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named);
+ auto gamutXform = GrColorSpaceXform::Make(srgbColorSpace.get(), dstColorSpace);
+ return SkColorToUnpremulGrColor4f(c, true, gamutXform.get());
+ } else {
+ return SkColorToUnpremulGrColor4f(c, false, nullptr);
+ }
+}
+
GrColor4f SkColorToPremulGrColor4f(SkColor c, bool gammaCorrect, GrColorSpaceXform* gamutXform) {
// We want to premultiply after linearizing, so this is easy:
return SkColorToUnpremulGrColor4f(c, gammaCorrect, gamutXform).premul();