Flutter Engine
 
Loading...
Searching...
No Matches
matrix.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
6
9
10namespace flutter {
11
12// Mappings from SkMatrix-index to input-index.
13static const int kSkMatrixIndexToMatrix4Index[] = {
14 // clang-format off
15 0, 4, 12,
16 1, 5, 13,
17 3, 7, 15,
18 // clang-format on
19};
20
21SkM44 ToSkM44(const tonic::Float64List& matrix4) {
22 // clang-format off
23 return SkM44(
24 SafeNarrow(matrix4[ 0]), SafeNarrow(matrix4[ 4]), SafeNarrow(matrix4[ 8]), SafeNarrow(matrix4[12]),
25 SafeNarrow(matrix4[ 1]), SafeNarrow(matrix4[ 5]), SafeNarrow(matrix4[ 9]), SafeNarrow(matrix4[13]),
26 SafeNarrow(matrix4[ 2]), SafeNarrow(matrix4[ 6]), SafeNarrow(matrix4[10]), SafeNarrow(matrix4[14]),
27 SafeNarrow(matrix4[ 3]), SafeNarrow(matrix4[ 7]), SafeNarrow(matrix4[11]), SafeNarrow(matrix4[15])
28 );
29 // clang-format on
30}
31
32SkMatrix ToSkMatrix(const tonic::Float64List& matrix4) {
33 FML_DCHECK(matrix4.data());
34 SkMatrix sk_matrix;
35 for (int i = 0; i < 9; ++i) {
36 int matrix4_index = kSkMatrixIndexToMatrix4Index[i];
37 if (matrix4_index < matrix4.num_elements()) {
38 sk_matrix[i] = SafeNarrow(matrix4[matrix4_index]);
39 } else {
40 sk_matrix[i] = 0.0f;
41 }
42 }
43 return sk_matrix;
44}
45
46DlMatrix ToDlMatrix(const tonic::Float64List& matrix4) {
47 FML_DCHECK(matrix4.data());
48 // clang-format off
50 SafeNarrow(matrix4[ 0]), SafeNarrow(matrix4[ 1]), SafeNarrow(matrix4[ 2]), SafeNarrow(matrix4[ 3]),
51 SafeNarrow(matrix4[ 4]), SafeNarrow(matrix4[ 5]), SafeNarrow(matrix4[ 6]), SafeNarrow(matrix4[ 7]),
52 SafeNarrow(matrix4[ 8]), SafeNarrow(matrix4[ 9]), SafeNarrow(matrix4[10]), SafeNarrow(matrix4[11]),
53 SafeNarrow(matrix4[12]), SafeNarrow(matrix4[13]), SafeNarrow(matrix4[14]), SafeNarrow(matrix4[15])
54 );
55 // clang-format on
56}
57
58tonic::Float64List ToMatrix4(const SkMatrix& sk_matrix) {
59 tonic::Float64List matrix4(Dart_NewTypedData(Dart_TypedData_kFloat64, 16));
60 for (int i = 0; i < 9; ++i) {
62 }
63 matrix4[10] = 1.0; // Identity along the z axis.
64 return matrix4;
65}
66
67} // namespace flutter
SkMatrix sk_matrix
#define FML_DCHECK(condition)
Definition logging.h:122
static const int kSkMatrixIndexToMatrix4Index[]
Definition matrix.cc:13
tonic::Float64List ToMatrix4(const SkMatrix &sk_matrix)
Definition matrix.cc:58
SkMatrix ToSkMatrix(const DlMatrix &matrix)
static float SafeNarrow(double value)
DlMatrix ToDlMatrix(const SkMatrix &matrix)
SkM44 ToSkM44(const DlMatrix &matrix)
A 4x4 matrix using column-major storage.
Definition matrix.h:37
static constexpr Matrix MakeColumn(Scalar m0, Scalar m1, Scalar m2, Scalar m3, Scalar m4, Scalar m5, Scalar m6, Scalar m7, Scalar m8, Scalar m9, Scalar m10, Scalar m11, Scalar m12, Scalar m13, Scalar m14, Scalar m15)
Definition matrix.h:69