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 | |
5 | #include "flutter/lib/ui/painting/matrix.h" |
6 | |
7 | #include "flutter/fml/logging.h" |
8 | |
9 | namespace flutter { |
10 | |
11 | // Mappings from SkMatrix-index to input-index. |
12 | static const int kSkMatrixIndexToMatrix4Index[] = { |
13 | // clang-format off |
14 | 0, 4, 12, |
15 | 1, 5, 13, |
16 | 3, 7, 15, |
17 | // clang-format on |
18 | }; |
19 | |
20 | SkMatrix ToSkMatrix(const tonic::Float64List& matrix4) { |
21 | FML_DCHECK(matrix4.data()); |
22 | SkMatrix sk_matrix; |
23 | for (int i = 0; i < 9; ++i) { |
24 | int matrix4_index = kSkMatrixIndexToMatrix4Index[i]; |
25 | if (matrix4_index < matrix4.num_elements()) { |
26 | sk_matrix[i] = matrix4[matrix4_index]; |
27 | } else { |
28 | sk_matrix[i] = 0.0; |
29 | } |
30 | } |
31 | return sk_matrix; |
32 | } |
33 | |
34 | tonic::Float64List ToMatrix4(const SkMatrix& sk_matrix) { |
35 | tonic::Float64List matrix4(Dart_NewTypedData(Dart_TypedData_kFloat64, 16)); |
36 | for (int i = 0; i < 9; ++i) { |
37 | matrix4[kSkMatrixIndexToMatrix4Index[i]] = sk_matrix[i]; |
38 | } |
39 | matrix4[10] = 1.0; // Identity along the z axis. |
40 | return matrix4; |
41 | } |
42 | |
43 | } // namespace flutter |
44 | |