| Flutter Impeller |

Public Types | Public Member Functions | List of all members
impeller::TiledTextureContents Class Referencefinal

`#include <tiled_texture_contents.h>`

Inheritance diagram for impeller::TiledTextureContents:

## Public Types
using | ColorFilterProc = std::function< std::shared_ptr< ColorFilterContents >(FilterInput::Ref)>
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
| TiledTextureContents ()
| ~TiledTextureContents () override
bool | IsOpaque (const Matrix &transform) const override
| 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...
bool | Render (const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
void | SetTexture (std::shared_ptr< Texture > texture)
void | SetTileModes (Entity::TileMode x_tile_mode, Entity::TileMode y_tile_mode)
void | SetSamplerDescriptor (SamplerDescriptor desc)
void | SetColorFilter (ColorFilterProc color_filter)
| Set a color filter to apply directly to this tiled texture. More...
std::optional< Snapshot > | RenderToSnapshot (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, const std::string &label="Tiled Texture Snapshot") const override
| 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...
Public Member Functions inherited from impeller::ColorSourceContents
| ColorSourceContents ()
| ~ColorSourceContents () override
void | SetGeometry (const Geometry *geometry)
| Set the geometry that this contents will use to render. More...
const Geometry * | GetGeometry () const
| Get the geometry that this contents will use to render. More...
void | SetEffectTransform (Matrix matrix)
| Set the effect transform for this color source. More...
const Matrix & | GetInverseEffectTransform () 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
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...
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 ClipCoverage | GetClipCoverage (const Entity &entity, const std::optional< Rect > &current_clip_coverage) const
| Given the current pass space bounding rectangle of the clip buffer, return the expected clip coverage after this draw call. This should only be implemented for contents that may write to the clip buffer. 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 const FilterContents * | AsFilter () const
| Cast to a filter. Returns `nullptr` if this Contents is not a filter. 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)
Protected Types inherited from impeller::ColorSourceContents
using | BindFragmentCallback = std::function< bool(RenderPass &pass)>
using | PipelineBuilderMethod = std::shared_ptr< Pipeline< PipelineDescriptor > >(impeller::ContentContext::*)(ContentContextOptions) const
using | PipelineBuilderCallback = std::function< std::shared_ptr< Pipeline< PipelineDescriptor > >(ContentContextOptions)>
using | CreateGeometryCallback = std::function< GeometryResult(const ContentContext &renderer, const Entity &entity, RenderPass &pass, const Geometry *geom)>
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 19 of file tiled_texture_contents.h.

## Member Typedef Documentation

## ◆ ColorFilterProc

using impeller::TiledTextureContents::ColorFilterProc = std::function<std::shared_ptr<ColorFilterContents>(FilterInput::Ref)>

Definition at line 26 of file tiled_texture_contents.h.

## Constructor & Destructor Documentation

## ◆ TiledTextureContents()

impeller::TiledTextureContents::TiledTextureContents | ( |  | ) |
| default

## ◆ ~TiledTextureContents()

impeller::TiledTextureContents::~TiledTextureContents | ( |  | ) |
| overridedefault

## Member Function Documentation

## ◆ IsOpaque()

bool impeller::TiledTextureContents::IsOpaque | ( | const Matrix & | transform | ) | const
| overridevirtual

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.

Parameters

  transform | The current transform matrix of the entity that will render this contents.

Reimplemented from impeller::Contents.

Definition at line 99 of file tiled_texture_contents.cc.

99 {
100 if (GetOpacityFactor() < 1 || x_tile_mode_ == Entity::TileMode::kDecal ||
101 y_tile_mode_ == Entity::TileMode::kDecal) {
102 return false;
103 }
104 if (color_filter_) {
105 return false;
106 }
107 return texture_->IsOpaque() && !AppliesAlphaForStrokeCoverage(transform);
108 }

References impeller::ColorSourceContents::AppliesAlphaForStrokeCoverage(), impeller::ColorSourceContents::GetOpacityFactor(), impeller::Entity::kDecal, and transform.

Referenced by impeller::testing::TEST_P().

## ◆ Render()

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

Implements impeller::Contents.

Definition at line 110 of file tiled_texture_contents.cc.

112 {
113 if (texture_ == nullptr) {
114 return true;
115 }
116
117 using VS = TextureUvFillVertexShader;
118 using FS = TiledTextureFillFragmentShader;
119
120 const auto texture_size = texture_->GetSize();
121 if (texture_size.IsEmpty()) {
122 return true;
123 }
124
125 VS::FrameInfo frame_info;
126 frame_info.texture_sampler_y_coord_scale = texture_->GetYCoordScale();
127 frame_info.uv_transform =
128 Rect::MakeSize(texture_size).GetNormalizingTransform() *
129 GetInverseEffectTransform();
130
131 PipelineBuilderCallback pipeline_callback =
132 [&renderer](ContentContextOptions options) {
133 return renderer.GetTiledTexturePipeline(options);
134 };
135 return ColorSourceContents::DrawGeometry<VS>(
136 renderer, entity, pass, pipeline_callback, frame_info,
137 [this, &renderer, &entity](RenderPass& pass) {
138 auto& host_buffer = renderer.GetTransientsBuffer();
139 #ifdef IMPELLER_DEBUG
140 pass.SetCommandLabel("TextureFill");
141 #endif // IMPELLER_DEBUG
142
143 FS::FragInfo frag_info;
144 frag_info.x_tile_mode = static_cast<Scalar>(x_tile_mode_);
145 frag_info.y_tile_mode = static_cast<Scalar>(y_tile_mode_);
146 frag_info.alpha =
147 GetOpacityFactor() *
148 GetGeometry()->ComputeAlphaCoverage(entity.GetTransform());
149 FS::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info));
150
151 if (color_filter_) {
152 auto filtered_texture = CreateFilterTexture(renderer);
153 if (!filtered_texture) {
154 return false;
155 }
156 FS::BindTextureSampler(
157 pass, filtered_texture,
158 renderer.GetContext()->GetSamplerLibrary()->GetSampler(
159 CreateSamplerDescriptor(renderer.GetDeviceCapabilities())));
160 } else {
161 FS::BindTextureSampler(
162 pass, texture_,
163 renderer.GetContext()->GetSamplerLibrary()->GetSampler(
164 CreateSamplerDescriptor(renderer.GetDeviceCapabilities())));
165 }
166
167 return true;
168 });
169 }

References impeller::Geometry::ComputeAlphaCoverage(), impeller::ContentContext::GetContext(), impeller::ContentContext::GetDeviceCapabilities(), impeller::ColorSourceContents::GetGeometry(), impeller::ColorSourceContents::GetInverseEffectTransform(), impeller::TRect< T >::GetNormalizingTransform(), impeller::ColorSourceContents::GetOpacityFactor(), impeller::ContentContext::GetTiledTexturePipeline(), impeller::Entity::GetTransform(), impeller::ContentContext::GetTransientsBuffer(), impeller::TRect< Scalar >::MakeSize(), and impeller::RenderPass::SetCommandLabel().

Referenced by impeller::testing::TEST_P().

## ◆ RenderToSnapshot()

std::optional< Snapshot > impeller::TiledTextureContents::RenderToSnapshot | ( | 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`,
|  | const std::string & | label = `"Tiled Texture Snapshot"`
| ) |  | const
| overridevirtual

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)`.

Reimplemented from impeller::Contents.

Definition at line 171 of file tiled_texture_contents.cc.

178 {
179 std::optional<Rect> geometry_coverage = GetGeometry()->GetCoverage({});
180 if (GetInverseEffectTransform().IsIdentity() &&
181 GetGeometry()->IsAxisAlignedRect() &&
182 (!geometry_coverage.has_value() ||
183 Rect::MakeSize(texture_->GetSize())
184 .Contains(geometry_coverage.value()))) {
185 auto coverage = GetCoverage(entity);
186 if (!coverage.has_value()) {
187 return std::nullopt;
188 }
189 auto scale = Vector2(coverage->GetSize() / Size(texture_->GetSize()));
190
191 return Snapshot{
192 .texture = texture_,
193 .transform = Matrix::MakeTranslation(coverage->GetOrigin()) *
194 Matrix::MakeScale(scale),
195 .sampler_descriptor = sampler_descriptor.value_or(sampler_descriptor_),
196 .opacity = GetOpacityFactor(),
197 };
198 }
199
200 return Contents::RenderToSnapshot(
201 renderer, // renderer
202 entity, // entity
203 std::nullopt, // coverage_limit
204 sampler_descriptor.value_or(sampler_descriptor_), // sampler_descriptor
205 true, // msaa_enabled
206 /*mip_count=*/1,
207 label); // label
208 }

References impeller::TRect< T >::Contains(), impeller::ColorSourceContents::GetCoverage(), impeller::Geometry::GetCoverage(), impeller::ColorSourceContents::GetGeometry(), impeller::ColorSourceContents::GetInverseEffectTransform(), impeller::ColorSourceContents::GetOpacityFactor(), impeller::Matrix::MakeScale(), impeller::TRect< Scalar >::MakeSize(), impeller::Matrix::MakeTranslation(), impeller::Contents::RenderToSnapshot(), scale, and impeller::Snapshot::texture.

## ◆ SetColorFilter()

void impeller::TiledTextureContents::SetColorFilter | ( | ColorFilterProc | color_filter | ) |

Set a color filter to apply directly to this tiled texture.

Parameters

  color_filter | When applying a color filter to a tiled texture, we can reduce the size and number of the subpasses required and the shader workload by applying the filter to the untiled image and absorbing the opacity before tiling it into the final location.

This may not be a performance improvement if the image is tiled into a much smaller size that its original texture size.

Definition at line 54 of file tiled_texture_contents.cc.

54 {
55 color_filter_ = std::move(color_filter);
56 }

## ◆ SetSamplerDescriptor()

void impeller::TiledTextureContents::SetSamplerDescriptor | ( | SamplerDescriptor | desc | ) |

Definition at line 50 of file tiled_texture_contents.cc.

50 {
51 sampler_descriptor_ = std::move(desc);
52 }

## ◆ SetTexture()

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

Definition at line 40 of file tiled_texture_contents.cc.

40 {
41 texture_ = std::move(texture);
42 }

Referenced by impeller::testing::TEST_P().

## ◆ SetTileModes()

void impeller::TiledTextureContents::SetTileModes | ( | Entity::TileMode | x_tile_mode,
|  | Entity::TileMode | y_tile_mode
| ) |  |

Definition at line 44 of file tiled_texture_contents.cc.

45 {
46 x_tile_mode_ = x_tile_mode;
47 y_tile_mode_ = y_tile_mode;
48 }

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

- impeller/entity/contents/tiled_texture_contents.h
- impeller/entity/contents/tiled_texture_contents.cc

impeller::ColorSourceContents::PipelineBuilderCallback
std::function< std::shared_ptr< Pipeline< PipelineDescriptor > >(ContentContextOptions)> PipelineBuilderCallback
Definition: color_source_contents.h:108
impeller::ColorSourceContents::GetOpacityFactor
Scalar GetOpacityFactor() const
Get the opacity factor for this color source.
Definition: color_source_contents.cc:28
impeller::Geometry::ComputeAlphaCoverage
virtual Scalar ComputeAlphaCoverage(const Matrix &transform) const
Definition: geometry.h:124
impeller::Scalar
float Scalar
Definition: scalar.h:18
impeller::Geometry::GetCoverage
virtual std::optional< Rect > GetCoverage(const Matrix &transform) const =0
impeller::Entity::TileMode::kDecal
@ kDecal
impeller::Contents::RenderToSnapshot
virtual std::optional< Snapshot > RenderToSnapshot(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, const std::string &label="Snapshot") const
Render this contents to a snapshot, respecting the entity's transform, path, clip depth,...
Definition: contents.cc:63
impeller::Vector2
Point Vector2
Definition: point.h:331
impeller::TRect::GetNormalizingTransform
constexpr Matrix GetNormalizingTransform() const
Constructs a Matrix that will map all points in the coordinate space of the rectangle into a new norm...
Definition: rect.h:485
impeller::Size
TSize< Scalar > Size
Definition: size.h:137
impeller::Matrix::MakeTranslation
static constexpr Matrix MakeTranslation(const Vector3 &t)
Definition: matrix.h:95
impeller::VS
SolidFillVertexShader VS
Definition: stroke_path_geometry.cc:16
transform
Matrix transform
Definition: gaussian_blur_filter_contents.cc:213
impeller::TRect::Contains
constexpr bool Contains(const TPoint< Type > &p) const
Returns true iff the provided point |p| is inside the half-open interior of this rectangle.
Definition: rect.h:225
impeller::ColorSourceContents::GetGeometry
const Geometry * GetGeometry() const
Get the geometry that this contents will use to render.
Definition: color_source_contents.cc:20
impeller::ColorSourceContents::GetCoverage
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.
Definition: color_source_contents.cc:44
impeller::TRect< Scalar >::MakeSize
constexpr static TRect MakeSize(const TSize< U > &size)
Definition: rect.h:150
scale
const Scalar scale
Definition: stroke_path_geometry.cc:301
impeller::ColorSourceContents::AppliesAlphaForStrokeCoverage
bool AppliesAlphaForStrokeCoverage(const Matrix &transform) const
Whether the entity should be treated as non-opaque due to stroke geometry requiring alpha for coverag...
Definition: color_source_contents.cc:53
impeller::Matrix::MakeScale
static constexpr Matrix MakeScale(const Vector3 &s)
Definition: matrix.h:104
impeller::ColorSourceContents::GetInverseEffectTransform
const Matrix & GetInverseEffectTransform() const
Set the inverted effect transform for this color source.
Definition: color_source_contents.cc:36