Flutter Engine
The Flutter Engine
AffineMatrix.h
Go to the documentation of this file.
1/*
2 * Copyright 2021 Google LLC.
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 skgpu_tessellate_AffineMatrix_DEFINED
9#define skgpu_tessellate_AffineMatrix_DEFINED
10
14#include "src/base/SkUtils.h"
15#include "src/base/SkVx.h"
16
17namespace skgpu::tess {
18
19// Applies an affine 2d transformation to points. Uses SIMD, but takes care to map points
20// identically, regardless of which method is called.
21//
22// This class stores redundant data, so it is best used only as a stack-allocated object at the
23// point of use.
25public:
26 AffineMatrix() = default;
27 AffineMatrix(const SkMatrix& m) { *this = m; }
28
30 SkASSERT(!m.hasPerspective());
31 // Duplicate the matrix in float4.lo and float4.hi so we can map two points at once.
32 fScale = skvx::float2(m.getScaleX(), m.getScaleY()).xyxy();
33 fSkew = skvx::float2(m.getSkewX(), m.getSkewY()).xyxy();
34 fTrans = skvx::float2(m.getTranslateX(), m.getTranslateY()).xyxy();
35 return *this;
36 }
37
39 return fScale * p0p1 + (fSkew * p0p1.yxwz() + fTrans);
40 }
41
43 return this->map2Points(skvx::float4::Load(pts));
44 }
45
47 return this->map2Points(skvx::float4(sk_bit_cast<skvx::float2>(p0),
48 sk_bit_cast<skvx::float2>(p1)));
49 }
50
52 return fScale.lo * p + (fSkew.lo * p.yx() + fTrans.lo);
53 }
54
56 return this->mapPoint(skvx::float2::Load(pt));
57 }
58
60 return sk_bit_cast<SkPoint>(this->mapPoint(sk_bit_cast<skvx::float2>(p)));
61 }
62
63private:
64 skvx::float4 fScale;
65 skvx::float4 fSkew;
66 skvx::float4 fTrans;
67};
68
69} // namespace skgpu::tess
70
71#endif // skgpu_tessellate_AffineMatrix_DEFINED
#define SkASSERT(cond)
Definition: SkAssert.h:116
#define SK_ALWAYS_INLINE
Definition: SkAttributes.h:30
AffineMatrix(const SkMatrix &m)
Definition: AffineMatrix.h:27
SK_ALWAYS_INLINE skvx::float4 map2Points(const SkPoint pts[2]) const
Definition: AffineMatrix.h:42
SK_ALWAYS_INLINE skvx::float2 map1Point(const SkPoint pt[1]) const
Definition: AffineMatrix.h:55
SK_ALWAYS_INLINE skvx::float2 mapPoint(skvx::float2 p) const
Definition: AffineMatrix.h:51
AffineMatrix & operator=(const SkMatrix &m)
Definition: AffineMatrix.h:29
SK_ALWAYS_INLINE SkPoint mapPoint(SkPoint p) const
Definition: AffineMatrix.h:59
SK_ALWAYS_INLINE skvx::float4 map2Points(skvx::float4 p0p1) const
Definition: AffineMatrix.h:38
SK_ALWAYS_INLINE skvx::float4 map2Points(SkPoint p0, SkPoint p1) const
Definition: AffineMatrix.h:46
Vec< 2, float > float2
Definition: SkVx.h:1145
Definition: SkVx.h:83
static SKVX_ALWAYS_INLINE Vec Load(const void *ptr)
Definition: SkVx.h:109
Vec< N/2, T > lo
Definition: SkVx.h:117