Flutter Engine
The Flutter Engine
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
21 builder->MoveTo(Point(x, y));
22}
23
25 builder->LineTo(Point(x, y));
26}
27
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
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[]
static void copy(void *dst, const uint8_t *src, int width, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
Definition: SkSwizzler.cpp:31
An extended tessellator that offers arbitrary/concave tessellation via the libtess2 library.
TessellatorLibtess::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
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57
float Scalar
Definition: scalar.h:18
struct Vertices * Tessellate(PathBuilder *builder, int fill_type, Scalar tolerance)
Definition: tessellator.cc:42
FillType
Definition: path.h:30
TPoint< Scalar > Point
Definition: point.h:322
PathBuilder * CreatePathBuilder()
Definition: tessellator.cc:12
void DestroyPathBuilder(PathBuilder *builder)
Definition: tessellator.cc:16
void DestroyVertices(Vertices *vertices)
Definition: tessellator.cc:76
void MoveTo(PathBuilder *builder, Scalar x, Scalar y)
Definition: tessellator.cc:20
void LineTo(PathBuilder *builder, Scalar x, Scalar y)
Definition: tessellator.cc:24
void CubicTo(PathBuilder *builder, Scalar x1, Scalar y1, Scalar x2, Scalar y2, Scalar x3, Scalar y3)
Definition: tessellator.cc:28
void Close(PathBuilder *builder)
Definition: tessellator.cc:38