Changeset 227065 in webkit


Ignore:
Timestamp:
Jan 17, 2018, 5:06:01 AM (8 years ago)
Author:
zandobersek@gmail.com
Message:

[Cairo] Don't mirror global alpha and image interpolation quality state values in PlatformContextCairo
https://bugs.webkit.org/show_bug.cgi?id=181725

Reviewed by Carlos Garcia Campos.

Source/WebCore:

Don't duplicate global alpha and image interpolation quality state
values on the PlatformContextCairo. Instead, retrieve them from
the managing GraphicsContextState when necessary.

For Cairo operations, the FillSource and StrokeSource containers now
store the global alpha value, using it during the operation executions.
For drawNativeImage(), the global alpha and interpolation quality values
are passed through arguments.

In PlatformContextCairo, the two values are no longer stored on the
internally-managed stack, and the getter-setter pairs for the two values
are removed. In drawSurfaceToContext(), the two values are now expected
to be passed through the method arguments.

No new tests -- no change in behavior.

  • platform/graphics/cairo/CairoOperations.cpp:

(WebCore::Cairo::prepareForFilling):
(WebCore::Cairo::prepareForStroking):
(WebCore::Cairo::drawPathShadow):
(WebCore::Cairo::fillCurrentCairoPath):
(WebCore::Cairo::FillSource::FillSource):
(WebCore::Cairo::StrokeSource::StrokeSource):
(WebCore::Cairo::strokeRect):
(WebCore::Cairo::strokePath):
(WebCore::Cairo::drawGlyphs):
(WebCore::Cairo::drawNativeImage):
(WebCore::Cairo::State::setGlobalAlpha): Deleted.
(WebCore::Cairo::State::setImageInterpolationQuality): Deleted.

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

(WebCore::GraphicsContext::drawNativeImage):
(WebCore::GraphicsContext::setPlatformAlpha):
(WebCore::GraphicsContext::setPlatformImageInterpolationQuality):

  • platform/graphics/cairo/PlatformContextCairo.cpp:

(WebCore::PlatformContextCairo::save):
(WebCore::PlatformContextCairo::drawSurfaceToContext):
(WebCore::PlatformContextCairo::State::State): Deleted.
(WebCore::PlatformContextCairo::setImageInterpolationQuality): Deleted.
(WebCore::PlatformContextCairo::imageInterpolationQuality const): Deleted.
(WebCore::PlatformContextCairo::globalAlpha const): Deleted.
(WebCore::PlatformContextCairo::setGlobalAlpha): Deleted.

  • platform/graphics/cairo/PlatformContextCairo.h:
  • platform/graphics/win/MediaPlayerPrivateMediaFoundation.cpp:

(WebCore::MediaPlayerPrivateMediaFoundation::Direct3DPresenter::paintCurrentFrame):

Source/WebKit:

  • Shared/cairo/ShareableBitmapCairo.cpp:

(WebKit::ShareableBitmap::paint):
Adjust the PlatformContextCairo::drawSurfaceToContext() invocation.

  • WebProcess/WebCoreSupport/gtk/WebDragClientGtk.cpp:

(WebKit::convertCairoSurfaceToShareableBitmap): Ditto.

Location:
trunk/Source
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r227061 r227065  
     12018-01-17  Zan Dobersek  <zdobersek@igalia.com>
     2
     3        [Cairo] Don't mirror global alpha and image interpolation quality state values in PlatformContextCairo
     4        https://bugs.webkit.org/show_bug.cgi?id=181725
     5
     6        Reviewed by Carlos Garcia Campos.
     7
     8        Don't duplicate global alpha and image interpolation quality state
     9        values on the PlatformContextCairo. Instead, retrieve them from
     10        the managing GraphicsContextState when necessary.
     11
     12        For Cairo operations, the FillSource and StrokeSource containers now
     13        store the global alpha value, using it during the operation executions.
     14        For drawNativeImage(), the global alpha and interpolation quality values
     15        are passed through arguments.
     16
     17        In PlatformContextCairo, the two values are no longer stored on the
     18        internally-managed stack, and the getter-setter pairs for the two values
     19        are removed. In drawSurfaceToContext(), the two values are now expected
     20        to be passed through the method arguments.
     21
     22        No new tests -- no change in behavior.
     23
     24        * platform/graphics/cairo/CairoOperations.cpp:
     25        (WebCore::Cairo::prepareForFilling):
     26        (WebCore::Cairo::prepareForStroking):
     27        (WebCore::Cairo::drawPathShadow):
     28        (WebCore::Cairo::fillCurrentCairoPath):
     29        (WebCore::Cairo::FillSource::FillSource):
     30        (WebCore::Cairo::StrokeSource::StrokeSource):
     31        (WebCore::Cairo::strokeRect):
     32        (WebCore::Cairo::strokePath):
     33        (WebCore::Cairo::drawGlyphs):
     34        (WebCore::Cairo::drawNativeImage):
     35        (WebCore::Cairo::State::setGlobalAlpha): Deleted.
     36        (WebCore::Cairo::State::setImageInterpolationQuality): Deleted.
     37        * platform/graphics/cairo/CairoOperations.h:
     38        * platform/graphics/cairo/GraphicsContextCairo.cpp:
     39        (WebCore::GraphicsContext::drawNativeImage):
     40        (WebCore::GraphicsContext::setPlatformAlpha):
     41        (WebCore::GraphicsContext::setPlatformImageInterpolationQuality):
     42        * platform/graphics/cairo/PlatformContextCairo.cpp:
     43        (WebCore::PlatformContextCairo::save):
     44        (WebCore::PlatformContextCairo::drawSurfaceToContext):
     45        (WebCore::PlatformContextCairo::State::State): Deleted.
     46        (WebCore::PlatformContextCairo::setImageInterpolationQuality): Deleted.
     47        (WebCore::PlatformContextCairo::imageInterpolationQuality const): Deleted.
     48        (WebCore::PlatformContextCairo::globalAlpha const): Deleted.
     49        (WebCore::PlatformContextCairo::setGlobalAlpha): Deleted.
     50        * platform/graphics/cairo/PlatformContextCairo.h:
     51        * platform/graphics/win/MediaPlayerPrivateMediaFoundation.cpp:
     52        (WebCore::MediaPlayerPrivateMediaFoundation::Direct3DPresenter::paintCurrentFrame):
     53
    1542018-01-17  Philippe Normand  <pnormand@igalia.com>
    255
  • trunk/Source/WebCore/platform/graphics/cairo/CairoOperations.cpp

    r227055 r227065  
    114114}
    115115
    116 static void prepareForFilling(cairo_t* cr, const Cairo::FillSource& fillSource, float globalAlpha, PatternAdjustment patternAdjustment)
     116static void prepareForFilling(cairo_t* cr, const Cairo::FillSource& fillSource, PatternAdjustment patternAdjustment)
    117117{
    118118    cairo_set_fill_rule(cr, fillSource.fillRule == RULE_EVENODD ? CAIRO_FILL_RULE_EVEN_ODD : CAIRO_FILL_RULE_WINDING);
     
    125125
    126126    prepareCairoContextSource(cr, fillSource.pattern.object.get(), gradient,
    127         fillSource.color, adjustForAlpha ? globalAlpha : 1);
     127        fillSource.color, adjustForAlpha ? fillSource.globalAlpha : 1);
    128128
    129129    if (fillSource.pattern.object) {
     
    133133}
    134134
    135 void prepareForStroking(cairo_t* cr, const Cairo::StrokeSource& strokeSource, float globalAlpha, AlphaPreservation alphaPreservation)
     135void prepareForStroking(cairo_t* cr, const Cairo::StrokeSource& strokeSource, AlphaPreservation alphaPreservation)
    136136{
    137137    bool preserveAlpha = alphaPreservation == PreserveAlpha;
     
    142142
    143143    prepareCairoContextSource(cr, strokeSource.pattern.get(), gradient,
    144         strokeSource.color, preserveAlpha ? globalAlpha : 1);
     144        strokeSource.color, preserveAlpha ? strokeSource.globalAlpha : 1);
    145145}
    146146
     
    201201        cairo_save(cairoShadowContext);
    202202        cairo_append_path(cairoShadowContext, path.get());
    203         prepareForFilling(cairoShadowContext, fillSource, shadowContext->platformContext()->globalAlpha(), NoAdjustment);
     203        prepareForFilling(cairoShadowContext, fillSource, NoAdjustment);
    204204        cairo_fill(cairoShadowContext);
    205205        cairo_restore(cairoShadowContext);
     
    208208    if (drawingStyle & Stroke) {
    209209        cairo_append_path(cairoShadowContext, path.get());
    210         prepareForStroking(cairoShadowContext, strokeSource, shadowContext->platformContext()->globalAlpha(), DoNotPreserveAlpha);
     210        prepareForStroking(cairoShadowContext, strokeSource, DoNotPreserveAlpha);
    211211        cairo_stroke(cairoShadowContext);
    212212    }
     
    226226    cairo_save(cr);
    227227
    228     prepareForFilling(cr, fillSource, platformContext.globalAlpha(), AdjustPatternForGlobalAlpha);
     228    prepareForFilling(cr, fillSource, AdjustPatternForGlobalAlpha);
    229229    cairo_fill(cr);
    230230
     
    431431}
    432432
    433 void setGlobalAlpha(PlatformContextCairo& platformContext, float alpha)
    434 {
    435     platformContext.setGlobalAlpha(alpha);
    436 }
    437 
    438433void setCompositeOperation(PlatformContextCairo& platformContext, CompositeOperator compositeOperation, BlendMode blendMode)
    439434{
     
    447442    // antialiasing.
    448443    cairo_set_antialias(platformContext.cr(), enable ? CAIRO_ANTIALIAS_DEFAULT : CAIRO_ANTIALIAS_NONE);
    449 }
    450 
    451 void setImageInterpolationQuality(PlatformContextCairo& platformContext, InterpolationQuality quality)
    452 {
    453     platformContext.setImageInterpolationQuality(quality);
    454444}
    455445
     
    523513
    524514FillSource::FillSource(const GraphicsContextState& state)
     515    : globalAlpha(state.alpha)
     516    , fillRule(state.fillRule)
    525517{
    526518    if (state.fillPattern) {
     
    538530    } else
    539531        color = state.fillColor;
    540 
    541     fillRule = state.fillRule;
    542532}
    543533
    544534StrokeSource::StrokeSource(const GraphicsContextState& state)
     535    : globalAlpha(state.alpha)
    545536{
    546537    if (state.strokePattern)
     
    721712    cairo_set_line_width(cr, lineWidth);
    722713    drawPathShadow(platformContext, { }, strokeSource, shadowState, targetContext, Stroke);
    723     prepareForStroking(cr, strokeSource, platformContext.globalAlpha(), PreserveAlpha);
     714    prepareForStroking(cr, strokeSource, PreserveAlpha);
    724715    cairo_stroke(cr);
    725716
     
    733724    setPathOnCairoContext(cr, path.platformPath()->context());
    734725    drawPathShadow(platformContext, { }, strokeSource, shadowState, targetContext, Stroke);
    735     prepareForStroking(cr, strokeSource, platformContext.globalAlpha(), PreserveAlpha);
     726    prepareForStroking(cr, strokeSource, PreserveAlpha);
    736727    cairo_stroke(cr);
    737728}
     
    756747
    757748    if (textDrawingMode & TextModeFill) {
    758         prepareForFilling(cr, fillSource, platformContext.globalAlpha(), AdjustPatternForGlobalAlpha);
     749        prepareForFilling(cr, fillSource, AdjustPatternForGlobalAlpha);
    759750        drawGlyphsToContext(cr, scaledFont, syntheticBoldOffset, glyphs);
    760751    }
     
    765756    //  See https://bugs.webkit.org/show_bug.cgi?id=33759.
    766757    if (textDrawingMode & TextModeStroke && strokeThickness < 2 * xOffset) {
    767         prepareForStroking(cr, strokeSource, platformContext.globalAlpha(), PreserveAlpha);
     758        prepareForStroking(cr, strokeSource, PreserveAlpha);
    768759        cairo_set_line_width(cr, strokeThickness);
    769760
     
    777768}
    778769
    779 void drawNativeImage(PlatformContextCairo& platformContext, cairo_surface_t* surface, const FloatRect& destRect, const FloatRect& srcRect, CompositeOperator compositeOperator, BlendMode blendMode, ImageOrientation orientation, const ShadowState& shadowState, GraphicsContext& targetContext)
     770void drawNativeImage(PlatformContextCairo& platformContext, cairo_surface_t* surface, const FloatRect& destRect, const FloatRect& srcRect, CompositeOperator compositeOperator, BlendMode blendMode, ImageOrientation orientation, InterpolationQuality imageInterpolationQuality, float globalAlpha, const ShadowState& shadowState, GraphicsContext& targetContext)
    780771{
    781772    platformContext.save();
     
    800791    }
    801792
    802     platformContext.drawSurfaceToContext(surface, dst, srcRect, shadowState, targetContext);
     793    platformContext.drawSurfaceToContext(surface, dst, srcRect, imageInterpolationQuality, globalAlpha, shadowState, targetContext);
    803794    platformContext.restore();
    804795}
  • trunk/Source/WebCore/platform/graphics/cairo/CairoOperations.h

    r227051 r227065  
    6060void setStrokeStyle(PlatformContextCairo&, StrokeStyle);
    6161
    62 void setGlobalAlpha(PlatformContextCairo&, float);
    6362void setCompositeOperation(PlatformContextCairo&, CompositeOperator, BlendMode);
    6463void setShouldAntialias(PlatformContextCairo&, bool);
    65 void setImageInterpolationQuality(PlatformContextCairo&, InterpolationQuality);
    6664
    6765void setCTM(PlatformContextCairo&, const AffineTransform&);
     
    7977    explicit FillSource(const GraphicsContextState&);
    8078
     79    float globalAlpha { 0 };
    8180    struct {
    8281        RefPtr<cairo_pattern_t> object;
     
    9998    explicit StrokeSource(const GraphicsContextState&);
    10099
     100    float globalAlpha { 0 };
    101101    RefPtr<cairo_pattern_t> pattern;
    102102    struct {
     
    136136void drawGlyphs(PlatformContextCairo&, const FillSource&, const StrokeSource&, const ShadowState&, const FloatPoint&, cairo_scaled_font_t*, double, const Vector<cairo_glyph_t>&, float, TextDrawingModeFlags, float, const FloatSize&, const Color&, GraphicsContext&);
    137137
    138 void drawNativeImage(PlatformContextCairo&, cairo_surface_t*, const FloatRect&, const FloatRect&, CompositeOperator, BlendMode, ImageOrientation, const ShadowState&, GraphicsContext&);
     138void drawNativeImage(PlatformContextCairo&, cairo_surface_t*, const FloatRect&, const FloatRect&, CompositeOperator, BlendMode, ImageOrientation, InterpolationQuality, float, const ShadowState&, GraphicsContext&);
    139139void drawPattern(PlatformContextCairo&, cairo_surface_t*, const IntSize&, const FloatRect&, const FloatRect&, const AffineTransform&, const FloatPoint&, CompositeOperator, BlendMode);
    140140
  • trunk/Source/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp

    r227051 r227065  
    140140
    141141    ASSERT(hasPlatformContext());
    142     Cairo::drawNativeImage(*platformContext(), image.get(), destRect, srcRect, compositeOperator, blendMode, orientation, Cairo::ShadowState(state()), *this);
     142    auto& state = this->state();
     143    Cairo::drawNativeImage(*platformContext(), image.get(), destRect, srcRect, compositeOperator, blendMode, orientation, state.imageInterpolationQuality, state.alpha, Cairo::ShadowState(state), *this);
    143144}
    144145
     
    574575}
    575576
    576 void GraphicsContext::setPlatformAlpha(float alpha)
    577 {
    578     Cairo::State::setGlobalAlpha(*platformContext(), alpha);
     577void GraphicsContext::setPlatformAlpha(float)
     578{
    579579}
    580580
     
    697697}
    698698
    699 void GraphicsContext::setPlatformImageInterpolationQuality(InterpolationQuality quality)
    700 {
    701     ASSERT(hasPlatformContext());
    702     Cairo::State::setImageInterpolationQuality(*platformContext(), quality);
     699void GraphicsContext::setPlatformImageInterpolationQuality(InterpolationQuality)
     700{
    703701}
    704702
  • trunk/Source/WebCore/platform/graphics/cairo/PlatformContextCairo.cpp

    r227055 r227065  
    6363class PlatformContextCairo::State {
    6464public:
    65     State()
    66         : m_globalAlpha(1)
    67         , m_imageInterpolationQuality(InterpolationDefault)
    68     {
    69     }
    70 
    71     State(float globalAlpha, InterpolationQuality imageInterpolationQuality)
    72         : m_globalAlpha(globalAlpha)
    73         , m_imageInterpolationQuality(imageInterpolationQuality)
    74     {
    75         // We do not copy m_imageMaskInformation because otherwise it would be applied
    76         // more than once during subsequent calls to restore().
    77     }
     65    State() = default;
    7866
    7967    ImageMaskInformation m_imageMaskInformation;
    80     float m_globalAlpha;
    81     InterpolationQuality m_imageInterpolationQuality;
    8268};
    8369
     
    10995void PlatformContextCairo::save()
    11096{
    111     m_stateStack.append(State(m_state->m_globalAlpha, m_state->m_imageInterpolationQuality));
     97    m_stateStack.append(State());
    11298    m_state = &m_stateStack.last();
    11399
     
    158144}
    159145
    160 void PlatformContextCairo::drawSurfaceToContext(cairo_surface_t* surface, const FloatRect& destRect, const FloatRect& originalSrcRect, const Cairo::ShadowState& shadowState, GraphicsContext& context)
     146void PlatformContextCairo::drawSurfaceToContext(cairo_surface_t* surface, const FloatRect& destRect, const FloatRect& originalSrcRect, InterpolationQuality imageInterpolationQuality, float globalAlpha, const Cairo::ShadowState& shadowState, GraphicsContext& context)
    161147{
    162148    // Avoid invalid cairo matrix with small values.
     
    195181
    196182    ASSERT(m_state);
    197     switch (m_state->m_imageInterpolationQuality) {
     183    switch (imageInterpolationQuality) {
    198184    case InterpolationNone:
    199185    case InterpolationLow:
     
    228214
    229215    cairo_save(m_cr.get());
    230     drawPatternToCairoContext(m_cr.get(), pattern.get(), destRect, globalAlpha());
     216    drawPatternToCairoContext(m_cr.get(), pattern.get(), destRect, globalAlpha);
    231217    cairo_restore(m_cr.get());
    232218}
    233219
    234 void PlatformContextCairo::setImageInterpolationQuality(InterpolationQuality quality)
    235 {
    236     ASSERT(m_state);
    237     m_state->m_imageInterpolationQuality = quality;
    238 }
    239 
    240 InterpolationQuality PlatformContextCairo::imageInterpolationQuality() const
    241 {
    242     ASSERT(m_state);
    243     return m_state->m_imageInterpolationQuality;
    244 }
    245 
    246 
    247 float PlatformContextCairo::globalAlpha() const
    248 {
    249     return m_state->m_globalAlpha;
    250 }
    251 
    252 void PlatformContextCairo::setGlobalAlpha(float globalAlpha)
    253 {
    254     m_state->m_globalAlpha = globalAlpha;
    255 }
    256 
    257220} // namespace WebCore
    258221
  • trunk/Source/WebCore/platform/graphics/cairo/PlatformContextCairo.h

    r227055 r227065  
    6565    void save();
    6666    void restore();
    67     void setGlobalAlpha(float);
    68     float globalAlpha() const;
    6967
    7068    void pushImageMask(cairo_surface_t*, const FloatRect&);
    71     WEBCORE_EXPORT void drawSurfaceToContext(cairo_surface_t*, const FloatRect& destRect, const FloatRect& srcRect, const Cairo::ShadowState&, GraphicsContext&);
    72 
    73     void setImageInterpolationQuality(InterpolationQuality);
    74     InterpolationQuality imageInterpolationQuality() const;
     69    WEBCORE_EXPORT void drawSurfaceToContext(cairo_surface_t*, const FloatRect& destRect, const FloatRect& srcRect, InterpolationQuality, float globalAlpha, const Cairo::ShadowState&, GraphicsContext&);
    7570
    7671private:
  • trunk/Source/WebCore/platform/graphics/win/MediaPlayerPrivateMediaFoundation.cpp

    r227051 r227065  
    29752975        if (image) {
    29762976            WebCore::PlatformContextCairo* ctxt = context.platformContext();
    2977             ctxt->drawSurfaceToContext(image, destRect, srcRect, Cairo::ShadowState(context.state()), context);
     2977            auto& state = context.state();
     2978            ctxt->drawSurfaceToContext(image, destRect, srcRect, state.imageInterpolationQuality, state.alpha, Cairo::ShadowState(state), context);
    29782979            cairo_surface_destroy(image);
    29792980        }
  • trunk/Source/WebKit/ChangeLog

    r227058 r227065  
     12018-01-17  Zan Dobersek  <zdobersek@igalia.com>
     2
     3        [Cairo] Don't mirror global alpha and image interpolation quality state values in PlatformContextCairo
     4        https://bugs.webkit.org/show_bug.cgi?id=181725
     5
     6        Reviewed by Carlos Garcia Campos.
     7
     8        * Shared/cairo/ShareableBitmapCairo.cpp:
     9        (WebKit::ShareableBitmap::paint):
     10        Adjust the PlatformContextCairo::drawSurfaceToContext() invocation.
     11        * WebProcess/WebCoreSupport/gtk/WebDragClientGtk.cpp:
     12        (WebKit::convertCairoSurfaceToShareableBitmap): Ditto.
     13
    1142018-01-17  Carlos Garcia Campos  <cgarcia@igalia.com>
    215
  • trunk/Source/WebKit/Shared/cairo/ShareableBitmapCairo.cpp

    r227051 r227065  
    7676    FloatRect srcRectScaled(srcRect);
    7777    srcRectScaled.scale(scaleFactor);
    78     context.platformContext()->drawSurfaceToContext(surface.get(), destRect, srcRectScaled, Cairo::ShadowState(context.state()), context);
     78    auto& state = context.state();
     79    context.platformContext()->drawSurfaceToContext(surface.get(), destRect, srcRectScaled, state.imageInterpolationQuality, state.alpha, Cairo::ShadowState(state), context);
    7980}
    8081
  • trunk/Source/WebKit/WebProcess/WebCoreSupport/gtk/WebDragClientGtk.cpp

    r227051 r227065  
    5555    auto graphicsContext = bitmap->createGraphicsContext();
    5656
    57     graphicsContext->platformContext()->drawSurfaceToContext(surface, IntRect(IntPoint(), imageSize), IntRect(IntPoint(), imageSize), Cairo::ShadowState(graphicsContext->state()), *graphicsContext);
     57    auto& state = graphicsContext->state();
     58    graphicsContext->platformContext()->drawSurfaceToContext(surface, IntRect(IntPoint(), imageSize), IntRect(IntPoint(), imageSize), state.imageInterpolationQuality, state.alpha, Cairo::ShadowState(state), *graphicsContext);
    5859    return bitmap;
    5960}
Note: See TracChangeset for help on using the changeset viewer.