mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-03-03 15:26:07 +00:00
Bug 663776. Part 2: Move TransformRectToRect from nsCSSRendering to gfxUtils. r=mattwoodrow
This commit is contained in:
parent
70681911f9
commit
5bac7c566d
@ -619,6 +619,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)
|
||||
|
@ -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
|
||||
|
@ -52,6 +52,7 @@
|
||||
#include "mozilla/Types.h"
|
||||
#include <ctime>
|
||||
#include <cstdlib> // for std::abs(int/long)
|
||||
#include "gfxUtils.h"
|
||||
#include <cmath> // for std::abs(float/double)
|
||||
|
||||
using namespace mozilla;
|
||||
@ -2074,35 +2075,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,
|
||||
@ -2440,7 +2412,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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user