Flutter Impeller
impeller::UberSDFContents Class Reference

#include <uber_sdf_contents.h>

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

Public Types

enum class  Type {
  kCircle ,
  kRect
}
 
- 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)>
 

Public Member Functions

 UberSDFContents (Type type, Rect rect, Color color, Scalar stroke_width, Join stroke_join, bool stroked, const Geometry *geometry, Scalar aa_padding)
 
 ~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. More...
 
Color GetColor () const
 
bool ApplyColorFilter (const ColorFilterProc &color_filter_proc) override
 If possible, applies a color filter to this contents inputs on the CPU. More...
 
const GeometryGetGeometry () 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 MatrixGetInverseEffectTransform () const
 Set 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< 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). More...
 
std::optional< SizeGetColorSourceSize () const
 Return the color source's intrinsic size, if available. More...
 
void SetColorSourceSize (Size size)
 
virtual std::optional< ColorAsBackgroundColor (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...
 

Static Public Member Functions

static std::unique_ptr< UberSDFContentsMakeRect (Color color, Scalar stroke_width, Join stroke_join, bool stroked, const FillRectGeometry *geometry)
 
static std::unique_ptr< UberSDFContentsMakeCircle (Color color, bool stroked, const CircleGeometry *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

- 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

Definition at line 20 of file uber_sdf_contents.h.

Member Enumeration Documentation

◆ Type

Enumerator
kCircle 
kRect 

Definition at line 22 of file uber_sdf_contents.h.

22  {
23  kCircle,
24  kRect,
25  };

Constructor & Destructor Documentation

◆ UberSDFContents()

impeller::UberSDFContents::UberSDFContents ( Type  type,
Rect  rect,
Color  color,
Scalar  stroke_width,
Join  stroke_join,
bool  stroked,
const Geometry geometry,
Scalar  aa_padding 
)

Definition at line 51 of file uber_sdf_contents.cc.

59  : type_(type),
60  bounding_box_(bounding_box),
61  color_(color),
62  stroke_width_(stroke_width),
63  stroke_join_(stroke_join),
64  stroked_(stroked),
65  geometry_(geometry),
66  aa_padding_(aa_padding) {}

Referenced by MakeCircle().

◆ ~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 134 of file uber_sdf_contents.cc.

135  {
136  color_ = color_filter_proc(color_);
137  return true;
138 }

◆ GetColor()

Color impeller::UberSDFContents::GetColor ( ) const

Definition at line 130 of file uber_sdf_contents.cc.

130  {
131  return color_;
132 }

◆ 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 122 of file uber_sdf_contents.cc.

122  {
123  return GetGeometry()->GetCoverage(entity.GetTransform());
124 }
virtual std::optional< Rect > GetCoverage(const Matrix &transform) const =0
const Geometry * GetGeometry() const override
Get the geometry that this contents will use to render.

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 126 of file uber_sdf_contents.cc.

126  {
127  return geometry_;
128 }

Referenced by GetCoverage(), and Render().

◆ MakeCircle()

std::unique_ptr< UberSDFContents > impeller::UberSDFContents::MakeCircle ( Color  color,
bool  stroked,
const CircleGeometry geometry 
)
static

Definition at line 37 of file uber_sdf_contents.cc.

40  {
41  Point center = geometry->GetCenter();
42  Scalar radius = geometry->GetRadius();
43  Rect bounding_box = Rect::MakeXYWH(center.x - radius, center.y - radius,
44  radius * 2, radius * 2);
45  Scalar aa_padding = geometry->GetAntialiasPadding();
46  return std::unique_ptr<UberSDFContents>(new UberSDFContents(
47  Type::kCircle, bounding_box, color, geometry->GetStrokeWidth(),
48  Join::kMiter, stroked, geometry, aa_padding));
49 }
UberSDFContents(Type type, Rect rect, Color color, Scalar stroke_width, Join stroke_join, bool stroked, const Geometry *geometry, Scalar aa_padding)
float Scalar
Definition: scalar.h:19
TRect< Scalar > Rect
Definition: rect.h:788
TPoint< Scalar > Point
Definition: point.h:426
constexpr static TRect MakeXYWH(Type x, Type y, Type width, Type height)
Definition: rect.h:136

References impeller::CircleGeometry::GetAntialiasPadding(), impeller::CircleGeometry::GetCenter(), impeller::CircleGeometry::GetRadius(), impeller::CircleGeometry::GetStrokeWidth(), kCircle, impeller::kMiter, impeller::TRect< Scalar >::MakeXYWH(), UberSDFContents(), impeller::TPoint< T >::x, and impeller::TPoint< T >::y.

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

◆ MakeRect()

std::unique_ptr< UberSDFContents > impeller::UberSDFContents::MakeRect ( Color  color,
Scalar  stroke_width,
Join  stroke_join,
bool  stroked,
const FillRectGeometry geometry 
)
static

Definition at line 24 of file uber_sdf_contents.cc.

29  {
30  Rect bounding_box = geometry->GetRect();
31  Scalar aa_padding = 1.0f;
32  return std::make_unique<UberSDFContents>(Type::kRect, bounding_box, color,
33  stroke_width, stroke_join, stroked,
34  geometry, aa_padding);
35 }

References impeller::FillRectGeometry::GetRect(), and kRect.

Referenced by impeller::Canvas::DrawRect(), 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 70 of file uber_sdf_contents.cc.

72  {
73  auto& data_host_buffer = renderer.GetTransientsDataBuffer();
74 
75  VS::FrameInfo frame_info;
76  FS::FragInfo frag_info;
77  frag_info.color = color_.WithAlpha(color_.alpha * GetOpacityFactor());
78  frag_info.center = bounding_box_.GetCenter();
79  frag_info.size =
80  Point(bounding_box_.GetWidth() / 2.0f, bounding_box_.GetHeight() / 2.0f);
81  frag_info.stroke_width = stroke_width_;
82  switch (stroke_join_) {
83  case Join::kMiter:
84  frag_info.stroke_join = 0.0f;
85  break;
86  case Join::kBevel:
87  frag_info.stroke_join = 1.0f;
88  break;
89  case Join::kRound:
90  frag_info.stroke_join = 2.0f;
91  break;
92  }
93  frag_info.aa_pixels = aa_padding_;
94  frag_info.stroked = stroked_ ? 1.0f : 0.0f;
95  frag_info.type = type_ == Type::kCircle ? 0.0f : 1.0f;
96 
97  auto geometry_result =
98  GetGeometry()->GetPositionBuffer(renderer, entity, pass);
99 
100  PipelineBuilderCallback pipeline_callback =
101  [&renderer](ContentContextOptions options) {
102  return renderer.GetUberSDFPipeline(options);
103  };
104 
105  return ColorSourceContents::DrawGeometry<VS>(
106  this, GetGeometry(), renderer, entity, pass, pipeline_callback,
107  frame_info,
108  /*bind_fragment_callback=*/
109  [&frag_info, &data_host_buffer](RenderPass& pass) {
110  FS::BindFragInfo(pass, data_host_buffer.EmplaceUniform(frag_info));
111  pass.SetCommandLabel("UberSDF");
112  return true;
113  },
114  /*force_stencil=*/false,
115  /*create_geom_callback=*/
116  [geometry_result = std::move(geometry_result)](
117  const ContentContext& renderer, const Entity& entity,
118  RenderPass& pass,
119  const Geometry* geometry) { return geometry_result; });
120 }
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
Scalar alpha
Definition: color.h:143
constexpr Color WithAlpha(Scalar new_alpha) const
Definition: color.h:278
constexpr Type GetHeight() const
Returns the height of the rectangle, equivalent to |GetSize().height|.
Definition: rect.h:347
constexpr Type GetWidth() const
Returns the width of the rectangle, equivalent to |GetSize().width|.
Definition: rect.h:341
constexpr Point GetCenter() const
Get the center point as a |Point|.
Definition: rect.h:382

References impeller::Color::alpha, impeller::TRect< T >::GetCenter(), GetGeometry(), impeller::TRect< T >::GetHeight(), impeller::ColorSourceContents::GetOpacityFactor(), impeller::Geometry::GetPositionBuffer(), impeller::ContentContext::GetTransientsDataBuffer(), impeller::ContentContext::GetUberSDFPipeline(), impeller::TRect< T >::GetWidth(), impeller::kBevel, kCircle, impeller::kMiter, impeller::kRound, impeller::RenderPass::SetCommandLabel(), and impeller::Color::WithAlpha().


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