blob: 93bd761970eaf8a8f599819125962ea60706beb3 [file] [log] [blame]
Brian Salomona33b67c2018-05-17 10:42:14 -04001/*
2 * Copyright 2018 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#include "GrQuad.h"
9
10GrQuad::GrQuad(const SkRect& rect, const SkMatrix& m) {
11 SkMatrix::TypeMask tm = m.getType();
12 if (tm <= (SkMatrix::kScale_Mask | SkMatrix::kTranslate_Mask)) {
13 auto r = Sk4f::Load(&rect);
14 const Sk4f t(m.getTranslateX(), m.getTranslateY(), m.getTranslateX(), m.getTranslateY());
15 if (tm <= SkMatrix::kTranslate_Mask) {
16 r += t;
17 } else {
18 const Sk4f s(m.getScaleX(), m.getScaleY(), m.getScaleX(), m.getScaleY());
19 r = r * s + t;
20 }
21 SkNx_shuffle<0, 0, 2, 2>(r).store(fX);
22 SkNx_shuffle<1, 3, 1, 3>(r).store(fY);
23 } else {
24 Sk4f rx(rect.fLeft, rect.fLeft, rect.fRight, rect.fRight);
25 Sk4f ry(rect.fTop, rect.fBottom, rect.fTop, rect.fBottom);
26 Sk4f sx(m.getScaleX());
27 Sk4f kx(m.getSkewX());
28 Sk4f tx(m.getTranslateX());
29 Sk4f ky(m.getSkewY());
30 Sk4f sy(m.getScaleY());
31 Sk4f ty(m.getTranslateY());
32 auto x = SkNx_fma(sx, rx, SkNx_fma(kx, ry, tx));
33 auto y = SkNx_fma(ky, rx, SkNx_fma(sy, ry, ty));
34 if (m.hasPerspective()) {
35 Sk4f w0(m.getPerspX());
36 Sk4f w1(m.getPerspY());
37 Sk4f w2(m.get(SkMatrix::kMPersp2));
38 auto iw = SkNx_fma(w0, rx, SkNx_fma(w1, ry, w2)).invert();
39 x *= iw;
40 y *= iw;
41 }
42 x.store(fX);
43 y.store(fY);
44 }
45}
Brian Salomonbe3c1d22018-05-21 12:54:39 -040046
47GrPerspQuad::GrPerspQuad(const SkRect& rect, const SkMatrix& m) {
48 SkMatrix::TypeMask tm = m.getType();
49 if (tm <= (SkMatrix::kScale_Mask | SkMatrix::kTranslate_Mask)) {
50 auto r = Sk4f::Load(&rect);
51 const Sk4f t(m.getTranslateX(), m.getTranslateY(), m.getTranslateX(), m.getTranslateY());
52 if (tm <= SkMatrix::kTranslate_Mask) {
53 r += t;
54 } else {
55 const Sk4f s(m.getScaleX(), m.getScaleY(), m.getScaleX(), m.getScaleY());
56 r = r * s + t;
57 }
58 SkNx_shuffle<0, 0, 2, 2>(r).store(fX);
59 SkNx_shuffle<1, 3, 1, 3>(r).store(fY);
60 fW[0] = fW[1] = fW[2] = fW[3] = 1.f;
61 fIW[0] = fIW[1] = fIW[2] = fIW[3] = 1.f;
62 } else {
63 Sk4f rx(rect.fLeft, rect.fLeft, rect.fRight, rect.fRight);
64 Sk4f ry(rect.fTop, rect.fBottom, rect.fTop, rect.fBottom);
65 Sk4f sx(m.getScaleX());
66 Sk4f kx(m.getSkewX());
67 Sk4f tx(m.getTranslateX());
68 Sk4f ky(m.getSkewY());
69 Sk4f sy(m.getScaleY());
70 Sk4f ty(m.getTranslateY());
71 SkNx_fma(sx, rx, SkNx_fma(kx, ry, tx)).store(fX);
72 SkNx_fma(ky, rx, SkNx_fma(sy, ry, ty)).store(fY);
73 if (m.hasPerspective()) {
74 Sk4f w0(m.getPerspX());
75 Sk4f w1(m.getPerspY());
76 Sk4f w2(m.get(SkMatrix::kMPersp2));
77 auto w = SkNx_fma(w0, rx, SkNx_fma(w1, ry, w2));
78 w.store(fW);
79 w.invert().store(fIW);
80 } else {
81 fW[0] = fW[1] = fW[2] = fW[3] = 1.f;
82 fIW[0] = fIW[1] = fIW[2] = fIW[3] = 1.f;
83 }
84 }
85}