Title: [224669] trunk/Source/WebCore
Revision
224669
Author
zandober...@gmail.com
Date
2017-11-10 00:18:02 -0800 (Fri, 10 Nov 2017)

Log Message

[Cairo] Start grouping Cairo GraphicsContext operations behind a separate interface
https://bugs.webkit.org/show_bug.cgi?id=179467

Reviewed by Carlos Garcia Campos.

Start moving the Cairo operations in GraphicsContext into a separate
translation unit, CairoOperations.cpp. This will ease leveraging these
operations from a pre-recorded list of GraphicsContext commands, or
from a Cairo-specific GraphicsContextImpl, without undermining the
current GraphicsContext implementation that we'll want to maintain
in a working state until necessary.

We start with the clipping operations. Each operation is encapsulated
in a static function inside the WebCore::Cairo namespace that expects
PlatformContextCairo reference as the first argument, which makes sense
since we have to utilize the cairo_t state object that's kept there.
Other parameters are passed as well, as required for some specific
operation.

In the Cairo implementation of GraphicsContext, the affected methods
are changed to assert presence of the platform context (i.e. this is a
GraphicsContext that operates on a valid cairo_t object, and is not
using an m_impl object or is in non-painting mode) before the
PlatformContextCairo object is dereferenced and passed along with
other arguments to the Cairo::clip*() function.

No new tests -- no change in behavior.

* platform/SourcesCairo.txt:
* platform/graphics/cairo/CairoOperations.cpp: Added.
(WebCore::Cairo::clip):
(WebCore::Cairo::clipOut):
(WebCore::Cairo::clipPath):
(WebCore::Cairo::clipToImageBuffer):
* platform/graphics/cairo/CairoOperations.h: Added.
* platform/graphics/cairo/GraphicsContextCairo.cpp:
(WebCore::GraphicsContext::clip):
(WebCore::GraphicsContext::clipPath):
(WebCore::GraphicsContext::clipToImageBuffer):
(WebCore::GraphicsContext::clipOut):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (224668 => 224669)


--- trunk/Source/WebCore/ChangeLog	2017-11-10 07:27:30 UTC (rev 224668)
+++ trunk/Source/WebCore/ChangeLog	2017-11-10 08:18:02 UTC (rev 224669)
@@ -1,3 +1,46 @@
+2017-11-10  Zan Dobersek  <zdober...@igalia.com>
+
+        [Cairo] Start grouping Cairo GraphicsContext operations behind a separate interface
+        https://bugs.webkit.org/show_bug.cgi?id=179467
+
+        Reviewed by Carlos Garcia Campos.
+
+        Start moving the Cairo operations in GraphicsContext into a separate
+        translation unit, CairoOperations.cpp. This will ease leveraging these
+        operations from a pre-recorded list of GraphicsContext commands, or
+        from a Cairo-specific GraphicsContextImpl, without undermining the
+        current GraphicsContext implementation that we'll want to maintain
+        in a working state until necessary.
+
+        We start with the clipping operations. Each operation is encapsulated
+        in a static function inside the WebCore::Cairo namespace that expects
+        PlatformContextCairo reference as the first argument, which makes sense
+        since we have to utilize the cairo_t state object that's kept there.
+        Other parameters are passed as well, as required for some specific
+        operation.
+
+        In the Cairo implementation of GraphicsContext, the affected methods
+        are changed to assert presence of the platform context (i.e. this is a
+        GraphicsContext that operates on a valid cairo_t object, and is not
+        using an m_impl object or is in non-painting mode) before the
+        PlatformContextCairo object is dereferenced and passed along with
+        other arguments to the Cairo::clip*() function.
+
+        No new tests -- no change in behavior.
+
+        * platform/SourcesCairo.txt:
+        * platform/graphics/cairo/CairoOperations.cpp: Added.
+        (WebCore::Cairo::clip):
+        (WebCore::Cairo::clipOut):
+        (WebCore::Cairo::clipPath):
+        (WebCore::Cairo::clipToImageBuffer):
+        * platform/graphics/cairo/CairoOperations.h: Added.
+        * platform/graphics/cairo/GraphicsContextCairo.cpp:
+        (WebCore::GraphicsContext::clip):
+        (WebCore::GraphicsContext::clipPath):
+        (WebCore::GraphicsContext::clipToImageBuffer):
+        (WebCore::GraphicsContext::clipOut):
+
 2017-11-09  Chris Dumez  <cdu...@apple.com>
 
         Unreviewed, rolling out r224661.

Modified: trunk/Source/WebCore/platform/SourcesCairo.txt (224668 => 224669)


--- trunk/Source/WebCore/platform/SourcesCairo.txt	2017-11-10 07:27:30 UTC (rev 224668)
+++ trunk/Source/WebCore/platform/SourcesCairo.txt	2017-11-10 08:18:02 UTC (rev 224669)
@@ -23,6 +23,7 @@
 
 platform/graphics/cairo/BackingStoreBackendCairoImpl.cpp
 platform/graphics/cairo/CairoUtilities.cpp @no-unify
+platform/graphics/cairo/CairoOperations.cpp
 platform/graphics/cairo/FloatRectCairo.cpp
 platform/graphics/cairo/FontCairo.cpp
 platform/graphics/cairo/GradientCairo.cpp

Added: trunk/Source/WebCore/platform/graphics/cairo/CairoOperations.cpp (0 => 224669)


--- trunk/Source/WebCore/platform/graphics/cairo/CairoOperations.cpp	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/cairo/CairoOperations.cpp	2017-11-10 08:18:02 UTC (rev 224669)
@@ -0,0 +1,116 @@
+/*
+ * Copyright (C) 2006 Apple Inc.  All rights reserved.
+ * Copyright (C) 2007 Alp Toker <a...@atoker.com>
+ * Copyright (C) 2008, 2009 Dirk Schulze <k...@webkit.org>
+ * Copyright (C) 2008 Nuanti Ltd.
+ * Copyright (C) 2009 Brent Fulgham <bfulg...@webkit.org>
+ * Copyright (C) 2010, 2011 Igalia S.L.
+ * Copyright (C) Research In Motion Limited 2010. All rights reserved.
+ * Copyright (C) 2012, Intel Corporation
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "CairoOperations.h"
+
+#if USE(CAIRO)
+
+#include "FloatRect.h"
+#include "Image.h"
+#include "Path.h"
+#include "PlatformContextCairo.h"
+#include "PlatformPathCairo.h"
+#include <cairo.h>
+
+namespace WebCore {
+namespace Cairo {
+
+void clip(PlatformContextCairo& platformContext, const FloatRect& rect)
+{
+    cairo_t* cr = platformContext.cr();
+    cairo_rectangle(cr, rect.x(), rect.y(), rect.width(), rect.height());
+    cairo_fill_rule_t savedFillRule = cairo_get_fill_rule(cr);
+    cairo_set_fill_rule(cr, CAIRO_FILL_RULE_WINDING);
+    // The rectangular clip function is traditionally not expected to
+    // antialias. If we don't force antialiased clipping here,
+    // edge fringe artifacts may occur at the layer edges
+    // when a transformation is applied to the GraphicsContext
+    // while drawing the transformed layer.
+    cairo_antialias_t savedAntialiasRule = cairo_get_antialias(cr);
+    cairo_set_antialias(cr, CAIRO_ANTIALIAS_NONE);
+    cairo_clip(cr);
+    cairo_set_fill_rule(cr, savedFillRule);
+    cairo_set_antialias(cr, savedAntialiasRule);
+}
+
+void clipOut(PlatformContextCairo& platformContext, const FloatRect& rect)
+{
+    cairo_t* cr = platformContext.cr();
+    double x1, y1, x2, y2;
+    cairo_clip_extents(cr, &x1, &y1, &x2, &y2);
+    cairo_rectangle(cr, x1, y1, x2 - x1, y2 - y1);
+    cairo_rectangle(cr, rect.x(), rect.y(), rect.width(), rect.height());
+    cairo_fill_rule_t savedFillRule = cairo_get_fill_rule(cr);
+    cairo_set_fill_rule(cr, CAIRO_FILL_RULE_EVEN_ODD);
+    cairo_clip(cr);
+    cairo_set_fill_rule(cr, savedFillRule);
+}
+
+void clipOut(PlatformContextCairo& platformContext, const Path& path)
+{
+    cairo_t* cr = platformContext.cr();
+    double x1, y1, x2, y2;
+    cairo_clip_extents(cr, &x1, &y1, &x2, &y2);
+    cairo_rectangle(cr, x1, y1, x2 - x1, y2 - y1);
+    appendWebCorePathToCairoContext(cr, path);
+
+    cairo_fill_rule_t savedFillRule = cairo_get_fill_rule(cr);
+    cairo_set_fill_rule(cr, CAIRO_FILL_RULE_EVEN_ODD);
+    cairo_clip(cr);
+    cairo_set_fill_rule(cr, savedFillRule);
+}
+
+void clipPath(PlatformContextCairo& platformContext, const Path& path, WindRule clipRule)
+{
+    cairo_t* cr = platformContext.cr();
+
+    if (!path.isNull())
+        setPathOnCairoContext(cr, path.platformPath()->context());
+
+    cairo_fill_rule_t savedFillRule = cairo_get_fill_rule(cr);
+    cairo_set_fill_rule(cr, clipRule == RULE_EVENODD ? CAIRO_FILL_RULE_EVEN_ODD : CAIRO_FILL_RULE_WINDING);
+    cairo_clip(cr);
+    cairo_set_fill_rule(cr, savedFillRule);
+}
+
+void clipToImageBuffer(PlatformContextCairo& platformContext, Image& image, const FloatRect& destRect)
+{
+    RefPtr<cairo_surface_t> surface = image.nativeImageForCurrentFrame();
+    if (surface)
+        platformContext.pushImageMask(surface.get(), destRect);
+}
+
+} // namespace Cairo
+} // namespace WebCore
+
+#endif // USE(CAIRO)

Added: trunk/Source/WebCore/platform/graphics/cairo/CairoOperations.h (0 => 224669)


--- trunk/Source/WebCore/platform/graphics/cairo/CairoOperations.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/cairo/CairoOperations.h	2017-11-10 08:18:02 UTC (rev 224669)
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2006 Apple Inc.  All rights reserved.
+ * Copyright (C) 2007 Alp Toker <a...@atoker.com>
+ * Copyright (C) 2008, 2009 Dirk Schulze <k...@webkit.org>
+ * Copyright (C) 2008 Nuanti Ltd.
+ * Copyright (C) 2009 Brent Fulgham <bfulg...@webkit.org>
+ * Copyright (C) 2010, 2011 Igalia S.L.
+ * Copyright (C) Research In Motion Limited 2010. All rights reserved.
+ * Copyright (C) 2012, Intel Corporation
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if USE(CAIRO)
+
+#include "GraphicsTypes.h"
+
+namespace WebCore {
+
+class FloatRect;
+class Image;
+class Path;
+class PlatformContextCairo;
+
+namespace Cairo {
+
+void clip(PlatformContextCairo&, const FloatRect&);
+void clipOut(PlatformContextCairo&, const FloatRect&);
+void clipOut(PlatformContextCairo&, const Path&);
+void clipPath(PlatformContextCairo&, const Path&, WindRule);
+
+void clipToImageBuffer(PlatformContextCairo&, Image&, const FloatRect&);
+
+} // namespace Cairo
+} // namespace WebCore
+
+#endif // USE(CAIRO)

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


--- trunk/Source/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp	2017-11-10 07:27:30 UTC (rev 224668)
+++ trunk/Source/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp	2017-11-10 08:18:02 UTC (rev 224669)
@@ -472,20 +472,8 @@
         return;
     }
 
-    cairo_t* cr = platformContext()->cr();
-    cairo_rectangle(cr, rect.x(), rect.y(), rect.width(), rect.height());
-    cairo_fill_rule_t savedFillRule = cairo_get_fill_rule(cr);
-    cairo_set_fill_rule(cr, CAIRO_FILL_RULE_WINDING);
-    // The rectangular clip function is traditionally not expected to
-    // antialias. If we don't force antialiased clipping here,
-    // edge fringe artifacts may occur at the layer edges
-    // when a transformation is applied to the GraphicsContext
-    // while drawing the transformed layer.
-    cairo_antialias_t savedAntialiasRule = cairo_get_antialias(cr);
-    cairo_set_antialias(cr, CAIRO_ANTIALIAS_NONE);
-    cairo_clip(cr);
-    cairo_set_fill_rule(cr, savedFillRule);
-    cairo_set_antialias(cr, savedAntialiasRule);
+    ASSERT(hasPlatformContext());
+    Cairo::clip(*platformContext(), rect);
     m_data->clip(rect);
 }
 
@@ -499,15 +487,8 @@
         return;
     }
 
-    cairo_t* cr = platformContext()->cr();
-    if (!path.isNull())
-        setPathOnCairoContext(cr, path.platformPath()->context());
-
-    cairo_fill_rule_t savedFillRule = cairo_get_fill_rule(cr);
-    cairo_set_fill_rule(cr, clipRule == RULE_EVENODD ? CAIRO_FILL_RULE_EVEN_ODD : CAIRO_FILL_RULE_WINDING);
-    cairo_clip(cr);
-    cairo_set_fill_rule(cr, savedFillRule);
-
+    ASSERT(hasPlatformContext());
+    Cairo::clipPath(*platformContext(), path, clipRule);
     m_data->clip(path);
 }
 
@@ -517,9 +498,9 @@
         return;
 
     RefPtr<Image> image = buffer.copyImage(DontCopyBackingStore);
-    RefPtr<cairo_surface_t> surface = image->nativeImageForCurrentFrame();
-    if (surface)
-        platformContext()->pushImageMask(surface.get(), destRect);
+
+    ASSERT(hasPlatformContext());
+    Cairo::clipToImageBuffer(*platformContext(), *image, destRect);
 }
 
 IntRect GraphicsContext::clipBounds() const
@@ -1056,16 +1037,8 @@
         return;
     }
 
-    cairo_t* cr = platformContext()->cr();
-    double x1, y1, x2, y2;
-    cairo_clip_extents(cr, &x1, &y1, &x2, &y2);
-    cairo_rectangle(cr, x1, y1, x2 - x1, y2 - y1);
-    appendWebCorePathToCairoContext(cr, path);
-
-    cairo_fill_rule_t savedFillRule = cairo_get_fill_rule(cr);
-    cairo_set_fill_rule(cr, CAIRO_FILL_RULE_EVEN_ODD);
-    cairo_clip(cr);
-    cairo_set_fill_rule(cr, savedFillRule);
+    ASSERT(hasPlatformContext());
+    Cairo::clipOut(*platformContext(), path);
 }
 
 void GraphicsContext::rotate(float radians)
@@ -1096,25 +1069,18 @@
     m_data->scale(size);
 }
 
-void GraphicsContext::clipOut(const FloatRect& r)
+void GraphicsContext::clipOut(const FloatRect& rect)
 {
     if (paintingDisabled())
         return;
 
     if (m_impl) {
-        m_impl->clipOut(r);
+        m_impl->clipOut(rect);
         return;
     }
 
-    cairo_t* cr = platformContext()->cr();
-    double x1, y1, x2, y2;
-    cairo_clip_extents(cr, &x1, &y1, &x2, &y2);
-    cairo_rectangle(cr, x1, y1, x2 - x1, y2 - y1);
-    cairo_rectangle(cr, r.x(), r.y(), r.width(), r.height());
-    cairo_fill_rule_t savedFillRule = cairo_get_fill_rule(cr);
-    cairo_set_fill_rule(cr, CAIRO_FILL_RULE_EVEN_ODD);
-    cairo_clip(cr);
-    cairo_set_fill_rule(cr, savedFillRule);
+    ASSERT(hasPlatformContext());
+    Cairo::clipOut(*platformContext(), rect);
 }
 
 void GraphicsContext::platformFillRoundedRect(const FloatRoundedRect& rect, const Color& color)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to