⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 99803 in webkit


Ignore:
Timestamp:
Nov 9, 2011, 7:10:09 PM (15 years ago)
Author:
Martin Robinson
Message:

[Cairo] Avoid clipping when painting more often
https://bugs.webkit.org/show_bug.cgi?id=71179

Reviewed by Xan Lopez.

No new tests. These changes are covered by existing tests.

  • platform/graphics/Gradient.h: Add a Cairo-specific method

that gets the platform gradient with a particular alpha value.

  • platform/graphics/cairo/GradientCairo.cpp: Now cache the alpha

value of the last created platform gradient.
(WebCore::Gradient::platformGradient): If the cached platform gradient
has a different alpha value than the one requested, destroy it and start
over.

  • platform/graphics/cairo/GraphicsContextCairo.cpp:

(WebCore::drawPathShadow): Adjust the source to avoid calling
cairo_clip/cairo_paint_with_alpha and just do a fill.
(WebCore::shadowAndFillCurrentCairoPath): No need to clip here. Just
call cairo_fill.

  • platform/graphics/cairo/PlatformContextCairo.cpp:

(WebCore::drawPatternToCairoContext): If we have a >= 1 alpha value
we can simply fill and avoid calling cairo_clip here.
(WebCore::prepareCairoContextSource): Remove TODO about recreating the
gradient. No longer need to reduce the gradient source.

Location:
trunk/Source/WebCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r99800 r99803  
     12011-11-09  Martin Robinson  <mrobinson@igalia.com>
     2
     3        [Cairo] Avoid clipping when painting more often
     4        https://bugs.webkit.org/show_bug.cgi?id=71179
     5
     6        Reviewed by Xan Lopez.
     7
     8        No new tests. These changes are covered by existing tests.
     9
     10        * platform/graphics/Gradient.h: Add a Cairo-specific method
     11        that gets the platform gradient with a particular alpha value.
     12        * platform/graphics/cairo/GradientCairo.cpp: Now cache the alpha
     13        value of the last created platform gradient.
     14        (WebCore::Gradient::platformGradient): If the cached platform gradient
     15        has a different alpha value than the one requested, destroy it and start
     16        over.
     17        * platform/graphics/cairo/GraphicsContextCairo.cpp:
     18        (WebCore::drawPathShadow): Adjust the source to avoid calling
     19        cairo_clip/cairo_paint_with_alpha and just do a fill.
     20        (WebCore::shadowAndFillCurrentCairoPath): No need to clip here. Just
     21        call cairo_fill.
     22        * platform/graphics/cairo/PlatformContextCairo.cpp:
     23        (WebCore::drawPatternToCairoContext): If we have a >= 1 alpha value
     24        we can simply fill and avoid calling cairo_clip here.
     25        (WebCore::prepareCairoContextSource): Remove TODO about recreating the
     26        gradient. No longer need to reduce the gradient source.
     27
    1282011-11-09  Alexey Proskuryakov  <ap@apple.com>
    229
  • trunk/Source/WebCore/platform/graphics/Gradient.h

    r95922 r99803  
    139139        void paint(CGContextRef);
    140140        void paint(GraphicsContext*);
     141#elif USE(CAIRO)
     142        PlatformGradient platformGradient(float globalAlpha);
    141143#endif
    142144
     
    164166
    165167        PlatformGradient m_gradient;
     168
     169#if USE(CAIRO)
     170        float m_platformGradientAlpha;
     171#endif
     172
    166173    };
    167174
  • trunk/Source/WebCore/platform/graphics/cairo/GradientCairo.cpp

    r95901 r99803  
    4545cairo_pattern_t* Gradient::platformGradient()
    4646{
    47     if (m_gradient)
     47    return platformGradient(1);
     48}
     49
     50cairo_pattern_t* Gradient::platformGradient(float globalAlpha)
     51{
     52    if (m_gradient && m_platformGradientAlpha == globalAlpha)
    4853        return m_gradient;
     54
     55    platformDestroy();
     56    m_platformGradientAlpha = globalAlpha;
    4957
    5058    if (m_radial)
     
    5563    Vector<ColorStop>::iterator stopIterator = m_stops.begin();
    5664    while (stopIterator != m_stops.end()) {
    57         cairo_pattern_add_color_stop_rgba(m_gradient, stopIterator->stop, stopIterator->red, stopIterator->green, stopIterator->blue, stopIterator->alpha);
     65        cairo_pattern_add_color_stop_rgba(m_gradient, stopIterator->stop,
     66                                          stopIterator->red, stopIterator->green, stopIterator->blue,
     67                                          stopIterator->alpha * globalAlpha);
    5868        ++stopIterator;
    5969    }
  • trunk/Source/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp

    r95685 r99803  
    135135        cairo_append_path(cairoShadowContext, path.get());
    136136        shadowContext->platformContext()->prepareForFilling(context->state(), PlatformContextCairo::NoAdjustment);
    137         cairo_clip(cairoShadowContext);
    138         cairo_paint(cairoShadowContext);
     137        cairo_fill(cairoShadowContext);
    139138        cairo_restore(cairoShadowContext);
    140139    }
     
    158157    cairo_save(cr);
    159158
    160     context->platformContext()->prepareForFilling(context->state(), PlatformContextCairo::NoAdjustment);
    161 
    162159    drawPathShadow(context, Fill);
    163160
    164     cairo_clip(cr);
    165     cairo_paint_with_alpha(cr, context->platformContext()->globalAlpha());
     161    context->platformContext()->prepareForFilling(context->state(), PlatformContextCairo::AdjustPatternForGlobalAlpha);
     162    cairo_fill(cr);
     163
    166164    cairo_restore(cr);
    167165}
  • trunk/Source/WebCore/platform/graphics/cairo/PlatformContextCairo.cpp

    r95901 r99803  
    144144    cairo_set_source(cr, pattern);
    145145    cairo_rectangle(cr, 0, 0, destRect.width(), destRect.height());
    146     cairo_clip(cr);
    147     cairo_paint_with_alpha(cr, alpha);
     146
     147    if (alpha < 1) {
     148        cairo_clip(cr);
     149        cairo_paint_with_alpha(cr, alpha);
     150    } else
     151        cairo_fill(cr);
    148152}
    149153
     
    214218        cairo_set_source(cr, cairoPattern.get());
    215219        reduceSourceByAlpha(cr, globalAlpha);
    216     } else if (gradient) {
    217         cairo_set_source(cr, gradient->platformGradient());
    218 
    219         // FIXME: It would be faster to simply recreate the Cairo gradient and multiply the
    220         // color stops by the global alpha.
    221         reduceSourceByAlpha(cr, globalAlpha);
    222     } else { // Solid color source.
     220    } else if (gradient)
     221        cairo_set_source(cr, gradient->platformGradient(globalAlpha));
     222    else { // Solid color source.
    223223        if (globalAlpha < 1)
    224224            setSourceRGBAFromColor(cr, colorWithOverrideAlpha(color.rgb(), color.alpha() / 255.f * globalAlpha));
Note: See TracChangeset for help on using the changeset viewer.