Fix issue with negative translations of small paths

Truncating negative values will produce a negative fractional part when
you subtract out the integer value, which causes havoc with rendering
the path and searching for it in the cache. What we want is the floor.

Bug: 819966, 819522
Change-Id: I2feb451e28bfb863111479f70fd99fa1299abac0
Reviewed-on: https://skia-review.googlesource.com/113428
Commit-Queue: Jim Van Verth <jvanverth@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
This commit is contained in:
Jim Van Verth 2018-03-09 14:16:31 -05:00 committed by Skia Commit-Bot
parent 629503de26
commit a64a5850d9

View File

@ -82,8 +82,10 @@ public:
SkScalar tx = ctm.get(SkMatrix::kMTransX);
SkScalar ty = ctm.get(SkMatrix::kMTransY);
// Allow 8 bits each in x and y of subpixel positioning.
SkFixed fracX = SkScalarToFixed(SkScalarFraction(tx)) & 0x0000FF00;
SkFixed fracY = SkScalarToFixed(SkScalarFraction(ty)) & 0x0000FF00;
tx -= SkScalarFloorToScalar(tx);
ty -= SkScalarFloorToScalar(ty);
SkFixed fracX = SkScalarToFixed(tx) & 0x0000FF00;
SkFixed fracY = SkScalarToFixed(ty) & 0x0000FF00;
int shapeKeySize = shape.unstyledKeySize();
fKey.reset(5 + shapeKeySize);
fKey[0] = SkFloat2Bits(sx);
@ -637,8 +639,12 @@ private:
return false;
}
SkMatrix drawMatrix(ctm);
drawMatrix.set(SkMatrix::kMTransX, SkScalarFraction(ctm.get(SkMatrix::kMTransX)));
drawMatrix.set(SkMatrix::kMTransY, SkScalarFraction(ctm.get(SkMatrix::kMTransY)));
SkScalar tx = ctm.getTranslateX();
SkScalar ty = ctm.getTranslateY();
tx -= SkScalarFloorToScalar(tx);
ty -= SkScalarFloorToScalar(ty);
drawMatrix.set(SkMatrix::kMTransX, tx);
drawMatrix.set(SkMatrix::kMTransY, ty);
SkRect shapeDevBounds;
drawMatrix.mapRect(&shapeDevBounds, bounds);
SkScalar dx = SkScalarFloorToScalar(shapeDevBounds.fLeft);
@ -732,8 +738,8 @@ private:
SkRect bounds = shapeData->fBounds;
SkRect translatedBounds(bounds);
if (!fUsesDistanceField) {
translatedBounds.offset(SkScalarTruncToScalar(ctm.get(SkMatrix::kMTransX)),
SkScalarTruncToScalar(ctm.get(SkMatrix::kMTransY)));
translatedBounds.offset(SkScalarFloorToScalar(ctm.get(SkMatrix::kMTransX)),
SkScalarFloorToScalar(ctm.get(SkMatrix::kMTransY)));
}
// vertex positions
@ -754,11 +760,12 @@ private:
position = (SkPoint*)positionOffset;
*position = quad.point(3);
} else {
SkPointPriv::SetRectTriStrip(positions, translatedBounds.left(),
translatedBounds.top(),
translatedBounds.right(),
translatedBounds.bottom(),
vertexStride);
SkPointPriv::SetRectTriStrip(positions,
translatedBounds.left(),
translatedBounds.top(),
translatedBounds.right(),
translatedBounds.bottom(),
vertexStride);
}
// colors