| Flutter Impeller |

compute_tessellator.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_RENDERER_COMPUTE_TESSELLATOR_H_
6 #define FLUTTER_IMPELLER_RENDERER_COMPUTE_TESSELLATOR_H_
7
8 #include "flutter/fml/macros.h"
9 #include "impeller/core/buffer_view.h"
10 #include "impeller/geometry/path.h"
11 #include "impeller/renderer/command_buffer.h"
12 #include "impeller/renderer/context.h"
13
14 namespace impeller {
15
16 //------------------------------------------------------------------------------
17 /// @brief A utility that generates triangles of the specified fill type
18 /// given a path.
19 ///
20 class ComputeTessellator {
21 public:
22 ComputeTessellator();
23
24 ~ComputeTessellator();
25
26 static constexpr size_t kMaxCubicCount = 512;
27 static constexpr size_t kMaxQuadCount = 2048;
28 static constexpr size_t kMaxLineCount = 4096;
29 static constexpr size_t kMaxComponentCount =
30 kMaxCubicCount + kMaxQuadCount + kMaxLineCount;
31
32 enum class Status {
33 kCommandInvalid,
34 kTooManyComponents,
35 kOk,
36 };
37
38 enum class Style {
39 kStroke,
40 // TODO(dnfield): Implement kFill.
41 };
42
43 ComputeTessellator& SetStyle(Style value);
44 ComputeTessellator& SetStrokeWidth(Scalar value);
45 ComputeTessellator& SetStrokeJoin(Join value);
46 ComputeTessellator& SetStrokeCap(Cap value);
47 ComputeTessellator& SetMiterLimit(Scalar value);
48 ComputeTessellator& SetCubicAccuracy(Scalar value);
49 ComputeTessellator& SetQuadraticTolerance(Scalar value);
50
51 //----------------------------------------------------------------------------
52 /// @brief Generates triangles from the path.
53 /// If the data needs to be synchronized back to the CPU, e.g.
54 /// because one of the buffer views are host visible and will be
55 /// used without creating a blit pass to copy them back, the
56 /// callback is used to determine when the GPU calculation is
57 /// complete and its status.
58 /// On Metal, no additional synchronization is needed as long as
59 /// the buffers are not heap allocated, so no additional
60 /// synchronization mechanism is provided.
61 ///
62 /// @return A |Status| value indicating success or failure of the submission.
63 ///
64 // TODO(dnfield): Provide additional synchronization methods here for Vulkan
65 // and heap allocated buffers on Metal.
66 Status Tessellate(
67 const Path& path,
68 const std::shared_ptr<Context>& context,
69 BufferView vertex_buffer,
70 BufferView vertex_buffer_count,
71 const CommandBuffer::CompletionCallback& callback = nullptr) const;
72
73 private:
74 Style style_ = Style::kStroke;
75 Scalar stroke_width_ = 1.0f;
76 Cap stroke_cap_ = Cap::kButt;
77 Join stroke_join_ = Join::kMiter;
78 Scalar miter_limit_ = 4.0f;
79 Scalar cubic_accuracy_ = kDefaultCurveTolerance;
80 Scalar quad_tolerance_ = .1f;
81
82 ComputeTessellator(const ComputeTessellator&) = delete;
83
84 ComputeTessellator& operator=(const ComputeTessellator&) = delete;
85 };
86
87 } // namespace impeller
88
89 #endif // FLUTTER_IMPELLER_RENDERER_COMPUTE_TESSELLATOR_H_
impeller::ComputeTessellator::Status::kCommandInvalid
@ kCommandInvalid
path.h
impeller::Scalar
float Scalar
Definition: scalar.h:18
impeller::ComputeTessellator::Status::kTooManyComponents
@ kTooManyComponents
impeller::kDefaultCurveTolerance
static constexpr Scalar kDefaultCurveTolerance
Definition: path_component.h:26
impeller::ComputeTessellator::Status
Status
Definition: compute_tessellator.h:32
impeller::ComputeTessellator::SetStrokeCap
ComputeTessellator & SetStrokeCap(Cap value)
Definition: compute_tessellator.cc:46
impeller::ComputeTessellator::SetQuadraticTolerance
ComputeTessellator & SetQuadraticTolerance(Scalar value)
Definition: compute_tessellator.cc:58
impeller::ComputeTessellator::kMaxCubicCount
static constexpr size_t kMaxCubicCount
Definition: compute_tessellator.h:26
impeller::Cap::kButt
@ kButt
impeller::ComputeTessellator::SetMiterLimit
ComputeTessellator & SetMiterLimit(Scalar value)
Definition: compute_tessellator.cc:50
impeller::CommandBuffer::CompletionCallback
std::function< void(Status)> CompletionCallback
Definition: command_buffer.h:55
impeller::Join::kMiter
@ kMiter
impeller::ComputeTessellator
A utility that generates triangles of the specified fill type given a path.
Definition: compute_tessellator.h:20
impeller::ComputeTessellator::SetStrokeJoin
ComputeTessellator & SetStrokeJoin(Join value)
Definition: compute_tessellator.cc:42
impeller::ComputeTessellator::Style::kStroke
@ kStroke
impeller::ComputeTessellator::Status::kOk
@ kOk
impeller::ComputeTessellator::SetCubicAccuracy
ComputeTessellator & SetCubicAccuracy(Scalar value)
Definition: compute_tessellator.cc:54
impeller::ComputeTessellator::Style
Style
Definition: compute_tessellator.h:38
impeller::Path
Paths are lightweight objects that describe a collection of linear, quadratic, or cubic segments....
Definition: path.h:55
impeller::ComputeTessellator::SetStrokeWidth
ComputeTessellator & SetStrokeWidth(Scalar value)
Definition: compute_tessellator.cc:37
impeller::ComputeTessellator::kMaxComponentCount
static constexpr size_t kMaxComponentCount
Definition: compute_tessellator.h:29
impeller::ComputeTessellator::Tessellate
Status Tessellate(const Path &path, const std::shared_ptr< Context > &context, BufferView vertex_buffer, BufferView vertex_buffer_count, const CommandBuffer::CompletionCallback &callback=nullptr) const
Generates triangles from the path. If the data needs to be synchronized back to the CPU,...
Definition: compute_tessellator.cc:63
impeller::ComputeTessellator::kMaxQuadCount
static constexpr size_t kMaxQuadCount
Definition: compute_tessellator.h:27
impeller::ComputeTessellator::SetStyle
ComputeTessellator & SetStyle(Style value)
Definition: compute_tessellator.cc:32
command_buffer.h
impeller::BufferView
Definition: buffer_view.h:13
impeller::Join
Join
Definition: path.h:24
buffer_view.h
impeller::ComputeTessellator::kMaxLineCount
static constexpr size_t kMaxLineCount
Definition: compute_tessellator.h:28
context.h
impeller::ComputeTessellator::~ComputeTessellator
~ComputeTessellator()
impeller::ComputeTessellator::ComputeTessellator
ComputeTessellator()
impeller
Definition: aiks_context.cc:10
impeller::Cap
Cap
Definition: path.h:18