Account for non-pixel-aligned current transforms when snapping to pixel coordinates. b=369882 r=vlad

This commit is contained in:
dbaron@dbaron.org 2007-05-14 22:15:45 -07:00
parent 0b1ce291e2
commit b065ff84ea
6 changed files with 39 additions and 34 deletions

View File

@ -346,9 +346,6 @@ nsThebesImage::Draw(nsIRenderingContext &aContext,
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)
@ -362,14 +359,6 @@ nsThebesImage::Draw(nsIRenderingContext &aContext,
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 = aDestRect.size.width / aSourceRect.size.width;
gfxFloat yscale = aDestRect.size.height / aSourceRect.size.height;
@ -410,12 +399,9 @@ nsThebesImage::Draw(nsIRenderingContext &aContext,
ctx->NewPath();
ctx->SetPattern(pat);
ctx->Rectangle(destRect, doSnap);
ctx->Rectangle(destRect);
ctx->Fill();
if (doSnap)
ctx->SetMatrix(savedCTM);
return NS_OK;
}

View File

@ -63,6 +63,7 @@
#include "gfxIImageFrame.h"
#include "imgIContainer.h"
#include "gfxRect.h"
#include "gfxContext.h"
#include "nsIImage.h"
#include "nsIInterfaceRequestorUtils.h"
#include "nsCSSRendering.h"
@ -2043,6 +2044,10 @@ nsLayoutUtils::DrawImage(nsIRenderingContext* aRenderingContext,
aRenderingContext->GetDeviceContext(*getter_AddRefs(dc));
PRInt32 d2a = dc->AppUnitsPerDevPixel();
nsRefPtr<gfxContext> ctx = NS_STATIC_CAST(gfxContext*,
aRenderingContext->GetNativeGraphicData(
nsIRenderingContext::NATIVE_THEBES_CONTEXT));
// the dest rect is affected by the current transform; that'll be
// handled by Image::Draw(), when we actually set up the rectangle.
@ -2050,15 +2055,12 @@ nsLayoutUtils::DrawImage(nsIRenderingContext* aRenderingContext,
// pixel, but then convert back to gfxFloats for the rest of the math.
gfxRect pxDest;
{
nsIntRect r;
r.x = NSAppUnitsToIntPixels(aDestRect.x, d2a);
r.y = NSAppUnitsToIntPixels(aDestRect.y, d2a);
r.width = NSAppUnitsToIntPixels(aDestRect.XMost(), d2a) - r.x;
r.height = NSAppUnitsToIntPixels(aDestRect.YMost(), d2a) - r.y;
pxDest.pos.x = gfxFloat(r.x);
pxDest.pos.y = gfxFloat(r.y);
pxDest.size.width = gfxFloat(r.width);
pxDest.size.height = gfxFloat(r.height);
pxDest.pos.x = NSAppUnitsToFloatPixels(aDestRect.x, d2a);
pxDest.pos.y = NSAppUnitsToFloatPixels(aDestRect.y, d2a);
pxDest.size.width = NSAppUnitsToFloatPixels(aDestRect.width, d2a);
pxDest.size.height = NSAppUnitsToFloatPixels(aDestRect.height, d2a);
if (ctx->UserToDevicePixelSnapped(pxDest))
pxDest = ctx->DeviceToUser(pxDest);
}
// And likewise for the dirty rect. (Is should be OK to round to
@ -2067,15 +2069,12 @@ nsLayoutUtils::DrawImage(nsIRenderingContext* aRenderingContext,
// been intersected with, and we should be rounding those consistently.)
gfxRect pxDirty;
{
nsIntRect r;
r.x = NSAppUnitsToIntPixels(dirtyRect.x, d2a);
r.y = NSAppUnitsToIntPixels(dirtyRect.y, d2a);
r.width = NSAppUnitsToIntPixels(dirtyRect.XMost(), d2a) - r.x;
r.height = NSAppUnitsToIntPixels(dirtyRect.YMost(), d2a) - r.y;
pxDirty.pos.x = gfxFloat(r.x);
pxDirty.pos.y = gfxFloat(r.y);
pxDirty.size.width = gfxFloat(r.width);
pxDirty.size.height = gfxFloat(r.height);
pxDirty.pos.x = NSAppUnitsToFloatPixels(dirtyRect.x, d2a);
pxDirty.pos.y = NSAppUnitsToFloatPixels(dirtyRect.y, d2a);
pxDirty.size.width = NSAppUnitsToFloatPixels(dirtyRect.width, d2a);
pxDirty.size.height = NSAppUnitsToFloatPixels(dirtyRect.height, d2a);
if (ctx->UserToDevicePixelSnapped(pxDirty))
pxDirty = ctx->DeviceToUser(pxDirty);
}
// Reduce the src rect to what's needed for the dirty rect.

View File

@ -0,0 +1,9 @@
<?xml version="1.0"?>
<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<hbox height="18" align="center">
<deck>
<image width="16" height="16"
src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAADElEQVR42mP4z8AAAAMBAQD3A0FDAAAAAElFTkSuQmCC"/>
</deck>
</hbox>
</window>

View File

@ -0,0 +1,10 @@
<?xml version="1.0"?>
<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<hbox height="17" align="center">
<deck>
<image width="16" height="16"
style="background:blue"
src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAADElEQVR42mP4z8AAAAMBAQD3A0FDAAAAAElFTkSuQmCC"/>
</deck>
</hbox>
</window>

View File

@ -209,6 +209,7 @@ fails == 368020-4.html 368020-4-ref.html # bug 368085
fails == 368504-1.html 368504-1-ref.html # bug 368504
== 368622-1.html 368622-1-ref.html
== 368622-1.html 368622-1-ref.html
== 369882.xul 369882-ref.xul
== 370422-1.html 370422-1-ref.html
== 370586-1.xhtml 370586-1-ref.xhtml
== 370629-1.html 370629-1-ref.html

View File

@ -138,7 +138,7 @@ random == image-width-left-6.html image-width-6.html
== offscreen-background-color-size-5.html offscreen-10-ref.html
== offscreen-background-color-size-6.html offscreen-10-ref.html
== offscreen-image-pos-4.html offscreen-0-ref.html
fails-if(MOZ_WIDGET_TOOLKIT!="cocoa") == offscreen-image-pos-5.html offscreen-10-ref.html # bug 368280
== offscreen-image-pos-5.html offscreen-10-ref.html
== offscreen-image-pos-6.html offscreen-10-ref.html
random == offscreen-image-size-4.html offscreen-0-ref.html # bug 371316
random == offscreen-image-size-5.html offscreen-10-ref.html # bug 371316