Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
tessellator.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 "tessellator.h"
6
7#include <vector>
8
10
11namespace impeller {
13 return new PathBuilder();
14}
15
17 delete builder;
18}
19
20void MoveTo(PathBuilder* builder, Scalar x, Scalar y) {
21 builder->MoveTo(Point(x, y));
22}
23
24void LineTo(PathBuilder* builder, Scalar x, Scalar y) {
25 builder->LineTo(Point(x, y));
26}
27
28void CubicTo(PathBuilder* builder,
29 Scalar x1,
30 Scalar y1,
31 Scalar x2,
32 Scalar y2,
33 Scalar x3,
34 Scalar y3) {
35 builder->CubicCurveTo(Point(x1, y1), Point(x2, y2), Point(x3, y3));
36}
37
38void Close(PathBuilder* builder) {
39 builder->Close();
40}
41
43 int fill_type,
44 Scalar tolerance) {
45 auto path = builder->CopyPath(static_cast<FillType>(fill_type));
46 std::vector<float> points;
48 path, tolerance,
49 [&points](const float* vertices, size_t vertices_count,
50 const uint16_t* indices, size_t indices_count) {
51 // Results are expected to be re-duplicated.
52 std::vector<Point> raw_points;
53 for (auto i = 0u; i < vertices_count * 2; i += 2) {
54 raw_points.emplace_back(Point{vertices[i], vertices[i + 1]});
55 }
56 for (auto i = 0u; i < indices_count; i++) {
57 auto point = raw_points[indices[i]];
58 points.push_back(point.x);
59 points.push_back(point.y);
60 }
61 return true;
63 return nullptr;
64 }
65
66 Vertices* vertices = new Vertices();
67 vertices->points = new float[points.size()];
68 if (!vertices->points) {
69 return nullptr;
70 }
71 vertices->length = points.size();
72 std::copy(points.begin(), points.end(), vertices->points);
73 return vertices;
74}
75
76void DestroyVertices(Vertices* vertices) {
77 delete vertices->points;
78 delete vertices;
79}
80
81} // namespace impeller
static const int points[]
An extended tessellator that offers arbitrary/concave tessellation via the libtess2 library.
Tessellator::Result Tessellate(const Path &path, Scalar tolerance, const BuilderCallback &callback)
Generates filled triangles from the path. A callback is invoked once for the entire tessellation.
double y
double x
float Scalar
Definition scalar.h:18
struct Vertices * Tessellate(PathBuilder *builder, int fill_type, Scalar tolerance)
FillType
Definition path.h:29
TPoint< Scalar > Point
Definition point.h:316
PathBuilder * CreatePathBuilder()
void DestroyPathBuilder(PathBuilder *builder)
void DestroyVertices(Vertices *vertices)
void MoveTo(PathBuilder *builder, Scalar x, Scalar y)
void LineTo(PathBuilder *builder, Scalar x, Scalar y)
void CubicTo(PathBuilder *builder, Scalar x1, Scalar y1, Scalar x2, Scalar y2, Scalar x3, Scalar y3)
void Close(PathBuilder *builder)