| Flutter Impeller |

dl_vertices_geometry.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/display_list/dl_vertices_geometry.h"
6
7 #include "display_list/dl_vertices.h"
8 #include "impeller/display_list/skia_conversions.h"
9 #include "impeller/entity/geometry/vertices_geometry.h"
10 #include "impeller/geometry/point.h"
11 #include "third_party/skia/include/core/SkPoint.h"
12 #include "third_party/skia/include/core/SkRect.h"
13
14 namespace impeller {
15
16 static Rect ToRect(const SkRect& rect) {
17 return Rect::MakeLTRB(rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
18 }
19
20 static VerticesGeometry::VertexMode ToVertexMode(flutter::DlVertexMode mode) {
21 switch (mode) {
22 case flutter::DlVertexMode::kTriangles:
23 return VerticesGeometry::VertexMode::kTriangles;
24 case flutter::DlVertexMode::kTriangleStrip:
25 return VerticesGeometry::VertexMode::kTriangleStrip;
26 case flutter::DlVertexMode::kTriangleFan:
27 return VerticesGeometry::VertexMode::kTriangleFan;
28 };
29 }
30
31 std::shared_ptr<impeller::VerticesGeometry> MakeVertices(
32 const flutter::DlVertices* vertices) {
33 auto bounds = ToRect(vertices->bounds());
34 auto mode = ToVertexMode(vertices->mode());
35 std::vector<Point> positions(vertices->vertex_count());
36 for (auto i = 0; i < vertices->vertex_count(); i++) {
37 positions[i] = skia_conversions::ToPoint(vertices->vertices()[i]);
38 }
39
40 std::vector<uint16_t> indices(vertices->index_count());
41 for (auto i = 0; i < vertices->index_count(); i++) {
42 indices[i] = vertices->indices()[i];
43 }
44
45 std::vector<Color> colors;
46 if (vertices->colors()) {
47 colors.reserve(vertices->vertex_count());
48 for (auto i = 0; i < vertices->vertex_count(); i++) {
49 colors.push_back(
50 skia_conversions::ToColor(vertices->colors()[i]).Premultiply());
51 }
52 }
53 std::vector<Point> texture_coordinates;
54 if (vertices->texture_coordinates()) {
55 texture_coordinates.reserve(vertices->vertex_count());
56 for (auto i = 0; i < vertices->vertex_count(); i++) {
57 texture_coordinates.push_back(
58 skia_conversions::ToPoint(vertices->texture_coordinates()[i]));
59 }
60 }
61 return std::make_shared<VerticesGeometry>(
62 positions, indices, texture_coordinates, colors, bounds, mode);
63 }
64
65 } // namespace impeller
point.h
impeller::MakeVertices
std::shared_ptr< impeller::VerticesGeometry > MakeVertices(const flutter::DlVertices *vertices)
Definition: dl_vertices_geometry.cc:31
impeller::skia_conversions::ToColor
Color ToColor(const flutter::DlColor &color)
Definition: skia_conversions.cc:142
impeller::VerticesGeometry::VertexMode
VertexMode
Definition: vertices_geometry.h:14
skia_conversions.h
impeller::ToVertexMode
static VerticesGeometry::VertexMode ToVertexMode(flutter::DlVertexMode mode)
Definition: dl_vertices_geometry.cc:20
impeller::VerticesGeometry::VertexMode::kTriangleStrip
@ kTriangleStrip
impeller::skia_conversions::ToPoint
Point ToPoint(const SkPoint &point)
Definition: skia_conversions.cc:138
vertices_geometry.h
dl_vertices_geometry.h
impeller::VerticesGeometry::VertexMode::kTriangles
@ kTriangles
impeller::TRect< Scalar >::MakeLTRB
constexpr static TRect MakeLTRB(Type left, Type top, Type right, Type bottom)
Definition: rect.h:40
impeller::ToRect
static Rect ToRect(const SkRect &rect)
Definition: dl_vertices_geometry.cc:16
impeller
Definition: aiks_context.cc:10
impeller::VerticesGeometry::VertexMode::kTriangleFan
@ kTriangleFan
impeller::Color::Premultiply
constexpr Color Premultiply() const
Definition: color.h:212
impeller::TRect
Definition: rect.h:20