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::RoundSuperellipseGeometry impeller::StrokePathGeometry impeller::SuperellipseGeometry impeller::VerticesGeometry

Public Member Functions

virtual ~Geometry ()
 
virtual GeometryResult GetPositionBuffer (const ContentContext &renderer, const Entity &entity, RenderPass &pass) const =0
 
virtual GeometryResult::Mode GetResultMode () const
 
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
 
virtual bool CanApplyMaskFilter () const
 
virtual Scalar ComputeAlphaCoverage (const Matrix &transform) const
 

Static Public Member Functions

static std::unique_ptr< GeometryMakeFillPath (const Path &path, std::optional< Rect > inner_rect=std::nullopt)
 
static std::unique_ptr< GeometryMakeStrokePath (const Path &path, Scalar stroke_width=0.0, Scalar miter_limit=4.0, Cap stroke_cap=Cap::kButt, Join stroke_join=Join::kMiter)
 
static std::unique_ptr< GeometryMakeCover ()
 
static std::unique_ptr< GeometryMakeRect (const Rect &rect)
 
static std::unique_ptr< GeometryMakeOval (const Rect &rect)
 
static std::unique_ptr< GeometryMakeLine (const Point &p0, const Point &p1, Scalar width, Cap cap)
 
static std::unique_ptr< GeometryMakeCircle (const Point &center, Scalar radius)
 
static std::unique_ptr< GeometryMakeStrokedCircle (const Point &center, Scalar radius, Scalar stroke_width)
 
static std::unique_ptr< GeometryMakeRoundRect (const Rect &rect, const Size &radii)
 
static std::unique_ptr< GeometryMakeRoundSuperellipse (const Rect &rect, Scalar corner_radius)
 
static Scalar ComputeStrokeAlphaCoverage (const Matrix &entity, Scalar stroke_width)
 Compute an alpha value to simulate lower coverage of fractional pixel strokes. More...
 
static GeometryResult ComputePositionGeometry (const ContentContext &renderer, const Tessellator::VertexGenerator &generator, const Entity &entity, RenderPass &pass)
 

Detailed Description

Definition at line 50 of file geometry.h.

Constructor & Destructor Documentation

◆ ~Geometry()

virtual impeller::Geometry::~Geometry ( )
inlinevirtual

Definition at line 52 of file geometry.h.

52 {}

Member Function Documentation

◆ CanApplyMaskFilter()

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

Reimplemented in impeller::CoverGeometry.

Definition at line 129 of file geometry.cc.

129  {
130  return true;
131 }

◆ ComputeAlphaCoverage()

virtual Scalar impeller::Geometry::ComputeAlphaCoverage ( const Matrix transform) const
inlinevirtual

◆ ComputePositionGeometry()

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

Definition at line 25 of file geometry.cc.

29  {
30  using VT = SolidFillVertexShader::PerVertexData;
31 
32  size_t count = generator.GetVertexCount();
33 
34  return GeometryResult{
35  .type = generator.GetTriangleType(),
36  .vertex_buffer =
37  {
38  .vertex_buffer = renderer.GetTransientsBuffer().Emplace(
39  count * sizeof(VT), alignof(VT),
40  [&generator](uint8_t* buffer) {
41  auto vertices = reinterpret_cast<VT*>(buffer);
42  generator.GenerateVertices([&vertices](const Point& p) {
43  *vertices++ = {
44  .position = p,
45  };
46  });
47  FML_DCHECK(vertices == reinterpret_cast<VT*>(buffer) +
48  generator.GetVertexCount());
49  }),
50  .vertex_count = count,
51  .index_type = IndexType::kNone,
52  },
53  .transform = entity.GetShaderTransform(pass),
54  };
55 }
@ kNone
Does not use the index buffer.
TPoint< Scalar > Point
Definition: point.h:327

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

◆ ComputeStrokeAlphaCoverage()

Scalar impeller::Geometry::ComputeStrokeAlphaCoverage ( const Matrix entity,
Scalar  stroke_width 
)
static

Compute an alpha value to simulate lower coverage of fractional pixel strokes.

Definition at line 134 of file geometry.cc.

135  {
136  Scalar scaled_stroke_width = transform.GetMaxBasisLengthXY() * stroke_width;
137  if (scaled_stroke_width == 0.0 || scaled_stroke_width >= kMinStrokeSize) {
138  return 1.0;
139  }
140  // This scalling is eyeballed from Skia.
141  return std::clamp(scaled_stroke_width * 2.0f, 0.f, 1.f);
142 }
float Scalar
Definition: scalar.h:18
static constexpr Scalar kMinStrokeSize
Definition: geometry.h:19
const Scalar stroke_width

References impeller::kMinStrokeSize, stroke_width, and transform.

Referenced by impeller::CircleGeometry::ComputeAlphaCoverage(), impeller::LineGeometry::ComputeAlphaCoverage(), and impeller::StrokePathGeometry::ComputeAlphaCoverage().

◆ 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::SuperellipseGeometry, impeller::RoundSuperellipseGeometry, impeller::RoundRectGeometry, impeller::RectGeometry, impeller::LineGeometry, impeller::FillPathGeometry, impeller::EllipseGeometry, impeller::CoverGeometry, and impeller::CircleGeometry.

Definition at line 121 of file geometry.cc.

121  {
122  return false;
123 }

Referenced by impeller::SolidColorContents::AsBackgroundColor().

◆ GetCoverage()

◆ GetPositionBuffer()

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

◆ GetResultMode()

GeometryResult::Mode impeller::Geometry::GetResultMode ( ) const
virtual

Definition at line 57 of file geometry.cc.

57  {
59 }
@ kNormal
The geometry has no overlapping triangles.

References impeller::GeometryResult::kNormal.

Referenced by impeller::ColorSourceContents::DrawGeometry().

◆ IsAxisAlignedRect()

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

◆ MakeCircle()

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

Definition at line 99 of file geometry.cc.

100  {
101  return std::make_unique<CircleGeometry>(center, radius);
102 }

◆ MakeCover()

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

Definition at line 80 of file geometry.cc.

80  {
81  return std::make_unique<CoverGeometry>();
82 }

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

◆ MakeFillPath()

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

Definition at line 61 of file geometry.cc.

63  {
64  return std::make_unique<FillPathGeometry>(path, inner_rect);
65 }

Referenced by impeller::testing::TEST(), and impeller::testing::TEST_P().

◆ MakeLine()

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

Definition at line 92 of file geometry.cc.

95  {
96  return std::make_unique<LineGeometry>(p0, p1, width, cap);
97 }

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

◆ MakeOval()

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

Definition at line 88 of file geometry.cc.

88  {
89  return std::make_unique<EllipseGeometry>(rect);
90 }

◆ MakeRect()

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

Definition at line 84 of file geometry.cc.

84  {
85  return std::make_unique<RectGeometry>(rect);
86 }

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

◆ MakeRoundRect()

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

Definition at line 110 of file geometry.cc.

111  {
112  return std::make_unique<RoundRectGeometry>(rect, radii);
113 }

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

◆ MakeRoundSuperellipse()

std::unique_ptr< Geometry > impeller::Geometry::MakeRoundSuperellipse ( const Rect rect,
Scalar  corner_radius 
)
static

Definition at line 115 of file geometry.cc.

117  {
118  return std::make_unique<RoundSuperellipseGeometry>(rect, corner_radius);
119 }

◆ MakeStrokedCircle()

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

Definition at line 104 of file geometry.cc.

106  {
107  return std::make_unique<CircleGeometry>(center, radius, stroke_width);
108 }

References stroke_width.

◆ MakeStrokePath()

std::unique_ptr< Geometry > impeller::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 
)
static

Definition at line 67 of file geometry.cc.

71  {
72  // Skia behaves like this.
73  if (miter_limit < 0) {
74  miter_limit = 4.0;
75  }
76  return std::make_unique<StrokePathGeometry>(path, stroke_width, miter_limit,
77  stroke_cap, stroke_join);
78 }

References stroke_width.

Referenced by impeller::testing::TEST(), and impeller::testing::TEST_P().


The documentation for this class was generated from the following files: