Bug 995216 - Compensate for rounding error in DrawSurfaceWithTextureCoords. r=bas
authorChris Lord <chrislord.net@gmail.com>
Thu, 08 May 2014 11:39:31 +0100
changeset 190937 b422e91ad2c9843b977867bce21c5dcb424073a9
parent 190928 8a968bedfccac7559e6aea17a1640c6512a68c13
child 190938 615cffdf77cd7f5f61c0259c0999d7b45637c252
push idunknown
push userunknown
push dateunknown
Bug 995216 - Compensate for rounding error in DrawSurfaceWithTextureCoords. r=bas Calculating the source rect in DrawSurfaceWithTextureCoords can introduce small floating point errors that result in detectable blending errors. Round to pixels because we know the original values (the visible region) are pixel-aligned. This is also what CompositorOGL does.
--- a/gfx/layers/basic/BasicCompositor.cpp
+++ b/gfx/layers/basic/BasicCompositor.cpp
@@ -139,16 +139,21 @@ DrawSurfaceWithTextureCoords(DrawTarget 
                              SourceSurface *aMask,
                              const Matrix* aMaskTransform)
   // Convert aTextureCoords into aSource's coordinate space
   gfxRect sourceRect(aTextureCoords.x * aSource->GetSize().width,
                      aTextureCoords.y * aSource->GetSize().height,
                      aTextureCoords.width * aSource->GetSize().width,
                      aTextureCoords.height * aSource->GetSize().height);
+  // Floating point error can accumulate above and we know our visible region
+  // is integer-aligned, so round it out.
+  sourceRect.Round();
   // Compute a transform that maps sourceRect to aDestRect.
   gfxMatrix transform =
                                   gfxPoint(aDestRect.x, aDestRect.y),
                                   gfxPoint(aDestRect.XMost(), aDestRect.y),
                                   gfxPoint(aDestRect.XMost(), aDestRect.YMost()));
   Matrix matrix = ToMatrix(transform);