Title: [163265] trunk/Source/WebCore
Revision
163265
Author
[email protected]
Date
2014-02-02 10:38:45 -0800 (Sun, 02 Feb 2014)

Log Message

Subpixel rendering: Introduce device pixel snapping helper functions.
https://bugs.webkit.org/show_bug.cgi?id=128049

Reviewed by Simon Fraser.

These functions help device pixel snapping during painting. They follow the logic of
the corresponding pixelSnappedInt* functions.

No change in functionality.

* platform/LayoutUnit.h:
(WebCore::roundToDevicePixel):
(WebCore::floorToDevicePixel):
(WebCore::snapSizeToPixel):
(WebCore::snapSizeToDevicePixel):
* platform/graphics/GraphicsContext.cpp:
(WebCore::GraphicsContext::GraphicsContext):
* platform/graphics/GraphicsContext.h:
(WebCore::GraphicsContext::pixelSnappingFactor):
* platform/graphics/LayoutRect.h:
(WebCore::pixelSnappedForPainting):
* platform/graphics/cg/GraphicsContextCG.cpp:
(WebCore::GraphicsContext::platformInit):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (163264 => 163265)


--- trunk/Source/WebCore/ChangeLog	2014-02-02 17:44:48 UTC (rev 163264)
+++ trunk/Source/WebCore/ChangeLog	2014-02-02 18:38:45 UTC (rev 163265)
@@ -1,5 +1,31 @@
 2014-02-02  Zalan Bujtas  <[email protected]>
 
+        Subpixel rendering: Introduce device pixel snapping helper functions.
+        https://bugs.webkit.org/show_bug.cgi?id=128049
+
+        Reviewed by Simon Fraser.
+
+        These functions help device pixel snapping during painting. They follow the logic of
+        the corresponding pixelSnappedInt* functions.
+
+        No change in functionality.
+
+        * platform/LayoutUnit.h:
+        (WebCore::roundToDevicePixel):
+        (WebCore::floorToDevicePixel):
+        (WebCore::snapSizeToPixel):
+        (WebCore::snapSizeToDevicePixel):
+        * platform/graphics/GraphicsContext.cpp:
+        (WebCore::GraphicsContext::GraphicsContext):
+        * platform/graphics/GraphicsContext.h:
+        (WebCore::GraphicsContext::pixelSnappingFactor):
+        * platform/graphics/LayoutRect.h:
+        (WebCore::pixelSnappedForPainting):
+        * platform/graphics/cg/GraphicsContextCG.cpp:
+        (WebCore::GraphicsContext::platformInit):
+
+2014-02-02  Zalan Bujtas  <[email protected]>
+
         Floor thickness and length after switching from int to float.
         https://bugs.webkit.org/show_bug.cgi?id=128071
 

Modified: trunk/Source/WebCore/platform/LayoutUnit.h (163264 => 163265)


--- trunk/Source/WebCore/platform/LayoutUnit.h	2014-02-02 17:44:48 UTC (rev 163264)
+++ trunk/Source/WebCore/platform/LayoutUnit.h	2014-02-02 18:38:45 UTC (rev 163265)
@@ -935,6 +935,22 @@
     return value.floor();
 }
 
+inline float roundToDevicePixel(LayoutUnit value, float pixelSnappingFactor)
+{
+    return round((value.rawValue() * pixelSnappingFactor) / kEffectiveFixedPointDenominator) / pixelSnappingFactor;
+}
+
+inline float floorToDevicePixel(LayoutUnit value, float pixelSnappingFactor)
+{
+    return floor((value.rawValue() * pixelSnappingFactor) / kEffectiveFixedPointDenominator) / pixelSnappingFactor;
+}
+
+inline float snapSizeToDevicePixel(LayoutUnit size, LayoutUnit location, float pixelSnappingFactor)
+{
+    LayoutUnit fraction = location.fraction();
+    return roundToDevicePixel(fraction + size, pixelSnappingFactor) - roundToDevicePixel(fraction, pixelSnappingFactor);
+}
+
 inline LayoutUnit roundedLayoutUnit(float value)
 {
 #if ENABLE(SUBPIXEL_LAYOUT)

Modified: trunk/Source/WebCore/platform/graphics/GraphicsContext.cpp (163264 => 163265)


--- trunk/Source/WebCore/platform/graphics/GraphicsContext.cpp	2014-02-02 17:44:48 UTC (rev 163264)
+++ trunk/Source/WebCore/platform/graphics/GraphicsContext.cpp	2014-02-02 18:38:45 UTC (rev 163265)
@@ -80,6 +80,7 @@
 GraphicsContext::GraphicsContext(PlatformGraphicsContext* platformGraphicsContext)
     : m_updatingControlTints(false)
     , m_transparencyCount(0)
+    , m_pixelSnappingFactor(1)
 {
     platformInit(platformGraphicsContext);
 }
@@ -87,6 +88,7 @@
 GraphicsContext::GraphicsContext(PlatformGraphicsContext* platformGraphicsContext, bool shouldUseContextColors)
     : m_updatingControlTints(false)
     , m_transparencyCount(0)
+    , m_pixelSnappingFactor(1)
 {
     platformInit(platformGraphicsContext, shouldUseContextColors);
 }

Modified: trunk/Source/WebCore/platform/graphics/GraphicsContext.h (163264 => 163265)


--- trunk/Source/WebCore/platform/graphics/GraphicsContext.h	2014-02-02 17:44:48 UTC (rev 163264)
+++ trunk/Source/WebCore/platform/graphics/GraphicsContext.h	2014-02-02 18:38:45 UTC (rev 163265)
@@ -444,6 +444,8 @@
         enum IncludeDeviceScale { DefinitelyIncludeDeviceScale, PossiblyIncludeDeviceScale };
         AffineTransform getCTM(IncludeDeviceScale includeScale = PossiblyIncludeDeviceScale) const;
 
+        float pixelSnappingFactor() const { return m_pixelSnappingFactor; }
+
 #if ENABLE(3D_RENDERING) && USE(TEXTURE_MAPPER)
         // This is needed when using accelerated-compositing in software mode, like in TextureMapper.
         void concat3DTransform(const TransformationMatrix&);
@@ -580,6 +582,7 @@
         Vector<GraphicsContextState> m_stack;
         bool m_updatingControlTints;
         unsigned m_transparencyCount;
+        float m_pixelSnappingFactor;
     };
 
     class GraphicsContextStateSaver {

Modified: trunk/Source/WebCore/platform/graphics/LayoutRect.h (163264 => 163265)


--- trunk/Source/WebCore/platform/graphics/LayoutRect.h	2014-02-02 17:44:48 UTC (rev 163264)
+++ trunk/Source/WebCore/platform/graphics/LayoutRect.h	2014-02-02 18:38:45 UTC (rev 163265)
@@ -231,6 +231,22 @@
     return IntRect(roundedIntPoint(location), pixelSnappedIntSize(size, location));
 }
 
+inline FloatRect pixelSnappedForPainting(const LayoutRect& rect, float pixelSnappingFactor)
+{
+#if ENABLE(SUBPIXEL_LAYOUT)
+    return FloatRect(roundToDevicePixel(rect.x(), pixelSnappingFactor), roundToDevicePixel(rect.y(), pixelSnappingFactor),
+        snapSizeToDevicePixel(rect.width(), rect.x(), pixelSnappingFactor), snapSizeToDevicePixel(rect.height(), rect.y(), pixelSnappingFactor));
+#else
+    UNUSED_PARAM(pixelSnappingFactor);
+    return FloatRect(rect);
+#endif
+}
+
+inline FloatRect pixelSnappedForPainting(LayoutUnit x, LayoutUnit y, LayoutUnit width, LayoutUnit height, float pixelSnappingFactor)
+{
+    return pixelSnappedForPainting(LayoutRect(x, y, width, height), pixelSnappingFactor);
+}
+
 } // namespace WebCore
 
 #endif // LayoutRect_h

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


--- trunk/Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp	2014-02-02 17:44:48 UTC (rev 163264)
+++ trunk/Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp	2014-02-02 18:38:45 UTC (rev 163265)
@@ -138,6 +138,10 @@
         setPlatformFillColor(fillColor(), fillColorSpace());
         setPlatformStrokeColor(strokeColor(), strokeColorSpace());
     }
+
+    CGAffineTransform baseDeviceMatrix = CGContextGetUserSpaceToDeviceSpaceTransform(cgContext);
+    ASSERT(abs(baseDeviceMatrix.a) == abs(baseDeviceMatrix.d));
+    m_pixelSnappingFactor = baseDeviceMatrix.a;
 }
 
 void GraphicsContext::platformDestroy()
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to