Title: [164555] trunk/Source/WebCore
Revision
164555
Author
[email protected]
Date
2014-02-23 08:22:58 -0800 (Sun, 23 Feb 2014)

Log Message

Subpixel rendering: Add devicepixel based computation to BorderEdge class.
https://bugs.webkit.org/show_bug.cgi?id=129224

Reviewed by Simon Fraser.

To produce correct width (and type) results, BorderEdge class needs to take device pixel ratio into account.

Currently not testable.

* rendering/RenderBoxModelObject.cpp:
(WebCore::BorderEdge::BorderEdge):
(WebCore::BorderEdge::obscuresBackgroundEdge):
(WebCore::BorderEdge::getDoubleBorderStripeWidths): this does not always produce the same
result as before, but the sum of inner and outer is not different.
(WebCore::BorderEdge::borderWidthInDevicePixel):
(WebCore::RenderBoxModelObject::getBorderEdgeInfo):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (164554 => 164555)


--- trunk/Source/WebCore/ChangeLog	2014-02-23 05:44:05 UTC (rev 164554)
+++ trunk/Source/WebCore/ChangeLog	2014-02-23 16:22:58 UTC (rev 164555)
@@ -1,3 +1,22 @@
+2014-02-23  Zalan Bujtas  <[email protected]>
+
+        Subpixel rendering: Add devicepixel based computation to BorderEdge class.
+        https://bugs.webkit.org/show_bug.cgi?id=129224
+
+        Reviewed by Simon Fraser.
+
+        To produce correct width (and type) results, BorderEdge class needs to take device pixel ratio into account.
+
+        Currently not testable.
+
+        * rendering/RenderBoxModelObject.cpp:
+        (WebCore::BorderEdge::BorderEdge):
+        (WebCore::BorderEdge::obscuresBackgroundEdge):
+        (WebCore::BorderEdge::getDoubleBorderStripeWidths): this does not always produce the same
+        result as before, but the sum of inner and outer is not different.
+        (WebCore::BorderEdge::borderWidthInDevicePixel):
+        (WebCore::RenderBoxModelObject::getBorderEdgeInfo):
+
 2014-02-22  Dan Bernstein  <[email protected]>
 
         REGRESSION (r164507): Crash beneath JSGlobalObjectInspectorController::reportAPIException at facebook.com, twitter.com, youtube.com

Modified: trunk/Source/WebCore/rendering/RenderBoxModelObject.cpp (164554 => 164555)


--- trunk/Source/WebCore/rendering/RenderBoxModelObject.cpp	2014-02-23 05:44:05 UTC (rev 164554)
+++ trunk/Source/WebCore/rendering/RenderBoxModelObject.cpp	2014-02-23 16:22:58 UTC (rev 164555)
@@ -1396,22 +1396,24 @@
 
 class BorderEdge {
 public:
-    BorderEdge(LayoutUnit edgeWidth, const Color& edgeColor, EBorderStyle edgeStyle, bool edgeIsTransparent, bool edgeIsPresent = true)
+    BorderEdge(LayoutUnit edgeWidth, const Color& edgeColor, EBorderStyle edgeStyle, bool edgeIsTransparent, bool edgeIsPresent, float devicePixelRatio)
         : width(edgeWidth)
         , color(edgeColor)
         , style(edgeStyle)
         , isTransparent(edgeIsTransparent)
         , isPresent(edgeIsPresent)
+        , devicePixelRatio(devicePixelRatio)
     {
-        if (style == DOUBLE && edgeWidth < 3)
+        if (style == DOUBLE && width  < borderWidthInDevicePixel(3))
             style = SOLID;
     }
     
     BorderEdge()
-        : width(0)
+        : width(LayoutUnit::fromPixel(0))
         , style(BHIDDEN)
         , isTransparent(false)
         , isPresent(false)
+        , devicePixelRatio(1)
     {
     }
     
@@ -1420,14 +1422,14 @@
     bool presentButInvisible() const { return usedWidth() && !hasVisibleColorAndStyle(); }
     bool obscuresBackgroundEdge(float scale) const
     {
-        if (!isPresent || isTransparent || (width * scale) < 2 || color.hasAlpha() || style == BHIDDEN)
+        if (!isPresent || isTransparent || (width * scale) < borderWidthInDevicePixel(2) || color.hasAlpha() || style == BHIDDEN)
             return false;
 
         if (style == DOTTED || style == DASHED)
             return false;
 
         if (style == DOUBLE)
-            return width >= 5 * scale; // The outer band needs to be >= 2px wide at unit scale.
+            return width >= scale * borderWidthInDevicePixel(5); // The outer band needs to be >= 2px wide at unit scale.
 
         return true;
     }
@@ -1446,16 +1448,9 @@
     
     void getDoubleBorderStripeWidths(LayoutUnit& outerWidth, LayoutUnit& innerWidth) const
     {
-        int fullWidth = usedWidth();
-        outerWidth = fullWidth / 3;
-        innerWidth = fullWidth * 2 / 3;
-
-        // We need certain integer rounding results
-        if (fullWidth % 3 == 2)
-            outerWidth += 1;
-
-        if (fullWidth % 3 == 1)
-            innerWidth += 1;
+        LayoutUnit fullWidth = usedWidth();
+        innerWidth = ceilToDevicePixel(fullWidth * 2 / 3, devicePixelRatio);
+        outerWidth = floorToDevicePixel(fullWidth / 3, devicePixelRatio);
     }
     
     LayoutUnit width;
@@ -1463,6 +1458,10 @@
     EBorderStyle style;
     bool isTransparent;
     bool isPresent;
+    float devicePixelRatio;
+
+private:
+    float borderWidthInDevicePixel(int logicalPixels) const { return LayoutUnit(logicalPixels / devicePixelRatio).toFloat(); }
 };
 
 static bool allCornersClippedOut(const RoundedRect& border, const LayoutRect& clipRect)
@@ -2353,30 +2352,35 @@
 void RenderBoxModelObject::getBorderEdgeInfo(BorderEdge edges[], const RenderStyle* style, bool includeLogicalLeftEdge, bool includeLogicalRightEdge) const
 {
     bool horizontal = style->isHorizontalWritingMode();
+    float deviceScaleFactor = document().deviceScaleFactor();
 
     edges[BSTop] = BorderEdge(style->borderTopWidth(),
         style->visitedDependentColor(CSSPropertyBorderTopColor),
         style->borderTopStyle(),
         style->borderTopIsTransparent(),
-        horizontal || includeLogicalLeftEdge);
+        horizontal || includeLogicalLeftEdge,
+        deviceScaleFactor);
 
     edges[BSRight] = BorderEdge(style->borderRightWidth(),
         style->visitedDependentColor(CSSPropertyBorderRightColor),
         style->borderRightStyle(),
         style->borderRightIsTransparent(),
-        !horizontal || includeLogicalRightEdge);
+        !horizontal || includeLogicalRightEdge,
+        deviceScaleFactor);
 
     edges[BSBottom] = BorderEdge(style->borderBottomWidth(),
         style->visitedDependentColor(CSSPropertyBorderBottomColor),
         style->borderBottomStyle(),
         style->borderBottomIsTransparent(),
-        horizontal || includeLogicalRightEdge);
+        horizontal || includeLogicalRightEdge,
+        deviceScaleFactor);
 
     edges[BSLeft] = BorderEdge(style->borderLeftWidth(),
         style->visitedDependentColor(CSSPropertyBorderLeftColor),
         style->borderLeftStyle(),
         style->borderLeftIsTransparent(),
-        !horizontal || includeLogicalLeftEdge);
+        !horizontal || includeLogicalLeftEdge,
+        deviceScaleFactor);
 }
 
 bool RenderBoxModelObject::borderObscuresBackgroundEdge(const FloatSize& contextScale) const
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to