Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
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::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 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 (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, 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).
 
- Public Member Functions inherited from impeller::ColorSourceContents
 ColorSourceContents ()
 
 ~ColorSourceContents () override
 
void SetGeometry (std::shared_ptr< Geometry > geometry)
 Set the geometry that this contents will use to render.
 
const std::shared_ptr< Geometry > & GetGeometry () const
 Get the geometry that this contents will use to render.
 
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.
 
bool CanInheritOpacity (const Entity &entity) const override
 Whether or not this contents can accept the opacity peephole optimization.
 
void SetInheritedOpacity (Scalar opacity) override
 Inherit the provided opacity.
 
- Public Member Functions inherited from impeller::Contents
 Contents ()
 
virtual ~Contents ()
 
virtual void PopulateGlyphAtlas (const std::shared_ptr< LazyGlyphAtlas > &lazy_glyph_atlas, Scalar scale)
 Add any text data to the specified lazy atlas. The scale parameter must be used again later when drawing the text.
 
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
 
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.
 
virtual bool ShouldRender (const Entity &entity, const std::optional< Rect > clip_coverage) 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 const FilterContentsAsFilter () const
 Cast to a filter. Returns nullptr if this Contents is not a filter.
 
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::Contents
static std::shared_ptr< ContentsMakeAnonymous (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)>
 
- Protected Member Functions inherited from impeller::ColorSourceContents
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) const
 

Detailed Description

Definition at line 21 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 ( )
default

◆ ~TiledTextureContents()

impeller::TiledTextureContents::~TiledTextureContents ( )
overridedefault

Member Function Documentation

◆ IsOpaque()

bool impeller::TiledTextureContents::IsOpaque ( ) 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.

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();
108}
Scalar GetOpacityFactor() const
Get the opacity factor for this color source.

◆ 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 using FSExternal = TiledTextureFillExternalFragmentShader;
120
121 const auto texture_size = texture_->GetSize();
122 if (texture_size.IsEmpty()) {
123 return true;
124 }
125
126 bool is_external_texture =
127 texture_->GetTextureDescriptor().type == TextureType::kTextureExternalOES;
128
129 VS::FrameInfo frame_info;
130 frame_info.texture_sampler_y_coord_scale = texture_->GetYCoordScale();
131 frame_info.uv_transform =
134
135 PipelineBuilderMethod pipeline_method;
136
137#ifdef IMPELLER_ENABLE_OPENGLES
138 if (is_external_texture) {
139 pipeline_method = &ContentContext::GetTiledTextureExternalPipeline;
140 } else {
142 }
143#else
145#endif // IMPELLER_ENABLE_OPENGLES
146
147 PipelineBuilderCallback pipeline_callback =
148 [&renderer, &pipeline_method](ContentContextOptions options) {
149 return (renderer.*pipeline_method)(options);
150 };
151 return ColorSourceContents::DrawGeometry<VS>(
152 renderer, entity, pass, pipeline_callback, frame_info,
153 [this, &renderer, &is_external_texture](RenderPass& pass) {
154 auto& host_buffer = renderer.GetTransientsBuffer();
155
156 pass.SetCommandLabel("TextureFill");
157
158 if (is_external_texture) {
159 FSExternal::FragInfo frag_info;
160 frag_info.x_tile_mode = static_cast<Scalar>(x_tile_mode_);
161 frag_info.y_tile_mode = static_cast<Scalar>(y_tile_mode_);
162 frag_info.alpha = GetOpacityFactor();
163 FSExternal::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info));
164 } else {
165 FS::FragInfo frag_info;
166 frag_info.x_tile_mode = static_cast<Scalar>(x_tile_mode_);
167 frag_info.y_tile_mode = static_cast<Scalar>(y_tile_mode_);
168 frag_info.alpha = GetOpacityFactor();
169 FS::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info));
170 }
171
172 if (is_external_texture) {
173 SamplerDescriptor sampler_desc;
174 // OES_EGL_image_external states that only CLAMP_TO_EDGE is valid, so
175 // we emulate all other tile modes here by remapping the texture
176 // coordinates.
177 sampler_desc.width_address_mode = SamplerAddressMode::kClampToEdge;
178 sampler_desc.height_address_mode = SamplerAddressMode::kClampToEdge;
179
180 // Also, external textures cannot be bound to color filters, so ignore
181 // this case for now.
182 FML_DCHECK(!color_filter_) << "Color filters are not currently "
183 "supported for external textures.";
184
185 FSExternal::BindSAMPLEREXTERNALOESTextureSampler(
186 pass, texture_,
187 renderer.GetContext()->GetSamplerLibrary()->GetSampler(
188 sampler_desc));
189 } else {
190 if (color_filter_) {
191 auto filtered_texture = CreateFilterTexture(renderer);
192 if (!filtered_texture) {
193 return false;
194 }
195 FS::BindTextureSampler(
196 pass, filtered_texture,
197 renderer.GetContext()->GetSamplerLibrary()->GetSampler(
198 CreateSamplerDescriptor(renderer.GetDeviceCapabilities())));
199 } else {
200 FS::BindTextureSampler(
201 pass, texture_,
202 renderer.GetContext()->GetSamplerLibrary()->GetSampler(
203 CreateSamplerDescriptor(renderer.GetDeviceCapabilities())));
204 }
205 }
206
207 return true;
208 });
209}
const char * options
std::function< std::shared_ptr< Pipeline< PipelineDescriptor > >(ContentContextOptions)> PipelineBuilderCallback
std::shared_ptr< Pipeline< PipelineDescriptor > >(impeller::ContentContext::*)(ContentContextOptions) const PipelineBuilderMethod
const Matrix & GetInverseEffectTransform() const
Set the inverted effect transform for this color source.
std::shared_ptr< Pipeline< PipelineDescriptor > > GetTiledTexturePipeline(ContentContextOptions opts) const
#define FML_DCHECK(condition)
Definition logging.h:103
float Scalar
Definition scalar.h:18
SolidFillVertexShader VS
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:459
static constexpr TRect MakeSize(const TSize< U > &size)
Definition rect.h:146

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

218 {
219 std::optional<Rect> geometry_coverage = GetGeometry()->GetCoverage({});
220 if (GetInverseEffectTransform().IsIdentity() &&
221 GetGeometry()->IsAxisAlignedRect() &&
222 (!geometry_coverage.has_value() ||
223 Rect::MakeSize(texture_->GetSize())
224 .Contains(geometry_coverage.value()))) {
225 auto coverage = GetCoverage(entity);
226 if (!coverage.has_value()) {
227 return std::nullopt;
228 }
229 auto scale = Vector2(coverage->GetSize() / Size(texture_->GetSize()));
230
231 return Snapshot{
232 .texture = texture_,
233 .transform = Matrix::MakeTranslation(coverage->GetOrigin()) *
235 .sampler_descriptor = sampler_descriptor.value_or(sampler_descriptor_),
236 .opacity = GetOpacityFactor(),
237 };
238 }
239
241 renderer, // renderer
242 entity, // entity
243 std::nullopt, // coverage_limit
244 sampler_descriptor.value_or(sampler_descriptor_), // sampler_descriptor
245 true, // msaa_enabled
246 /*mip_count=*/1,
247 label); // label
248}
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.
const std::shared_ptr< Geometry > & GetGeometry() const
Get the geometry that this contents will use to render.
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:64
Point Vector2
Definition point.h:320
TSize< Scalar > Size
Definition size.h:137
const Scalar scale
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:217

◆ 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}
static sk_sp< SkImage > color_filter(const SkImage *image, SkColorFilter *colorFilter)

◆ 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}
FlTexture * texture

◆ 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: