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"
14 
15 namespace impeller {
16 
17 class Tessellator;
18 
20  enum class Mode {
21  /// The geometry has no overlapping triangles.
22  kNormal,
23  /// The geometry may have overlapping triangles. The geometry should be
24  /// stenciled with the NonZero fill rule.
25  kNonZero,
26  /// The geometry may have overlapping triangles. The geometry should be
27  /// stenciled with the EvenOdd fill rule.
28  kEvenOdd,
29  /// The geometry may have overlapping triangles, but they should not
30  /// overdraw or cancel each other out. This is a special case for stroke
31  /// geometry.
33  };
34 
39 };
40 
41 static const GeometryResult kEmptyResult = {
42  .vertex_buffer =
43  {
45  },
46 };
47 
48 class Geometry {
49  public:
50  static std::shared_ptr<Geometry> MakeFillPath(
51  const Path& path,
52  std::optional<Rect> inner_rect = std::nullopt);
53 
54  static std::shared_ptr<Geometry> MakeStrokePath(
55  const Path& path,
56  Scalar stroke_width = 0.0,
57  Scalar miter_limit = 4.0,
58  Cap stroke_cap = Cap::kButt,
59  Join stroke_join = Join::kMiter);
60 
61  static std::shared_ptr<Geometry> MakeCover();
62 
63  static std::shared_ptr<Geometry> MakeRect(const Rect& rect);
64 
65  static std::shared_ptr<Geometry> MakeOval(const Rect& rect);
66 
67  static std::shared_ptr<Geometry> MakeLine(const Point& p0,
68  const Point& p1,
69  Scalar width,
70  Cap cap);
71 
72  static std::shared_ptr<Geometry> MakeCircle(const Point& center,
73  Scalar radius);
74 
75  static std::shared_ptr<Geometry> MakeStrokedCircle(const Point& center,
76  Scalar radius,
78 
79  static std::shared_ptr<Geometry> MakeRoundRect(const Rect& rect,
80  const Size& radii);
81 
82  static std::shared_ptr<Geometry> MakePointField(std::vector<Point> points,
83  Scalar radius,
84  bool round);
85 
86  virtual GeometryResult GetPositionBuffer(const ContentContext& renderer,
87  const Entity& entity,
88  RenderPass& pass) const = 0;
89 
90  virtual GeometryResult::Mode GetResultMode() const;
91 
92  virtual std::optional<Rect> GetCoverage(const Matrix& transform) const = 0;
93 
94  /// @brief Determines if this geometry, transformed by the given
95  /// `transform`, will completely cover all surface area of the given
96  /// `rect`.
97  ///
98  /// This is a conservative estimate useful for certain
99  /// optimizations.
100  ///
101  /// @returns `true` if the transformed geometry is guaranteed to cover the
102  /// given `rect`. May return `false` in many undetected cases where
103  /// the transformed geometry does in fact cover the `rect`.
104  virtual bool CoversArea(const Matrix& transform, const Rect& rect) const;
105 
106  virtual bool IsAxisAlignedRect() const;
107 
108  virtual bool CanApplyMaskFilter() const;
109 
110  virtual Scalar ComputeAlphaCoverage(const Entity& entitys) const {
111  return 1.0;
112  }
113 
114  protected:
116  const ContentContext& renderer,
117  const Tessellator::VertexGenerator& generator,
118  const Entity& entity,
119  RenderPass& pass);
120 };
121 
122 } // namespace impeller
123 
124 #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:66
impeller::Geometry::MakeStrokedCircle
static std::shared_ptr< Geometry > MakeStrokedCircle(const Point &center, Scalar radius, Scalar stroke_width)
Definition: geometry.cc:109
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:72
impeller::Geometry::MakeRoundRect
static std::shared_ptr< Geometry > MakeRoundRect(const Rect &rect, const Size &radii)
Definition: geometry.cc:115
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:128
impeller::Geometry::IsAxisAlignedRect
virtual bool IsAxisAlignedRect() const
Definition: geometry.cc:124
impeller::Geometry::GetResultMode
virtual GeometryResult::Mode GetResultMode() const
Definition: geometry.cc:56
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:120
impeller::Cap::kButt
@ kButt
impeller::GeometryResult::Mode::kEvenOdd
@ kEvenOdd
stroke_width
const Scalar stroke_width
Definition: stroke_path_geometry.cc:304
impeller::GeometryResult::Mode
Mode
Definition: geometry.h:20
impeller::Geometry::MakeOval
static std::shared_ptr< Geometry > MakeOval(const Rect &rect)
Definition: geometry.cc:93
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:24
impeller::Entity
Definition: entity.h:20
impeller::Geometry::MakeFillPath
static std::shared_ptr< Geometry > MakeFillPath(const Path &path, std::optional< Rect > inner_rect=std::nullopt)
Definition: geometry.cc:60
impeller::TSize< Scalar >
impeller::Geometry::ComputeAlphaCoverage
virtual Scalar ComputeAlphaCoverage(const Entity &entitys) const
Definition: geometry.h:110
impeller::Tessellator::VertexGenerator
An object which produces a list of vertices as |Point|s that tessellate a previously provided shape a...
Definition: tessellator.h:91
impeller::PrimitiveType::kTriangleStrip
@ kTriangleStrip
impeller::PrimitiveType
PrimitiveType
Decides how backend draws pixels based on input vertices.
Definition: formats.h:352
render_pass.h
impeller::GeometryResult::type
PrimitiveType type
Definition: geometry.h:35
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:52
transform
Matrix transform
Definition: gaussian_blur_filter_contents.cc:231
impeller::GeometryResult
Definition: geometry.h:19
impeller::IndexType::kNone
@ kNone
Does not use the index buffer.
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:89
impeller::GeometryResult::transform
Matrix transform
Definition: geometry.h:37
content_context.h
impeller::Geometry
Definition: geometry.h:48
impeller::Join
Join
Definition: path.h:24
impeller::kEmptyResult
static const GeometryResult kEmptyResult
Definition: geometry.h:41
impeller::TPoint< Scalar >
impeller::GeometryResult::Mode::kPreventOverdraw
@ kPreventOverdraw
impeller::Geometry::MakeCircle
static std::shared_ptr< Geometry > MakeCircle(const Point &center, Scalar radius)
Definition: geometry.cc:104
impeller::GeometryResult::vertex_buffer
VertexBuffer vertex_buffer
Definition: geometry.h:36
impeller
Definition: aiks_blend_unittests.cc:18
impeller::ContentContext
Definition: content_context.h:366
impeller::TRect< Scalar >
impeller::GeometryResult::mode
Mode mode
Definition: geometry.h:38
impeller::Matrix
A 4x4 matrix using column-major storage.
Definition: matrix.h:37
impeller::Cap
Cap
Definition: path.h:18
impeller::GeometryResult::Mode::kNonZero
@ kNonZero
impeller::Geometry::MakeCover
static std::shared_ptr< Geometry > MakeCover()
Definition: geometry.cc:85
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:97