aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkMatrix.cpp
diff options
context:
space:
mode:
authorGravatar reed <reed@google.com>2015-03-23 08:15:14 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-03-23 08:15:14 -0700
commit8010632f2408ce9d840c1dcd26a8be0e4967233e (patch)
treed6b302cb048fee561cc401ed9f9340a4ba20bf87 /src/core/SkMatrix.cpp
parent9c328187d9dee33736b77dc14dfb59529d948bb1 (diff)
remove meaningless matrix benches, add mapPts() and add new benches
mapPts definitely faster than mapPoints (identity and perspective same speed). Up to 3x for large values of N. cloned from https://codereview.chromium.org/1031443002/ BUG=skia: Review URL: https://codereview.chromium.org/1030653002
Diffstat (limited to 'src/core/SkMatrix.cpp')
-rw-r--r--src/core/SkMatrix.cpp84
1 files changed, 84 insertions, 0 deletions
diff --git a/src/core/SkMatrix.cpp b/src/core/SkMatrix.cpp
index 753c4dc61e..81b8960855 100644
--- a/src/core/SkMatrix.cpp
+++ b/src/core/SkMatrix.cpp
@@ -1020,6 +1020,90 @@ void SkMatrix::mapPoints(SkPoint dst[], const SkPoint src[], int count) const {
this->getMapPtsProc()(*this, dst, src, count);
}
+#include "Sk4x.h"
+
+void SkMatrix::mapPts(SkPoint dst[], const SkPoint src[], int count) const {
+ if (count <= 0) {
+ return;
+ }
+
+ 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 & 1) {
+ dst->fX = src->fX + tx;
+ dst->fY = src->fY + ty;
+ src += 1;
+ dst += 1;
+ }
+ Sk4f trans4(tx, ty, tx, ty);
+ count >>= 1;
+ for (int i = 0; i < count; ++i) {
+ (Sk4f::Load(&src->fX) + trans4).store(&dst->fX);
+ src += 2;
+ dst += 2;
+ }
+ return;
+ }
+ if (mask <= SkMatrix::kScale_Mask + SkMatrix::kTranslate_Mask) {
+ SkScalar tx = this->getTranslateX();
+ SkScalar ty = this->getTranslateY();
+ SkScalar sx = this->getScaleX();
+ SkScalar sy = this->getScaleY();
+ if (count & 1) {
+ dst->fX = src->fX * sx + tx;
+ dst->fY = src->fY * sy + ty;
+ src += 1;
+ dst += 1;
+ }
+ Sk4f trans4(tx, ty, tx, ty);
+ Sk4f scale4(sx, sy, sx, sy);
+ count >>= 1;
+ for (int i = 0; i < count; ++i) {
+ (Sk4f::Load(&src->fX) * scale4 + trans4).store(&dst->fX);
+ src += 2;
+ dst += 2;
+ }
+ return;
+ }
+ 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();
+ if (count & 1) {
+ dst->set(src->fX * sx + src->fY * kx + tx,
+ src->fX * ky + src->fY * sy + ty);
+ src += 1;
+ dst += 1;
+ }
+ Sk4f trans4(tx, ty, tx, ty);
+ Sk4f scale4(sx, sy, sx, sy);
+ Sk4f skew4(kx, ky, kx, ky); // applied to swizzle of src4
+ count >>= 1;
+ for (int i = 0; i < count; ++i) {
+ Sk4f src4 = Sk4f::Load(&src->fX);
+ Sk4f swz4(src[0].fY, src[0].fX, src[1].fY, src[1].fX); // need ABCD -> BADC
+ (src4 * scale4 + swz4 * skew4 + trans4).store(&dst->fX);
+ src += 2;
+ dst += 2;
+ }
+ return;
+ }
+ // fall through for perspective
+ this->mapPoints(dst, src, count);
+}
+
///////////////////////////////////////////////////////////////////////////////
void SkMatrix::mapHomogeneousPoints(SkScalar dst[], const SkScalar src[], int count) const {