Title: [186430] releases/WebKitGTK/webkit-2.8
Revision
186430
Author
[email protected]
Date
2015-07-07 03:11:27 -0700 (Tue, 07 Jul 2015)

Log Message

Merge r185916 - Subpixel rendering: roundToDevicePixel() snaps to wrong value.
https://bugs.webkit.org/show_bug.cgi?id=146273
rdar://problem/18509840

Reviewed by Simon Fraser.

Due to the floating point approximate representation, we can't always produce
the correct snap value. This patch addresses the issue by removing redundant kFixedPointDenominator multiplication
and by changing the rounding in roundToDevicePixel() from float to double.

Source/WebCore:

API test is added.

* platform/LayoutUnit.h:
(WebCore::roundToDevicePixel):

Tools:

* TestWebKitAPI/Tests/WebCore/LayoutUnit.cpp:
(TestWebKitAPI::TEST):

Modified Paths

Diff

Modified: releases/WebKitGTK/webkit-2.8/Source/WebCore/ChangeLog (186429 => 186430)


--- releases/WebKitGTK/webkit-2.8/Source/WebCore/ChangeLog	2015-07-07 09:44:58 UTC (rev 186429)
+++ releases/WebKitGTK/webkit-2.8/Source/WebCore/ChangeLog	2015-07-07 10:11:27 UTC (rev 186430)
@@ -1,3 +1,27 @@
+2015-06-30  Zalan Bujtas  <[email protected]>
+
+        Addressing post-review comments in r185916
+
+        * platform/LayoutUnit.h:
+        (WebCore::roundToDevicePixel):
+
+2015-06-24  Zalan Bujtas  <[email protected]>
+
+        Subpixel rendering: roundToDevicePixel() snaps to wrong value.
+        https://bugs.webkit.org/show_bug.cgi?id=146273
+        rdar://problem/18509840
+
+        Reviewed by Simon Fraser.
+
+        Due to the floating point approximate representation, we can't always produce
+        the correct snap value. This patch addresses the issue by removing redundant kFixedPointDenominator multiplication
+        and by changing the rounding in roundToDevicePixel() from float to double.
+
+        API test is added.
+
+        * platform/LayoutUnit.h:
+        (WebCore::roundToDevicePixel):
+
 2015-06-22  Simon Fraser  <[email protected]>
 
         ASSERT(!m_zOrderListsDirty) when mousing over web view with incremental rendering suppressed

Modified: releases/WebKitGTK/webkit-2.8/Source/WebCore/platform/LayoutUnit.h (186429 => 186430)


--- releases/WebKitGTK/webkit-2.8/Source/WebCore/platform/LayoutUnit.h	2015-07-07 09:44:58 UTC (rev 186429)
+++ releases/WebKitGTK/webkit-2.8/Source/WebCore/platform/LayoutUnit.h	2015-07-07 10:11:27 UTC (rev 186430)
@@ -876,18 +876,20 @@
     return value.floor();
 }
 
-inline float roundToDevicePixel(LayoutUnit value, const float pixelSnappingFactor, bool needsDirectionalRounding = false)
+inline float roundToDevicePixel(LayoutUnit value, float pixelSnappingFactor, bool needsDirectionalRounding = false)
 {
-    auto roundInternal = [&] (float valueToRound) { return roundf((valueToRound * pixelSnappingFactor) / kFixedPointDenominator) / pixelSnappingFactor; };
+    double valueToRound = value.toDouble();
+    if (needsDirectionalRounding)
+        valueToRound -= LayoutUnit::epsilon() / (2 * kFixedPointDenominator);
 
-    float adjustedValue = value.rawValue() - (needsDirectionalRounding ? LayoutUnit::epsilon() / 2.0f : 0);
-    if (adjustedValue >= 0)
-        return roundInternal(adjustedValue);
+    if (valueToRound >= 0)
+        return round(valueToRound * pixelSnappingFactor) / pixelSnappingFactor;
 
     // This adjusts directional rounding on negative halfway values. It produces the same direction for both negative and positive values.
+    // Instead of rounding negative halfway cases away from zero, we translate them to positive values before rounding.
     // It helps snapping relative negative coordinates to the same position as if they were positive absolute coordinates.
-    float translateOrigin = fabsf(adjustedValue - LayoutUnit::fromPixel(1));
-    return roundInternal(adjustedValue + (translateOrigin * kFixedPointDenominator)) - translateOrigin;
+    unsigned translateOrigin = -value.rawValue();
+    return (round((valueToRound + translateOrigin) * pixelSnappingFactor) / pixelSnappingFactor) - translateOrigin;
 }
 
 inline float floorToDevicePixel(LayoutUnit value, float pixelSnappingFactor)

Modified: releases/WebKitGTK/webkit-2.8/Tools/ChangeLog (186429 => 186430)


--- releases/WebKitGTK/webkit-2.8/Tools/ChangeLog	2015-07-07 09:44:58 UTC (rev 186429)
+++ releases/WebKitGTK/webkit-2.8/Tools/ChangeLog	2015-07-07 10:11:27 UTC (rev 186430)
@@ -1,3 +1,18 @@
+2015-06-24  Zalan Bujtas  <[email protected]>
+
+        Subpixel rendering: roundToDevicePixel() snaps to wrong value.
+        https://bugs.webkit.org/show_bug.cgi?id=146273
+        rdar://problem/18509840
+
+        Reviewed by Simon Fraser.
+
+        Due to the floating point approximate representation, we can't always produce
+        the correct snap value. This patch addresses the issue by removing redundant kFixedPointDenominator multiplication
+        and by changing the rounding in roundToDevicePixel() from float to double.
+
+        * TestWebKitAPI/Tests/WebCore/LayoutUnit.cpp:
+        (TestWebKitAPI::TEST):
+
 2015-05-24  Sam Weinig  <[email protected]>
 
         Crash when using a removed ScriptMessageHandler

Modified: releases/WebKitGTK/webkit-2.8/Tools/TestWebKitAPI/Tests/WebCore/LayoutUnit.cpp (186429 => 186430)


--- releases/WebKitGTK/webkit-2.8/Tools/TestWebKitAPI/Tests/WebCore/LayoutUnit.cpp	2015-07-07 09:44:58 UTC (rev 186429)
+++ releases/WebKitGTK/webkit-2.8/Tools/TestWebKitAPI/Tests/WebCore/LayoutUnit.cpp	2015-07-07 10:11:27 UTC (rev 186430)
@@ -231,5 +231,19 @@
     ASSERT_EQ((LayoutUnit(intMinForLayoutUnit) + LayoutUnit(1)).floor(), intMinForLayoutUnit + 1);
 }
 
+TEST(WebCoreLayoutUnit, LayoutUnitPixelSnapping)
+{
+    for (int i = -100000; i <= 100000; ++i) {
+        ASSERT_EQ(roundToDevicePixel(LayoutUnit(i), 1), i);
+        ASSERT_EQ(roundToDevicePixel(LayoutUnit(i), 2), i);
+        ASSERT_EQ(roundToDevicePixel(LayoutUnit(i), 3), i);
+    }
 
+    for (float i = -10000; i < 0; i = i + 0.5)
+        ASSERT_FLOAT_EQ(roundToDevicePixel(LayoutUnit(i), 2), i);
+
+    for (float i = -10000.25; i < 0; i = i + 0.5)
+        ASSERT_FLOAT_EQ(roundToDevicePixel(LayoutUnit(i), 2), i + 0.25);
+}
+
 } // namespace TestWebKitAPI
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to