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
5
#include "
flutter/lib/ui/painting/matrix.h
"
6
7
#include "
flutter/fml/logging.h
"
8
#include "
flutter/lib/ui/floating_point.h
"
9
10
namespace
flutter
{
11
12
// Mappings from SkMatrix-index to input-index.
13
static
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
21
SkM44
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
32
SkMatrix
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
46
DlMatrix
ToDlMatrix
(
const
tonic::Float64List& matrix4) {
47
FML_DCHECK
(matrix4.data());
48
// clang-format off
49
return
DlMatrix::MakeColumn
(
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
58
tonic::Float64List
ToMatrix4
(
const
SkMatrix&
sk_matrix
) {
59
tonic::Float64List matrix4(Dart_NewTypedData(Dart_TypedData_kFloat64, 16));
60
for
(
int
i
= 0;
i
< 9; ++
i
) {
61
matrix4[
kSkMatrixIndexToMatrix4Index
[
i
]] =
sk_matrix
[
i
];
62
}
63
matrix4[10] = 1.0;
// Identity along the z axis.
64
return
matrix4;
65
}
66
67
}
// namespace flutter
sk_matrix
SkMatrix sk_matrix
Definition
dl_transform_benchmarks.cc:93
i
int i
Definition
fl_socket_accessible.cc:18
floating_point.h
logging.h
FML_DCHECK
#define FML_DCHECK(condition)
Definition
logging.h:122
matrix.h
flutter
Definition
asset_manager.cc:10
flutter::kSkMatrixIndexToMatrix4Index
static const int kSkMatrixIndexToMatrix4Index[]
Definition
matrix.cc:13
flutter::ToMatrix4
tonic::Float64List ToMatrix4(const SkMatrix &sk_matrix)
Definition
matrix.cc:58
flutter::ToSkMatrix
SkMatrix ToSkMatrix(const DlMatrix &matrix)
Definition
dl_geometry_conversions.h:159
flutter::SafeNarrow
static float SafeNarrow(double value)
Definition
floating_point.h:15
flutter::ToDlMatrix
DlMatrix ToDlMatrix(const SkMatrix &matrix)
Definition
dl_geometry_conversions.h:61
flutter::ToSkM44
SkM44 ToSkM44(const DlMatrix &matrix)
Definition
dl_geometry_conversions.h:165
impeller::Matrix
A 4x4 matrix using column-major storage.
Definition
matrix.h:37
impeller::Matrix::MakeColumn
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
lib
ui
painting
matrix.cc
Generated on Wed Nov 5 2025 21:33:14 for Flutter Engine by
1.9.8