Title: [224753] trunk/Source/WebCore
Revision
224753
Author
[email protected]
Date
2017-11-13 05:41:41 -0800 (Mon, 13 Nov 2017)

Log Message

[Cairo] Move state change operations from GraphicsContextCairo to CairoOperations
https://bugs.webkit.org/show_bug.cgi?id=179610

Reviewed by Carlos Garcia Campos.

Move operations that perform Cairo state changes to the CairoOperations
file. This enforces only using the PlatformContextCairo object to
achieve the state change, leveraging the cairo_t and ShadowBlur objects
that are owned by PlatformContextCairo.

Along with state modification operations, various state query operations
are also placed under the Cairo::State namespace, again limited to the
PlatformContextCairo object.

No new tests -- no change in behavior.

* platform/graphics/cairo/CairoOperations.cpp:
(WebCore::Cairo::State::setStrokeThickness):
(WebCore::Cairo::State::setGlobalAlpha):
(WebCore::Cairo::State::setCompositeOperation):
(WebCore::Cairo::State::setShouldAntialias):
(WebCore::Cairo::State::setImageInterpolationQuality):
(WebCore::Cairo::State::setCTM):
(WebCore::Cairo::State::getCTM):
(WebCore::Cairo::State::setShadowValues):
(WebCore::Cairo::State::clearShadow):
(WebCore::Cairo::State::getClipBounds):
(WebCore::Cairo::State::roundToDevicePixels):
(WebCore::Cairo::State::isAcceleratedContext):
* platform/graphics/cairo/CairoOperations.h:
* platform/graphics/cairo/GraphicsContextCairo.cpp:
(WebCore::GraphicsContext::getCTM const):
(WebCore::GraphicsContext::restorePlatformState):
(WebCore::GraphicsContext::clipBounds const):
(WebCore::GraphicsContext::roundToDevicePixels):
(WebCore::GraphicsContext::setPlatformStrokeThickness):
(WebCore::GraphicsContext::setCTM):
(WebCore::GraphicsContext::setPlatformShadow):
(WebCore::GraphicsContext::clearPlatformShadow):
(WebCore::GraphicsContext::setPlatformAlpha):
(WebCore::GraphicsContext::setPlatformCompositeOperation):
(WebCore::GraphicsContext::setPlatformShouldAntialias):
(WebCore::GraphicsContext::setPlatformImageInterpolationQuality):
(WebCore::GraphicsContext::isAcceleratedContext const):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (224752 => 224753)


--- trunk/Source/WebCore/ChangeLog	2017-11-13 13:33:07 UTC (rev 224752)
+++ trunk/Source/WebCore/ChangeLog	2017-11-13 13:41:41 UTC (rev 224753)
@@ -1,5 +1,52 @@
 2017-11-13  Zan Dobersek  <[email protected]>
 
+        [Cairo] Move state change operations from GraphicsContextCairo to CairoOperations
+        https://bugs.webkit.org/show_bug.cgi?id=179610
+
+        Reviewed by Carlos Garcia Campos.
+
+        Move operations that perform Cairo state changes to the CairoOperations
+        file. This enforces only using the PlatformContextCairo object to
+        achieve the state change, leveraging the cairo_t and ShadowBlur objects
+        that are owned by PlatformContextCairo.
+
+        Along with state modification operations, various state query operations
+        are also placed under the Cairo::State namespace, again limited to the
+        PlatformContextCairo object.
+
+        No new tests -- no change in behavior.
+
+        * platform/graphics/cairo/CairoOperations.cpp:
+        (WebCore::Cairo::State::setStrokeThickness):
+        (WebCore::Cairo::State::setGlobalAlpha):
+        (WebCore::Cairo::State::setCompositeOperation):
+        (WebCore::Cairo::State::setShouldAntialias):
+        (WebCore::Cairo::State::setImageInterpolationQuality):
+        (WebCore::Cairo::State::setCTM):
+        (WebCore::Cairo::State::getCTM):
+        (WebCore::Cairo::State::setShadowValues):
+        (WebCore::Cairo::State::clearShadow):
+        (WebCore::Cairo::State::getClipBounds):
+        (WebCore::Cairo::State::roundToDevicePixels):
+        (WebCore::Cairo::State::isAcceleratedContext):
+        * platform/graphics/cairo/CairoOperations.h:
+        * platform/graphics/cairo/GraphicsContextCairo.cpp:
+        (WebCore::GraphicsContext::getCTM const):
+        (WebCore::GraphicsContext::restorePlatformState):
+        (WebCore::GraphicsContext::clipBounds const):
+        (WebCore::GraphicsContext::roundToDevicePixels):
+        (WebCore::GraphicsContext::setPlatformStrokeThickness):
+        (WebCore::GraphicsContext::setCTM):
+        (WebCore::GraphicsContext::setPlatformShadow):
+        (WebCore::GraphicsContext::clearPlatformShadow):
+        (WebCore::GraphicsContext::setPlatformAlpha):
+        (WebCore::GraphicsContext::setPlatformCompositeOperation):
+        (WebCore::GraphicsContext::setPlatformShouldAntialias):
+        (WebCore::GraphicsContext::setPlatformImageInterpolationQuality):
+        (WebCore::GraphicsContext::isAcceleratedContext const):
+
+2017-11-13  Zan Dobersek  <[email protected]>
+
         [Cairo] Move glyph drawing operations from FontCairo to CairoOperations
         https://bugs.webkit.org/show_bug.cgi?id=179609
 

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


--- trunk/Source/WebCore/platform/graphics/cairo/CairoOperations.cpp	2017-11-13 13:33:07 UTC (rev 224752)
+++ trunk/Source/WebCore/platform/graphics/cairo/CairoOperations.cpp	2017-11-13 13:41:41 UTC (rev 224753)
@@ -35,6 +35,7 @@
 
 #if USE(CAIRO)
 
+#include "FloatConversion.h"
 #include "FloatRect.h"
 #include "GraphicsContext.h"
 #include "Image.h"
@@ -211,6 +212,11 @@
 
 namespace State {
 
+void setStrokeThickness(PlatformContextCairo& platformContext, float strokeThickness)
+{
+    cairo_set_line_width(platformContext.cr(), strokeThickness);
+}
+
 void setStrokeStyle(PlatformContextCairo& platformContext, StrokeStyle strokeStyle)
 {
     static const double dashPattern[] = { 5.0, 5.0 };
@@ -237,6 +243,110 @@
     }
 }
 
+void setGlobalAlpha(PlatformContextCairo& platformContext, float alpha)
+{
+    platformContext.setGlobalAlpha(alpha);
+}
+
+void setCompositeOperation(PlatformContextCairo& platformContext, CompositeOperator compositeOperation, BlendMode blendMode)
+{
+    cairo_set_operator(platformContext.cr(), toCairoOperator(compositeOperation, blendMode));
+}
+
+void setShouldAntialias(PlatformContextCairo& platformContext, bool enable)
+{
+    // When true, use the default Cairo backend antialias mode (usually this
+    // enables standard 'grayscale' antialiasing); false to explicitly disable
+    // antialiasing.
+    cairo_set_antialias(platformContext.cr(), enable ? CAIRO_ANTIALIAS_DEFAULT : CAIRO_ANTIALIAS_NONE);
+}
+
+void setImageInterpolationQuality(PlatformContextCairo& platformContext, InterpolationQuality quality)
+{
+    platformContext.setImageInterpolationQuality(quality);
+}
+
+void setCTM(PlatformContextCairo& platformContext, const AffineTransform& transform)
+{
+    const cairo_matrix_t matrix = toCairoMatrix(transform);
+    cairo_set_matrix(platformContext.cr(), &matrix);
+}
+
+AffineTransform getCTM(PlatformContextCairo& platformContext)
+{
+    cairo_matrix_t m;
+    cairo_get_matrix(platformContext.cr(), &m);
+    return AffineTransform(m.xx, m.yx, m.xy, m.yy, m.x0, m.y0);
+}
+
+void setShadowValues(PlatformContextCairo& platformContext, const FloatSize& radius, const FloatSize& offset, const Color& color, bool ignoreTransforms)
+{
+    FloatSize adjustedOffset = offset;
+    if (ignoreTransforms) {
+        // Meaning that this graphics context is associated with a CanvasRenderingContext
+        // We flip the height since CG and HTML5 Canvas have opposite Y axis
+        adjustedOffset.setHeight(-offset.height());
+    }
+
+    // Cairo doesn't support shadows natively, they are drawn manually in the draw* functions using ShadowBlur.
+    platformContext.shadowBlur().setShadowValues(radius, adjustedOffset, color, ignoreTransforms);
+}
+
+void clearShadow(PlatformContextCairo& platformContext)
+{
+    platformContext.shadowBlur().clear();
+}
+
+IntRect getClipBounds(PlatformContextCairo& platformContext)
+{
+    double x1, x2, y1, y2;
+    cairo_clip_extents(platformContext.cr(), &x1, &y1, &x2, &y2);
+    return enclosingIntRect(FloatRect(x1, y1, x2 - x1, y2 - y1));
+}
+
+FloatRect roundToDevicePixels(PlatformContextCairo& platformContext, const FloatRect& rect)
+{
+    FloatRect result;
+    double x = rect.x();
+    double y = rect.y();
+
+    cairo_t* cr = platformContext.cr();
+    cairo_user_to_device(cr, &x, &y);
+    x = round(x);
+    y = round(y);
+    cairo_device_to_user(cr, &x, &y);
+    result.setX(narrowPrecisionToFloat(x));
+    result.setY(narrowPrecisionToFloat(y));
+
+    // We must ensure width and height are at least 1 (or -1) when
+    // we're given float values in the range between 0 and 1 (or -1 and 0).
+    double width = rect.width();
+    double height = rect.height();
+    cairo_user_to_device_distance(cr, &width, &height);
+    if (width > -1 && width < 0)
+        width = -1;
+    else if (width > 0 && width < 1)
+        width = 1;
+    else
+        width = round(width);
+    if (height > -1 && height < 0)
+        height = -1;
+    else if (height > 0 && height < 1)
+        height = 1;
+    else
+        height = round(height);
+    cairo_device_to_user_distance(cr, &width, &height);
+    result.setWidth(narrowPrecisionToFloat(width));
+    result.setHeight(narrowPrecisionToFloat(height));
+
+    return result;
+}
+
+bool isAcceleratedContext(PlatformContextCairo& platformContext)
+{
+    return cairo_surface_get_type(cairo_get_target(platformContext.cr())) == CAIRO_SURFACE_TYPE_GL;
+}
+
 } // namespace State
 
 void setLineCap(PlatformContextCairo& platformContext, LineCap lineCap)

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


--- trunk/Source/WebCore/platform/graphics/cairo/CairoOperations.h	2017-11-13 13:33:07 UTC (rev 224752)
+++ trunk/Source/WebCore/platform/graphics/cairo/CairoOperations.h	2017-11-13 13:41:41 UTC (rev 224753)
@@ -56,9 +56,28 @@
 namespace Cairo {
 
 namespace State {
+
+void setStrokeThickness(PlatformContextCairo&, float);
 void setStrokeStyle(PlatformContextCairo&, StrokeStyle);
-}
 
+void setGlobalAlpha(PlatformContextCairo&, float);
+void setCompositeOperation(PlatformContextCairo&, CompositeOperator, BlendMode);
+void setShouldAntialias(PlatformContextCairo&, bool);
+void setImageInterpolationQuality(PlatformContextCairo&, InterpolationQuality);
+
+void setCTM(PlatformContextCairo&, const AffineTransform&);
+AffineTransform getCTM(PlatformContextCairo&);
+
+void setShadowValues(PlatformContextCairo&, const FloatSize&, const FloatSize&, const Color&, bool);
+void clearShadow(PlatformContextCairo&);
+
+IntRect getClipBounds(PlatformContextCairo&);
+FloatRect roundToDevicePixels(PlatformContextCairo&, const FloatRect&);
+
+bool isAcceleratedContext(PlatformContextCairo&);
+
+} // namespace State
+
 void setLineCap(PlatformContextCairo&, LineCap);
 void setLineDash(PlatformContextCairo&, const DashArray&, float);
 void setLineJoin(PlatformContextCairo&, LineJoin);

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


--- trunk/Source/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp	2017-11-13 13:33:07 UTC (rev 224752)
+++ trunk/Source/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp	2017-11-13 13:41:41 UTC (rev 224753)
@@ -200,10 +200,8 @@
         return AffineTransform();
     }
 
-    cairo_t* cr = platformContext()->cr();
-    cairo_matrix_t m;
-    cairo_get_matrix(cr, &m);
-    return AffineTransform(m.xx, m.yx, m.xy, m.yy, m.x0, m.y0);
+    ASSERT(hasPlatformContext());
+    return Cairo::State::getCTM(*platformContext());
 }
 
 PlatformContextCairo* GraphicsContext::platformContext() const
@@ -224,10 +222,8 @@
     Cairo::restore(*platformContext());
     m_data->restore();
 
-    platformContext()->shadowBlur().setShadowValues(FloatSize(m_state.shadowBlur, m_state.shadowBlur),
-                                                    m_state.shadowOffset,
-                                                    m_state.shadowColor,
-                                                    m_state.shadowsIgnoreTransforms);
+    Cairo::State::setShadowValues(*platformContext(), FloatSize { m_state.shadowBlur, m_state.shadowBlur },
+        m_state.shadowOffset, m_state.shadowColor, m_state.shadowsIgnoreTransforms);
 }
 
 // Draws a filled rectangle with a stroked border.
@@ -508,9 +504,8 @@
         return IntRect(-2048, -2048, 4096, 4096); // FIXME: display lists.
     }
 
-    double x1, x2, y1, y2;
-    cairo_clip_extents(platformContext()->cr(), &x1, &y1, &x2, &y2);
-    return enclosingIntRect(FloatRect(x1, y1, x2 - x1, y2 - y1));
+    ASSERT(hasPlatformContext());
+    return Cairo::State::getClipBounds(*platformContext());
 }
 
 void GraphicsContext::drawFocusRing(const Path& path, float width, float offset, const Color& color)
@@ -617,49 +612,17 @@
     cairo_restore(cr);
 }
 
-FloatRect GraphicsContext::roundToDevicePixels(const FloatRect& frect, RoundingMode)
+FloatRect GraphicsContext::roundToDevicePixels(const FloatRect& rect, RoundingMode)
 {
     if (paintingDisabled())
-        return frect;
+        return rect;
 
     if (m_impl) {
         WTFLogAlways("GraphicsContext::roundToDevicePixels() is not yet compatible with recording contexts.");
-        return frect;
+        return rect;
     }
 
-    FloatRect result;
-    double x = frect.x();
-    double y = frect.y();
-    cairo_t* cr = platformContext()->cr();
-    cairo_user_to_device(cr, &x, &y);
-    x = round(x);
-    y = round(y);
-    cairo_device_to_user(cr, &x, &y);
-    result.setX(narrowPrecisionToFloat(x));
-    result.setY(narrowPrecisionToFloat(y));
-
-    // We must ensure width and height are at least 1 (or -1) when
-    // we're given float values in the range between 0 and 1 (or -1 and 0).
-    double width = frect.width();
-    double height = frect.height();
-    cairo_user_to_device_distance(cr, &width, &height);
-    if (width > -1 && width < 0)
-        width = -1;
-    else if (width > 0 && width < 1)
-        width = 1;
-    else
-        width = round(width);
-    if (height > -1 && height < 0)
-        height = -1;
-    else if (height > 0 && height < 1)
-        height = 1;
-    else
-        height = round(height);
-    cairo_device_to_user_distance(cr, &width, &height);
-    result.setWidth(narrowPrecisionToFloat(width));
-    result.setHeight(narrowPrecisionToFloat(height));
-
-    return result;
+    return Cairo::State::roundToDevicePixels(*platformContext(), rect);
 }
 
 void GraphicsContext::translate(float x, float y)
@@ -695,8 +658,7 @@
         return;
 
     ASSERT(hasPlatformContext());
-
-    cairo_set_line_width(platformContext()->cr(), strokeThickness);
+    Cairo::State::setStrokeThickness(*platformContext(), strokeThickness);
 }
 
 void GraphicsContext::setPlatformStrokeStyle(StrokeStyle strokeStyle)
@@ -738,28 +700,19 @@
         return;
     }
 
-    cairo_t* cr = platformContext()->cr();
-    const cairo_matrix_t matrix = toCairoMatrix(transform);
-    cairo_set_matrix(cr, &matrix);
+    ASSERT(hasPlatformContext());
+    Cairo::State::setCTM(*platformContext(), transform);
     m_data->setCTM(transform);
 }
 
-void GraphicsContext::setPlatformShadow(FloatSize const& size, float, Color const&)
+void GraphicsContext::setPlatformShadow(const FloatSize& offset, float blur, const Color& color)
 {
     if (paintingDisabled())
         return;
 
-    if (m_state.shadowsIgnoreTransforms) {
-        // Meaning that this graphics context is associated with a CanvasRenderingContext
-        // We flip the height since CG and HTML5 Canvas have opposite Y axis
-        m_state.shadowOffset = FloatSize(size.width(), -size.height());
-    }
-
-    // Cairo doesn't support shadows natively, they are drawn manually in the draw* functions using ShadowBlur.
-    platformContext()->shadowBlur().setShadowValues(FloatSize(m_state.shadowBlur, m_state.shadowBlur),
-                                                    m_state.shadowOffset,
-                                                    m_state.shadowColor,
-                                                    m_state.shadowsIgnoreTransforms);
+    ASSERT(hasPlatformContext());
+    Cairo::State::setShadowValues(*platformContext(), FloatSize { blur, blur },
+        offset, color, m_state.shadowsIgnoreTransforms);
 }
 
 void GraphicsContext::clearPlatformShadow()
@@ -767,7 +720,8 @@
     if (paintingDisabled())
         return;
 
-    platformContext()->shadowBlur().clear();
+    ASSERT(hasPlatformContext());
+    Cairo::State::clearShadow(*platformContext());
 }
 
 void GraphicsContext::beginPlatformTransparencyLayer(float opacity)
@@ -880,15 +834,16 @@
 
 void GraphicsContext::setPlatformAlpha(float alpha)
 {
-    platformContext()->setGlobalAlpha(alpha);
+    Cairo::State::setGlobalAlpha(*platformContext(), alpha);
 }
 
-void GraphicsContext::setPlatformCompositeOperation(CompositeOperator op, BlendMode blendOp)
+void GraphicsContext::setPlatformCompositeOperation(CompositeOperator compositeOperator, BlendMode blendMode)
 {
     if (paintingDisabled())
         return;
 
-    cairo_set_operator(platformContext()->cr(), toCairoOperator(op, blendOp));
+    ASSERT(hasPlatformContext());
+    Cairo::State::setCompositeOperation(*platformContext(), compositeOperator, blendMode);
 }
 
 void GraphicsContext::canvasClip(const Path& path, WindRule windRule)
@@ -1001,18 +956,13 @@
         return;
 
     ASSERT(hasPlatformContext());
-
-    // When true, use the default Cairo backend antialias mode (usually this
-    // enables standard 'grayscale' antialiasing); false to explicitly disable
-    // antialiasing.
-    cairo_set_antialias(platformContext()->cr(), enable ? CAIRO_ANTIALIAS_DEFAULT : CAIRO_ANTIALIAS_NONE);
+    Cairo::State::setShouldAntialias(*platformContext(), enable);
 }
 
 void GraphicsContext::setPlatformImageInterpolationQuality(InterpolationQuality quality)
 {
     ASSERT(hasPlatformContext());
-
-    platformContext()->setImageInterpolationQuality(quality);
+    Cairo::State::setImageInterpolationQuality(*platformContext(), quality);
 }
 
 bool GraphicsContext::isAcceleratedContext() const
@@ -1020,7 +970,7 @@
     if (!hasPlatformContext())
         return false;
 
-    return cairo_surface_get_type(cairo_get_target(platformContext()->cr())) == CAIRO_SURFACE_TYPE_GL;
+    return Cairo::State::isAcceleratedContext(*platformContext());
 }
 
 } // namespace WebCore
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to