Flutter Impeller
impeller::Geometry Class Referenceabstract

#include <geometry.h>

Inheritance diagram for impeller::Geometry:
impeller::ArcGeometry impeller::CircleGeometry impeller::CoverGeometry impeller::EllipseGeometry impeller::FillPathSourceGeometry impeller::FillRectGeometry impeller::LineGeometry impeller::PointFieldGeometry impeller::RoundRectGeometry impeller::RoundSuperellipseGeometry impeller::StrokeRectGeometry impeller::StrokeSegmentsGeometry impeller::SuperellipseGeometry impeller::UberSDFGeometry 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< Rect > GetCoverage (const Matrix &transform) const =0
 The coverage rectangle of this geometry, transformed by the transform argument. More...
 
virtual bool CoversArea (const Matrix &transform, const IRect &rect) const
 Determines if this geometry, transformed by the given transform, will completely cover all of the pixels within the given integer 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< Geometry > MakeFillPath (const flutter::DlPath &path, std::optional< Rect > inner_rect=std::nullopt)
 
static std::unique_ptr< Geometry > MakeStrokePath (const flutter::DlPath &path, const StrokeParameters &stroke={})
 
static std::unique_ptr< Geometry > MakeCover ()
 
static std::unique_ptr< Geometry > MakeRect (const Rect &rect)
 
static std::unique_ptr< Geometry > MakeOval (const Rect &rect)
 
static std::unique_ptr< Geometry > MakeLine (const Point &p0, const Point &p1, const StrokeParameters &stroke)
 
static std::unique_ptr< Geometry > MakeCircle (const Point &center, Scalar radius)
 
static std::unique_ptr< Geometry > MakeStrokedCircle (const Point &center, Scalar radius, Scalar stroke_width)
 
static std::unique_ptr< Geometry > MakeFilledArc (const Rect &oval_bounds, Degrees start, Degrees sweep, bool include_center)
 
static std::unique_ptr< Geometry > MakeStrokedArc (const Rect &oval_bounds, Degrees start, Degrees sweep, const StrokeParameters &stroke)
 
static std::unique_ptr< Geometry > MakeRoundRect (const Rect &rect, const Size &radii)
 
static std::unique_ptr< Geometry > MakeRoundSuperellipse (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, and impeller::DlVerticesGeometry.

Definition at line 144 of file geometry.cc.

144  {
145  return true;
146 }

◆ 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 26 of file geometry.cc.

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

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

Referenced by impeller::CircleGeometry::GetPositionBuffer().

◆ 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 149 of file geometry.cc.

150  {
151  Scalar scaled_stroke_width = transform.GetMaxBasisLengthXY() * stroke_width;
152  if (scaled_stroke_width == 0.0 || scaled_stroke_width >= kMinStrokeSize) {
153  return 1.0;
154  }
155  // This scalling is eyeballed from Skia.
156  return std::clamp(scaled_stroke_width * 2.0f, 0.f, 1.f);
157 }
float Scalar
Definition: scalar.h:19
static constexpr Scalar kMinStrokeSize
Definition: geometry.h:19

References impeller::kMinStrokeSize, and transform.

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

◆ CoversArea()

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

Determines if this geometry, transformed by the given transform, will completely cover all of the pixels within the given integer rect.

The integer rect, by definition, will contain all of the area covered by any pixel within its boundary.

The return value can be a conservative estimate which will still be useful for certain optimizations. It may return false for obscure cases that might actually contain all of the pixels if it is too computationally costly to prove containment, but it should never return 'true' unless the implementation can prove that all pixels are fully covered (rendered) by the geometry.

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

Reimplemented in impeller::UberSDFGeometry, impeller::SuperellipseGeometry, impeller::RoundSuperellipseGeometry, impeller::FillRoundRectGeometry, impeller::RoundRectGeometry, impeller::FillRectGeometry, impeller::LineGeometry, impeller::FillPathSourceGeometry, impeller::EllipseGeometry, impeller::CoverGeometry, impeller::CircleGeometry, and impeller::ArcGeometry.

Definition at line 136 of file geometry.cc.

136  {
137  return false;
138 }

Referenced by impeller::SolidColorContents::AsBackgroundColor(), and impeller::UberSDFContents::AsBackgroundColor().

◆ GetCoverage()

◆ GetPositionBuffer()

◆ GetResultMode()

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

Definition at line 58 of file geometry.cc.

58  {
60 }
@ kNormal
The geometry has no overlapping triangles.

References impeller::GeometryResult::kNormal.

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

◆ IsAxisAlignedRect()

◆ MakeCircle()

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

Definition at line 97 of file geometry.cc.

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

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

◆ MakeCover()

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

Definition at line 79 of file geometry.cc.

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

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

◆ MakeFilledArc()

std::unique_ptr< Geometry > impeller::Geometry::MakeFilledArc ( const Rect &  oval_bounds,
Degrees  start,
Degrees  sweep,
bool  include_center 
)
static

Definition at line 108 of file geometry.cc.

111  {
112  return std::make_unique<ArcGeometry>(
113  Arc(oval_bounds, start, sweep, include_center));
114 }
const size_t start

References start.

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

◆ MakeFillPath()

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

Definition at line 62 of file geometry.cc.

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

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

◆ MakeLine()

std::unique_ptr< Geometry > impeller::Geometry::MakeLine ( const Point &  p0,
const Point &  p1,
const StrokeParameters &  stroke 
)
static

Definition at line 91 of file geometry.cc.

93  {
94  return std::make_unique<LineGeometry>(p0, p1, stroke);
95 }

References p1.

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

◆ MakeOval()

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

Definition at line 87 of file geometry.cc.

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

◆ MakeRect()

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

Definition at line 83 of file geometry.cc.

83  {
84  return std::make_unique<FillRectGeometry>(rect);
85 }

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 125 of file geometry.cc.

126  {
127  return std::make_unique<RoundRectGeometry>(rect, radii);
128 }

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

◆ MakeRoundSuperellipse()

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

Definition at line 130 of file geometry.cc.

132  {
133  return std::make_unique<RoundSuperellipseGeometry>(rect, corner_radius);
134 }

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

◆ MakeStrokedArc()

std::unique_ptr< Geometry > impeller::Geometry::MakeStrokedArc ( const Rect &  oval_bounds,
Degrees  start,
Degrees  sweep,
const StrokeParameters &  stroke 
)
static

Definition at line 116 of file geometry.cc.

120  {
121  return std::make_unique<ArcGeometry>(Arc(oval_bounds, start, sweep, false),
122  stroke);
123 }

References start.

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

◆ MakeStrokedCircle()

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

Definition at line 102 of file geometry.cc.

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

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

◆ MakeStrokePath()

std::unique_ptr< Geometry > impeller::Geometry::MakeStrokePath ( const flutter::DlPath &  path,
const StrokeParameters &  stroke = {} 
)
static

Definition at line 68 of file geometry.cc.

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

References impeller::StrokeParameters::miter_limit.

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


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