Flutter Impeller
impeller::VerticesSimpleBlendContents Class Referencefinal

#include <vertices_contents.h>

Inheritance diagram for impeller::VerticesSimpleBlendContents:
impeller::Contents

Public Types

using LazyTexture = std::function< std::shared_ptr< Texture >(const ContentContext &renderer)>
 
- 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

 VerticesSimpleBlendContents ()
 
 ~VerticesSimpleBlendContents () override
 
void SetGeometry (std::shared_ptr< VerticesGeometry > geometry)
 
void SetAlpha (Scalar alpha)
 
void SetBlendMode (BlendMode blend_mode)
 
void SetTexture (std::shared_ptr< Texture > texture)
 
void SetLazyTexture (const LazyTexture &lazy_texture)
 
void SetSamplerDescriptor (const SamplerDescriptor &descriptor)
 
void SetTileMode (Entity::TileMode tile_mode_x, Entity::TileMode tile_mode_y)
 
void SetEffectTransform (Matrix transform)
 
void SetLazyTextureCoverage (Rect rect)
 
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...
 
bool Render (const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
 
- 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 void SetInheritedOpacity (Scalar opacity)
 Inherit the provided opacity. More...
 
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...
 

Additional Inherited Members

- Static Public Member Functions inherited from impeller::Contents
static std::shared_ptr< Contents > MakeAnonymous (RenderProc render_proc, CoverageProc coverage_proc)
 

Detailed Description

A vertices contents for (optional) per-color vertices + texture and any blend mode.

Definition at line 20 of file vertices_contents.h.

Member Typedef Documentation

◆ LazyTexture

using impeller::VerticesSimpleBlendContents::LazyTexture = std::function<std::shared_ptr<Texture>(const ContentContext& renderer)>

Definition at line 26 of file vertices_contents.h.

Constructor & Destructor Documentation

◆ VerticesSimpleBlendContents()

impeller::VerticesSimpleBlendContents::VerticesSimpleBlendContents ( )

Definition at line 49 of file vertices_contents.cc.

49 {}

◆ ~VerticesSimpleBlendContents()

impeller::VerticesSimpleBlendContents::~VerticesSimpleBlendContents ( )
override

Definition at line 51 of file vertices_contents.cc.

51 {}

Member Function Documentation

◆ GetCoverage()

std::optional< Rect > impeller::VerticesSimpleBlendContents::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.

Implements impeller::Contents.

Definition at line 70 of file vertices_contents.cc.

71  {
72  return geometry_->GetCoverage(entity.GetTransform());
73 }

References impeller::Entity::GetTransform().

◆ Render()

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

Implements impeller::Contents.

Definition at line 99 of file vertices_contents.cc.

101  {
102  FML_DCHECK(texture_ || lazy_texture_ || blend_mode_ == BlendMode::kDst);
103  BlendMode blend_mode = blend_mode_;
104  if (!geometry_->HasVertexColors()) {
105  blend_mode = BlendMode::kSrc;
106  }
107 
108  std::shared_ptr<Texture> texture;
109  if (blend_mode != BlendMode::kDst) {
110  if (!texture_) {
111  texture = lazy_texture_(renderer);
112  } else {
113  texture = texture_;
114  }
115  } else {
116  texture = renderer.GetEmptyTexture();
117  }
118  if (!texture) {
119  VALIDATION_LOG << "Missing texture for VerticesSimpleBlendContents";
120  return false;
121  }
122 
123  auto dst_sampler_descriptor = descriptor_;
124  dst_sampler_descriptor.width_address_mode =
125  TileModeToAddressMode(tile_mode_x_, renderer.GetDeviceCapabilities())
127  dst_sampler_descriptor.height_address_mode =
128  TileModeToAddressMode(tile_mode_y_, renderer.GetDeviceCapabilities())
130 
131  raw_ptr<const Sampler> dst_sampler =
132  renderer.GetContext()->GetSamplerLibrary()->GetSampler(
133  dst_sampler_descriptor);
134 
135  GeometryResult geometry_result = geometry_->GetPositionUVColorBuffer(
136  lazy_texture_coverage_.has_value() ? lazy_texture_coverage_.value()
137  : Rect::MakeSize(texture->GetSize()),
138  inverse_matrix_, renderer, entity, pass);
139  if (geometry_result.vertex_buffer.vertex_count == 0) {
140  return true;
141  }
142  FML_DCHECK(geometry_result.mode == GeometryResult::Mode::kNormal);
143 
144  if (blend_mode <= Entity::kLastPipelineBlendMode) {
147 
148 #ifdef IMPELLER_DEBUG
149  pass.SetCommandLabel(std::format("DrawVertices Porterduff Blend ({})",
150  BlendModeToString(blend_mode)));
151 #endif // IMPELLER_DEBUG
152  pass.SetVertexBuffer(std::move(geometry_result.vertex_buffer));
153 
154  auto options = OptionsFromPassAndEntity(pass, entity);
155  options.primitive_type = geometry_result.type;
156  auto inverted_blend_mode =
157  InvertPorterDuffBlend(blend_mode).value_or(BlendMode::kSrc);
158  pass.SetPipeline(
159  renderer.GetPorterDuffPipeline(inverted_blend_mode, options));
160 
161  FS::BindTextureSamplerDst(pass, texture, dst_sampler);
162 
163  VS::FrameInfo frame_info;
164  FS::FragInfo frag_info;
165 
166  frame_info.mvp = geometry_result.transform;
167 
168  frag_info.input_alpha_output_alpha_tmx_tmy =
169  Vector4(1, alpha_, static_cast<int>(tile_mode_x_),
170  static_cast<int>(tile_mode_y_));
171  frag_info.use_strict_source_rect = 0.0;
172 
173  auto& host_buffer = renderer.GetTransientsDataBuffer();
174  FS::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info));
175  VS::BindFrameInfo(pass, host_buffer.EmplaceUniform(frame_info));
176 
177  return pass.Draw().ok();
178  }
179 
182 
183 #ifdef IMPELLER_DEBUG
184  pass.SetCommandLabel(std::format("DrawVertices Advanced Blend ({})",
185  BlendModeToString(blend_mode)));
186 #endif // IMPELLER_DEBUG
187  pass.SetVertexBuffer(std::move(geometry_result.vertex_buffer));
188 
189  auto options = OptionsFromPassAndEntity(pass, entity);
190  options.primitive_type = geometry_result.type;
191  pass.SetPipeline(renderer.GetDrawVerticesUberPipeline(blend_mode, options));
192 
193  FS::BindTextureSampler(pass, texture, dst_sampler);
194 
195  VS::FrameInfo frame_info;
196  FS::FragInfo frag_info;
197 
198  frame_info.mvp = geometry_result.transform;
199  frag_info.alpha = alpha_;
200  frag_info.blend_mode = static_cast<int>(blend_mode);
201 
202  // These values are ignored if the platform supports native decal mode.
203  frag_info.tmx = static_cast<int>(tile_mode_x_);
204  frag_info.tmy = static_cast<int>(tile_mode_y_);
205 
206  auto& host_buffer = renderer.GetTransientsDataBuffer();
207  FS::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info));
208  VS::BindFrameInfo(pass, host_buffer.EmplaceUniform(frame_info));
209 
210  return pass.Draw().ok();
211 }
static constexpr BlendMode kLastPipelineBlendMode
Definition: entity.h:28
FragmentShader_ FragmentShader
Definition: pipeline.h:169
const char * BlendModeToString(BlendMode blend_mode)
Definition: color.cc:45
LinePipeline::FragmentShader FS
static std::optional< SamplerAddressMode > TileModeToAddressMode(Entity::TileMode tile_mode, const Capabilities &capabilities)
std::optional< BlendMode > InvertPorterDuffBlend(BlendMode blend_mode)
BlendMode
Definition: color.h:58
LinePipeline::VertexShader VS
ContentContextOptions OptionsFromPassAndEntity(const RenderPass &pass, const Entity &entity)
Definition: contents.cc:34
@ kNormal
The geometry has no overlapping triangles.
SamplerAddressMode width_address_mode
constexpr static TRect MakeSize(const TSize< U > &size)
Definition: rect.h:150
#define VALIDATION_LOG
Definition: validation.h:91

References impeller::BlendModeToString(), impeller::RenderPass::Draw(), impeller::ContentContext::GetContext(), impeller::ContentContext::GetDeviceCapabilities(), impeller::ContentContext::GetDrawVerticesUberPipeline(), impeller::ContentContext::GetEmptyTexture(), impeller::ContentContext::GetPorterDuffPipeline(), impeller::ContentContext::GetTransientsDataBuffer(), impeller::InvertPorterDuffBlend(), impeller::kClampToEdge, impeller::kDst, impeller::Entity::kLastPipelineBlendMode, impeller::GeometryResult::kNormal, impeller::kSrc, impeller::TRect< Scalar >::MakeSize(), impeller::GeometryResult::mode, impeller::OptionsFromPassAndEntity(), impeller::RenderPass::SetCommandLabel(), impeller::RenderPass::SetPipeline(), impeller::RenderPass::SetVertexBuffer(), impeller::TileModeToAddressMode(), impeller::GeometryResult::transform, impeller::GeometryResult::type, VALIDATION_LOG, impeller::GeometryResult::vertex_buffer, impeller::VertexBuffer::vertex_count, and impeller::SamplerDescriptor::width_address_mode.

◆ SetAlpha()

void impeller::VerticesSimpleBlendContents::SetAlpha ( Scalar  alpha)

Definition at line 58 of file vertices_contents.cc.

58  {
59  alpha_ = alpha;
60 }

◆ SetBlendMode()

void impeller::VerticesSimpleBlendContents::SetBlendMode ( BlendMode  blend_mode)

Definition at line 62 of file vertices_contents.cc.

62  {
63  blend_mode_ = blend_mode;
64 }

◆ SetEffectTransform()

void impeller::VerticesSimpleBlendContents::SetEffectTransform ( Matrix  transform)

Definition at line 86 of file vertices_contents.cc.

86  {
87  inverse_matrix_ = transform.Invert();
88 }

References transform.

◆ SetGeometry()

void impeller::VerticesSimpleBlendContents::SetGeometry ( std::shared_ptr< VerticesGeometry >  geometry)

Definition at line 53 of file vertices_contents.cc.

54  {
55  geometry_ = std::move(geometry);
56 }

◆ SetLazyTexture()

void impeller::VerticesSimpleBlendContents::SetLazyTexture ( const LazyTexture &  lazy_texture)

Definition at line 90 of file vertices_contents.cc.

91  {
92  lazy_texture_ = lazy_texture;
93 }

◆ SetLazyTextureCoverage()

void impeller::VerticesSimpleBlendContents::SetLazyTextureCoverage ( Rect  rect)

Definition at line 95 of file vertices_contents.cc.

95  {
96  lazy_texture_coverage_ = rect;
97 }

◆ SetSamplerDescriptor()

void impeller::VerticesSimpleBlendContents::SetSamplerDescriptor ( const SamplerDescriptor &  descriptor)

Definition at line 75 of file vertices_contents.cc.

76  {
77  descriptor_ = descriptor;
78 }

◆ SetTexture()

void impeller::VerticesSimpleBlendContents::SetTexture ( std::shared_ptr< Texture >  texture)

Definition at line 66 of file vertices_contents.cc.

66  {
67  texture_ = std::move(texture);
68 }

◆ SetTileMode()

void impeller::VerticesSimpleBlendContents::SetTileMode ( Entity::TileMode  tile_mode_x,
Entity::TileMode  tile_mode_y 
)

Definition at line 80 of file vertices_contents.cc.

81  {
82  tile_mode_x_ = tile_mode_x;
83  tile_mode_y_ = tile_mode_y;
84 }

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