Changeset 194798 in webkit


Ignore:
Timestamp:
Jan 8, 2016, 3:26:48 PM (10 years ago)
Author:
Simon Fraser
Message:

Consider painting to be disabled on a GraphicsContext with no platform data, and make updatingControlTints() immutable state
https://bugs.webkit.org/show_bug.cgi?id=152927

Reviewed by Tim Horton.

GraphicsContext had setters for paintingDisabled and updatingControlTints, but neither
were changed dynamically.

We can eliminate paintingDisabled by simply considering a GraphicsContext that was
created with no platform context to be paint-disabled.

We make updatingControlTints immutable state by providing a constructor that takes
a "NonPaintingReasons" enum, and doesn't create platform data.

More functions in platform code were protected by if (paintingDisabled())...

  • page/FrameView.cpp:

(WebCore::FrameView::paintControlTints):

  • platform/graphics/GraphicsContext.cpp:

(WebCore::GraphicsContext::GraphicsContext):
(WebCore::GraphicsContext::fillRoundedRect):
(WebCore::GraphicsContext::setUpdatingControlTints): Deleted.
(WebCore::GraphicsContext::clip): Deleted.

  • platform/graphics/GraphicsContext.h:

(WebCore::GraphicsContext::paintingDisabled):
(WebCore::GraphicsContext::updatingControlTints):
(WebCore::GraphicsContextState::GraphicsContextState): Deleted.
(WebCore::GraphicsContext::setPaintingDisabled): Deleted.

  • platform/graphics/cairo/GraphicsContextCairo.cpp:

(WebCore::GraphicsContext::GraphicsContext):
(WebCore::GraphicsContext::platformInit):

  • platform/graphics/cg/GraphicsContextCG.cpp:

(WebCore::GraphicsContext::platformInit):
(WebCore::GraphicsContext::savePlatformState):
(WebCore::GraphicsContext::restorePlatformState):
(WebCore::GraphicsContext::drawNativeImage):
(WebCore::GraphicsContext::drawPattern):
(WebCore::GraphicsContext::drawRect):
(WebCore::GraphicsContext::applyStrokePattern):
(WebCore::GraphicsContext::applyFillPattern):
(WebCore::GraphicsContext::clip):
(WebCore::GraphicsContext::clipBounds):
(WebCore::GraphicsContext::setLineDash):
(WebCore::GraphicsContext::roundToDevicePixels):
(WebCore::GraphicsContext::setPlatformImageInterpolationQuality):
(WebCore::GraphicsContext::setIsCALayerContext):
(WebCore::GraphicsContext::isCALayerContext):
(WebCore::GraphicsContext::setIsAcceleratedContext):
(WebCore::GraphicsContext::isAcceleratedContext):
(WebCore::GraphicsContext::platformApplyDeviceScaleFactor):

  • platform/graphics/win/GraphicsContextCGWin.cpp:

(WebCore::GraphicsContext::platformInit):
(WebCore::GraphicsContext::GraphicsContext): Deleted.

  • platform/graphics/win/GraphicsContextCairoWin.cpp:

(WebCore::GraphicsContext::platformInit):
(WebCore::GraphicsContext::GraphicsContext): Deleted.

Location:
trunk/Source/WebCore
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r194796 r194798  
     12016-01-08  Simon Fraser  <simon.fraser@apple.com>
     2
     3        Consider painting to be disabled on a GraphicsContext with no platform data, and make updatingControlTints() immutable state
     4        https://bugs.webkit.org/show_bug.cgi?id=152927
     5
     6        Reviewed by Tim Horton.
     7
     8        GraphicsContext had setters for paintingDisabled and updatingControlTints, but neither
     9        were changed dynamically.
     10       
     11        We can eliminate paintingDisabled by simply considering a GraphicsContext that was
     12        created with no platform context to be paint-disabled.
     13       
     14        We make updatingControlTints immutable state by providing a constructor that takes
     15        a "NonPaintingReasons" enum, and doesn't create platform data.
     16       
     17        More functions in platform code were protected by if (paintingDisabled())...
     18
     19        * page/FrameView.cpp:
     20        (WebCore::FrameView::paintControlTints):
     21        * platform/graphics/GraphicsContext.cpp:
     22        (WebCore::GraphicsContext::GraphicsContext):
     23        (WebCore::GraphicsContext::fillRoundedRect):
     24        (WebCore::GraphicsContext::setUpdatingControlTints): Deleted.
     25        (WebCore::GraphicsContext::clip): Deleted.
     26        * platform/graphics/GraphicsContext.h:
     27        (WebCore::GraphicsContext::paintingDisabled):
     28        (WebCore::GraphicsContext::updatingControlTints):
     29        (WebCore::GraphicsContextState::GraphicsContextState): Deleted.
     30        (WebCore::GraphicsContext::setPaintingDisabled): Deleted.
     31        * platform/graphics/cairo/GraphicsContextCairo.cpp:
     32        (WebCore::GraphicsContext::GraphicsContext):
     33        (WebCore::GraphicsContext::platformInit):
     34        * platform/graphics/cg/GraphicsContextCG.cpp:
     35        (WebCore::GraphicsContext::platformInit):
     36        (WebCore::GraphicsContext::savePlatformState):
     37        (WebCore::GraphicsContext::restorePlatformState):
     38        (WebCore::GraphicsContext::drawNativeImage):
     39        (WebCore::GraphicsContext::drawPattern):
     40        (WebCore::GraphicsContext::drawRect):
     41        (WebCore::GraphicsContext::applyStrokePattern):
     42        (WebCore::GraphicsContext::applyFillPattern):
     43        (WebCore::GraphicsContext::clip):
     44        (WebCore::GraphicsContext::clipBounds):
     45        (WebCore::GraphicsContext::setLineDash):
     46        (WebCore::GraphicsContext::roundToDevicePixels):
     47        (WebCore::GraphicsContext::setPlatformImageInterpolationQuality):
     48        (WebCore::GraphicsContext::setIsCALayerContext):
     49        (WebCore::GraphicsContext::isCALayerContext):
     50        (WebCore::GraphicsContext::setIsAcceleratedContext):
     51        (WebCore::GraphicsContext::isAcceleratedContext):
     52        (WebCore::GraphicsContext::platformApplyDeviceScaleFactor):
     53        * platform/graphics/win/GraphicsContextCGWin.cpp:
     54        (WebCore::GraphicsContext::platformInit):
     55        (WebCore::GraphicsContext::GraphicsContext): Deleted.
     56        * platform/graphics/win/GraphicsContextCairoWin.cpp:
     57        (WebCore::GraphicsContext::platformInit):
     58        (WebCore::GraphicsContext::GraphicsContext): Deleted.
     59
    1602016-01-08  Anders Carlsson  <andersca@apple.com>
    261
  • trunk/Source/WebCore/page/FrameView.cpp

    r194667 r194798  
    38983898        layout();
    38993899
    3900     GraphicsContext context((PlatformGraphicsContext*)nullptr);
    3901     context.setUpdatingControlTints(true);
     3900    GraphicsContext context(GraphicsContext::NonPaintingReasons::UpdatingControlTints);
    39023901    if (platformWidget()) {
    39033902        // FIXME: consult paintsEntireContents().
  • trunk/Source/WebCore/platform/graphics/GraphicsContext.cpp

    r194775 r194798  
    360360}
    361361
     362GraphicsContext::GraphicsContext(NonPaintingReasons nonPaintingReasons)
     363    : m_nonPaintingReasons(nonPaintingReasons)
     364{
     365}
    362366
    363367GraphicsContext::GraphicsContext(PlatformGraphicsContext* platformGraphicsContext)
    364     : m_updatingControlTints(false)
    365     , m_transparencyCount(0)
    366368{
    367369    platformInit(platformGraphicsContext);
     
    571573}
    572574
    573 void GraphicsContext::setUpdatingControlTints(bool b)
    574 {
    575     setPaintingDisabled(b);
    576     m_updatingControlTints = b;
    577 }
    578 
    579575float GraphicsContext::drawText(const FontCascade& font, const TextRun& run, const FloatPoint& point, int from, int to)
    580576{
     
    733729}
    734730
    735 void GraphicsContext::clip(const IntRect& rect)
    736 {
    737     clip(FloatRect(rect));
    738 }
    739 
    740731void GraphicsContext::clipRoundedRect(const FloatRoundedRect& rect)
    741732{
     
    799790void GraphicsContext::fillRoundedRect(const FloatRoundedRect& rect, const Color& color, BlendMode blendMode)
    800791{
     792    if (paintingDisabled())
     793        return;
     794
    801795    if (rect.isRounded()) {
    802796        setCompositeOperation(compositeOperation(), blendMode);
  • trunk/Source/WebCore/platform/graphics/GraphicsContext.h

    r194757 r194798  
    117117        , antialiasedFontDilationEnabled(true)
    118118        , shouldSubpixelQuantizeFonts(true)
    119         , paintingDisabled(false)
    120119        , shadowsIgnoreTransforms(false)
    121120#if USE(CG)
     
    184183    bool antialiasedFontDilationEnabled : 1;
    185184    bool shouldSubpixelQuantizeFonts : 1;
    186     bool paintingDisabled : 1;
    187185    bool shadowsIgnoreTransforms : 1;
    188186#if USE(CG)
     
    250248    WEBCORE_EXPORT GraphicsContext(PlatformGraphicsContext*);
    251249    WEBCORE_EXPORT ~GraphicsContext();
     250   
     251    enum class NonPaintingReasons {
     252        NoReasons,
     253        UpdatingControlTints
     254    };
     255    GraphicsContext(NonPaintingReasons);
    252256
    253257    WEBCORE_EXPORT PlatformGraphicsContext* platformContext() const;
     258
     259    bool paintingDisabled() const { return !m_data; }
     260    bool updatingControlTints() const { return m_nonPaintingReasons == NonPaintingReasons::UpdatingControlTints; }
    254261
    255262    void setStrokeThickness(float);
     
    368375    InterpolationQuality imageInterpolationQuality() const { return m_state.imageInterpolationQuality; }
    369376
    370     WEBCORE_EXPORT void clip(const IntRect&);
    371377    WEBCORE_EXPORT void clip(const FloatRect&);
    372378    void clipRoundedRect(const FloatRoundedRect&);
     
    408414    static void updateDocumentMarkerResources();
    409415    void drawLineForDocumentMarker(const FloatPoint&, float width, DocumentMarkerLineStyle);
    410 
    411     void setPaintingDisabled(bool paintingDisabled) { m_state.paintingDisabled = paintingDisabled; }
    412     bool paintingDisabled() const { return m_state.paintingDisabled; }
    413 
    414     void setUpdatingControlTints(bool);
    415     bool updatingControlTints() const { return m_updatingControlTints; }
    416416
    417417    WEBCORE_EXPORT void beginTransparencyLayer(float opacity);
     
    602602    FloatRect computeLineBoundsAndAntialiasingModeForText(const FloatPoint&, float width, bool printing,  Color&);
    603603
    604     GraphicsContextPlatformPrivate* m_data;
     604    GraphicsContextPlatformPrivate* m_data { nullptr };
    605605
    606606    GraphicsContextState m_state;
    607607    Vector<GraphicsContextState, 1> m_stack;
    608     bool m_updatingControlTints;
    609     unsigned m_transparencyCount;
     608
     609    const NonPaintingReasons m_nonPaintingReasons { NonPaintingReasons::NoReasons };
     610    unsigned m_transparencyCount { 0 };
    610611};
    611612
  • trunk/Source/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp

    r194757 r194798  
    176176
    177177GraphicsContext::GraphicsContext(cairo_t* cr)
    178     : m_updatingControlTints(false)
    179     , m_transparencyCount(0)
    180 {
     178{
     179    if (!cr)
     180        return;
     181
    181182    m_data = new GraphicsContextPlatformPrivateToplevel(new PlatformContextCairo(cr));
    182183}
     
    184185void GraphicsContext::platformInit(PlatformContextCairo* platformContext)
    185186{
     187    if (!platformContext)
     188        return;
     189
    186190    m_data = new GraphicsContextPlatformPrivate(platformContext);
    187     if (platformContext)
    188         m_data->syncContext(platformContext->cr());
    189     else
    190         setPaintingDisabled(true);
     191    m_data->syncContext(platformContext->cr());
    191192}
    192193
  • trunk/Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp

    r194757 r194798  
    116116void GraphicsContext::platformInit(CGContextRef cgContext)
    117117{
     118    if (!cgContext)
     119        return;
     120
    118121    m_data = new GraphicsContextPlatformPrivate(cgContext);
    119     setPaintingDisabled(!cgContext);
    120     if (cgContext) {
    121         // Make sure the context starts in sync with our state.
    122         setPlatformFillColor(fillColor());
    123         setPlatformStrokeColor(strokeColor());
    124         setPlatformStrokeThickness(strokeThickness());
    125         m_state.imageInterpolationQuality = convertInterpolationQuality(CGContextGetInterpolationQuality(platformContext()));
    126     }
     122    // Make sure the context starts in sync with our state.
     123    setPlatformFillColor(fillColor());
     124    setPlatformStrokeColor(strokeColor());
     125    setPlatformStrokeThickness(strokeThickness());
     126    m_state.imageInterpolationQuality = convertInterpolationQuality(CGContextGetInterpolationQuality(platformContext()));
    127127}
    128128
     
    141141void GraphicsContext::savePlatformState()
    142142{
     143    ASSERT(!paintingDisabled());
    143144    // Note: Do not use this function within this class implementation, since we want to avoid the extra
    144145    // save of the secondary context (in GraphicsContextPlatformPrivateCG.h).
     
    149150void GraphicsContext::restorePlatformState()
    150151{
     152    ASSERT(!paintingDisabled());
    151153    // Note: Do not use this function within this class implementation, since we want to avoid the extra
    152154    // restore of the secondary context (in GraphicsContextPlatformPrivateCG.h).
     
    158160void GraphicsContext::drawNativeImage(PassNativeImagePtr imagePtr, const FloatSize& imageSize, const FloatRect& destRect, const FloatRect& srcRect, CompositeOperator op, BlendMode blendMode, ImageOrientation orientation)
    159161{
     162    if (paintingDisabled())
     163        return;
     164
    160165    RetainPtr<CGImageRef> image(imagePtr);
    161166
     
    272277void GraphicsContext::drawPattern(Image& image, const FloatRect& tileRect, const AffineTransform& patternTransform, const FloatPoint& phase, const FloatSize& spacing, CompositeOperator op, const FloatRect& destRect, BlendMode blendMode)
    273278{
    274     if (!patternTransform.isInvertible())
     279    if (paintingDisabled() || !patternTransform.isInvertible())
    275280        return;
    276281
     
    372377void GraphicsContext::drawRect(const FloatRect& rect, float borderThickness)
    373378{
    374     // FIXME: this function does not handle patterns and gradients
    375     // like drawPath does, it probably should.
    376     if (paintingDisabled())
    377         return;
    378 
     379    if (paintingDisabled())
     380        return;
     381
     382    // FIXME: this function does not handle patterns and gradients like drawPath does, it probably should.
    379383    ASSERT(!rect.isEmpty());
    380384
     
    553557void GraphicsContext::applyStrokePattern()
    554558{
     559    if (paintingDisabled())
     560        return;
     561
    555562    CGContextRef cgContext = platformContext();
    556563    AffineTransform userToBaseCTM = AffineTransform(getUserToBaseCTM(cgContext));
     
    569576void GraphicsContext::applyFillPattern()
    570577{
     578    if (paintingDisabled())
     579        return;
     580
    571581    CGContextRef cgContext = platformContext();
    572582    AffineTransform userToBaseCTM = AffineTransform(getUserToBaseCTM(cgContext));
     
    922932    if (paintingDisabled())
    923933        return;
     934
    924935    CGContextClipToRect(platformContext(), rect);
    925936    m_data->clip(rect);
     
    966977IntRect GraphicsContext::clipBounds() const
    967978{
     979    if (paintingDisabled())
     980        return IntRect();
     981
    968982    return enclosingIntRect(CGContextGetClipBoundingBox(platformContext()));
    969983}
     
    11731187void GraphicsContext::setLineDash(const DashArray& dashes, float dashOffset)
    11741188{
     1189    if (paintingDisabled())
     1190        return;
     1191
    11751192    if (dashOffset < 0) {
    11761193        float length = 0;
     
    12781295FloatRect GraphicsContext::roundToDevicePixels(const FloatRect& rect, RoundingMode roundingMode)
    12791296{
     1297    if (paintingDisabled())
     1298        return rect;
     1299
    12801300    // It is not enough just to round to pixels in device space. The rotation part of the
    12811301    // affine transform matrix to device space can mess with this conversion if we have a
     
    13911411void GraphicsContext::setPlatformImageInterpolationQuality(InterpolationQuality mode)
    13921412{
     1413    ASSERT(!paintingDisabled());
     1414
    13931415    CGInterpolationQuality quality = kCGInterpolationDefault;
    13941416    switch (mode) {
     
    14141436void GraphicsContext::setIsCALayerContext(bool isLayerContext)
    14151437{
     1438    if (paintingDisabled())
     1439        return;
     1440
    14161441    if (isLayerContext)
    14171442        m_data->m_contextFlags |= IsLayerCGContext;
     
    14221447bool GraphicsContext::isCALayerContext() const
    14231448{
     1449    if (paintingDisabled())
     1450        return false;
     1451
    14241452    return m_data->m_contextFlags & IsLayerCGContext;
    14251453}
     
    14271455void GraphicsContext::setIsAcceleratedContext(bool isAccelerated)
    14281456{
     1457    if (paintingDisabled())
     1458        return;
     1459
    14291460    if (isAccelerated)
    14301461        m_data->m_contextFlags |= IsAcceleratedCGContext;
     
    14351466bool GraphicsContext::isAcceleratedContext() const
    14361467{
     1468    if (paintingDisabled())
     1469        return false;
     1470
    14371471    return m_data->m_contextFlags & IsAcceleratedCGContext;
    14381472}
     
    16141648void GraphicsContext::platformApplyDeviceScaleFactor(float deviceScaleFactor)
    16151649{
     1650    if (paintingDisabled())
     1651        return;
     1652
    16161653    // CoreGraphics expects the base CTM of a HiDPI context to have the scale factor applied to it.
    16171654    // Failing to change the base level CTM will cause certain CG features, such as focus rings,
  • trunk/Source/WebCore/platform/graphics/win/GraphicsContextCGWin.cpp

    r194421 r194798  
    6969
    7070GraphicsContext::GraphicsContext(HDC hdc, bool hasAlpha)
    71     : m_updatingControlTints(false),
    72       m_transparencyCount(0)
    7371{
    7472    platformInit(hdc, hasAlpha);
     
    7775void GraphicsContext::platformInit(HDC hdc, bool hasAlpha)
    7876{
     77    if (!hdc)
     78        return;
     79
    7980    m_data = new GraphicsContextPlatformPrivate(CGContextWithHDC(hdc, hasAlpha));
    8081    CGContextRelease(m_data->m_cgContext.get());
    8182    m_data->m_hdc = hdc;
    82     setPaintingDisabled(!m_data->m_cgContext);
    8383    if (m_data->m_cgContext) {
    8484        // Make sure the context starts in sync with our state.
  • trunk/Source/WebCore/platform/graphics/win/GraphicsContextCairoWin.cpp

    r192140 r194798  
    6868
    6969GraphicsContext::GraphicsContext(HDC dc, bool hasAlpha)
    70     : m_updatingControlTints(false),
    71       m_transparencyCount(0)
    7270{
    7371    platformInit(dc, hasAlpha);
     
    7674void GraphicsContext::platformInit(HDC dc, bool hasAlpha)
    7775{
    78     cairo_t* cr = 0;
    79     if (dc)
    80         cr = createCairoContextWithHDC(dc, hasAlpha);
    81     else
    82         setPaintingDisabled(true);
     76    if (!dc)
     77        return;
     78
     79    cairo_t* cr = createCairoContextWithHDC(dc, hasAlpha);
    8380
    8481    m_data = new GraphicsContextPlatformPrivateToplevel(new PlatformContextCairo(cr));
Note: See TracChangeset for help on using the changeset viewer.