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

Unified Diff: src/core/SkMatrix.cpp

Issue 1040783002: use table of procs (and unrolling) to speed up mapPts (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 9 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') | no next file » | 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 81b8960855c355599aa82e53a551e496d61798b4..a43e00f3af562630723e9456a90af12c25750a6c 100644
--- a/src/core/SkMatrix.cpp
+++ b/src/core/SkMatrix.cpp
@@ -1022,22 +1022,12 @@ void SkMatrix::mapPoints(SkPoint dst[], const SkPoint src[], int count) const {
#include "Sk4x.h"
-void SkMatrix::mapPts(SkPoint dst[], const SkPoint src[], int count) const {
- if (count <= 0) {
- return;
- }
+void SkMatrix::Trans_vpts(const SkMatrix& m, SkPoint dst[], const SkPoint src[], int count) {
+ SkASSERT(m.getType() <= kTranslate_Mask);
- unsigned mask = this->getType() & 0xF;
-
- if (SkMatrix::kIdentity_Mask == mask) {
- if (src != dst) {
- memcpy(dst, src, count * sizeof(SkPoint));
- }
- return;
- }
- if (SkMatrix::kTranslate_Mask == mask) {
- SkScalar tx = this->getTranslateX();
- SkScalar ty = this->getTranslateY();
+ if (count > 0) {
+ SkScalar tx = m.getTranslateX();
+ SkScalar ty = m.getTranslateY();
if (count & 1) {
dst->fX = src->fX + tx;
dst->fY = src->fY + ty;
@@ -1046,18 +1036,29 @@ void SkMatrix::mapPts(SkPoint dst[], const SkPoint src[], int count) const {
}
Sk4f trans4(tx, ty, tx, ty);
count >>= 1;
- for (int i = 0; i < count; ++i) {
+ if (count & 1) {
(Sk4f::Load(&src->fX) + trans4).store(&dst->fX);
src += 2;
dst += 2;
}
- return;
+ count >>= 1;
+ for (int i = 0; i < count; ++i) {
+ (Sk4f::Load(&src[0].fX) + trans4).store(&dst[0].fX);
+ (Sk4f::Load(&src[2].fX) + trans4).store(&dst[2].fX);
+ src += 4;
+ dst += 4;
+ }
}
- if (mask <= SkMatrix::kScale_Mask + SkMatrix::kTranslate_Mask) {
- SkScalar tx = this->getTranslateX();
- SkScalar ty = this->getTranslateY();
- SkScalar sx = this->getScaleX();
- SkScalar sy = this->getScaleY();
+}
+
+void SkMatrix::Scale_vpts(const SkMatrix& m, SkPoint dst[], const SkPoint src[], int count) {
+ SkASSERT(m.getType() <= (kScale_Mask | kTranslate_Mask));
+
+ if (count > 0) {
+ SkScalar tx = m.getTranslateX();
+ SkScalar ty = m.getTranslateY();
+ SkScalar sx = m.getScaleX();
+ SkScalar sy = m.getScaleY();
if (count & 1) {
dst->fX = src->fX * sx + tx;
dst->fY = src->fY * sy + ty;
@@ -1067,20 +1068,31 @@ void SkMatrix::mapPts(SkPoint dst[], const SkPoint src[], int count) const {
Sk4f trans4(tx, ty, tx, ty);
Sk4f scale4(sx, sy, sx, sy);
count >>= 1;
- for (int i = 0; i < count; ++i) {
+ if (count & 1) {
(Sk4f::Load(&src->fX) * scale4 + trans4).store(&dst->fX);
src += 2;
dst += 2;
}
- return;
+ count >>= 1;
+ for (int i = 0; i < count; ++i) {
+ (Sk4f::Load(&src[0].fX) * scale4 + trans4).store(&dst[0].fX);
+ (Sk4f::Load(&src[2].fX) * scale4 + trans4).store(&dst[2].fX);
+ src += 4;
+ dst += 4;
+ }
}
- if (mask < SkMatrix::kPerspective_Mask) { // affine
- SkScalar tx = this->getTranslateX();
- SkScalar ty = this->getTranslateY();
- SkScalar sx = this->getScaleX();
- SkScalar sy = this->getScaleY();
- SkScalar kx = this->getSkewX();
- SkScalar ky = this->getSkewY();
+}
+
+void SkMatrix::Affine_vpts(const SkMatrix& m, SkPoint dst[], const SkPoint src[], int count) {
+ SkASSERT(m.getType() != kPerspective_Mask);
+
+ if (count > 0) {
+ SkScalar tx = m.getTranslateX();
+ SkScalar ty = m.getTranslateY();
+ SkScalar sx = m.getScaleX();
+ SkScalar sy = m.getScaleY();
+ SkScalar kx = m.getSkewX();
+ SkScalar ky = m.getSkewY();
if (count & 1) {
dst->set(src->fX * sx + src->fY * kx + tx,
src->fX * ky + src->fY * sy + ty);
@@ -1098,12 +1110,21 @@ void SkMatrix::mapPts(SkPoint dst[], const SkPoint src[], int count) const {
src += 2;
dst += 2;
}
- return;
}
- // fall through for perspective
- this->mapPoints(dst, src, count);
}
+const SkMatrix::MapPtsProc SkMatrix::gMapVPtsProcs[] = {
+ SkMatrix::Identity_pts, SkMatrix::Trans_vpts,
+ SkMatrix::Scale_vpts, SkMatrix::Scale_vpts,
+ SkMatrix::Affine_vpts, SkMatrix::Affine_vpts,
+ SkMatrix::Affine_vpts, SkMatrix::Affine_vpts,
+ // repeat the persp proc 8 times
+ SkMatrix::Persp_pts, SkMatrix::Persp_pts,
+ SkMatrix::Persp_pts, SkMatrix::Persp_pts,
+ SkMatrix::Persp_pts, SkMatrix::Persp_pts,
+ SkMatrix::Persp_pts, SkMatrix::Persp_pts
+};
+
///////////////////////////////////////////////////////////////////////////////
void SkMatrix::mapHomogeneousPoints(SkScalar dst[], const SkScalar src[], int count) const {
« no previous file with comments | « include/core/SkMatrix.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698