summaryrefslogtreecommitdiff
path: root/vcl/inc/skia/gdiimpl.hxx
diff options
context:
space:
mode:
authorLuboš Luňák <l.lunak@collabora.com>2020-07-14 16:12:36 +0200
committerLuboš Luňák <l.lunak@collabora.com>2020-07-16 11:56:18 +0200
commit4bb931a488b8fe7a0b4961956252f667b683a630 (patch)
treefd261c23e12e13d9b73d29930661a0537bd4648b /vcl/inc/skia/gdiimpl.hxx
parentb0ac1fc0e434df76c44f283508e6da8ef7f61278 (diff)
use consistent Skia pixel position adjustments (tdf#134346)
What happens in tdf#134346 is that the same shape was drawn twice, once using drawPolyPolygon() and once as an outline using drawPolyLine(). Those had different offsets, so with AA enabled the tiny difference could be actually visible. Be more consistent with how the pixels are positioned in float coordinates. Change-Id: Id852fef70e7bd829ff0108a86d1ebee29c300e3a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/98745 Tested-by: Jenkins Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
Diffstat (limited to 'vcl/inc/skia/gdiimpl.hxx')
-rw-r--r--vcl/inc/skia/gdiimpl.hxx12
1 files changed, 7 insertions, 5 deletions
diff --git a/vcl/inc/skia/gdiimpl.hxx b/vcl/inc/skia/gdiimpl.hxx
index c98038807287..344509fe301e 100644
--- a/vcl/inc/skia/gdiimpl.hxx
+++ b/vcl/inc/skia/gdiimpl.hxx
@@ -272,12 +272,14 @@ protected:
sk_sp<SkImage> mergeCacheBitmaps(const SkiaSalBitmap& bitmap, const SkiaSalBitmap* alphaBitmap,
const Size targetSize);
- // When drawing using GPU, rounding errors may result in off-by-one errors,
+ // Skia uses floating point coordinates, so when we use integer coordinates, sometimes
+ // rounding results in off-by-one errors (down), especially when drawing using GPU,
// see https://bugs.chromium.org/p/skia/issues/detail?id=9611 . Compensate for
- // it by using centers of pixels (Skia uses float coordinates). In raster case
- // it seems better to not do this though.
- SkScalar toSkX(long x) const { return mIsGPU ? x + 0.5 : x; }
- SkScalar toSkY(long y) const { return mIsGPU ? y + 0.5 : y; }
+ // it by using centers of pixels. Using 0.5 may sometimes round up, so go with 0.495 .
+ static constexpr SkScalar toSkX(long x) { return x + 0.495; }
+ static constexpr SkScalar toSkY(long y) { return y + 0.495; }
+ // Value to add to be exactly in the middle of the pixel.
+ static constexpr SkScalar toSkXYFix = SkScalar(0.005);
template <typename charT, typename traits>
friend inline std::basic_ostream<charT, traits>&