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

Side by Side Diff: src/core/SkMatrixPriv.h

Issue 2268443002: add SkMatrixPriv for specialized helpers Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 4 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 unified diff | Download patch
« no previous file with comments | « src/core/SkMatrix.cpp ('k') | src/gpu/GrDrawContext.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2016 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #ifndef SkMatrixPriv_DEFINE
9 #define SkMatrixPriv_DEFINE
10
11 #include "SkMatrix.h"
12 #include "SkNx.h"
13
14 class SkMatrixPriv {
15 public:
16 /**
17 * Attempt to map the rect through the inverse of the matrix. If it is not invertible,
18 * then this returns false and dst is unchanged.
19 */
20 static bool SK_WARN_UNUSED_RESULT InverseMapRect(const SkMatrix& mx,
21 SkRect* dst, const SkRect& src) {
22 if (mx.getType() <= SkMatrix::kTranslate_Mask) {
23 SkScalar tx = mx.getTranslateX();
24 SkScalar ty = mx.getTranslateY();
25 Sk4f trans(tx, ty, tx, ty);
26 (Sk4f::Load(&src.fLeft) - trans).store(&dst->fLeft);
27 return true;
28 }
29 // Insert other special-cases here (e.g. scale+translate)
30
31 // general case
32 SkMatrix inverse;
33 if (mx.invert(&inverse)) {
34 inverse.mapRect(dst, src);
35 return true;
36 }
37 return false;
38 }
39
40 static void MapPointsWithStride(const SkMatrix& mx, SkPoint pts[], size_t st ride, int count) {
41 SkASSERT(stride >= sizeof(SkPoint));
42 SkASSERT(0 == stride % sizeof(SkScalar));
43
44 SkMatrix::TypeMask tm = mx.getType();
45
46 if (SkMatrix::kIdentity_Mask == tm) {
47 return;
48 }
49 if (SkMatrix::kTranslate_Mask == tm) {
50 const SkScalar tx = mx.getTranslateX();
51 const SkScalar ty = mx.getTranslateY();
52 Sk2s trans(tx, ty);
53 for (int i = 0; i < count; ++i) {
54 (Sk2s::Load(&pts->fX) + trans).store(&pts->fX);
55 pts = (SkPoint*)((intptr_t)pts + stride);
56 }
57 return;
58 }
59 // Insert other special-cases here (e.g. scale+translate)
60
61 // general case
62 SkMatrix::MapXYProc proc = mx.getMapXYProc();
63 for (int i = 0; i < count; ++i) {
64 proc(mx, pts->fX, pts->fY, pts);
65 pts = (SkPoint*)((intptr_t)pts + stride);
66 }
67 }
68 };
69
70 #endif
OLDNEW
« no previous file with comments | « src/core/SkMatrix.cpp ('k') | src/gpu/GrDrawContext.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698