Source/WebCore/ChangeLog

 12014-02-01 Zalan Bujtas <zalan@apple.com>
 2
 3 Subpixel rendering: Introduce device pixel snapping helper functions.
 4 https://bugs.webkit.org/show_bug.cgi?id=128049
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 These functions help device pixel snapping during painting. They follow the logic of
 9 the corresponding pixelSnappedInt* functions.
 10
 11 No change in functionality.
 12
 13 * platform/LayoutUnit.h:
 14 (WebCore::roundToDevicePixel):
 15 (WebCore::floorToDevicePixel):
 16 (WebCore::snapSizeToPixel):
 17 (WebCore::snapSizeToDevicePixel):
 18 * platform/graphics/GraphicsContext.cpp:
 19 (WebCore::GraphicsContext::GraphicsContext):
 20 * platform/graphics/GraphicsContext.h:
 21 (WebCore::GraphicsContext::paintPixelRatio):
 22 * platform/graphics/LayoutRect.h:
 23 (WebCore::pixelSnappedForPainting):
 24 * platform/graphics/cg/GraphicsContextCG.cpp:
 25 (WebCore::GraphicsContext::platformInit): ASSERT against uniform scaling. Apparently
 26 scaleX = 1, scaleY = -1 is a valid scaling context for ImageBuffer.
 27
1282014-02-01 Alexey Proskuryakov <ap@apple.com>
229
330 Update WebCrypto JWK mapping to use key_ops

Source/WebCore/platform/LayoutUnit.h

@@inline float& operator/=(float& a, const LayoutUnit& b)
919919 return a;
920920}
921921
922 inline int snapSizeToPixel(LayoutUnit size, LayoutUnit location)
923 {
924  LayoutUnit fraction = location.fraction();
925  return (fraction + size).round() - fraction.round();
926 }
927 
928922inline int roundToInt(LayoutUnit value)
929923{
930924 return value.round();

@@inline int floorToInt(LayoutUnit value)
935929 return value.floor();
936930}
937931
 932inline float roundToDevicePixel(LayoutUnit value, float devicePixelRatio)
 933{
 934 return round((value.rawValue() * devicePixelRatio) / kEffectiveFixedPointDenominator) / devicePixelRatio;
 935}
 936
 937inline float floorToDevicePixel(LayoutUnit value, float devicePixelRatio)
 938{
 939 return floor((value.rawValue() * devicePixelRatio) / kEffectiveFixedPointDenominator) / devicePixelRatio;
 940}
 941
 942inline int snapSizeToPixel(LayoutUnit size, LayoutUnit location)
 943{
 944 LayoutUnit fraction = location.fraction();
 945 return (fraction + size).round() - fraction.round();
 946}
 947
 948inline float snapSizeToDevicePixel(LayoutUnit size, LayoutUnit location, float devicePixelRatio)
 949{
 950 LayoutUnit fraction = location.fraction();
 951 return roundToDevicePixel(fraction + size, devicePixelRatio) - roundToDevicePixel(fraction, devicePixelRatio);
 952}
 953
938954inline LayoutUnit roundedLayoutUnit(float value)
939955{
940956#if ENABLE(SUBPIXEL_LAYOUT)

Source/WebCore/platform/graphics/GraphicsContext.cpp

@@private:
8080GraphicsContext::GraphicsContext(PlatformGraphicsContext* platformGraphicsContext)
8181 : m_updatingControlTints(false)
8282 , m_transparencyCount(0)
 83 , m_paintPixelRatio(1)
8384{
8485 platformInit(platformGraphicsContext);
8586}

@@GraphicsContext::GraphicsContext(PlatformGraphicsContext* platformGraphicsContex
8788GraphicsContext::GraphicsContext(PlatformGraphicsContext* platformGraphicsContext, bool shouldUseContextColors)
8889 : m_updatingControlTints(false)
8990 , m_transparencyCount(0)
 91 , m_paintPixelRatio(2)
9092{
9193 platformInit(platformGraphicsContext, shouldUseContextColors);
9294}

Source/WebCore/platform/graphics/GraphicsContext.h

@@namespace WebCore {
444444 enum IncludeDeviceScale { DefinitelyIncludeDeviceScale, PossiblyIncludeDeviceScale };
445445 AffineTransform getCTM(IncludeDeviceScale includeScale = PossiblyIncludeDeviceScale) const;
446446
 447 float paintPixelRatio() const { return m_paintPixelRatio; }
 448
447449#if ENABLE(3D_RENDERING) && USE(TEXTURE_MAPPER)
448450 // This is needed when using accelerated-compositing in software mode, like in TextureMapper.
449451 void concat3DTransform(const TransformationMatrix&);

@@namespace WebCore {
580582 Vector<GraphicsContextState> m_stack;
581583 bool m_updatingControlTints;
582584 unsigned m_transparencyCount;
 585 float m_paintPixelRatio;
583586 };
584587
585588 class GraphicsContextStateSaver {

Source/WebCore/platform/graphics/LayoutRect.h

@@inline IntRect pixelSnappedIntRect(LayoutPoint location, LayoutSize size)
231231 return IntRect(roundedIntPoint(location), pixelSnappedIntSize(size, location));
232232}
233233
 234inline FloatRect pixelSnappedForPainting(const LayoutRect& rect, float devicePixelRatio)
 235{
 236#if ENABLE(SUBPIXEL_LAYOUT)
 237 return FloatRect(roundToDevicePixel(rect.x(), devicePixelRatio), roundToDevicePixel(rect.y(), devicePixelRatio),
 238 snapSizeToDevicePixel(rect.width(), rect.x(), devicePixelRatio), snapSizeToDevicePixel(rect.height(), rect.y(), devicePixelRatio));
 239#else
 240 return FloatRect(rect);
 241#endif
 242}
 243
 244inline FloatRect pixelSnappedForPainting(LayoutUnit x, LayoutUnit y, LayoutUnit width, LayoutUnit height, float devicePixelRatio)
 245{
 246 return pixelSnappedForPainting(LayoutRect(x, y, width, height), devicePixelRatio);
 247}
 248
234249} // namespace WebCore
235250
236251#endif // LayoutRect_h

Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp

@@void GraphicsContext::platformInit(CGContextRef cgContext, bool shouldUseContext
138138 setPlatformFillColor(fillColor(), fillColorSpace());
139139 setPlatformStrokeColor(strokeColor(), strokeColorSpace());
140140 }
 141
 142 CGAffineTransform baseDeviceMatrix = CGContextGetUserSpaceToDeviceSpaceTransform(cgContext);
 143 ASSERT(abs(baseDeviceMatrix.a) == abs(baseDeviceMatrix.d));
 144 m_paintPixelRatio = baseDeviceMatrix.a;
141145}
142146
143147void GraphicsContext::platformDestroy()