Changeset 215613 in webkit


Ignore:
Timestamp:
Apr 21, 2017 9:58:49 AM (7 years ago)
Author:
yoon@igalia.com
Message:

Do not paint the border of the box if the dirty region does not intersect with border area
https://bugs.webkit.org/show_bug.cgi?id=170988

Reviewed by Simon Fraser.

No new tests, since there is no change in behavior.

  • platform/graphics/GeometryUtilities.cpp:

(WebCore::ellipseContainsPoint):
Checks if a point is within an ellipse.

  • platform/graphics/GeometryUtilities.h:

Replace header-guards with #pragma once.

  • platform/graphics/RoundedRect.cpp:

(WebCore::RoundedRect::contains):
Implemented to know the dirty rectangle intersects with rounded rectangle or not.

  • platform/graphics/RoundedRect.h:
  • rendering/RenderBoxModelObject.cpp:

(WebCore::RenderBoxModelObject::paintBorder):
When typing in decorated text box, the dirty rect generated only for the
inside of the text box, not for the decorations. So we can avoid the
calculations to draw borders if the inner border totally covers the
target surface. It will optimize the rendering process since we don't
have to render border decorations whenever we type somethings in side of
the text input element.

Location:
trunk/Source/WebCore
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r215612 r215613  
     12017-04-21  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  Anders Carlsson  <andersca@apple.com>
    231
  • trunk/Source/WebCore/platform/graphics/GeometryUtilities.cpp

    r181770 r215613  
    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);
    149161}
     162
     163}
  • trunk/Source/WebCore/platform/graphics/GeometryUtilities.h

    r181770 r215613  
    2424 */
    2525
    26 #ifndef GeometryUtilities_h
    27 #define GeometryUtilities_h
     26#pragma once
    2827
    2928#include "FloatRect.h"
     
    5251FloatRect boundsOfRotatingRect(const FloatRect&);
    5352
     53bool ellipseContainsPoint(const FloatPoint& center, const FloatSize& radii, const FloatPoint&);
    5454}
    55 
    56 #endif // GeometryUtilities_h
  • trunk/Source/WebCore/platform/graphics/RoundedRect.cpp

    r173047 r215613  
    3030
    3131#include "FloatRoundedRect.h"
     32#include "GeometryUtilities.h"
    3233#include "LayoutRect.h"
    3334#include "LayoutUnit.h"
     
    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{
  • trunk/Source/WebCore/platform/graphics/RoundedRect.h

    r170458 r215613  
    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;
  • trunk/Source/WebCore/rendering/RenderBoxModelObject.cpp

    r214450 r215613  
    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;
Note: See TracChangeset for help on using the changeset viewer.