Flutter Impeller
impeller::AtlasContents Class Referencefinal

#include <atlas_contents.h>

Inheritance diagram for impeller::AtlasContents:
impeller::Contents

Public Member Functions

 AtlasContents ()
 
 ~AtlasContents () override
 
void SetGeometry (AtlasGeometry *geometry)
 
void SetAlpha (Scalar alpha)
 
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

- 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)>
 
- Static Public Member Functions inherited from impeller::Contents
static std::shared_ptr< ContentsMakeAnonymous (RenderProc render_proc, CoverageProc coverage_proc)
 

Detailed Description

Definition at line 40 of file atlas_contents.h.

Constructor & Destructor Documentation

◆ AtlasContents()

impeller::AtlasContents::AtlasContents ( )
explicitdefault

◆ ~AtlasContents()

impeller::AtlasContents::~AtlasContents ( )
overridedefault

Member Function Documentation

◆ GetCoverage()

std::optional< Rect > impeller::AtlasContents::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 23 of file atlas_contents.cc.

23  {
24  if (!geometry_) {
25  return std::nullopt;
26  }
27  return geometry_->ComputeBoundingBox().TransformBounds(entity.GetTransform());
28 }
virtual Rect ComputeBoundingBox() const =0
constexpr TRect TransformBounds(const Matrix &transform) const
Creates a new bounding box that contains this transformed rectangle.
Definition: rect.h:476

References impeller::AtlasGeometry::ComputeBoundingBox(), impeller::Entity::GetTransform(), and impeller::TRect< T >::TransformBounds().

◆ Render()

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

Implements impeller::Contents.

Definition at line 38 of file atlas_contents.cc.

40  {
41  if (geometry_->ShouldSkip() || alpha_ <= 0.0) {
42  return true;
43  }
44 
45  auto dst_sampler_descriptor = geometry_->GetSamplerDescriptor();
46  if (renderer.GetDeviceCapabilities().SupportsDecalSamplerAddressMode()) {
47  dst_sampler_descriptor.width_address_mode = SamplerAddressMode::kDecal;
48  dst_sampler_descriptor.height_address_mode = SamplerAddressMode::kDecal;
49  }
50  raw_ptr<const Sampler> dst_sampler =
51  renderer.GetContext()->GetSamplerLibrary()->GetSampler(
52  dst_sampler_descriptor);
53 
54  auto& host_buffer = renderer.GetTransientsBuffer();
55  if (!geometry_->ShouldUseBlend()) {
56  using VS = TextureFillVertexShader;
57  using FS = TextureFillFragmentShader;
58 
59  auto dst_sampler_descriptor = geometry_->GetSamplerDescriptor();
60 
61  raw_ptr<const Sampler> dst_sampler =
62  renderer.GetContext()->GetSamplerLibrary()->GetSampler(
63  dst_sampler_descriptor);
64 
65  auto pipeline_options = OptionsFromPassAndEntity(pass, entity);
66  pipeline_options.primitive_type = PrimitiveType::kTriangle;
67  pipeline_options.depth_write_enabled =
68  pipeline_options.blend_mode == BlendMode::kSource;
69 
70  pass.SetPipeline(renderer.GetTexturePipeline(pipeline_options));
71  pass.SetVertexBuffer(geometry_->CreateSimpleVertexBuffer(host_buffer));
72 #ifdef IMPELLER_DEBUG
73  pass.SetCommandLabel("DrawAtlas");
74 #endif // IMPELLER_DEBUG
75 
76  VS::FrameInfo frame_info;
77  frame_info.mvp = entity.GetShaderTransform(pass);
78  frame_info.texture_sampler_y_coord_scale =
79  geometry_->GetAtlas()->GetYCoordScale();
80 
81  VS::BindFrameInfo(pass, host_buffer.EmplaceUniform(frame_info));
82 
83  FS::FragInfo frag_info;
84  frag_info.alpha = alpha_;
85  FS::BindFragInfo(pass, host_buffer.EmplaceUniform((frag_info)));
86  FS::BindTextureSampler(pass, geometry_->GetAtlas(), dst_sampler);
87  return pass.Draw().ok();
88  }
89 
90  BlendMode blend_mode = geometry_->GetBlendMode();
91 
92  if (blend_mode <= BlendMode::kModulate) {
95 
96 #ifdef IMPELLER_DEBUG
97  pass.SetCommandLabel("DrawAtlas Blend");
98 #endif // IMPELLER_DEBUG
99  pass.SetVertexBuffer(geometry_->CreateBlendVertexBuffer(host_buffer));
100  auto inverted_blend_mode =
101  InvertPorterDuffBlend(blend_mode).value_or(BlendMode::kSource);
102  pass.SetPipeline(renderer.GetPorterDuffPipeline(inverted_blend_mode,
103  OptionsFromPass(pass)));
104 
105  FS::FragInfo frag_info;
106  VS::FrameInfo frame_info;
107 
108  FS::BindTextureSamplerDst(pass, geometry_->GetAtlas(), dst_sampler);
109  frame_info.texture_sampler_y_coord_scale =
110  geometry_->GetAtlas()->GetYCoordScale();
111 
112  frag_info.output_alpha = alpha_;
113  frag_info.input_alpha = 1.0;
114 
115  // These values are ignored on platforms that natively support decal.
116  frag_info.tmx = static_cast<int>(Entity::TileMode::kDecal);
117  frag_info.tmy = static_cast<int>(Entity::TileMode::kDecal);
118 
119  FS::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info));
120 
121  frame_info.mvp = entity.GetShaderTransform(pass);
122 
123  auto uniform_view = host_buffer.EmplaceUniform(frame_info);
124  VS::BindFrameInfo(pass, uniform_view);
125 
126  return pass.Draw().ok();
127  }
128 
131 
132 #ifdef IMPELLER_DEBUG
133  pass.SetCommandLabel("DrawAtlas Advanced Blend");
134 #endif // IMPELLER_DEBUG
135  pass.SetVertexBuffer(geometry_->CreateBlendVertexBuffer(host_buffer));
136 
137  pass.SetPipeline(renderer.GetDrawVerticesUberShader(OptionsFromPass(pass)));
138  FS::BindTextureSampler(pass, geometry_->GetAtlas(), dst_sampler);
139 
140  VUS::FrameInfo frame_info;
141  FS::FragInfo frag_info;
142 
143  frame_info.texture_sampler_y_coord_scale =
144  geometry_->GetAtlas()->GetYCoordScale();
145  frame_info.mvp = entity.GetShaderTransform(pass);
146 
147  frag_info.alpha = alpha_;
148  frag_info.blend_mode = static_cast<int>(blend_mode);
149 
150  // These values are ignored on platforms that natively support decal.
151  frag_info.tmx = static_cast<int>(Entity::TileMode::kDecal);
152  frag_info.tmy = static_cast<int>(Entity::TileMode::kDecal);
153 
154  FS::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info));
155  VUS::BindFrameInfo(pass, host_buffer.EmplaceUniform(frame_info));
156 
157  return pass.Draw().ok();
158 }
virtual VertexBuffer CreateSimpleVertexBuffer(HostBuffer &host_buffer) const =0
virtual bool ShouldUseBlend() const =0
virtual std::shared_ptr< Texture > GetAtlas() const =0
virtual const SamplerDescriptor & GetSamplerDescriptor() const =0
virtual bool ShouldSkip() const =0
virtual VertexBuffer CreateBlendVertexBuffer(HostBuffer &host_buffer) const =0
virtual BlendMode GetBlendMode() const =0
FragmentShader_ FragmentShader
Definition: pipeline.h:114
@ kDecal
decal sampling mode is only supported on devices that pass the Capabilities.SupportsDecalSamplerAddre...
GlyphAtlasPipeline::VertexShader VS
std::optional< BlendMode > InvertPorterDuffBlend(BlendMode blend_mode)
BlendMode
Definition: color.h:58
GlyphAtlasPipeline::FragmentShader FS
ContentContextOptions OptionsFromPassAndEntity(const RenderPass &pass, const Entity &entity)
Definition: contents.cc:34
ContentContextOptions OptionsFromPass(const RenderPass &pass)
Definition: contents.cc:19
SamplerAddressMode width_address_mode

References impeller::AtlasGeometry::CreateBlendVertexBuffer(), impeller::AtlasGeometry::CreateSimpleVertexBuffer(), impeller::RenderPass::Draw(), impeller::AtlasGeometry::GetAtlas(), impeller::AtlasGeometry::GetBlendMode(), impeller::ContentContext::GetContext(), impeller::ContentContext::GetDeviceCapabilities(), impeller::ContentContext::GetDrawVerticesUberShader(), impeller::ContentContext::GetPorterDuffPipeline(), impeller::AtlasGeometry::GetSamplerDescriptor(), impeller::Entity::GetShaderTransform(), impeller::ContentContext::GetTexturePipeline(), impeller::ContentContext::GetTransientsBuffer(), impeller::InvertPorterDuffBlend(), impeller::kDecal, impeller::Entity::kDecal, impeller::kModulate, impeller::kSource, impeller::kTriangle, impeller::OptionsFromPass(), impeller::OptionsFromPassAndEntity(), impeller::RenderPass::SetCommandLabel(), impeller::RenderPass::SetPipeline(), impeller::RenderPass::SetVertexBuffer(), impeller::AtlasGeometry::ShouldSkip(), impeller::AtlasGeometry::ShouldUseBlend(), impeller::Capabilities::SupportsDecalSamplerAddressMode(), and impeller::SamplerDescriptor::width_address_mode.

◆ SetAlpha()

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

Definition at line 34 of file atlas_contents.cc.

34  {
35  alpha_ = alpha;
36 }

◆ SetGeometry()

void impeller::AtlasContents::SetGeometry ( AtlasGeometry geometry)

Definition at line 30 of file atlas_contents.cc.

30  {
31  geometry_ = geometry;
32 }

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