Title: [226620] trunk/Source/WebCore
Revision
226620
Author
[email protected]
Date
2018-01-09 01:52:13 -0800 (Tue, 09 Jan 2018)

Log Message

[Cairo] Pass state values directly to Cairo operations
https://bugs.webkit.org/show_bug.cgi?id=181389

Reviewed by Carlos Garcia Campos.

Instead of passing reference to the GraphicsContextState object to
various Cairo operations, only pass the required state values. This
makes it explicit what state values are used in these operations, at the
expense of some long parameter lists, but this will be better addressed
by future refactoring of this code into more concise functions.

No new tests -- no change in functionality.

* platform/graphics/cairo/CairoOperations.cpp:
(WebCore::Cairo::drawGlyphsShadow):
(WebCore::Cairo::dashedLineCornerWidthForStrokeWidth):
(WebCore::Cairo::dashedLinePatternWidthForStrokeWidth):
(WebCore::Cairo::drawGlyphs):
(WebCore::Cairo::drawRect):
(WebCore::Cairo::drawLine):
(WebCore::Cairo::drawEllipse):
* platform/graphics/cairo/CairoOperations.h:
* platform/graphics/cairo/FontCairo.cpp:
(WebCore::FontCascade::drawGlyphs):
* platform/graphics/cairo/GraphicsContextCairo.cpp:
(WebCore::GraphicsContext::drawRect):
(WebCore::GraphicsContext::drawLine):
(WebCore::GraphicsContext::drawEllipse):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (226619 => 226620)


--- trunk/Source/WebCore/ChangeLog	2018-01-09 09:29:52 UTC (rev 226619)
+++ trunk/Source/WebCore/ChangeLog	2018-01-09 09:52:13 UTC (rev 226620)
@@ -1,3 +1,34 @@
+2018-01-09  Zan Dobersek  <[email protected]>
+
+        [Cairo] Pass state values directly to Cairo operations
+        https://bugs.webkit.org/show_bug.cgi?id=181389
+
+        Reviewed by Carlos Garcia Campos.
+
+        Instead of passing reference to the GraphicsContextState object to
+        various Cairo operations, only pass the required state values. This
+        makes it explicit what state values are used in these operations, at the
+        expense of some long parameter lists, but this will be better addressed
+        by future refactoring of this code into more concise functions.
+
+        No new tests -- no change in functionality.
+
+        * platform/graphics/cairo/CairoOperations.cpp:
+        (WebCore::Cairo::drawGlyphsShadow):
+        (WebCore::Cairo::dashedLineCornerWidthForStrokeWidth):
+        (WebCore::Cairo::dashedLinePatternWidthForStrokeWidth):
+        (WebCore::Cairo::drawGlyphs):
+        (WebCore::Cairo::drawRect):
+        (WebCore::Cairo::drawLine):
+        (WebCore::Cairo::drawEllipse):
+        * platform/graphics/cairo/CairoOperations.h:
+        * platform/graphics/cairo/FontCairo.cpp:
+        (WebCore::FontCascade::drawGlyphs):
+        * platform/graphics/cairo/GraphicsContextCairo.cpp:
+        (WebCore::GraphicsContext::drawRect):
+        (WebCore::GraphicsContext::drawLine):
+        (WebCore::GraphicsContext::drawEllipse):
+
 2018-01-09  Ryosuke Niwa  <[email protected]>
 
         Release assert in addResourceTiming when a cache resource is requested during style recalc

Modified: trunk/Source/WebCore/platform/graphics/cairo/CairoOperations.cpp (226619 => 226620)


--- trunk/Source/WebCore/platform/graphics/cairo/CairoOperations.cpp	2018-01-09 09:29:52 UTC (rev 226619)
+++ trunk/Source/WebCore/platform/graphics/cairo/CairoOperations.cpp	2018-01-09 09:52:13 UTC (rev 226620)
@@ -182,11 +182,11 @@
     }
 }
 
-static void drawGlyphsShadow(PlatformContextCairo& platformContext, const GraphicsContextState& state, const ShadowBlurUsage& shadowBlurUsage, const FloatPoint& point, cairo_scaled_font_t* scaledFont, double syntheticBoldOffset, const Vector<cairo_glyph_t>& glyphs, GraphicsContext& targetContext)
+static void drawGlyphsShadow(PlatformContextCairo& platformContext, const ShadowBlurUsage& shadowBlurUsage, TextDrawingModeFlags textDrawingMode, const FloatSize& shadowOffset, const Color& shadowColor, const FloatPoint& point, cairo_scaled_font_t* scaledFont, double syntheticBoldOffset, const Vector<cairo_glyph_t>& glyphs, GraphicsContext& targetContext)
 {
     ShadowBlur& shadow = platformContext.shadowBlur();
 
-    if (!(state.textDrawingMode & TextModeFill) || shadow.type() == ShadowBlur::NoShadow)
+    if (!(textDrawingMode & TextModeFill) || shadow.type() == ShadowBlur::NoShadow)
         return;
 
     if (!shadowBlurUsage.required(platformContext)) {
@@ -194,9 +194,8 @@
         cairo_t* context = platformContext.cr();
         cairo_save(context);
 
-        FloatSize shadowOffset(state.shadowOffset);
         cairo_translate(context, shadowOffset.width(), shadowOffset.height());
-        setSourceRGBAFromColor(context, state.shadowColor);
+        setSourceRGBAFromColor(context, shadowColor);
         drawGlyphsToContext(context, scaledFont, syntheticBoldOffset, glyphs);
 
         cairo_restore(context);
@@ -250,18 +249,16 @@
 
 // FIXME: Replace once GraphicsContext::dashedLineCornerWidthForStrokeWidth()
 // is refactored as a static public function.
-static float dashedLineCornerWidthForStrokeWidth(float strokeWidth, const GraphicsContextState& state)
+static float dashedLineCornerWidthForStrokeWidth(float strokeWidth, StrokeStyle strokeStyle, float strokeThickness)
 {
-    float thickness = state.strokeThickness;
-    return state.strokeStyle == DottedStroke ? thickness : std::min(2.0f * thickness, std::max(thickness, strokeWidth / 3.0f));
+    return strokeStyle == DottedStroke ? strokeThickness : std::min(2.0f * strokeThickness, std::max(strokeThickness, strokeWidth / 3.0f));
 }
 
 // FIXME: Replace once GraphicsContext::dashedLinePatternWidthForStrokeWidth()
 // is refactored as a static public function.
-static float dashedLinePatternWidthForStrokeWidth(float strokeWidth, const GraphicsContextState& state)
+static float dashedLinePatternWidthForStrokeWidth(float strokeWidth, StrokeStyle strokeStyle, float strokeThickness)
 {
-    float thickness = state.strokeThickness;
-    return state.strokeStyle == DottedStroke ? thickness : std::min(3.0f * thickness, std::max(thickness, strokeWidth / 3.0f));
+    return strokeStyle == DottedStroke ? strokeThickness : std::min(3.0f * strokeThickness, std::max(strokeThickness, strokeWidth / 3.0f));
 }
 
 // FIXME: Replace once GraphicsContext::dashedLinePatternOffsetForPatternAndStrokeWidth()
@@ -656,14 +653,14 @@
     cairo_restore(cr);
 }
 
-void drawGlyphs(PlatformContextCairo& platformContext, const GraphicsContextState& state, const FillSource& fillSource, const StrokeSource& strokeSource, const ShadowBlurUsage& shadowBlurUsage, const FloatPoint& point, cairo_scaled_font_t* scaledFont, double syntheticBoldOffset, const Vector<cairo_glyph_t>& glyphs, float xOffset, GraphicsContext& targetContext)
+void drawGlyphs(PlatformContextCairo& platformContext, const FillSource& fillSource, const StrokeSource& strokeSource, const ShadowBlurUsage& shadowBlurUsage, const FloatPoint& point, cairo_scaled_font_t* scaledFont, double syntheticBoldOffset, const Vector<cairo_glyph_t>& glyphs, float xOffset, TextDrawingModeFlags textDrawingMode, float strokeThickness, const FloatSize& shadowOffset, const Color& shadowColor, GraphicsContext& targetContext)
 {
-    drawGlyphsShadow(platformContext, state, shadowBlurUsage, point, scaledFont, syntheticBoldOffset, glyphs, targetContext);
+    drawGlyphsShadow(platformContext, shadowBlurUsage, textDrawingMode, shadowOffset, shadowColor, point, scaledFont, syntheticBoldOffset, glyphs, targetContext);
 
     cairo_t* cr = platformContext.cr();
     cairo_save(cr);
 
-    if (state.textDrawingMode & TextModeFill) {
+    if (textDrawingMode & TextModeFill) {
         platformContext.prepareForFilling(fillSource, PlatformContextCairo::AdjustPatternForGlobalAlpha);
         drawGlyphsToContext(cr, scaledFont, syntheticBoldOffset, glyphs);
     }
@@ -672,9 +669,9 @@
     // twice the size of the width of the text we will not ask cairo to stroke
     // the text as even one single stroke would cover the full wdth of the text.
     //  See https://bugs.webkit.org/show_bug.cgi?id=33759.
-    if (state.textDrawingMode & TextModeStroke && state.strokeThickness < 2 * xOffset) {
+    if (textDrawingMode & TextModeStroke && strokeThickness < 2 * xOffset) {
         platformContext.prepareForStroking(strokeSource, PlatformContextCairo::PreserveAlpha);
-        cairo_set_line_width(cr, state.strokeThickness);
+        cairo_set_line_width(cr, strokeThickness);
 
         // This may disturb the CTM, but we are going to call cairo_restore soon after.
         cairo_set_scaled_font(cr, scaledFont);
@@ -718,7 +715,7 @@
     drawPatternToCairoContext(platformContext.cr(), surface, size, tileRect, patternTransform, phase, toCairoOperator(compositeOperator, blendMode), destRect);
 }
 
-void drawRect(PlatformContextCairo& platformContext, const FloatRect& rect, float borderThickness, const GraphicsContextState& state)
+void drawRect(PlatformContextCairo& platformContext, const FloatRect& rect, float borderThickness, const Color& fillColor, StrokeStyle strokeStyle, const Color& strokeColor)
 {
     // FIXME: how should borderThickness be used?
     UNUSED_PARAM(borderThickness);
@@ -726,10 +723,10 @@
     cairo_t* cr = platformContext.cr();
     cairo_save(cr);
 
-    fillRectWithColor(cr, rect, state.fillColor);
+    fillRectWithColor(cr, rect, fillColor);
 
-    if (state.strokeStyle != NoStroke) {
-        setSourceRGBAFromColor(cr, state.strokeColor);
+    if (strokeStyle != NoStroke) {
+        setSourceRGBAFromColor(cr, strokeColor);
         FloatRect r(rect);
         r.inflate(-.5f);
         cairo_rectangle(cr, r.x(), r.y(), r.width(), r.height());
@@ -740,30 +737,30 @@
     cairo_restore(cr);
 }
 
-void drawLine(PlatformContextCairo& platformContext, const FloatPoint& point1, const FloatPoint& point2, const GraphicsContextState& state)
+void drawLine(PlatformContextCairo& platformContext, const FloatPoint& point1, const FloatPoint& point2, StrokeStyle strokeStyle, const Color& strokeColor, float strokeThickness, bool shouldAntialias)
 {
-    bool isVerticalLine = (point1.x() + state.strokeThickness == point2.x());
+    bool isVerticalLine = (point1.x() + strokeThickness == point2.x());
     float strokeWidth = isVerticalLine ? point2.y() - point1.y() : point2.x() - point1.x();
-    if (!state.strokeThickness || !strokeWidth)
+    if (!strokeThickness || !strokeWidth)
         return;
 
     cairo_t* cairoContext = platformContext.cr();
     float cornerWidth = 0;
-    bool drawsDashedLine = state.strokeStyle == DottedStroke || state.strokeStyle == DashedStroke;
+    bool drawsDashedLine = strokeStyle == DottedStroke || strokeStyle == DashedStroke;
 
     if (drawsDashedLine) {
         cairo_save(cairoContext);
         // Figure out end points to ensure we always paint corners.
-        cornerWidth = dashedLineCornerWidthForStrokeWidth(strokeWidth, state);
+        cornerWidth = dashedLineCornerWidthForStrokeWidth(strokeWidth, strokeStyle, strokeThickness);
         if (isVerticalLine) {
-            fillRectWithColor(cairoContext, FloatRect(point1.x(), point1.y(), state.strokeThickness, cornerWidth), state.strokeColor);
-            fillRectWithColor(cairoContext, FloatRect(point1.x(), point2.y() - cornerWidth, state.strokeThickness, cornerWidth), state.strokeColor);
+            fillRectWithColor(cairoContext, FloatRect(point1.x(), point1.y(), strokeThickness, cornerWidth), strokeColor);
+            fillRectWithColor(cairoContext, FloatRect(point1.x(), point2.y() - cornerWidth, strokeThickness, cornerWidth), strokeColor);
         } else {
-            fillRectWithColor(cairoContext, FloatRect(point1.x(), point1.y(), cornerWidth, state.strokeThickness), state.strokeColor);
-            fillRectWithColor(cairoContext, FloatRect(point2.x() - cornerWidth, point1.y(), cornerWidth, state.strokeThickness), state.strokeColor);
+            fillRectWithColor(cairoContext, FloatRect(point1.x(), point1.y(), cornerWidth, strokeThickness), strokeColor);
+            fillRectWithColor(cairoContext, FloatRect(point2.x() - cornerWidth, point1.y(), cornerWidth, strokeThickness), strokeColor);
         }
         strokeWidth -= 2 * cornerWidth;
-        float patternWidth = dashedLinePatternWidthForStrokeWidth(strokeWidth, state);
+        float patternWidth = dashedLinePatternWidthForStrokeWidth(strokeWidth, strokeStyle, strokeThickness);
         // Check if corner drawing sufficiently covers the line.
         if (strokeWidth <= patternWidth + 1) {
             cairo_restore(cairoContext);
@@ -774,8 +771,8 @@
         const double dashedLine[2] = { static_cast<double>(patternWidth), static_cast<double>(patternWidth) };
         cairo_set_dash(cairoContext, dashedLine, 2, patternOffset);
     } else {
-        setSourceRGBAFromColor(cairoContext, state.strokeColor);
-        if (state.strokeThickness < 1)
+        setSourceRGBAFromColor(cairoContext, strokeColor);
+        if (strokeThickness < 1)
             cairo_set_line_width(cairoContext, 1);
     }
 
@@ -783,7 +780,7 @@
     auto p1 = centeredPoints[0];
     auto p2 = centeredPoints[1];
 
-    if (state.shouldAntialias)
+    if (shouldAntialias)
         cairo_set_antialias(cairoContext, CAIRO_ANTIALIAS_NONE);
 
     cairo_new_path(cairoContext);
@@ -793,7 +790,7 @@
     if (drawsDashedLine)
         cairo_restore(cairoContext);
 
-    if (state.shouldAntialias)
+    if (shouldAntialias)
         cairo_set_antialias(cairoContext, CAIRO_ANTIALIAS_DEFAULT);
 }
 
@@ -841,7 +838,7 @@
     cairo_restore(cr);
 }
 
-void drawEllipse(PlatformContextCairo& platformContext, const FloatRect& rect, const GraphicsContextState& state)
+void drawEllipse(PlatformContextCairo& platformContext, const FloatRect& rect, const Color& fillColor, StrokeStyle strokeStyle, const Color& strokeColor, float strokeThickness)
 {
     cairo_t* cr = platformContext.cr();
 
@@ -853,14 +850,14 @@
     cairo_arc(cr, 0., 0., 1., 0., 2 * piFloat);
     cairo_restore(cr);
 
-    if (state.fillColor.isVisible()) {
-        setSourceRGBAFromColor(cr, state.fillColor);
+    if (fillColor.isVisible()) {
+        setSourceRGBAFromColor(cr, fillColor);
         cairo_fill_preserve(cr);
     }
 
-    if (state.strokeStyle != NoStroke) {
-        setSourceRGBAFromColor(cr, state.strokeColor);
-        cairo_set_line_width(cr, state.strokeThickness);
+    if (strokeStyle != NoStroke) {
+        setSourceRGBAFromColor(cr, strokeColor);
+        cairo_set_line_width(cr, strokeThickness);
         cairo_stroke(cr);
     } else
         cairo_new_path(cr);

Modified: trunk/Source/WebCore/platform/graphics/cairo/CairoOperations.h (226619 => 226620)


--- trunk/Source/WebCore/platform/graphics/cairo/CairoOperations.h	2018-01-09 09:29:52 UTC (rev 226619)
+++ trunk/Source/WebCore/platform/graphics/cairo/CairoOperations.h	2018-01-09 09:52:13 UTC (rev 226620)
@@ -134,16 +134,16 @@
 void strokePath(PlatformContextCairo&, const Path&, const StrokeSource&, GraphicsContext&);
 void clearRect(PlatformContextCairo&, const FloatRect&);
 
-void drawGlyphs(PlatformContextCairo&, const GraphicsContextState&, const FillSource&, const StrokeSource&, const ShadowBlurUsage&, const FloatPoint&, cairo_scaled_font_t*, double, const Vector<cairo_glyph_t>&, float, GraphicsContext&);
+void drawGlyphs(PlatformContextCairo&, const FillSource&, const StrokeSource&, const ShadowBlurUsage&, const FloatPoint&, cairo_scaled_font_t*, double, const Vector<cairo_glyph_t>&, float, TextDrawingModeFlags, float, const FloatSize&, const Color&, GraphicsContext&);
 
 void drawNativeImage(PlatformContextCairo&, cairo_surface_t*, const FloatRect&, const FloatRect&, CompositeOperator, BlendMode, ImageOrientation, GraphicsContext&);
 void drawPattern(PlatformContextCairo&, cairo_surface_t*, const IntSize&, const FloatRect&, const FloatRect&, const AffineTransform&, const FloatPoint&, CompositeOperator, BlendMode);
 
-void drawRect(PlatformContextCairo&, const FloatRect&, float, const GraphicsContextState&);
-void drawLine(PlatformContextCairo&, const FloatPoint&, const FloatPoint&, const GraphicsContextState&);
+void drawRect(PlatformContextCairo&, const FloatRect&, float, const Color&, StrokeStyle, const Color&);
+void drawLine(PlatformContextCairo&, const FloatPoint&, const FloatPoint&, StrokeStyle, const Color&, float, bool);
 void drawLinesForText(PlatformContextCairo&, const FloatPoint&, const DashArray&, bool, bool, const Color&, float);
 void drawLineForDocumentMarker(PlatformContextCairo&, const FloatPoint&, float, GraphicsContext::DocumentMarkerLineStyle);
-void drawEllipse(PlatformContextCairo&, const FloatRect&, const GraphicsContextState&);
+void drawEllipse(PlatformContextCairo&, const FloatRect&, const Color&, StrokeStyle, const Color&, float);
 
 void drawFocusRing(PlatformContextCairo&, const Path&, float, const Color&);
 void drawFocusRing(PlatformContextCairo&, const Vector<FloatRect>&, float, const Color&);

Modified: trunk/Source/WebCore/platform/graphics/cairo/FontCairo.cpp (226619 => 226620)


--- trunk/Source/WebCore/platform/graphics/cairo/FontCairo.cpp	2018-01-09 09:29:52 UTC (rev 226619)
+++ trunk/Source/WebCore/platform/graphics/cairo/FontCairo.cpp	2018-01-09 09:52:13 UTC (rev 226620)
@@ -72,7 +72,9 @@
 
     ASSERT(context.hasPlatformContext());
     auto& state = context.state();
-    Cairo::drawGlyphs(*context.platformContext(), state, Cairo::FillSource(state), Cairo::StrokeSource(state), Cairo::ShadowBlurUsage(state), point, scaledFont, syntheticBoldOffset, glyphs, xOffset, context);
+    Cairo::drawGlyphs(*context.platformContext(), Cairo::FillSource(state), Cairo::StrokeSource(state),
+        Cairo::ShadowBlurUsage(state), point, scaledFont, syntheticBoldOffset, glyphs, xOffset,
+        state.textDrawingMode, state.strokeThickness, state.shadowOffset, state.shadowColor, context);
 }
 
 #if ENABLE(CSS3_TEXT_DECORATION_SKIP_INK)

Modified: trunk/Source/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp (226619 => 226620)


--- trunk/Source/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp	2018-01-09 09:29:52 UTC (rev 226619)
+++ trunk/Source/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp	2018-01-09 09:52:13 UTC (rev 226620)
@@ -127,7 +127,8 @@
 
     ASSERT(!rect.isEmpty());
     ASSERT(hasPlatformContext());
-    Cairo::drawRect(*platformContext(), rect, borderThickness, state());
+    auto& state = this->state();
+    Cairo::drawRect(*platformContext(), rect, borderThickness, state.fillColor, state.strokeStyle, state.strokeColor);
 }
 
 void GraphicsContext::drawNativeImage(const NativeImagePtr& image, const FloatSize& imageSize, const FloatRect& destRect, const FloatRect& srcRect, CompositeOperator compositeOperator, BlendMode blendMode, ImageOrientation orientation)
@@ -159,7 +160,8 @@
     }
 
     ASSERT(hasPlatformContext());
-    Cairo::drawLine(*platformContext(), point1, point2, state());
+    auto& state = this->state();
+    Cairo::drawLine(*platformContext(), point1, point2, state.strokeStyle, state.strokeColor, state.strokeThickness, state.shouldAntialias);
 }
 
 // This method is only used to draw the little circles used in lists.
@@ -174,7 +176,8 @@
     }
 
     ASSERT(hasPlatformContext());
-    Cairo::drawEllipse(*platformContext(), rect, state());
+    auto& state = this->state();
+    Cairo::drawEllipse(*platformContext(), rect, state.fillColor, state.strokeStyle, state.strokeColor, state.strokeThickness);
 }
 
 void GraphicsContext::fillPath(const Path& path)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to