<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[164698] trunk/Source/WebCore</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/164698">164698</a></dd>
<dt>Author</dt> <dd>zalan@apple.com</dd>
<dt>Date</dt> <dd>2014-02-25 22:24:22 -0800 (Tue, 25 Feb 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>Subpixel rendering: Ensure consistent border painting width.
https://bugs.webkit.org/show_bug.cgi?id=129259
Reviewed by Simon Fraser.
Border edges are painted as (semi)independent rectangles. When snapping an edge rectangle
to device pixels, its painted dimensions depend on its size and its fractional position.
Specific combination of position and border width can result in painting edges sized differently.
Using device snapped border width to calculate inner/outer rectangles helps to maintain
uniform border width.
Currently not testable.
* rendering/RenderBoxModelObject.cpp:
(WebCore::BorderEdge::BorderEdge):
(WebCore::BorderEdge::shouldRender):
(WebCore::BorderEdge::presentButInvisible):
(WebCore::BorderEdge::widthForPainting):
(WebCore::BorderEdge::getDoubleBorderStripeWidths):
(WebCore::RenderBoxModelObject::paintOneBorderSide):
(WebCore::calculateSideRect):
(WebCore::RenderBoxModelObject::paintBorderSides):
(WebCore::RenderBoxModelObject::paintBorder):
(WebCore::RenderBoxModelObject::drawBoxSideFromPath):
(WebCore::calculateSideRectIncludingInner):</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorerenderingRenderBoxModelObjectcpp">trunk/Source/WebCore/rendering/RenderBoxModelObject.cpp</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (164697 => 164698)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2014-02-26 06:23:03 UTC (rev 164697)
+++ trunk/Source/WebCore/ChangeLog        2014-02-26 06:24:22 UTC (rev 164698)
</span><span class="lines">@@ -1,5 +1,33 @@
</span><span class="cx"> 2014-02-25 Zalan Bujtas <zalan@apple.com>
</span><span class="cx">
</span><ins>+ Subpixel rendering: Ensure consistent border painting width.
+ https://bugs.webkit.org/show_bug.cgi?id=129259
+
+ Reviewed by Simon Fraser.
+
+ Border edges are painted as (semi)independent rectangles. When snapping an edge rectangle
+ to device pixels, its painted dimensions depend on its size and its fractional position.
+ Specific combination of position and border width can result in painting edges sized differently.
+ Using device snapped border width to calculate inner/outer rectangles helps to maintain
+ uniform border width.
+
+ Currently not testable.
+
+ * rendering/RenderBoxModelObject.cpp:
+ (WebCore::BorderEdge::BorderEdge):
+ (WebCore::BorderEdge::shouldRender):
+ (WebCore::BorderEdge::presentButInvisible):
+ (WebCore::BorderEdge::widthForPainting):
+ (WebCore::BorderEdge::getDoubleBorderStripeWidths):
+ (WebCore::RenderBoxModelObject::paintOneBorderSide):
+ (WebCore::calculateSideRect):
+ (WebCore::RenderBoxModelObject::paintBorderSides):
+ (WebCore::RenderBoxModelObject::paintBorder):
+ (WebCore::RenderBoxModelObject::drawBoxSideFromPath):
+ (WebCore::calculateSideRectIncludingInner):
+
+2014-02-25 Zalan Bujtas <zalan@apple.com>
+
</ins><span class="cx"> Subpixel layout: Remove explicit static_cast<LayoutUnit> conversions.
</span><span class="cx"> https://bugs.webkit.org/show_bug.cgi?id=129359
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingRenderBoxModelObjectcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/RenderBoxModelObject.cpp (164697 => 164698)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/RenderBoxModelObject.cpp        2014-02-26 06:23:03 UTC (rev 164697)
+++ trunk/Source/WebCore/rendering/RenderBoxModelObject.cpp        2014-02-26 06:24:22 UTC (rev 164698)
</span><span class="lines">@@ -1409,6 +1409,7 @@
</span><span class="cx"> {
</span><span class="cx"> if (style == DOUBLE && width < borderWidthInDevicePixel(3))
</span><span class="cx"> style = SOLID;
</span><ins>+ flooredToDevicePixelWidth = floorToDevicePixel(width, devicePixelRatio);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> BorderEdge()
</span><span class="lines">@@ -1416,13 +1417,14 @@
</span><span class="cx"> , style(BHIDDEN)
</span><span class="cx"> , isTransparent(false)
</span><span class="cx"> , isPresent(false)
</span><ins>+ , flooredToDevicePixelWidth(0)
</ins><span class="cx"> , devicePixelRatio(1)
</span><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> bool hasVisibleColorAndStyle() const { return style > BHIDDEN && !isTransparent; }
</span><del>- bool shouldRender() const { return isPresent && width && hasVisibleColorAndStyle(); }
- bool presentButInvisible() const { return usedWidth() && !hasVisibleColorAndStyle(); }
</del><ins>+ bool shouldRender() const { return isPresent && widthForPainting() && hasVisibleColorAndStyle(); }
+ bool presentButInvisible() const { return widthForPainting() && !hasVisibleColorAndStyle(); }
</ins><span class="cx"> bool obscuresBackgroundEdge(float scale) const
</span><span class="cx"> {
</span><span class="cx"> if (!isPresent || isTransparent || (width * scale) < borderWidthInDevicePixel(2) || color.hasAlpha() || style == BHIDDEN)
</span><span class="lines">@@ -1447,11 +1449,11 @@
</span><span class="cx"> return true;
</span><span class="cx"> }
</span><span class="cx">
</span><del>- LayoutUnit usedWidth() const { return isPresent ? width : LayoutUnit::fromPixel(0); }
</del><ins>+ float widthForPainting() const { return isPresent ? flooredToDevicePixelWidth : 0; }
</ins><span class="cx">
</span><span class="cx"> void getDoubleBorderStripeWidths(LayoutUnit& outerWidth, LayoutUnit& innerWidth) const
</span><span class="cx"> {
</span><del>- LayoutUnit fullWidth = usedWidth();
</del><ins>+ LayoutUnit fullWidth = widthForPainting();
</ins><span class="cx"> innerWidth = ceilToDevicePixel(fullWidth * 2 / 3, devicePixelRatio);
</span><span class="cx"> outerWidth = floorToDevicePixel(fullWidth / 3, devicePixelRatio);
</span><span class="cx"> }
</span><span class="lines">@@ -1461,10 +1463,12 @@
</span><span class="cx"> EBorderStyle style;
</span><span class="cx"> bool isTransparent;
</span><span class="cx"> bool isPresent;
</span><del>- float devicePixelRatio;
</del><span class="cx">
</span><span class="cx"> private:
</span><span class="cx"> float borderWidthInDevicePixel(int logicalPixels) const { return LayoutUnit(logicalPixels / devicePixelRatio).toFloat(); }
</span><ins>+
+ float flooredToDevicePixelWidth;
+ float devicePixelRatio;
</ins><span class="cx"> };
</span><span class="cx">
</span><span class="cx"> static bool allCornersClippedOut(const RoundedRect& border, const LayoutRect& clipRect)
</span><span class="lines">@@ -1656,7 +1660,7 @@
</span><span class="cx"> BackgroundBleedAvoidance bleedAvoidance, bool includeLogicalLeftEdge, bool includeLogicalRightEdge, bool antialias, const Color* overrideColor)
</span><span class="cx"> {
</span><span class="cx"> const BorderEdge& edgeToRender = edges[side];
</span><del>- ASSERT(edgeToRender.width);
</del><ins>+ ASSERT(edgeToRender.widthForPainting());
</ins><span class="cx"> const BorderEdge& adjacentEdge1 = edges[adjacentSide1];
</span><span class="cx"> const BorderEdge& adjacentEdge2 = edges[adjacentSide2];
</span><span class="cx">
</span><span class="lines">@@ -1674,8 +1678,8 @@
</span><span class="cx"> clipBorderSidePolygon(graphicsContext, outerBorder, innerBorder, side, adjacentSide1StylesMatch, adjacentSide2StylesMatch);
</span><span class="cx"> else
</span><span class="cx"> clipBorderSideForComplexInnerPath(graphicsContext, outerBorder, innerBorder, side, edges);
</span><del>- float thickness = std::max(std::max(edgeToRender.width, adjacentEdge1.width), adjacentEdge2.width);
- drawBoxSideFromPath(graphicsContext, outerBorder.rect(), *path, edges, edgeToRender.width, thickness, side, style,
</del><ins>+ float thickness = std::max(std::max(edgeToRender.widthForPainting(), adjacentEdge1.widthForPainting()), adjacentEdge2.widthForPainting());
+ drawBoxSideFromPath(graphicsContext, outerBorder.rect(), *path, edges, edgeToRender.widthForPainting(), thickness, side, style,
</ins><span class="cx"> colorToPaint, edgeToRender.style, bleedAvoidance, includeLogicalLeftEdge, includeLogicalRightEdge);
</span><span class="cx"> } else {
</span><span class="cx"> bool clipForStyle = styleRequiresClipPolygon(edgeToRender.style) && (mitreAdjacentSide1 || mitreAdjacentSide2);
</span><span class="lines">@@ -1694,14 +1698,14 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> drawLineForBoxSide(graphicsContext, sideRect.x(), sideRect.y(), sideRect.maxX(), sideRect.maxY(), side, colorToPaint, edgeToRender.style,
</span><del>- mitreAdjacentSide1 ? adjacentEdge1.width : LayoutUnit::fromPixel(0), mitreAdjacentSide2 ? adjacentEdge2.width : LayoutUnit::fromPixel(0), antialias);
</del><ins>+ mitreAdjacentSide1 ? adjacentEdge1.widthForPainting() : 0, mitreAdjacentSide2 ? adjacentEdge2.widthForPainting() : 0, antialias);
</ins><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> static LayoutRect calculateSideRect(const RoundedRect& outerBorder, const BorderEdge edges[], int side)
</span><span class="cx"> {
</span><span class="cx"> LayoutRect sideRect = outerBorder.rect();
</span><del>- int width = edges[side].width;
</del><ins>+ float width = edges[side].widthForPainting();
</ins><span class="cx">
</span><span class="cx"> if (side == BSTop)
</span><span class="cx"> sideRect.setHeight(width);
</span><span class="lines">@@ -1732,7 +1736,7 @@
</span><span class="cx">
</span><span class="cx"> if (edges[BSTop].shouldRender() && includesEdge(edgeSet, BSTop)) {
</span><span class="cx"> LayoutRect sideRect = outerBorder.rect();
</span><del>- sideRect.setHeight(edges[BSTop].width + innerBorderAdjustment.y());
</del><ins>+ sideRect.setHeight(edges[BSTop].widthForPainting() + innerBorderAdjustment.y());
</ins><span class="cx">
</span><span class="cx"> bool usePath = renderRadii && (borderStyleHasInnerDetail(edges[BSTop].style) || borderWillArcInnerEdge(innerBorder.radii().topLeft(), innerBorder.radii().topRight()));
</span><span class="cx"> paintOneBorderSide(graphicsContext, style, outerBorder, innerBorder, sideRect, BSTop, BSLeft, BSRight, edges, usePath ? &roundedPath : 0, bleedAvoidance, includeLogicalLeftEdge, includeLogicalRightEdge, antialias, overrideColor);
</span><span class="lines">@@ -1740,7 +1744,7 @@
</span><span class="cx">
</span><span class="cx"> if (edges[BSBottom].shouldRender() && includesEdge(edgeSet, BSBottom)) {
</span><span class="cx"> LayoutRect sideRect = outerBorder.rect();
</span><del>- sideRect.shiftYEdgeTo(sideRect.maxY() - edges[BSBottom].width - innerBorderAdjustment.y());
</del><ins>+ sideRect.shiftYEdgeTo(sideRect.maxY() - edges[BSBottom].widthForPainting() - innerBorderAdjustment.y());
</ins><span class="cx">
</span><span class="cx"> bool usePath = renderRadii && (borderStyleHasInnerDetail(edges[BSBottom].style) || borderWillArcInnerEdge(innerBorder.radii().bottomLeft(), innerBorder.radii().bottomRight()));
</span><span class="cx"> paintOneBorderSide(graphicsContext, style, outerBorder, innerBorder, sideRect, BSBottom, BSLeft, BSRight, edges, usePath ? &roundedPath : 0, bleedAvoidance, includeLogicalLeftEdge, includeLogicalRightEdge, antialias, overrideColor);
</span><span class="lines">@@ -1748,7 +1752,7 @@
</span><span class="cx">
</span><span class="cx"> if (edges[BSLeft].shouldRender() && includesEdge(edgeSet, BSLeft)) {
</span><span class="cx"> LayoutRect sideRect = outerBorder.rect();
</span><del>- sideRect.setWidth(edges[BSLeft].width + innerBorderAdjustment.x());
</del><ins>+ sideRect.setWidth(edges[BSLeft].widthForPainting() + innerBorderAdjustment.x());
</ins><span class="cx">
</span><span class="cx"> bool usePath = renderRadii && (borderStyleHasInnerDetail(edges[BSLeft].style) || borderWillArcInnerEdge(innerBorder.radii().bottomLeft(), innerBorder.radii().topLeft()));
</span><span class="cx"> paintOneBorderSide(graphicsContext, style, outerBorder, innerBorder, sideRect, BSLeft, BSTop, BSBottom, edges, usePath ? &roundedPath : 0, bleedAvoidance, includeLogicalLeftEdge, includeLogicalRightEdge, antialias, overrideColor);
</span><span class="lines">@@ -1756,7 +1760,7 @@
</span><span class="cx">
</span><span class="cx"> if (edges[BSRight].shouldRender() && includesEdge(edgeSet, BSRight)) {
</span><span class="cx"> LayoutRect sideRect = outerBorder.rect();
</span><del>- sideRect.shiftXEdgeTo(sideRect.maxX() - edges[BSRight].width - innerBorderAdjustment.x());
</del><ins>+ sideRect.shiftXEdgeTo(sideRect.maxX() - edges[BSRight].widthForPainting() - innerBorderAdjustment.x());
</ins><span class="cx">
</span><span class="cx"> bool usePath = renderRadii && (borderStyleHasInnerDetail(edges[BSRight].style) || borderWillArcInnerEdge(innerBorder.radii().bottomRight(), innerBorder.radii().topRight()));
</span><span class="cx"> paintOneBorderSide(graphicsContext, style, outerBorder, innerBorder, sideRect, BSRight, BSTop, BSBottom, edges, usePath ? &roundedPath : 0, bleedAvoidance, includeLogicalLeftEdge, includeLogicalRightEdge, antialias, overrideColor);
</span><span class="lines">@@ -1842,7 +1846,7 @@
</span><span class="cx"> continue;
</span><span class="cx"> }
</span><span class="cx">
</span><del>- if (!currEdge.width) {
</del><ins>+ if (!currEdge.widthForPainting()) {
</ins><span class="cx"> --numEdgesVisible;
</span><span class="cx"> continue;
</span><span class="cx"> }
</span><span class="lines">@@ -2091,10 +2095,10 @@
</span><span class="cx">
</span><span class="cx"> // Paint inner only
</span><span class="cx"> GraphicsContextStateSaver stateSaver(*graphicsContext);
</span><del>- LayoutUnit topWidth = edges[BSTop].usedWidth() / 2;
- LayoutUnit bottomWidth = edges[BSBottom].usedWidth() / 2;
- LayoutUnit leftWidth = edges[BSLeft].usedWidth() / 2;
- LayoutUnit rightWidth = edges[BSRight].usedWidth() / 2;
</del><ins>+ LayoutUnit topWidth = edges[BSTop].widthForPainting() / 2;
+ LayoutUnit bottomWidth = edges[BSBottom].widthForPainting() / 2;
+ LayoutUnit leftWidth = edges[BSLeft].widthForPainting() / 2;
+ LayoutUnit rightWidth = edges[BSRight].widthForPainting() / 2;
</ins><span class="cx">
</span><span class="cx"> RoundedRect clipRect = style->getRoundedInnerBorderFor(borderRect,
</span><span class="cx"> topWidth, bottomWidth, leftWidth, rightWidth,
</span><span class="lines">@@ -2245,19 +2249,19 @@
</span><span class="cx">
</span><span class="cx"> switch (side) {
</span><span class="cx"> case BSTop:
</span><del>- width = sideRect.height() - edges[BSBottom].width;
</del><ins>+ width = sideRect.height() - edges[BSBottom].widthForPainting();
</ins><span class="cx"> sideRect.setHeight(width);
</span><span class="cx"> break;
</span><span class="cx"> case BSBottom:
</span><del>- width = sideRect.height() - edges[BSTop].width;
</del><ins>+ width = sideRect.height() - edges[BSTop].widthForPainting();
</ins><span class="cx"> sideRect.shiftYEdgeTo(sideRect.maxY() - width);
</span><span class="cx"> break;
</span><span class="cx"> case BSLeft:
</span><del>- width = sideRect.width() - edges[BSRight].width;
</del><ins>+ width = sideRect.width() - edges[BSRight].widthForPainting();
</ins><span class="cx"> sideRect.setWidth(width);
</span><span class="cx"> break;
</span><span class="cx"> case BSRight:
</span><del>- width = sideRect.width() - edges[BSLeft].width;
</del><ins>+ width = sideRect.width() - edges[BSLeft].widthForPainting();
</ins><span class="cx"> sideRect.shiftXEdgeTo(sideRect.maxX() - width);
</span><span class="cx"> break;
</span><span class="cx"> }
</span></span></pre>
</div>
</div>
</body>
</html>