Replace SkColorSpace::filterColor with filterColor4f (flutter/engine#50821)

The old API is deprecated. The new one operates on float colors, but is
also explicit about the color space of the source color (and the working
space of the filter).

Bug: b/40040795
This commit is contained in:
Brian Osman
2024-02-23 09:23:00 -05:00
committed by GitHub
parent aaf2566641
commit f1951104cb
2 changed files with 20 additions and 4 deletions

View File

@@ -10,6 +10,7 @@
#include "flutter/display_list/effects/dl_color_source.h"
#include "flutter/display_list/skia/dl_sk_conversions.h"
#include "gtest/gtest.h"
#include "third_party/skia/include/core/SkColorSpace.h"
#include "third_party/skia/include/core/SkSamplingOptions.h"
#include "third_party/skia/include/core/SkTileMode.h"
@@ -155,17 +156,24 @@ TEST(DisplayListSkConversions, BlendColorFilterModifiesTransparency) {
<< "]";
std::string desc = desc_str.str();
DlBlendColorFilter filter(color, mode);
auto srgb = SkColorSpace::MakeSRGB();
if (filter.modifies_transparent_black()) {
auto dl_filter = DlBlendColorFilter::Make(color, mode);
auto sk_filter = ToSk(filter);
ASSERT_NE(dl_filter, nullptr) << desc;
ASSERT_NE(sk_filter, nullptr) << desc;
ASSERT_TRUE(sk_filter->filterColor(0) != 0) << desc;
ASSERT_TRUE(sk_filter->filterColor4f(SkColors::kTransparent, srgb.get(),
srgb.get()) !=
SkColors::kTransparent)
<< desc;
} else {
auto dl_filter = DlBlendColorFilter::Make(color, mode);
auto sk_filter = ToSk(filter);
EXPECT_EQ(dl_filter == nullptr, sk_filter == nullptr) << desc;
ASSERT_TRUE(sk_filter == nullptr || sk_filter->filterColor(0) == 0)
ASSERT_TRUE(sk_filter == nullptr ||
sk_filter->filterColor4f(SkColors::kTransparent, srgb.get(),
srgb.get()) ==
SkColors::kTransparent)
<< desc;
}
};
@@ -266,9 +274,12 @@ TEST(DisplayListSkConversions, MatrixColorFilterModifiesTransparency) {
DlMatrixColorFilter filter(matrix);
auto dl_filter = DlMatrixColorFilter::Make(matrix);
auto sk_filter = ToSk(filter);
auto srgb = SkColorSpace::MakeSRGB();
EXPECT_EQ(dl_filter == nullptr, sk_filter == nullptr);
EXPECT_EQ(filter.modifies_transparent_black(),
sk_filter && sk_filter->filterColor(0) != 0);
sk_filter && sk_filter->filterColor4f(SkColors::kTransparent,
srgb.get(), srgb.get()) !=
SkColors::kTransparent);
};
// Tests identity (matrix[0] already == 1 in an identity filter)

View File

@@ -24,6 +24,7 @@
#include "third_party/skia/include/core/SkBBHFactory.h"
#include "third_party/skia/include/core/SkColorFilter.h"
#include "third_party/skia/include/core/SkColorSpace.h"
#include "third_party/skia/include/core/SkFontMgr.h"
#include "third_party/skia/include/core/SkPictureRecorder.h"
#include "third_party/skia/include/core/SkStream.h"
@@ -4528,10 +4529,14 @@ class DisplayListNopTest : public DisplayListRendering {
auto sk_mode = static_cast<SkBlendMode>(mode);
auto sk_color_filter = SkColorFilters::Blend(ToSk(color), sk_mode);
auto srgb = SkColorSpace::MakeSRGB();
int all_flags = 0;
if (sk_color_filter) {
for (DlColor dst_color : test_dst_colors) {
DlColor result = DlColor(sk_color_filter->filterColor(ToSk(dst_color)));
SkColor4f dst_color_f = SkColor4f::FromColor(ToSk(dst_color));
DlColor result = DlColor(
sk_color_filter->filterColor4f(dst_color_f, srgb.get(), srgb.get())
.toSkColor());
all_flags |= check_color_result(dst_color, result, dl, desc);
}
if ((all_flags & kWasMTB) != 0) {