From 0edb21df154cd2469ba91ea95c8c6464d1140c8d Mon Sep 17 00:00:00 2001 From: Louai Al-Khanji Date: Tue, 29 Apr 2014 16:14:19 +0300 Subject: Direct2D QPA: Pixel-align aliased drawing Aliased drawing has so far not been perfectly pixel aligned, resulting in less than stellar output in some instances. Although a little hacky, adding 0.5 to all coordinates when in aliased mode fixes things up nicely. There doesn't appear to be a better way to get d2d to cooperate as we would like it to. Change-Id: I10ee494d2f576bfd0eca6d4429095a3726c0bf14 Reviewed-by: Risto Avila Reviewed-by: Andrew Knight --- src/plugins/platforms/direct2d/qwindowsdirect2dpaintengine.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/plugins/platforms/direct2d/qwindowsdirect2dpaintengine.cpp b/src/plugins/platforms/direct2d/qwindowsdirect2dpaintengine.cpp index 8d775e5a9d..0c3618132d 100644 --- a/src/plugins/platforms/direct2d/qwindowsdirect2dpaintengine.cpp +++ b/src/plugins/platforms/direct2d/qwindowsdirect2dpaintengine.cpp @@ -89,6 +89,11 @@ enum ClipType { LayerClip }; +// Since d2d is a float-based system we need to be able to snap our drawing to whole pixels. +// Applying the magical aliasing offset to coordinates will do so, just make sure that +// aliased painting is turned on on the d2d device context. +static const qreal MAGICAL_ALIASING_OFFSET = 0.5; + #define D2D_TAG(tag) d->dc()->SetTags(tag, tag) Q_GUI_EXPORT QImage qt_imageForBrush(int brushStyle, bool invert); @@ -184,8 +189,11 @@ public: private: D2D1_POINT_2F adjusted(const QPointF &point) { + static const QPointF adjustment(MAGICAL_ALIASING_OFFSET, + MAGICAL_ALIASING_OFFSET); + if (m_roundCoordinates) - return to_d2d_point_2f(point.toPoint()); + return to_d2d_point_2f(point + adjustment); else return to_d2d_point_2f(point); } -- cgit v1.2.3