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 builder->SetFillType(static_cast<FillType>(fill_type));
46 auto path = builder->CopyPath();
47 std::vector<float> points;
49 path, tolerance,
50 [&points](const float* vertices, size_t vertices_count,
51 const uint16_t* indices, size_t indices_count) {
52 // Results are expected to be re-duplicated.
53 std::vector<Point> raw_points;
54 for (auto i = 0u; i < vertices_count * 2; i += 2) {
55 raw_points.emplace_back(Point{vertices[i], vertices[i + 1]});
56 }
57 for (auto i = 0u; i < indices_count; i++) {
58 auto point = raw_points[indices[i]];
59 points.push_back(point.x);
60 points.push_back(point.y);
61 }
62 return true;
64 return nullptr;
65 }
66
67 Vertices* vertices = new Vertices();
68 vertices->points = new float[points.size()];
69 if (!vertices->points) {
70 return nullptr;
71 }
72 vertices->length = points.size();
73 std::copy(points.begin(), points.end(), vertices->points);
74 return vertices;
75}
76
77void DestroyVertices(Vertices* vertices) {
78 delete vertices->points;
79 delete vertices;
80}
81
82} // namespace impeller
DlPathBuilder & LineTo(DlPoint p2)
Draw a line from the current point to the indicated point p2.
DlPathBuilder & MoveTo(DlPoint p2)
Start a new contour that will originate at the indicated point p2.
const DlPath CopyPath()
Returns the path constructed by this path builder so far and retains all current geometry to continue...
DlPathBuilder & SetFillType(DlPathFillType fill_type)
Set the fill type that should be used to determine the interior of this path to the indicated |fill_t...
DlPathBuilder & Close()
The path is closed back to the location of the most recent MoveTo call. Contours that are filled are ...
DlPathBuilder & CubicCurveTo(DlPoint cp1, DlPoint cp2, DlPoint p2)
Draw a cubic bezier curve from the current point to the indicated point p2, using the indicated point...
An extended tessellator that offers arbitrary/concave tessellation via the libtess2 library.
TessellatorLibtess::Result Tessellate(const PathSource &source, Scalar tolerance, const BuilderCallback &callback)
Generates filled triangles from the path. A callback is invoked once for the entire tessellation.
int32_t x
double y
float Scalar
Definition scalar.h:19
struct Vertices * Tessellate(PathBuilder *builder, int fill_type, Scalar tolerance)
TPoint< Scalar > Point
Definition point.h:327
PathBuilder * CreatePathBuilder()
void DestroyPathBuilder(PathBuilder *builder)
flutter::DlPathBuilder PathBuilder
Definition tessellator.h:22
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)
std::vector< Point > points