Bug 376124: Some rounding fixes related to a scrolling paint bug. r=vlad
authorsharparrow1@yahoo.com
Wed, 25 Jul 2007 10:19:40 -0700
changeset 3960 e9b9d4fef8c018c151aaf3739eb49e6e48860419
parent 3959 e200b1563539ae8347f5166a58b04f1cbb466387
child 3961 848a029c8596de0edf545041e776120c5d4b45c2
push id1
push userbsmedberg@mozilla.com
push dateThu, 20 Mar 2008 16:49:24 +0000
treeherdermozilla-central@61007906a1f8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvlad
bugs376124
milestone1.9a7pre
Bug 376124: Some rounding fixes related to a scrolling paint bug. r=vlad
gfx/src/thebes/nsThebesImage.cpp
--- a/gfx/src/thebes/nsThebesImage.cpp
+++ b/gfx/src/thebes/nsThebesImage.cpp
@@ -477,31 +477,19 @@ nsThebesImage::ThebesDrawTile(gfxContext
 
     // don't do anything if we have a transparent pixel source
     if (mSinglePixel && mSinglePixelColor.a == 0.0)
         return NS_OK;
 
     // so we can hold on to this for a bit longer; might not be needed
     nsRefPtr<gfxPattern> pat;
 
-    gfxMatrix savedCTM(thebesContext->CurrentMatrix());
-    PRBool doSnap = !(savedCTM.HasNonTranslation());
+    PRBool doSnap = !(thebesContext->CurrentMatrix().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);
-    }
-
     nsRefPtr<gfxASurface> tmpSurfaceGrip;
 
     if (mSinglePixel && !hasPadding) {
         thebesContext->SetColor(mSinglePixelColor);
     } else {
         nsRefPtr<gfxASurface> surface;
         PRInt32 width, height;
 
@@ -513,17 +501,16 @@ nsThebesImage::ThebesDrawTile(gfxContext
 
             // Reject over-wide or over-tall images.
             if (!AllowedImageSize(width, height))
                 return NS_ERROR_FAILURE;
 
             surface = new gfxImageSurface(gfxIntSize(width, height),
                                           gfxASurface::ImageFormatARGB32);
             if (!surface || surface->CairoStatus()) {
-                thebesContext->SetMatrix(savedCTM);
                 return NS_ERROR_OUT_OF_MEMORY;
             }
 
             tmpSurfaceGrip = surface;
 
             nsRefPtr<gfxContext> tmpContext = new gfxContext(surface);
             if (mSinglePixel) {
                 tmpContext->SetColor(mSinglePixelColor);
@@ -537,29 +524,24 @@ nsThebesImage::ThebesDrawTile(gfxContext
             width = mWidth;
             height = mHeight;
             surface = ThebesSurface();
         }
 
         gfxMatrix patMat;
         gfxPoint p0;
 
-        if (offset.x > width || offset.y > height) {
-            p0.x = - floor(fmod(offset.x, gfxFloat(width)) + 0.5);
-            p0.y = - floor(fmod(offset.y, gfxFloat(height)) + 0.5);
-        } else {
-            p0.x = - floor(offset.x + 0.5);
-            p0.y = - floor(offset.y + 0.5);
-        }
+        p0.x = - floor(offset.x + 0.5);
+        p0.y = - floor(offset.y + 0.5);
         // Scale factor to account for CSS pixels; note that the offset (and 
         // therefore p0) is in device pixels, while the width and height are in
         // CSS pixels.
-        gfxFloat scale = gfxFloat(nsIDeviceContext::AppUnitsPerCSSPixel()) / 
-                         gfxFloat(dx->AppUnitsPerDevPixel());
-        patMat.Scale(1.0 / scale, 1.0 / scale);
+        gfxFloat scale = gfxFloat(dx->AppUnitsPerDevPixel()) /
+                         gfxFloat(nsIDeviceContext::AppUnitsPerCSSPixel());
+        patMat.Scale(scale, scale);
         patMat.Translate(p0);
 
         pat = new gfxPattern(surface);
         pat->SetExtend(gfxPattern::EXTEND_REPEAT);
         pat->SetMatrix(patMat);
 
 #ifndef XP_MACOSX
         if (scale > 1.0) {
@@ -572,18 +554,16 @@ nsThebesImage::ThebesDrawTile(gfxContext
         thebesContext->SetPattern(pat);
     }
 
     thebesContext->NewPath();
     thebesContext->Rectangle(targetRect, doSnap);
     thebesContext->Fill();
 
     thebesContext->SetColor(gfxRGBA(0,0,0,0));
-    if (doSnap)
-        thebesContext->SetMatrix(savedCTM);
 
     return NS_OK;
 }
 
 /* This is only used by the GIF decoder, via gfxImageFrame::DrawTo */
 NS_IMETHODIMP
 nsThebesImage::DrawToImage(nsIImage* aDstImage, PRInt32 aDX, PRInt32 aDY, PRInt32 aDWidth, PRInt32 aDHeight)
 {