Bug 1090494, part 4 - Add AppendRectToPath() and MakePathForRect() helpers to Moz2D's PathHelpers.h. r=mattwoodrow
authorJonathan Watt <jwatt@jwatt.org>
Thu, 30 Oct 2014 09:34:10 +0000
changeset 213075 b991ca238a3538e152dbcd7317b2c5f178b61555
parent 213074 b17a0c6392b2cc39e3369cde47f08a1530b61c7e
child 213076 1aa1b23d799e5cf08b21bd8b08f78716d35d89f6
child 213159 b03320f5bab6ea7baea766d259d5453d8d85985a
push id27738
push usercbook@mozilla.com
push dateThu, 30 Oct 2014 13:46:07 +0000
treeherdermozilla-central@1aa1b23d799e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmattwoodrow
bugs1090494
milestone36.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1090494, part 4 - Add AppendRectToPath() and MakePathForRect() helpers to Moz2D's PathHelpers.h. r=mattwoodrow
gfx/2d/PathHelpers.cpp
gfx/2d/PathHelpers.h
--- a/gfx/2d/PathHelpers.cpp
+++ b/gfx/2d/PathHelpers.cpp
@@ -6,16 +6,35 @@
 #include "PathHelpers.h"
 
 namespace mozilla {
 namespace gfx {
 
 UserDataKey sDisablePixelSnapping;
 
 void
+AppendRectToPath(PathBuilder* aPathBuilder,
+                 const Rect& aRect,
+                 bool aDrawClockwise)
+{
+  if (aDrawClockwise) {
+    aPathBuilder->MoveTo(aRect.TopLeft());
+    aPathBuilder->LineTo(aRect.TopRight());
+    aPathBuilder->LineTo(aRect.BottomRight());
+    aPathBuilder->LineTo(aRect.BottomLeft());
+  } else {
+    aPathBuilder->MoveTo(aRect.TopRight());
+    aPathBuilder->LineTo(aRect.TopLeft());
+    aPathBuilder->LineTo(aRect.BottomLeft());
+    aPathBuilder->LineTo(aRect.BottomRight());
+  }
+  aPathBuilder->Close();
+}
+
+void
 AppendRoundedRectToPath(PathBuilder* aPathBuilder,
                         const Rect& aRect,
                         const RectCornerRadii& aRadii,
                         bool aDrawClockwise)
 {
   // For CW drawing, this looks like:
   //
   //  ...******0**      1    C
--- a/gfx/2d/PathHelpers.h
+++ b/gfx/2d/PathHelpers.h
@@ -125,16 +125,39 @@ void EllipseToBezier(T* aSink, const Poi
     // cos(x+pi/2) == -sin(x)
     // sin(x+pi/2) == cos(x)
     Float tmp = cosStartAngle;
     cosStartAngle = -sinStartAngle;
     sinStartAngle = tmp;
   }
 }
 
+/**
+ * Appends a path represending a rectangle to the path being built by
+ * aPathBuilder.
+ *
+ * aRect           The rectangle to append.
+ * aDrawClockwise  If set to true, the path will start at the left of the top
+ *                 left edge and draw clockwise. If set to false the path will
+ *                 start at the right of the top left edge and draw counter-
+ *                 clockwise.
+ */
+GFX2D_API void AppendRectToPath(PathBuilder* aPathBuilder,
+                                const Rect& aRect,
+                                bool aDrawClockwise = true);
+
+inline TemporaryRef<Path> MakePathForRect(const DrawTarget& aDrawTarget,
+                                          const Rect& aRect,
+                                          bool aDrawClockwise = true)
+{
+  RefPtr<PathBuilder> builder = aDrawTarget.CreatePathBuilder();
+  AppendRectToPath(builder, aRect, aDrawClockwise);
+  return builder->Finish();
+}
+
 // We can't use MOZ_BEGIN_ENUM_CLASS here because that prevents the enum
 // values from being used for indexing. Wrapping the enum in a struct does at
 // least gives us name scoping.
 struct RectCorner {
   enum {
     // This order is important since AppendRoundedRectToPath and other code
     // depends on it!
     TopLeft = 0,