Source/WebCore/ChangeLog

 12017-04-20 Gwang Yoon Hwang <yoon@igalia.com>
 2
 3 Do not paint the border of the box if the dirty region does not intersect with border area
 4 https://bugs.webkit.org/show_bug.cgi?id=170988
 5
 6 Reviewed by Simon Fraser.
 7
 8 No new tests, since there is no change in behavior.
 9
 10 * platform/graphics/GeometryUtilities.cpp:
 11 (WebCore::ellipseContainsPoint):
 12 Checks if a point is within an ellipse.
 13
 14 * platform/graphics/GeometryUtilities.h:
 15 Replace header-guards with #pragma once.
 16
 17 * platform/graphics/RoundedRect.cpp:
 18 (WebCore::RoundedRect::contains):
 19 Implemented to know the dirty rectangle intersects with rounded rectangle or not.
 20 * platform/graphics/RoundedRect.h:
 21 * rendering/RenderBoxModelObject.cpp:
 22 (WebCore::RenderBoxModelObject::paintBorder):
 23 When typing in decorated text box, the dirty rect generated only for the
 24 inside of the text box, not for the decorations. So we can avoid the
 25 calculations to draw borders if the inner border totally covers the
 26 target surface. It will optimize the rendering process since we don't
 27 have to render border decorations whenever we type somethings in side of
 28 the text input element.
 29
1302017-04-21 Alex Christensen <achristensen@webkit.org>
231
332 Reduce copies and allocations in SharedBuffer::append

Source/WebCore/platform/graphics/GeometryUtilities.cpp

@@FloatRect smallestRectWithAspectRatioAroundRect(float aspectRatio, const FloatRe
146146 return destRect;
147147}
148148
 149bool ellipseContainsPoint(const FloatPoint& center, const FloatSize& radii, const FloatPoint& point)
 150{
 151 FloatPoint transformedPoint(point);
 152 transformedPoint.move(-center.x(), -center.y());
 153 transformedPoint.scale(radii.height(), radii.width());
 154 float radius = radii.width() * radii.height();
 155
 156 if (transformedPoint.x() > radius || transformedPoint.y() > radius)
 157 return false;
 158 if (transformedPoint.x() + transformedPoint.y() <= radius)
 159 return true;
 160 return (transformedPoint.lengthSquared() <= radius * radius);
 161}
 162
149163}

Source/WebCore/platform/graphics/GeometryUtilities.h

2323 * THE POSSIBILITY OF SUCH DAMAGE.
2424 */
2525
26 #ifndef GeometryUtilities_h
27 #define GeometryUtilities_h
 26#pragma once
2827
2928#include "FloatRect.h"
3029#include "IntRect.h"

@@WEBCORE_EXPORT FloatRect smallestRectWithAspectRatioAroundRect(float aspectRatio
5150// Compute a rect that encloses all points covered by the given rect if it were rotated a full turn around (0,0).
5251FloatRect boundsOfRotatingRect(const FloatRect&);
5352
 53bool ellipseContainsPoint(const FloatPoint& center, const FloatSize& radii, const FloatPoint&);
5454}
55 
56 #endif // GeometryUtilities_h

Source/WebCore/platform/graphics/RoundedRect.cpp

2929#include "RoundedRect.h"
3030
3131#include "FloatRoundedRect.h"
 32#include "GeometryUtilities.h"
3233#include "LayoutRect.h"
3334#include "LayoutUnit.h"
3435

@@bool RoundedRect::intersectsQuad(const FloatQuad& quad) const
236237 return true;
237238}
238239
 240bool RoundedRect::contains(const LayoutRect& otherRect) const
 241{
 242 if (!rect().contains(otherRect))
 243 return false;
 244
 245 const LayoutSize& topLeft = m_radii.topLeft();
 246 if (!topLeft.isEmpty()) {
 247 FloatPoint center = { m_rect.x() + topLeft.width(), m_rect.y() + topLeft.height() };
 248 if (otherRect.x() <= center.x() && otherRect.y() <= center.y()) {
 249 if (!ellipseContainsPoint(center, topLeft, otherRect.location()))
 250 return false;
 251 }
 252 }
 253
 254 const LayoutSize& topRight = m_radii.topRight();
 255 if (!topRight.isEmpty()) {
 256 FloatPoint center = { m_rect.maxX() - topRight.width(), m_rect.y() + topRight.height() };
 257 if (otherRect.maxX() >= center.x() && otherRect.y() <= center.y()) {
 258 if (!ellipseContainsPoint(center, topRight, otherRect.location()))
 259 return false;
 260 }
 261 }
 262
 263 const LayoutSize& bottomLeft = m_radii.bottomLeft();
 264 if (!bottomLeft.isEmpty()) {
 265 FloatPoint center = { m_rect.x() + bottomLeft.width(), m_rect.maxY() - bottomLeft.height() };
 266 if (otherRect.maxX() >= center.x() && otherRect.maxY() >= center.y()) {
 267 if (!ellipseContainsPoint(center, bottomLeft, otherRect.location()))
 268 return false;
 269 }
 270 }
 271
 272 const LayoutSize& bottomRight = m_radii.bottomRight();
 273 if (!bottomRight.isEmpty()) {
 274 FloatPoint center = { m_rect.maxX() - bottomRight.width(), m_rect.maxY() - bottomRight.height() };
 275 if (otherRect.x() <= center.x() && otherRect.maxY() >= center.y()) {
 276 if (!ellipseContainsPoint(center, bottomRight, otherRect.location()))
 277 return false;
 278 }
 279 }
 280
 281 return true;
 282}
 283
239284FloatRoundedRect RoundedRect::pixelSnappedRoundedRectForPainting(float deviceScaleFactor) const
240285{
241286 LayoutRect originalRect = rect();

Source/WebCore/platform/graphics/RoundedRect.h

@@public:
106106 // Tests whether the quad intersects any part of this rounded rectangle.
107107 // This only works for convex quads.
108108 bool intersectsQuad(const FloatQuad&) const;
 109 bool contains(const LayoutRect&) const;
109110
110111 FloatRoundedRect pixelSnappedRoundedRectForPainting(float deviceScaleFactor) const;
111112

Source/WebCore/rendering/RenderBoxModelObject.cpp

@@void RenderBoxModelObject::paintBorder(const PaintInfo& info, const LayoutRect&
17341734 RoundedRect outerBorder = style.getRoundedBorderFor(rect, includeLogicalLeftEdge, includeLogicalRightEdge);
17351735 RoundedRect innerBorder = style.getRoundedInnerBorderFor(borderInnerRectAdjustedForBleedAvoidance(graphicsContext, rect, bleedAvoidance), includeLogicalLeftEdge, includeLogicalRightEdge);
17361736
 1737 // If no borders intersects with the dirty area, we can skip the border painting.
 1738 if (innerBorder.contains(info.rect))
 1739 return;
 1740
17371741 bool haveAlphaColor = false;
17381742 bool haveAllSolidEdges = true;
17391743 bool haveAllDoubleEdges = true;