aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkMatrixPriv.h
diff options
context:
space:
mode:
authorGravatar reed <reed@google.com>2016-08-22 06:39:49 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-08-22 06:39:49 -0700
commita39667c848146d9070e1a45662fb292d8e6bb8fb (patch)
treed515d31992658dbdc05673987c8eda731ba1b438 /src/core/SkMatrixPriv.h
parent0a8efd7355f3e258b1b4b1da6babfc8f1718ecd4 (diff)
add SkMatrixPriv for specialized helpers
Diffstat (limited to 'src/core/SkMatrixPriv.h')
-rw-r--r--src/core/SkMatrixPriv.h70
1 files changed, 70 insertions, 0 deletions
diff --git a/src/core/SkMatrixPriv.h b/src/core/SkMatrixPriv.h
new file mode 100644
index 0000000000..91185f08d1
--- /dev/null
+++ b/src/core/SkMatrixPriv.h
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2016 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef SkMatrixPriv_DEFINE
+#define SkMatrixPriv_DEFINE
+
+#include "SkMatrix.h"
+#include "SkNx.h"
+
+class SkMatrixPriv {
+public:
+ /**
+ * Attempt to map the rect through the inverse of the matrix. If it is not invertible,
+ * then this returns false and dst is unchanged.
+ */
+ static bool SK_WARN_UNUSED_RESULT InverseMapRect(const SkMatrix& mx,
+ SkRect* dst, const SkRect& src) {
+ if (mx.getType() <= SkMatrix::kTranslate_Mask) {
+ SkScalar tx = mx.getTranslateX();
+ SkScalar ty = mx.getTranslateY();
+ Sk4f trans(tx, ty, tx, ty);
+ (Sk4f::Load(&src.fLeft) - trans).store(&dst->fLeft);
+ return true;
+ }
+ // Insert other special-cases here (e.g. scale+translate)
+
+ // general case
+ SkMatrix inverse;
+ if (mx.invert(&inverse)) {
+ inverse.mapRect(dst, src);
+ return true;
+ }
+ return false;
+ }
+
+ static void MapPointsWithStride(const SkMatrix& mx, SkPoint pts[], size_t stride, int count) {
+ SkASSERT(stride >= sizeof(SkPoint));
+ SkASSERT(0 == stride % sizeof(SkScalar));
+
+ SkMatrix::TypeMask tm = mx.getType();
+
+ if (SkMatrix::kIdentity_Mask == tm) {
+ return;
+ }
+ if (SkMatrix::kTranslate_Mask == tm) {
+ const SkScalar tx = mx.getTranslateX();
+ const SkScalar ty = mx.getTranslateY();
+ Sk2s trans(tx, ty);
+ for (int i = 0; i < count; ++i) {
+ (Sk2s::Load(&pts->fX) + trans).store(&pts->fX);
+ pts = (SkPoint*)((intptr_t)pts + stride);
+ }
+ return;
+ }
+ // Insert other special-cases here (e.g. scale+translate)
+
+ // general case
+ SkMatrix::MapXYProc proc = mx.getMapXYProc();
+ for (int i = 0; i < count; ++i) {
+ proc(mx, pts->fX, pts->fY, pts);
+ pts = (SkPoint*)((intptr_t)pts + stride);
+ }
+ }
+};
+
+#endif