[Cairo] Drop cairo_matrix_t conversion operators for AffineTransform, TransformationM...
authorzandobersek@gmail.com <zandobersek@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 28 Sep 2017 06:16:52 +0000 (06:16 +0000)
committerzandobersek@gmail.com <zandobersek@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 28 Sep 2017 06:16:52 +0000 (06:16 +0000)
https://bugs.webkit.org/show_bug.cgi?id=177539

Reviewed by Carlos Garcia Campos.

Remove the cairo_matrix_t conversion operators from the AffineTransform
and TransformationMatrix classes. These are rarely used, but enforce
including the cairo.h header in both headers, which leads to the Cairo
headers being included in around 800 build targets.

Instead, the toCairoMatrix() function is added to CairoUtilities.h that
creates a cairo_matrix_t object for the given AffineTransform. No
toCairoMatrix() is needed for TransformationMatrix since objects of
that type aren't converted to cairo_matrix_t anywhere in the codebase.

This patch excludes unnecessary Cairo headers from about 550 build
targets (with those headers being included in the other affected 250
targets by some other header inclusion chain). CairoUtilities.h header
is now included where necessary to make toCairoMatrix() available, and
duplicated cairo.h inclusions are removed.

No new tests -- no change in behavior.

* editing/gtk/EditorGtk.cpp: Explicitly include <cairo.h> since it's
necessary for Cairo operations used there.
* platform/Cairo.cmake:
* platform/graphics/cairo/CairoUtilities.cpp:
(WebCore::drawPatternToCairoContext):
(WebCore::toCairoMatrix):
* platform/graphics/cairo/CairoUtilities.h:
* platform/graphics/cairo/GradientCairo.cpp:
(WebCore::Gradient::platformGradient):
(WebCore::Gradient::setPlatformGradientSpaceTransform):
* platform/graphics/cairo/GraphicsContextCairo.cpp:
(WebCore::GraphicsContext::concatCTM):
(WebCore::GraphicsContext::setCTM):
* platform/graphics/cairo/PathCairo.cpp: No need to include AffineTransform.h.
(WebCore::Path::addPath):
(WebCore::Path::transform):
* platform/graphics/cairo/PatternCairo.cpp: Ditto.
(WebCore::Pattern::createPlatformPattern const):
* platform/graphics/cairo/TransformationMatrixCairo.cpp: Removed.
* platform/graphics/transforms/AffineTransform.h:
* platform/graphics/transforms/TransformationMatrix.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@222603 268f45cc-cd09-0410-ab3c-d52691b4dbfc

12 files changed:
Source/WebCore/ChangeLog
Source/WebCore/editing/gtk/EditorGtk.cpp
Source/WebCore/platform/Cairo.cmake
Source/WebCore/platform/graphics/cairo/CairoUtilities.cpp
Source/WebCore/platform/graphics/cairo/CairoUtilities.h
Source/WebCore/platform/graphics/cairo/GradientCairo.cpp
Source/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp
Source/WebCore/platform/graphics/cairo/PathCairo.cpp
Source/WebCore/platform/graphics/cairo/PatternCairo.cpp
Source/WebCore/platform/graphics/cairo/TransformationMatrixCairo.cpp [deleted file]
Source/WebCore/platform/graphics/transforms/AffineTransform.h
Source/WebCore/platform/graphics/transforms/TransformationMatrix.h

index 3d12b18..92e05d7 100644 (file)
@@ -1,3 +1,50 @@
+2017-09-27  Zan Dobersek  <zdobersek@igalia.com>
+
+        [Cairo] Drop cairo_matrix_t conversion operators for AffineTransform, TransformationMatrix
+        https://bugs.webkit.org/show_bug.cgi?id=177539
+
+        Reviewed by Carlos Garcia Campos.
+
+        Remove the cairo_matrix_t conversion operators from the AffineTransform
+        and TransformationMatrix classes. These are rarely used, but enforce
+        including the cairo.h header in both headers, which leads to the Cairo
+        headers being included in around 800 build targets.
+
+        Instead, the toCairoMatrix() function is added to CairoUtilities.h that
+        creates a cairo_matrix_t object for the given AffineTransform. No
+        toCairoMatrix() is needed for TransformationMatrix since objects of
+        that type aren't converted to cairo_matrix_t anywhere in the codebase.
+
+        This patch excludes unnecessary Cairo headers from about 550 build
+        targets (with those headers being included in the other affected 250
+        targets by some other header inclusion chain). CairoUtilities.h header
+        is now included where necessary to make toCairoMatrix() available, and
+        duplicated cairo.h inclusions are removed.
+
+        No new tests -- no change in behavior.
+
+        * editing/gtk/EditorGtk.cpp: Explicitly include <cairo.h> since it's
+        necessary for Cairo operations used there.
+        * platform/Cairo.cmake:
+        * platform/graphics/cairo/CairoUtilities.cpp:
+        (WebCore::drawPatternToCairoContext):
+        (WebCore::toCairoMatrix):
+        * platform/graphics/cairo/CairoUtilities.h:
+        * platform/graphics/cairo/GradientCairo.cpp:
+        (WebCore::Gradient::platformGradient):
+        (WebCore::Gradient::setPlatformGradientSpaceTransform):
+        * platform/graphics/cairo/GraphicsContextCairo.cpp:
+        (WebCore::GraphicsContext::concatCTM):
+        (WebCore::GraphicsContext::setCTM):
+        * platform/graphics/cairo/PathCairo.cpp: No need to include AffineTransform.h.
+        (WebCore::Path::addPath):
+        (WebCore::Path::transform):
+        * platform/graphics/cairo/PatternCairo.cpp: Ditto.
+        (WebCore::Pattern::createPlatformPattern const):
+        * platform/graphics/cairo/TransformationMatrixCairo.cpp: Removed.
+        * platform/graphics/transforms/AffineTransform.h:
+        * platform/graphics/transforms/TransformationMatrix.h:
+
 2017-09-27  Alex Christensen  <achristensen@webkit.org>
 
         Add WKContentRuleList notify action type
index 321439a..be463a8 100644 (file)
@@ -45,6 +45,7 @@
 #include "SelectionData.h"
 #include "XLinkNames.h"
 #include "markup.h"
+#include <cairo.h>
 
 namespace WebCore {
 
index 7dd1e00..1e7d727 100644 (file)
@@ -20,7 +20,6 @@ list(APPEND WebCore_SOURCES
     platform/graphics/cairo/PlatformContextCairo.cpp
     platform/graphics/cairo/PlatformPathCairo.cpp
     platform/graphics/cairo/RefPtrCairo.cpp
-    platform/graphics/cairo/TransformationMatrixCairo.cpp
 )
 
 list(APPEND WebCore_LIBRARIES
index 63c0bdd..24d4eb5 100644 (file)
@@ -254,7 +254,7 @@ void drawPatternToCairoContext(cairo_t* cr, cairo_surface_t* image, const IntSiz
     // are drawing a repeated pattern. This means that, assuming that (w, h) is the size of the pattern, samplig it at (x, y) is the same
     // than sampling it at (x mod w, y mod h), so we transform the translation component of the pattern matrix in that way.
 
-    cairo_matrix_t patternMatrix = cairo_matrix_t(patternTransform);
+    cairo_matrix_t patternMatrix = toCairoMatrix(patternTransform);
     // dx and dy are added here as well to compensate the previous translation of the destination rectangle.
     double phaseOffsetX = phase.x() + tileRect.x() * patternTransform.a() + dx;
     double phaseOffsetY = phase.y() + tileRect.y() * patternTransform.d() + dy;
@@ -385,6 +385,11 @@ RefPtr<cairo_region_t> toCairoRegion(const Region& region)
     return cairoRegion;
 }
 
+cairo_matrix_t toCairoMatrix(const AffineTransform& transform)
+{
+    return cairo_matrix_t { transform.a(), transform.b(), transform.c(), transform.d(), transform.e(), transform.f() };
+}
+
 } // namespace WebCore
 
 #endif // USE(CAIRO)
index 9528e02..381d3c8 100644 (file)
@@ -95,6 +95,8 @@ void cairoSurfaceGetDeviceScale(cairo_surface_t*, double& xScale, double& yScale
 
 RefPtr<cairo_region_t> toCairoRegion(const Region&);
 
+cairo_matrix_t toCairoMatrix(const AffineTransform&);
+
 } // namespace WebCore
 
 #endif // USE(CAIRO)
index c4b769d..9d29dd6 100644 (file)
@@ -29,9 +29,9 @@
 
 #if USE(CAIRO)
 
+#include "CairoUtilities.h"
 #include "GraphicsContext.h"
 #include "PlatformContextCairo.h"
-#include <cairo.h>
 
 namespace WebCore {
 
@@ -84,7 +84,7 @@ cairo_pattern_t* Gradient::platformGradient(float globalAlpha)
         break;
     }
 
-    cairo_matrix_t matrix = m_gradientSpaceTransformation;
+    cairo_matrix_t matrix = toCairoMatrix(m_gradientSpaceTransformation);
     cairo_matrix_invert(&matrix);
     cairo_pattern_set_matrix(m_gradient, &matrix);
 
@@ -94,7 +94,7 @@ cairo_pattern_t* Gradient::platformGradient(float globalAlpha)
 void Gradient::setPlatformGradientSpaceTransform(const AffineTransform& gradientSpaceTransformation)
 {
     if (m_gradient) {
-        cairo_matrix_t matrix = gradientSpaceTransformation;
+        cairo_matrix_t matrix = toCairoMatrix(gradientSpaceTransformation);
         cairo_matrix_invert(&matrix);
         cairo_pattern_set_matrix(m_gradient, &matrix);
     }
index ac4b4a0..45ca9d9 100644 (file)
@@ -822,7 +822,7 @@ void GraphicsContext::concatCTM(const AffineTransform& transform)
     }
 
     cairo_t* cr = platformContext()->cr();
-    const cairo_matrix_t matrix = cairo_matrix_t(transform);
+    const cairo_matrix_t matrix = toCairoMatrix(transform);
     cairo_transform(cr, &matrix);
     m_data->concatCTM(transform);
 }
@@ -838,7 +838,7 @@ void GraphicsContext::setCTM(const AffineTransform& transform)
     }
 
     cairo_t* cr = platformContext()->cr();
-    const cairo_matrix_t matrix = cairo_matrix_t(transform);
+    const cairo_matrix_t matrix = toCairoMatrix(transform);
     cairo_set_matrix(cr, &matrix);
     m_data->setCTM(transform);
 }
index 6ab7910..82ffc97 100644 (file)
 
 #if USE(CAIRO)
 
-#include "AffineTransform.h"
+#include "CairoUtilities.h"
 #include "FloatRect.h"
 #include "GraphicsContext.h"
 #include "PlatformPathCairo.h"
 #include "StrokeStyleApplier.h"
-#include <cairo.h>
 #include <math.h>
 #include <wtf/MathExtras.h>
 #include <wtf/text/WTFString.h>
@@ -317,7 +316,7 @@ void Path::addPath(const Path& path, const AffineTransform& transform)
     if (path.isNull())
         return;
 
-    cairo_matrix_t matrix(transform);
+    cairo_matrix_t matrix = toCairoMatrix(transform);
     if (cairo_matrix_invert(&matrix) != CAIRO_STATUS_SUCCESS)
         return;
 
@@ -431,12 +430,12 @@ void Path::apply(const PathApplierFunction& function) const
     cairo_path_destroy(pathCopy);
 }
 
-void Path::transform(const AffineTransform& trans)
+void Path::transform(const AffineTransform& transform)
 {
     cairo_t* cr = ensurePlatformPath()->context();
-    cairo_matrix_t c_matrix = cairo_matrix_t(trans);
-    cairo_matrix_invert(&c_matrix);
-    cairo_transform(cr, &c_matrix);
+    cairo_matrix_t matrix = toCairoMatrix(transform);
+    cairo_matrix_invert(&matrix);
+    cairo_transform(cr, &matrix);
 }
 
 } // namespace WebCore
index 7e5df04..ce52780 100644 (file)
@@ -28,9 +28,8 @@
 
 #if USE(CAIRO)
 
-#include "AffineTransform.h"
+#include "CairoUtilities.h"
 #include "GraphicsContext.h"
-#include <cairo.h>
 
 namespace WebCore {
 
@@ -43,7 +42,7 @@ cairo_pattern_t* Pattern::createPlatformPattern(const AffineTransform&) const
     cairo_pattern_t* pattern = cairo_pattern_create_for_surface(surface.get());
 
     // cairo merges patter space and user space itself
-    cairo_matrix_t matrix = m_patternSpaceTransformation;
+    cairo_matrix_t matrix = toCairoMatrix(m_patternSpaceTransformation);
     cairo_matrix_invert(&matrix);
     cairo_pattern_set_matrix(pattern, &matrix);
 
diff --git a/Source/WebCore/platform/graphics/cairo/TransformationMatrixCairo.cpp b/Source/WebCore/platform/graphics/cairo/TransformationMatrixCairo.cpp
deleted file mode 100644 (file)
index a5cc372..0000000
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- *
- * 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 "TransformationMatrix.h"
-
-#if USE(CAIRO)
-
-#include "AffineTransform.h"
-#include "FloatRect.h"
-#include "IntRect.h"
-#include <cairo.h>
-
-namespace WebCore {
-
-TransformationMatrix::operator cairo_matrix_t() const
-{
-    cairo_matrix_t m;
-
-    cairo_matrix_init (&m,
-                       a(),
-                       b(),
-                       c(),
-                       d(),
-                       e(),
-                       f());
-    return m;
-}
-
-AffineTransform::operator cairo_matrix_t() const
-{
-    cairo_matrix_t m;
-
-    cairo_matrix_init (&m,
-                       a(),
-                       b(),
-                       c(),
-                       d(),
-                       e(),
-                       f());
-    return m;
-}
-
-} // namespace WebCore
-
-#endif // USE(CAIRO)
index 4f034b0..e7d7d33 100644 (file)
@@ -34,8 +34,6 @@
 
 #if USE(CG)
 typedef struct CGAffineTransform CGAffineTransform;
-#elif USE(CAIRO)
-#include <cairo.h>
 #endif
 
 #if PLATFORM(WIN)
@@ -181,8 +179,6 @@ public:
 
 #if USE(CG)
     WEBCORE_EXPORT operator CGAffineTransform() const;
-#elif USE(CAIRO)
-    operator cairo_matrix_t() const;
 #endif
 
 #if PLATFORM(WIN)
index 14b6206..e832ba9 100644 (file)
@@ -37,8 +37,6 @@ typedef struct CATransform3D CATransform3D;
 #endif
 #if USE(CG)
 typedef struct CGAffineTransform CGAffineTransform;
-#elif USE(CAIRO)
-#include <cairo.h>
 #endif
 
 #if PLATFORM(WIN) || (PLATFORM(GTK) && OS(WINDOWS))
@@ -360,8 +358,6 @@ public:
 #if USE(CG)
     WEBCORE_EXPORT TransformationMatrix(const CGAffineTransform&);
     WEBCORE_EXPORT operator CGAffineTransform() const;
-#elif USE(CAIRO)
-    operator cairo_matrix_t() const;
 #endif
 
 #if PLATFORM(WIN) || (PLATFORM(GTK) && OS(WINDOWS))