Flutter Impeller
tessellator_libtess.h
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 #ifndef FLUTTER_IMPELLER_TESSELLATOR_TESSELLATOR_LIBTESS_H_
6 #define FLUTTER_IMPELLER_TESSELLATOR_TESSELLATOR_LIBTESS_H_
7 
8 #include <functional>
9 #include <memory>
10 
11 #include "impeller/geometry/path.h"
12 
13 struct TESStesselator;
14 
15 namespace impeller {
16 
17 void DestroyTessellator(TESStesselator* tessellator);
18 
19 using CTessellator =
20  std::unique_ptr<TESStesselator, decltype(&DestroyTessellator)>;
21 
22 //------------------------------------------------------------------------------
23 /// @brief An extended tessellator that offers arbitrary/concave
24 /// tessellation via the libtess2 library.
25 ///
26 /// This object is not thread safe, and its methods must not be
27 /// called from multiple threads.
28 ///
30  public:
32 
34 
35  enum class Result {
36  kSuccess,
39  };
40 
41  /// @brief A callback that returns the results of the tessellation.
42  ///
43  /// The index buffer may not be populated, in which case [indices] will
44  /// be nullptr and indices_count will be 0.
45  using BuilderCallback = std::function<bool(const float* vertices,
46  size_t vertices_count,
47  const uint16_t* indices,
48  size_t indices_count)>;
49 
50  //----------------------------------------------------------------------------
51  /// @brief Generates filled triangles from the path. A callback is
52  /// invoked once for the entire tessellation.
53  ///
54  /// @param[in] path The path to tessellate.
55  /// @param[in] tolerance The tolerance value for conversion of the path to
56  /// a polyline. This value is often derived from the
57  /// Matrix::GetMaxBasisLength of the CTM applied to the
58  /// path for rendering.
59  /// @param[in] callback The callback, return false to indicate failure.
60  ///
61  /// @return The result status of the tessellation.
62  ///
64  Scalar tolerance,
65  const BuilderCallback& callback);
66 
67  private:
68  CTessellator c_tessellator_;
69 
70  TessellatorLibtess(const TessellatorLibtess&) = delete;
71 
72  TessellatorLibtess& operator=(const TessellatorLibtess&) = delete;
73 };
74 
75 } // namespace impeller
76 
77 #endif // FLUTTER_IMPELLER_TESSELLATOR_TESSELLATOR_LIBTESS_H_
path.h
impeller::TessellatorLibtess::Result
Result
Definition: tessellator_libtess.h:35
impeller::TessellatorLibtess::Result::kTessellationError
@ kTessellationError
impeller::Scalar
float Scalar
Definition: scalar.h:18
impeller::TessellatorLibtess::Result::kInputError
@ kInputError
impeller::TessellatorLibtess::~TessellatorLibtess
~TessellatorLibtess()
impeller::TessellatorLibtess::Tessellate
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.
Definition: tessellator_libtess.cc:56
impeller::Path
Paths are lightweight objects that describe a collection of linear, quadratic, or cubic segments....
Definition: path.h:52
impeller::DestroyTessellator
void DestroyTessellator(TESStesselator *tessellator)
Definition: tessellator_libtess.cc:163
impeller::TessellatorLibtess
An extended tessellator that offers arbitrary/concave tessellation via the libtess2 library.
Definition: tessellator_libtess.h:29
impeller::TessellatorLibtess::BuilderCallback
std::function< bool(const float *vertices, size_t vertices_count, const uint16_t *indices, size_t indices_count)> BuilderCallback
A callback that returns the results of the tessellation.
Definition: tessellator_libtess.h:48
impeller::TessellatorLibtess::TessellatorLibtess
TessellatorLibtess()
Definition: tessellator_libtess.cc:34
impeller
Definition: aiks_blend_unittests.cc:18
impeller::TessellatorLibtess::Result::kSuccess
@ kSuccess
impeller::CTessellator
std::unique_ptr< TESStesselator, decltype(&DestroyTessellator)> CTessellator
Definition: tessellator_libtess.h:20