Bug 663776. Part 2: Move TransformRectToRect from nsCSSRendering to gfxUtils. r=mattwoodrow
authorRobert O'Callahan <robert@ocallahan.org>
Fri, 07 Dec 2012 12:58:13 +1300
changeset 117116 59b5ec3ba8d3c6b1324bef1ddbda2c661257dca9
parent 117115 75a09d9557b9cae550f59b7b377a2b47092317e4
child 117117 76eb5642d77b25590e647846122bf84d09cbe27d
push id20318
push userrocallahan@mozilla.com
push dateThu, 27 Dec 2012 19:38:05 +0000
treeherdermozilla-inbound@76eb5642d77b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmattwoodrow
bugs663776
milestone20.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 663776. Part 2: Move TransformRectToRect from nsCSSRendering to gfxUtils. r=mattwoodrow
gfx/thebes/gfxUtils.cpp
gfx/thebes/gfxUtils.h
layout/base/nsCSSRendering.cpp
--- a/gfx/thebes/gfxUtils.cpp
+++ b/gfx/thebes/gfxUtils.cpp
@@ -587,16 +587,39 @@ gfxUtils::PathFromRegion(gfxContext* aCo
 }
 
 /*static*/ void
 gfxUtils::PathFromRegionSnapped(gfxContext* aContext, const nsIntRegion& aRegion)
 {
   PathFromRegionInternal(aContext, aRegion, true);
 }
 
+gfxMatrix
+gfxUtils::TransformRectToRect(const gfxRect& aFrom, const gfxPoint& aToTopLeft,
+                              const gfxPoint& aToTopRight, const gfxPoint& aToBottomRight)
+{
+  gfxMatrix m;
+  if (aToTopRight.y == aToTopLeft.y && aToTopRight.x == aToBottomRight.x) {
+    // Not a rotation, so xy and yx are zero
+    m.xy = m.yx = 0.0;
+    m.xx = (aToBottomRight.x - aToTopLeft.x)/aFrom.width;
+    m.yy = (aToBottomRight.y - aToTopLeft.y)/aFrom.height;
+    m.x0 = aToTopLeft.x - m.xx*aFrom.x;
+    m.y0 = aToTopLeft.y - m.yy*aFrom.y;
+  } else {
+    NS_ASSERTION(aToTopRight.y == aToBottomRight.y && aToTopRight.x == aToTopLeft.x,
+                 "Destination rectangle not axis-aligned");
+    m.xx = m.yy = 0.0;
+    m.xy = (aToBottomRight.x - aToTopLeft.x)/aFrom.height;
+    m.yx = (aToBottomRight.y - aToTopLeft.y)/aFrom.width;
+    m.x0 = aToTopLeft.x - m.xy*aFrom.y;
+    m.y0 = aToTopLeft.y - m.yx*aFrom.x;
+  }
+  return m;
+}
 
 bool
 gfxUtils::GfxRectToIntRect(const gfxRect& aIn, nsIntRect* aOut)
 {
   *aOut = nsIntRect(int32_t(aIn.X()), int32_t(aIn.Y()),
   int32_t(aIn.Width()), int32_t(aIn.Height()));
   return gfxRect(aOut->x, aOut->y, aOut->width, aOut->height).IsEqualEdges(aIn);
 }
--- a/gfx/thebes/gfxUtils.h
+++ b/gfx/thebes/gfxUtils.h
@@ -82,16 +82,26 @@ public:
     static void PathFromRegionSnapped(gfxContext* aContext, const nsIntRegion& aRegion);
 
     /*
      * Convert image format to depth value
      */
     static int ImageFormatToDepth(gfxASurface::gfxImageFormat aFormat);
 
     /**
+     * Return the transform matrix that maps aFrom to the rectangle defined by
+     * aToTopLeft/aToTopRight/aToBottomRight. aFrom must be
+     * nonempty and the destination rectangle must be axis-aligned.
+     */
+    static gfxMatrix TransformRectToRect(const gfxRect& aFrom,
+                                         const gfxPoint& aToTopLeft,
+                                         const gfxPoint& aToTopRight,
+                                         const gfxPoint& aToBottomRight);
+
+    /**
      * If aIn can be represented exactly using an nsIntRect (i.e.
      * integer-aligned edges and coordinates in the int32_t range) then we
      * set aOut to that rectangle, otherwise return failure.
     */
     static bool GfxRectToIntRect(const gfxRect& aIn, nsIntRect* aOut);
 
     /**
      * Return the smallest power of kScaleResolution (2) greater than or equal to
--- a/layout/base/nsCSSRendering.cpp
+++ b/layout/base/nsCSSRendering.cpp
@@ -51,16 +51,17 @@
 #include "nsSVGEffects.h"
 #include "nsSVGIntegrationUtils.h"
 #include "gfxDrawable.h"
 #include "sampler.h"
 #include "nsCSSRenderingBorders.h"
 #include "mozilla/css/ImageLoader.h"
 #include "ImageContainer.h"
 #include "mozilla/Telemetry.h"
+#include "gfxUtils.h"
 
 using namespace mozilla;
 using namespace mozilla::css;
 
 static int gFrameTreeLockCount = 0;
 
 // To avoid storing this data on nsInlineFrame (bloat) and to avoid
 // recalculating this for each frame in a continuation (perf), hold
@@ -2072,45 +2073,16 @@ InterpolateColor(const gfxRGBA& aC1, con
 static nscoord
 FindTileStart(nscoord aDirtyCoord, nscoord aTilePos, nscoord aTileDim)
 {
   NS_ASSERTION(aTileDim > 0, "Non-positive tile dimension");
   double multiples = floor(double(aDirtyCoord - aTilePos)/aTileDim);
   return NSToCoordRound(multiples*aTileDim + aTilePos);
 }
 
-/**
- * Return the transform matrix that maps aFrom to the rectangle defined by
- * aToTopLeft/aToTopRight/aToBottomRight. The destination rectangle must be
- * nonempty and must be axis-aligned.
- */
-static gfxMatrix
-TransformRectToRect(const gfxRect& aFrom, const gfxPoint& aToTopLeft,
-                    const gfxPoint& aToTopRight, const gfxPoint& aToBottomRight)
-{
-  gfxMatrix m;
-  if (aToTopRight.y == aToTopLeft.y && aToTopRight.x == aToBottomRight.x) {
-    // Not a rotation, so xy and yx are zero
-    m.xy = m.yx = 0.0;
-    m.xx = (aToBottomRight.x - aToTopLeft.x)/aFrom.width;
-    m.yy = (aToBottomRight.y - aToTopLeft.y)/aFrom.height;
-    m.x0 = aToTopLeft.x - m.xx*aFrom.x;
-    m.y0 = aToTopLeft.y - m.yy*aFrom.y;
-  } else {
-    NS_ASSERTION(aToTopRight.y == aToBottomRight.y && aToTopRight.x == aToTopLeft.x,
-                 "Destination rectangle not axis-aligned");
-    m.xx = m.yy = 0.0;
-    m.xy = (aToBottomRight.x - aToTopLeft.x)/aFrom.height;
-    m.yx = (aToBottomRight.y - aToTopLeft.y)/aFrom.width;
-    m.x0 = aToTopLeft.x - m.xy*aFrom.y;
-    m.y0 = aToTopLeft.y - m.yx*aFrom.x;
-  }
-  return m;
-}
-
 void
 nsCSSRendering::PaintGradient(nsPresContext* aPresContext,
                               nsRenderingContext& aRenderingContext,
                               nsStyleGradient* aGradient,
                               const nsRect& aDirtyRect,
                               const nsRect& aOneCellArea,
                               const nsRect& aFillArea)
 {
@@ -2438,17 +2410,17 @@ nsCSSRendering::PaintGradient(nsPresCont
             snappedFillRectTopLeft.y == snappedFillRectBottomRight.y) {
           // Nothing to draw; avoid scaling by zero and other weirdness that
           // could put the context in an error state.
           continue;
         }
         // Set the context's transform to the transform that maps fillRect to
         // snappedFillRect. The part of the gradient that was going to
         // exactly fill fillRect will fill snappedFillRect instead.
-        gfxMatrix transform = TransformRectToRect(fillRect,
+        gfxMatrix transform = gfxUtils::TransformRectToRect(fillRect,
             snappedFillRectTopLeft, snappedFillRectTopRight,
             snappedFillRectBottomRight);
         ctx->SetMatrix(transform);
       }
       ctx->Rectangle(fillRect);
       ctx->Translate(tileRect.TopLeft());
       ctx->SetPattern(pattern->mPattern);
       ctx->Fill();