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

Unified Diff: src/core/SkMatrix.cpp

Issue 2111703002: speed up maprect for scale+trans case (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: test on nexus_7 Created 4 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 | « include/core/SkMatrix.h ('k') | tests/MatrixTest.cpp » ('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 5711bd9aef2f169fba19af723be848dbc0cef584..db89ab68c98c9d6733cb2264262a11b81fece9dc 100644
--- a/src/core/SkMatrix.cpp
+++ b/src/core/SkMatrix.cpp
@@ -1097,12 +1097,37 @@ void SkMatrix::mapVectors(SkPoint dst[], const SkPoint src[], int count) const {
}
}
+void SkMatrix::mapRectScaleTranslate(SkRect* dst, const SkRect& src) const {
+ SkASSERT(dst);
+ SkASSERT(this->isScaleTranslate());
+
+#if 1
mtklein 2016/06/30 13:15:39 You're saying this enabled #if case is faster than
reed1 2016/06/30 13:20:51 Done.
+ SkScalar sx = fMat[kMScaleX];
+ SkScalar sy = fMat[kMScaleY];
+ SkScalar tx = fMat[kMTransX];
+ SkScalar ty = fMat[kMTransY];
+ Sk4f scale(sx, sy, sx, sy);
+ Sk4f trans(tx, ty, tx, ty);
+#else
+ Sk4f a = Sk4f::Load(&fMat[0]);
+ Sk4f b = Sk4f::Load(&fMat[4]);
+ Sk4f scale(a[0], b[0], a[0], b[0]);
+ Sk4f trans(a[2], b[1], a[2], b[1]);
+#endif
+
+ Sk4f result = Sk4f::Load(&src.fLeft) * scale + trans;
mtklein 2016/06/30 13:15:39 I'd personally rename result to ltrb and flipped t
reed1 2016/06/30 13:20:51 Done.
+ // need to sort so we're not inverted
+ Sk4f flipped(result[2], result[3], result[0], result[1]);
+ Sk4f min = Sk4f::Min(result, flipped);
+ Sk4f max = Sk4f::Max(result, flipped);
+ Sk4f(min[0], min[1], max[0], max[1]).store(&dst->fLeft);
+}
+
bool SkMatrix::mapRect(SkRect* dst, const SkRect& src) const {
SkASSERT(dst);
- if (this->rectStaysRect()) {
- this->mapPoints((SkPoint*)dst, (const SkPoint*)&src, 2);
- dst->sort();
+ if (this->isScaleTranslate()) {
+ this->mapRectScaleTranslate(dst, src);
return true;
} else {
SkPoint quad[4];
« no previous file with comments | « include/core/SkMatrix.h ('k') | tests/MatrixTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698