Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
impeller::UberSDFGeometry Class Referencefinal

Geometry for rendering shapes using the UberSDF shader. More...

#include <uber_sdf_geometry.h>

Inheritance diagram for impeller::UberSDFGeometry:
impeller::Geometry

Public Member Functions

 UberSDFGeometry (const UberSDFParameters &params)
 
 ~UberSDFGeometry () override
 
GeometryResult GetPositionBuffer (const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
 
std::optional< RectGetCoverage (const Matrix &transform) const override
 The coverage rectangle of this geometry, transformed by the transform argument.
 
bool CoversArea (const Matrix &transform, const IRect &rect) const override
 Determines if this geometry, transformed by the given transform, will completely cover all of the pixels within the given integer rect.
 
bool IsAxisAlignedRect () const override
 
- Public Member Functions inherited from impeller::Geometry
virtual ~Geometry ()
 
virtual GeometryResult::Mode GetResultMode () const
 
virtual bool CanApplyMaskFilter () const
 
virtual Scalar ComputeAlphaCoverage (const Matrix &transform) const
 

Additional Inherited Members

- Static Public Member Functions inherited from impeller::Geometry
static std::unique_ptr< GeometryMakeFillPath (const flutter::DlPath &path, std::optional< Rect > inner_rect=std::nullopt)
 
static std::unique_ptr< GeometryMakeStrokePath (const flutter::DlPath &path, const StrokeParameters &stroke={})
 
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, const StrokeParameters &stroke)
 
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< GeometryMakeFilledArc (const Rect &oval_bounds, Degrees start, Degrees sweep, bool include_center)
 
static std::unique_ptr< GeometryMakeStrokedArc (const Rect &oval_bounds, Degrees start, Degrees sweep, const StrokeParameters &stroke)
 
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.
 
static GeometryResult ComputePositionGeometry (const ContentContext &renderer, const Tessellator::VertexGenerator &generator, const Entity &entity, RenderPass &pass)
 

Detailed Description

Geometry for rendering shapes using the UberSDF shader.

Definition at line 14 of file uber_sdf_geometry.h.

Constructor & Destructor Documentation

◆ UberSDFGeometry()

impeller::UberSDFGeometry::UberSDFGeometry ( const UberSDFParameters params)
explicit

Definition at line 11 of file uber_sdf_geometry.cc.

12 : params_(params) {}
const EmbeddedViewParams * params

◆ ~UberSDFGeometry()

impeller::UberSDFGeometry::~UberSDFGeometry ( )
overridedefault

Member Function Documentation

◆ CoversArea()

bool impeller::UberSDFGeometry::CoversArea ( const Matrix transform,
const IRect rect 
) const
overridevirtual

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 from impeller::Geometry.

Definition at line 35 of file uber_sdf_geometry.cc.

36 {
37 if (params_.type == UberSDFParameters::Type::kRect && !params_.stroke &&
38 transform.IsTranslationScaleOnly()) {
39 // The SDF is a filled axis-aligned rectangle. It "covers" the input rect if
40 // the SDF shader fully replaces the pixels contained in the rect parameter.
41 // The SDF shader is computed by the GPU at the center of the pixels it
42 // intersects and it computes a coverage for the pixels that reaches full
43 // coverage (1.0) at (aa_pixels / 2.0) inside the geometry. That coverage
44 // value will be applied for every MSAA sample intersected by the geometry.
45 //
46 // Since the input rect is an integer rect we already know that it encloses
47 // at least half a pixel on each side of the pixel centers inside it and
48 // that it encloses every MSAA sample location within those pixels. This
49 // means that the integer rect already meets all of the above criteria (as
50 // long as kAntialiasPixels is <= 1.0), so if the transformed geometry
51 // contains the integer input rect, all pixels will be fully rendered.
52 static_assert(UberSDFParameters::kAntialiasPixels <= 1.0);
53 return Rect::MakeEllipseBounds(params_.center, params_.size)
55 .Contains(rect);
56 }
57
58 // Conservatively return false. We can optimize to handle more cases in the
59 // future if needed for performance reasons.
60 return false;
61}
constexpr TRect TransformBounds(const Matrix &transform) const
Creates a new bounding box that contains this transformed rectangle.
Definition rect.h:506
static constexpr TRect MakeEllipseBounds(const TPoint< Type > &center, const TSize< Type > &radii)
Definition rect.h:164
constexpr bool Contains(const TPoint< Type > &p) const
Returns true iff the provided point |p| is inside the half-open interior of this rectangle.
Definition rect.h:255
Type type
The type of shape to render.
Point center
The center point of the shape in local coordinates.
static constexpr Scalar kAntialiasPixels
std::optional< StrokeParameters > stroke
The stroke parameters. If std::nullopt, the shape is filled.

References impeller::UberSDFParameters::center, impeller::TRect< T >::Contains(), impeller::UberSDFParameters::kAntialiasPixels, impeller::UberSDFParameters::kRect, impeller::TRect< Scalar >::MakeEllipseBounds(), impeller::UberSDFParameters::size, impeller::UberSDFParameters::stroke, transform, impeller::TRect< T >::TransformBounds(), and impeller::UberSDFParameters::type.

◆ GetCoverage()

std::optional< Rect > impeller::UberSDFGeometry::GetCoverage ( const Matrix transform) const
overridevirtual

The coverage rectangle of this geometry, transformed by the transform argument.

Implements impeller::Geometry.

Definition at line 30 of file uber_sdf_geometry.cc.

31 {
32 return GetExpandedBounds(transform).TransformAndClipBounds(transform);
33}
constexpr TRect TransformAndClipBounds(const Matrix &transform) const
Creates a new bounding box that contains this transformed rectangle, clipped against the near clippin...
Definition rect.h:472

References transform, and impeller::TRect< T >::TransformAndClipBounds().

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

◆ GetPositionBuffer()

GeometryResult impeller::UberSDFGeometry::GetPositionBuffer ( const ContentContext renderer,
const Entity entity,
RenderPass pass 
) const
overridevirtual

Implements impeller::Geometry.

Definition at line 16 of file uber_sdf_geometry.cc.

19 {
20 // Return a quad (FillRectGeometry) that covers the base shape expanded by
21 // padding for stroke width and AA.
22 //
23 // For future performance enhancements (if the fill rate is a limiting factor)
24 // this can be optimized to use a tighter geometry for specific shapes. E.g.
25 // Using a tighter polygon, or cutting out the interior for stroked shapes.
26 FillRectGeometry frg(GetExpandedBounds(entity.GetTransform()));
27 return frg.GetPositionBuffer(renderer, entity, pass);
28}

References impeller::FillRectGeometry::GetPositionBuffer(), and impeller::Entity::GetTransform().

◆ IsAxisAlignedRect()

bool impeller::UberSDFGeometry::IsAxisAlignedRect ( ) const
overridevirtual

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