Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
impeller::TiledTextureContents Class Referencefinal

#include <tiled_texture_contents.h>

Inheritance diagram for impeller::TiledTextureContents:
impeller::ColorSourceContents impeller::Contents

Public Types

using ColorFilterProc = std::function< std::shared_ptr< ColorFilterContents >(FilterInput::Ref)>
 
- 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

 TiledTextureContents (const Geometry *geometry)
 
 ~TiledTextureContents () override
 
const GeometryGetGeometry () const override
 Get the geometry that this contents will use to render.
 
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.
 
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 (const SamplerDescriptor &desc)
 
void SetColorFilter (ColorFilterProc color_filter)
 Set a color filter to apply directly to this tiled texture.
 
std::optional< SnapshotRenderToSnapshot (const ContentContext &renderer, const Entity &entity, const SnapshotOptions &options) 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).
 
- Public Member Functions inherited from impeller::ColorSourceContents
 ColorSourceContents ()
 
 ~ColorSourceContents () override
 
void SetEffectTransform (Matrix matrix)
 Set the effect transform for this color source.
 
const MatrixGetInverseEffectTransform () const
 Set the inverted effect transform for this color source.
 
void SetOpacityFactor (Scalar opacity)
 Set the opacity factor for this color source.
 
Scalar GetOpacityFactor () const
 Get the opacity factor for this color source.
 
virtual bool IsSolidColor () const
 
std::optional< RectGetCoverage (const Entity &entity) const override
 Get the area of the render pass that will be affected when this contents is rendered.
 
void SetInheritedOpacity (Scalar opacity) override
 Inherit the provided opacity.
 
- 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().
 
const std::optional< Rect > & GetCoverageHint () const
 
std::optional< SizeGetColorSourceSize () const
 Return the color source's intrinsic size, if available.
 
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.
 
virtual bool ApplyColorFilter (const ColorFilterProc &color_filter_proc)
 If possible, applies a color filter to this contents inputs on the CPU.
 

Additional Inherited Members

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

Definition at line 27 of file tiled_texture_contents.h.

Constructor & Destructor Documentation

◆ TiledTextureContents()

impeller::TiledTextureContents::TiledTextureContents ( const Geometry geometry)
explicit

Definition at line 37 of file tiled_texture_contents.cc.

38 : geometry_(geometry) {}

◆ ~TiledTextureContents()

impeller::TiledTextureContents::~TiledTextureContents ( )
overridedefault

Member Function Documentation

◆ GetGeometry()

const Geometry * impeller::TiledTextureContents::GetGeometry ( ) const
overridevirtual

Get the geometry that this contents will use to render.

Implements impeller::ColorSourceContents.

Definition at line 42 of file tiled_texture_contents.cc.

42 {
43 return geometry_;
44}

Referenced by Render(), and RenderToSnapshot().

◆ 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
transformThe current transform matrix of the entity that will render this contents.

Reimplemented from impeller::Contents.

Definition at line 106 of file tiled_texture_contents.cc.

106 {
107 if (GetOpacityFactor() < 1 || x_tile_mode_ == Entity::TileMode::kDecal ||
108 y_tile_mode_ == Entity::TileMode::kDecal) {
109 return false;
110 }
111 if (color_filter_) {
112 return false;
113 }
114 return texture_->IsOpaque() && !AppliesAlphaForStrokeCoverage(transform);
115}
Scalar GetOpacityFactor() const
Get the opacity factor for this color source.
bool AppliesAlphaForStrokeCoverage(const Matrix &transform) const
Whether the entity should be treated as non-opaque due to stroke geometry requiring alpha for coverag...

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 117 of file tiled_texture_contents.cc.

119 {
120 if (texture_ == nullptr) {
121 return true;
122 }
123
124 using VS = TextureUvFillVertexShader;
125 using FS = TiledTextureFillFragmentShader;
126
127 const auto texture_size = texture_->GetSize();
128 if (texture_size.IsEmpty()) {
129 return true;
130 }
131
132 VS::FrameInfo frame_info;
133 frame_info.uv_transform =
136
137#if defined(IMPELLER_ENABLE_OPENGLES) && !defined(FML_OS_EMSCRIPTEN)
138 using FSExternal = TiledTextureFillExternalFragmentShader;
139 if (texture_->GetTextureDescriptor().type ==
141 return ColorSourceContents::DrawGeometry<VS>(
142 renderer, entity, pass,
143 [&renderer](ContentContextOptions options) {
144 return renderer.GetTiledTextureUvExternalPipeline(options);
145 },
146 frame_info,
147 [this, &renderer](RenderPass& pass) {
148 auto& data_host_buffer = renderer.GetTransientsDataBuffer();
149#ifdef IMPELLER_DEBUG
150 pass.SetCommandLabel("TextureFill External");
151#endif // IMPELLER_DEBUG
152
153 FML_DCHECK(!color_filter_);
154 FSExternal::FragInfo frag_info;
155 frag_info.x_tile_mode =
156 static_cast<Scalar>(sampler_descriptor_.width_address_mode);
157 frag_info.y_tile_mode =
158 static_cast<Scalar>(sampler_descriptor_.height_address_mode);
159 frag_info.alpha = GetOpacityFactor();
160 FSExternal::BindFragInfo(pass,
161 data_host_buffer.EmplaceUniform(frag_info));
162
163 SamplerDescriptor sampler_desc;
164 // OES_EGL_image_external states that only CLAMP_TO_EDGE is valid,
165 // so we emulate all other tile modes here by remapping the texture
166 // coordinates.
167 sampler_desc.width_address_mode = SamplerAddressMode::kClampToEdge;
168 sampler_desc.height_address_mode = SamplerAddressMode::kClampToEdge;
169 sampler_desc.min_filter = sampler_descriptor_.min_filter;
170 sampler_desc.mag_filter = sampler_descriptor_.mag_filter;
171 sampler_desc.mip_filter = MipFilter::kBase;
172
173 FSExternal::BindSAMPLEREXTERNALOESTextureSampler(
174 pass, texture_,
175 renderer.GetContext()->GetSamplerLibrary()->GetSampler(
176 sampler_desc));
177 return true;
178 });
179 }
180#endif // IMPELLER_ENABLE_OPENGLES
181
182 PipelineBuilderCallback pipeline_callback =
183 [&renderer](ContentContextOptions options) {
184 return renderer.GetTiledTexturePipeline(options);
185 };
186 return ColorSourceContents::DrawGeometry<VS>(
187 renderer, entity, pass, pipeline_callback, frame_info,
188 [this, &renderer, &entity](RenderPass& pass) {
189 auto& data_host_buffer = renderer.GetTransientsDataBuffer();
190#ifdef IMPELLER_DEBUG
191 pass.SetCommandLabel("TextureFill");
192#endif // IMPELLER_DEBUG
193
194 FS::FragInfo frag_info;
195 frag_info.x_tile_mode = static_cast<Scalar>(x_tile_mode_);
196 frag_info.y_tile_mode = static_cast<Scalar>(y_tile_mode_);
197 frag_info.alpha =
199 GetGeometry()->ComputeAlphaCoverage(entity.GetTransform());
200 FS::BindFragInfo(pass, data_host_buffer.EmplaceUniform(frag_info));
201
202 if (color_filter_) {
203 auto filtered_texture = CreateFilterTexture(renderer);
204 if (!filtered_texture) {
205 return false;
206 }
207 FS::BindTextureSampler(
208 pass, filtered_texture,
209 renderer.GetContext()->GetSamplerLibrary()->GetSampler(
210 CreateSamplerDescriptor(renderer.GetDeviceCapabilities())));
211 } else {
212 FS::BindTextureSampler(
213 pass, texture_,
214 renderer.GetContext()->GetSamplerLibrary()->GetSampler(
215 CreateSamplerDescriptor(renderer.GetDeviceCapabilities())));
216 }
217
218 return true;
219 });
220}
const Matrix & GetInverseEffectTransform() const
Set the inverted effect transform for this color source.
std::function< PipelineRef(ContentContextOptions)> PipelineBuilderCallback
virtual Scalar ComputeAlphaCoverage(const Matrix &transform) const
Definition geometry.h:135
const Geometry * GetGeometry() const override
Get the geometry that this contents will use to render.
#define FML_DCHECK(condition)
Definition logging.h:122
float Scalar
Definition scalar.h:19
LinePipeline::FragmentShader FS
@ kBase
The texture is sampled as if it only had a single mipmap level.
LinePipeline::VertexShader VS
SamplerAddressMode width_address_mode
SamplerAddressMode height_address_mode
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:525
static constexpr TRect MakeSize(const TSize< U > &size)
Definition rect.h:150

References impeller::Geometry::ComputeAlphaCoverage(), FML_DCHECK, impeller::ContentContext::GetContext(), impeller::ContentContext::GetDeviceCapabilities(), GetGeometry(), impeller::ColorSourceContents::GetInverseEffectTransform(), impeller::TRect< T >::GetNormalizingTransform(), impeller::ColorSourceContents::GetOpacityFactor(), impeller::ContentContext::GetTiledTexturePipeline(), impeller::Entity::GetTransform(), impeller::ContentContext::GetTransientsDataBuffer(), impeller::SamplerDescriptor::height_address_mode, impeller::kBase, impeller::kClampToEdge, impeller::kTextureExternalOES, impeller::SamplerDescriptor::mag_filter, impeller::TRect< Scalar >::MakeSize(), impeller::SamplerDescriptor::min_filter, impeller::SamplerDescriptor::mip_filter, impeller::RenderPass::SetCommandLabel(), and impeller::SamplerDescriptor::width_address_mode.

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

◆ RenderToSnapshot()

std::optional< Snapshot > impeller::TiledTextureContents::RenderToSnapshot ( const ContentContext renderer,
const Entity entity,
const SnapshotOptions options 
) 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 222 of file tiled_texture_contents.cc.

225 {
226 std::optional<Rect> geometry_coverage = GetGeometry()->GetCoverage({});
227 if (GetInverseEffectTransform().IsIdentity() &&
228 GetGeometry()->IsAxisAlignedRect() &&
229 (!geometry_coverage.has_value() ||
230 Rect::MakeSize(texture_->GetSize())
231 .Contains(geometry_coverage.value()))) {
232 auto coverage = GetCoverage(entity);
233 if (!coverage.has_value()) {
234 return std::nullopt;
235 }
236 auto scale = Vector2(coverage->GetSize() / Size(texture_->GetSize()));
237
238 return Snapshot{
239 .texture = texture_,
240 .transform = Matrix::MakeTranslation(coverage->GetOrigin()) *
241 Matrix::MakeScale(scale),
242 .sampler_descriptor =
243 options.sampler_descriptor.value_or(sampler_descriptor_),
244 .opacity = GetOpacityFactor(),
245 };
246 }
247
249 renderer, entity,
250 {.coverage_limit = std::nullopt,
251 .sampler_descriptor =
252 options.sampler_descriptor.value_or(sampler_descriptor_),
253 .msaa_enabled = true,
254 .mip_count = 1,
255 .label = options.label});
256}
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.
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,...
Definition contents.cc:56
virtual std::optional< Rect > GetCoverage(const Matrix &transform) const =0
The coverage rectangle of this geometry, transformed by the transform argument.
Point Vector2
Definition point.h:430
TSize< Scalar > Size
Definition size.h:159
static constexpr Matrix MakeTranslation(const Vector3 &t)
Definition matrix.h:95
static constexpr Matrix MakeScale(const Vector3 &s)
Definition matrix.h:104
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:255

References impeller::TRect< T >::Contains(), impeller::ColorSourceContents::GetCoverage(), impeller::Geometry::GetCoverage(), GetGeometry(), impeller::ColorSourceContents::GetInverseEffectTransform(), impeller::ColorSourceContents::GetOpacityFactor(), impeller::Contents::SnapshotOptions::label, impeller::Matrix::MakeScale(), impeller::TRect< Scalar >::MakeSize(), impeller::Matrix::MakeTranslation(), impeller::Contents::RenderToSnapshot(), impeller::Contents::SnapshotOptions::sampler_descriptor, 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 60 of file tiled_texture_contents.cc.

60 {
61 color_filter_ = std::move(color_filter);
62}

◆ SetSamplerDescriptor()

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

Definition at line 56 of file tiled_texture_contents.cc.

56 {
57 sampler_descriptor_ = desc;
58}

◆ SetTexture()

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

Definition at line 46 of file tiled_texture_contents.cc.

46 {
47 texture_ = std::move(texture);
48}
FlTexture * texture

References texture.

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

◆ SetTileModes()

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

Definition at line 50 of file tiled_texture_contents.cc.

51 {
52 x_tile_mode_ = x_tile_mode;
53 y_tile_mode_ = y_tile_mode;
54}

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