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 
25 };
26 
27 static const GeometryResult kEmptyResult = {
28  .vertex_buffer =
29  {
31  },
32 };
33 
37  kUV,
38 };
39 
40 /// @brief Compute UV geometry for a VBB that contains only position geometry.
41 ///
42 /// texture_origin should be set to 0, 0 for stroke and stroke based geometry,
43 /// like the point field.
44 VertexBufferBuilder<TextureFillVertexShader::PerVertexData>
46  VertexBufferBuilder<SolidFillVertexShader::PerVertexData>& input,
47  Point texture_origin,
48  Size texture_coverage,
49  Matrix effect_transform);
50 
51 GeometryResult ComputeUVGeometryForRect(Rect source_rect,
52  Rect texture_coverage,
53  Matrix effect_transform,
54  const ContentContext& renderer,
55  const Entity& entity,
56  RenderPass& pass);
57 
58 class Geometry {
59  public:
60  static std::shared_ptr<Geometry> MakeFillPath(
61  Path path,
62  std::optional<Rect> inner_rect = std::nullopt);
63 
64  static std::shared_ptr<Geometry> MakeStrokePath(
65  Path path,
66  Scalar stroke_width = 0.0,
67  Scalar miter_limit = 4.0,
68  Cap stroke_cap = Cap::kButt,
69  Join stroke_join = Join::kMiter);
70 
71  static std::shared_ptr<Geometry> MakeCover();
72 
73  static std::shared_ptr<Geometry> MakeRect(const Rect& rect);
74 
75  static std::shared_ptr<Geometry> MakeOval(const Rect& rect);
76 
77  static std::shared_ptr<Geometry> MakeLine(const Point& p0,
78  const Point& p1,
79  Scalar width,
80  Cap cap);
81 
82  static std::shared_ptr<Geometry> MakeCircle(const Point& center,
83  Scalar radius);
84 
85  static std::shared_ptr<Geometry> MakeStrokedCircle(const Point& center,
86  Scalar radius,
87  Scalar stroke_width);
88 
89  static std::shared_ptr<Geometry> MakeRoundRect(const Rect& rect,
90  const Size& radii);
91 
92  static std::shared_ptr<Geometry> MakePointField(std::vector<Point> points,
93  Scalar radius,
94  bool round);
95 
96  virtual GeometryResult GetPositionBuffer(const ContentContext& renderer,
97  const Entity& entity,
98  RenderPass& pass) const = 0;
99 
100  virtual GeometryResult GetPositionUVBuffer(Rect texture_coverage,
101  Matrix effect_transform,
102  const ContentContext& renderer,
103  const Entity& entity,
104  RenderPass& pass) const = 0;
105 
106  virtual GeometryVertexType GetVertexType() const = 0;
107 
108  virtual std::optional<Rect> GetCoverage(const Matrix& transform) const = 0;
109 
110  /// @brief Determines if this geometry, transformed by the given
111  /// `transform`, will completely cover all surface area of the given
112  /// `rect`.
113  ///
114  /// This is a conservative estimate useful for certain
115  /// optimizations.
116  ///
117  /// @returns `true` if the transformed geometry is guaranteed to cover the
118  /// given `rect`. May return `false` in many undetected cases where
119  /// the transformed geometry does in fact cover the `rect`.
120  virtual bool CoversArea(const Matrix& transform, const Rect& rect) const;
121 
122  virtual bool IsAxisAlignedRect() const;
123 
124  protected:
126  const Tessellator::VertexGenerator& generator,
127  const Entity& entity,
128  RenderPass& pass);
129 
131  const Tessellator::VertexGenerator& generator,
132  const Matrix& uv_transform,
133  const Entity& entity,
134  RenderPass& pass);
135 };
136 
137 } // namespace impeller
138 
139 #endif // FLUTTER_IMPELLER_ENTITY_GEOMETRY_GEOMETRY_H_
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:156
impeller::Geometry::MakeStrokedCircle
static std::shared_ptr< Geometry > MakeStrokedCircle(const Point &center, Scalar radius, Scalar stroke_width)
Definition: geometry.cc:199
impeller::Scalar
float Scalar
Definition: scalar.h:18
vertex_buffer.h
impeller::Geometry::MakeRoundRect
static std::shared_ptr< Geometry > MakeRoundRect(const Rect &rect, const Size &radii)
Definition: geometry.cc:205
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::IsAxisAlignedRect
virtual bool IsAxisAlignedRect() const
Definition: geometry.cc:214
impeller::Size
TSize< Scalar > Size
Definition: size.h:137
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:210
impeller::Cap::kButt
@ kButt
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:91
impeller::GeometryVertexType
GeometryVertexType
Definition: geometry.h:34
impeller::Geometry::MakeStrokePath
static std::shared_ptr< Geometry > MakeStrokePath(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:162
impeller::Geometry::MakeOval
static std::shared_ptr< Geometry > MakeOval(const Rect &rect)
Definition: geometry.cc:183
impeller::Join::kMiter
@ kMiter
impeller::GeometryResult::prevent_overdraw
bool prevent_overdraw
Definition: geometry.h:24
impeller::kColor
@ kColor
Definition: geometry.h:36
impeller::Entity
Definition: entity.h:21
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:99
impeller::PrimitiveType
PrimitiveType
Decides how backend draws pixels based on input vertices.
Definition: formats.h:350
impeller::Point
TPoint< Scalar > Point
Definition: point.h:308
render_pass.h
impeller::GeometryResult::type
PrimitiveType type
Definition: geometry.h:21
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:55
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:142
impeller::GeometryResult
Definition: geometry.h:20
impeller::IndexType::kNone
@ kNone
Does not use the index buffer.
impeller::Geometry::ComputePositionGeometry
static GeometryResult ComputePositionGeometry(const Tessellator::VertexGenerator &generator, const Entity &entity, RenderPass &pass)
Definition: geometry.cc:23
impeller::Rect
TRect< Scalar > Rect
Definition: rect.h:488
impeller::Geometry::GetVertexType
virtual GeometryVertexType GetVertexType() const =0
impeller::kUV
@ kUV
Definition: geometry.h:37
impeller::Geometry::MakeFillPath
static std::shared_ptr< Geometry > MakeFillPath(Path path, std::optional< Rect > inner_rect=std::nullopt)
Definition: geometry.cc:150
impeller::RenderPass
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition: render_pass.h:29
impeller::Geometry::MakeRect
static std::shared_ptr< Geometry > MakeRect(const Rect &rect)
Definition: geometry.cc:179
impeller::GeometryResult::transform
Matrix transform
Definition: geometry.h:23
content_context.h
impeller::Geometry
Definition: geometry.h:58
impeller::Join
Join
Definition: path.h:24
impeller::kEmptyResult
static const GeometryResult kEmptyResult
Definition: geometry.h:27
impeller::TPoint< Scalar >
impeller::Geometry::MakeCircle
static std::shared_ptr< Geometry > MakeCircle(const Point &center, Scalar radius)
Definition: geometry.cc:194
impeller::GeometryResult::vertex_buffer
VertexBuffer vertex_buffer
Definition: geometry.h:22
impeller::ComputeUVGeometryForRect
GeometryResult ComputeUVGeometryForRect(Rect source_rect, Rect texture_coverage, Matrix effect_transform, const ContentContext &renderer, const Entity &entity, RenderPass &pass)
Definition: geometry.cc:111
impeller
Definition: aiks_context.cc:10
impeller::Geometry::ComputePositionUVGeometry
static GeometryResult ComputePositionUVGeometry(const Tessellator::VertexGenerator &generator, const Matrix &uv_transform, const Entity &entity, RenderPass &pass)
Definition: geometry.cc:55
impeller::kPosition
@ kPosition
Definition: geometry.h:35
impeller::ContentContext
Definition: content_context.h:332
impeller::TRect< Scalar >
impeller::Matrix
A 4x4 matrix using column-major storage.
Definition: matrix.h:37
impeller::Cap
Cap
Definition: path.h:18
impeller::Geometry::MakeCover
static std::shared_ptr< Geometry > MakeCover()
Definition: geometry.cc:175
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:187