Changeset 191617 in webkit


Ignore:
Timestamp:
Oct 26, 2015, 9:03:38 PM (10 years ago)
Author:
Simon Fraser
Message:

Remove redundant GraphicsContext::clip(const Path&, WindRule)
https://bugs.webkit.org/show_bug.cgi?id=150584

Reviewed by Tim Horton.

GraphicsContext had both clipPath(const Path&, WindRule) and clip(const Path&, WindRule),
which were mostly the same other than GraphicsContext::clipPath() not clipping if the path
was empty (added, I think by mistake, in r72926), and not calling m_data->clip().

Make clipPath() be the winner, and have it behave like clip() with empty paths, and call m_data->clip().

  • platform/graphics/GraphicsContext.cpp:

(WebCore::GraphicsContext::clipRoundedRect):

  • platform/graphics/GraphicsContext.h:
  • platform/graphics/cairo/GraphicsContextCairo.cpp:

(WebCore::GraphicsContext::clipPath):
(WebCore::GraphicsContext::clip): Deleted.

  • platform/graphics/cg/GraphicsContextCG.cpp:

(WebCore::GraphicsContext::clipPath):
(WebCore::GraphicsContext::canvasClip):
(WebCore::GraphicsContext::clip): Deleted.

  • rendering/RenderBoxModelObject.cpp:

(WebCore::RenderBoxModelObject::paintBoxShadow): Making a path, calling addRoundedRect() and then clipping
to the path is the same as context.clipRoundedRect().

  • rendering/mathml/RenderMathMLRadicalOperator.cpp:

(WebCore::RenderMathMLRadicalOperator::paint):

Location:
trunk/Source/WebCore
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r191610 r191617  
     12015-10-26  Simon Fraser  <simon.fraser@apple.com>
     2
     3        Remove redundant GraphicsContext::clip(const Path&, WindRule)
     4        https://bugs.webkit.org/show_bug.cgi?id=150584
     5
     6        Reviewed by Tim Horton.
     7
     8        GraphicsContext had both clipPath(const Path&, WindRule) and clip(const Path&, WindRule),
     9        which were mostly the same other than GraphicsContext::clipPath() not clipping if the path
     10        was empty (added, I think by mistake, in r72926), and not calling m_data->clip().
     11
     12        Make clipPath() be the winner, and have it behave like clip() with empty paths, and call m_data->clip().
     13
     14        * platform/graphics/GraphicsContext.cpp:
     15        (WebCore::GraphicsContext::clipRoundedRect):
     16        * platform/graphics/GraphicsContext.h:
     17        * platform/graphics/cairo/GraphicsContextCairo.cpp:
     18        (WebCore::GraphicsContext::clipPath):
     19        (WebCore::GraphicsContext::clip): Deleted.
     20        * platform/graphics/cg/GraphicsContextCG.cpp:
     21        (WebCore::GraphicsContext::clipPath):
     22        (WebCore::GraphicsContext::canvasClip):
     23        (WebCore::GraphicsContext::clip): Deleted.
     24        * rendering/RenderBoxModelObject.cpp:
     25        (WebCore::RenderBoxModelObject::paintBoxShadow): Making a path, calling addRoundedRect() and then clipping
     26        to the path is the same as context.clipRoundedRect().
     27        * rendering/mathml/RenderMathMLRadicalOperator.cpp:
     28        (WebCore::RenderMathMLRadicalOperator::paint):
     29
    1302015-10-26  Zalan Bujtas  <zalan@apple.com>
    231
  • trunk/Source/WebCore/platform/graphics/GraphicsContext.cpp

    r191330 r191617  
    462462    Path path;
    463463    path.addRoundedRect(rect);
    464     clip(path);
     464    clipPath(path);
    465465}
    466466
  • trunk/Source/WebCore/platform/graphics/GraphicsContext.h

    r191330 r191617  
    332332    void clipOut(const FloatRect&);
    333333    void clipOutRoundedRect(const FloatRoundedRect&);
    334     void clipPath(const Path&, WindRule);
     334    void clipPath(const Path&, WindRule = RULE_EVENODD);
    335335    void clipConvexPolygon(size_t numPoints, const FloatPoint*, bool antialias = true);
    336336    void clipToImageBuffer(ImageBuffer&, const FloatRect&);
     
    413413    void setDrawLuminanceMask(bool drawLuminanceMask) { m_state.drawLuminanceMask = drawLuminanceMask; }
    414414    bool drawLuminanceMask() const { return m_state.drawLuminanceMask; }
    415 
    416     WEBCORE_EXPORT void clip(const Path&, WindRule = RULE_EVENODD);
    417415
    418416    // This clip function is used only by <canvas> code. It allows
  • trunk/Source/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp

    r191330 r191617  
    495495    if (!path.isNull())
    496496        setPathOnCairoContext(cr, path.platformPath()->context());
     497
     498    cairo_fill_rule_t savedFillRule = cairo_get_fill_rule(cr);
    497499    cairo_set_fill_rule(cr, clipRule == RULE_EVENODD ? CAIRO_FILL_RULE_EVEN_ODD : CAIRO_FILL_RULE_WINDING);
    498500    cairo_clip(cr);
     501    cairo_set_fill_rule(cr, savedFillRule);
     502
     503    m_data->clip(path);
    499504}
    500505
     
    961966}
    962967
    963 void GraphicsContext::clip(const Path& path, WindRule windRule)
    964 {
    965     if (paintingDisabled())
    966         return;
    967 
    968     cairo_t* cr = platformContext()->cr();
    969     if (!path.isNull()) {
    970         cairo_path_t* pathCopy = cairo_copy_path(path.platformPath()->context());
    971         cairo_append_path(cr, pathCopy);
    972         cairo_path_destroy(pathCopy);
    973     }
    974     cairo_fill_rule_t savedFillRule = cairo_get_fill_rule(cr);
    975     if (windRule == RULE_NONZERO)
    976         cairo_set_fill_rule(cr, CAIRO_FILL_RULE_WINDING);
    977     else
    978         cairo_set_fill_rule(cr, CAIRO_FILL_RULE_EVEN_ODD);
    979     cairo_clip(cr);
    980     cairo_set_fill_rule(cr, savedFillRule);
    981     m_data->clip(path);
    982 }
    983 
    984968void GraphicsContext::canvasClip(const Path& path, WindRule windRule)
    985969{
    986     clip(path, windRule);
     970    clipPath(path, windRule);
    987971}
    988972
  • trunk/Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp

    r191590 r191617  
    983983        return;
    984984
    985     // Why does clipping to an empty path do nothing?
    986     // Why is this different from GraphicsContext::clip(const Path&).
     985    CGContextRef context = platformContext();
    987986    if (path.isEmpty())
    988         return;
    989 
    990     CGContextRef context = platformContext();
    991 
    992     CGContextBeginPath(platformContext());
    993     CGContextAddPath(platformContext(), path.platformPath());
    994 
    995     if (clipRule == RULE_EVENODD)
    996         CGContextEOClip(context);
    997     else
    998         CGContextClip(context);
     987        CGContextClipToRect(context, CGRectZero);
     988    else {
     989        CGContextBeginPath(platformContext());
     990        CGContextAddPath(platformContext(), path.platformPath());
     991
     992        if (clipRule == RULE_EVENODD)
     993            CGContextEOClip(context);
     994        else
     995            CGContextClip(context);
     996    }
     997   
     998    m_data->clip(path);
    999999}
    10001000
     
    12351235}
    12361236
    1237 void GraphicsContext::clip(const Path& path, WindRule fillRule)
    1238 {
    1239     if (paintingDisabled())
    1240         return;
    1241     CGContextRef context = platformContext();
    1242 
    1243     // CGContextClip does nothing if the path is empty, so in this case, we
    1244     // instead clip against a zero rect to reduce the clipping region to
    1245     // nothing - which is the intended behavior of clip() if the path is empty.   
    1246     if (path.isEmpty())
    1247         CGContextClipToRect(context, CGRectZero);
    1248     else {
    1249         CGContextBeginPath(context);
    1250         CGContextAddPath(context, path.platformPath());
    1251         if (fillRule == RULE_NONZERO)
    1252             CGContextClip(context);
    1253         else
    1254             CGContextEOClip(context);
    1255     }
    1256     m_data->clip(path);
    1257 }
    1258 
    12591237void GraphicsContext::canvasClip(const Path& path, WindRule fillRule)
    12601238{
    1261     clip(path, fillRule);
     1239    clipPath(path, fillRule);
    12621240}
    12631241
  • trunk/Source/WebCore/rendering/RenderBoxModelObject.cpp

    r191049 r191617  
    23472347            GraphicsContextStateSaver stateSaver(context);
    23482348            if (hasBorderRadius) {
    2349                 Path path;
    2350                 path.addRoundedRect(pixelSnappedBorderRect);
    2351                 context.clip(path);
     2349                context.clipRoundedRect(pixelSnappedBorderRect);
    23522350                pixelSnappedRoundedHole.shrinkRadii(shadowSpread);
    23532351            } else
  • trunk/Source/WebCore/rendering/mathml/RenderMathMLRadicalOperator.cpp

    r189144 r191617  
    153153
    154154    // Build a mask to draw the thick part of the root.
    155     Path mask;
     155    Path maskPath;
    156156
    157     mask.moveTo(overbarLeftPoint);
    158     mask.addLineTo(bottomPoint);
    159     mask.addLineTo(dipLeftPoint);
    160     mask.addLineTo(FloatPoint(2 * dipLeftPoint.x() - leftEnd.x(), 2 * dipLeftPoint.y() - leftEnd.y()));
     157    maskPath.moveTo(overbarLeftPoint);
     158    maskPath.addLineTo(bottomPoint);
     159    maskPath.addLineTo(dipLeftPoint);
     160    maskPath.addLineTo(FloatPoint(2 * dipLeftPoint.x() - leftEnd.x(), 2 * dipLeftPoint.y() - leftEnd.y()));
    161161
    162     info.context().clip(mask);
     162    info.context().clipPath(maskPath);
    163163
    164164    // Draw the thick part of the root.
Note: See TracChangeset for help on using the changeset viewer.