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

#include <uber_sdf_contents.h>

Inheritance diagram for impeller::UberSDFContents:
impeller::ColorSourceContents impeller::Contents

Public Member Functions

 ~UberSDFContents () override
 
bool Render (const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
 
std::optional< RectGetCoverage (const Entity &entity) const override
 Get the area of the render pass that will be affected when this contents is rendered.
 
Color GetColor () const
 
bool ApplyColorFilter (const ColorFilterProc &color_filter_proc) override
 If possible, applies a color filter to this contents inputs on the CPU.
 
const GeometryGetGeometry () const override
 Get the geometry that this contents will use to render.
 
std::optional< ColorAsBackgroundColor (const Entity &entity, ISize target_size) const override
 Returns a color if this Contents will flood the given target_size with a color. This output color is the "Source" color that will be used for the Entity's blend operation.
 
- Public Member Functions inherited from impeller::ColorSourceContents
 ColorSourceContents ()
 
 ~ColorSourceContents () override
 
void SetEffectTransform (Matrix matrix)
 Set the effect transform for this color source.
 
const MatrixGetInverseEffectTransform () const
 Set the inverted effect transform for this color source.
 
void SetOpacityFactor (Scalar opacity)
 Set the opacity factor for this color source.
 
Scalar GetOpacityFactor () const
 Get the opacity factor for this color source.
 
virtual bool IsSolidColor () const
 
void SetInheritedOpacity (Scalar opacity) override
 Inherit the provided opacity.
 
- Public Member Functions inherited from impeller::Contents
 Contents ()
 
virtual ~Contents ()
 
void SetCoverageHint (std::optional< Rect > coverage_hint)
 Hint that specifies the coverage area of this Contents that will actually be used during rendering. This is for optimization purposes only and can not be relied on as a clip. May optionally affect the result of GetCoverage().
 
const std::optional< Rect > & GetCoverageHint () const
 
virtual bool IsOpaque (const Matrix &transform) const
 Whether this Contents only emits opaque source colors from the fragment stage. This value does not account for any entity properties (e.g. the blend mode), clips/visibility culling, or inherited opacity.
 
virtual std::optional< SnapshotRenderToSnapshot (const ContentContext &renderer, const Entity &entity, const SnapshotOptions &options) const
 Render this contents to a snapshot, respecting the entity's transform, path, clip depth, and blend mode. The result texture size is always the size of GetCoverage(entity).
 
std::optional< SizeGetColorSourceSize () const
 Return the color source's intrinsic size, if available.
 
void SetColorSourceSize (Size size)
 

Static Public Member Functions

static std::unique_ptr< UberSDFContentsMake (const UberSDFParameters &params, std::unique_ptr< Geometry > geometry)
 
- Static Public Member Functions inherited from impeller::ColorSourceContents
template<typename VertexShaderT >
static bool DrawGeometry (const Contents *contents, const Geometry *geometry, const ContentContext &renderer, const Entity &entity, RenderPass &pass, const PipelineBuilderCallback &pipeline_callback, typename VertexShaderT::FrameInfo frame_info, const BindFragmentCallback &bind_fragment_callback, bool force_stencil=false, const CreateGeometryCallback &create_geom_callback=DefaultCreateGeometryCallback)
 
- Static Public Member Functions inherited from impeller::Contents
static std::shared_ptr< ContentsMakeAnonymous (RenderProc render_proc, CoverageProc coverage_proc)
 

Additional Inherited Members

- Public Types inherited from impeller::ColorSourceContents
using BindFragmentCallback = std::function< bool(RenderPass &pass)>
 
using PipelineBuilderCallback = std::function< PipelineRef(ContentContextOptions)>
 
using CreateGeometryCallback = std::function< GeometryResult(const ContentContext &renderer, const Entity &entity, RenderPass &pass, const Geometry *geom)>
 
- Public Types inherited from impeller::Contents
using ColorFilterProc = std::function< Color(Color)>
 
using RenderProc = std::function< bool(const ContentContext &renderer, const Entity &entity, RenderPass &pass)>
 
using CoverageProc = std::function< std::optional< Rect >(const Entity &entity)>
 
- Protected Member Functions inherited from impeller::ColorSourceContents
bool AppliesAlphaForStrokeCoverage (const Matrix &transform) const
 Whether the entity should be treated as non-opaque due to stroke geometry requiring alpha for coverage.
 
template<typename VertexShaderT >
bool DrawGeometry (const ContentContext &renderer, const Entity &entity, RenderPass &pass, const PipelineBuilderCallback &pipeline_callback, typename VertexShaderT::FrameInfo frame_info, const BindFragmentCallback &bind_fragment_callback, bool force_stencil=false, const CreateGeometryCallback &create_geom_callback=DefaultCreateGeometryCallback) const
 
- Static Protected Member Functions inherited from impeller::ColorSourceContents
static GeometryResult DefaultCreateGeometryCallback (const ContentContext &renderer, const Entity &entity, RenderPass &pass, const Geometry *geom)
 

Detailed Description

Definition at line 19 of file uber_sdf_contents.h.

Constructor & Destructor Documentation

◆ ~UberSDFContents()

impeller::UberSDFContents::~UberSDFContents ( )
overridedefault

Member Function Documentation

◆ ApplyColorFilter()

bool impeller::UberSDFContents::ApplyColorFilter ( const ColorFilterProc color_filter_proc)
overridevirtual

If possible, applies a color filter to this contents inputs on the CPU.

This method will either fully apply the color filter or perform no action. Partial/incorrect application of the color filter will never occur.

Parameters
[in]color_filter_procA function that filters a given unpremultiplied color to produce a new unpremultiplied color.
Returns
True if the color filter was able to be fully applied to all all relevant inputs. Otherwise, this operation is a no-op and false is returned.

Reimplemented from impeller::Contents.

Definition at line 132 of file uber_sdf_contents.cc.

133 {
134 params_.color = color_filter_proc(params_.color);
135 return true;
136}
Color color
The color used for filling or stroking the shape.

References impeller::UberSDFParameters::color.

◆ AsBackgroundColor()

std::optional< Color > impeller::UberSDFContents::AsBackgroundColor ( const Entity entity,
ISize  target_size 
) const
overridevirtual

Returns a color if this Contents will flood the given target_size with a color. This output color is the "Source" color that will be used for the Entity's blend operation.

This is useful for absorbing full screen solid color draws into subpass clear colors.

Reimplemented from impeller::Contents.

Definition at line 138 of file uber_sdf_contents.cc.

140 {
141 if (params_.type != UberSDFParameters::Type::kRect) {
142 return std::nullopt;
143 }
144 const Geometry* geometry = GetGeometry();
145 if (geometry == nullptr) {
146 return std::nullopt;
147 }
148 IRect target_rect = IRect::MakeSize(target_size);
149 return geometry->CoversArea(entity.GetTransform(), target_rect)
150 ? GetColor()
151 : std::optional<Color>();
152}
const Geometry * GetGeometry() const override
Get the geometry that this contents will use to render.
IRect64 IRect
Definition rect.h:825
Definition ref_ptr.h:261
static constexpr TRect MakeSize(const TSize< U > &size)
Definition rect.h:150
Type type
The type of shape to render.

References impeller::Geometry::CoversArea(), GetColor(), GetGeometry(), impeller::Entity::GetTransform(), impeller::UberSDFParameters::kRect, impeller::TRect< T >::MakeSize(), and impeller::UberSDFParameters::type.

◆ GetColor()

Color impeller::UberSDFContents::GetColor ( ) const

Definition at line 128 of file uber_sdf_contents.cc.

128 {
129 return params_.color;
130}

References impeller::UberSDFParameters::color.

Referenced by AsBackgroundColor().

◆ GetCoverage()

std::optional< Rect > impeller::UberSDFContents::GetCoverage ( const Entity entity) const
overridevirtual

Get the area of the render pass that will be affected when this contents is rendered.

During rendering, coverage coordinates count pixels from the top left corner of the framebuffer.

Returns
The coverage rectangle. An std::nullopt result means that rendering this contents has no effect on the output color.

Reimplemented from impeller::ColorSourceContents.

Definition at line 120 of file uber_sdf_contents.cc.

120 {
121 return GetGeometry()->GetCoverage(entity.GetTransform());
122}
virtual std::optional< Rect > GetCoverage(const Matrix &transform) const =0
The coverage rectangle of this geometry, transformed by the transform argument.

References impeller::Geometry::GetCoverage(), GetGeometry(), and impeller::Entity::GetTransform().

◆ GetGeometry()

const Geometry * impeller::UberSDFContents::GetGeometry ( ) const
overridevirtual

Get the geometry that this contents will use to render.

Implements impeller::ColorSourceContents.

Definition at line 124 of file uber_sdf_contents.cc.

124 {
125 return geometry_.get();
126}

Referenced by AsBackgroundColor(), GetCoverage(), and Render().

◆ Make()

std::unique_ptr< UberSDFContents > impeller::UberSDFContents::Make ( const UberSDFParameters params,
std::unique_ptr< Geometry geometry 
)
static

Definition at line 51 of file uber_sdf_contents.cc.

53 {
54 return std::unique_ptr<UberSDFContents>(
55 new UberSDFContents(params, std::move(geometry)));
56}
const EmbeddedViewParams * params

References params.

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

◆ Render()

bool impeller::UberSDFContents::Render ( const ContentContext renderer,
const Entity entity,
RenderPass pass 
) const
overridevirtual

Implements impeller::Contents.

Definition at line 64 of file uber_sdf_contents.cc.

66 {
67 auto& data_host_buffer = renderer.GetTransientsDataBuffer();
68
69 VS::FrameInfo frame_info;
70 FS::FragInfo frag_info;
71 frag_info.type = ToShaderType(params_.type);
72 frag_info.color =
73 params_.color.WithAlpha(params_.color.alpha * GetOpacityFactor());
74 frag_info.center = params_.center;
75 frag_info.size = params_.size;
76 frag_info.radii =
77 Vector4(params_.radii.bottom_right.width, params_.radii.top_right.width,
78 params_.radii.bottom_left.width, params_.radii.top_left.width);
79 frag_info.radii_right =
80 Vector4(params_.radii.bottom_right.height, params_.radii.top_right.height,
81 params_.radii.bottom_left.height, params_.radii.top_left.height);
82 frag_info.stroked = params_.stroke ? 1.0f : 0.0f;
83 frag_info.stroke_width = params_.stroke ? params_.stroke->width : 0.0f;
84 frag_info.stroke_join =
85 params_.stroke ? ToShaderStrokeJoin(params_.stroke->join) : 0.0f;
86 frag_info.aa_pixels = UberSDFParameters::kAntialiasPixels;
87 frag_info.superellipse_degree = params_.superellipse_degree;
88 frag_info.superellipse_a = params_.superellipse_a;
89 frag_info.corner_angle_span = params_.corner_angle_span;
90 frag_info.corner_circle_center_top = params_.corner_circle_center_top;
91 frag_info.corner_circle_center_right = params_.corner_circle_center_right;
92 frag_info.superellipse_c = params_.superellipse_c;
93 frag_info.superellipse_scale = params_.superellipse_scale;
94
95 auto geometry_result =
96 GetGeometry()->GetPositionBuffer(renderer, entity, pass);
97
98 PipelineBuilderCallback pipeline_callback =
99 [&renderer](ContentContextOptions options) {
100 return renderer.GetUberSDFPipeline(options);
101 };
102
103 return ColorSourceContents::DrawGeometry<VS>(
104 this, GetGeometry(), renderer, entity, pass, pipeline_callback,
105 frame_info,
106 /*bind_fragment_callback=*/
107 [&frag_info, &data_host_buffer](RenderPass& pass) {
108 FS::BindFragInfo(pass, data_host_buffer.EmplaceUniform(frag_info));
109 pass.SetCommandLabel("UberSDF");
110 return true;
111 },
112 /*force_stencil=*/false,
113 /*create_geom_callback=*/
114 [geometry_result = std::move(geometry_result)](
115 const ContentContext& renderer, const Entity& entity,
116 RenderPass& pass,
117 const Geometry* geometry) { return geometry_result; });
118}
Scalar GetOpacityFactor() const
Get the opacity factor for this color source.
std::function< PipelineRef(ContentContextOptions)> PipelineBuilderCallback
virtual GeometryResult GetPositionBuffer(const ContentContext &renderer, const Entity &entity, RenderPass &pass) const =0
constexpr ArchiveShaderType ToShaderType(fb::Stage stage)
Scalar alpha
Definition color.h:143
constexpr Color WithAlpha(Scalar new_alpha) const
Definition color.h:283
Type height
Definition size.h:29
Type width
Definition size.h:28
Point superellipse_a
The semi-axes of the top (.x) and right (.y) superellipse segments.
Point corner_circle_center_right
The center of the right circular arc in a RoundSuperellipse.
Point superellipse_degree
The degrees of the top (.x) and right (.y) octants of a RoundSuperellipse.
Point center
The center point of the shape in local coordinates.
Point corner_angle_span
The spans of the top (.x) and right (.y) circular arcs.
static constexpr Scalar kAntialiasPixels
Point superellipse_scale
The scale of the superellipse.
std::optional< StrokeParameters > stroke
The stroke parameters. If std::nullopt, the shape is filled.
Point corner_circle_center_top
The center of the top circular arc in a RoundSuperellipse.
Scalar superellipse_c
The offset of the octants in a RoundSuperellipse.

References impeller::Color::alpha, impeller::RoundingRadii::bottom_left, impeller::RoundingRadii::bottom_right, impeller::UberSDFParameters::center, impeller::UberSDFParameters::color, impeller::UberSDFParameters::corner_angle_span, impeller::UberSDFParameters::corner_circle_center_right, impeller::UberSDFParameters::corner_circle_center_top, GetGeometry(), impeller::ColorSourceContents::GetOpacityFactor(), impeller::Geometry::GetPositionBuffer(), impeller::ContentContext::GetTransientsDataBuffer(), impeller::ContentContext::GetUberSDFPipeline(), impeller::TSize< T >::height, impeller::UberSDFParameters::kAntialiasPixels, impeller::UberSDFParameters::radii, impeller::RenderPass::SetCommandLabel(), impeller::UberSDFParameters::size, impeller::UberSDFParameters::stroke, impeller::UberSDFParameters::superellipse_a, impeller::UberSDFParameters::superellipse_c, impeller::UberSDFParameters::superellipse_degree, impeller::UberSDFParameters::superellipse_scale, impeller::RoundingRadii::top_left, impeller::RoundingRadii::top_right, impeller::ToShaderType(), impeller::UberSDFParameters::type, impeller::TSize< T >::width, and impeller::Color::WithAlpha().


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