| Flutter Impeller |

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
5 #include "impeller/scene/importer/conversions.h"
6
7 #include <cstring>
8
9 #include "impeller/scene/importer/scene_flatbuffers.h"
10
11 namespace impeller {
12 namespace scene {
13 namespace importer {
14
15 Matrix 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
26 Matrix ToMatrix(const fb::Matrix& m) {
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
34 Vector2 ToVector2(const fb::Vec2& v) {
35 return Vector2(v.x(), v.y());
36 }
37
38 Vector3 ToVector3(const fb::Vec3& v) {
39 return Vector3(v.x(), v.y(), v.z());
40 }
41
42 Vector4 ToVector4(const fb::Vec4& v) {
43 return Vector4(v.x(), v.y(), v.z(), v.w());
44 }
45
46 Color ToColor(const fb::Color& c) {
47 return Color(c.r(), c.g(), c.b(), c.a());
48 }
49
50 //-----------------------------------------------------------------------------
51 /// Impeller -> Flatbuffers
52 ///
53
54 fb::Matrix ToFBMatrix(const Matrix& m) {
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
62 std::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
70 fb::Vec2 ToFBVec2(const Vector2 v) {
71 return fb::Vec2(v.x, v.y);
72 }
73
74 fb::Vec3 ToFBVec3(const Vector3 v) {
75 return fb::Vec3(v.x, v.y, v.z);
76 }
77
78 fb::Vec4 ToFBVec4(const Vector4 v) {
79 return fb::Vec4(v.x, v.y, v.z, v.w);
80 }
81
82 fb::Color ToFBColor(const Color c) {
83 return fb::Color(c.red, c.green, c.blue, c.alpha);
84 }
85
86 std::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
impeller::Matrix::m
Scalar m[16]
Definition: matrix.h:39
impeller::TPoint::y
Type y
Definition: point.h:31
impeller::Color
Definition: color.h:124
impeller::Vector4
Definition: vector.h:232
impeller::Vector2
Point Vector2
Definition: point.h:320
impeller::scene::importer::ToVector4
Vector4 ToVector4(const fb::Vec4 &v)
Definition: conversions.cc:42
impeller::Color::alpha
Scalar alpha
Definition: color.h:143
impeller::Color::green
Scalar green
Definition: color.h:133
impeller::Vector3::x
Scalar x
Definition: vector.h:23
conversions.h
impeller::scene::importer::ToFBVec2
fb::Vec2 ToFBVec2(const Vector2 v)
Definition: conversions.cc:70
impeller::scene::importer::ToFBMatrix
fb::Matrix ToFBMatrix(const Matrix &m)
Definition: conversions.cc:54
impeller::scene::importer::ToColor
Color ToColor(const fb::Color &c)
Definition: conversions.cc:46
impeller::Color::red
Scalar red
Definition: color.h:128
impeller::Vector3::z
Scalar z
Definition: vector.h:25
impeller::scene::importer::ToFBVec3
fb::Vec3 ToFBVec3(const Vector3 v)
Definition: conversions.cc:74
impeller::Vector4::x
Scalar x
Definition: vector.h:235
impeller::scene::importer::ToVector3
Vector3 ToVector3(const fb::Vec3 &v)
Definition: conversions.cc:38
impeller::scene::importer::ToVector2
Vector2 ToVector2(const fb::Vec2 &v)
Definition: conversions.cc:34
impeller::Vector3::y
Scalar y
Definition: vector.h:24
impeller::TPoint::x
Type x
Definition: point.h:30
impeller::scene::importer::ToFBColor
fb::Color ToFBColor(const Color c)
Definition: conversions.cc:82
impeller::Vector4::w
Scalar w
Definition: vector.h:238
impeller::scene::importer::ToFBMatrixUniquePtr
std::unique_ptr< fb::Matrix > ToFBMatrixUniquePtr(const Matrix &m)
Definition: conversions.cc:62
impeller::Vector4::y
Scalar y
Definition: vector.h:236
impeller::TPoint< Scalar >
impeller::Color::blue
Scalar blue
Definition: color.h:138
impeller::Vector4::z
Scalar z
Definition: vector.h:237
impeller
Definition: aiks_blur_unittests.cc:20
impeller::Matrix
A 4x4 matrix using column-major storage.
Definition: matrix.h:37
impeller::Vector3
Definition: vector.h:20
impeller::scene::importer::ToMatrix
Matrix ToMatrix(const std::vector< double > &m)
Definition: conversions.cc:15
impeller::scene::importer::ToFBVec4
fb::Vec4 ToFBVec4(const Vector4 v)
Definition: conversions.cc:78