Flutter Engine
The Flutter Engine
conversions.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
7#include <cstring>
8
9#include "impeller/scene/importer/scene_flatbuffers.h"
10
11namespace impeller {
12namespace scene {
13namespace importer {
14
15Matrix ToMatrix(const std::vector<double>& m) {
16 return Matrix(m[0], m[1], m[2], m[3], //
17 m[4], m[5], m[6], m[7], //
18 m[8], m[9], m[10], m[11], //
19 m[12], m[13], m[14], m[15]);
20}
21
22//-----------------------------------------------------------------------------
23/// Flatbuffers -> Impeller
24///
25
27 auto& a = *m.m();
28 return Matrix(a[0], a[1], a[2], a[3], //
29 a[4], a[5], a[6], a[7], //
30 a[8], a[9], a[10], a[11], //
31 a[12], a[13], a[14], a[15]);
32}
33
34Vector2 ToVector2(const fb::Vec2& v) {
35 return Vector2(v.x(), v.y());
36}
37
38Vector3 ToVector3(const fb::Vec3& v) {
39 return Vector3(v.x(), v.y(), v.z());
40}
41
43 return Vector4(v.x(), v.y(), v.z(), v.w());
44}
45
47 return Color(c.r(), c.g(), c.b(), c.a());
48}
49
50//-----------------------------------------------------------------------------
51/// Impeller -> Flatbuffers
52///
53
55 auto array = std::array<Scalar, 16>{m.m[0], m.m[1], m.m[2], m.m[3], //
56 m.m[4], m.m[5], m.m[6], m.m[7], //
57 m.m[8], m.m[9], m.m[10], m.m[11], //
58 m.m[12], m.m[13], m.m[14], m.m[15]};
59 return fb::Matrix(array);
60}
61
62std::unique_ptr<fb::Matrix> ToFBMatrixUniquePtr(const Matrix& m) {
63 auto array = std::array<Scalar, 16>{m.m[0], m.m[1], m.m[2], m.m[3], //
64 m.m[4], m.m[5], m.m[6], m.m[7], //
65 m.m[8], m.m[9], m.m[10], m.m[11], //
66 m.m[12], m.m[13], m.m[14], m.m[15]};
67 return std::make_unique<fb::Matrix>(array);
68}
69
70fb::Vec2 ToFBVec2(const Vector2 v) {
71 return fb::Vec2(v.x, v.y);
72}
73
74fb::Vec3 ToFBVec3(const Vector3 v) {
75 return fb::Vec3(v.x, v.y, v.z);
76}
77
79 return fb::Vec4(v.x, v.y, v.z, v.w);
80}
81
83 return fb::Color(c.red, c.green, c.blue, c.alpha);
84}
85
86std::unique_ptr<fb::Color> ToFBColor(const std::vector<double>& c) {
87 auto* color = new fb::Color(c.size() > 0 ? c[0] : 1, //
88 c.size() > 1 ? c[1] : 1, //
89 c.size() > 2 ? c[2] : 1, //
90 c.size() > 3 ? c[3] : 1);
91 return std::unique_ptr<fb::Color>(color);
92}
93
94} // namespace importer
95} // namespace scene
96} // namespace impeller
skvx::Vec< 4, float > Vec4
DlColor color
struct MyStruct a[10]
SK_API sk_sp< SkShader > Color(SkColor)
fb::Vec3 ToFBVec3(const Vector3 v)
Definition: conversions.cc:74
fb::Vec4 ToFBVec4(const Vector4 v)
Definition: conversions.cc:78
std::unique_ptr< fb::Matrix > ToFBMatrixUniquePtr(const Matrix &m)
Definition: conversions.cc:62
fb::Vec2 ToFBVec2(const Vector2 v)
Definition: conversions.cc:70
fb::Color ToFBColor(const Color c)
Definition: conversions.cc:82
Matrix ToMatrix(const std::vector< double > &m)
Definition: conversions.cc:15
Color ToColor(const fb::Color &c)
Definition: conversions.cc:46
Vector3 ToVector3(const fb::Vec3 &v)
Definition: conversions.cc:38
fb::Matrix ToFBMatrix(const Matrix &m)
Definition: conversions.cc:54
Vector4 ToVector4(const fb::Vec4 &v)
Definition: conversions.cc:42
Vector2 ToVector2(const fb::Vec2 &v)
Definition: conversions.cc:34
Point Vector2
Definition: point.h:326
SK_API sk_sp< PrecompileColorFilter > Matrix()
Scalar blue
Definition: color.h:138
Scalar alpha
Definition: color.h:143
Scalar red
Definition: color.h:128
Scalar green
Definition: color.h:133
A 4x4 matrix using column-major storage.
Definition: matrix.h:37