Bug 663776. Part 2: Move TransformRectToRect from nsCSSRendering to gfxUtils. r=mattwoodrow

This commit is contained in:
Robert O'Callahan 2012-12-07 12:58:13 +13:00
parent 7b004d061c
commit 5d03c1907d
3 changed files with 35 additions and 30 deletions

View File

@ -592,6 +592,29 @@ 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)

View File

@ -86,6 +86,16 @@ public:
*/
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

View File

@ -56,6 +56,7 @@
#include "mozilla/css/ImageLoader.h"
#include "ImageContainer.h"
#include "mozilla/Telemetry.h"
#include "gfxUtils.h"
using namespace mozilla;
using namespace mozilla::css;
@ -2077,35 +2078,6 @@ FindTileStart(nscoord aDirtyCoord, nscoord aTilePos, nscoord 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,
@ -2443,7 +2415,7 @@ nsCSSRendering::PaintGradient(nsPresContext* aPresContext,
// 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);