Flutter Engine
The 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
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());
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
46tonic::Float64List ToMatrix4(const SkMatrix& sk_matrix) {
47 tonic::Float64List matrix4(Dart_NewTypedData(Dart_TypedData_kFloat64, 16));
48 for (int i = 0; i < 9; ++i) {
50 }
51 matrix4[10] = 1.0; // Identity along the z axis.
52 return matrix4;
53}
54
55} // namespace flutter
Definition SkM44.h:150
@ Dart_TypedData_kFloat64
Definition dart_api.h:2615
DART_EXPORT Dart_Handle Dart_NewTypedData(Dart_TypedData_Type type, intptr_t length)
SkMatrix sk_matrix
#define FML_DCHECK(condition)
Definition logging.h:103
static const int kSkMatrixIndexToMatrix4Index[]
Definition matrix.cc:13
tonic::Float64List ToMatrix4(const SkMatrix &sk_matrix)
Definition matrix.cc:46
static float SafeNarrow(double value)
SkM44 ToSkM44(const tonic::Float64List &matrix4)
Definition matrix.cc:21
SkMatrix ToSkMatrix(const tonic::Float64List &matrix4)
Definition matrix.cc:32