| Flutter Impeller |

Public Member Functions | Static Public Member Functions | Static Protected Member Functions | List of all members
impeller::Geometry Class Referenceabstract

`#include <geometry.h>`

Inheritance diagram for impeller::Geometry:

## 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
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< Geometry > | MakeFillPath (const Path &path, std::optional< Rect > inner_rect=std::nullopt)
static std::unique_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)
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, Scalar width, Cap cap)
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 > | MakeRoundRect (const Rect &rect, const Size &radii)
static Scalar | ComputeStrokeAlphaCoverage (const Matrix &entity, Scalar stroke_width)
| Compute an alpha value to simulate lower coverage of fractional pixel strokes. More...

## Static Protected Member Functions
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 | ( |  | ) |
| inline virtual

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

121 {
122 return true;
123 }

## ◆ ComputeAlphaCoverage()

virtual Scalar impeller::Geometry::ComputeAlphaCoverage | ( | const Matrix & | transform | ) | const
| inline virtual

Reimplemented in impeller::StrokePathGeometry, impeller::LineGeometry, and impeller::CircleGeometry.

Definition at line 115 of file geometry.h.

115 {
116 return 1.0;
117 }

Referenced by impeller::ColorSourceContents::AppliesAlphaForStrokeCoverage(), impeller::SolidColorContents::Render(), and impeller::TiledTextureContents::Render().

## ◆ ComputePositionGeometry()

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

Definition at line 23 of file geometry.cc.

27 {
28 using VT = SolidFillVertexShader::PerVertexData;
29
30 size_t count = generator.GetVertexCount();
31
32 return GeometryResult{
33 .type = generator.GetTriangleType(),
34 .vertex_buffer =
35 {
36 .vertex_buffer = renderer.GetTransientsBuffer().Emplace(
37 count * sizeof(VT), alignof(VT),
38 [&generator](uint8_t* buffer) {
39 auto vertices = reinterpret_cast<VT*>(buffer);
40 generator.GenerateVertices([&vertices](const Point& p) {
41 *vertices++ = {
42 .position = p,
43 };
44 });
45 FML_DCHECK(vertices == reinterpret_cast<VT*>(buffer) +
46 generator.GetVertexCount());
47 }),
48 .vertex_count = count,
49 .index_type = IndexType::kNone,
50 },
51 .transform = entity.GetShaderTransform(pass),
52 };
53 }
impeller::IndexType::kNone
@ kNone
Does not use the index buffer.
impeller::Point
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 126 of file geometry.cc.

127 {
128 Scalar scaled_stroke_width = transform.GetMaxBasisLengthXY() * stroke_width;
129 if (scaled_stroke_width == 0.0 || scaled_stroke_width >= kMinStrokeSize) {
130 return 1.0;
131 }
132 // This scalling is eyeballed from Skia.
133 return std::clamp(scaled_stroke_width * 2.0f, 0.f, 1.f);
134 }
transform
Matrix transform
Definition: gaussian_blur_filter_contents.cc:214
impeller::Scalar
float Scalar
Definition: scalar.h:18
impeller::kMinStrokeSize
static constexpr Scalar kMinStrokeSize
Definition: geometry.h:19
stroke_width
const Scalar stroke_width
Definition: stroke_path_geometry.cc:312

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

113 {
114 return false;
115 }

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

## ◆ GetCoverage()

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

Implemented in impeller::RectGeometry, impeller::PointFieldGeometry, and impeller::DlVerticesGeometry.

Referenced by impeller::Canvas::ClipGeometry(), impeller::ColorSourceContents::DrawGeometry(), impeller::ColorSourceContents::GetCoverage(), impeller::SolidColorContents::GetCoverage(), and impeller::TiledTextureContents::RenderToSnapshot().

## ◆ GetPositionBuffer()

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

Implemented in impeller::RectGeometry, and impeller::DlVerticesGeometry.

Referenced by impeller::Canvas::ClipGeometry(), impeller::ColorSourceContents::DefaultCreateGeometryCallback(), and impeller::ColorSourceContents::DrawGeometry().

## ◆ GetResultMode()

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

Definition at line 55 of file geometry.cc.

55 {
56 return GeometryResult::Mode::kNormal;
57 }
impeller::GeometryResult::Mode::kNormal
@ kNormal
The geometry has no overlapping triangles.

References impeller::GeometryResult::kNormal.

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

## ◆ IsAxisAlignedRect()

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

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

Definition at line 117 of file geometry.cc.

117 {
118 return false;
119 }

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

## ◆ 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 }

## ◆ MakeCover()

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

Definition at line 78 of file geometry.cc.

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

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

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

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

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

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

## ◆ MakeOval()

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

Definition at line 86 of file geometry.cc.

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

## ◆ MakeRect()

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

Definition at line 82 of file geometry.cc.

82 {
83 return std::make_unique<RectGeometry>(rect);
84 }

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

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

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

## ◆ 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 }

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

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

References stroke_width.

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

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

- impeller/entity/geometry/geometry.h
- impeller/entity/geometry/geometry.cc