From ae724f1320c712ed8e72de48332d9b7484ae1c3f Mon Sep 17 00:00:00 2001 From: reed-at-google Date: Mon, 29 Apr 2019 09:03:10 -0400 Subject: [PATCH] colormatrix is now 0...1 (#8772) * colormatrix is now 0...1 * reformat --- lib/ui/painting/paint.cc | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/lib/ui/painting/paint.cc b/lib/ui/painting/paint.cc index febe40fe70..cf5fe2cf56 100644 --- a/lib/ui/painting/paint.cc +++ b/lib/ui/painting/paint.cc @@ -52,7 +52,7 @@ constexpr double kStrokeMiterLimitDefault = 4.0; // A color matrix which inverts colors. // clang-format off -constexpr SkScalar invert_colors[20] = { +constexpr float invert_colors[20] = { -1.0, 0, 0, 1.0, 0, 0, -1.0, 0, 1.0, 0, 0, 0, -1.0, 1.0, 0, @@ -72,6 +72,19 @@ enum ColorFilterType { SRGBToLinearGamma }; +// Flutter still defines the matrix to be biased by 255 in the last column +// (translate). skia is normalized, treating the last column as 0...1, so we +// post-scale here before calling the skia factory. +static sk_sp MakeColorMatrixFilter255(const float array[20]) { + float tmp[20]; + memcpy(tmp, array, sizeof(tmp)); + tmp[4] *= 1.0f / 255; + tmp[9] *= 1.0f / 255; + tmp[14] *= 1.0f / 255; + tmp[19] *= 1.0f / 255; + return SkColorFilters::Matrix(tmp); +} + sk_sp ExtractColorFilter(const uint32_t* uint_data, Dart_Handle* values) { switch (uint_data[kColorFilterIndex]) { @@ -92,7 +105,7 @@ sk_sp ExtractColorFilter(const uint32_t* uint_data, FML_CHECK(length == 20); tonic::Float32List decoded(matrixHandle); - return SkColorFilters::MatrixRowMajor255(decoded.data()); + return MakeColorMatrixFilter255(decoded.data()); } return nullptr; } @@ -178,11 +191,11 @@ Paint::Paint(Dart_Handle paint_objects, Dart_Handle paint_data) { sk_sp color_filter = ExtractColorFilter(uint_data, values); if (color_filter) { sk_sp invert_filter = - SkColorFilters::MatrixRowMajor255(invert_colors); + MakeColorMatrixFilter255(invert_colors); paint_.setColorFilter(invert_filter->makeComposed(color_filter)); } } else if (uint_data[kInvertColorIndex]) { - paint_.setColorFilter(SkColorFilters::MatrixRowMajor255(invert_colors)); + paint_.setColorFilter(MakeColorMatrixFilter255(invert_colors)); } else if (uint_data[kColorFilterIndex]) { sk_sp color_filter = ExtractColorFilter(uint_data, values); if (color_filter) { -- GitLab