Flutter Impeller
impeller::Geometry Class Referenceabstract

#include <geometry.h>

Inheritance diagram for impeller::Geometry:
impeller::CircleGeometry impeller::CoverGeometry impeller::EllipseGeometry impeller::FillPathGeometry impeller::LineGeometry impeller::PointFieldGeometry impeller::RectGeometry impeller::RoundRectGeometry impeller::StrokePathGeometry impeller::VerticesGeometry

Public Member Functions

virtual GeometryResult GetPositionBuffer (const ContentContext &renderer, const Entity &entity, RenderPass &pass) const =0
 
virtual GeometryResult GetPositionUVBuffer (Rect texture_coverage, Matrix effect_transform, const ContentContext &renderer, const Entity &entity, RenderPass &pass) const =0
 
virtual GeometryVertexType GetVertexType () const =0
 
virtual std::optional< RectGetCoverage (const Matrix &transform) const =0
 
virtual bool CoversArea (const Matrix &transform, const Rect &rect) const
 Determines if this geometry, transformed by the given transform, will completely cover all surface area of the given rect. More...
 
virtual bool IsAxisAlignedRect () const
 

Static Public Member Functions

static std::shared_ptr< GeometryMakeFillPath (Path path, std::optional< Rect > inner_rect=std::nullopt)
 
static std::shared_ptr< GeometryMakeStrokePath (Path path, Scalar stroke_width=0.0, Scalar miter_limit=4.0, Cap stroke_cap=Cap::kButt, Join stroke_join=Join::kMiter)
 
static std::shared_ptr< GeometryMakeCover ()
 
static std::shared_ptr< GeometryMakeRect (const Rect &rect)
 
static std::shared_ptr< GeometryMakeOval (const Rect &rect)
 
static std::shared_ptr< GeometryMakeLine (const Point &p0, const Point &p1, Scalar width, Cap cap)
 
static std::shared_ptr< GeometryMakeCircle (const Point &center, Scalar radius)
 
static std::shared_ptr< GeometryMakeStrokedCircle (const Point &center, Scalar radius, Scalar stroke_width)
 
static std::shared_ptr< GeometryMakeRoundRect (const Rect &rect, const Size &radii)
 
static std::shared_ptr< GeometryMakePointField (std::vector< Point > points, Scalar radius, bool round)
 

Static Protected Member Functions

static GeometryResult ComputePositionGeometry (const Tessellator::VertexGenerator &generator, const Entity &entity, RenderPass &pass)
 
static GeometryResult ComputePositionUVGeometry (const Tessellator::VertexGenerator &generator, const Matrix &uv_transform, const Entity &entity, RenderPass &pass)
 

Detailed Description

Definition at line 58 of file geometry.h.

Member Function Documentation

◆ ComputePositionGeometry()

GeometryResult impeller::Geometry::ComputePositionGeometry ( const Tessellator::VertexGenerator generator,
const Entity entity,
RenderPass pass 
)
staticprotected

Definition at line 23 of file geometry.cc.

26  {
27  using VT = SolidFillVertexShader::PerVertexData;
28 
29  size_t count = generator.GetVertexCount();
30 
31  return GeometryResult{
32  .type = generator.GetTriangleType(),
33  .vertex_buffer =
34  {
35  .vertex_buffer = pass.GetTransientsBuffer().Emplace(
36  count * sizeof(VT), alignof(VT),
37  [&generator](uint8_t* buffer) {
38  auto vertices = reinterpret_cast<VT*>(buffer);
39  generator.GenerateVertices([&vertices](const Point& p) {
40  *vertices++ = {
41  .position = p,
42  };
43  });
44  FML_DCHECK(vertices == reinterpret_cast<VT*>(buffer) +
45  generator.GetVertexCount());
46  }),
47  .vertex_count = count,
48  .index_type = IndexType::kNone,
49  },
50  .transform = pass.GetOrthographicTransform() * entity.GetTransform(),
51  .prevent_overdraw = false,
52  };
53 }

References impeller::HostBuffer::Emplace(), impeller::Tessellator::VertexGenerator::GenerateVertices(), impeller::RenderPass::GetOrthographicTransform(), impeller::Entity::GetTransform(), impeller::RenderPass::GetTransientsBuffer(), impeller::Tessellator::VertexGenerator::GetTriangleType(), impeller::Tessellator::VertexGenerator::GetVertexCount(), impeller::kNone, and impeller::GeometryResult::type.

◆ ComputePositionUVGeometry()

GeometryResult impeller::Geometry::ComputePositionUVGeometry ( const Tessellator::VertexGenerator generator,
const Matrix uv_transform,
const Entity entity,
RenderPass pass 
)
staticprotected

Definition at line 55 of file geometry.cc.

59  {
60  using VT = TextureFillVertexShader::PerVertexData;
61 
62  size_t count = generator.GetVertexCount();
63 
64  return GeometryResult{
65  .type = generator.GetTriangleType(),
66  .vertex_buffer =
67  {
68  .vertex_buffer = pass.GetTransientsBuffer().Emplace(
69  count * sizeof(VT), alignof(VT),
70  [&generator, &uv_transform](uint8_t* buffer) {
71  auto vertices = reinterpret_cast<VT*>(buffer);
72  generator.GenerateVertices(
73  [&vertices, &uv_transform](const Point& p) { //
74  *vertices++ = {
75  .position = p,
76  .texture_coords = uv_transform * p,
77  };
78  });
79  FML_DCHECK(vertices == reinterpret_cast<VT*>(buffer) +
80  generator.GetVertexCount());
81  }),
82  .vertex_count = count,
83  .index_type = IndexType::kNone,
84  },
85  .transform = pass.GetOrthographicTransform() * entity.GetTransform(),
86  .prevent_overdraw = false,
87  };
88 }

References impeller::HostBuffer::Emplace(), impeller::Tessellator::VertexGenerator::GenerateVertices(), impeller::RenderPass::GetOrthographicTransform(), impeller::Entity::GetTransform(), impeller::RenderPass::GetTransientsBuffer(), impeller::Tessellator::VertexGenerator::GetTriangleType(), impeller::Tessellator::VertexGenerator::GetVertexCount(), impeller::kNone, and impeller::GeometryResult::type.

◆ CoversArea()

bool impeller::Geometry::CoversArea ( const Matrix transform,
const Rect rect 
) const
virtual

Determines if this geometry, transformed by the given transform, will completely cover all surface area of the given rect.

This is a conservative estimate useful for certain optimizations.

Returns
true if the transformed geometry is guaranteed to cover the given rect. May return false in many undetected cases where the transformed geometry does in fact cover the rect.

Reimplemented in impeller::CircleGeometry, impeller::FillPathGeometry, impeller::EllipseGeometry, impeller::RoundRectGeometry, impeller::LineGeometry, impeller::CoverGeometry, and impeller::RectGeometry.

Definition at line 210 of file geometry.cc.

210  {
211  return false;
212 }

◆ GetCoverage()

virtual std::optional<Rect> impeller::Geometry::GetCoverage ( const Matrix transform) const
pure virtual

Implemented in impeller::VerticesGeometry.

◆ GetPositionBuffer()

virtual GeometryResult impeller::Geometry::GetPositionBuffer ( const ContentContext renderer,
const Entity entity,
RenderPass pass 
) const
pure virtual

Implemented in impeller::VerticesGeometry.

◆ GetPositionUVBuffer()

GeometryResult impeller::Geometry::GetPositionUVBuffer ( Rect  texture_coverage,
Matrix  effect_transform,
const ContentContext renderer,
const Entity entity,
RenderPass pass 
) const
pure virtual

Implemented in impeller::VerticesGeometry.

Definition at line 142 of file geometry.cc.

146  {
147  return {};
148 }

◆ GetVertexType()

virtual GeometryVertexType impeller::Geometry::GetVertexType ( ) const
pure virtual

Implemented in impeller::VerticesGeometry.

◆ IsAxisAlignedRect()

bool impeller::Geometry::IsAxisAlignedRect ( ) const
virtual

Reimplemented in impeller::CircleGeometry, impeller::EllipseGeometry, impeller::RoundRectGeometry, impeller::LineGeometry, and impeller::RectGeometry.

Definition at line 214 of file geometry.cc.

214  {
215  return false;
216 }

◆ MakeCircle()

std::shared_ptr< Geometry > impeller::Geometry::MakeCircle ( const Point center,
Scalar  radius 
)
static

Definition at line 194 of file geometry.cc.

195  {
196  return std::make_shared<CircleGeometry>(center, radius);
197 }

Referenced by impeller::Canvas::DrawCircle().

◆ MakeCover()

std::shared_ptr< Geometry > impeller::Geometry::MakeCover ( )
static

Definition at line 175 of file geometry.cc.

175  {
176  return std::make_shared<CoverGeometry>();
177 }

Referenced by impeller::testing::TEST_P().

◆ MakeFillPath()

std::shared_ptr< Geometry > impeller::Geometry::MakeFillPath ( Path  path,
std::optional< Rect inner_rect = std::nullopt 
)
static

Definition at line 150 of file geometry.cc.

152  {
153  return std::make_shared<FillPathGeometry>(std::move(path), inner_rect);
154 }

Referenced by impeller::Canvas::ClipPath(), impeller::SolidColorContents::Make(), impeller::testing::TEST(), and impeller::testing::TEST_P().

◆ MakeLine()

std::shared_ptr< Geometry > impeller::Geometry::MakeLine ( const Point p0,
const Point p1,
Scalar  width,
Cap  cap 
)
static

Definition at line 187 of file geometry.cc.

190  {
191  return std::make_shared<LineGeometry>(p0, p1, width, cap);
192 }

Referenced by impeller::Canvas::DrawLine(), and impeller::testing::TEST().

◆ MakeOval()

std::shared_ptr< Geometry > impeller::Geometry::MakeOval ( const Rect rect)
static

Definition at line 183 of file geometry.cc.

183  {
184  return std::make_shared<EllipseGeometry>(rect);
185 }

Referenced by impeller::Canvas::ClipOval(), and impeller::Canvas::DrawOval().

◆ MakePointField()

std::shared_ptr< Geometry > impeller::Geometry::MakePointField ( std::vector< Point points,
Scalar  radius,
bool  round 
)
static

Definition at line 156 of file geometry.cc.

158  {
159  return std::make_shared<PointFieldGeometry>(std::move(points), radius, round);
160 }

Referenced by impeller::Canvas::DrawPoints(), and impeller::testing::TEST_P().

◆ MakeRect()

std::shared_ptr< Geometry > impeller::Geometry::MakeRect ( const Rect rect)
static

◆ MakeRoundRect()

std::shared_ptr< Geometry > impeller::Geometry::MakeRoundRect ( const Rect rect,
const Size radii 
)
static

Definition at line 205 of file geometry.cc.

206  {
207  return std::make_shared<RoundRectGeometry>(rect, radii);
208 }

Referenced by impeller::Canvas::ClipRRect(), impeller::Canvas::DrawRRect(), and impeller::testing::TEST().

◆ MakeStrokedCircle()

std::shared_ptr< Geometry > impeller::Geometry::MakeStrokedCircle ( const Point center,
Scalar  radius,
Scalar  stroke_width 
)
static

Definition at line 199 of file geometry.cc.

201  {
202  return std::make_shared<CircleGeometry>(center, radius, stroke_width);
203 }

Referenced by impeller::Canvas::DrawCircle().

◆ MakeStrokePath()

std::shared_ptr< Geometry > impeller::Geometry::MakeStrokePath ( Path  path,
Scalar  stroke_width = 0.0,
Scalar  miter_limit = 4.0,
Cap  stroke_cap = Cap::kButt,
Join  stroke_join = Join::kMiter 
)
static

Definition at line 162 of file geometry.cc.

166  {
167  // Skia behaves like this.
168  if (miter_limit < 0) {
169  miter_limit = 4.0;
170  }
171  return std::make_shared<StrokePathGeometry>(
172  std::move(path), stroke_width, miter_limit, stroke_cap, stroke_join);
173 }

Referenced by impeller::testing::TEST_P().


The documentation for this class was generated from the following files:
impeller::Point
TPoint< Scalar > Point
Definition: point.h:308
impeller::IndexType::kNone
@ kNone
Does not use the index buffer.