Commit 3716f5fb authored by bdakin's avatar bdakin
Browse files

Reviewed by Maciej.

        Fix for <rdar://problem/4616595> REGRESSION: Problems with world 
        clock widget clock hand motion on 9A211 + 4604574

        The second hand on the widget was jiggling because the rotation was 
        messing up the use of the affine transformation matrix while 
        rounding to pixel boundaries in device space. We are mainly 
        concerned with rounding to pixel boundaries with the scale in mind, 
        so this patch extracts the scale to device space from the matrix, 
        and rounds to pixel boundaries using only the scale. This doesn't 
        seem like it is a perfect solution, but it definitely solves the 
        immediate problem. We will probably need to re-address what should 
        happen to avoid pixel cracks with rotations at non-integral scale 
        factors. 

        * platform/cg/GraphicsContextCG.cpp:
        (WebCore::GraphicsContext::roundToDevicePixels):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@15470 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent a2d061c7
2006-07-16 Beth Dakin <bdakin@apple.com>
Reviewed by Maciej.
Fix for <rdar://problem/4616595> REGRESSION: Problems with world
clock widget clock hand motion on 9A211 + 4604574
The second hand on the widget was jiggling because the rotation was
messing up the use of the affine transformation matrix while
rounding to pixel boundaries in device space. We are mainly
concerned with rounding to pixel boundaries with the scale in mind,
so this patch extracts the scale to device space from the matrix,
and rounds to pixel boundaries using only the scale. This doesn't
seem like it is a perfect solution, but it definitely solves the
immediate problem. We will probably need to re-address what should
happen to avoid pixel cracks with rotations at non-integral scale
factors.
* platform/cg/GraphicsContextCG.cpp:
(WebCore::GraphicsContext::roundToDevicePixels):
2006-07-15 Darin Adler <darin@apple.com>
 
- fix mistake from fix for 8952 that was breaking layout tests
......
......@@ -636,11 +636,17 @@ void GraphicsContext::translate(const FloatSize& size)
FloatRect GraphicsContext::roundToDevicePixels(const FloatRect& rect)
{
// It's important to separately transform the two corners, as transforming the whole rect
// will grab bounding boxes, and so will enlarge the rect when there is any rotation or skew
// in the current transform
CGPoint deviceOrigin = CGContextConvertPointToDeviceSpace(platformContext(), rect.location());
CGPoint deviceLowerRight = CGContextConvertPointToDeviceSpace(platformContext(), rect.location() + rect.size());
// It is not enough just to round to pixels in device space. The rotation part of the
// affine transform matrix to device space can mess with this conversion if we have a
// rotating image like the hands of the world clock widget. We just need the scale, so
// we get the affine transform matrix and extract the scale.
CGAffineTransform deviceMatrix = CGContextGetUserSpaceToDeviceSpaceTransform(platformContext());
float deviceScaleX = sqrtf(deviceMatrix.a * deviceMatrix.a + deviceMatrix.b * deviceMatrix.b);
float deviceScaleY = sqrtf(deviceMatrix.c * deviceMatrix.c + deviceMatrix.d * deviceMatrix.d);
CGPoint deviceOrigin = CGPointMake(rect.x() * deviceScaleX, rect.y() * deviceScaleY);
CGPoint deviceLowerRight = CGPointMake((rect.x() + rect.width()) * deviceScaleX,
(rect.y() + rect.height()) * deviceScaleY);
deviceOrigin.x = roundf(deviceOrigin.x);
deviceOrigin.y = roundf(deviceOrigin.y);
......@@ -652,10 +658,9 @@ FloatRect GraphicsContext::roundToDevicePixels(const FloatRect& rect)
deviceLowerRight.y += 1;
if (deviceOrigin.x == deviceLowerRight.x && rect.width() != 0)
deviceLowerRight.x += 1;
FloatPoint roundedOrigin = CGContextConvertPointToUserSpace(platformContext(), deviceOrigin);
FloatPoint roundedLowerRight = CGContextConvertPointToUserSpace(platformContext(), deviceLowerRight);
FloatPoint roundedOrigin = FloatPoint(deviceOrigin.x / deviceScaleX, deviceOrigin.y / deviceScaleY);
FloatPoint roundedLowerRight = FloatPoint(deviceLowerRight.x / deviceScaleX, deviceLowerRight.y / deviceScaleY);
return FloatRect(roundedOrigin, roundedLowerRight - roundedOrigin);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment