|
| 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 | + |
| 9 | +namespace impeller { |
| 10 | +PathBuilder* CreatePathBuilder() { |
| 11 | + return new PathBuilder(); |
| 12 | +} |
| 13 | + |
| 14 | +void DestroyPathBuilder(PathBuilder* builder) { |
| 15 | + delete builder; |
| 16 | +} |
| 17 | + |
| 18 | +void MoveTo(PathBuilder* builder, Scalar x, Scalar y) { |
| 19 | + builder->MoveTo(Point(x, y)); |
| 20 | +} |
| 21 | + |
| 22 | +void LineTo(PathBuilder* builder, Scalar x, Scalar y) { |
| 23 | + builder->LineTo(Point(x, y)); |
| 24 | +} |
| 25 | + |
| 26 | +void CubicTo(PathBuilder* builder, |
| 27 | + Scalar x1, |
| 28 | + Scalar y1, |
| 29 | + Scalar x2, |
| 30 | + Scalar y2, |
| 31 | + Scalar x3, |
| 32 | + Scalar y3) { |
| 33 | + builder->CubicCurveTo(Point(x1, y1), Point(x2, y2), Point(x3, y3)); |
| 34 | +} |
| 35 | + |
| 36 | +void Close(PathBuilder* builder) { |
| 37 | + builder->Close(); |
| 38 | +} |
| 39 | + |
| 40 | +struct Vertices* Tessellate(PathBuilder* builder) { |
| 41 | + auto path = builder->CopyPath(); |
| 42 | + auto polyline = path.CreatePolyline(); |
| 43 | + |
| 44 | + std::vector<float> points; |
| 45 | + if (!Tessellator{path.GetFillType()}.Tessellate(polyline, |
| 46 | + [&points](Point vertex) { |
| 47 | + points.push_back(vertex.x); |
| 48 | + points.push_back(vertex.y); |
| 49 | + })) { |
| 50 | + return nullptr; |
| 51 | + } |
| 52 | + |
| 53 | + Vertices* vertices = new Vertices(); |
| 54 | + vertices->points = new float[points.size()]; |
| 55 | + if (!vertices->points) { |
| 56 | + return nullptr; |
| 57 | + } |
| 58 | + vertices->length = points.size(); |
| 59 | + std::copy(points.begin(), points.end(), vertices->points); |
| 60 | + return vertices; |
| 61 | +} |
| 62 | + |
| 63 | +void DestroyVertices(Vertices* vertices) { |
| 64 | + delete vertices->points; |
| 65 | + delete vertices; |
| 66 | +} |
| 67 | + |
| 68 | +} // namespace impeller |
0 commit comments