diff --git a/gfx/src/thebes/nsThebesImage.cpp b/gfx/src/thebes/nsThebesImage.cpp index abd6570fe0f..95c759c8e7a 100644 --- a/gfx/src/thebes/nsThebesImage.cpp +++ b/gfx/src/thebes/nsThebesImage.cpp @@ -340,6 +340,9 @@ nsThebesImage::Draw(nsIRenderingContext &aContext, nsIDrawingSurface *aSurface, mDecoded.x, mDecoded.y, mDecoded.width, mDecoded.height); #endif + gfxMatrix savedCTM(ctx->CurrentMatrix()); + PRBool doSnap = !(savedCTM.HasNonTranslation()); + if (mSinglePixel) { // if a == 0, it's a noop if (mSinglePixelColor.a == 0.0) @@ -353,6 +356,14 @@ nsThebesImage::Draw(nsIRenderingContext &aContext, nsIDrawingSurface *aSurface, return NS_OK; } + // See comment inside ThebesDrawTile + if (doSnap) { + gfxMatrix roundedCTM(savedCTM); + roundedCTM.x0() = ::floor(roundedCTM.x0() + 0.5); + roundedCTM.y0() = ::floor(roundedCTM.y0() + 0.5); + ctx->SetMatrix(roundedCTM); + } + gfxFloat xscale = gfxFloat(aDWidth) / aSWidth; gfxFloat yscale = gfxFloat(aDHeight) / aSHeight; @@ -377,13 +388,22 @@ nsThebesImage::Draw(nsIRenderingContext &aContext, nsIDrawingSurface *aSurface, mat.Translate(gfxPoint(aSX, aSY)); mat.Scale(1.0/xscale, 1.0/yscale); + /* Translate the start point of the image (the aSX,aSY point) + * to coincide with the destination rectangle origin + */ + mat.Translate(gfxPoint(-aDX, -aDY)); + nsRefPtr pat = new gfxPattern(ThebesSurface()); pat->SetMatrix(mat); ctx->NewPath(); - ctx->PixelSnappedRectangleAndSetPattern(dr, pat); + ctx->SetPattern(pat); + ctx->Rectangle(dr, doSnap); ctx->Fill(); + if (doSnap) + ctx->SetMatrix(savedCTM); + return NS_OK; } @@ -404,9 +424,21 @@ nsThebesImage::ThebesDrawTile(gfxContext *thebesContext, // so we can hold on to this for a bit longer; might not be needed nsRefPtr pat; - PRBool doSnap = !(thebesContext->CurrentMatrix().HasNonTranslation()); + gfxMatrix savedCTM(thebesContext->CurrentMatrix()); + PRBool doSnap = !(savedCTM.HasNonTranslation()); PRBool hasPadding = ((xPadding != 0) || (yPadding != 0)); + // If we need to snap, we need to round the CTM as well; + // otherwise, we may have non-integer pixels in the translation, + // which will affect the rendering of images (since the current CTM + // is what's used at the time of a SetPattern call). + if (doSnap) { + gfxMatrix roundedCTM(savedCTM); + roundedCTM.x0() = ::floor(roundedCTM.x0() + 0.5); + roundedCTM.y0() = ::floor(roundedCTM.y0() + 0.5); + thebesContext->SetMatrix(roundedCTM); + } + if (mSinglePixel && !hasPadding) { thebesContext->SetColor(mSinglePixelColor); } else { @@ -460,6 +492,9 @@ nsThebesImage::ThebesDrawTile(gfxContext *thebesContext, thebesContext->Rectangle(targetRect, doSnap); thebesContext->Fill(); + if (doSnap) + thebesContext->SetMatrix(savedCTM); + return NS_OK; }