| 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 HostBuffer& host_buffer,
69 const std::shared_ptr<Context>& context,
70 BufferView vertex_buffer,
71 BufferView vertex_buffer_count,
72 const CommandBuffer::CompletionCallback& callback = nullptr) const;
73
74 private:
75 Style style_ = Style::kStroke;
76 Scalar stroke_width_ = 1.0f;
77 Cap stroke_cap_ = Cap::kButt;
78 Join stroke_join_ = Join::kMiter;
79 Scalar miter_limit_ = 4.0f;
80 Scalar cubic_accuracy_ = kDefaultCurveTolerance;
81 Scalar quad_tolerance_ = .1f;
82
83 ComputeTessellator(const ComputeTessellator&) = delete;
84
85 ComputeTessellator& operator=(const ComputeTessellator&) = delete;
86 };
87
88 } // namespace impeller
89
90 #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:27
impeller::ComputeTessellator::Status
Status
Definition: compute_tessellator.h:32
impeller::HostBuffer
Definition: host_buffer.h:28
impeller::ComputeTessellator::SetStrokeCap
ComputeTessellator & SetStrokeCap(Cap value)
Definition: compute_tessellator.cc:47
impeller::ComputeTessellator::SetQuadraticTolerance
ComputeTessellator & SetQuadraticTolerance(Scalar value)
Definition: compute_tessellator.cc:59
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:51
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:43
impeller::ComputeTessellator::Style::kStroke
@ kStroke
impeller::ComputeTessellator::Status::kOk
@ kOk
impeller::ComputeTessellator::SetCubicAccuracy
ComputeTessellator & SetCubicAccuracy(Scalar value)
Definition: compute_tessellator.cc:55
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:51
impeller::ComputeTessellator::SetStrokeWidth
ComputeTessellator & SetStrokeWidth(Scalar value)
Definition: compute_tessellator.cc:38
impeller::ComputeTessellator::kMaxComponentCount
static constexpr size_t kMaxComponentCount
Definition: compute_tessellator.h:29
impeller::ComputeTessellator::kMaxQuadCount
static constexpr size_t kMaxQuadCount
Definition: compute_tessellator.h:27
impeller::ComputeTessellator::SetStyle
ComputeTessellator & SetStyle(Style value)
Definition: compute_tessellator.cc:33
command_buffer.h
impeller::BufferView
Definition: buffer_view.h:15
impeller::Join
Join
Definition: path.h:23
buffer_view.h
impeller::ComputeTessellator::Tessellate
Status Tessellate(const Path &path, HostBuffer &host_buffer, 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:64
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_blur_unittests.cc:20
impeller::Cap
Cap
Definition: path.h:17