Bug 1376782 - Replace gfxPoint with a typedef to PointDouble. r?jrmuizel draft
authorKartikaya Gupta <kgupta@mozilla.com>
Wed, 28 Jun 2017 11:42:23 -0400
changeset 601384 8d9947753d319dba6f43588d3e6501b016ddd724
parent 601383 d7d1faeaf3c79a533754ab7b28a213b3ecb90a37
child 635236 a14914c66229ac773a389b7d6893bdd2b9f23762
push id66037
push userkgupta@mozilla.com
push dateWed, 28 Jun 2017 18:23:09 +0000
reviewersjrmuizel
bugs1376782
milestone56.0a1
Bug 1376782 - Replace gfxPoint with a typedef to PointDouble. r?jrmuizel This also moves the WithinEpsilonOf function from gfxPoint into PointTyped, and changes call sites that are using gfxPoint::Transform(Matrix4x4) to use Matrix4x4::TransformPoint(Point) instead, which should be equivalent. MozReview-Commit-ID: 3Z0bsU41rQt
gfx/2d/Point.h
gfx/thebes/gfxASurface.h
gfx/thebes/gfxPoint.h
gfx/thebes/gfxRect.cpp
layout/base/nsLayoutUtils.cpp
layout/base/nsLayoutUtils.h
layout/style/nsStyleTransformMatrix.h
--- a/gfx/2d/Point.h
+++ b/gfx/2d/Point.h
@@ -126,16 +126,20 @@ struct PointTyped :
   constexpr PointTyped(F aX, F aY) : Super(Coord(aX), Coord(aY)) {}
   // The mixed-type constructors (Float, Coord) and (Coord, Float) are needed to
   // avoid ambiguities because Coord is implicitly convertible to Float.
   constexpr PointTyped(F aX, Coord aY) : Super(Coord(aX), aY) {}
   constexpr PointTyped(Coord aX, F aY) : Super(aX, Coord(aY)) {}
   constexpr PointTyped(Coord aX, Coord aY) : Super(aX.value, aY.value) {}
   constexpr MOZ_IMPLICIT PointTyped(const IntPointTyped<units>& point) : Super(F(point.x), F(point.y)) {}
 
+  bool WithinEpsilonOf(const PointTyped<units, F>& aPoint, F aEpsilon) {
+    return fabs(aPoint.x - this->x) < aEpsilon && fabs(aPoint.y - this->y) < aEpsilon;
+  }
+
   // XXX When all of the code is ported, the following functions to convert to and from
   // unknown types should be removed.
 
   static PointTyped<units, F> FromUnknownPoint(const PointTyped<UnknownUnits, F>& aPoint) {
     return PointTyped<units, F>(aPoint.x, aPoint.y);
   }
 
   PointTyped<UnknownUnits, F> ToUnknownPoint() const {
--- a/gfx/thebes/gfxASurface.h
+++ b/gfx/thebes/gfxASurface.h
@@ -4,26 +4,26 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef GFX_ASURFACE_H
 #define GFX_ASURFACE_H
 
 #include "mozilla/MemoryReporting.h"
 #include "mozilla/UniquePtr.h"
 
+#include "gfxPoint.h"
 #include "gfxTypes.h"
 #include "nscore.h"
 #include "nsSize.h"
 #include "mozilla/gfx/Rect.h"
 
 #include "nsStringFwd.h"
 
 class gfxImageSurface;
 struct gfxRect;
-struct gfxPoint;
 
 template <typename T>
 struct already_AddRefed;
 
 /**
  * A surface is something you can draw on. Instantiate a subclass of this
  * abstract class, and use gfxContext to draw on this surface.
  */
--- a/gfx/thebes/gfxPoint.h
+++ b/gfx/thebes/gfxPoint.h
@@ -1,59 +1,14 @@
 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef GFX_POINT_H
 #define GFX_POINT_H
 
-#include "nsMathUtils.h"
-#include "mozilla/gfx/BaseSize.h"
-#include "mozilla/gfx/BasePoint.h"
-#include "mozilla/gfx/Matrix.h"
 #include "mozilla/gfx/Point.h"
-#include "nsSize.h"
-#include "nsPoint.h"
-
-#include "gfxTypes.h"
 
 typedef mozilla::gfx::SizeDouble gfxSize;
-
-struct gfxPoint : public mozilla::gfx::BasePoint<gfxFloat, gfxPoint> {
-    typedef mozilla::gfx::BasePoint<gfxFloat, gfxPoint> Super;
-
-    gfxPoint() : Super() {}
-    gfxPoint(gfxFloat aX, gfxFloat aY) : Super(aX, aY) {}
-    MOZ_IMPLICIT gfxPoint(const nsIntPoint& aPoint) : Super(aPoint.x, aPoint.y) {}
-
-    bool WithinEpsilonOf(const gfxPoint& aPoint, gfxFloat aEpsilon) {
-        return fabs(aPoint.x - x) < aEpsilon && fabs(aPoint.y - y) < aEpsilon;
-    }
-
-    void Transform(const mozilla::gfx::Matrix4x4 &aMatrix)
-    {
-      // Transform this point with aMatrix
-      double px = x;
-      double py = y;
-
-      x = px * aMatrix._11 + py * aMatrix._21 + aMatrix._41;
-      y = px * aMatrix._12 + py * aMatrix._22 + aMatrix._42;
-
-      double w = px * aMatrix._14 + py * aMatrix._24 + aMatrix._44;
-      x /= w;
-      y /= w;
-    }
-};
-
-inline gfxPoint
-operator*(const gfxPoint& aPoint, const gfxSize& aSize)
-{
-  return gfxPoint(aPoint.x * aSize.width, aPoint.y * aSize.height);
-}
-
-inline gfxPoint
-operator/(const gfxPoint& aPoint, const gfxSize& aSize)
-{
-  return gfxPoint(aPoint.x / aSize.width, aPoint.y / aSize.height);
-}
+typedef mozilla::gfx::PointDouble gfxPoint;
 
 #endif /* GFX_POINT_H */
--- a/gfx/thebes/gfxRect.cpp
+++ b/gfx/thebes/gfxRect.cpp
@@ -11,25 +11,20 @@
 
 #include "gfxQuad.h"
 
 gfxQuad
 gfxRect::TransformToQuad(const mozilla::gfx::Matrix4x4 &aMatrix) const
 {
   gfxPoint points[4];
 
-  points[0] = TopLeft();
-  points[1] = TopRight();
-  points[2] = BottomRight();
-  points[3] = BottomLeft();
-
-  points[0].Transform(aMatrix);
-  points[1].Transform(aMatrix);
-  points[2].Transform(aMatrix);
-  points[3].Transform(aMatrix);
+  points[0] = aMatrix.TransformPoint(TopLeft());
+  points[1] = aMatrix.TransformPoint(TopRight());
+  points[2] = aMatrix.TransformPoint(BottomRight());
+  points[3] = aMatrix.TransformPoint(BottomLeft());
 
   // Could this ever result in lines that intersect? I don't think so.
   return gfxQuad(points[0], points[1], points[2], points[3]);
 }
 
 static bool
 WithinEpsilonOfInteger(gfxFloat aX, gfxFloat aEpsilon)
 {
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -2636,17 +2636,17 @@ nsLayoutUtils::MatrixTransformRect(const
 }
 
 nsPoint
 nsLayoutUtils::MatrixTransformPoint(const nsPoint &aPoint,
                                     const Matrix4x4 &aMatrix, float aFactor)
 {
   gfxPoint image = gfxPoint(NSAppUnitsToFloatPixels(aPoint.x, aFactor),
                             NSAppUnitsToFloatPixels(aPoint.y, aFactor));
-  image.Transform(aMatrix);
+  image = aMatrix.TransformPoint(image);
   return nsPoint(NSFloatPixelsToAppUnits(float(image.x), aFactor),
                  NSFloatPixelsToAppUnits(float(image.y), aFactor));
 }
 
 void
 nsLayoutUtils::PostTranslate(Matrix4x4& aTransform, const nsPoint& aOrigin, float aAppUnitsPerPixel, bool aRounded)
 {
   Point3D gfxOrigin =
--- a/layout/base/nsLayoutUtils.h
+++ b/layout/base/nsLayoutUtils.h
@@ -29,16 +29,17 @@
 #include "mozilla/ToString.h"
 #include "mozilla/ReflowOutput.h"
 #include "ImageContainer.h"
 #include "gfx2DGlue.h"
 #include "nsStyleConsts.h"
 #include "SVGImageContext.h"
 #include <limits>
 #include <algorithm>
+#include "gfxPoint.h"
 
 class gfxContext;
 class nsPresContext;
 class nsIContent;
 class nsIAtom;
 class nsIScrollableFrame;
 class nsIDOMEvent;
 class nsRegion;
@@ -53,17 +54,16 @@ class nsBlockFrame;
 class nsContainerFrame;
 class nsView;
 class nsIFrame;
 class nsStyleCoord;
 class nsStyleCorners;
 class nsPIDOMWindowOuter;
 class imgIRequest;
 class nsIDocument;
-struct gfxPoint;
 struct nsStyleFont;
 struct nsStyleImageOrientation;
 struct nsOverflowAreas;
 
 namespace mozilla {
 enum class CSSPseudoElementType : uint8_t;
 class EventListenerManager;
 enum class LayoutFrameType : uint8_t;
--- a/layout/style/nsStyleTransformMatrix.h
+++ b/layout/style/nsStyleTransformMatrix.h
@@ -5,16 +5,17 @@
 
 /*
  * A class representing three matrices that can be used for style transforms.
  */
 
 #ifndef nsStyleTransformMatrix_h_
 #define nsStyleTransformMatrix_h_
 
+#include "mozilla/gfx/Matrix.h"
 #include "mozilla/EnumeratedArray.h"
 #include "nsCSSValue.h"
 
 #include <limits>
 
 class nsIFrame;
 class nsStyleContext;
 class nsPresContext;