diff options
author | reed <reed@google.com> | 2016-05-04 13:09:39 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-05-04 13:09:39 -0700 |
commit | 0ccc62d4f79809fe20de299ba1fabdf2592ce2e5 (patch) | |
tree | 9503a3a366b739b9092073ba75c41f9e0192b6e4 /gm/color4f.cpp | |
parent | 3e375b0a51a46814cf08ecd1a513862006a704e5 (diff) |
move colorshader into its own .cpp, add color4f variant
Implemented as a different subclass for SkColorShader (which is also private) partly to make the CL clearer/simpler, and partly for flatten/unflatten compatibility. Later I'm sure we could combine these if that proves useful.
Lots of TODOs at the moment, but still valuable to get reviewed.
Note: this ignores the question (for the moment) about how to interpret SkColor in the larger world. That needs to happen, but this CL is more focused on what *else* to do besides handle the old-style input (and old-style pipeline).
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1934313002
Review-Url: https://codereview.chromium.org/1934313002
Diffstat (limited to 'gm/color4f.cpp')
-rw-r--r-- | gm/color4f.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/gm/color4f.cpp b/gm/color4f.cpp index 2585ad87c1..829434c248 100644 --- a/gm/color4f.cpp +++ b/gm/color4f.cpp @@ -84,3 +84,42 @@ DEF_SIMPLE_GM(color4f, canvas, 1024, 260) { canvas->translate(0, 120); } } + +/////////////////////////////////////////////////////////////////////////////////////////////////// +#include "SkColorSpace.h" + +DEF_SIMPLE_GM(color4shader, canvas, 1024, 260) { + canvas->translate(10, 10); + + SkMatrix44 mat(SkMatrix44::kUninitialized_Constructor); + // red -> blue, green -> red, blue -> green + mat.set3x3(0, 1, 0, 0, 0, 1, 1, 0, 0); + + const SkColor4f colors[] { + { 1, 1, 0, 0 }, + { 1, 0, 1, 0 }, + { 1, 0, 0, 1 }, + { 1, 0.5, 0.5, 0.5 }, + }; + + SkPaint paint; + SkRect r = SkRect::MakeWH(100, 100); + + for (const auto& c4 : colors) { + sk_sp<SkShader> shaders[] { + SkShader::MakeColorShader(c4, nullptr), + SkShader::MakeColorShader(c4, SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named)), + SkShader::MakeColorShader(c4, SkColorSpace::NewRGB(SkColorSpace::SkGammas(1, 1, 1), + mat)), + }; + + canvas->save(); + for (const auto& s : shaders) { + paint.setShader(s); + canvas->drawRect(r, paint); + canvas->translate(r.width() * 6 / 5, 0); + } + canvas->restore(); + canvas->translate(0, r.height() * 6 / 5); + } +} |