Title: [114548] trunk/Source/WebCore
Revision
114548
Author
[email protected]
Date
2012-04-18 13:05:10 -0700 (Wed, 18 Apr 2012)

Log Message

GraphicsContextCG's roundToDevicePixels should round even when there's no transform
https://bugs.webkit.org/show_bug.cgi?id=84191

Reviewed by Eric Seidel.

When painting with the identify transform, the roundToDevicePixels function in GraphicsContextCG
does an early return that simply returns the FloatRect that was passed in. This proved to be a
problem in sub-pixel layout, as we wouldn't adjust the paint rect for text underline, and it could
end up being more than one pixel wide. Adding a roundedIntRect method on FloatRect for the simple
short-circuit case.

No new tests. No change in behavior before switching to sub-pixel layout.

* platform/graphics/FloatRect.cpp:
(WebCore::roundedIntRect):
* platform/graphics/FloatRect.h:
* platform/graphics/cg/GraphicsContextCG.cpp:
(WebCore::GraphicsContext::roundToDevicePixels):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (114547 => 114548)


--- trunk/Source/WebCore/ChangeLog	2012-04-18 19:53:46 UTC (rev 114547)
+++ trunk/Source/WebCore/ChangeLog	2012-04-18 20:05:10 UTC (rev 114548)
@@ -1,3 +1,24 @@
+2012-04-18  Levi Weintraub  <[email protected]>
+
+        GraphicsContextCG's roundToDevicePixels should round even when there's no transform
+        https://bugs.webkit.org/show_bug.cgi?id=84191
+
+        Reviewed by Eric Seidel.
+
+        When painting with the identify transform, the roundToDevicePixels function in GraphicsContextCG
+        does an early return that simply returns the FloatRect that was passed in. This proved to be a
+        problem in sub-pixel layout, as we wouldn't adjust the paint rect for text underline, and it could
+        end up being more than one pixel wide. Adding a roundedIntRect method on FloatRect for the simple
+        short-circuit case.
+
+        No new tests. No change in behavior before switching to sub-pixel layout.
+
+        * platform/graphics/FloatRect.cpp:
+        (WebCore::roundedIntRect):
+        * platform/graphics/FloatRect.h:
+        * platform/graphics/cg/GraphicsContextCG.cpp:
+        (WebCore::GraphicsContext::roundToDevicePixels):
+
 2012-04-18  Keishi Hattori  <[email protected]>
 
         [chromium] Turn on ENABLE_DATALIST for chromium

Modified: trunk/Source/WebCore/platform/graphics/FloatRect.cpp (114547 => 114548)


--- trunk/Source/WebCore/platform/graphics/FloatRect.cpp	2012-04-18 19:53:46 UTC (rev 114547)
+++ trunk/Source/WebCore/platform/graphics/FloatRect.cpp	2012-04-18 20:05:10 UTC (rev 114548)
@@ -236,6 +236,11 @@
     return IntRect(x, y, width, height);
 }
 
+IntRect roundedIntRect(const FloatRect& rect)
+{
+    return IntRect(roundedIntPoint(rect.location()), roundedIntSize(rect.size()));
+}
+
 FloatRect mapRect(const FloatRect& r, const FloatRect& srcRect, const FloatRect& destRect)
 {
     if (srcRect.width() == 0 || srcRect.height() == 0)

Modified: trunk/Source/WebCore/platform/graphics/FloatRect.h (114547 => 114548)


--- trunk/Source/WebCore/platform/graphics/FloatRect.h	2012-04-18 19:53:46 UTC (rev 114547)
+++ trunk/Source/WebCore/platform/graphics/FloatRect.h	2012-04-18 20:05:10 UTC (rev 114548)
@@ -288,6 +288,8 @@
 // Returns a valid IntRect contained within the given FloatRect.
 IntRect enclosedIntRect(const FloatRect&);
 
+IntRect roundedIntRect(const FloatRect&);
+
 // Map rect r from srcRect to an equivalent rect in destRect.
 FloatRect mapRect(const FloatRect& r, const FloatRect& srcRect, const FloatRect& destRect);
 

Modified: trunk/Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp (114547 => 114548)


--- trunk/Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp	2012-04-18 19:53:46 UTC (rev 114547)
+++ trunk/Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp	2012-04-18 20:05:10 UTC (rev 114548)
@@ -1313,12 +1313,12 @@
     // we get the affine transform matrix and extract the scale.
 
     if (m_data->m_userToDeviceTransformKnownToBeIdentity)
-        return rect;
+        return roundedIntRect(rect);
 
     CGAffineTransform deviceMatrix = CGContextGetUserSpaceToDeviceSpaceTransform(platformContext());
     if (CGAffineTransformIsIdentity(deviceMatrix)) {
         m_data->m_userToDeviceTransformKnownToBeIdentity = true;
-        return rect;
+        return roundedIntRect(rect);
     }
 
     float deviceScaleX = sqrtf(deviceMatrix.a * deviceMatrix.a + deviceMatrix.b * deviceMatrix.b);
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to