| Flutter Impeller |

geometry.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_ENTITY_GEOMETRY_GEOMETRY_H_
6 #define FLUTTER_IMPELLER_ENTITY_GEOMETRY_GEOMETRY_H_
7
8 #include "impeller/core/formats.h"
9 #include "impeller/core/vertex_buffer.h"
10 #include "impeller/entity/contents/content_context.h"
11 #include "impeller/entity/entity.h"
12 #include "impeller/geometry/stroke_parameters.h"
13 #include "impeller/renderer/render_pass.h"
14 #include "impeller/renderer/vertex_buffer_builder.h"
15
16 namespace impeller {
17
18 [[maybe_unused]]
19 static constexpr Scalar kMinStrokeSize = 1.0f;
20
21 struct GeometryResult {
22 enum class Mode {
23 /// The geometry has no overlapping triangles.
24 kNormal,
25 /// The geometry may have overlapping triangles. The geometry should be
26 /// stenciled with the NonZero fill rule.
27 kNonZero,
28 /// The geometry may have overlapping triangles. The geometry should be
29 /// stenciled with the EvenOdd fill rule.
30 kEvenOdd,
31 /// The geometry may have overlapping triangles, but they should not
32 /// overdraw or cancel each other out. This is a special case for stroke
33 /// geometry.
34 kPreventOverdraw,
35 };
36
37 PrimitiveType type = PrimitiveType::kTriangleStrip;
38 VertexBuffer vertex_buffer;
39 Matrix transform;
40 Mode mode = Mode::kNormal;
41 };
42
43 static const GeometryResult kEmptyResult = {
44 .vertex_buffer =
45 {
46 .index_type = IndexType::kNone,
47 },
48 };
49
50 class Geometry {
51 public:
52 virtual ~Geometry() {}
53
54 static std::unique_ptr<Geometry> MakeFillPath(
55 const flutter::DlPath& path,
56 std::optional<Rect> inner_rect = std::nullopt);
57
58 static std::unique_ptr<Geometry> MakeStrokePath(
59 const flutter::DlPath& path,
60 const StrokeParameters& stroke = {});
61
62 static std::unique_ptr<Geometry> MakeCover();
63
64 static std::unique_ptr<Geometry> MakeRect(const Rect& rect);
65
66 static std::unique_ptr<Geometry> MakeOval(const Rect& rect);
67
68 static std::unique_ptr<Geometry> MakeLine(const Point& p0,
69 const Point& p1,
70 const StrokeParameters& stroke);
71
72 static std::unique_ptr<Geometry> MakeCircle(const Point& center,
73 Scalar radius);
74
75 static std::unique_ptr<Geometry> MakeStrokedCircle(const Point& center,
76 Scalar radius,
77 Scalar stroke_width);
78
79 static std::unique_ptr<Geometry> MakeFilledArc(const Rect& oval_bounds,
80 Degrees start,
81 Degrees sweep,
82 bool include_center);
83
84 static std::unique_ptr<Geometry> MakeStrokedArc(
85 const Rect& oval_bounds,
86 Degrees start,
87 Degrees sweep,
88 const StrokeParameters& stroke);
89
90 static std::unique_ptr<Geometry> MakeRoundRect(const Rect& rect,
91 const Size& radii);
92
93 static std::unique_ptr<Geometry> MakeRoundSuperellipse(const Rect& rect,
94 Scalar corner_radius);
95
96 virtual GeometryResult GetPositionBuffer(const ContentContext& renderer,
97 const Entity& entity,
98 RenderPass& pass) const = 0;
99
100 virtual GeometryResult::Mode GetResultMode() const;
101
102 virtual std::optional<Rect> GetCoverage(const Matrix& transform) const = 0;
103
104 /// @brief Compute an alpha value to simulate lower coverage of fractional
105 /// pixel strokes.
106 static Scalar ComputeStrokeAlphaCoverage(const Matrix& entity,
107 Scalar stroke_width);
108
109 /// @brief Determines if this geometry, transformed by the given
110 /// `transform`, will completely cover all surface area of the given
111 /// `rect`.
112 ///
113 /// This is a conservative estimate useful for certain
114 /// optimizations.
115 ///
116 /// @returns `true` if the transformed geometry is guaranteed to cover the
117 /// given `rect`. May return `false` in many undetected cases where
118 /// the transformed geometry does in fact cover the `rect`.
119 virtual bool CoversArea(const Matrix& transform, const Rect& rect) const;
120
121 virtual bool IsAxisAlignedRect() const;
122
123 virtual bool CanApplyMaskFilter() const;
124
125 virtual Scalar ComputeAlphaCoverage(const Matrix& transform) const {
126 return 1.0;
127 }
128
129 static GeometryResult ComputePositionGeometry(
130 const ContentContext& renderer,
131 const Tessellator::VertexGenerator& generator,
132 const Entity& entity,
133 RenderPass& pass);
134 };
135
136 } // namespace impeller
137
138 #endif // FLUTTER_IMPELLER_ENTITY_GEOMETRY_GEOMETRY_H_
impeller::ContentContext
Definition: content_context.h:122
impeller::Entity
Definition: entity.h:26
impeller::Geometry
Definition: geometry.h:50
impeller::Geometry::ComputeAlphaCoverage
virtual Scalar ComputeAlphaCoverage(const Matrix &transform) const
Definition: geometry.h:125
impeller::Geometry::MakeFillPath
static std::unique_ptr< Geometry > MakeFillPath(const flutter::DlPath &path, std::optional< Rect > inner_rect=std::nullopt)
Definition: geometry.cc:62
impeller::Geometry::ComputeStrokeAlphaCoverage
static Scalar ComputeStrokeAlphaCoverage(const Matrix &entity, Scalar stroke_width)
Compute an alpha value to simulate lower coverage of fractional pixel strokes.
Definition: geometry.cc:149
impeller::Geometry::GetResultMode
virtual GeometryResult::Mode GetResultMode() const
Definition: geometry.cc:58
impeller::Geometry::MakeRect
static std::unique_ptr< Geometry > MakeRect(const Rect &rect)
Definition: geometry.cc:83
impeller::Geometry::MakeFilledArc
static std::unique_ptr< Geometry > MakeFilledArc(const Rect &oval_bounds, Degrees start, Degrees sweep, bool include_center)
Definition: geometry.cc:108
impeller::Geometry::MakeStrokePath
static std::unique_ptr< Geometry > MakeStrokePath(const flutter::DlPath &path, const StrokeParameters &stroke={})
Definition: geometry.cc:68
impeller::Geometry::MakeCircle
static std::unique_ptr< Geometry > MakeCircle(const Point &center, Scalar radius)
Definition: geometry.cc:97
impeller::Geometry::GetPositionBuffer
virtual GeometryResult GetPositionBuffer(const ContentContext &renderer, const Entity &entity, RenderPass &pass) const =0
impeller::Geometry::CanApplyMaskFilter
virtual bool CanApplyMaskFilter() const
Definition: geometry.cc:144
impeller::Geometry::MakeRoundRect
static std::unique_ptr< Geometry > MakeRoundRect(const Rect &rect, const Size &radii)
Definition: geometry.cc:125
impeller::Geometry::ComputePositionGeometry
static GeometryResult ComputePositionGeometry(const ContentContext &renderer, const Tessellator::VertexGenerator &generator, const Entity &entity, RenderPass &pass)
Definition: geometry.cc:26
impeller::Geometry::GetCoverage
virtual std::optional< Rect > GetCoverage(const Matrix &transform) const =0
impeller::Geometry::CoversArea
virtual bool CoversArea(const Matrix &transform, const Rect &rect) const
Determines if this geometry, transformed by the given transform, will completely cover all surface ar...
Definition: geometry.cc:136
impeller::Geometry::MakeLine
static std::unique_ptr< Geometry > MakeLine(const Point &p0, const Point &p1, const StrokeParameters &stroke)
Definition: geometry.cc:91
impeller::Geometry::MakeOval
static std::unique_ptr< Geometry > MakeOval(const Rect &rect)
Definition: geometry.cc:87
impeller::Geometry::MakeStrokedCircle
static std::unique_ptr< Geometry > MakeStrokedCircle(const Point &center, Scalar radius, Scalar stroke_width)
Definition: geometry.cc:102
impeller::Geometry::MakeRoundSuperellipse
static std::unique_ptr< Geometry > MakeRoundSuperellipse(const Rect &rect, Scalar corner_radius)
Definition: geometry.cc:130
impeller::Geometry::~Geometry
virtual ~Geometry()
Definition: geometry.h:52
impeller::Geometry::MakeCover
static std::unique_ptr< Geometry > MakeCover()
Definition: geometry.cc:79
impeller::Geometry::MakeStrokedArc
static std::unique_ptr< Geometry > MakeStrokedArc(const Rect &oval_bounds, Degrees start, Degrees sweep, const StrokeParameters &stroke)
Definition: geometry.cc:116
impeller::Geometry::IsAxisAlignedRect
virtual bool IsAxisAlignedRect() const
Definition: geometry.cc:140
impeller::RenderPass
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition: render_pass.h:30
impeller::Tessellator::VertexGenerator
An object which produces a list of vertices as |Point|s that tessellate a previously provided shape a...
Definition: tessellator.h:110
content_context.h
formats.h
entity.h
transform
Matrix transform
Definition: gaussian_blur_filter_contents.cc:312
impeller
Definition: allocation.cc:12
impeller::PrimitiveType
PrimitiveType
Decides how backend draws pixels based on input vertices.
Definition: formats.h:355
impeller::PrimitiveType::kTriangleStrip
@ kTriangleStrip
impeller::Scalar
float Scalar
Definition: scalar.h:19
impeller::IndexType::kNone
@ kNone
Does not use the index buffer.
impeller::Rect
TRect< Scalar > Rect
Definition: rect.h:788
impeller::Point
TPoint< Scalar > Point
Definition: point.h:425
impeller::kEmptyResult
static const GeometryResult kEmptyResult
Definition: geometry.h:43
impeller::DlPath
flutter::DlPath DlPath
Definition: dl_dispatcher.h:29
impeller::Size
TSize< Scalar > Size
Definition: size.h:159
impeller::kMinStrokeSize
static constexpr Scalar kMinStrokeSize
Definition: geometry.h:19
render_pass.h
stroke_parameters.h
impeller::GeometryResult
Definition: geometry.h:21
impeller::GeometryResult::type
PrimitiveType type
Definition: geometry.h:37
impeller::GeometryResult::Mode
Mode
Definition: geometry.h:22
impeller::GeometryResult::Mode::kNormal
@ kNormal
The geometry has no overlapping triangles.
impeller::GeometryResult::Mode::kEvenOdd
@ kEvenOdd
impeller::GeometryResult::Mode::kPreventOverdraw
@ kPreventOverdraw
impeller::GeometryResult::Mode::kNonZero
@ kNonZero
impeller::GeometryResult::transform
Matrix transform
Definition: geometry.h:39
impeller::GeometryResult::vertex_buffer
VertexBuffer vertex_buffer
Definition: geometry.h:38
impeller::GeometryResult::mode
Mode mode
Definition: geometry.h:40
impeller::Matrix
A 4x4 matrix using column-major storage.
Definition: matrix.h:37
impeller::StrokeParameters
A structure to store all of the parameters related to stroking a path or basic geometry object.
Definition: stroke_parameters.h:28
impeller::TRect< Scalar >
impeller::VertexBuffer
Definition: vertex_buffer.h:15
impeller::VertexBuffer::index_type
IndexType index_type
Definition: vertex_buffer.h:31
start
const size_t start
Definition: tessellator_libtess.cc:62
vertex_buffer.h
vertex_buffer_builder.h