aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core
diff options
context:
space:
mode:
authorGravatar Mike Klein <mtklein@chromium.org>2017-03-13 09:56:34 -0700
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-03-13 18:18:25 +0000
commit49f33b8c84146dece85801dc1de21dd347310b6b (patch)
tree557a542701ba03307afa50486eb39d0885ef4a35 /src/core
parent7a5e0f38474a0ab996e038aa42f27c0d152b517e (diff)
More SkCSXformCanvas work.
- handle color arrays in drawPatch(), drawVertices(), drawAtlas() - color filters Color filter support is a one-off for SkModeColorFilter. I don't know any other color filters that are parameterized by a color. If there are any/many, we may want to wire up something more comprehensive here. Change-Id: Ibc89574e3a32d38af3bc2443a7d4bac0bb52d493 Reviewed-on: https://skia-review.googlesource.com/9601 Reviewed-by: Brian Osman <brianosman@google.com> Commit-Queue: Mike Klein <mtklein@chromium.org>
Diffstat (limited to 'src/core')
-rw-r--r--src/core/SkColorSpaceXformCanvas.cpp52
1 files changed, 41 insertions, 11 deletions
diff --git a/src/core/SkColorSpaceXformCanvas.cpp b/src/core/SkColorSpaceXformCanvas.cpp
index 7267a2893f..89c81e5462 100644
--- a/src/core/SkColorSpaceXformCanvas.cpp
+++ b/src/core/SkColorSpaceXformCanvas.cpp
@@ -5,6 +5,7 @@
* found in the LICENSE file.
*/
+#include "SkColorFilter.h"
#include "SkColorSpaceXform.h"
#include "SkColorSpaceXformCanvas.h"
#include "SkMakeUnique.h"
@@ -23,11 +24,15 @@ public:
fFromSRGB = SkColorSpaceXform::New(SkColorSpace::MakeSRGB().get(), fTargetCS.get());
}
+ void xform(SkColor* xformed, const SkColor* srgb, int n) const {
+ SkAssertResult(fFromSRGB->apply(SkColorSpaceXform::kBGRA_8888_ColorFormat, xformed,
+ SkColorSpaceXform::kBGRA_8888_ColorFormat, srgb,
+ n, kUnpremul_SkAlphaType));
+ }
+
SkColor xform(SkColor srgb) const {
SkColor xformed;
- SkAssertResult(fFromSRGB->apply(SkColorSpaceXform::kBGRA_8888_ColorFormat, &xformed,
- SkColorSpaceXform::kBGRA_8888_ColorFormat, &srgb,
- 1, kUnpremul_SkAlphaType));
+ this->xform(&xformed, &srgb, 1);
return xformed;
}
@@ -46,23 +51,31 @@ public:
get_lazy()->setColor(this->xform(paint.getColor()));
}
+ // As far as I know, SkModeColorFilter is the only color filter that holds a color.
+ if (auto cf = paint.getColorFilter()) {
+ SkColor color;
+ SkBlendMode mode;
+ if (cf->asColorMode(&color, &mode)) {
+ get_lazy()->setColorFilter(SkColorFilter::MakeModeFilter(this->xform(color), mode));
+ }
+ }
+
// TODO:
// - shaders
- // - color filters
// - image filters?
return *result;
}
+ const SkPaint* xform(const SkPaint* paint, SkTLazy<SkPaint>* lazy) const {
+ return paint ? &this->xform(*paint, lazy) : nullptr;
+ }
+
sk_sp<const SkImage> xform(const SkImage* img) const {
// TODO: for real
return sk_ref_sp(img);
}
- const SkPaint* xform(const SkPaint* paint, SkTLazy<SkPaint>* lazy) const {
- return paint ? &this->xform(*paint, lazy) : nullptr;
- }
-
void onDrawPaint(const SkPaint& paint) override {
SkTLazy<SkPaint> lazy;
fTarget->drawPaint(this->xform(paint, &lazy));
@@ -99,7 +112,12 @@ public:
}
void onDrawPatch(const SkPoint cubics[12], const SkColor colors[4], const SkPoint texs[4],
SkBlendMode mode, const SkPaint& paint) override {
- // TODO: colors
+ SkColor xformed[4];
+ if (colors) {
+ this->xform(xformed, colors, 4);
+ colors = xformed;
+ }
+
SkTLazy<SkPaint> lazy;
fTarget->drawPatch(cubics, colors, texs, mode, this->xform(paint, &lazy));
}
@@ -112,7 +130,13 @@ public:
const SkPoint* verts, const SkPoint* texs, const SkColor* colors,
SkBlendMode mode,
const uint16_t* indices, int indexCount, const SkPaint& paint) override {
- // TODO: colors
+ SkTArray<SkColor> xformed;
+ if (colors) {
+ xformed.reset(count);
+ this->xform(xformed.begin(), colors, count);
+ colors = xformed.begin();
+ }
+
SkTLazy<SkPaint> lazy;
fTarget->drawVertices(vmode, count, verts, texs, colors, mode, indices, indexCount,
this->xform(paint, &lazy));
@@ -190,7 +214,13 @@ public:
void onDrawAtlas(const SkImage* atlas, const SkRSXform* xforms, const SkRect* tex,
const SkColor* colors, int count, SkBlendMode mode,
const SkRect* cull, const SkPaint* paint) override {
- // TODO: colors
+ SkTArray<SkColor> xformed;
+ if (colors) {
+ xformed.reset(count);
+ this->xform(xformed.begin(), colors, count);
+ colors = xformed.begin();
+ }
+
SkTLazy<SkPaint> lazy;
fTarget->drawAtlas(this->xform(atlas).get(), xforms, tex, colors, count, mode, cull,
this->xform(paint, &lazy));