Simplify Path(CG)::transform/translate
authortimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 19 Jul 2015 04:38:46 +0000 (04:38 +0000)
committertimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 19 Jul 2015 04:38:46 +0000 (04:38 +0000)
https://bugs.webkit.org/show_bug.cgi?id=147077

Reviewed by Simon Fraser.

No new tests; no behavior change.

* platform/graphics/cg/PathCG.cpp:
(WebCore::Path::translate):
(WebCore::Path::transform):
Use CGPathCreateMutableCopyByTransformingPath to do the copy and transform
in a single call instead of two.

Make use of transform() to implement translate() instead of duplicating the code.
Move the two functions near each other.

(WebCore::Path::boundingRect):
Remove irrelevant reference to Snow Leopard.

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

Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/cg/PathCG.cpp

index 6deb83c..849888b 100644 (file)
@@ -1,3 +1,24 @@
+2015-07-18  Tim Horton  <timothy_horton@apple.com>
+
+        Simplify Path(CG)::transform/translate
+        https://bugs.webkit.org/show_bug.cgi?id=147077
+
+        Reviewed by Simon Fraser.
+
+        No new tests; no behavior change.
+
+        * platform/graphics/cg/PathCG.cpp:
+        (WebCore::Path::translate):
+        (WebCore::Path::transform):
+        Use CGPathCreateMutableCopyByTransformingPath to do the copy and transform
+        in a single call instead of two.
+
+        Make use of transform() to implement translate() instead of duplicating the code.
+        Move the two functions near each other.
+
+        (WebCore::Path::boundingRect):
+        Remove irrelevant reference to Snow Leopard.
+
 2015-07-17  Matt Rajca  <mrajca@apple.com>
 
         Media Session: Add support for 'Content' interruption types
index 3a3e0fd..08bb8db 100644 (file)
@@ -182,12 +182,18 @@ bool Path::strokeContains(StrokeStyleApplier* applier, const FloatPoint& point)
 
 void Path::translate(const FloatSize& size)
 {
-    CGAffineTransform translation = CGAffineTransformMake(1, 0, 0, 1, size.width(), size.height());
-    CGMutablePathRef newPath = CGPathCreateMutable();
-    // FIXME: This is potentially wasteful to allocate an empty path only to create a transformed copy.
-    CGPathAddPath(newPath, &translation, ensurePlatformPath());
+    transform(AffineTransform(1, 0, 0, 1, size.width(), size.height()));
+}
+
+void Path::transform(const AffineTransform& transform)
+{
+    if (transform.isIdentity() || isEmpty())
+        return;
+
+    CGAffineTransform transformCG = transform;
+    CGMutablePathRef path = CGPathCreateMutableCopyByTransformingPath(m_path, &transformCG);
     CGPathRelease(m_path);
-    m_path = newPath;
+    m_path = path;
 }
 
 FloatRect Path::boundingRect() const
@@ -195,8 +201,7 @@ FloatRect Path::boundingRect() const
     if (isNull())
         return CGRectZero;
 
-    // CGPathGetBoundingBox includes the path's control points, CGPathGetPathBoundingBox
-    // does not, but only exists on 10.6 and above.
+    // CGPathGetBoundingBox includes the path's control points, CGPathGetPathBoundingBox does not.
 
     CGRect bound = CGPathGetPathBoundingBox(m_path);
     return CGRectIsNull(bound) ? CGRectZero : bound;
@@ -409,18 +414,6 @@ void Path::apply(void* info, PathApplierFunction function) const
     CGPathApply(m_path, &pinfo, CGPathApplierToPathApplier);
 }
 
-void Path::transform(const AffineTransform& transform)
-{
-    if (transform.isIdentity() || isEmpty())
-        return;
-
-    CGMutablePathRef path = CGPathCreateMutable();
-    CGAffineTransform transformCG = transform;
-    CGPathAddPath(path, &transformCG, m_path);
-    CGPathRelease(m_path);
-    m_path = path;
-}
-
 }
 
 #endif // USE(CG)