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< RectGetCoverage (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< SnapshotRenderToSnapshot (const ContentContext &renderer, const Entity &entity, std::optional< Rect > coverage_limit=std::nullopt, const std::optional< SamplerDescriptor > &sampler_descriptor=std::nullopt, bool msaa_enabled=true, int32_t mip_count=1, std::string_view label="Snapshot") 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 void SetInheritedOpacity (Scalar opacity)
 Inherit the provided opacity. More...
 
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...
 
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< ContentsMakeAnonymous (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 47 of file vertices_contents.cc.

47 {}

◆ ~VerticesSimpleBlendContents()

impeller::VerticesSimpleBlendContents::~VerticesSimpleBlendContents ( )
override

Definition at line 49 of file vertices_contents.cc.

49 {}

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 68 of file vertices_contents.cc.

69  {
70  return geometry_->GetCoverage(entity.GetTransform());
71 }

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 97 of file vertices_contents.cc.

99  {
100  FML_DCHECK(texture_ || lazy_texture_ || blend_mode_ == BlendMode::kDst);
101  BlendMode blend_mode = blend_mode_;
102  if (!geometry_->HasVertexColors()) {
103  blend_mode = BlendMode::kSrc;
104  }
105 
106  std::shared_ptr<Texture> texture;
107  if (blend_mode != BlendMode::kDst) {
108  if (!texture_) {
109  texture = lazy_texture_(renderer);
110  } else {
111  texture = texture_;
112  }
113  } else {
114  texture = renderer.GetEmptyTexture();
115  }
116  if (!texture) {
117  VALIDATION_LOG << "Missing texture for VerticesSimpleBlendContents";
118  return false;
119  }
120 
121  auto dst_sampler_descriptor = descriptor_;
122  dst_sampler_descriptor.width_address_mode =
123  TileModeToAddressMode(tile_mode_x_, renderer.GetDeviceCapabilities())
125  dst_sampler_descriptor.height_address_mode =
126  TileModeToAddressMode(tile_mode_y_, renderer.GetDeviceCapabilities())
128 
129  raw_ptr<const Sampler> dst_sampler =
130  renderer.GetContext()->GetSamplerLibrary()->GetSampler(
131  dst_sampler_descriptor);
132 
133  GeometryResult geometry_result = geometry_->GetPositionUVColorBuffer(
134  lazy_texture_coverage_.has_value() ? lazy_texture_coverage_.value()
135  : Rect::MakeSize(texture->GetSize()),
136  inverse_matrix_, renderer, entity, pass);
137  if (geometry_result.vertex_buffer.vertex_count == 0) {
138  return true;
139  }
140  FML_DCHECK(geometry_result.mode == GeometryResult::Mode::kNormal);
141 
142  if (blend_mode <= Entity::kLastPipelineBlendMode) {
145 
146 #ifdef IMPELLER_DEBUG
147  pass.SetCommandLabel(SPrintF("DrawVertices Porterduff Blend (%s)",
148  BlendModeToString(blend_mode)));
149 #endif // IMPELLER_DEBUG
150  pass.SetVertexBuffer(std::move(geometry_result.vertex_buffer));
151 
152  auto options = OptionsFromPassAndEntity(pass, entity);
153  options.primitive_type = geometry_result.type;
154  auto inverted_blend_mode =
155  InvertPorterDuffBlend(blend_mode).value_or(BlendMode::kSrc);
156  pass.SetPipeline(
157  renderer.GetPorterDuffPipeline(inverted_blend_mode, options));
158 
159  FS::BindTextureSamplerDst(pass, texture, dst_sampler);
160 
161  VS::FrameInfo frame_info;
162  FS::FragInfo frag_info;
163 
164  frame_info.texture_sampler_y_coord_scale = texture->GetYCoordScale();
165  frame_info.mvp = geometry_result.transform;
166 
167  frag_info.input_alpha_output_alpha_tmx_tmy =
168  Vector4(1, alpha_, static_cast<int>(tile_mode_x_),
169  static_cast<int>(tile_mode_y_));
170  frag_info.use_strict_source_rect = 0.0;
171 
172  auto& host_buffer = renderer.GetTransientsBuffer();
173  FS::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info));
174  VS::BindFrameInfo(pass, host_buffer.EmplaceUniform(frame_info));
175 
176  return pass.Draw().ok();
177  }
178 
181 
182 #ifdef IMPELLER_DEBUG
183  pass.SetCommandLabel(SPrintF("DrawVertices Advanced Blend (%s)",
184  BlendModeToString(blend_mode)));
185 #endif // IMPELLER_DEBUG
186  pass.SetVertexBuffer(std::move(geometry_result.vertex_buffer));
187 
188  auto options = OptionsFromPassAndEntity(pass, entity);
189  options.primitive_type = geometry_result.type;
190  pass.SetPipeline(renderer.GetDrawVerticesUberPipeline(blend_mode, options));
191 
192  FS::BindTextureSampler(pass, texture, dst_sampler);
193 
194  VS::FrameInfo frame_info;
195  FS::FragInfo frag_info;
196 
197  frame_info.texture_sampler_y_coord_scale = texture->GetYCoordScale();
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.GetTransientsBuffer();
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:164
const char * BlendModeToString(BlendMode blend_mode)
Definition: color.cc:47
std::string SPrintF(const char *format,...)
Definition: strings.cc:12
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::GetTransientsBuffer(), 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::SPrintF(), 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 56 of file vertices_contents.cc.

56  {
57  alpha_ = alpha;
58 }

◆ SetBlendMode()

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

Definition at line 60 of file vertices_contents.cc.

60  {
61  blend_mode_ = blend_mode;
62 }

◆ SetEffectTransform()

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

Definition at line 84 of file vertices_contents.cc.

84  {
85  inverse_matrix_ = transform.Invert();
86 }

References transform.

◆ SetGeometry()

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

Definition at line 51 of file vertices_contents.cc.

52  {
53  geometry_ = std::move(geometry);
54 }

◆ SetLazyTexture()

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

Definition at line 88 of file vertices_contents.cc.

89  {
90  lazy_texture_ = lazy_texture;
91 }

◆ SetLazyTextureCoverage()

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

Definition at line 93 of file vertices_contents.cc.

93  {
94  lazy_texture_coverage_ = rect;
95 }

◆ SetSamplerDescriptor()

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

Definition at line 73 of file vertices_contents.cc.

74  {
75  descriptor_ = descriptor;
76 }

◆ SetTexture()

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

Definition at line 64 of file vertices_contents.cc.

64  {
65  texture_ = std::move(texture);
66 }

◆ SetTileMode()

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

Definition at line 78 of file vertices_contents.cc.

79  {
80  tile_mode_x_ = tile_mode_x;
81  tile_mode_y_ = tile_mode_y;
82 }

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