Flutter Impeller
impeller::ComplexRoundedSuperellipseContents Class Reference

#include <complex_rse_contents.h>

Inheritance diagram for impeller::ComplexRoundedSuperellipseContents:
impeller::ColorSourceContents impeller::Contents

Public Member Functions

bool Render (const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
 
std::optional< Rect > GetCoverage (const Entity &entity) const override
 Get the area of the render pass that will be affected when this contents is rendered. More...
 
const Geometry * GetGeometry () const override
 Get the geometry that this contents will use to render. More...
 
- Public Member Functions inherited from impeller::ColorSourceContents
 ColorSourceContents ()
 
 ~ColorSourceContents () override
 
void SetEffectTransform (Matrix matrix)
 Set the effect transform for this color source. More...
 
const Matrix & GetInverseEffectTransform () const
 Get the inverted effect transform for this color source. More...
 
void SetOpacityFactor (Scalar opacity)
 Set the opacity factor for this color source. More...
 
Scalar GetOpacityFactor () const
 Get the opacity factor for this color source. More...
 
virtual bool IsSolidColor () const
 
void SetInheritedOpacity (Scalar opacity) override
 Inherit the provided opacity. More...
 
- 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(). More...
 
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. More...
 
virtual std::optional< Snapshot > RenderToSnapshot (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). More...
 
std::optional< Size > GetColorSourceSize () const
 Return the color source's intrinsic size, if available. More...
 
void SetColorSourceSize (Size size)
 
virtual std::optional< Color > AsBackgroundColor (const Entity &entity, ISize target_size) const
 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. More...
 
virtual bool ApplyColorFilter (const ColorFilterProc &color_filter_proc)
 If possible, applies a color filter to this contents inputs on the CPU. More...
 

Static Public Member Functions

static std::unique_ptr< ComplexRoundedSuperellipseContents > Make (Color color, const Rect &bounds, const RoundSuperellipseParam &round_superellipse_params, std::optional< StrokeParameters > stroke)
 
- 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< Contents > MakeAnonymous (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. More...
 
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

A Contents class that renders asymmetric rounded superellipses using SDFs.

Separated from 'UberSDFContents' to reduce uniform bloat

Definition at line 24 of file complex_rse_contents.h.

Member Function Documentation

◆ GetCoverage()

std::optional< Rect > impeller::ComplexRoundedSuperellipseContents::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 163 of file complex_rse_contents.cc.

164  {
165  return GetGeometry()->GetCoverage(entity.GetTransform());
166 }
const Geometry * GetGeometry() const override
Get the geometry that this contents will use to render.
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::ComplexRoundedSuperellipseContents::GetGeometry ( ) const
overridevirtual

Get the geometry that this contents will use to render.

Implements impeller::ColorSourceContents.

Definition at line 168 of file complex_rse_contents.cc.

168  {
169  return geometry_.get();
170 }

Referenced by GetCoverage(), and Render().

◆ Make()

std::unique_ptr< ComplexRoundedSuperellipseContents > impeller::ComplexRoundedSuperellipseContents::Make ( Color  color,
const Rect &  bounds,
const RoundSuperellipseParam &  round_superellipse_params,
std::optional< StrokeParameters >  stroke 
)
static

Definition at line 25 of file complex_rse_contents.cc.

29  {
30  return std::unique_ptr<ComplexRoundedSuperellipseContents>(
31  new ComplexRoundedSuperellipseContents(
32  color, bounds, round_superellipse_params, stroke));
33 }

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

◆ Render()

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

Implements impeller::Contents.

Definition at line 51 of file complex_rse_contents.cc.

53  {
54  auto& data_host_buffer = renderer.GetTransientsDataBuffer();
55 
56  Point center = bounds_.GetCenter();
57 
58  RoundSuperellipseParam::Quadrant top_right =
59  round_superellipse_params_.top_right;
60  RoundSuperellipseParam::Quadrant bottom_right =
61  round_superellipse_params_.bottom_right;
62  RoundSuperellipseParam::Quadrant bottom_left =
63  round_superellipse_params_.bottom_left;
64  RoundSuperellipseParam::Quadrant top_left =
65  round_superellipse_params_.top_left;
66 
67  Point top_right_center_relative = top_right.offset - center;
68  Point bottom_right_center_relative = bottom_right.offset - center;
69  Point bottom_left_center_relative = bottom_left.offset - center;
70  Point top_left_center_relative = top_left.offset - center;
71 
72  Point size = Point(bounds_.GetSize() * 0.5f);
73 
74  VS::FrameInfo frame_info;
75  FS::FragInfo frag_info;
76 
77  frag_info.color = color_.WithAlpha(color_.alpha * GetOpacityFactor());
78  frag_info.center = center;
79  frag_info.size = size;
80  frag_info.stroked = stroke_ ? 1.0f : 0.0f;
81  frag_info.stroke_width = stroke_ ? stroke_->width : 0.0f;
82 
83  frag_info.superellipse_degrees_top =
84  Vector4(bottom_right.top.se_n, top_right.top.se_n, bottom_left.top.se_n,
85  top_left.top.se_n);
86  frag_info.superellipse_degrees_right =
87  Vector4(bottom_right.right.se_n, top_right.right.se_n,
88  bottom_left.right.se_n, top_left.right.se_n);
89  frag_info.superellipse_semi_axes_top =
90  Vector4(bottom_right.top.se_a, top_right.top.se_a, bottom_left.top.se_a,
91  top_left.top.se_a);
92  frag_info.superellipse_semi_axes_right =
93  Vector4(bottom_right.right.se_a, top_right.right.se_a,
94  bottom_left.right.se_a, top_left.right.se_a);
95  frag_info.angle_spans_top = Vector4(bottom_right.top.circle_max_angle.radians,
96  top_right.top.circle_max_angle.radians,
97  bottom_left.top.circle_max_angle.radians,
98  top_left.top.circle_max_angle.radians);
99  frag_info.angle_spans_right =
100  Vector4(bottom_right.right.circle_max_angle.radians,
101  top_right.right.circle_max_angle.radians,
102  bottom_left.right.circle_max_angle.radians,
103  top_left.right.circle_max_angle.radians);
104  frag_info.octant_offsets_c =
105  Vector4(bottom_right.top.se_a - bottom_right.right.se_a,
106  top_right.top.se_a - top_right.right.se_a,
107  bottom_left.top.se_a - bottom_left.right.se_a,
108  top_left.top.se_a - top_left.right.se_a);
109  frag_info.radii_width =
110  Vector4(bottom_right.top.circle_radius, top_right.top.circle_radius,
111  bottom_left.top.circle_radius, top_left.top.circle_radius);
112  frag_info.radii_height =
113  Vector4(bottom_right.right.circle_radius, top_right.right.circle_radius,
114  bottom_left.right.circle_radius, top_left.right.circle_radius);
115  frag_info.circle_centers_top_x =
116  Vector4(bottom_right.top.circle_center.x, top_right.top.circle_center.x,
117  bottom_left.top.circle_center.x, top_left.top.circle_center.x);
118  frag_info.circle_centers_top_y =
119  Vector4(bottom_right.top.circle_center.y, top_right.top.circle_center.y,
120  bottom_left.top.circle_center.y, top_left.top.circle_center.y);
121  frag_info.circle_centers_right_x = Vector4(
122  bottom_right.right.circle_center.x, top_right.right.circle_center.x,
123  bottom_left.right.circle_center.x, top_left.right.circle_center.x);
124  frag_info.circle_centers_right_y = Vector4(
125  bottom_right.right.circle_center.y, top_right.right.circle_center.y,
126  bottom_left.right.circle_center.y, top_left.right.circle_center.y);
127  frag_info.superellipse_scales_x =
128  Vector4(bottom_right.signed_scale.Abs().x, top_right.signed_scale.Abs().x,
129  bottom_left.signed_scale.Abs().x, top_left.signed_scale.Abs().x);
130  frag_info.superellipse_scales_y =
131  Vector4(bottom_right.signed_scale.Abs().y, top_right.signed_scale.Abs().y,
132  bottom_left.signed_scale.Abs().y, top_left.signed_scale.Abs().y);
133  frag_info.quadrant_centers_x =
134  Vector4(bottom_right_center_relative.x, top_right_center_relative.x,
135  bottom_left_center_relative.x, top_left_center_relative.x);
136  frag_info.quadrant_centers_y =
137  Vector4(bottom_right_center_relative.y, top_right_center_relative.y,
138  bottom_left_center_relative.y, top_left_center_relative.y);
139  frag_info.quadrant_splits =
140  Vector4(round_superellipse_params_.top_split - center.x,
141  round_superellipse_params_.bottom_split - center.x,
142  round_superellipse_params_.left_split - center.y,
143  round_superellipse_params_.right_split - center.y);
144 
145  auto geometry_result =
146  GetGeometry()->GetPositionBuffer(renderer, entity, pass);
147 
148  PipelineBuilderCallback pipeline_callback =
149  [&renderer](ContentContextOptions options) {
150  return renderer.GetComplexRSEPipeline(options);
151  };
152 
153  return ColorSourceContents::DrawGeometry<VS>(
154  this, GetGeometry(), renderer, entity, pass, pipeline_callback,
155  frame_info,
156  /*bind_fragment_callback=*/
157  [&frag_info, &data_host_buffer](RenderPass& pass) {
158  FS::BindFragInfo(pass, data_host_buffer.EmplaceUniform(frag_info));
159  return true;
160  });
161 }
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
TPoint< Scalar > Point
Definition: point.h:426
Scalar alpha
Definition: color.h:143
constexpr Color WithAlpha(Scalar new_alpha) const
Definition: color.h:283
constexpr TSize< Type > GetSize() const
Returns the size of the rectangle which may be negative in either width or height and may have been c...
Definition: rect.h:361
constexpr Point GetCenter() const
Get the center point as a |Point|.
Definition: rect.h:416

References impeller::TPoint< T >::Abs(), impeller::Color::alpha, impeller::RoundSuperellipseParam::bottom_left, impeller::RoundSuperellipseParam::bottom_right, impeller::RoundSuperellipseParam::bottom_split, impeller::RoundSuperellipseParam::Octant::circle_center, impeller::RoundSuperellipseParam::Octant::circle_max_angle, impeller::RoundSuperellipseParam::Octant::circle_radius, impeller::TRect< T >::GetCenter(), impeller::ContentContext::GetComplexRSEPipeline(), GetGeometry(), impeller::ColorSourceContents::GetOpacityFactor(), impeller::Geometry::GetPositionBuffer(), impeller::TRect< T >::GetSize(), impeller::ContentContext::GetTransientsDataBuffer(), impeller::RoundSuperellipseParam::left_split, impeller::RoundSuperellipseParam::Quadrant::offset, impeller::Radians::radians, impeller::RoundSuperellipseParam::Quadrant::right, impeller::RoundSuperellipseParam::right_split, impeller::RoundSuperellipseParam::Octant::se_a, impeller::RoundSuperellipseParam::Octant::se_n, impeller::RoundSuperellipseParam::Quadrant::signed_scale, impeller::RoundSuperellipseParam::Quadrant::top, impeller::RoundSuperellipseParam::top_left, impeller::RoundSuperellipseParam::top_right, impeller::RoundSuperellipseParam::top_split, impeller::Color::WithAlpha(), impeller::TPoint< T >::x, and impeller::TPoint< T >::y.


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