From 2f3350d15787c8bf3df6fb8b62abf276e9ec9626 Mon Sep 17 00:00:00 2001 From: Samuel Attard Date: Wed, 29 Apr 2020 13:38:04 -0700 Subject: [PATCH] fix: backport fix for zero-size pixels in blink --- patches/chromium/.patches | 1 + ...on-zero-size_pixel_snap_to_zero_size.patch | 144 ++++++++++++++++++ 2 files changed, 145 insertions(+) create mode 100644 patches/chromium/never_let_a_non-zero-size_pixel_snap_to_zero_size.patch diff --git a/patches/chromium/.patches b/patches/chromium/.patches index 04d5282462f77..50762bdc0305f 100644 --- a/patches/chromium/.patches +++ b/patches/chromium/.patches @@ -93,3 +93,4 @@ feat_allow_embedders_to_add_observers_on_created_hunspell.patch feat_enable_offscreen_rendering_with_viz_compositor.patch when_suspending_context_don_t_clear_handlers.patch use_keepselfalive_on_audiocontext_to_keep_it_alive_until_rendering.patch +never_let_a_non-zero-size_pixel_snap_to_zero_size.patch diff --git a/patches/chromium/never_let_a_non-zero-size_pixel_snap_to_zero_size.patch b/patches/chromium/never_let_a_non-zero-size_pixel_snap_to_zero_size.patch new file mode 100644 index 0000000000000..6943b0d69a362 --- /dev/null +++ b/patches/chromium/never_let_a_non-zero-size_pixel_snap_to_zero_size.patch @@ -0,0 +1,144 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Samuel Attard +Date: Wed, 29 Apr 2020 13:36:00 -0700 +Subject: Never let a non-zero-size pixel snap to zero size + +The logic for LayoutUnit::SnapSizeToPixel maps the size to +the closest pixel align edge given a location. When a size of +width less than 1 happens to straddle a pixel aligned edge this +forces the size to zero. + +Force the size to always be non-zero if the input size is non-zero, +and change PhysicalRect to use the LayoutRect snapping to get +correct cull rects. + +Bug: 793785 +Change-Id: Ia4c30d10c389fb4677006441aac9ee380a7c2f41 +Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1948057 +Commit-Queue: Stephen Chenney +Reviewed-by: Xianzhu Wang +Cr-Commit-Position: refs/heads/master@{#726516} + +diff --git a/third_party/blink/renderer/platform/geometry/layout_unit.h b/third_party/blink/renderer/platform/geometry/layout_unit.h +index eaaff017795237c83b9eb06e8cb70f8598ec5664..8ffe3e11501c005edb233130b231c33e6e79000b 100644 +--- a/third_party/blink/renderer/platform/geometry/layout_unit.h ++++ b/third_party/blink/renderer/platform/geometry/layout_unit.h +@@ -723,7 +723,12 @@ inline float& operator/=(float& a, const LayoutUnit& b) { + + inline int SnapSizeToPixel(LayoutUnit size, LayoutUnit location) { + LayoutUnit fraction = location.Fraction(); +- return (fraction + size).Round() - fraction.Round(); ++ int result = (fraction + size).Round() - fraction.Round(); ++ if (UNLIKELY(result == 0 && ++ std::abs(size.ToFloat()) > LayoutUnit::Epsilon() * 4)) { ++ return size > 0 ? 1 : -1; ++ } ++ return result; + } + + inline int RoundToInt(LayoutUnit value) { +diff --git a/third_party/blink/renderer/platform/geometry/layout_unit_test.cc b/third_party/blink/renderer/platform/geometry/layout_unit_test.cc +index db1fa1f610f195eb7933ab044c26c3b2bae84120..05d4a2f762ede01f712470363ed118f7b37925a4 100644 +--- a/third_party/blink/renderer/platform/geometry/layout_unit_test.cc ++++ b/third_party/blink/renderer/platform/geometry/layout_unit_test.cc +@@ -155,8 +155,20 @@ TEST(LayoutUnitTest, LayoutUnitSnapSizeToPixel) { + EXPECT_EQ(1, SnapSizeToPixel(LayoutUnit(1.5), LayoutUnit(0.99))); + EXPECT_EQ(2, SnapSizeToPixel(LayoutUnit(1.5), LayoutUnit(1))); + +- EXPECT_EQ(0, SnapSizeToPixel(LayoutUnit(0.5), LayoutUnit(1.5))); +- EXPECT_EQ(0, SnapSizeToPixel(LayoutUnit(0.99), LayoutUnit(1.5))); ++ // 0.046875 is 3/64, lower than 4 * LayoutUnit::Epsilon() ++ EXPECT_EQ(0, SnapSizeToPixel(LayoutUnit(0.046875), LayoutUnit(0))); ++ // 0.078125 is 5/64, higher than 4 * LayoutUnit::Epsilon() ++ EXPECT_EQ(1, SnapSizeToPixel(LayoutUnit(0.078125), LayoutUnit(0))); ++ ++ // Negative versions ++ EXPECT_EQ(0, SnapSizeToPixel(LayoutUnit(-0.046875), LayoutUnit(0))); ++ EXPECT_EQ(-1, SnapSizeToPixel(LayoutUnit(-0.078125), LayoutUnit(0))); ++ ++ // The next 2 would snap to zero but for the requirement that we not snap ++ // sizes greater than 4 * LayoutUnit::Epsilon() to 0. ++ EXPECT_EQ(1, SnapSizeToPixel(LayoutUnit(0.5), LayoutUnit(1.5))); ++ EXPECT_EQ(1, SnapSizeToPixel(LayoutUnit(0.99), LayoutUnit(1.5))); ++ + EXPECT_EQ(1, SnapSizeToPixel(LayoutUnit(1.0), LayoutUnit(1.5))); + EXPECT_EQ(1, SnapSizeToPixel(LayoutUnit(1.49), LayoutUnit(1.5))); + EXPECT_EQ(1, SnapSizeToPixel(LayoutUnit(1.5), LayoutUnit(1.5))); +diff --git a/third_party/blink/web_tests/external/wpt/css/css-sizing/thin-element-render-ref.html b/third_party/blink/web_tests/external/wpt/css/css-sizing/thin-element-render-ref.html +new file mode 100644 +index 0000000000000000000000000000000000000000..0d5851d5544f9692d0761dc92c23b6b2b546b4d3 +--- /dev/null ++++ b/third_party/blink/web_tests/external/wpt/css/css-sizing/thin-element-render-ref.html +@@ -0,0 +1,31 @@ ++ ++Reference: Thin elements should paint even at small size ++ ++ ++ ++ ++ ++ ++
++
++
++ ++ +\ No newline at end of file +diff --git a/third_party/blink/web_tests/external/wpt/css/css-sizing/thin-element-render.html b/third_party/blink/web_tests/external/wpt/css/css-sizing/thin-element-render.html +new file mode 100644 +index 0000000000000000000000000000000000000000..fa587360a6d2625c8f02cd7f0eba54b3bb09a1f1 +--- /dev/null ++++ b/third_party/blink/web_tests/external/wpt/css/css-sizing/thin-element-render.html +@@ -0,0 +1,33 @@ ++ ++Thin elements should still paint even at small size. ++ ++ ++ ++ ++ ++ ++ ++ ++
++
++
++ ++ +\ No newline at end of file