Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(80)

Unified Diff: src/core/SkMatrix.cpp

Issue 306013010: allow subpixel positioning w/ bitmap filtering Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/core/SkDraw.cpp ('k') | src/core/SkMatrixUtils.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkMatrix.cpp
diff --git a/src/core/SkMatrix.cpp b/src/core/SkMatrix.cpp
index 95662fc4cd42bca1edfb286e94089494b6e5a206..81115620810ef147ca0c06036a13e9a6ac47b319 100644
--- a/src/core/SkMatrix.cpp
+++ b/src/core/SkMatrix.cpp
@@ -1638,6 +1638,32 @@ void SkMatrix::toString(SkString* str) const {
#include "SkMatrixUtils.h"
+bool SkRectIsOnGrid(int width, int height, const SkRect& r, unsigned subpixelBits) {
+ const int lowBitsMask = (1 << subpixelBits) - 1;
+ const SkScalar scale = 1 << subpixelBits;
+
+ const int dL = SkScalarRoundToInt(r.fLeft * scale);
+ const int dT = SkScalarRoundToInt(r.fTop * scale);
+ const int dR = SkScalarRoundToInt(r.fRight * scale);
+ const int dB = SkScalarRoundToInt(r.fBottom * scale);
+
+ if (subpixelBits) {
+ // we only check the low-bits for gridding if we have subpixelBits
+ const int merge = dL | dT | dR | dB;
+ if (merge & lowBitsMask) {
+ return false;
+ }
+ }
+
+ // Now we know we're integral, just need to check our width/height
+ const int dW = (dR - dL);
+ const int dH = (dB - dT);
+ if (dW != (width << subpixelBits) || dH != (height << subpixelBits)) {
+ return false;
+ }
+ return true;
+}
+
bool SkTreatAsSprite(const SkMatrix& mat, int width, int height,
unsigned subpixelBits) {
// quick reject on affine or perspective
@@ -1664,6 +1690,7 @@ bool SkTreatAsSprite(const SkMatrix& mat, int width, int height,
mat.mapRect(&dst, src);
}
+#if 0
// just apply the translate to isrc
isrc.offset(SkScalarRoundToInt(mat.getTranslateX()),
SkScalarRoundToInt(mat.getTranslateY()));
@@ -1684,6 +1711,9 @@ bool SkTreatAsSprite(const SkMatrix& mat, int width, int height,
SkIRect idst;
dst.round(&idst);
return isrc == idst;
+#else
+ return SkRectIsOnGrid(width, height, dst, subpixelBits);
+#endif
}
// A square matrix M can be decomposed (via polar decomposition) into two matrices --
« no previous file with comments | « src/core/SkDraw.cpp ('k') | src/core/SkMatrixUtils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698