0

Let cc::FuzzyPixelComparator check large errors separately

Previously cc::FuzzyPixelComparator had overrall error parameters and
tiny error parameters. For example, the following set of parameters
   error_pixels_percentage_limit: 3
   small_error_pixel_percentage_limit: 2
   max_abs_error_limit: 100
   small_error_threshold: 2
allowed 3% of pixels to have diff<=100, and all of them can be >2.
There was no way to allow 2% small error pixels and only 1% of large
error pixels. The parameters actually applied stricter rule on small
errors than large errors.

Now add multiple methods to set parameters of FuzzyPixelComparator
instead of the original constructor with many parameters. The
error_pixels_percentage_limit parameter is changed to
large_error_pixels_percentage_limit to check for large errors
separately. The values of the parameter at callsites (only 2) where
small_error_pixel_percentage_limit was zero are adjusted accordingly.

check_critical_errors of FuzzyPixelComparator is removed and critical
errors are always checked.

discard_alpha parameter of all PixelComparator implementations is
removed and is replaced with dedicated method and classes.

Change-Id: Ic2be2882e432383a55f972f80f8e1c09fdde017c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4185898
Reviewed-by: Lei Zhang <thestig@chromium.org>
Reviewed-by: Scott Violet <sky@chromium.org>
Commit-Queue: Xianzhu Wang <wangxianzhu@chromium.org>
Reviewed-by: Vladimir Levin <vmpstr@chromium.org>
Owners-Override: Xianzhu Wang <wangxianzhu@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1096498}
This commit is contained in:
Xianzhu Wang
2023-01-24 23:59:09 +00:00
committed by Chromium LUCI CQ
parent 5fa93d7dff
commit 43fe4442da
30 changed files with 559 additions and 594 deletions

@@ -154,9 +154,8 @@ TEST_F(SuggestionChipViewTest, DarkAndLightTheme) {
EXPECT_EQ(label->GetEnabledColor(), EXPECT_EQ(label->GetEnabledColor(),
ColorProvider::Get()->GetContentLayerColor( ColorProvider::Get()->GetContentLayerColor(
ColorProvider::ContentLayerType::kTextColorSecondary)); ColorProvider::ContentLayerType::kTextColorSecondary));
EXPECT_TRUE( EXPECT_TRUE(cc::ExactPixelComparator().Compare(
cc::ExactPixelComparator(/*discard_alpha=*/false) GetSuggestionChipViewBitmap(suggestion_chip_view),
.Compare(GetSuggestionChipViewBitmap(suggestion_chip_view),
GetBitmapWithInnerRoundedRect( GetBitmapWithInnerRoundedRect(
kSuggestionChipViewSize, /*stroke_width=*/1, kSuggestionChipViewSize, /*stroke_width=*/1,
ColorProvider::Get()->GetContentLayerColor( ColorProvider::Get()->GetContentLayerColor(
@@ -165,9 +164,7 @@ TEST_F(SuggestionChipViewTest, DarkAndLightTheme) {
// Focus the chip view and confirm that focus ring is rendered. // Focus the chip view and confirm that focus ring is rendered.
suggestion_chip_view->RequestFocus(); suggestion_chip_view->RequestFocus();
views::test::RunScheduledLayout(views::FocusRing::Get(suggestion_chip_view)); views::test::RunScheduledLayout(views::FocusRing::Get(suggestion_chip_view));
EXPECT_TRUE( EXPECT_TRUE(cc::ExactPixelComparator().Compare(
cc::ExactPixelComparator(/*discard_alpha=*/false)
.Compare(
GetFocusRingBitmap(views::FocusRing::Get(suggestion_chip_view)), GetFocusRingBitmap(views::FocusRing::Get(suggestion_chip_view)),
GetBitmapWithInnerRoundedRect( GetBitmapWithInnerRoundedRect(
kSuggestionChipViewSize, /*stroke_width=*/2, kSuggestionChipViewSize, /*stroke_width=*/2,
@@ -184,9 +181,8 @@ TEST_F(SuggestionChipViewTest, DarkAndLightTheme) {
EXPECT_EQ(label->GetEnabledColor(), EXPECT_EQ(label->GetEnabledColor(),
ColorProvider::Get()->GetContentLayerColor( ColorProvider::Get()->GetContentLayerColor(
ColorProvider::ContentLayerType::kTextColorSecondary)); ColorProvider::ContentLayerType::kTextColorSecondary));
EXPECT_TRUE( EXPECT_TRUE(cc::ExactPixelComparator().Compare(
cc::ExactPixelComparator(/*discard_alpha=*/false) GetSuggestionChipViewBitmap(suggestion_chip_view),
.Compare(GetSuggestionChipViewBitmap(suggestion_chip_view),
GetBitmapWithInnerRoundedRect( GetBitmapWithInnerRoundedRect(
kSuggestionChipViewSize, /*stroke_width=*/1, kSuggestionChipViewSize, /*stroke_width=*/1,
ColorProvider::Get()->GetContentLayerColor( ColorProvider::Get()->GetContentLayerColor(
@@ -194,9 +190,7 @@ TEST_F(SuggestionChipViewTest, DarkAndLightTheme) {
// Focus the chip view and confirm that focus ring is rendered. // Focus the chip view and confirm that focus ring is rendered.
suggestion_chip_view->RequestFocus(); suggestion_chip_view->RequestFocus();
EXPECT_TRUE( EXPECT_TRUE(cc::ExactPixelComparator().Compare(
cc::ExactPixelComparator(/*discard_alpha=*/false)
.Compare(
GetFocusRingBitmap(views::FocusRing::Get(suggestion_chip_view)), GetFocusRingBitmap(views::FocusRing::Get(suggestion_chip_view)),
GetBitmapWithInnerRoundedRect( GetBitmapWithInnerRoundedRect(
kSuggestionChipViewSize, /*stroke_width=*/2, kSuggestionChipViewSize, /*stroke_width=*/2,

@@ -972,9 +972,7 @@ TEST_F(SavedDeskTest, SaveDeskButtonFocusRingColor) {
// Verify the focus ring of the given button is as expected. // Verify the focus ring of the given button is as expected.
auto verify_button_focus_ring_color = [this](SavedDeskSaveDeskButton* button, auto verify_button_focus_ring_color = [this](SavedDeskSaveDeskButton* button,
bool highlighted) { bool highlighted) {
EXPECT_EQ( EXPECT_EQ(cc::ExactPixelComparator().Compare(
cc::ExactPixelComparator(/*discard_alpha=*/false)
.Compare(
GetFocusRingBitmap(views::FocusRing::Get(button)), GetFocusRingBitmap(views::FocusRing::Get(button)),
GetBitmapWithInnerRoundedRect( GetBitmapWithInnerRoundedRect(
views::FocusRing::Get(button)->size(), views::FocusRing::Get(button)->size(),

@@ -278,10 +278,10 @@ class OopPixelTest : public testing::Test,
} }
// Verifies |actual| matches the expected PNG image. // Verifies |actual| matches the expected PNG image.
void ExpectEquals(const SkBitmap& actual, void ExpectEquals(
const SkBitmap& actual,
const base::FilePath::StringType& ref_filename, const base::FilePath::StringType& ref_filename,
const PixelComparator& comparator = const PixelComparator& comparator = ExactPixelComparator()) {
ExactPixelComparator(/*discard_alpha=*/false)) {
base::FilePath test_data_dir; base::FilePath test_data_dir;
ASSERT_TRUE( ASSERT_TRUE(
base::PathService::Get(viz::Paths::DIR_TEST_DATA, &test_data_dir)); base::PathService::Get(viz::Paths::DIR_TEST_DATA, &test_data_dir));
@@ -296,10 +296,10 @@ class OopPixelTest : public testing::Test,
} }
} }
void ExpectEquals(SkBitmap actual, void ExpectEquals(
SkBitmap actual,
SkBitmap expected, SkBitmap expected,
const PixelComparator& comparator = const PixelComparator& comparator = ExactPixelComparator()) {
ExactPixelComparator(/*discard_alpha=*/false)) {
EXPECT_TRUE(MatchesBitmap(actual, expected, comparator)); EXPECT_TRUE(MatchesBitmap(actual, expected, comparator));
} }
@@ -611,9 +611,9 @@ TEST_F(OopPixelTest, DrawImageWithTargetColorSpace) {
#if BUILDFLAG(IS_ANDROID) #if BUILDFLAG(IS_ANDROID)
// Android has slight differences in color. // Android has slight differences in color.
FuzzyPixelOffByOneComparator comparator(/*discard_alpha=*/false); FuzzyPixelOffByOneComparator comparator;
#else #else
ExactPixelComparator comparator(/*discard_alpha=*/false); ExactPixelComparator comparator;
#endif #endif
ExpectEquals(actual, FILE_PATH_LITERAL("oop_image_target_color_space.png"), ExpectEquals(actual, FILE_PATH_LITERAL("oop_image_target_color_space.png"),
@@ -738,15 +738,12 @@ TEST_F(OopPixelTest, DrawImageWithSourceColorSpace) {
#if BUILDFLAG(IS_ANDROID) #if BUILDFLAG(IS_ANDROID)
// Android has slight differences in color. // Android has slight differences in color.
FuzzyPixelComparator comparator( auto comparator = FuzzyPixelComparator()
/*discard_alpha=*/false, .SetErrorPixelsPercentageLimit(100.0f)
/*error_pixels_percentage_limit=*/100.0f, .SetAvgAbsErrorLimit(1.2f)
/*small_error_pixels_percentage_limit=*/0.0f, .SetAbsErrorLimit(2);
/*avg_abs_error_limit=*/1.2f,
/*max_abs_error_limit=*/2,
/*small_error_threshold=*/0);
#else #else
ExactPixelComparator comparator(/*discard_alpha=*/false); ExactPixelComparator comparator;
#endif #endif
ExpectEquals(actual, ExpectEquals(actual,
@@ -783,9 +780,9 @@ TEST_F(OopPixelTest, DrawImageWithSourceAndTargetColorSpace) {
#if BUILDFLAG(IS_ANDROID) #if BUILDFLAG(IS_ANDROID)
// Android has slight differences in color. // Android has slight differences in color.
FuzzyPixelOffByOneComparator comparator(/*discard_alpha=*/false); FuzzyPixelOffByOneComparator comparator;
#else #else
ExactPixelComparator comparator(/*discard_alpha=*/false); ExactPixelComparator comparator;
#endif #endif
ExpectEquals(actual, FILE_PATH_LITERAL("oop_draw_image_both_color_space.png"), ExpectEquals(actual, FILE_PATH_LITERAL("oop_draw_image_both_color_space.png"),
@@ -1521,7 +1518,7 @@ TEST_F(OopPixelTest, DrawRectQueryMiddleOfDisplayList) {
auto actual = Raster(display_item_list, options); auto actual = Raster(display_item_list, options);
ExpectEquals(actual, FILE_PATH_LITERAL("oop_draw_rect_query.png"), ExpectEquals(actual, FILE_PATH_LITERAL("oop_draw_rect_query.png"),
FuzzyPixelOffByOneComparator(/*discard_alpha=*/false)); FuzzyPixelOffByOneComparator());
} }
TEST_F(OopPixelTest, DrawRectColorSpace) { TEST_F(OopPixelTest, DrawRectColorSpace) {
@@ -1704,13 +1701,11 @@ class OopTextBlobPixelTest
} }
} }
FuzzyPixelComparator comparator( auto comparator =
/*discard_alpha=*/false, FuzzyPixelComparator()
/*error_pixels_percentage_limit=*/error_pixels_percentage, .SetErrorPixelsPercentageLimit(error_pixels_percentage)
/*small_error_pixels_percentage_limit=*/0.0f, .SetAvgAbsErrorLimit(avg_error)
/*avg_abs_error_limit=*/avg_error, .SetAbsErrorLimit(max_abs_error);
/*max_abs_error_limit=*/max_abs_error,
/*small_error_threshold=*/0);
ExpectEquals(actual, expected, comparator); ExpectEquals(actual, expected, comparator);
} }
@@ -2132,13 +2127,9 @@ TEST_F(OopPixelTest, DrawTextBlobPersistentShaderCache) {
// Allow 1% of pixels to be off by 1 due to differences between software and // Allow 1% of pixels to be off by 1 due to differences between software and
// GPU canvas. // GPU canvas.
FuzzyPixelComparator comparator( auto comparator = FuzzyPixelComparator()
/*discard_alpha=*/false, .SetErrorPixelsPercentageLimit(1.0f)
/*error_pixels_percentage_limit=*/1.0f, .SetAbsErrorLimit(1);
/*small_error_pixels_percentage_limit=*/0.0f,
/*avg_abs_error_limit=*/1.0f,
/*max_abs_error_limit=*/1,
/*small_error_threshold=*/0);
ExpectEquals(actual, expected, comparator); ExpectEquals(actual, expected, comparator);
@@ -2325,13 +2316,9 @@ TEST_P(OopYUVToRGBPixelTest, ConvertYUVToRGB) {
options.resource_size, SkColor4f::FromColor(expected_color)); options.resource_size, SkColor4f::FromColor(expected_color));
// Allow slight rounding error on all pixels. // Allow slight rounding error on all pixels.
FuzzyPixelComparator comparator( auto comparator = FuzzyPixelComparator()
/*discard_alpha=*/false, .SetErrorPixelsPercentageLimit(100.0f)
/*error_pixels_percentage_limit=*/100.0f, .SetAbsErrorLimit(2);
/*small_error_pixels_percentage_limit=*/0.0f,
/*avg_abs_error_limit=*/2.f,
/*max_abs_error_limit=*/2.f,
/*small_error_threshold=*/0);
ExpectEquals(actual_bitmap, expected_bitmap, comparator); ExpectEquals(actual_bitmap, expected_bitmap, comparator);
gpu::SyncToken sync_token; gpu::SyncToken sync_token;
@@ -2445,14 +2432,9 @@ class OopPathPixelTest : public OopPixelTest,
display_item_list->Finalize(); display_item_list->Finalize();
// Allow 8 pixels in 100x100 image to be different due to non-AA pixel // Allow 8 pixels in 100x100 image to be different due to non-AA pixel
// rounding (hence 255 for error limit). // rounding.
FuzzyPixelComparator comparator( auto comparator =
/*discard_alpha=*/false, FuzzyPixelComparator().SetErrorPixelsPercentageLimit(0.08f);
/*error_pixels_percentage_limit=*/0.08f,
/*small_error_pixels_percentage_limit=*/0.0f,
/*avg_abs_error_limit=*/255,
/*max_abs_error_limit=*/255,
/*small_error_threshold=*/0);
auto actual = Raster(display_item_list, options); auto actual = Raster(display_item_list, options);
ExpectEquals(actual, FILE_PATH_LITERAL("oop_path.png"), comparator); ExpectEquals(actual, FILE_PATH_LITERAL("oop_path.png"), comparator);
} }

@@ -56,7 +56,8 @@ TestRasterType GetDefaultRasterType(viz::RendererType renderer_type) {
LayerTreePixelTest::LayerTreePixelTest(viz::RendererType renderer_type) LayerTreePixelTest::LayerTreePixelTest(viz::RendererType renderer_type)
: LayerTreeTest(renderer_type), : LayerTreeTest(renderer_type),
raster_type_(GetDefaultRasterType(renderer_type)), raster_type_(GetDefaultRasterType(renderer_type)),
pixel_comparator_(new ExactPixelComparator(true)), pixel_comparator_(
std::make_unique<AlphaDiscardingExactPixelComparator>()),
pending_texture_mailbox_callbacks_(0) {} pending_texture_mailbox_callbacks_(0) {}
LayerTreePixelTest::~LayerTreePixelTest() = default; LayerTreePixelTest::~LayerTreePixelTest() = default;

@@ -14,10 +14,6 @@
namespace cc { namespace cc {
ExactPixelComparator::ExactPixelComparator(const bool discard_alpha)
: discard_alpha_(discard_alpha) {
}
bool ExactPixelComparator::Compare(const SkBitmap& actual_bmp, bool ExactPixelComparator::Compare(const SkBitmap& actual_bmp,
const SkBitmap& expected_bmp) const { const SkBitmap& expected_bmp) const {
// Number of pixels with an error // Number of pixels with an error
@@ -92,27 +88,21 @@ bool ManhattanDistancePixelComparator::Compare(
return true; return true;
} }
FuzzyPixelComparator::FuzzyPixelComparator(
bool discard_alpha,
float error_pixels_percentage_limit,
float small_error_pixels_percentage_limit,
float avg_abs_error_limit,
int max_abs_error_limit,
int small_error_threshold,
bool check_critical_error)
: discard_alpha_(discard_alpha),
error_pixels_percentage_limit_(error_pixels_percentage_limit),
small_error_pixels_percentage_limit_(small_error_pixels_percentage_limit),
avg_abs_error_limit_(avg_abs_error_limit),
max_abs_error_limit_(max_abs_error_limit),
small_error_threshold_(small_error_threshold),
check_critical_error_(check_critical_error) {}
bool FuzzyPixelComparator::Compare(const SkBitmap& actual_bmp, bool FuzzyPixelComparator::Compare(const SkBitmap& actual_bmp,
const SkBitmap& expected_bmp) const { const SkBitmap& expected_bmp) const {
// Number of pixels with an error // Check that bitmaps have identical dimensions.
DCHECK_EQ(actual_bmp.width(), expected_bmp.width());
DCHECK_EQ(actual_bmp.height(), expected_bmp.height());
// Check that bitmaps are not empty.
DCHECK_GT(actual_bmp.width(), 0);
DCHECK_GT(actual_bmp.height(), 0);
DCHECK_GE(max_abs_error_limit_, small_abs_error_limit_);
// Number of pixels with an error.
int error_pixels_count = 0; int error_pixels_count = 0;
// Number of pixels with a small error // Number of pixels with a small error.
int small_error_pixels_count = 0; int small_error_pixels_count = 0;
// Number of pixels with a critical error. // Number of pixels with a critical error.
int critial_error_pixels_count = 0; int critial_error_pixels_count = 0;
@@ -129,14 +119,6 @@ bool FuzzyPixelComparator::Compare(const SkBitmap& actual_bmp,
gfx::Rect error_bounding_rect = gfx::Rect(); gfx::Rect error_bounding_rect = gfx::Rect();
// Check that bitmaps have identical dimensions.
DCHECK_EQ(actual_bmp.width(), expected_bmp.width());
DCHECK_EQ(actual_bmp.height(), expected_bmp.height());
// Check that bitmaps are not empty.
DCHECK_GT(actual_bmp.width(), 0);
DCHECK_GT(actual_bmp.height(), 0);
for (int x = 0; x < actual_bmp.width(); ++x) { for (int x = 0; x < actual_bmp.width(); ++x) {
for (int y = 0; y < actual_bmp.height(); ++y) { for (int y = 0; y < actual_bmp.height(); ++y) {
SkColor actual_color = actual_bmp.getColor(x, y); SkColor actual_color = actual_bmp.getColor(x, y);
@@ -161,15 +143,18 @@ bool FuzzyPixelComparator::Compare(const SkBitmap& actual_bmp,
int abs_error_a = std::abs(error_a); int abs_error_a = std::abs(error_a);
// Increment small error counter if error is below threshold // Increment small error counter if error is below threshold
if (abs_error_r <= small_error_threshold_ && if (abs_error_r <= small_abs_error_limit_ &&
abs_error_g <= small_error_threshold_ && abs_error_g <= small_abs_error_limit_ &&
abs_error_b <= small_error_threshold_ && abs_error_b <= small_abs_error_limit_ &&
abs_error_a <= small_error_threshold_) abs_error_a <= small_abs_error_limit_) {
++small_error_pixels_count; ++small_error_pixels_count;
}
if (check_critical_error_ && abs_error_a != 0 && if (abs_error_a != 0 &&
(expected_alpha == 0 || expected_alpha == 0xff)) (expected_alpha == 0 || expected_alpha == 0xff)) {
DCHECK(!discard_alpha_);
++critial_error_pixels_count; ++critial_error_pixels_count;
}
// Update per channel maximum absolute errors // Update per channel maximum absolute errors
max_abs_error_r = std::max(max_abs_error_r, abs_error_r); max_abs_error_r = std::max(max_abs_error_r, abs_error_r);
@@ -188,14 +173,16 @@ bool FuzzyPixelComparator::Compare(const SkBitmap& actual_bmp,
// Compute error metrics from collected data // Compute error metrics from collected data
int pixels_count = actual_bmp.width() * actual_bmp.height(); int pixels_count = actual_bmp.width() * actual_bmp.height();
float error_pixels_percentage = 0.0f; DCHECK(pixels_count);
float large_error_pixels_percentage = 0.0f;
float small_error_pixels_percentage = 0.0f; float small_error_pixels_percentage = 0.0f;
if (pixels_count > 0) { int large_error_pixels_count = error_pixels_count - small_error_pixels_count;
error_pixels_percentage = static_cast<float>(error_pixels_count) / large_error_pixels_percentage =
pixels_count * 100.0f; static_cast<float>(large_error_pixels_count) / pixels_count * 100.0f;
small_error_pixels_percentage = small_error_pixels_percentage =
static_cast<float>(small_error_pixels_count) / pixels_count * 100.0f; static_cast<float>(small_error_pixels_count) / pixels_count * 100.0f;
}
float avg_abs_error_r = 0.0f; float avg_abs_error_r = 0.0f;
float avg_abs_error_g = 0.0f; float avg_abs_error_g = 0.0f;
float avg_abs_error_b = 0.0f; float avg_abs_error_b = 0.0f;
@@ -207,7 +194,7 @@ bool FuzzyPixelComparator::Compare(const SkBitmap& actual_bmp,
avg_abs_error_a = static_cast<float>(sum_abs_error_a) / error_pixels_count; avg_abs_error_a = static_cast<float>(sum_abs_error_a) / error_pixels_count;
} }
if (error_pixels_percentage > error_pixels_percentage_limit_ || if (large_error_pixels_percentage > large_error_pixels_percentage_limit_ ||
small_error_pixels_percentage > small_error_pixels_percentage_limit_ || small_error_pixels_percentage > small_error_pixels_percentage_limit_ ||
avg_abs_error_r > avg_abs_error_limit_ || avg_abs_error_r > avg_abs_error_limit_ ||
avg_abs_error_g > avg_abs_error_limit_ || avg_abs_error_g > avg_abs_error_limit_ ||
@@ -217,11 +204,17 @@ bool FuzzyPixelComparator::Compare(const SkBitmap& actual_bmp,
max_abs_error_g > max_abs_error_limit_ || max_abs_error_g > max_abs_error_limit_ ||
max_abs_error_b > max_abs_error_limit_ || max_abs_error_b > max_abs_error_limit_ ||
max_abs_error_a > max_abs_error_limit_ || critial_error_pixels_count) { max_abs_error_a > max_abs_error_limit_ || critial_error_pixels_count) {
LOG(ERROR) << "Percentage of pixels with an error: " if (small_abs_error_limit_) {
<< error_pixels_percentage; LOG(ERROR) << "Percentage of pixels with errors >"
LOG(ERROR) << "Percentage of pixels with errors not greater than " << small_abs_error_limit_ << ": "
<< small_error_threshold_ << ": " << large_error_pixels_percentage;
LOG(ERROR) << "Percentage of pixels with errors <="
<< small_abs_error_limit_ << ": "
<< small_error_pixels_percentage; << small_error_pixels_percentage;
} else {
LOG(ERROR) << "Percentage of pixels with an error: "
<< large_error_pixels_percentage;
}
LOG(ERROR) << "Average absolute error (excluding identical pixels): " LOG(ERROR) << "Average absolute error (excluding identical pixels): "
<< "R=" << avg_abs_error_r << " " << "R=" << avg_abs_error_r << " "
<< "G=" << avg_abs_error_g << " " << "G=" << avg_abs_error_g << " "
@@ -232,7 +225,7 @@ bool FuzzyPixelComparator::Compare(const SkBitmap& actual_bmp,
<< "G=" << max_abs_error_g << " " << "G=" << max_abs_error_g << " "
<< "B=" << max_abs_error_b << " " << "B=" << max_abs_error_b << " "
<< "A=" << max_abs_error_a; << "A=" << max_abs_error_a;
LOG(ERROR) << "Critical error: " << critial_error_pixels_count; LOG(ERROR) << "Critical errors: " << critial_error_pixels_count;
for (int x = 0; x < actual_bmp.width(); ++x) { for (int x = 0; x < actual_bmp.width(); ++x) {
for (int y = 0; y < actual_bmp.height(); ++y) { for (int y = 0; y < actual_bmp.height(); ++y) {

@@ -22,18 +22,19 @@ class PixelComparator {
// Exact pixel comparator. Counts the number of pixel with an error. // Exact pixel comparator. Counts the number of pixel with an error.
class ExactPixelComparator : public PixelComparator { class ExactPixelComparator : public PixelComparator {
public: public:
explicit ExactPixelComparator(const bool discard_alpha);
~ExactPixelComparator() override = default;
// Returns true if the two bitmaps are identical. Otherwise, returns false // Returns true if the two bitmaps are identical. Otherwise, returns false
// and report the number of pixels with an error on LOG(ERROR). Differences // and report the number of pixels with an error on LOG(ERROR).
// in the alpha channel are ignored.
bool Compare(const SkBitmap& actual_bmp, bool Compare(const SkBitmap& actual_bmp,
const SkBitmap& expected_bmp) const override; const SkBitmap& expected_bmp) const override;
private: protected:
// Exclude alpha channel from comparison? // Exclude alpha channel from comparison?
bool discard_alpha_; bool discard_alpha_ = false;
};
class AlphaDiscardingExactPixelComparator : public ExactPixelComparator {
public:
AlphaDiscardingExactPixelComparator() { discard_alpha_ = true; }
}; };
// Different platforms have slightly different pixel output, due to different // Different platforms have slightly different pixel output, due to different
@@ -58,49 +59,83 @@ class ManhattanDistancePixelComparator : public PixelComparator {
}; };
// Fuzzy pixel comparator. Counts small and arbitrary errors separately and // Fuzzy pixel comparator. Counts small and arbitrary errors separately and
// computes average and maximum absolute errors per color channel. // computes average and maximum absolute errors per color channel. It can be
// configured to discard alpha channel. If alpha channel is not discarded
// (by default), alpha changing among fully transparent, translucent and fully
// opaque (e.g. 0 to 1, 254 to 255) are always reported.
class FuzzyPixelComparator : public PixelComparator { class FuzzyPixelComparator : public PixelComparator {
public: public:
FuzzyPixelComparator(bool discard_alpha, FuzzyPixelComparator& DiscardAlpha() {
float error_pixels_percentage_limit, discard_alpha_ = true;
float small_error_pixels_percentage_limit, return *this;
float avg_abs_error_limit, }
int max_abs_error_limit, // Sets the limits for percentages of pixels with errors:
int small_error_threshold, // - large errors: >small_abs_error_limit_,
bool check_critical_error = true); // - small errors: >0 and <= small_abs_error_limit_.
~FuzzyPixelComparator() override = default; // If small_abs_error_limit_ is zero (by default),
// `large_error_pixels_percentage_limit` is for all errors.
FuzzyPixelComparator& SetErrorPixelsPercentageLimit(
float large_error_pixels_percentage_limit,
float small_error_pixels_percentage_limit = 0) {
large_error_pixels_percentage_limit_ = large_error_pixels_percentage_limit;
small_error_pixels_percentage_limit_ = small_error_pixels_percentage_limit;
return *this;
}
// Sets limit for average absolute error (excluding identical pixels).
// The default is 255.0, which means it's not checked.
FuzzyPixelComparator& SetAvgAbsErrorLimit(float avg_abs_error_limit) {
avg_abs_error_limit_ = avg_abs_error_limit;
return *this;
}
// Sets limits of the largest absolute error and the small absolute error.
// The default of `max_abs_error_limit` is 255, which means it's not checked
// by default. The default of `small_abs_eror_limit` is 0, which means all
// errors are treated as large errors by default.
FuzzyPixelComparator& SetAbsErrorLimit(int max_abs_error_limit,
int small_abs_error_limit = 0) {
max_abs_error_limit_ = max_abs_error_limit;
small_abs_error_limit_ = small_abs_error_limit;
return *this;
}
// Computes error metrics and returns true if the errors don't exceed the // Computes error metrics and returns true if the errors don't exceed the
// specified limits. Otherwise, returns false and reports the error metrics on // specified limits. Otherwise, returns false and reports the error metrics on
// LOG(ERROR). Differences in the alpha channel are ignored. // LOG(ERROR).
bool Compare(const SkBitmap& actual_bmp, bool Compare(const SkBitmap& actual_bmp,
const SkBitmap& expected_bmp) const override; const SkBitmap& expected_bmp) const override;
private: private:
// Exclude alpha channel from comparison? // Exclude alpha channel from comparison?
bool discard_alpha_; bool discard_alpha_ = false;
// Limit for percentage of pixels with an error. float large_error_pixels_percentage_limit_ = 0;
float error_pixels_percentage_limit_; // Limit for percentage of pixels with a small error
// Limit for percentage of pixels with a small error. // (>0 and <= small_abs_error_limit_).
float small_error_pixels_percentage_limit_; float small_error_pixels_percentage_limit_ = 0;
// Limit for average absolute error (excluding identical pixels). float avg_abs_error_limit_ = 255.0;
float avg_abs_error_limit_; int max_abs_error_limit_ = 255;
// Limit for largest absolute error. int small_abs_error_limit_ = 0;
int max_abs_error_limit_;
// Threshold for small errors.
int small_error_threshold_;
// If true, comparator will report critical errors. For example:
// alpha value goes from 0 to 1 or 256 to 255.
bool check_critical_error_;
}; };
// All pixels can be off by one, but any more than that is an error. // All pixels can be off by one, but any more than that is an error.
class FuzzyPixelOffByOneComparator : public FuzzyPixelComparator { class FuzzyPixelOffByOneComparator : public FuzzyPixelComparator {
public: public:
explicit FuzzyPixelOffByOneComparator(bool discard_alpha) FuzzyPixelOffByOneComparator() {
: FuzzyPixelComparator(discard_alpha, 100.f, 0.f, 1.f, 1, 0) {} SetErrorPixelsPercentageLimit(100.f);
SetAbsErrorLimit(1);
}
protected:
using FuzzyPixelComparator::DiscardAlpha;
using FuzzyPixelComparator::SetAbsErrorLimit;
using FuzzyPixelComparator::SetAvgAbsErrorLimit;
using FuzzyPixelComparator::SetErrorPixelsPercentageLimit;
}; };
class AlphaDiscardingFuzzyPixelOffByOneComparator
: public FuzzyPixelOffByOneComparator {
public:
AlphaDiscardingFuzzyPixelOffByOneComparator() { DiscardAlpha(); }
};
} // namespace cc } // namespace cc
#endif // CC_TEST_PIXEL_COMPARATOR_H_ #endif // CC_TEST_PIXEL_COMPARATOR_H_

@@ -72,7 +72,8 @@ class LayerTreeHostBlendingPixelTest
LayerTreeHostBlendingPixelTest() LayerTreeHostBlendingPixelTest()
: LayerTreeHostPixelResourceTest(resource_type()), : LayerTreeHostPixelResourceTest(resource_type()),
force_antialiasing_(false) { force_antialiasing_(false) {
pixel_comparator_ = std::make_unique<FuzzyPixelOffByOneComparator>(true); pixel_comparator_ =
std::make_unique<AlphaDiscardingFuzzyPixelOffByOneComparator>();
} }
RasterTestConfig resource_type() const { RasterTestConfig resource_type() const {
@@ -224,17 +225,10 @@ class LayerTreeHostBlendingPixelTest
if (renderer_type_ == viz::RendererType::kSkiaVk) { if (renderer_type_ == viz::RendererType::kSkiaVk) {
// Blending results might differ with one pixel. // Blending results might differ with one pixel.
float percentage_pixels_error = 35.f;
float percentage_pixels_small_error = 0.f;
float average_error_allowed_in_bad_pixels = 1.f;
int large_error_allowed = 1;
int small_error_allowed = 0;
pixel_comparator_ = std::make_unique<FuzzyPixelComparator>( pixel_comparator_ = std::make_unique<FuzzyPixelComparator>(
false, // discard_alpha FuzzyPixelComparator()
percentage_pixels_error, percentage_pixels_small_error, .SetErrorPixelsPercentageLimit(35.f)
average_error_allowed_in_bad_pixels, large_error_allowed, .SetAbsErrorLimit(1));
small_error_allowed);
} }
RunPixelResourceTest(root, CreateBlendingWithRenderPassExpected( RunPixelResourceTest(root, CreateBlendingWithRenderPassExpected(

@@ -111,16 +111,11 @@ TEST_P(LayerTreeHostFiltersPixelTest, BackdropFilterBlurRect) {
#if BUILDFLAG(IS_WIN) || defined(ARCH_CPU_ARM64) #if BUILDFLAG(IS_WIN) || defined(ARCH_CPU_ARM64)
// Windows and ARM64 have 436 pixels off by 1: crbug.com/259915 // Windows and ARM64 have 436 pixels off by 1: crbug.com/259915
float percentage_pixels_large_error = 1.09f; // 436px / (200*200)
float percentage_pixels_small_error = 0.0f;
float average_error_allowed_in_bad_pixels = 1.f;
int large_error_allowed = 1;
int small_error_allowed = 0;
pixel_comparator_ = std::make_unique<FuzzyPixelComparator>( pixel_comparator_ = std::make_unique<FuzzyPixelComparator>(
true, // discard_alpha FuzzyPixelComparator()
percentage_pixels_large_error, percentage_pixels_small_error, .DiscardAlpha()
average_error_allowed_in_bad_pixels, large_error_allowed, .SetErrorPixelsPercentageLimit(1.09f) // 436px / (200*200)
small_error_allowed); .SetAbsErrorLimit(1));
#endif #endif
RunPixelTest(background, RunPixelTest(background,
@@ -176,22 +171,20 @@ TEST_P(LayerTreeHostFiltersPixelTest, BackdropFilterBlurRadius) {
blur->SetBackdropFilterBounds(backdrop_filter_bounds); blur->SetBackdropFilterBounds(backdrop_filter_bounds);
#if BUILDFLAG(IS_FUCHSIA) #if BUILDFLAG(IS_FUCHSIA)
pixel_comparator_ = std::make_unique<FuzzyPixelOffByOneComparator>(false); pixel_comparator_ = std::make_unique<FuzzyPixelOffByOneComparator>();
#elif BUILDFLAG(IS_WIN) || defined(ARCH_CPU_ARM64) #elif BUILDFLAG(IS_WIN) || defined(ARCH_CPU_ARM64)
// Windows and ARM64 have 436 pixels off by 1: crbug.com/259915 // Windows and ARM64 have 436 pixels off by 1 or 2: crbug.com/259915
float percentage_pixels_large_error = 1.09f; // 436px / (200*200) float percentage_pixels_error = 1.09f; // 436px / (200*200)
float percentage_pixels_small_error = 0.0f;
float average_error_allowed_in_bad_pixels = 1.f;
int large_error_allowed = 2;
int small_error_allowed = 0;
// Windows using Dawn D3D12 has 4044 pixels off by max of 2. // Windows using Dawn D3D12 has 4044 pixels off by max of 2.
if (use_d3d12()) if (use_d3d12()) {
percentage_pixels_large_error = 2.5275f; // 4044px / (400*400) percentage_pixels_error = 2.5275f; // 4044px / (400*400)
}
pixel_comparator_ = std::make_unique<FuzzyPixelComparator>( pixel_comparator_ = std::make_unique<FuzzyPixelComparator>(
true, // discard_alpha FuzzyPixelComparator()
percentage_pixels_large_error, percentage_pixels_small_error, .DiscardAlpha()
average_error_allowed_in_bad_pixels, large_error_allowed, .SetErrorPixelsPercentageLimit(percentage_pixels_error)
small_error_allowed); .SetAvgAbsErrorLimit(1.f)
.SetAbsErrorLimit(2));
#endif #endif
RunPixelTest( RunPixelTest(
background, background,
@@ -228,15 +221,16 @@ TEST_P(LayerTreeHostFiltersPixelTest, BackdropFilterBlurRounded) {
// Allow for ~1 perimeter of the clip path to have a small error. // Allow for ~1 perimeter of the clip path to have a small error.
float percentage_pixels_small_error = 100.f * (100*4) / (200*200); float percentage_pixels_small_error = 100.f * (100*4) / (200*200);
int large_error_limit = 128; // Off by two samples in 4 MSAA. int large_error_limit = 128; // Off by two samples in 4 MSAA.
float percentage_pixels_large_or_small_error = float percentage_pixels_large_error = 0.01f * percentage_pixels_small_error;
1.01f * percentage_pixels_small_error;
// Divide average error by 4 since we blur most of the result. // Divide average error by 4 since we blur most of the result.
float average_error_allowed_in_bad_pixels = small_error_threshold / 4.f; float average_error_allowed_in_bad_pixels = small_error_threshold / 4.f;
pixel_comparator_ = std::make_unique<FuzzyPixelComparator>( pixel_comparator_ = std::make_unique<FuzzyPixelComparator>(
true, // discard_alpha FuzzyPixelComparator()
percentage_pixels_large_or_small_error, percentage_pixels_small_error, .DiscardAlpha()
average_error_allowed_in_bad_pixels, large_error_limit, .SetErrorPixelsPercentageLimit(percentage_pixels_large_error,
small_error_threshold); percentage_pixels_small_error)
.SetAvgAbsErrorLimit(average_error_allowed_in_bad_pixels)
.SetAbsErrorLimit(large_error_limit, small_error_threshold));
RunPixelTest(background, use_software_renderer() RunPixelTest(background, use_software_renderer()
? base::FilePath(FILE_PATH_LITERAL( ? base::FilePath(FILE_PATH_LITERAL(
@@ -273,23 +267,21 @@ TEST_P(LayerTreeHostFiltersPixelTest, BackdropFilterBlurOutsets) {
#if BUILDFLAG(IS_WIN) || defined(_MIPS_ARCH_LOONGSON) || defined(ARCH_CPU_ARM64) #if BUILDFLAG(IS_WIN) || defined(_MIPS_ARCH_LOONGSON) || defined(ARCH_CPU_ARM64)
#if BUILDFLAG(IS_WIN) || defined(ARCH_CPU_ARM64) #if BUILDFLAG(IS_WIN) || defined(ARCH_CPU_ARM64)
// Windows has 5.9325% pixels by at most 2: crbug.com/259922 // Windows has 5.9325% pixels by at most 2: crbug.com/259922
float percentage_pixels_large_error = 6.0f; float percentage_pixels_error = 6.0f;
#else #else
// Loongson has 8.685% pixels by at most 2: crbug.com/819110 // Loongson has 8.685% pixels by at most 2: crbug.com/819110
float percentage_pixels_large_error = 8.7f; float percentage_pixels_error = 8.7f;
#endif #endif
float percentage_pixels_small_error = 0.0f;
float average_error_allowed_in_bad_pixels = 2.f;
int large_error_allowed = 2;
int small_error_allowed = 0;
pixel_comparator_ = std::make_unique<FuzzyPixelComparator>( pixel_comparator_ = std::make_unique<FuzzyPixelComparator>(
true, // discard_alpha FuzzyPixelComparator()
percentage_pixels_large_error, percentage_pixels_small_error, .DiscardAlpha()
average_error_allowed_in_bad_pixels, large_error_allowed, .SetErrorPixelsPercentageLimit(percentage_pixels_error)
small_error_allowed); .SetAbsErrorLimit(2));
#else #else
if (use_skia_vulkan()) if (use_skia_vulkan()) {
pixel_comparator_ = std::make_unique<FuzzyPixelOffByOneComparator>(true); pixel_comparator_ =
std::make_unique<AlphaDiscardingFuzzyPixelOffByOneComparator>();
}
#endif #endif
RunPixelTest( RunPixelTest(
@@ -383,26 +375,26 @@ TEST_P(LayerTreeHostBlurFiltersPixelTestGPULayerList,
#if BUILDFLAG(IS_WIN) || defined(ARCH_CPU_ARM64) #if BUILDFLAG(IS_WIN) || defined(ARCH_CPU_ARM64)
#if BUILDFLAG(IS_WIN) #if BUILDFLAG(IS_WIN)
// Windows has 116 pixels off by at most 2: crbug.com/225027 // Windows has 116 pixels off by at most 2: crbug.com/225027
float percentage_pixels_large_error = 0.3f; // 116px / (200*200), rounded up float percentage_pixels_error = 0.3f; // 116px / (200*200), rounded up
int large_error_allowed = 2; int error_allowed = 2;
// Windows on SkiaRenderer Dawn has 447 pixels off by at most 2. // Windows on SkiaRenderer Dawn has 447 pixels off by at most 2.
if (use_d3d12()) if (use_d3d12())
percentage_pixels_large_error = 1.12f; // 447px / (200*200), rounded up percentage_pixels_error = 1.12f; // 447px / (200*200), rounded up
#else #else
float percentage_pixels_large_error = 0.25f; // 96px / (200*200), rounded up float percentage_pixels_error = 0.25f; // 96px / (200*200), rounded up
int large_error_allowed = 1; int error_allowed = 1;
#endif #endif
float percentage_pixels_small_error = 0.0f;
float average_error_allowed_in_bad_pixels = 1.f; float average_error_allowed_in_bad_pixels = 1.f;
int small_error_allowed = 0;
pixel_comparator_ = std::make_unique<FuzzyPixelComparator>( pixel_comparator_ = std::make_unique<FuzzyPixelComparator>(
true, // discard_alpha FuzzyPixelComparator()
percentage_pixels_large_error, percentage_pixels_small_error, .DiscardAlpha()
average_error_allowed_in_bad_pixels, large_error_allowed, .SetErrorPixelsPercentageLimit(percentage_pixels_error)
small_error_allowed); .SetAvgAbsErrorLimit(average_error_allowed_in_bad_pixels)
.SetAbsErrorLimit(error_allowed));
#else #else
if (use_skia_vulkan() || renderer_type_ == viz::RendererType::kSkiaDawn) if (use_skia_vulkan() || renderer_type_ == viz::RendererType::kSkiaDawn)
pixel_comparator_ = std::make_unique<FuzzyPixelOffByOneComparator>(true); pixel_comparator_ =
std::make_unique<AlphaDiscardingFuzzyPixelOffByOneComparator>();
#endif #endif
RunPixelTestWithLayerList( RunPixelTestWithLayerList(
@@ -595,39 +587,37 @@ TEST_P(LayerTreeHostFiltersPixelTest, ImageFilterScaled) {
#if BUILDFLAG(IS_FUCHSIA) #if BUILDFLAG(IS_FUCHSIA)
if (renderer_type() == viz::RendererType::kSkiaVk) { if (renderer_type() == viz::RendererType::kSkiaVk) {
pixel_comparator_ = std::make_unique<FuzzyPixelOffByOneComparator>(false); pixel_comparator_ = std::make_unique<FuzzyPixelOffByOneComparator>();
} }
#elif BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_CHROMEOS) || \ #elif BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_CHROMEOS) || \
defined(_MIPS_ARCH_LOONGSON) || defined(ARCH_CPU_ARM64) defined(_MIPS_ARCH_LOONGSON) || defined(ARCH_CPU_ARM64)
#if BUILDFLAG(IS_WIN) #if BUILDFLAG(IS_WIN)
// Windows has 153 pixels off by at most 2: crbug.com/225027 // Windows has 153 pixels off by at most 2: crbug.com/225027
float percentage_pixels_large_error = 0.3825f; // 153px / (200*200) float percentage_pixels_error = 0.3825f; // 153px / (200*200)
int large_error_allowed = 2; int error_allowed = 2;
// Windows using Dawn D3D12 has 166 pixels off by 1. // Windows using Dawn D3D12 has 166 pixels off by 1.
if (use_d3d12()) { if (use_d3d12()) {
percentage_pixels_large_error = 0.415f; // 166px / (200*200) percentage_pixels_error = 0.415f; // 166px / (200*200)
large_error_allowed = 1; error_allowed = 1;
} }
#elif BUILDFLAG(IS_MAC) || BUILDFLAG(IS_CHROMEOS) #elif BUILDFLAG(IS_MAC) || BUILDFLAG(IS_CHROMEOS)
// There's a 1 pixel error on MacOS and ChromeOS // There's a 1 pixel error on MacOS and ChromeOS
float percentage_pixels_large_error = 0.0025f; // 1px / (200*200) float percentage_pixels_error = 0.0025f; // 1px / (200*200)
int large_error_allowed = 1; int error_allowed = 1;
#elif defined(_MIPS_ARCH_LOONGSON) #elif defined(_MIPS_ARCH_LOONGSON)
// Loongson has 2 pixels off by at most 2: crbug.com/819075 // Loongson has 2 pixels off by at most 2: crbug.com/819075
float percentage_pixels_large_error = 0.005f; // 2px / (200*200) float percentage_pixels_error = 0.005f; // 2px / (200*200)
int large_error_allowed = 2; int error_allowed = 2;
#else #else
float percentage_pixels_large_error = 0.0325f; // 13px / (200*200) float percentage_pixels_error = 0.0325f; // 13px / (200*200)
int large_error_allowed = 1; int error_allowed = 1;
#endif #endif
float percentage_pixels_small_error = 0.0f;
float average_error_allowed_in_bad_pixels = 1.f;
int small_error_allowed = 0;
pixel_comparator_ = std::make_unique<FuzzyPixelComparator>( pixel_comparator_ = std::make_unique<FuzzyPixelComparator>(
true, // discard_alpha FuzzyPixelComparator()
percentage_pixels_large_error, percentage_pixels_small_error, .DiscardAlpha()
average_error_allowed_in_bad_pixels, large_error_allowed, .SetErrorPixelsPercentageLimit(percentage_pixels_error)
small_error_allowed); .SetAvgAbsErrorLimit(1.f)
.SetAbsErrorLimit(error_allowed));
#endif #endif
RunPixelTest( RunPixelTest(
@@ -682,16 +672,11 @@ TEST_P(LayerTreeHostFiltersPixelTest, BackdropFilterRotated) {
// changes to blur or rectangle rendering. // changes to blur or rectangle rendering.
// Fuchsia/Flutter forces off the lowp skia raster pipeline resulting // Fuchsia/Flutter forces off the lowp skia raster pipeline resulting
// in a totally different code path for software rendering. // in a totally different code path for software rendering.
float percentage_pixels_large_error = 5.f;
float percentage_pixels_small_error = 0.0f;
float average_error_allowed_in_bad_pixels = 2.f;
int large_error_allowed = 2;
int small_error_allowed = 0;
pixel_comparator_ = std::make_unique<FuzzyPixelComparator>( pixel_comparator_ = std::make_unique<FuzzyPixelComparator>(
true, // discard_alpha FuzzyPixelComparator()
percentage_pixels_large_error, percentage_pixels_small_error, .DiscardAlpha()
average_error_allowed_in_bad_pixels, large_error_allowed, .SetErrorPixelsPercentageLimit(5.f)
small_error_allowed); .SetAbsErrorLimit(2));
RunPixelTest(background, RunPixelTest(background,
base::FilePath(FILE_PATH_LITERAL("backdrop_filter_rotated_.png")) base::FilePath(FILE_PATH_LITERAL("backdrop_filter_rotated_.png"))
@@ -728,27 +713,27 @@ TEST_P(LayerTreeHostFiltersPixelTest, ImageRenderSurfaceScaled) {
background->AddChild(render_surface_layer); background->AddChild(render_surface_layer);
float percentage_pixels_large_error = 0.0f; float percentage_pixels_error = 0.0f;
float percentage_pixels_small_error = 0.0f;
float average_error_allowed_in_bad_pixels = 0.0f; float average_error_allowed_in_bad_pixels = 0.0f;
int large_error_allowed = 0; int error_allowed = 0;
int small_error_allowed = 0;
if (use_software_renderer()) { if (use_software_renderer()) {
// Software has some huge differences in the AA'd pixels on the different // Software has some huge differences in the AA'd pixels on the different
// trybots. See crbug.com/452198. // trybots. See crbug.com/452198.
percentage_pixels_large_error = 0.686f; percentage_pixels_error = 0.686f;
average_error_allowed_in_bad_pixels = 16.f; average_error_allowed_in_bad_pixels = 16.f;
large_error_allowed = 17; error_allowed = 17;
} else if (use_d3d12()) { } else if (use_d3d12()) {
// Windows using Dawn D3D12 has 25 pixels off by 1. // Windows using Dawn D3D12 has 25 pixels off by 1.
percentage_pixels_large_error = 0.028; percentage_pixels_error = 0.028;
average_error_allowed_in_bad_pixels = 1.f; average_error_allowed_in_bad_pixels = 1.f;
large_error_allowed = 1; error_allowed = 1;
} }
pixel_comparator_ = std::make_unique<FuzzyPixelComparator>( pixel_comparator_ = std::make_unique<FuzzyPixelComparator>(
/*discard_alpha=*/true, percentage_pixels_large_error, FuzzyPixelComparator()
percentage_pixels_small_error, average_error_allowed_in_bad_pixels, .DiscardAlpha()
large_error_allowed, small_error_allowed); .SetErrorPixelsPercentageLimit(percentage_pixels_error)
.SetAvgAbsErrorLimit(average_error_allowed_in_bad_pixels)
.SetAbsErrorLimit(error_allowed));
RunPixelTest( RunPixelTest(
background, background,
@@ -808,16 +793,11 @@ TEST_P(LayerTreeHostFiltersPixelTest, ZoomFilter) {
#if BUILDFLAG(IS_WIN) #if BUILDFLAG(IS_WIN)
// Windows has 1 pixel off by 1: crbug.com/259915 // Windows has 1 pixel off by 1: crbug.com/259915
float percentage_pixels_large_error = 0.00111112f; // 1px / (300*300)
float percentage_pixels_small_error = 0.0f;
float average_error_allowed_in_bad_pixels = 1.f;
int large_error_allowed = 1;
int small_error_allowed = 0;
pixel_comparator_ = std::make_unique<FuzzyPixelComparator>( pixel_comparator_ = std::make_unique<FuzzyPixelComparator>(
true, // discard_alpha FuzzyPixelComparator()
percentage_pixels_large_error, percentage_pixels_small_error, .DiscardAlpha()
average_error_allowed_in_bad_pixels, large_error_allowed, .SetErrorPixelsPercentageLimit(0.00111112f) // 1px / (300*300)
small_error_allowed); .SetAbsErrorLimit(1));
#endif #endif
RunPixelTest(std::move(root), RunPixelTest(std::move(root),
@@ -851,29 +831,28 @@ TEST_P(LayerTreeHostFiltersPixelTest, RotatedFilter) {
#if defined(ARCH_CPU_ARM64) #if defined(ARCH_CPU_ARM64)
// Windows, macOS, and Fuchsia on ARM64 has some pixels difference // Windows, macOS, and Fuchsia on ARM64 has some pixels difference
// crbug.com/1029728, crbug.com/1048249, crbug.com/1128443 // crbug.com/1029728, crbug.com/1048249, crbug.com/1128443
float percentage_pixels_large_error = 1.f; float percentage_pixels_error = 1.f;
float average_error_allowed_in_bad_pixels = 2.f; float average_error_allowed_in_bad_pixels = 2.f;
int large_error_allowed = 3; int error_allowed = 3;
#elif BUILDFLAG(IS_WIN) #elif BUILDFLAG(IS_WIN)
// Windows has 1 pixel off by 1: crbug.com/259915 // Windows has 1 pixel off by 1: crbug.com/259915
float percentage_pixels_large_error = 0.00111112f; // 1px / (300*300) float percentage_pixels_error = 0.00111112f; // 1px / (300*300)
float average_error_allowed_in_bad_pixels = 1.f; float average_error_allowed_in_bad_pixels = 1.f;
int large_error_allowed = 1; int error_allowed = 1;
// Windows using Dawn D3D12 has 104 pixels off by 1. // Windows using Dawn D3D12 has 104 pixels off by 1.
if (use_d3d12()) if (use_d3d12())
percentage_pixels_large_error = 0.115556f; // 104px / (300*300) percentage_pixels_error = 0.115556f; // 104px / (300*300)
#else #else
float percentage_pixels_large_error = 0.0f; // 1px / (300*300) float percentage_pixels_error = 0.0f; // 1px / (300*300)
float average_error_allowed_in_bad_pixels = 0.0f; float average_error_allowed_in_bad_pixels = 0.0f;
int large_error_allowed = 0; int error_allowed = 0;
#endif #endif
float percentage_pixels_small_error = 0.0f;
int small_error_allowed = 0;
pixel_comparator_ = std::make_unique<FuzzyPixelComparator>( pixel_comparator_ = std::make_unique<FuzzyPixelComparator>(
true, // discard_alpha FuzzyPixelComparator()
percentage_pixels_large_error, percentage_pixels_small_error, .DiscardAlpha()
average_error_allowed_in_bad_pixels, large_error_allowed, .SetErrorPixelsPercentageLimit(percentage_pixels_error)
small_error_allowed); .SetAvgAbsErrorLimit(average_error_allowed_in_bad_pixels)
.SetAbsErrorLimit(error_allowed));
#endif #endif
RunPixelTest(background, RunPixelTest(background,
@@ -914,33 +893,34 @@ TEST_P(LayerTreeHostFiltersPixelTest, RotatedDropShadowFilter) {
(BUILDFLAG(IS_WIN) || BUILDFLAG(IS_FUCHSIA) || BUILDFLAG(IS_MAC)) (BUILDFLAG(IS_WIN) || BUILDFLAG(IS_FUCHSIA) || BUILDFLAG(IS_MAC))
// Windows, macOS, and Fuchsia on ARM64 has some pixels difference. // Windows, macOS, and Fuchsia on ARM64 has some pixels difference.
// crbug.com/1029728, crbug.com/1128443 // crbug.com/1029728, crbug.com/1128443
float percentage_pixels_large_error = 0.89f; float percentage_pixels_error = 0.89f;
float average_error_allowed_in_bad_pixels = 5.f; float average_error_allowed_in_bad_pixels = 5.f;
int large_error_allowed = 17; int error_allowed = 17;
#elif BUILDFLAG(IS_MAC) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_OZONE) #elif BUILDFLAG(IS_MAC) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_OZONE)
// There's a 1 pixel error on MacOS and ChromeOS // There's a 1 pixel error on MacOS and ChromeOS
float percentage_pixels_large_error = 0.00111112f; // 1px / (300*300) float percentage_pixels_error = 0.00111112f; // 1px / (300*300)
float average_error_allowed_in_bad_pixels = 1.f; float average_error_allowed_in_bad_pixels = 1.f;
int large_error_allowed = 1; int error_allowed = 1;
#else #else
// Windows and all other ARM64 have 3 pixels off by 1: crbug.com/259915 // Windows and all other ARM64 have 3 pixels off by 1: crbug.com/259915
float percentage_pixels_large_error = 0.00333334f; // 3px / (300*300) float percentage_pixels_error = 0.00333334f; // 3px / (300*300)
float average_error_allowed_in_bad_pixels = 1.f; float average_error_allowed_in_bad_pixels = 1.f;
int large_error_allowed = 1; int error_allowed = 1;
// Windows using Dawn D3D12 has 22 pixels off by 1. // Windows using Dawn D3D12 has 22 pixels off by 1.
if (use_d3d12()) if (use_d3d12())
percentage_pixels_large_error = 0.02445; // 22px / (300*300) percentage_pixels_error = 0.02445; // 22px / (300*300)
#endif #endif
float percentage_pixels_small_error = 0.0f;
int small_error_allowed = 0;
pixel_comparator_ = std::make_unique<FuzzyPixelComparator>( pixel_comparator_ = std::make_unique<FuzzyPixelComparator>(
true, // discard_alpha FuzzyPixelComparator()
percentage_pixels_large_error, percentage_pixels_small_error, .DiscardAlpha()
average_error_allowed_in_bad_pixels, large_error_allowed, .SetErrorPixelsPercentageLimit(percentage_pixels_error)
small_error_allowed); .SetAvgAbsErrorLimit(average_error_allowed_in_bad_pixels)
.SetAbsErrorLimit(error_allowed));
#else #else
if (use_skia_vulkan()) if (use_skia_vulkan()) {
pixel_comparator_ = std::make_unique<FuzzyPixelOffByOneComparator>(true); pixel_comparator_ =
std::make_unique<AlphaDiscardingFuzzyPixelOffByOneComparator>();
}
#endif #endif
RunPixelTest( RunPixelTest(
@@ -983,8 +963,11 @@ TEST_P(LayerTreeHostFiltersPixelTest, TranslatedFilter) {
parent->AddChild(child); parent->AddChild(child);
clip->AddChild(parent); clip->AddChild(parent);
if (use_software_renderer() || renderer_type_ == viz::RendererType::kSkiaDawn) if (use_software_renderer() ||
pixel_comparator_ = std::make_unique<FuzzyPixelOffByOneComparator>(true); renderer_type_ == viz::RendererType::kSkiaDawn) {
pixel_comparator_ =
std::make_unique<AlphaDiscardingFuzzyPixelOffByOneComparator>();
}
RunPixelTest(clip, base::FilePath( RunPixelTest(clip, base::FilePath(
FILE_PATH_LITERAL("translated_blue_green_alpha.png"))); FILE_PATH_LITERAL("translated_blue_green_alpha.png")));
@@ -1095,21 +1078,18 @@ TEST_P(LayerTreeHostFiltersPixelTest, BlurFilterWithClip) {
#if BUILDFLAG(IS_WIN) || defined(ARCH_CPU_ARM64) #if BUILDFLAG(IS_WIN) || defined(ARCH_CPU_ARM64)
#if BUILDFLAG(IS_WIN) #if BUILDFLAG(IS_WIN)
// Windows has 1880 pixels off by 1: crbug.com/259915 // Windows has 1880 pixels off by 1: crbug.com/259915
float percentage_pixels_large_error = 4.7f; // 1880px / (200*200) float percentage_pixels_error = 4.7f; // 1880px / (200*200)
#else #else
// Differences in floating point calculation on ARM means a small percentage // Differences in floating point calculation on ARM means a small percentage
// of pixels will have small differences. // of pixels will have small differences.
float percentage_pixels_large_error = 2.76f; // 1104px / (200*200) float percentage_pixels_error = 2.76f; // 1104px / (200*200)
#endif #endif
float percentage_pixels_small_error = 0.0f;
float average_error_allowed_in_bad_pixels = 1.f;
int large_error_allowed = 2;
int small_error_allowed = 0;
pixel_comparator_ = std::make_unique<FuzzyPixelComparator>( pixel_comparator_ = std::make_unique<FuzzyPixelComparator>(
true, // discard_alpha FuzzyPixelComparator()
percentage_pixels_large_error, percentage_pixels_small_error, .DiscardAlpha()
average_error_allowed_in_bad_pixels, large_error_allowed, .SetErrorPixelsPercentageLimit(percentage_pixels_error)
small_error_allowed); .SetAvgAbsErrorLimit(1.f)
.SetAbsErrorLimit(2));
#endif #endif
RunPixelTest(filter_layer, RunPixelTest(filter_layer,
@@ -1224,16 +1204,11 @@ class BackdropFilterInvertTest : public LayerTreeHostFiltersPixelTest {
expected_result = expected_result.InsertBeforeExtensionASCII("_sw"); expected_result = expected_result.InsertBeforeExtensionASCII("_sw");
} else if (use_d3d12()) { } else if (use_d3d12()) {
// Windows using Dawn D3D12 has 16 pixels off by 1. // Windows using Dawn D3D12 has 16 pixels off by 1.
float percentage_pixels_large_error = 0.04f; // 16px / (200*200)
float average_error_allowed_in_bad_pixels = 1.f;
int large_error_allowed = 1;
float percentage_pixels_small_error = 0.0f;
int small_error_allowed = 0;
pixel_comparator_ = std::make_unique<FuzzyPixelComparator>( pixel_comparator_ = std::make_unique<FuzzyPixelComparator>(
true, // discard_alpha FuzzyPixelComparator()
percentage_pixels_large_error, percentage_pixels_small_error, .DiscardAlpha()
average_error_allowed_in_bad_pixels, large_error_allowed, .SetErrorPixelsPercentageLimit(0.04f) // 16px / (200*200)
small_error_allowed); .SetAbsErrorLimit(1));
} }
RunPixelTest(std::move(root), expected_result); RunPixelTest(std::move(root), expected_result);
} }

@@ -105,7 +105,8 @@ TEST_P(LayerTreeHostMasksPixelTest, MaskOfLayer) {
mask->SetIsDrawable(true); mask->SetIsDrawable(true);
green->SetMaskLayer(mask); green->SetMaskLayer(mask);
pixel_comparator_ = std::make_unique<FuzzyPixelOffByOneComparator>(true); pixel_comparator_ =
std::make_unique<AlphaDiscardingFuzzyPixelOffByOneComparator>();
RunPixelResourceTest(background, RunPixelResourceTest(background,
base::FilePath(FILE_PATH_LITERAL("mask_of_layer.png"))); base::FilePath(FILE_PATH_LITERAL("mask_of_layer.png")));
@@ -163,7 +164,7 @@ TEST_P(LayerTreeHostMaskPixelTestWithLayerList, MaskWithEffect) {
mask_layer_ = PictureLayer::Create(&client); mask_layer_ = PictureLayer::Create(&client);
pixel_comparator_ = pixel_comparator_ =
std::make_unique<FuzzyPixelOffByOneComparator>(true /* discard_alpha */); std::make_unique<AlphaDiscardingFuzzyPixelOffByOneComparator>();
RunPixelResourceTestWithLayerList( RunPixelResourceTestWithLayerList(
base::FilePath(FILE_PATH_LITERAL("mask_with_effect.png"))); base::FilePath(FILE_PATH_LITERAL("mask_with_effect.png")));
} }
@@ -298,7 +299,7 @@ TEST_P(LayerTreeHostMaskPixelTest_ScaledMaskWithEffect, Test) {
mask_layer_ = PictureLayer::Create(&client); mask_layer_ = PictureLayer::Create(&client);
pixel_comparator_ = pixel_comparator_ =
std::make_unique<FuzzyPixelOffByOneComparator>(true /* discard_alpha */); std::make_unique<AlphaDiscardingFuzzyPixelOffByOneComparator>();
RunPixelResourceTestWithLayerList( RunPixelResourceTestWithLayerList(
base::FilePath(FILE_PATH_LITERAL("scaled_mask_with_effect_.png")) base::FilePath(FILE_PATH_LITERAL("scaled_mask_with_effect_.png"))
@@ -311,7 +312,7 @@ TEST_P(LayerTreeHostMaskPixelTestWithLayerList, MaskWithEffectDifferentSize) {
mask_layer_ = PictureLayer::Create(&client); mask_layer_ = PictureLayer::Create(&client);
pixel_comparator_ = pixel_comparator_ =
std::make_unique<FuzzyPixelOffByOneComparator>(true /* discard_alpha */); std::make_unique<AlphaDiscardingFuzzyPixelOffByOneComparator>();
// The mask is half the size of thing it's masking. In layer-list mode, // The mask is half the size of thing it's masking. In layer-list mode,
// the mask is not automatically scaled to match the other layer. // the mask is not automatically scaled to match the other layer.
@@ -334,7 +335,7 @@ TEST_P(LayerTreeHostMaskPixelTestWithLayerList, ImageMaskWithEffect) {
mask_layer_ = FakePictureLayer::Create(&layer_client); mask_layer_ = FakePictureLayer::Create(&layer_client);
pixel_comparator_ = pixel_comparator_ =
std::make_unique<FuzzyPixelOffByOneComparator>(true /* discard_alpha */); std::make_unique<AlphaDiscardingFuzzyPixelOffByOneComparator>();
// The mask is half the size of thing it's masking. In layer-list mode, // The mask is half the size of thing it's masking. In layer-list mode,
// the mask is not automatically scaled to match the other layer. // the mask is not automatically scaled to match the other layer.
@@ -368,7 +369,7 @@ TEST_P(LayerTreeHostMasksPixelTest, ImageMaskOfLayer) {
background->AddChild(green); background->AddChild(green);
pixel_comparator_ = pixel_comparator_ =
std::make_unique<FuzzyPixelOffByOneComparator>(true /* discard_alpha */); std::make_unique<AlphaDiscardingFuzzyPixelOffByOneComparator>();
RunPixelResourceTest( RunPixelResourceTest(
background, base::FilePath(FILE_PATH_LITERAL("image_mask_of_layer.png"))); background, base::FilePath(FILE_PATH_LITERAL("image_mask_of_layer.png")));
@@ -397,7 +398,7 @@ TEST_P(LayerTreeHostMasksPixelTest, MaskOfClippedLayer) {
green->SetMaskLayer(mask); green->SetMaskLayer(mask);
pixel_comparator_ = pixel_comparator_ =
std::make_unique<FuzzyPixelOffByOneComparator>(true /* discard_alpha */); std::make_unique<AlphaDiscardingFuzzyPixelOffByOneComparator>();
RunPixelResourceTest( RunPixelResourceTest(
background, background,
@@ -421,7 +422,7 @@ TEST_P(LayerTreeHostMasksPixelTest, MaskOfLayerNonExactTextureSize) {
green->SetMaskLayer(mask); green->SetMaskLayer(mask);
pixel_comparator_ = pixel_comparator_ =
std::make_unique<FuzzyPixelOffByOneComparator>(true /* discard_alpha */); std::make_unique<AlphaDiscardingFuzzyPixelOffByOneComparator>();
RunPixelResourceTest(background, RunPixelResourceTest(background,
base::FilePath(FILE_PATH_LITERAL( base::FilePath(FILE_PATH_LITERAL(
@@ -577,15 +578,11 @@ TEST_P(LayerTreeHostMasksForBackdropFiltersPixelTestWithLayerList, Test) {
if (use_skia_vulkan() && use_accelerated_raster()) { if (use_skia_vulkan() && use_accelerated_raster()) {
// Vulkan with OOP raster has 3 pixels errors (the circle mask shape is // Vulkan with OOP raster has 3 pixels errors (the circle mask shape is
// slightly different). // slightly different).
float percentage_pixels_large_error = 0.031f; // 3px / (100*100)
float percentage_pixels_small_error = 0.0f;
float average_error_allowed_in_bad_pixels = 182.f;
int large_error_allowed = 182;
int small_error_allowed = 0;
pixel_comparator_ = std::make_unique<FuzzyPixelComparator>( pixel_comparator_ = std::make_unique<FuzzyPixelComparator>(
true /* discard_alpha */, percentage_pixels_large_error, FuzzyPixelComparator()
percentage_pixels_small_error, average_error_allowed_in_bad_pixels, .DiscardAlpha()
large_error_allowed, small_error_allowed); .SetErrorPixelsPercentageLimit(0.031f) // 3px / (100*100)
.SetAbsErrorLimit(182));
} }
RunPixelResourceTestWithLayerList(image_name); RunPixelResourceTestWithLayerList(image_name);
@@ -637,15 +634,11 @@ TEST_P(LayerTreeHostMasksForBackdropFiltersPixelTestWithLayerTree, Test) {
if (use_skia_vulkan() && use_accelerated_raster()) { if (use_skia_vulkan() && use_accelerated_raster()) {
// Vulkan with OOP raster has 3 pixels errors (the circle mask shape is // Vulkan with OOP raster has 3 pixels errors (the circle mask shape is
// slightly different). // slightly different).
float percentage_pixels_large_error = 0.031f; // 3px / (100*100)
float percentage_pixels_small_error = 0.0f;
float average_error_allowed_in_bad_pixels = 182.f;
int large_error_allowed = 182;
int small_error_allowed = 0;
pixel_comparator_ = std::make_unique<FuzzyPixelComparator>( pixel_comparator_ = std::make_unique<FuzzyPixelComparator>(
true /* discard_alpha */, percentage_pixels_large_error, FuzzyPixelComparator()
percentage_pixels_small_error, average_error_allowed_in_bad_pixels, .DiscardAlpha()
large_error_allowed, small_error_allowed); .SetErrorPixelsPercentageLimit(0.031f) // 3px / (100*100)
.SetAbsErrorLimit(182));
} }
RunPixelResourceTest(background, image_name); RunPixelResourceTest(background, image_name);
@@ -682,18 +675,11 @@ TEST_P(LayerTreeHostMasksPixelTest, MaskOfLayerWithBlend) {
mask->SetIsDrawable(true); mask->SetIsDrawable(true);
picture_horizontal->SetMaskLayer(mask); picture_horizontal->SetMaskLayer(mask);
float percentage_pixels_large_error = 0.04f; // 0.04%, ~6px / (128*128)
float percentage_pixels_small_error = 0.0f;
float average_error_allowed_in_bad_pixels = 256.0f;
int large_error_allowed = 256;
int small_error_allowed = 0;
pixel_comparator_ = std::make_unique<FuzzyPixelComparator>( pixel_comparator_ = std::make_unique<FuzzyPixelComparator>(
true, // discard_alpha FuzzyPixelComparator()
percentage_pixels_large_error, .DiscardAlpha()
percentage_pixels_small_error, .SetErrorPixelsPercentageLimit(0.04f) // 0.04%, ~6px / (128*128)
average_error_allowed_in_bad_pixels, .SetAbsErrorLimit(255));
large_error_allowed,
small_error_allowed);
RunPixelResourceTest(background, RunPixelResourceTest(background,
base::FilePath( base::FilePath(
@@ -744,14 +730,14 @@ class LayerTreeHostMaskAsBlendingPixelTest
: LayerTreeHostPixelResourceTest(GetParam().test_config), : LayerTreeHostPixelResourceTest(GetParam().test_config),
use_antialiasing_(GetParam().flags & kUseAntialiasing), use_antialiasing_(GetParam().flags & kUseAntialiasing),
force_shaders_(GetParam().flags & kForceShaders) { force_shaders_(GetParam().flags & kForceShaders) {
float percentage_pixels_error = 0.f; float percentage_pixels_large_error = 0.f;
float percentage_pixels_small_error = 0.f; float percentage_pixels_small_error = 0.f;
float average_error_allowed_in_bad_pixels = 0.f; float average_error_allowed_in_bad_pixels = 0.f;
int large_error_allowed = 0; int large_error_allowed = 0;
int small_error_allowed = 0; int small_error_allowed = 0;
if (!use_software_renderer()) { if (!use_software_renderer()) {
percentage_pixels_error = 6.0f; percentage_pixels_large_error = 4.0f;
percentage_pixels_small_error = 2.f; percentage_pixels_small_error = 2.0f;
average_error_allowed_in_bad_pixels = 2.1f; average_error_allowed_in_bad_pixels = 2.1f;
large_error_allowed = 11; large_error_allowed = 11;
small_error_allowed = 1; small_error_allowed = 1;
@@ -761,13 +747,13 @@ class LayerTreeHostMaskAsBlendingPixelTest
// ARM Windows, macOS, and Fuchsia has some pixels difference // ARM Windows, macOS, and Fuchsia has some pixels difference
// Affected tests: RotatedClippedCircle, RotatedClippedCircleUnderflow // Affected tests: RotatedClippedCircle, RotatedClippedCircleUnderflow
// crbug.com/1030244, crbug.com/1048249, crbug.com/1128443 // crbug.com/1030244, crbug.com/1048249, crbug.com/1128443
percentage_pixels_error = 7.f; percentage_pixels_large_error = 7.f;
average_error_allowed_in_bad_pixels = 5.f; average_error_allowed_in_bad_pixels = 5.f;
large_error_allowed = 20; large_error_allowed = 20;
#else #else
// Differences in floating point calculation on ARM means a small // Differences in floating point calculation on ARM means a small
// percentage of pixels will be off by 1. // percentage of pixels will be off by 1.
percentage_pixels_error = 0.112f; percentage_pixels_large_error = 0.112f;
average_error_allowed_in_bad_pixels = 1.f; average_error_allowed_in_bad_pixels = 1.f;
large_error_allowed = 1; large_error_allowed = 1;
#endif #endif
@@ -775,10 +761,11 @@ class LayerTreeHostMaskAsBlendingPixelTest
} }
pixel_comparator_ = std::make_unique<FuzzyPixelComparator>( pixel_comparator_ = std::make_unique<FuzzyPixelComparator>(
false, // discard_alpha FuzzyPixelComparator()
percentage_pixels_error, percentage_pixels_small_error, .SetErrorPixelsPercentageLimit(percentage_pixels_large_error,
average_error_allowed_in_bad_pixels, large_error_allowed, percentage_pixels_small_error)
small_error_allowed); .SetAvgAbsErrorLimit(average_error_allowed_in_bad_pixels)
.SetAbsErrorLimit(large_error_allowed, small_error_allowed));
} }
static scoped_refptr<Layer> CreateCheckerboardLayer(const gfx::Size& bounds) { static scoped_refptr<Layer> CreateCheckerboardLayer(const gfx::Size& bounds) {

@@ -50,20 +50,18 @@ TEST_P(LayerTreeHostMirrorPixelTest, MirrorLayer) {
background->AddChild(mirror_layer); background->AddChild(mirror_layer);
if (use_software_renderer()) { if (use_software_renderer()) {
const bool discard_alpha = true;
const float error_pixels_percentage_limit = 3.f;
const float small_error_pixels_percentage_limit = 0.f;
const float avg_abs_error_limit = 65.f;
const int max_abs_error_limit = 120;
const int small_error_threshold = 0;
pixel_comparator_ = std::make_unique<FuzzyPixelComparator>( pixel_comparator_ = std::make_unique<FuzzyPixelComparator>(
discard_alpha, error_pixels_percentage_limit, FuzzyPixelComparator()
small_error_pixels_percentage_limit, avg_abs_error_limit, .DiscardAlpha()
max_abs_error_limit, small_error_threshold); .SetErrorPixelsPercentageLimit(3.f)
.SetAvgAbsErrorLimit(65.f)
.SetAbsErrorLimit(120));
} }
if (use_skia_vulkan()) if (use_skia_vulkan()) {
pixel_comparator_ = std::make_unique<FuzzyPixelOffByOneComparator>(true); pixel_comparator_ =
std::make_unique<AlphaDiscardingFuzzyPixelOffByOneComparator>();
}
RunPixelTest(background, RunPixelTest(background,
base::FilePath(FILE_PATH_LITERAL("mirror_layer.png"))); base::FilePath(FILE_PATH_LITERAL("mirror_layer.png")));

@@ -176,7 +176,8 @@ TEST_P(LayerTreeHostScrollbarsPixelTest, MAYBE_HugeTransformScale) {
scale_transform.Scale(scale, scale); scale_transform.Scale(scale, scale);
layer->SetTransform(scale_transform); layer->SetTransform(scale_transform);
pixel_comparator_ = std::make_unique<FuzzyPixelOffByOneComparator>(true); pixel_comparator_ =
std::make_unique<AlphaDiscardingFuzzyPixelOffByOneComparator>();
RunPixelTest(background, RunPixelTest(background,
base::FilePath(use_skia_vulkan() base::FilePath(use_skia_vulkan()

@@ -337,7 +337,7 @@ TEST_P(LayerTreeHostTilesTestRasterColorSpace, GenericRGB) {
TEST_P(LayerTreeHostTilesTestRasterColorSpace, CustomColorSpace) { TEST_P(LayerTreeHostTilesTestRasterColorSpace, CustomColorSpace) {
#if BUILDFLAG(IS_FUCHSIA) #if BUILDFLAG(IS_FUCHSIA)
pixel_comparator_ = std::make_unique<FuzzyPixelOffByOneComparator>(false); pixel_comparator_ = std::make_unique<FuzzyPixelOffByOneComparator>();
#endif #endif
// Create a color space with a different blue point. // Create a color space with a different blue point.
SkColorSpacePrimaries primaries; SkColorSpacePrimaries primaries;

@@ -215,9 +215,8 @@ TEST_F(AppIconFactoryTest, LoadFromFileSuccess) {
EXPECT_FALSE(fallback_called); EXPECT_FALSE(fallback_called);
ASSERT_TRUE(result); ASSERT_TRUE(result);
EXPECT_TRUE( EXPECT_TRUE(cc::MatchesBitmap(*bitmap, *result->uncompressed.bitmap(),
cc::MatchesBitmap(*bitmap, *result->uncompressed.bitmap(), cc::ExactPixelComparator()));
cc::ExactPixelComparator(/*discard_alpha=*/false)));
} }
TEST_F(AppIconFactoryTest, LoadFromFileFallback) { TEST_F(AppIconFactoryTest, LoadFromFileFallback) {

@@ -36,20 +36,16 @@
// Mac has subtle rendering differences between different versions of MacOS, so // Mac has subtle rendering differences between different versions of MacOS, so
// we account for them with these fuzzy pixel comparators. These two comparators // we account for them with these fuzzy pixel comparators. These two comparators
// are used in different tests in order to keep the matching somewhat strict. // are used in different tests in order to keep the matching somewhat strict.
const cc::FuzzyPixelComparator mac_strict_comparator( const auto mac_strict_comparator = cc::FuzzyPixelComparator()
/* discard_alpha */ true, .DiscardAlpha()
/* error_pixels_percentage_limit */ 3.f, .SetErrorPixelsPercentageLimit(3.f)
/* small_error_pixels_percentage_limit */ 0.f, .SetAvgAbsErrorLimit(20.f)
/* avg_abs_error_limit */ 20.f, .SetAbsErrorLimit(49);
/* max_abs_error_limit */ 49.f, const auto mac_loose_comparator = cc::FuzzyPixelComparator()
/* small_error_threshold */ 0); .DiscardAlpha()
const cc::FuzzyPixelComparator mac_loose_comparator( .SetErrorPixelsPercentageLimit(8.7f)
/* discard_alpha */ true, .SetAvgAbsErrorLimit(20.f)
/* error_pixels_percentage_limit */ 8.7f, .SetAbsErrorLimit(43);
/* small_error_pixels_percentage_limit */ 0.f,
/* avg_abs_error_limit */ 20.f,
/* max_abs_error_limit */ 43.f,
/* small_error_threshold */ 0);
#endif #endif
class FocusRingBrowserTest : public InProcessBrowserTest { class FocusRingBrowserTest : public InProcessBrowserTest {
@@ -119,9 +115,9 @@ class FocusRingBrowserTest : public InProcessBrowserTest {
#endif #endif
IN_PROC_BROWSER_TEST_F(FocusRingBrowserTest, MAYBE_Checkbox) { IN_PROC_BROWSER_TEST_F(FocusRingBrowserTest, MAYBE_Checkbox) {
#if BUILDFLAG(IS_MAC) #if BUILDFLAG(IS_MAC)
cc::FuzzyPixelComparator comparator = mac_strict_comparator; auto comparator = mac_strict_comparator;
#else #else
cc::ExactPixelComparator comparator(/*discard_alpha=*/true); cc::AlphaDiscardingExactPixelComparator comparator;
#endif #endif
RunTest("focus_ring_browsertest_checkbox", RunTest("focus_ring_browsertest_checkbox",
"<input type=checkbox autofocus>" "<input type=checkbox autofocus>"
@@ -138,9 +134,9 @@ IN_PROC_BROWSER_TEST_F(FocusRingBrowserTest, MAYBE_Checkbox) {
#endif #endif
IN_PROC_BROWSER_TEST_F(FocusRingBrowserTest, MAYBE_Radio) { IN_PROC_BROWSER_TEST_F(FocusRingBrowserTest, MAYBE_Radio) {
#if BUILDFLAG(IS_MAC) #if BUILDFLAG(IS_MAC)
cc::FuzzyPixelComparator comparator = mac_loose_comparator; auto comparator = mac_loose_comparator;
#else #else
cc::ExactPixelComparator comparator(/*discard_alpha=*/true); cc::AlphaDiscardingExactPixelComparator comparator;
#endif #endif
RunTest("focus_ring_browsertest_radio", RunTest("focus_ring_browsertest_radio",
"<input type=radio autofocus>" "<input type=radio autofocus>"
@@ -157,9 +153,9 @@ IN_PROC_BROWSER_TEST_F(FocusRingBrowserTest, MAYBE_Radio) {
#endif #endif
IN_PROC_BROWSER_TEST_F(FocusRingBrowserTest, MAYBE_Button) { IN_PROC_BROWSER_TEST_F(FocusRingBrowserTest, MAYBE_Button) {
#if BUILDFLAG(IS_MAC) #if BUILDFLAG(IS_MAC)
cc::FuzzyPixelComparator comparator = mac_strict_comparator; auto comparator = mac_strict_comparator;
#else #else
cc::ExactPixelComparator comparator(/*discard_alpha=*/true); cc::AlphaDiscardingExactPixelComparator comparator;
#endif #endif
RunTest("focus_ring_browsertest_button", RunTest("focus_ring_browsertest_button",
"<button autofocus style=\"width:40px;height:20px;\"></button>" "<button autofocus style=\"width:40px;height:20px;\"></button>"
@@ -178,9 +174,9 @@ IN_PROC_BROWSER_TEST_F(FocusRingBrowserTest, MAYBE_Button) {
#endif #endif
IN_PROC_BROWSER_TEST_F(FocusRingBrowserTest, MAYBE_Anchor) { IN_PROC_BROWSER_TEST_F(FocusRingBrowserTest, MAYBE_Anchor) {
#if BUILDFLAG(IS_MAC) #if BUILDFLAG(IS_MAC)
cc::FuzzyPixelComparator comparator = mac_strict_comparator; auto comparator = mac_strict_comparator;
#else #else
cc::ExactPixelComparator comparator(/*discard_alpha=*/true); cc::AlphaDiscardingExactPixelComparator comparator;
#endif #endif
RunTest("focus_ring_browsertest_anchor", RunTest("focus_ring_browsertest_anchor",
"<div style='text-align: center; width: 80px;'>" "<div style='text-align: center; width: 80px;'>"
@@ -204,9 +200,9 @@ IN_PROC_BROWSER_TEST_F(FocusRingBrowserTest, MAYBE_DarkModeButton) {
#if BUILDFLAG(IS_MAC) #if BUILDFLAG(IS_MAC)
if (!MacOSVersionSupportsDarkMode()) if (!MacOSVersionSupportsDarkMode())
return; return;
cc::FuzzyPixelComparator comparator = mac_strict_comparator; auto comparator = mac_strict_comparator;
#else #else
cc::ExactPixelComparator comparator(/*discard_alpha=*/true); cc::AlphaDiscardingExactPixelComparator comparator;
#endif #endif
RunTest("focus_ring_browsertest_dark_mode_button", RunTest("focus_ring_browsertest_dark_mode_button",
"<meta name=\"color-scheme\" content=\"dark\">" "<meta name=\"color-scheme\" content=\"dark\">"

@@ -240,7 +240,7 @@ class ReadbackHolder : public base::RefCountedThreadSafe<ReadbackHolder> {
std::unique_ptr<base::RunLoop> run_loop_; std::unique_ptr<base::RunLoop> run_loop_;
}; };
const cc::ExactPixelComparator pixel_comparator(/*discard_alpha=*/false); const cc::ExactPixelComparator pixel_comparator;
// Flaky on Lacros: https://crbug.com/1289366 // Flaky on Lacros: https://crbug.com/1289366
#if (BUILDFLAG(IS_MAC) && \ #if (BUILDFLAG(IS_MAC) && \

@@ -220,7 +220,7 @@ class SecurePaymentConfirmationDialogViewTest
DialogViewID::INSTRUMENT_ICON))) DialogViewID::INSTRUMENT_ICON)))
->GetImage() ->GetImage()
.bitmap()), .bitmap()),
cc::ExactPixelComparator(/*discard_alpha=*/false))); cc::ExactPixelComparator()));
ExpectLabelText( ExpectLabelText(
model_.total_label(), model_.total_label(),

@@ -850,8 +850,7 @@ TEST_F(DataOfferTest, SetClipboardDataImage) {
ASSERT_TRUE(gfx::PNGCodec::Decode( ASSERT_TRUE(gfx::PNGCodec::Decode(
reinterpret_cast<const unsigned char*>(result.data()), result.size(), reinterpret_cast<const unsigned char*>(result.data()), result.size(),
&decoded)); &decoded));
EXPECT_TRUE(cc::MatchesBitmap( EXPECT_TRUE(cc::MatchesBitmap(image, decoded, cc::ExactPixelComparator()));
image, decoded, cc::ExactPixelComparator(/*discard_alpha=*/false)));
std::string good = result; std::string good = result;
ASSERT_TRUE(ReadString(std::move(read_pipe2), &result)); ASSERT_TRUE(ReadString(std::move(read_pipe2), &result));
EXPECT_EQ(good, result); EXPECT_EQ(good, result);

@@ -929,7 +929,7 @@ TEST_P(RendererPixelTest, SimpleGreenRect) {
EXPECT_TRUE(this->RunPixelTest(&pass_list, EXPECT_TRUE(this->RunPixelTest(&pass_list,
base::FilePath(FILE_PATH_LITERAL("green.png")), base::FilePath(FILE_PATH_LITERAL("green.png")),
cc::ExactPixelComparator(true))); cc::AlphaDiscardingExactPixelComparator()));
} }
TEST_P(RendererPixelTest, SimpleGreenRectNonRootRenderPass) { TEST_P(RendererPixelTest, SimpleGreenRectNonRootRenderPass) {
@@ -966,7 +966,7 @@ TEST_P(RendererPixelTest, SimpleGreenRectNonRootRenderPass) {
EXPECT_TRUE(this->RunPixelTestWithReadbackTarget( EXPECT_TRUE(this->RunPixelTestWithReadbackTarget(
&pass_list, child_pass_ptr, &pass_list, child_pass_ptr,
base::FilePath(FILE_PATH_LITERAL("green_small.png")), base::FilePath(FILE_PATH_LITERAL("green_small.png")),
cc::ExactPixelComparator(true))); cc::AlphaDiscardingExactPixelComparator()));
} }
TEST_P(RendererPixelTest, PremultipliedTextureWithoutBackground) { TEST_P(RendererPixelTest, PremultipliedTextureWithoutBackground) {
@@ -995,7 +995,7 @@ TEST_P(RendererPixelTest, PremultipliedTextureWithoutBackground) {
EXPECT_TRUE(this->RunPixelTest( EXPECT_TRUE(this->RunPixelTest(
&pass_list, base::FilePath(FILE_PATH_LITERAL("green_alpha.png")), &pass_list, base::FilePath(FILE_PATH_LITERAL("green_alpha.png")),
cc::FuzzyPixelOffByOneComparator(true))); cc::AlphaDiscardingFuzzyPixelOffByOneComparator()));
} }
TEST_P(RendererPixelTest, PremultipliedTextureWithBackground) { TEST_P(RendererPixelTest, PremultipliedTextureWithBackground) {
@@ -1027,7 +1027,7 @@ TEST_P(RendererPixelTest, PremultipliedTextureWithBackground) {
EXPECT_TRUE(this->RunPixelTest( EXPECT_TRUE(this->RunPixelTest(
&pass_list, base::FilePath(FILE_PATH_LITERAL("green_alpha.png")), &pass_list, base::FilePath(FILE_PATH_LITERAL("green_alpha.png")),
cc::FuzzyPixelOffByOneComparator(true))); cc::AlphaDiscardingFuzzyPixelOffByOneComparator()));
} }
TEST_P(RendererPixelTest, TextureDrawQuadVisibleRectInsetTopLeft) { TEST_P(RendererPixelTest, TextureDrawQuadVisibleRectInsetTopLeft) {
@@ -1061,7 +1061,7 @@ TEST_P(RendererPixelTest, TextureDrawQuadVisibleRectInsetTopLeft) {
EXPECT_TRUE(this->RunPixelTest( EXPECT_TRUE(this->RunPixelTest(
&pass_list, base::FilePath(FILE_PATH_LITERAL("inset_top_left.png")), &pass_list, base::FilePath(FILE_PATH_LITERAL("inset_top_left.png")),
cc::FuzzyPixelOffByOneComparator(true))); cc::AlphaDiscardingFuzzyPixelOffByOneComparator()));
} }
// This tests drawing a TextureDrawQuad with a visible_rect strictly included in // This tests drawing a TextureDrawQuad with a visible_rect strictly included in
@@ -1105,7 +1105,7 @@ TEST_P(RendererPixelTest,
EXPECT_TRUE(this->RunPixelTest( EXPECT_TRUE(this->RunPixelTest(
&pass_list, &pass_list,
base::FilePath(FILE_PATH_LITERAL("offset_inset_top_left.png")), base::FilePath(FILE_PATH_LITERAL("offset_inset_top_left.png")),
cc::FuzzyPixelOffByOneComparator(true))); cc::AlphaDiscardingFuzzyPixelOffByOneComparator()));
} }
TEST_P(RendererPixelTest, TextureDrawQuadVisibleRectInsetBottomRight) { TEST_P(RendererPixelTest, TextureDrawQuadVisibleRectInsetBottomRight) {
@@ -1146,7 +1146,7 @@ TEST_P(RendererPixelTest, TextureDrawQuadVisibleRectInsetBottomRight) {
EXPECT_TRUE(this->RunPixelTest( EXPECT_TRUE(this->RunPixelTest(
&pass_list, base::FilePath(FILE_PATH_LITERAL("inset_bottom_right.png")), &pass_list, base::FilePath(FILE_PATH_LITERAL("inset_bottom_right.png")),
cc::FuzzyPixelOffByOneComparator(true))); cc::AlphaDiscardingFuzzyPixelOffByOneComparator()));
} }
TEST_P(GPURendererPixelTest, SolidColorBlend) { TEST_P(GPURendererPixelTest, SolidColorBlend) {
@@ -1180,7 +1180,7 @@ TEST_P(GPURendererPixelTest, SolidColorBlend) {
EXPECT_TRUE(this->RunPixelTest( EXPECT_TRUE(this->RunPixelTest(
&pass_list, base::FilePath(FILE_PATH_LITERAL("dark_grey.png")), &pass_list, base::FilePath(FILE_PATH_LITERAL("dark_grey.png")),
cc::FuzzyPixelOffByOneComparator(/*discard_alpha=*/true))); cc::AlphaDiscardingFuzzyPixelOffByOneComparator()));
} }
TEST_P(GPURendererPixelTest, SolidColorWithTemperature) { TEST_P(GPURendererPixelTest, SolidColorWithTemperature) {
@@ -1206,7 +1206,7 @@ TEST_P(GPURendererPixelTest, SolidColorWithTemperature) {
EXPECT_TRUE(this->RunPixelTest( EXPECT_TRUE(this->RunPixelTest(
&pass_list, base::FilePath(FILE_PATH_LITERAL("temperature_brown.png")), &pass_list, base::FilePath(FILE_PATH_LITERAL("temperature_brown.png")),
cc::FuzzyPixelOffByOneComparator(true))); cc::AlphaDiscardingFuzzyPixelOffByOneComparator()));
} }
TEST_P(GPURendererPixelTest, SolidColorWithTemperatureNonRootRenderPass) { TEST_P(GPURendererPixelTest, SolidColorWithTemperatureNonRootRenderPass) {
@@ -1248,7 +1248,7 @@ TEST_P(GPURendererPixelTest, SolidColorWithTemperatureNonRootRenderPass) {
EXPECT_TRUE(this->RunPixelTest( EXPECT_TRUE(this->RunPixelTest(
&render_passes_in_draw_order, &render_passes_in_draw_order,
base::FilePath(FILE_PATH_LITERAL("temperature_brown_non_root.png")), base::FilePath(FILE_PATH_LITERAL("temperature_brown_non_root.png")),
cc::FuzzyPixelOffByOneComparator(true))); cc::AlphaDiscardingFuzzyPixelOffByOneComparator()));
} }
TEST_P(GPURendererPixelTest, TEST_P(GPURendererPixelTest,
@@ -1284,7 +1284,7 @@ TEST_P(GPURendererPixelTest,
EXPECT_TRUE(this->RunPixelTest( EXPECT_TRUE(this->RunPixelTest(
&pass_list, &pass_list,
base::FilePath(FILE_PATH_LITERAL("green_alpha_vertex_opacity.png")), base::FilePath(FILE_PATH_LITERAL("green_alpha_vertex_opacity.png")),
cc::FuzzyPixelOffByOneComparator(true))); cc::AlphaDiscardingFuzzyPixelOffByOneComparator()));
} }
class IntersectingQuadPixelTest : public VizPixelTestWithParam { class IntersectingQuadPixelTest : public VizPixelTestWithParam {
@@ -1413,7 +1413,7 @@ TEST_P(IntersectingQuadPixelTest, SolidColorQuads) {
quad2->SetNew(this->back_quad_state_, this->quad_rect_, this->quad_rect_, quad2->SetNew(this->back_quad_state_, this->quad_rect_, this->quad_rect_,
SkColors::kGreen, false); SkColors::kGreen, false);
this->AppendBackgroundAndRunTest( this->AppendBackgroundAndRunTest(
cc::FuzzyPixelComparator(false, 2.f, 0.f, 256.f, 256, 0.f), cc::FuzzyPixelComparator().SetErrorPixelsPercentageLimit(2.f),
FILE_PATH_LITERAL("intersecting_blue_green.png")); FILE_PATH_LITERAL("intersecting_blue_green.png"));
} }
@@ -1435,7 +1435,7 @@ TEST_P(IntersectingQuadPixelTest, TexturedQuads) {
this->child_context_provider_, this->render_pass_.get()); this->child_context_provider_, this->render_pass_.get());
this->AppendBackgroundAndRunTest( this->AppendBackgroundAndRunTest(
cc::FuzzyPixelComparator(false, 2.f, 0.f, 256.f, 256, 0.f), cc::FuzzyPixelComparator().SetErrorPixelsPercentageLimit(2.f),
FILE_PATH_LITERAL("intersecting_blue_green_squares.png")); FILE_PATH_LITERAL("intersecting_blue_green_squares.png"));
} }
@@ -1461,7 +1461,7 @@ TEST_P(IntersectingQuadPixelTest, NonFlippedTexturedQuads) {
this->child_context_provider_, this->render_pass_.get()); this->child_context_provider_, this->render_pass_.get());
this->AppendBackgroundAndRunTest( this->AppendBackgroundAndRunTest(
cc::FuzzyPixelComparator(false, 2.f, 0.f, 256.f, 256, 0.f), cc::FuzzyPixelComparator().SetErrorPixelsPercentageLimit(2.f),
FILE_PATH_LITERAL( FILE_PATH_LITERAL(
"intersecting_non_flipped_blue_green_half_size_rectangles.png")); "intersecting_non_flipped_blue_green_half_size_rectangles.png"));
} }
@@ -1488,7 +1488,7 @@ TEST_P(IntersectingQuadPixelTest, FlippedTexturedQuads) {
this->child_context_provider_, this->render_pass_.get()); this->child_context_provider_, this->render_pass_.get());
this->AppendBackgroundAndRunTest( this->AppendBackgroundAndRunTest(
cc::FuzzyPixelComparator(false, 2.f, 0.f, 256.f, 256, 0.f), cc::FuzzyPixelComparator().SetErrorPixelsPercentageLimit(2.f),
FILE_PATH_LITERAL( FILE_PATH_LITERAL(
"intersecting_flipped_blue_green_half_size_rectangles.png")); "intersecting_flipped_blue_green_half_size_rectangles.png"));
} }
@@ -1543,7 +1543,7 @@ TEST_P(IntersectingQuadSoftwareTest, PictureQuads) {
this->quad_rect_, 1.f, {}, this->quad_rect_, 1.f, {},
green_raster_source->GetDisplayItemList()); green_raster_source->GetDisplayItemList());
this->AppendBackgroundAndRunTest( this->AppendBackgroundAndRunTest(
cc::FuzzyPixelComparator(false, 2.f, 0.f, 256.f, 256, 0.f), cc::FuzzyPixelComparator().SetErrorPixelsPercentageLimit(2.f),
FILE_PATH_LITERAL("intersecting_blue_green_squares.png")); FILE_PATH_LITERAL("intersecting_blue_green_squares.png"));
} }
@@ -1586,7 +1586,7 @@ TEST_P(IntersectingQuadPixelTest, RenderPassQuads) {
this->pass_list_.push_back(std::move(child_pass1)); this->pass_list_.push_back(std::move(child_pass1));
this->pass_list_.push_back(std::move(child_pass2)); this->pass_list_.push_back(std::move(child_pass2));
this->AppendBackgroundAndRunTest( this->AppendBackgroundAndRunTest(
cc::FuzzyPixelComparator(false, 2.f, 0.f, 256.f, 256, 0.f), cc::FuzzyPixelComparator().SetErrorPixelsPercentageLimit(2.f),
FILE_PATH_LITERAL("intersecting_blue_green_squares.png")); FILE_PATH_LITERAL("intersecting_blue_green_squares.png"));
} }
@@ -1615,7 +1615,11 @@ TEST_P(IntersectingVideoQuadPixelTest, YUVVideoQuads) {
this->child_context_provider_.get()); this->child_context_provider_.get());
this->AppendBackgroundAndRunTest( this->AppendBackgroundAndRunTest(
cc::FuzzyPixelComparator(true, 0.50f, 0.f, 1.2f, 2, 0), cc::FuzzyPixelComparator()
.DiscardAlpha()
.SetErrorPixelsPercentageLimit(0.50f)
.SetAvgAbsErrorLimit(1.2f)
.SetAbsErrorLimit(2),
FILE_PATH_LITERAL("intersecting_blue_green_squares_video.png")); FILE_PATH_LITERAL("intersecting_blue_green_squares_video.png"));
} }
@@ -1642,7 +1646,7 @@ TEST_P(IntersectingVideoQuadPixelTest, Y16VideoQuads) {
this->child_context_provider_.get()); this->child_context_provider_.get());
this->AppendBackgroundAndRunTest( this->AppendBackgroundAndRunTest(
cc::FuzzyPixelOffByOneComparator(false), cc::FuzzyPixelOffByOneComparator(),
FILE_PATH_LITERAL("intersecting_light_dark_squares_video.png")); FILE_PATH_LITERAL("intersecting_light_dark_squares_video.png"));
} }
@@ -1673,7 +1677,7 @@ TEST_P(GPURendererPixelTest, NonPremultipliedTextureWithoutBackground) {
EXPECT_TRUE(this->RunPixelTest( EXPECT_TRUE(this->RunPixelTest(
&pass_list, base::FilePath(FILE_PATH_LITERAL("green_alpha.png")), &pass_list, base::FilePath(FILE_PATH_LITERAL("green_alpha.png")),
cc::FuzzyPixelOffByOneComparator(true))); cc::AlphaDiscardingFuzzyPixelOffByOneComparator()));
} }
// TODO(skaslev): The software renderer does not support non-premultplied alpha. // TODO(skaslev): The software renderer does not support non-premultplied alpha.
@@ -1706,7 +1710,7 @@ TEST_P(GPURendererPixelTest, NonPremultipliedTextureWithBackground) {
EXPECT_TRUE(this->RunPixelTest( EXPECT_TRUE(this->RunPixelTest(
&pass_list, base::FilePath(FILE_PATH_LITERAL("green_alpha.png")), &pass_list, base::FilePath(FILE_PATH_LITERAL("green_alpha.png")),
cc::FuzzyPixelOffByOneComparator(true))); cc::AlphaDiscardingFuzzyPixelOffByOneComparator()));
} }
class VideoRendererPixelTestBase : public VizPixelTest { class VideoRendererPixelTestBase : public VizPixelTest {
@@ -1813,7 +1817,7 @@ TEST_P(VideoRendererPixelHiLoTest, SimpleYUVRect) {
EXPECT_TRUE(this->RunPixelTest( EXPECT_TRUE(this->RunPixelTest(
&pass_list, base::FilePath(FILE_PATH_LITERAL("yuv_stripes.png")), &pass_list, base::FilePath(FILE_PATH_LITERAL("yuv_stripes.png")),
cc::FuzzyPixelOffByOneComparator(true))); cc::AlphaDiscardingFuzzyPixelOffByOneComparator()));
} }
TEST_P(VideoRendererPixelHiLoTest, ClippedYUVRect) { TEST_P(VideoRendererPixelHiLoTest, ClippedYUVRect) {
@@ -1841,7 +1845,7 @@ TEST_P(VideoRendererPixelHiLoTest, ClippedYUVRect) {
EXPECT_TRUE(this->RunPixelTest( EXPECT_TRUE(this->RunPixelTest(
&pass_list, base::FilePath(FILE_PATH_LITERAL("yuv_stripes_clipped.png")), &pass_list, base::FilePath(FILE_PATH_LITERAL("yuv_stripes_clipped.png")),
cc::FuzzyPixelOffByOneComparator(true))); cc::AlphaDiscardingFuzzyPixelOffByOneComparator()));
} }
#endif // #if BUILDFLAG(ENABLE_GL_BACKEND_TESTS) #endif // #if BUILDFLAG(ENABLE_GL_BACKEND_TESTS)
@@ -1886,7 +1890,7 @@ TEST_P(VideoRendererPixelTest, OffsetYUVRect) {
EXPECT_TRUE(this->RunPixelTest( EXPECT_TRUE(this->RunPixelTest(
&pass_list, base::FilePath(FILE_PATH_LITERAL("yuv_stripes_offset.png")), &pass_list, base::FilePath(FILE_PATH_LITERAL("yuv_stripes_offset.png")),
cc::FuzzyPixelComparator(true, 100.0f, 1.0f, 1.0f, 1, 0))); cc::AlphaDiscardingFuzzyPixelOffByOneComparator()));
} }
TEST_P(VideoRendererPixelTest, SimpleYUVRectBlack) { TEST_P(VideoRendererPixelTest, SimpleYUVRectBlack) {
@@ -1913,9 +1917,9 @@ TEST_P(VideoRendererPixelTest, SimpleYUVRectBlack) {
// If we didn't get black out of the YUV values above, then we probably have a // If we didn't get black out of the YUV values above, then we probably have a
// color range issue. // color range issue.
EXPECT_TRUE(this->RunPixelTest(&pass_list, EXPECT_TRUE(this->RunPixelTest(
base::FilePath(FILE_PATH_LITERAL("black.png")), &pass_list, base::FilePath(FILE_PATH_LITERAL("black.png")),
cc::FuzzyPixelOffByOneComparator(true))); cc::AlphaDiscardingFuzzyPixelOffByOneComparator()));
} }
TEST_P(VideoRendererPixelTest, SimpleYUVJRect) { TEST_P(VideoRendererPixelTest, SimpleYUVJRect) {
@@ -1938,9 +1942,9 @@ TEST_P(VideoRendererPixelTest, SimpleYUVJRect) {
AggregatedRenderPassList pass_list; AggregatedRenderPassList pass_list;
pass_list.push_back(std::move(pass)); pass_list.push_back(std::move(pass));
EXPECT_TRUE(this->RunPixelTest(&pass_list, EXPECT_TRUE(this->RunPixelTest(
base::FilePath(FILE_PATH_LITERAL("green.png")), &pass_list, base::FilePath(FILE_PATH_LITERAL("green.png")),
cc::FuzzyPixelOffByOneComparator(true))); cc::AlphaDiscardingFuzzyPixelOffByOneComparator()));
} }
TEST_P(VideoRendererPixelTest, SimpleYUVJRectWithTemperature) { TEST_P(VideoRendererPixelTest, SimpleYUVJRectWithTemperature) {
@@ -1971,7 +1975,7 @@ TEST_P(VideoRendererPixelTest, SimpleYUVJRectWithTemperature) {
EXPECT_TRUE(this->RunPixelTest( EXPECT_TRUE(this->RunPixelTest(
&pass_list, base::FilePath(FILE_PATH_LITERAL("temperature_brown.png")), &pass_list, base::FilePath(FILE_PATH_LITERAL("temperature_brown.png")),
cc::FuzzyPixelOffByOneComparator(true))); cc::AlphaDiscardingFuzzyPixelOffByOneComparator()));
} }
TEST_P(VideoRendererPixelTest, SimpleNV12JRect) { TEST_P(VideoRendererPixelTest, SimpleNV12JRect) {
@@ -1994,9 +1998,9 @@ TEST_P(VideoRendererPixelTest, SimpleNV12JRect) {
AggregatedRenderPassList pass_list; AggregatedRenderPassList pass_list;
pass_list.push_back(std::move(pass)); pass_list.push_back(std::move(pass));
EXPECT_TRUE(this->RunPixelTest(&pass_list, EXPECT_TRUE(this->RunPixelTest(
base::FilePath(FILE_PATH_LITERAL("green.png")), &pass_list, base::FilePath(FILE_PATH_LITERAL("green.png")),
cc::FuzzyPixelOffByOneComparator(true))); cc::AlphaDiscardingFuzzyPixelOffByOneComparator()));
} }
// Test that a YUV video doesn't bleed outside of its tex coords when the // Test that a YUV video doesn't bleed outside of its tex coords when the
@@ -2005,9 +2009,9 @@ TEST_P(VideoRendererPixelTest, YUVEdgeBleed) {
AggregatedRenderPassList pass_list; AggregatedRenderPassList pass_list;
this->CreateEdgeBleedPass(media::PIXEL_FORMAT_I420, this->CreateEdgeBleedPass(media::PIXEL_FORMAT_I420,
gfx::ColorSpace::CreateJpeg(), &pass_list); gfx::ColorSpace::CreateJpeg(), &pass_list);
EXPECT_TRUE(this->RunPixelTest(&pass_list, EXPECT_TRUE(this->RunPixelTest(
base::FilePath(FILE_PATH_LITERAL("green.png")), &pass_list, base::FilePath(FILE_PATH_LITERAL("green.png")),
cc::FuzzyPixelOffByOneComparator(true))); cc::AlphaDiscardingFuzzyPixelOffByOneComparator()));
} }
TEST_P(VideoRendererPixelTest, YUVAEdgeBleed) { TEST_P(VideoRendererPixelTest, YUVAEdgeBleed) {
@@ -2016,9 +2020,9 @@ TEST_P(VideoRendererPixelTest, YUVAEdgeBleed) {
gfx::ColorSpace::CreateREC601(), &pass_list); gfx::ColorSpace::CreateREC601(), &pass_list);
// Set the output color space to match the input primaries and transfer. // Set the output color space to match the input primaries and transfer.
this->display_color_spaces_ = kRec601DisplayColorSpaces; this->display_color_spaces_ = kRec601DisplayColorSpaces;
EXPECT_TRUE(this->RunPixelTest(&pass_list, EXPECT_TRUE(this->RunPixelTest(
base::FilePath(FILE_PATH_LITERAL("green.png")), &pass_list, base::FilePath(FILE_PATH_LITERAL("green.png")),
cc::FuzzyPixelOffByOneComparator(true))); cc::AlphaDiscardingFuzzyPixelOffByOneComparator()));
} }
TEST_P(VideoRendererPixelTest, SimpleYUVJRectGrey) { TEST_P(VideoRendererPixelTest, SimpleYUVJRectGrey) {
@@ -2043,7 +2047,7 @@ TEST_P(VideoRendererPixelTest, SimpleYUVJRectGrey) {
EXPECT_TRUE(this->RunPixelTest( EXPECT_TRUE(this->RunPixelTest(
&pass_list, base::FilePath(FILE_PATH_LITERAL("dark_grey.png")), &pass_list, base::FilePath(FILE_PATH_LITERAL("dark_grey.png")),
cc::FuzzyPixelOffByOneComparator(true))); cc::AlphaDiscardingFuzzyPixelOffByOneComparator()));
} }
TEST_P(VideoRendererPixelTest, SimpleYUVARect) { TEST_P(VideoRendererPixelTest, SimpleYUVARect) {
@@ -2072,7 +2076,7 @@ TEST_P(VideoRendererPixelTest, SimpleYUVARect) {
EXPECT_TRUE(this->RunPixelTest( EXPECT_TRUE(this->RunPixelTest(
&pass_list, base::FilePath(FILE_PATH_LITERAL("yuv_stripes_alpha.png")), &pass_list, base::FilePath(FILE_PATH_LITERAL("yuv_stripes_alpha.png")),
cc::FuzzyPixelOffByOneComparator(true))); cc::AlphaDiscardingFuzzyPixelOffByOneComparator()));
} }
TEST_P(VideoRendererPixelTest, FullyTransparentYUVARect) { TEST_P(VideoRendererPixelTest, FullyTransparentYUVARect) {
@@ -2101,7 +2105,7 @@ TEST_P(VideoRendererPixelTest, FullyTransparentYUVARect) {
EXPECT_TRUE(this->RunPixelTest(&pass_list, EXPECT_TRUE(this->RunPixelTest(&pass_list,
base::FilePath(FILE_PATH_LITERAL("black.png")), base::FilePath(FILE_PATH_LITERAL("black.png")),
cc::ExactPixelComparator(true))); cc::AlphaDiscardingExactPixelComparator()));
} }
TEST_P(VideoRendererPixelTest, TwoColorY16Rect) { TEST_P(VideoRendererPixelTest, TwoColorY16Rect) {
@@ -2126,7 +2130,7 @@ TEST_P(VideoRendererPixelTest, TwoColorY16Rect) {
EXPECT_TRUE(this->RunPixelTest( EXPECT_TRUE(this->RunPixelTest(
&pass_list, &pass_list,
base::FilePath(FILE_PATH_LITERAL("blue_yellow_filter_chain.png")), base::FilePath(FILE_PATH_LITERAL("blue_yellow_filter_chain.png")),
cc::FuzzyPixelOffByOneComparator(true))); cc::AlphaDiscardingFuzzyPixelOffByOneComparator()));
} }
TEST_P(RendererPixelTest, FastPassColorFilterAlpha) { TEST_P(RendererPixelTest, FastPassColorFilterAlpha) {
@@ -2205,7 +2209,7 @@ TEST_P(RendererPixelTest, FastPassColorFilterAlpha) {
// renderer so use a fuzzy comparator. // renderer so use a fuzzy comparator.
EXPECT_TRUE(this->RunPixelTest( EXPECT_TRUE(this->RunPixelTest(
&pass_list, base::FilePath(FILE_PATH_LITERAL("blue_yellow_alpha.png")), &pass_list, base::FilePath(FILE_PATH_LITERAL("blue_yellow_alpha.png")),
cc::FuzzyPixelOffByOneComparator(false))); cc::FuzzyPixelOffByOneComparator()));
} }
TEST_P(RendererPixelTest, FastPassSaturateFilter) { TEST_P(RendererPixelTest, FastPassSaturateFilter) {
@@ -2266,7 +2270,7 @@ TEST_P(RendererPixelTest, FastPassSaturateFilter) {
// renderer so use a fuzzy comparator. // renderer so use a fuzzy comparator.
EXPECT_TRUE(this->RunPixelTest( EXPECT_TRUE(this->RunPixelTest(
&pass_list, base::FilePath(FILE_PATH_LITERAL("blue_yellow_alpha.png")), &pass_list, base::FilePath(FILE_PATH_LITERAL("blue_yellow_alpha.png")),
cc::FuzzyPixelOffByOneComparator(false))); cc::FuzzyPixelOffByOneComparator()));
} }
TEST_P(RendererPixelTest, FastPassFilterChain) { TEST_P(RendererPixelTest, FastPassFilterChain) {
@@ -2329,7 +2333,7 @@ TEST_P(RendererPixelTest, FastPassFilterChain) {
EXPECT_TRUE(this->RunPixelTest( EXPECT_TRUE(this->RunPixelTest(
&pass_list, &pass_list,
base::FilePath(FILE_PATH_LITERAL("blue_yellow_filter_chain.png")), base::FilePath(FILE_PATH_LITERAL("blue_yellow_filter_chain.png")),
cc::FuzzyPixelOffByOneComparator(false))); cc::FuzzyPixelOffByOneComparator()));
} }
TEST_P(RendererPixelTest, FastPassColorFilterAlphaTranslation) { TEST_P(RendererPixelTest, FastPassColorFilterAlphaTranslation) {
@@ -2413,7 +2417,7 @@ TEST_P(RendererPixelTest, FastPassColorFilterAlphaTranslation) {
EXPECT_TRUE(this->RunPixelTest( EXPECT_TRUE(this->RunPixelTest(
&pass_list, &pass_list,
base::FilePath(FILE_PATH_LITERAL("blue_yellow_alpha_translate.png")), base::FilePath(FILE_PATH_LITERAL("blue_yellow_alpha_translate.png")),
cc::FuzzyPixelOffByOneComparator(false))); cc::FuzzyPixelOffByOneComparator()));
} }
TEST_P(RendererPixelTest, EnlargedRenderPassTexture) { TEST_P(RendererPixelTest, EnlargedRenderPassTexture) {
@@ -2457,7 +2461,7 @@ TEST_P(RendererPixelTest, EnlargedRenderPassTexture) {
EXPECT_TRUE(this->RunPixelTest( EXPECT_TRUE(this->RunPixelTest(
&pass_list, base::FilePath(FILE_PATH_LITERAL("blue_yellow.png")), &pass_list, base::FilePath(FILE_PATH_LITERAL("blue_yellow.png")),
cc::FuzzyPixelOffByOneComparator(true))); cc::AlphaDiscardingFuzzyPixelOffByOneComparator()));
} }
TEST_P(RendererPixelTest, EnlargedRenderPassTextureWithAntiAliasing) { TEST_P(RendererPixelTest, EnlargedRenderPassTextureWithAntiAliasing) {
@@ -2512,7 +2516,11 @@ TEST_P(RendererPixelTest, EnlargedRenderPassTextureWithAntiAliasing) {
EXPECT_TRUE(this->RunPixelTest( EXPECT_TRUE(this->RunPixelTest(
&pass_list, &pass_list,
base::FilePath(FILE_PATH_LITERAL("blue_yellow_anti_aliasing.png")), base::FilePath(FILE_PATH_LITERAL("blue_yellow_anti_aliasing.png")),
cc::FuzzyPixelComparator(true, 100.f, 0.f, 5.f, 7, 0))); cc::FuzzyPixelComparator()
.DiscardAlpha()
.SetErrorPixelsPercentageLimit(100.f)
.SetAvgAbsErrorLimit(5.f)
.SetAbsErrorLimit(7)));
} }
// This tests the case where we have a RenderPass with a mask, but the quad // This tests the case where we have a RenderPass with a mask, but the quad
@@ -2609,7 +2617,7 @@ TEST_P(RendererPixelTest, RenderPassAndMaskWithPartialQuad) {
EXPECT_TRUE(this->RunPixelTest( EXPECT_TRUE(this->RunPixelTest(
&pass_list, base::FilePath(FILE_PATH_LITERAL("mask_bottom_right.png")), &pass_list, base::FilePath(FILE_PATH_LITERAL("mask_bottom_right.png")),
cc::ExactPixelComparator(true))); cc::AlphaDiscardingExactPixelComparator()));
} }
// This tests the case where we have a RenderPass with a mask, but the quad // This tests the case where we have a RenderPass with a mask, but the quad
@@ -2706,7 +2714,7 @@ TEST_P(RendererPixelTest, RenderPassAndMaskWithPartialQuad2) {
EXPECT_TRUE(this->RunPixelTest( EXPECT_TRUE(this->RunPixelTest(
&pass_list, base::FilePath(FILE_PATH_LITERAL("mask_middle.png")), &pass_list, base::FilePath(FILE_PATH_LITERAL("mask_middle.png")),
cc::ExactPixelComparator(true))); cc::AlphaDiscardingExactPixelComparator()));
} }
TEST_P(RendererPixelTest, RenderPassAndMaskForRoundedCorner) { TEST_P(RendererPixelTest, RenderPassAndMaskForRoundedCorner) {
@@ -2795,7 +2803,8 @@ TEST_P(RendererPixelTest, RenderPassAndMaskForRoundedCorner) {
EXPECT_TRUE(this->RunPixelTest( EXPECT_TRUE(this->RunPixelTest(
&pass_list, &pass_list,
base::FilePath(FILE_PATH_LITERAL("rounded_corner_simple.png")), base::FilePath(FILE_PATH_LITERAL("rounded_corner_simple.png")),
cc::FuzzyPixelComparator(true, 0.6f, 0.f, 255.f, 255, 0))); cc::FuzzyPixelComparator().DiscardAlpha().SetErrorPixelsPercentageLimit(
0.6f)));
} }
TEST_P(RendererPixelTest, RenderPassAndMaskForRoundedCornerMultiRadii) { TEST_P(RendererPixelTest, RenderPassAndMaskForRoundedCornerMultiRadii) {
@@ -2896,7 +2905,8 @@ TEST_P(RendererPixelTest, RenderPassAndMaskForRoundedCornerMultiRadii) {
EXPECT_TRUE(this->RunPixelTest( EXPECT_TRUE(this->RunPixelTest(
&pass_list, &pass_list,
base::FilePath(FILE_PATH_LITERAL("rounded_corner_multi_radii.png")), base::FilePath(FILE_PATH_LITERAL("rounded_corner_multi_radii.png")),
cc::FuzzyPixelComparator(true, 0.6f, 0.f, 255.f, 255, 0))); cc::FuzzyPixelComparator().DiscardAlpha().SetErrorPixelsPercentageLimit(
0.6f)));
} }
class RendererPixelTestWithBackdropFilter : public VizPixelTestWithParam { class RendererPixelTestWithBackdropFilter : public VizPixelTestWithParam {
@@ -3075,7 +3085,7 @@ TEST_P(RendererPixelTestWithBackdropFilter, InvertFilter) {
EXPECT_TRUE(this->RunPixelTest( EXPECT_TRUE(this->RunPixelTest(
&this->pass_list_, &this->pass_list_,
base::FilePath(FILE_PATH_LITERAL("backdrop_filter.png")), base::FilePath(FILE_PATH_LITERAL("backdrop_filter.png")),
cc::ExactPixelComparator(true))); cc::AlphaDiscardingExactPixelComparator()));
} }
TEST_P(RendererPixelTestWithBackdropFilter, InvertFilterWithMask) { TEST_P(RendererPixelTestWithBackdropFilter, InvertFilterWithMask) {
@@ -3093,7 +3103,7 @@ TEST_P(RendererPixelTestWithBackdropFilter, InvertFilterWithMask) {
: FILE_PATH_LITERAL("backdrop_filter_masked.png")); : FILE_PATH_LITERAL("backdrop_filter_masked.png"));
EXPECT_TRUE(this->RunPixelTest(&this->pass_list_, expected_path, EXPECT_TRUE(this->RunPixelTest(&this->pass_list_, expected_path,
cc::FuzzyPixelOffByOneComparator(false))); cc::FuzzyPixelOffByOneComparator()));
} }
// Software renderer does not support anti-aliased edges. // Software renderer does not support anti-aliased edges.
@@ -3135,7 +3145,7 @@ TEST_P(GPURendererPixelTest, AntiAliasing) {
this->RunPixelTest(&pass_list, this->RunPixelTest(&pass_list,
base::FilePath(FILE_PATH_LITERAL("anti_aliasing_.png")) base::FilePath(FILE_PATH_LITERAL("anti_aliasing_.png"))
.InsertBeforeExtensionASCII(this->renderer_str()), .InsertBeforeExtensionASCII(this->renderer_str()),
cc::FuzzyPixelOffByOneComparator(true))); cc::AlphaDiscardingFuzzyPixelOffByOneComparator()));
} }
// Software renderer does not support anti-aliased edges. // Software renderer does not support anti-aliased edges.
@@ -3173,7 +3183,7 @@ TEST_P(GPURendererPixelTest, AntiAliasingPerspective) {
&pass_list, &pass_list,
base::FilePath(FILE_PATH_LITERAL("anti_aliasing_perspective_.png")) base::FilePath(FILE_PATH_LITERAL("anti_aliasing_perspective_.png"))
.InsertBeforeExtensionASCII(this->renderer_str()), .InsertBeforeExtensionASCII(this->renderer_str()),
cc::FuzzyPixelOffByOneComparator(true))); cc::AlphaDiscardingFuzzyPixelOffByOneComparator()));
} }
// This test tests that anti-aliasing works for axis aligned quads. // This test tests that anti-aliasing works for axis aligned quads.
@@ -3201,7 +3211,7 @@ TEST_P(GPURendererPixelTest, AxisAligned) {
EXPECT_TRUE(this->RunPixelTest( EXPECT_TRUE(this->RunPixelTest(
&pass_list, base::FilePath(FILE_PATH_LITERAL("axis_aligned.png")), &pass_list, base::FilePath(FILE_PATH_LITERAL("axis_aligned.png")),
cc::FuzzyPixelOffByOneComparator(true))); cc::AlphaDiscardingFuzzyPixelOffByOneComparator()));
} }
// This test tests that forcing anti-aliasing off works as expected for // This test tests that forcing anti-aliasing off works as expected for
@@ -3240,7 +3250,7 @@ TEST_P(GPURendererPixelTest, SolidColorDrawQuadForceAntiAliasingOff) {
EXPECT_TRUE(this->RunPixelTest( EXPECT_TRUE(this->RunPixelTest(
&pass_list, &pass_list,
base::FilePath(FILE_PATH_LITERAL("force_anti_aliasing_off.png")), base::FilePath(FILE_PATH_LITERAL("force_anti_aliasing_off.png")),
cc::ExactPixelComparator(/*discard_alpha=*/true))); cc::AlphaDiscardingExactPixelComparator()));
} }
// This test tests that forcing anti-aliasing off works as expected for // This test tests that forcing anti-aliasing off works as expected for
@@ -3299,7 +3309,7 @@ TEST_P(GPURendererPixelTest, RenderPassDrawQuadForceAntiAliasingOff) {
EXPECT_TRUE(this->RunPixelTest( EXPECT_TRUE(this->RunPixelTest(
&pass_list, &pass_list,
base::FilePath(FILE_PATH_LITERAL("force_anti_aliasing_off.png")), base::FilePath(FILE_PATH_LITERAL("force_anti_aliasing_off.png")),
cc::ExactPixelComparator(/*discard_alpha=*/true))); cc::AlphaDiscardingExactPixelComparator()));
} }
// This test tests that forcing anti-aliasing off works as expected for // This test tests that forcing anti-aliasing off works as expected for
@@ -3367,7 +3377,7 @@ TEST_P(GPURendererPixelTest, TileDrawQuadForceAntiAliasingOff) {
EXPECT_TRUE(this->RunPixelTest( EXPECT_TRUE(this->RunPixelTest(
&pass_list, &pass_list,
base::FilePath(FILE_PATH_LITERAL("force_anti_aliasing_off.png")), base::FilePath(FILE_PATH_LITERAL("force_anti_aliasing_off.png")),
cc::ExactPixelComparator(/*discard_alpha=*/true))); cc::AlphaDiscardingExactPixelComparator()));
} }
// This test tests that forcing anti-aliasing off works as expected while // This test tests that forcing anti-aliasing off works as expected while
@@ -3397,7 +3407,7 @@ TEST_P(GPURendererPixelTest, BlendingWithoutAntiAliasing) {
EXPECT_TRUE(this->RunPixelTest( EXPECT_TRUE(this->RunPixelTest(
&pass_list, &pass_list,
base::FilePath(FILE_PATH_LITERAL("translucent_quads_no_aa.png")), base::FilePath(FILE_PATH_LITERAL("translucent_quads_no_aa.png")),
cc::ExactPixelComparator(/*discard_alpha=*/true))); cc::AlphaDiscardingExactPixelComparator()));
} }
TEST_P(GPURendererPixelTest, TrilinearFiltering) { TEST_P(GPURendererPixelTest, TrilinearFiltering) {
@@ -3456,12 +3466,12 @@ TEST_P(GPURendererPixelTest, TrilinearFiltering) {
EXPECT_TRUE(this->RunPixelTest( EXPECT_TRUE(this->RunPixelTest(
&pass_list, &pass_list,
base::FilePath(FILE_PATH_LITERAL("trilinear_filtering_skia_vk.png")), base::FilePath(FILE_PATH_LITERAL("trilinear_filtering_skia_vk.png")),
cc::ExactPixelComparator(true))); cc::AlphaDiscardingExactPixelComparator()));
} else { } else {
EXPECT_TRUE(this->RunPixelTest( EXPECT_TRUE(this->RunPixelTest(
&pass_list, &pass_list,
base::FilePath(FILE_PATH_LITERAL("trilinear_filtering.png")), base::FilePath(FILE_PATH_LITERAL("trilinear_filtering.png")),
cc::ExactPixelComparator(true))); cc::AlphaDiscardingExactPixelComparator()));
} }
} }
@@ -3542,7 +3552,7 @@ TEST_F(SoftwareRendererPixelTest, PictureDrawQuadIdentityScale) {
EXPECT_TRUE(this->RunPixelTest( EXPECT_TRUE(this->RunPixelTest(
&pass_list, &pass_list,
base::FilePath(FILE_PATH_LITERAL("green_with_blue_corner.png")), base::FilePath(FILE_PATH_LITERAL("green_with_blue_corner.png")),
cc::ExactPixelComparator(true))); cc::AlphaDiscardingExactPixelComparator()));
} }
// Not WithSkiaGPUBackend since that path currently requires tiles for opacity. // Not WithSkiaGPUBackend since that path currently requires tiles for opacity.
@@ -3602,7 +3612,7 @@ TEST_F(SoftwareRendererPixelTest, PictureDrawQuadOpacity) {
EXPECT_TRUE(this->RunPixelTest( EXPECT_TRUE(this->RunPixelTest(
&pass_list, base::FilePath(FILE_PATH_LITERAL("green_alpha.png")), &pass_list, base::FilePath(FILE_PATH_LITERAL("green_alpha.png")),
cc::FuzzyPixelOffByOneComparator(true))); cc::AlphaDiscardingFuzzyPixelOffByOneComparator()));
} }
TEST_F(SoftwareRendererPixelTest, PictureDrawQuadOpacityWithAlpha) { TEST_F(SoftwareRendererPixelTest, PictureDrawQuadOpacityWithAlpha) {
@@ -3659,9 +3669,9 @@ TEST_F(SoftwareRendererPixelTest, PictureDrawQuadOpacityWithAlpha) {
AggregatedRenderPassList pass_list; AggregatedRenderPassList pass_list;
pass_list.push_back(std::move(pass)); pass_list.push_back(std::move(pass));
EXPECT_TRUE(this->RunPixelTest(&pass_list, EXPECT_TRUE(this->RunPixelTest(
base::FilePath(FILE_PATH_LITERAL("white.png")), &pass_list, base::FilePath(FILE_PATH_LITERAL("white.png")),
cc::FuzzyPixelOffByOneComparator(true))); cc::AlphaDiscardingFuzzyPixelOffByOneComparator()));
} }
void draw_point_color(SkCanvas* canvas, void draw_point_color(SkCanvas* canvas,
@@ -3721,7 +3731,7 @@ TEST_F(SoftwareRendererPixelTest, PictureDrawQuadDisableImageFiltering) {
EXPECT_TRUE(this->RunPixelTest( EXPECT_TRUE(this->RunPixelTest(
&pass_list, &pass_list,
base::FilePath(FILE_PATH_LITERAL("four_blue_green_checkers.png")), base::FilePath(FILE_PATH_LITERAL("four_blue_green_checkers.png")),
cc::ExactPixelComparator(true))); cc::AlphaDiscardingExactPixelComparator()));
} }
// This disables filtering by setting |nearest_neighbor| on the // This disables filtering by setting |nearest_neighbor| on the
@@ -3770,7 +3780,7 @@ TEST_F(SoftwareRendererPixelTest, PictureDrawQuadNearestNeighbor) {
EXPECT_TRUE(this->RunPixelTest( EXPECT_TRUE(this->RunPixelTest(
&pass_list, &pass_list,
base::FilePath(FILE_PATH_LITERAL("four_blue_green_checkers.png")), base::FilePath(FILE_PATH_LITERAL("four_blue_green_checkers.png")),
cc::ExactPixelComparator(true))); cc::AlphaDiscardingExactPixelComparator()));
} }
// This disables filtering by setting |nearest_neighbor| on the // This disables filtering by setting |nearest_neighbor| on the
@@ -3832,7 +3842,7 @@ TEST_P(RendererPixelTest, TileDrawQuadNearestNeighbor) {
EXPECT_TRUE(this->RunPixelTest( EXPECT_TRUE(this->RunPixelTest(
&pass_list, &pass_list,
base::FilePath(FILE_PATH_LITERAL("four_blue_green_checkers.png")), base::FilePath(FILE_PATH_LITERAL("four_blue_green_checkers.png")),
cc::ExactPixelComparator(true))); cc::AlphaDiscardingExactPixelComparator()));
} }
// This disables filtering by setting |nearest_neighbor| to true on the // This disables filtering by setting |nearest_neighbor| to true on the
@@ -3884,7 +3894,7 @@ TEST_F(SoftwareRendererPixelTest, TextureDrawQuadNearestNeighbor) {
EXPECT_TRUE(this->RunPixelTest( EXPECT_TRUE(this->RunPixelTest(
&pass_list, &pass_list,
base::FilePath(FILE_PATH_LITERAL("four_blue_green_checkers.png")), base::FilePath(FILE_PATH_LITERAL("four_blue_green_checkers.png")),
cc::FuzzyPixelComparator(false, 2.f, 0.f, 256.f, 256, 0.f))); cc::FuzzyPixelComparator().SetErrorPixelsPercentageLimit(2.f)));
} }
// This ensures filtering is enabled by setting |nearest_neighbor| to false on // This ensures filtering is enabled by setting |nearest_neighbor| to false on
@@ -3941,7 +3951,9 @@ TEST_F(SoftwareRendererPixelTest, TextureDrawQuadLinear) {
EXPECT_TRUE(this->RunPixelTest( EXPECT_TRUE(this->RunPixelTest(
&pass_list, &pass_list,
base::FilePath(FILE_PATH_LITERAL("four_blue_green_checkers_linear.png")), base::FilePath(FILE_PATH_LITERAL("four_blue_green_checkers_linear.png")),
cc::FuzzyPixelComparator(false, 100.f, 0.f, 16.f, 16.f, 0.f))); cc::FuzzyPixelComparator()
.SetErrorPixelsPercentageLimit(100.f)
.SetAbsErrorLimit(16)));
} }
TEST_F(SoftwareRendererPixelTest, PictureDrawQuadNonIdentityScale) { TEST_F(SoftwareRendererPixelTest, PictureDrawQuadNonIdentityScale) {
@@ -4076,7 +4088,7 @@ TEST_F(SoftwareRendererPixelTest, PictureDrawQuadNonIdentityScale) {
EXPECT_TRUE(this->RunPixelTest( EXPECT_TRUE(this->RunPixelTest(
&pass_list, &pass_list,
base::FilePath(FILE_PATH_LITERAL("four_blue_green_checkers.png")), base::FilePath(FILE_PATH_LITERAL("four_blue_green_checkers.png")),
cc::ExactPixelComparator(true))); cc::AlphaDiscardingExactPixelComparator()));
} }
class RendererPixelTestWithFlippedOutputSurface : public VizPixelTestWithParam { class RendererPixelTestWithFlippedOutputSurface : public VizPixelTestWithParam {
@@ -4138,7 +4150,7 @@ TEST_P(RendererPixelTestWithFlippedOutputSurface, ExplicitFlipTest) {
// right-side up result regardless (i.e., NOT blue_yellow_flipped.png). // right-side up result regardless (i.e., NOT blue_yellow_flipped.png).
EXPECT_TRUE(this->RunPixelTest( EXPECT_TRUE(this->RunPixelTest(
&pass_list, base::FilePath(FILE_PATH_LITERAL("blue_yellow.png")), &pass_list, base::FilePath(FILE_PATH_LITERAL("blue_yellow.png")),
cc::FuzzyPixelOffByOneComparator(true))); cc::AlphaDiscardingFuzzyPixelOffByOneComparator()));
} }
TEST_P(RendererPixelTestWithFlippedOutputSurface, CheckChildPassUnflipped) { TEST_P(RendererPixelTestWithFlippedOutputSurface, CheckChildPassUnflipped) {
@@ -4183,7 +4195,7 @@ TEST_P(RendererPixelTestWithFlippedOutputSurface, CheckChildPassUnflipped) {
EXPECT_TRUE(this->RunPixelTestWithReadbackTarget( EXPECT_TRUE(this->RunPixelTestWithReadbackTarget(
&pass_list, pass_list.front().get(), &pass_list, pass_list.front().get(),
base::FilePath(FILE_PATH_LITERAL("blue_yellow.png")), base::FilePath(FILE_PATH_LITERAL("blue_yellow.png")),
cc::ExactPixelComparator(true))); cc::AlphaDiscardingExactPixelComparator()));
} }
TEST_P(GPURendererPixelTest, CheckReadbackSubset) { TEST_P(GPURendererPixelTest, CheckReadbackSubset) {
@@ -4232,7 +4244,7 @@ TEST_P(GPURendererPixelTest, CheckReadbackSubset) {
EXPECT_TRUE(this->RunPixelTestWithReadbackTargetAndArea( EXPECT_TRUE(this->RunPixelTestWithReadbackTargetAndArea(
&pass_list, pass_list.front().get(), &pass_list, pass_list.front().get(),
base::FilePath(FILE_PATH_LITERAL("green_small_with_blue_corner.png")), base::FilePath(FILE_PATH_LITERAL("green_small_with_blue_corner.png")),
cc::ExactPixelComparator(true), &capture_rect)); cc::AlphaDiscardingExactPixelComparator(), &capture_rect));
} }
TEST_P(GPURendererPixelTest, TextureQuadBatching) { TEST_P(GPURendererPixelTest, TextureQuadBatching) {
@@ -4317,7 +4329,7 @@ TEST_P(GPURendererPixelTest, TextureQuadBatching) {
EXPECT_TRUE(this->RunPixelTest( EXPECT_TRUE(this->RunPixelTest(
&pass_list, base::FilePath(FILE_PATH_LITERAL("spiral.png")), &pass_list, base::FilePath(FILE_PATH_LITERAL("spiral.png")),
cc::FuzzyPixelOffByOneComparator(true))); cc::AlphaDiscardingFuzzyPixelOffByOneComparator()));
} }
TEST_P(GPURendererPixelTest, TileQuadClamping) { TEST_P(GPURendererPixelTest, TileQuadClamping) {
@@ -4390,7 +4402,7 @@ TEST_P(GPURendererPixelTest, TileQuadClamping) {
EXPECT_TRUE(this->RunPixelTest(&pass_list, EXPECT_TRUE(this->RunPixelTest(&pass_list,
base::FilePath(FILE_PATH_LITERAL("green.png")), base::FilePath(FILE_PATH_LITERAL("green.png")),
cc::ExactPixelComparator(true))); cc::AlphaDiscardingExactPixelComparator()));
} }
TEST_P(RendererPixelTest, RoundedCornerSimpleSolidDrawQuad) { TEST_P(RendererPixelTest, RoundedCornerSimpleSolidDrawQuad) {
@@ -4429,7 +4441,8 @@ TEST_P(RendererPixelTest, RoundedCornerSimpleSolidDrawQuad) {
EXPECT_TRUE(this->RunPixelTest( EXPECT_TRUE(this->RunPixelTest(
&pass_list, &pass_list,
base::FilePath(FILE_PATH_LITERAL("rounded_corner_simple.png")), base::FilePath(FILE_PATH_LITERAL("rounded_corner_simple.png")),
cc::FuzzyPixelComparator(true, 0.55f, 0.f, 255.f, 255, 0))); cc::FuzzyPixelComparator().DiscardAlpha().SetErrorPixelsPercentageLimit(
0.55f)));
} }
TEST_P(GPURendererPixelTest, RoundedCornerSimpleTextureDrawQuad) { TEST_P(GPURendererPixelTest, RoundedCornerSimpleTextureDrawQuad) {
@@ -4488,7 +4501,8 @@ TEST_P(GPURendererPixelTest, RoundedCornerSimpleTextureDrawQuad) {
EXPECT_TRUE(this->RunPixelTest( EXPECT_TRUE(this->RunPixelTest(
&pass_list, &pass_list,
base::FilePath(FILE_PATH_LITERAL("rounded_corner_simple.png")), base::FilePath(FILE_PATH_LITERAL("rounded_corner_simple.png")),
cc::FuzzyPixelComparator(true, 0.6f, 0.f, 255.f, 255, 0))); cc::FuzzyPixelComparator().DiscardAlpha().SetErrorPixelsPercentageLimit(
0.6f)));
} }
TEST_P(RendererPixelTest, RoundedCornerOnRenderPass) { TEST_P(RendererPixelTest, RoundedCornerOnRenderPass) {
@@ -4548,8 +4562,8 @@ TEST_P(RendererPixelTest, RoundedCornerOnRenderPass) {
base::FilePath path(FILE_PATH_LITERAL("rounded_corner_render_pass_.png")); base::FilePath path(FILE_PATH_LITERAL("rounded_corner_render_pass_.png"));
path = path.InsertBeforeExtensionASCII(this->renderer_str()); path = path.InsertBeforeExtensionASCII(this->renderer_str());
EXPECT_TRUE(this->RunPixelTest(&pass_list, path, EXPECT_TRUE(this->RunPixelTest(
cc::FuzzyPixelOffByOneComparator(true))); &pass_list, path, cc::AlphaDiscardingFuzzyPixelOffByOneComparator()));
} }
TEST_P(GPURendererPixelTest, LinearGradientOnRenderPass) { TEST_P(GPURendererPixelTest, LinearGradientOnRenderPass) {
@@ -4593,12 +4607,8 @@ TEST_P(GPURendererPixelTest, LinearGradientOnRenderPass) {
EXPECT_TRUE(this->RunPixelTest( EXPECT_TRUE(this->RunPixelTest(
&pass_list, &pass_list,
base::FilePath(FILE_PATH_LITERAL("linear_gradient_render_pass.png")), base::FilePath(FILE_PATH_LITERAL("linear_gradient_render_pass.png")),
cc::FuzzyPixelComparator(/*discard_alpha=*/true, cc::FuzzyPixelComparator().DiscardAlpha().SetErrorPixelsPercentageLimit(
/*error_pixels_percentage_limit=*/0.6f, 0.6f)));
/*small_error_pixels_percentage_limit=*/0.f,
/*avg_abs_error_limit=*/255.f,
/*max_abs_error_limit=*/255,
/*small_error_threshold=*/0)));
} }
TEST_P(GPURendererPixelTest, MultiLinearGradientOnRenderPass) { TEST_P(GPURendererPixelTest, MultiLinearGradientOnRenderPass) {
@@ -4663,12 +4673,8 @@ TEST_P(GPURendererPixelTest, MultiLinearGradientOnRenderPass) {
&pass_list, &pass_list,
base::FilePath( base::FilePath(
FILE_PATH_LITERAL("multi_linear_gradient_render_pass.png")), FILE_PATH_LITERAL("multi_linear_gradient_render_pass.png")),
cc::FuzzyPixelComparator(/*discard_alpha=*/true, cc::FuzzyPixelComparator().DiscardAlpha().SetErrorPixelsPercentageLimit(
/*error_pixels_percentage_limit=*/0.6f, 0.6f)));
/*small_error_pixels_percentage_limit=*/0.f,
/*avg_abs_error_limit=*/255.f,
/*max_abs_error_limit=*/255,
/*small_error_threshold=*/0)));
} }
TEST_P(RendererPixelTest, RoundedCornerMultiRadii) { TEST_P(RendererPixelTest, RoundedCornerMultiRadii) {
@@ -4715,7 +4721,8 @@ TEST_P(RendererPixelTest, RoundedCornerMultiRadii) {
EXPECT_TRUE(this->RunPixelTest( EXPECT_TRUE(this->RunPixelTest(
&pass_list, &pass_list,
base::FilePath(FILE_PATH_LITERAL("rounded_corner_multi_radii.png")), base::FilePath(FILE_PATH_LITERAL("rounded_corner_multi_radii.png")),
cc::FuzzyPixelComparator(true, 0.55f, 0.f, 255.f, 255, 0))); cc::FuzzyPixelComparator().DiscardAlpha().SetErrorPixelsPercentageLimit(
0.55f)));
} }
TEST_P(RendererPixelTest, RoundedCornerMultipleQads) { TEST_P(RendererPixelTest, RoundedCornerMultipleQads) {
@@ -4792,7 +4799,9 @@ TEST_P(RendererPixelTest, RoundedCornerMultipleQads) {
AggregatedRenderPassList pass_list; AggregatedRenderPassList pass_list;
pass_list.push_back(std::move(root_pass)); pass_list.push_back(std::move(root_pass));
cc::FuzzyPixelComparator comparator(true, 0.55f, 0.f, 255.f, 255, 0); auto comparator =
cc::FuzzyPixelComparator().DiscardAlpha().SetErrorPixelsPercentageLimit(
0.55f);
EXPECT_TRUE(this->RunPixelTest( EXPECT_TRUE(this->RunPixelTest(
&pass_list, &pass_list,
base::FilePath(FILE_PATH_LITERAL("rounded_corner_multi_quad.png")), base::FilePath(FILE_PATH_LITERAL("rounded_corner_multi_quad.png")),
@@ -4834,7 +4843,7 @@ TEST_P(RendererPixelTestWithOverdrawFeedback, TranslucentRectangles) {
EXPECT_TRUE(this->RunPixelTest( EXPECT_TRUE(this->RunPixelTest(
&pass_list, &pass_list,
base::FilePath(FILE_PATH_LITERAL("translucent_rectangles.png")), base::FilePath(FILE_PATH_LITERAL("translucent_rectangles.png")),
cc::FuzzyPixelComparator(false, 2.f, 0.f, 256.f, 256, 0.f))); cc::FuzzyPixelComparator().SetErrorPixelsPercentageLimit(2.f)));
} }
INSTANTIATE_TEST_SUITE_P(, INSTANTIATE_TEST_SUITE_P(,
@@ -4990,8 +4999,10 @@ class ColorTransformPixelTest
} }
#endif #endif
cc::FuzzyPixelComparator comparator(false, 100.f, 0.f, avg_abs_error_limit, auto comparator = cc::FuzzyPixelComparator()
max_abs_error_limit, 0); .SetErrorPixelsPercentageLimit(100.f)
.SetAvgAbsErrorLimit(avg_abs_error_limit)
.SetAbsErrorLimit(max_abs_error_limit);
EXPECT_TRUE( EXPECT_TRUE(
this->RunPixelTest(&pass_list, &expected_output_colors, comparator)) this->RunPixelTest(&pass_list, &expected_output_colors, comparator))
<< " src:" << src_color_space_ << ", dst:" << dst_color_space_; << " src:" << src_color_space_ << ", dst:" << dst_color_space_;
@@ -5110,8 +5121,9 @@ class DelegatedInkTest : public VizPixelTestWithParam,
AggregatedRenderPassList pass_list; AggregatedRenderPassList pass_list;
pass_list.push_back(std::move(pass)); pass_list.push_back(std::move(pass));
return this->RunPixelTest(&pass_list, base::FilePath(file), return this->RunPixelTest(
cc::FuzzyPixelOffByOneComparator(true)); &pass_list, base::FilePath(file),
cc::AlphaDiscardingFuzzyPixelOffByOneComparator());
} }
protected: protected:
@@ -5307,7 +5319,7 @@ TEST_P(DelegatedInkWithPredictionTest, DelegatedInkTrailAfterBatchedQuads) {
&pass_list, &pass_list,
base::FilePath( base::FilePath(
FILE_PATH_LITERAL("delegated_ink_trail_on_batched_quads.png")), FILE_PATH_LITERAL("delegated_ink_trail_on_batched_quads.png")),
cc::FuzzyPixelOffByOneComparator(true))); cc::AlphaDiscardingFuzzyPixelOffByOneComparator()));
} }
// Confirm that delegated ink trails are not drawn on non-root render passes. // Confirm that delegated ink trails are not drawn on non-root render passes.
@@ -5354,7 +5366,7 @@ TEST_P(DelegatedInkWithPredictionTest, SimpleTrailNonRootRenderPass) {
EXPECT_TRUE(this->RunPixelTestWithReadbackTarget( EXPECT_TRUE(this->RunPixelTestWithReadbackTarget(
&pass_list, child_pass_ptr, &pass_list, child_pass_ptr,
base::FilePath(FILE_PATH_LITERAL("green.png")), base::FilePath(FILE_PATH_LITERAL("green.png")),
cc::ExactPixelComparator(true))); cc::AlphaDiscardingExactPixelComparator()));
} }
// Draw two different trails that are made up of sets of DelegatedInkPoints with // Draw two different trails that are made up of sets of DelegatedInkPoints with

@@ -50,8 +50,10 @@ constexpr float kAvgAbsoluteErrorLimit = 8.f;
constexpr int kMaxAbsoluteErrorLimit = 32; constexpr int kMaxAbsoluteErrorLimit = 32;
cc::FuzzyPixelComparator GetDefaultFuzzyPixelComparator() { cc::FuzzyPixelComparator GetDefaultFuzzyPixelComparator() {
return cc::FuzzyPixelComparator(false, 100.f, 0.f, kAvgAbsoluteErrorLimit, return cc::FuzzyPixelComparator()
kMaxAbsoluteErrorLimit, 0); .SetErrorPixelsPercentageLimit(100.f)
.SetAvgAbsErrorLimit(kAvgAbsoluteErrorLimit)
.SetAbsErrorLimit(kMaxAbsoluteErrorLimit);
} }
base::FilePath GetTestFilePath(const base::FilePath::CharType* basename) { base::FilePath GetTestFilePath(const base::FilePath::CharType* basename) {
@@ -439,8 +441,7 @@ TEST_P(SkiaReadbackPixelTestRGBA, ExecutesCopyRequest) {
EXPECT_TRUE(cc::WritePNGFile(actual, expected_path, false)); EXPECT_TRUE(cc::WritePNGFile(actual, expected_path, false));
} }
if (!cc::MatchesPNGFile(actual, expected_path, if (!cc::MatchesPNGFile(actual, expected_path, cc::ExactPixelComparator())) {
cc::ExactPixelComparator(false))) {
LOG(ERROR) << "Entire source: " << cc::GetPNGDataUrl(GetSourceBitmap()); LOG(ERROR) << "Entire source: " << cc::GetPNGDataUrl(GetSourceBitmap());
ADD_FAILURE(); ADD_FAILURE();
} }

@@ -114,8 +114,7 @@ TEST_P(SurfaceAggregatorPixelTest, DrawSimpleFrame) {
auto aggregated_frame = aggregator.Aggregate( auto aggregated_frame = aggregator.Aggregate(
root_surface_id, this->GetNextDisplayTime(), gfx::OVERLAY_TRANSFORM_NONE); root_surface_id, this->GetNextDisplayTime(), gfx::OVERLAY_TRANSFORM_NONE);
bool discard_alpha = false; cc::ExactPixelComparator pixel_comparator;
cc::ExactPixelComparator pixel_comparator(discard_alpha);
auto* pass_list = &aggregated_frame.render_pass_list; auto* pass_list = &aggregated_frame.render_pass_list;
EXPECT_TRUE(this->RunPixelTest(pass_list, EXPECT_TRUE(this->RunPixelTest(pass_list,
base::FilePath(FILE_PATH_LITERAL("green.png")), base::FilePath(FILE_PATH_LITERAL("green.png")),
@@ -193,8 +192,7 @@ TEST_P(SurfaceAggregatorPixelTest, DrawSimpleAggregatedFrame) {
auto aggregated_frame = aggregator.Aggregate( auto aggregated_frame = aggregator.Aggregate(
root_surface_id, this->GetNextDisplayTime(), gfx::OVERLAY_TRANSFORM_NONE); root_surface_id, this->GetNextDisplayTime(), gfx::OVERLAY_TRANSFORM_NONE);
bool discard_alpha = false; cc::ExactPixelComparator pixel_comparator;
cc::ExactPixelComparator pixel_comparator(discard_alpha);
auto* pass_list = &aggregated_frame.render_pass_list; auto* pass_list = &aggregated_frame.render_pass_list;
EXPECT_TRUE(this->RunPixelTest( EXPECT_TRUE(this->RunPixelTest(
pass_list, base::FilePath(FILE_PATH_LITERAL("blue_yellow.png")), pass_list, base::FilePath(FILE_PATH_LITERAL("blue_yellow.png")),
@@ -327,8 +325,7 @@ TEST_P(SurfaceAggregatorPixelTest, DrawAggregatedFrameWithSurfaceTransforms) {
auto aggregated_frame = aggregator.Aggregate( auto aggregated_frame = aggregator.Aggregate(
root_surface_id, this->GetNextDisplayTime(), gfx::OVERLAY_TRANSFORM_NONE); root_surface_id, this->GetNextDisplayTime(), gfx::OVERLAY_TRANSFORM_NONE);
bool discard_alpha = false; cc::ExactPixelComparator pixel_comparator;
cc::ExactPixelComparator pixel_comparator(discard_alpha);
auto* pass_list = &aggregated_frame.render_pass_list; auto* pass_list = &aggregated_frame.render_pass_list;
EXPECT_TRUE(this->RunPixelTest( EXPECT_TRUE(this->RunPixelTest(
pass_list, pass_list,
@@ -380,8 +377,7 @@ TEST_P(SurfaceAggregatorPixelTest, DrawAndEraseDelegatedInkTrail) {
auto aggregated_frame = aggregator.Aggregate( auto aggregated_frame = aggregator.Aggregate(
root_surface_id, this->GetNextDisplayTime(), gfx::OVERLAY_TRANSFORM_NONE); root_surface_id, this->GetNextDisplayTime(), gfx::OVERLAY_TRANSFORM_NONE);
bool discard_alpha = false; cc::FuzzyPixelOffByOneComparator pixel_comparator;
cc::FuzzyPixelOffByOneComparator pixel_comparator(discard_alpha);
auto* pass_list = &aggregated_frame.render_pass_list; auto* pass_list = &aggregated_frame.render_pass_list;
EXPECT_TRUE(this->RunPixelTest( EXPECT_TRUE(this->RunPixelTest(
pass_list, base::FilePath(FILE_PATH_LITERAL("delegated_ink_trail.png")), pass_list, base::FilePath(FILE_PATH_LITERAL("delegated_ink_trail.png")),

@@ -133,8 +133,8 @@ void SkiaOutputSurfaceImplTest::CopyRequestCallbackOnGpuThread(
output_rect.width(), output_rect.height(), color_space.ToSkColorSpace())); output_rect.width(), output_rect.height(), color_space.ToSkColorSpace()));
expected.eraseColor(kOutputColor, /*colorSpace=*/nullptr); expected.eraseColor(kOutputColor, /*colorSpace=*/nullptr);
EXPECT_TRUE(cc::MatchesBitmap(result_bitmap, expected, EXPECT_TRUE(
cc::ExactPixelComparator(false))); cc::MatchesBitmap(result_bitmap, expected, cc::ExactPixelComparator()));
UnblockMainThread(); UnblockMainThread();
} }

@@ -448,9 +448,10 @@ class VideoCaptureOverlayRenderTest
// (16/255 for YUV tests). The YUV tests allow for more error due to the // (16/255 for YUV tests). The YUV tests allow for more error due to the
// expected errors introduced by both color space (dynamic range) and format // expected errors introduced by both color space (dynamic range) and format
// (chroma subsampling) conversion. // (chroma subsampling) conversion.
cc::FuzzyPixelComparator comparator(false, 100.0f, 0.0f, auto comparator = cc::FuzzyPixelComparator()
is_argb_test() ? 1.0f : 16.0f, .SetErrorPixelsPercentageLimit(100.0f)
is_argb_test() ? 1 : 64, 0); .SetAvgAbsErrorLimit(is_argb_test() ? 1.0f : 16.0f)
.SetAbsErrorLimit(is_argb_test() ? 1 : 64);
const bool matches_golden_file = const bool matches_golden_file =
cc::MatchesPNGFile(canonical_bitmap, golden_file_path, comparator); cc::MatchesPNGFile(canonical_bitmap, golden_file_path, comparator);
// If MatchesPNGFile() returned false, it will have LOG(ERROR)'ed the // If MatchesPNGFile() returned false, it will have LOG(ERROR)'ed the

@@ -101,30 +101,26 @@ class FormControlsBrowserTest : public ContentBrowserTest {
// This fuzzy pixel comparator handles several mac behaviors: // This fuzzy pixel comparator handles several mac behaviors:
// - Different font rendering after 10.14 // - Different font rendering after 10.14
// - Slight differences in radio and checkbox rendering in 10.15 // - Slight differences in radio and checkbox rendering in 10.15
// - Tiny errors (difference <= 1) are ignored for more pixels // TODO(wangxianzhu): Tighten these parameters.
cc::FuzzyPixelComparator comparator( auto comparator = cc::FuzzyPixelComparator()
/* discard_alpha */ true, .DiscardAlpha()
/* error_pixels_percentage_limit */ 26.f, .SetErrorPixelsPercentageLimit(26.f)
/* small_error_pixels_percentage_limit */ 0.f, .SetAvgAbsErrorLimit(20.f)
/* avg_abs_error_limit */ 20.f, .SetAbsErrorLimit(120);
/* max_abs_error_limit */ 120.f,
/* small_error_threshold */ 0);
#elif BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_WIN) || (OS_LINUX) || \ #elif BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_WIN) || (OS_LINUX) || \
BUILDFLAG(IS_FUCHSIA) BUILDFLAG(IS_FUCHSIA)
// Different versions of android may have slight differences in rendering. // Different versions of android may have slight differences in rendering.
// Some versions have more significant differences than others, which are // Some versions have more significant differences than others, which are
// tracked separately in separate baseline image files. The less significant // tracked separately in separate baseline image files. The less significant
// differences are accommodated for with this fuzzy pixel comparator. // differences are accommodated for with this fuzzy pixel comparator.
// This also applies to different versions of Windows. // This also applies to different versions of other OSes.
cc::FuzzyPixelComparator comparator( auto comparator = cc::FuzzyPixelComparator()
/* discard_alpha */ true, .DiscardAlpha()
/* error_pixels_percentage_limit */ 11.f, .SetErrorPixelsPercentageLimit(11.f)
/* small_error_pixels_percentage_limit */ 0.f, .SetAvgAbsErrorLimit(5.f)
/* avg_abs_error_limit */ 5.f, .SetAbsErrorLimit(140);
/* max_abs_error_limit */ 140.f,
/* small_error_threshold */ 0);
#else #else
cc::ExactPixelComparator comparator(/* disard_alpha */ true); cc::AlphaDiscardingExactPixelComparator comparator;
#endif #endif
EXPECT_TRUE(CompareWebContentsOutputToReference( EXPECT_TRUE(CompareWebContentsOutputToReference(
shell()->web_contents(), golden_filepath, shell()->web_contents(), golden_filepath,

@@ -192,9 +192,8 @@ TEST(RepackUtilsTest, UnpackStride) {
// Result bitmap should have red pixels after. // Result bitmap should have red pixels after.
UnpackPixelDataWithStride(size, repacked_data, expected_stride, pixmap); UnpackPixelDataWithStride(size, repacked_data, expected_stride, pixmap);
EXPECT_TRUE( EXPECT_TRUE(cc::MatchesBitmap(result_bitmap, source_bitmap,
cc::MatchesBitmap(result_bitmap, source_bitmap, cc::ExactPixelComparator()));
cc::ExactPixelComparator(/*discard_alpha=*/false)));
} }
TEST(RepackUtilsTest, SwizzleRedAndBlue) { TEST(RepackUtilsTest, SwizzleRedAndBlue) {
@@ -210,9 +209,8 @@ TEST(RepackUtilsTest, SwizzleRedAndBlue) {
SkBitmap expected_bitmap = SkBitmap expected_bitmap =
MakeSolidColorBitmap(size, kRGBA_8888_SkColorType, SK_ColorBLUE); MakeSolidColorBitmap(size, kRGBA_8888_SkColorType, SK_ColorBLUE);
EXPECT_TRUE( EXPECT_TRUE(cc::MatchesBitmap(swizzled_bitmap, expected_bitmap,
cc::MatchesBitmap(swizzled_bitmap, expected_bitmap, cc::ExactPixelComparator()));
cc::ExactPixelComparator(/*discard_alpha=*/false)));
} }
} // namespace } // namespace

@@ -638,8 +638,8 @@ TEST_P(GLTextureImageBackingFactoryWithReadbackTest, ReadbackToMemory) {
SkPixmap result_pixmap; SkPixmap result_pixmap;
ASSERT_TRUE(result_bitmap.peekPixels(&result_pixmap)); ASSERT_TRUE(result_bitmap.peekPixels(&result_pixmap));
ASSERT_TRUE(backing->ReadbackToMemory(result_pixmap)); ASSERT_TRUE(backing->ReadbackToMemory(result_pixmap));
EXPECT_TRUE(cc::MatchesBitmap(result_bitmap, bitmap, EXPECT_TRUE(
cc::ExactPixelComparator(false))); cc::MatchesBitmap(result_bitmap, bitmap, cc::ExactPixelComparator()));
} }
{ {
@@ -650,8 +650,8 @@ TEST_P(GLTextureImageBackingFactoryWithReadbackTest, ReadbackToMemory) {
SkPixmap result_pixmap; SkPixmap result_pixmap;
ASSERT_TRUE(result_bitmap.peekPixels(&result_pixmap)); ASSERT_TRUE(result_bitmap.peekPixels(&result_pixmap));
ASSERT_TRUE(backing->ReadbackToMemory(result_pixmap)); ASSERT_TRUE(backing->ReadbackToMemory(result_pixmap));
EXPECT_TRUE(cc::MatchesBitmap(result_bitmap, bitmap, EXPECT_TRUE(
cc::ExactPixelComparator(false))); cc::MatchesBitmap(result_bitmap, bitmap, cc::ExactPixelComparator()));
} }
} }

@@ -620,9 +620,8 @@ class HeadlessWebContentsBeginFrameControlViewportTest
SkImageInfo::MakeN32(300, 300, kOpaque_SkAlphaType), /*rowBytes=*/0); SkImageInfo::MakeN32(300, 300, kOpaque_SkAlphaType), /*rowBytes=*/0);
expected_bitmap.eraseColor(SkColorSetRGB(0x00, 0x00, 0xff)); expected_bitmap.eraseColor(SkColorSetRGB(0x00, 0x00, 0xff));
EXPECT_TRUE( EXPECT_TRUE(cc::MatchesBitmap(result_bitmap, expected_bitmap,
cc::MatchesBitmap(result_bitmap, expected_bitmap, cc::ExactPixelComparator()));
cc::ExactPixelComparator(/*discard_alpha=*/false)));
// Post completion to avoid deleting the WebContents on the same callstack // Post completion to avoid deleting the WebContents on the same callstack
// as frame finished callback. // as frame finished callback.

@@ -123,9 +123,8 @@ class PaintManagerTest : public testing::Test {
ASSERT_TRUE(expected_surface->makeImageSnapshot()->asLegacyBitmap( ASSERT_TRUE(expected_surface->makeImageSnapshot()->asLegacyBitmap(
&expected_bitmap)); &expected_bitmap));
EXPECT_TRUE( EXPECT_TRUE(cc::MatchesBitmap(snapshot_bitmap, expected_bitmap,
cc::MatchesBitmap(snapshot_bitmap, expected_bitmap, cc::ExactPixelComparator()));
cc::ExactPixelComparator(/*discard_alpha=*/false)));
} }
void TestScroll(const gfx::Vector2d& scroll_amount, void TestScroll(const gfx::Vector2d& scroll_amount,

@@ -498,9 +498,8 @@ class PdfViewWebPluginTest : public PdfViewWebPluginWithoutInitializeTest {
// color. // color.
SkBitmap expected_bitmap = GenerateExpectedBitmapForPaint( SkBitmap expected_bitmap = GenerateExpectedBitmapForPaint(
expected_clipped_rect, plugin_->GetBackgroundColor()); expected_clipped_rect, plugin_->GetBackgroundColor());
EXPECT_TRUE( EXPECT_TRUE(cc::MatchesBitmap(canvas_.GetBitmap(), expected_bitmap,
cc::MatchesBitmap(canvas_.GetBitmap(), expected_bitmap, cc::ExactPixelComparator()))
cc::ExactPixelComparator(/*discard_alpha=*/false)))
<< "Failure at device scale of " << device_scale << ", window rect of " << "Failure at device scale of " << device_scale << ", window rect of "
<< window_rect.ToString(); << window_rect.ToString();
} }
@@ -520,9 +519,8 @@ class PdfViewWebPluginTest : public PdfViewWebPluginWithoutInitializeTest {
// Expect the clipped area on canvas to be filled with `kPaintColor`. // Expect the clipped area on canvas to be filled with `kPaintColor`.
SkBitmap expected_bitmap = SkBitmap expected_bitmap =
GenerateExpectedBitmapForPaint(expected_clipped_rect, kPaintColor); GenerateExpectedBitmapForPaint(expected_clipped_rect, kPaintColor);
EXPECT_TRUE( EXPECT_TRUE(cc::MatchesBitmap(canvas_.GetBitmap(), expected_bitmap,
cc::MatchesBitmap(canvas_.GetBitmap(), expected_bitmap, cc::ExactPixelComparator()))
cc::ExactPixelComparator(/*discard_alpha=*/false)))
<< "Failure at device scale of " << device_scale << ", window rect of " << "Failure at device scale of " << device_scale << ", window rect of "
<< window_rect.ToString(); << window_rect.ToString();
} }

@@ -39,7 +39,7 @@ testing::AssertionResult MatchesPngFile(
return testing::AssertionFailure() << "Reference: " << expected_png_file; return testing::AssertionFailure() << "Reference: " << expected_png_file;
if (!cc::MatchesPNGFile(actual_bitmap, GetTestDataFilePath(expected_png_file), if (!cc::MatchesPNGFile(actual_bitmap, GetTestDataFilePath(expected_png_file),
cc::ExactPixelComparator(/*discard_alpha=*/false))) { cc::ExactPixelComparator())) {
return testing::AssertionFailure() << "Reference: " << expected_png_file; return testing::AssertionFailure() << "Reference: " << expected_png_file;
} }

@@ -1768,7 +1768,7 @@ TEST_F(LayerWithRealCompositorTest, DrawAlphaBlendedPixels) {
original_bitmap.allocPixels(bitmap.info()); original_bitmap.allocPixels(bitmap.info());
original_bitmap.eraseColor(blend_color); original_bitmap.eraseColor(blend_color);
cc::FuzzyPixelOffByOneComparator comparator(false); cc::FuzzyPixelOffByOneComparator comparator;
EXPECT_TRUE(comparator.Compare(bitmap, original_bitmap)); EXPECT_TRUE(comparator.Compare(bitmap, original_bitmap));
} }
@@ -1948,42 +1948,48 @@ TEST_F(LayerWithRealCompositorTest, ModifyHierarchy) {
ReadPixels(&bitmap); ReadPixels(&bitmap);
ASSERT_FALSE(bitmap.empty()); ASSERT_FALSE(bitmap.empty());
// WritePNGFile(bitmap, ref_img1); // WritePNGFile(bitmap, ref_img1);
EXPECT_TRUE(MatchesPNGFile(bitmap, ref_img1, cc::ExactPixelComparator(true))); EXPECT_TRUE(MatchesPNGFile(bitmap, ref_img1,
cc::AlphaDiscardingExactPixelComparator()));
l0->StackAtTop(l11.get()); l0->StackAtTop(l11.get());
DrawTree(l0.get()); DrawTree(l0.get());
ReadPixels(&bitmap); ReadPixels(&bitmap);
ASSERT_FALSE(bitmap.empty()); ASSERT_FALSE(bitmap.empty());
// WritePNGFile(bitmap, ref_img2); // WritePNGFile(bitmap, ref_img2);
EXPECT_TRUE(MatchesPNGFile(bitmap, ref_img2, cc::ExactPixelComparator(true))); EXPECT_TRUE(MatchesPNGFile(bitmap, ref_img2,
cc::AlphaDiscardingExactPixelComparator()));
// should restore to original configuration // should restore to original configuration
l0->StackAbove(l12.get(), l11.get()); l0->StackAbove(l12.get(), l11.get());
DrawTree(l0.get()); DrawTree(l0.get());
ReadPixels(&bitmap); ReadPixels(&bitmap);
ASSERT_FALSE(bitmap.empty()); ASSERT_FALSE(bitmap.empty());
EXPECT_TRUE(MatchesPNGFile(bitmap, ref_img1, cc::ExactPixelComparator(true))); EXPECT_TRUE(MatchesPNGFile(bitmap, ref_img1,
cc::AlphaDiscardingExactPixelComparator()));
// l11 back to front // l11 back to front
l0->StackAtTop(l11.get()); l0->StackAtTop(l11.get());
DrawTree(l0.get()); DrawTree(l0.get());
ReadPixels(&bitmap); ReadPixels(&bitmap);
ASSERT_FALSE(bitmap.empty()); ASSERT_FALSE(bitmap.empty());
EXPECT_TRUE(MatchesPNGFile(bitmap, ref_img2, cc::ExactPixelComparator(true))); EXPECT_TRUE(MatchesPNGFile(bitmap, ref_img2,
cc::AlphaDiscardingExactPixelComparator()));
// should restore to original configuration // should restore to original configuration
l0->StackAbove(l12.get(), l11.get()); l0->StackAbove(l12.get(), l11.get());
DrawTree(l0.get()); DrawTree(l0.get());
ReadPixels(&bitmap); ReadPixels(&bitmap);
ASSERT_FALSE(bitmap.empty()); ASSERT_FALSE(bitmap.empty());
EXPECT_TRUE(MatchesPNGFile(bitmap, ref_img1, cc::ExactPixelComparator(true))); EXPECT_TRUE(MatchesPNGFile(bitmap, ref_img1,
cc::AlphaDiscardingExactPixelComparator()));
// l11 back to front // l11 back to front
l0->StackAbove(l11.get(), l12.get()); l0->StackAbove(l11.get(), l12.get());
DrawTree(l0.get()); DrawTree(l0.get());
ReadPixels(&bitmap); ReadPixels(&bitmap);
ASSERT_FALSE(bitmap.empty()); ASSERT_FALSE(bitmap.empty());
EXPECT_TRUE(MatchesPNGFile(bitmap, ref_img2, cc::ExactPixelComparator(true))); EXPECT_TRUE(MatchesPNGFile(bitmap, ref_img2,
cc::AlphaDiscardingExactPixelComparator()));
} }
// Checks that basic background blur is working. // Checks that basic background blur is working.
@@ -2015,7 +2021,10 @@ TEST_F(LayerWithRealCompositorTest, BackgroundBlur) {
SkBitmap bitmap; SkBitmap bitmap;
// 25% of image can have up to a difference of 3. // 25% of image can have up to a difference of 3.
cc::FuzzyPixelComparator fuzzy_comparator(true, 25.f, 0.0f, 3.f, 3, 0); auto fuzzy_comparator = cc::FuzzyPixelComparator()
.DiscardAlpha()
.SetErrorPixelsPercentageLimit(25.f)
.SetAbsErrorLimit(3);
l0->Add(l1.get()); l0->Add(l1.get());
l0->Add(l2.get()); l0->Add(l2.get());
@@ -2059,7 +2068,10 @@ TEST_F(LayerWithRealCompositorTest, BackgroundBlurChangeDeviceScale) {
SkBitmap bitmap; SkBitmap bitmap;
// 25% of image can have up to a difference of 3. // 25% of image can have up to a difference of 3.
cc::FuzzyPixelComparator fuzzy_comparator(true, 25.f, 0.0f, 3.f, 3, 0); auto fuzzy_comparator = cc::FuzzyPixelComparator()
.DiscardAlpha()
.SetErrorPixelsPercentageLimit(25.f)
.SetAbsErrorLimit(3);
l0->Add(l1.get()); l0->Add(l1.get());
l0->Add(l2.get()); l0->Add(l2.get());
@@ -2105,7 +2117,8 @@ TEST_F(LayerWithRealCompositorTest, Opacity) {
ReadPixels(&bitmap); ReadPixels(&bitmap);
ASSERT_FALSE(bitmap.empty()); ASSERT_FALSE(bitmap.empty());
// WritePNGFile(bitmap, ref_img); // WritePNGFile(bitmap, ref_img);
EXPECT_TRUE(MatchesPNGFile(bitmap, ref_img, cc::ExactPixelComparator(true))); EXPECT_TRUE(MatchesPNGFile(bitmap, ref_img,
cc::AlphaDiscardingExactPixelComparator()));
} }
namespace { namespace {