Revert "Revert "inline common modecolorfilters""
inline commone modecolorfilters
This reverts commit 4049dffaa8392f6cebab3dd0b9f12fd1eaef4ede.
Bug: skia:
Change-Id: I8887cc47b2c92da7b6f83548221b7d65958cf01f
Reviewed-on: https://skia-review.googlesource.com/19561
Commit-Queue: Mike Reed <reed@google.com>
Commit-Queue: Mike Klein <mtklein@google.com>
Reviewed-by: Mike Klein <mtklein@google.com>
diff --git a/src/core/SkModeColorFilter.cpp b/src/core/SkModeColorFilter.cpp
index 7e93747..bca23c6 100644
--- a/src/core/SkModeColorFilter.cpp
+++ b/src/core/SkModeColorFilter.cpp
@@ -63,11 +63,41 @@
}
void SkModeColorFilter::filterSpan(const SkPMColor shader[], int count, SkPMColor result[]) const {
- SkPMColor color = fPMColor;
- SkXfermodeProc proc = SkXfermode::GetProc(fMode);
+ SkPMColor color = fPMColor;
- for (int i = 0; i < count; i++) {
- result[i] = proc(color, shader[i]);
+ switch (fMode) {
+ case SkBlendMode::kSrc:
+ sk_memset32(result, color, count);
+ break;
+ case SkBlendMode::kSrcIn:
+ for (int i = 0; i < count; ++i) {
+ result[i] = SkAlphaMulQ(color, SkAlpha255To256(SkGetPackedA32(shader[i])));
+ }
+ break;
+ case SkBlendMode::kModulate:
+ for (int i = 0; i < count; ++i) {
+ int a = SkMulDiv255Round(SkGetPackedA32(color), SkGetPackedA32(shader[i]));
+ int r = SkMulDiv255Round(SkGetPackedR32(color), SkGetPackedR32(shader[i]));
+ int g = SkMulDiv255Round(SkGetPackedG32(color), SkGetPackedG32(shader[i]));
+ int b = SkMulDiv255Round(SkGetPackedB32(color), SkGetPackedB32(shader[i]));
+ result[i] = SkPackARGB32(a, r, g, b);
+ }
+ break;
+ default: {
+ SkSTArenaAlloc<256> alloc;
+ SkRasterPipeline p(&alloc);
+
+ p.append(SkRasterPipeline::load_8888, &shader);
+ if (kN32_SkColorType == kBGRA_8888_SkColorType) {
+ p.append(SkRasterPipeline::swap_rb);
+ }
+ this->appendStages(&p, nullptr, &alloc, false);
+ if (kN32_SkColorType == kBGRA_8888_SkColorType) {
+ p.append(SkRasterPipeline::swap_rb);
+ }
+ p.append(SkRasterPipeline::store_8888, &result);
+ p.run(0, 0, count);
+ } break;
}
}
@@ -132,32 +162,6 @@
///////////////////////////////////////////////////////////////////////////////
-class Src_SkModeColorFilter final : public SkModeColorFilter {
-public:
- Src_SkModeColorFilter(SkColor color) : INHERITED(color, SkBlendMode::kSrc) {}
-
- void filterSpan(const SkPMColor shader[], int count, SkPMColor result[]) const override {
- sk_memset32(result, this->getPMColor(), count);
- }
-
-private:
- typedef SkModeColorFilter INHERITED;
-};
-
-class SrcOver_SkModeColorFilter final : public SkModeColorFilter {
-public:
- SrcOver_SkModeColorFilter(SkColor color) : INHERITED(color, SkBlendMode::kSrcOver) { }
-
- void filterSpan(const SkPMColor shader[], int count, SkPMColor result[]) const override {
- SkBlitRow::Color32(result, shader, count, this->getPMColor());
- }
-
-private:
- typedef SkModeColorFilter INHERITED;
-};
-
-///////////////////////////////////////////////////////////////////////////////
-
sk_sp<SkColorFilter> SkColorFilter::MakeModeFilter(SkColor color, SkBlendMode mode) {
if (!SkIsValidMode(mode)) {
return nullptr;
@@ -191,12 +195,5 @@
return nullptr;
}
- switch (mode) {
- case SkBlendMode::kSrc:
- return sk_make_sp<Src_SkModeColorFilter>(color);
- case SkBlendMode::kSrcOver:
- return sk_make_sp<SrcOver_SkModeColorFilter>(color);
- default:
- return SkModeColorFilter::Make(color, mode);
- }
+ return SkModeColorFilter::Make(color, mode);
}