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 
11 #include "impeller/entity/entity.h"
12 #include "impeller/entity/texture_fill.vert.h"
15 
16 namespace impeller {
17 
18 class Tessellator;
19 
21  enum class Mode {
22  /// The geometry has no overlapping triangles.
23  kNormal,
24  /// The geometry may have overlapping triangles. The geometry should be
25  /// stenciled with the NonZero fill rule.
26  kNonZero,
27  /// The geometry may have overlapping triangles. The geometry should be
28  /// stenciled with the EvenOdd fill rule.
29  kEvenOdd,
30  /// The geometry may have overlapping triangles, but they should not
31  /// overdraw or cancel each other out. This is a special case for stroke
32  /// geometry.
34  };
35 
40 };
41 
42 static const GeometryResult kEmptyResult = {
43  .vertex_buffer =
44  {
46  },
47 };
48 
52  kUV,
53 };
54 
55 /// @brief Compute UV geometry for a VBB that contains only position geometry.
56 ///
57 /// texture_origin should be set to 0, 0 for stroke and stroke based geometry,
58 /// like the point field.
59 VertexBufferBuilder<TextureFillVertexShader::PerVertexData>
61  VertexBufferBuilder<SolidFillVertexShader::PerVertexData>& input,
62  Point texture_origin,
63  Size texture_coverage,
64  Matrix effect_transform);
65 
66 /// @brief Computes geometry and UV coordinates for a rectangle to be rendered.
67 ///
68 /// UV is the horizontal and vertical coordinates within the texture.
69 ///
70 /// @param source_rect The rectangle to be rendered.
71 /// @param texture_bounds The local space bounding box of the geometry.
72 /// @param effect_transform The transform to apply to the UV coordinates.
73 /// @param renderer The content context to use for allocating buffers.
74 /// @param entity The entity to use for the transform.
75 /// @param pass The render pass to use for the transform.
76 GeometryResult ComputeUVGeometryForRect(Rect source_rect,
77  Rect texture_bounds,
78  Matrix effect_transform,
79  const ContentContext& renderer,
80  const Entity& entity,
81  RenderPass& pass);
82 
83 class Geometry {
84  public:
85  static std::shared_ptr<Geometry> MakeFillPath(
86  const Path& path,
87  std::optional<Rect> inner_rect = std::nullopt);
88 
89  static std::shared_ptr<Geometry> MakeStrokePath(
90  const Path& path,
91  Scalar stroke_width = 0.0,
92  Scalar miter_limit = 4.0,
93  Cap stroke_cap = Cap::kButt,
94  Join stroke_join = Join::kMiter);
95 
96  static std::shared_ptr<Geometry> MakeCover();
97 
98  static std::shared_ptr<Geometry> MakeRect(const Rect& rect);
99 
100  static std::shared_ptr<Geometry> MakeOval(const Rect& rect);
101 
102  static std::shared_ptr<Geometry> MakeLine(const Point& p0,
103  const Point& p1,
104  Scalar width,
105  Cap cap);
106 
107  static std::shared_ptr<Geometry> MakeCircle(const Point& center,
108  Scalar radius);
109 
110  static std::shared_ptr<Geometry> MakeStrokedCircle(const Point& center,
111  Scalar radius,
113 
114  static std::shared_ptr<Geometry> MakeRoundRect(const Rect& rect,
115  const Size& radii);
116 
117  static std::shared_ptr<Geometry> MakePointField(std::vector<Point> points,
118  Scalar radius,
119  bool round);
120 
121  virtual GeometryResult GetPositionBuffer(const ContentContext& renderer,
122  const Entity& entity,
123  RenderPass& pass) const = 0;
124 
125  virtual GeometryResult GetPositionUVBuffer(Rect texture_coverage,
126  Matrix effect_transform,
127  const ContentContext& renderer,
128  const Entity& entity,
129  RenderPass& pass) const = 0;
130 
131  virtual GeometryResult::Mode GetResultMode() const;
132 
133  virtual GeometryVertexType GetVertexType() const = 0;
134 
135  virtual std::optional<Rect> GetCoverage(const Matrix& transform) const = 0;
136 
137  /// @brief Determines if this geometry, transformed by the given
138  /// `transform`, will completely cover all surface area of the given
139  /// `rect`.
140  ///
141  /// This is a conservative estimate useful for certain
142  /// optimizations.
143  ///
144  /// @returns `true` if the transformed geometry is guaranteed to cover the
145  /// given `rect`. May return `false` in many undetected cases where
146  /// the transformed geometry does in fact cover the `rect`.
147  virtual bool CoversArea(const Matrix& transform, const Rect& rect) const;
148 
149  virtual bool IsAxisAlignedRect() const;
150 
151  virtual bool CanApplyMaskFilter() const;
152 
153  protected:
155  const ContentContext& renderer,
156  const Tessellator::VertexGenerator& generator,
157  const Entity& entity,
158  RenderPass& pass);
159 
161  const ContentContext& renderer,
162  const Tessellator::VertexGenerator& generator,
163  const Matrix& uv_transform,
164  const Entity& entity,
165  RenderPass& pass);
166 };
167 
168 } // namespace impeller
169 
170 #endif // FLUTTER_IMPELLER_ENTITY_GEOMETRY_GEOMETRY_H_
impeller::GeometryResult::Mode::kNormal
@ kNormal
The geometry has no overlapping triangles.
impeller::VertexBuffer::index_type
IndexType index_type
Definition: vertex_buffer.h:29
impeller::Geometry::MakePointField
static std::shared_ptr< Geometry > MakePointField(std::vector< Point > points, Scalar radius, bool round)
Definition: geometry.cc:181
impeller::Geometry::MakeStrokedCircle
static std::shared_ptr< Geometry > MakeStrokedCircle(const Point &center, Scalar radius, Scalar stroke_width)
Definition: geometry.cc:224
impeller::Scalar
float Scalar
Definition: scalar.h:18
vertex_buffer.h
impeller::Geometry::MakeStrokePath
static std::shared_ptr< Geometry > MakeStrokePath(const Path &path, Scalar stroke_width=0.0, Scalar miter_limit=4.0, Cap stroke_cap=Cap::kButt, Join stroke_join=Join::kMiter)
Definition: geometry.cc:187
impeller::Geometry::MakeRoundRect
static std::shared_ptr< Geometry > MakeRoundRect(const Rect &rect, const Size &radii)
Definition: geometry.cc:230
entity.h
impeller::Geometry::GetCoverage
virtual std::optional< Rect > GetCoverage(const Matrix &transform) const =0
impeller::VertexBuffer
Definition: vertex_buffer.h:13
formats.h
impeller::Geometry::CanApplyMaskFilter
virtual bool CanApplyMaskFilter() const
Definition: geometry.cc:243
impeller::Geometry::IsAxisAlignedRect
virtual bool IsAxisAlignedRect() const
Definition: geometry.cc:239
impeller::Size
TSize< Scalar > Size
Definition: size.h:137
impeller::Geometry::GetResultMode
virtual GeometryResult::Mode GetResultMode() const
Definition: geometry.cc:171
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:235
impeller::Cap::kButt
@ kButt
impeller::GeometryResult::Mode::kEvenOdd
@ kEvenOdd
stroke_width
const Scalar stroke_width
Definition: stroke_path_geometry.cc:293
impeller::ComputeUVGeometryCPU
VertexBufferBuilder< TextureFillVertexShader::PerVertexData > ComputeUVGeometryCPU(VertexBufferBuilder< SolidFillVertexShader::PerVertexData > &input, Point texture_origin, Size texture_coverage, Matrix effect_transform)
Compute UV geometry for a VBB that contains only position geometry.
Definition: geometry.cc:93
impeller::GeometryVertexType
GeometryVertexType
Definition: geometry.h:49
impeller::GeometryResult::Mode
Mode
Definition: geometry.h:21
impeller::Geometry::MakeOval
static std::shared_ptr< Geometry > MakeOval(const Rect &rect)
Definition: geometry.cc:208
impeller::Join::kMiter
@ kMiter
impeller::Geometry::ComputePositionGeometry
static GeometryResult ComputePositionGeometry(const ContentContext &renderer, const Tessellator::VertexGenerator &generator, const Entity &entity, RenderPass &pass)
Definition: geometry.cc:25
impeller::kColor
@ kColor
Definition: geometry.h:51
impeller::Entity
Definition: entity.h:21
impeller::Geometry::MakeFillPath
static std::shared_ptr< Geometry > MakeFillPath(const Path &path, std::optional< Rect > inner_rect=std::nullopt)
Definition: geometry.cc:175
impeller::TSize< Scalar >
impeller::Tessellator::VertexGenerator
An object which produces a list of vertices as |Point|s that tessellate a previously provided shape a...
Definition: tessellator.h:93
impeller::PrimitiveType::kTriangleStrip
@ kTriangleStrip
impeller::PrimitiveType
PrimitiveType
Decides how backend draws pixels based on input vertices.
Definition: formats.h:353
impeller::Point
TPoint< Scalar > Point
Definition: point.h:316
render_pass.h
impeller::GeometryResult::type
PrimitiveType type
Definition: geometry.h:36
impeller::Geometry::GetPositionBuffer
virtual GeometryResult GetPositionBuffer(const ContentContext &renderer, const Entity &entity, RenderPass &pass) const =0
impeller::Path
Paths are lightweight objects that describe a collection of linear, quadratic, or cubic segments....
Definition: path.h:51
impeller::Geometry::ComputePositionUVGeometry
static GeometryResult ComputePositionUVGeometry(const ContentContext &renderer, const Tessellator::VertexGenerator &generator, const Matrix &uv_transform, const Entity &entity, RenderPass &pass)
Definition: geometry.cc:57
impeller::Geometry::GetPositionUVBuffer
virtual GeometryResult GetPositionUVBuffer(Rect texture_coverage, Matrix effect_transform, const ContentContext &renderer, const Entity &entity, RenderPass &pass) const =0
Definition: geometry.cc:163
impeller::GeometryResult
Definition: geometry.h:20
impeller::IndexType::kNone
@ kNone
Does not use the index buffer.
impeller::Rect
TRect< Scalar > Rect
Definition: rect.h:661
impeller::Geometry::GetVertexType
virtual GeometryVertexType GetVertexType() const =0
impeller::kUV
@ kUV
Definition: geometry.h:52
impeller::RenderPass
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition: render_pass.h:33
impeller::Geometry::MakeRect
static std::shared_ptr< Geometry > MakeRect(const Rect &rect)
Definition: geometry.cc:204
impeller::GeometryResult::transform
Matrix transform
Definition: geometry.h:38
content_context.h
impeller::Geometry
Definition: geometry.h:83
impeller::Join
Join
Definition: path.h:23
impeller::kEmptyResult
static const GeometryResult kEmptyResult
Definition: geometry.h:42
impeller::TPoint< Scalar >
impeller::GeometryResult::Mode::kPreventOverdraw
@ kPreventOverdraw
impeller::ComputeUVGeometryForRect
GeometryResult ComputeUVGeometryForRect(Rect source_rect, Rect texture_bounds, Matrix effect_transform, const ContentContext &renderer, const Entity &entity, RenderPass &pass)
Computes geometry and UV coordinates for a rectangle to be rendered.
Definition: geometry.cc:113
impeller::Geometry::MakeCircle
static std::shared_ptr< Geometry > MakeCircle(const Point &center, Scalar radius)
Definition: geometry.cc:219
impeller::GeometryResult::vertex_buffer
VertexBuffer vertex_buffer
Definition: geometry.h:37
impeller
Definition: aiks_blur_unittests.cc:20
impeller::kPosition
@ kPosition
Definition: geometry.h:50
impeller::ContentContext
Definition: content_context.h:392
impeller::TRect< Scalar >
impeller::GeometryResult::mode
Mode mode
Definition: geometry.h:39
impeller::Matrix
A 4x4 matrix using column-major storage.
Definition: matrix.h:37
impeller::Cap
Cap
Definition: path.h:17
impeller::GeometryResult::Mode::kNonZero
@ kNonZero
impeller::Geometry::MakeCover
static std::shared_ptr< Geometry > MakeCover()
Definition: geometry.cc:200
vertex_buffer_builder.h
impeller::Geometry::MakeLine
static std::shared_ptr< Geometry > MakeLine(const Point &p0, const Point &p1, Scalar width, Cap cap)
Definition: geometry.cc:212