Bug 627273, part 2: Add some gfx path helpers. sr=roc
authorChris Jones <jones.chris.g@gmail.com>
Wed, 26 Jan 2011 00:26:37 -0600
changeset 61310 3bdbbd75eb04786b2560dcf762c4da9172983aea
parent 61309 656ed06c9a100e29d7b5814c471cb3d7745a20b6
child 61311 da677975bab102f9a06af64c7448c53dc47e2f74
push idunknown
push userunknown
push dateunknown
reviewersroc
bugs627273
milestone2.0b11pre
Bug 627273, part 2: Add some gfx path helpers. sr=roc
gfx/thebes/gfxUtils.cpp
gfx/thebes/gfxUtils.h
--- a/gfx/thebes/gfxUtils.cpp
+++ b/gfx/thebes/gfxUtils.cpp
@@ -429,41 +429,62 @@ gfxUtils::ImageFormatToDepth(gfxASurface
             return 24;
         case gfxASurface::ImageFormatRGB16_565:
             return 16;
         default:
             break;
     }
     return 0;
 }
+
 static void
-ClipToRegionInternal(gfxContext* aContext, const nsIntRegion& aRegion,
-                     PRBool aSnap)
+PathFromRegionInternal(gfxContext* aContext, const nsIntRegion& aRegion,
+                       PRBool aSnap)
 {
   aContext->NewPath();
   nsIntRegionRectIterator iter(aRegion);
   const nsIntRect* r;
   while ((r = iter.Next()) != nsnull) {
     aContext->Rectangle(gfxRect(r->x, r->y, r->width, r->height), aSnap);
   }
+}
+
+static void
+ClipToRegionInternal(gfxContext* aContext, const nsIntRegion& aRegion,
+                     PRBool aSnap)
+{
+  PathFromRegionInternal(aContext, aRegion, aSnap);
   aContext->Clip();
 }
 
 /*static*/ void
 gfxUtils::ClipToRegion(gfxContext* aContext, const nsIntRegion& aRegion)
 {
   ClipToRegionInternal(aContext, aRegion, PR_FALSE);
 }
 
 /*static*/ void
 gfxUtils::ClipToRegionSnapped(gfxContext* aContext, const nsIntRegion& aRegion)
 {
   ClipToRegionInternal(aContext, aRegion, PR_TRUE);
 }
 
+/*static*/ void
+gfxUtils::PathFromRegion(gfxContext* aContext, const nsIntRegion& aRegion)
+{
+  PathFromRegionInternal(aContext, aRegion, PR_FALSE);
+}
+
+/*static*/ void
+gfxUtils::PathFromRegionSnapped(gfxContext* aContext, const nsIntRegion& aRegion)
+{
+  PathFromRegionInternal(aContext, aRegion, PR_TRUE);
+}
+
+
 PRBool
 gfxUtils::GfxRectToIntRect(const gfxRect& aIn, nsIntRect* aOut)
 {
   *aOut = nsIntRect(PRInt32(aIn.X()), PRInt32(aIn.Y()),
   PRInt32(aIn.Width()), PRInt32(aIn.Height()));
   return gfxRect(aOut->x, aOut->y, aOut->width, aOut->height) == aIn;
 }
 
--- a/gfx/thebes/gfxUtils.h
+++ b/gfx/thebes/gfxUtils.h
@@ -91,16 +91,26 @@ public:
      */
     static void ClipToRegion(gfxContext* aContext, const nsIntRegion& aRegion);
 
     /**
      * Clip aContext to the region aRegion, snapping the rectangles.
      */
     static void ClipToRegionSnapped(gfxContext* aContext, const nsIntRegion& aRegion);
 
+    /**
+     * Create a path consisting of rectangles in |aRegion|.
+     */
+    static void PathFromRegion(gfxContext* aContext, const nsIntRegion& aRegion);
+
+    /**
+     * Create a path consisting of rectangles in |aRegion|, snapping the rectangles.
+     */
+    static void PathFromRegionSnapped(gfxContext* aContext, const nsIntRegion& aRegion);
+
     /*
      * Convert image format to depth value
      */
     static int ImageFormatToDepth(gfxASurface::gfxImageFormat aFormat);
 
     /**
      * If aIn can be represented exactly using an nsIntRect (i.e.
      * integer-aligned edges and coordinates in the PRInt32 range) then we