diff options
author | fmalita <fmalita@chromium.org> | 2015-12-18 07:59:47 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-12-18 07:59:47 -0800 |
commit | 5ae7fdcc3d7712da3193c39a751e88b092aa82db (patch) | |
tree | 85ac81312e756d57b45759feacc33e390ae7666c /src/core/SkBitmapProcState.h | |
parent | a11e5fce33f8d6f38c3324d639ca76ddf12598ba (diff) |
Repeating SkBitmapProcState rounding bias
Observe the bias in repeat matrix procs also.
Introduce a utility class to handle device space -> bitmap space
mapping.
BUG=skia:4680,skia:4649
R=reed@google.com
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1529833003
Review URL: https://codereview.chromium.org/1529833003
Diffstat (limited to 'src/core/SkBitmapProcState.h')
-rw-r--r-- | src/core/SkBitmapProcState.h | 39 |
1 files changed, 28 insertions, 11 deletions
diff --git a/src/core/SkBitmapProcState.h b/src/core/SkBitmapProcState.h index 4d7e7f32dc..bd2a344eca 100644 --- a/src/core/SkBitmapProcState.h +++ b/src/core/SkBitmapProcState.h @@ -25,17 +25,6 @@ typedef SkFixed3232 SkFractionalInt; #define SkFixedToFractionalInt(x) SkFixedToFixed3232(x) #define SkFractionalIntToInt(x) SkFixed3232ToInt(x) -// Applying a fixed point (SkFixed, SkFractionalInt) epsilon bias ensures that the inverse-mapped -// bitmap coordinates are rounded consistently WRT geometry. Note that we only have to do this -// when the scale is positive - for negative scales we're already rounding in the right direction. -static inline int bitmap_sampler_inv_bias(SkScalar scale) { -#ifndef SK_SUPPORT_LEGACY_BITMAP_SAMPLER_BIAS - return -(scale > 0); -#else - return 0; -#endif -} - class SkPaint; struct SkBitmapProcState { @@ -210,4 +199,32 @@ void S32_D16_filter_DX(const SkBitmapProcState& s, void S32_D16_filter_DXDY(const SkBitmapProcState& s, const uint32_t* xy, int count, uint16_t* colors); +// Helper class for mapping the middle of pixel (x, y) into SkFixed bitmap space. +class SkBitmapProcStateAutoMapper { +public: + SkBitmapProcStateAutoMapper(const SkBitmapProcState& s, int x, int y) { + SkPoint pt; + s.fInvProc(s.fInvMatrix, + SkIntToScalar(x) + SK_ScalarHalf, + SkIntToScalar(y) + SK_ScalarHalf, &pt); + +#ifndef SK_SUPPORT_LEGACY_BITMAP_SAMPLER_BIAS + // SkFixed epsilon bias to ensure inverse-mapped bitmap coordinates are rounded + // consistently WRT geometry. Note that we only need the bias for positive scales: + // for negative scales, the rounding is intrinsically correct. + fX = SkScalarToFixed(pt.x()) - (s.fInvMatrix.getScaleX() > 0); + fY = SkScalarToFixed(pt.y()) - (s.fInvMatrix.getScaleY() > 0); +#else + fX = SkScalarToFixed(pt.x()); + fY = SkScalarToFixed(pt.y()); +#endif + } + + SkFixed x() const { return fX; } + SkFixed y() const { return fY; } + +private: + SkFixed fX, fY; +}; + #endif |