9#include "impeller/entity/tiled_texture_fill.frag.h"
10#include "impeller/entity/tiled_texture_fill_external.frag.h"
46 x_tile_mode_ = x_tile_mode;
47 y_tile_mode_ = y_tile_mode;
51 sampler_descriptor_ = std::move(
desc);
58std::shared_ptr<Texture> TiledTextureContents::CreateFilterTexture(
64 auto snapshot = color_filter_contents->RenderToSnapshot(
71 "TiledTextureContents Snapshot");
72 if (snapshot.has_value()) {
73 return snapshot.value().texture;
78SamplerDescriptor TiledTextureContents::CreateSamplerDescriptor(
79 const Capabilities& capabilities)
const {
80 SamplerDescriptor descriptor = sampler_descriptor_;
83 if (width_mode.has_value()) {
84 descriptor.width_address_mode = width_mode.value();
86 if (height_mode.has_value()) {
87 descriptor.height_address_mode = height_mode.value();
92bool TiledTextureContents::UsesEmulatedTileMode(
93 const Capabilities& capabilities)
const {
107 return texture_->IsOpaque();
113 if (texture_ ==
nullptr) {
117 using VS = TextureUvFillVertexShader;
118 using FS = TiledTextureFillFragmentShader;
119 using FSExternal = TiledTextureFillExternalFragmentShader;
121 const auto texture_size = texture_->GetSize();
122 if (texture_size.IsEmpty()) {
126 bool is_external_texture =
129 VS::FrameInfo frame_info;
130 frame_info.texture_sampler_y_coord_scale = texture_->GetYCoordScale();
131 frame_info.uv_transform =
137#ifdef IMPELLER_ENABLE_OPENGLES
138 if (is_external_texture) {
139 pipeline_method = &ContentContext::GetTiledTextureExternalPipeline;
151 return ColorSourceContents::DrawGeometry<VS>(
152 renderer, entity, pass, pipeline_callback, frame_info,
154 auto& host_buffer =
renderer.GetTransientsBuffer();
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_);
164 FSExternal::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info));
166 FS::FragInfo frag_info;
167 frag_info.x_tile_mode =
static_cast<Scalar>(x_tile_mode_);
168 frag_info.y_tile_mode =
static_cast<Scalar>(y_tile_mode_);
171 FS::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info));
174 if (is_external_texture) {
184 FML_DCHECK(!color_filter_) <<
"Color filters are not currently "
185 "supported for external textures.";
187 FSExternal::BindSAMPLEREXTERNALOESTextureSampler(
189 renderer.GetContext()->GetSamplerLibrary()->GetSampler(
193 auto filtered_texture = CreateFilterTexture(
renderer);
194 if (!filtered_texture) {
197 FS::BindTextureSampler(
198 pass, filtered_texture,
199 renderer.GetContext()->GetSamplerLibrary()->GetSampler(
200 CreateSamplerDescriptor(
renderer.GetDeviceCapabilities())));
202 FS::BindTextureSampler(
204 renderer.GetContext()->GetSamplerLibrary()->GetSampler(
205 CreateSamplerDescriptor(
renderer.GetDeviceCapabilities())));
216 std::optional<Rect> coverage_limit,
217 const std::optional<SamplerDescriptor>& sampler_descriptor,
220 const std::string& label)
const {
221 std::optional<Rect> geometry_coverage =
GetGeometry()->GetCoverage({});
224 (!geometry_coverage.has_value() ||
226 .
Contains(geometry_coverage.value()))) {
237 .sampler_descriptor = sampler_descriptor.value_or(sampler_descriptor_),
246 sampler_descriptor.value_or(sampler_descriptor_),
static sk_sp< SkImage > color_filter(const SkImage *image, SkColorFilter *colorFilter)
virtual bool SupportsDecalSamplerAddressMode() const =0
Whether the context backend supports SamplerAddressMode::Decal.
Scalar GetOpacityFactor() const
Get the opacity factor for this color source.
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.
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.
const std::shared_ptr< Geometry > & GetGeometry() const
Get the geometry that this contents will use to render.
std::shared_ptr< Pipeline< PipelineDescriptor > > GetTiledTexturePipeline(ContentContextOptions opts) const
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,...
std::function< Color(Color)> ColorFilterProc
Render passes encode render commands directed as one specific render target into an underlying comman...
virtual void SetCommandLabel(std::string_view label)
The debugging label to use for the command.
void SetSamplerDescriptor(SamplerDescriptor desc)
~TiledTextureContents() override
bool IsOpaque() const override
Whether this Contents only emits opaque source colors from the fragment stage. This value does not ac...
bool Render(const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
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,...
void SetColorFilter(ColorFilterProc color_filter)
Set a color filter to apply directly to this tiled texture.
void SetTileModes(Entity::TileMode x_tile_mode, Entity::TileMode y_tile_mode)
void SetTexture(std::shared_ptr< Texture > texture)
#define FML_DCHECK(condition)
@ kDecal
decal sampling mode is only supported on devices that pass the Capabilities.SupportsDecalSamplerAddre...
static std::optional< SamplerAddressMode > TileModeToAddressMode(Entity::TileMode tile_mode, const Capabilities &capabilities)
static constexpr Matrix MakeTranslation(const Vector3 &t)
static constexpr Matrix MakeScale(const Vector3 &s)
SamplerAddressMode width_address_mode
SamplerAddressMode height_address_mode
Represents a texture and its intended draw transform/sampler configuration.
std::shared_ptr< Texture > texture
constexpr bool Contains(const TPoint< Type > &p) const
Returns true iff the provided point |p| is inside the half-open interior of this rectangle.
constexpr Matrix GetNormalizingTransform() const
Constructs a Matrix that will map all points in the coordinate space of the rectangle into a new norm...
static constexpr TRect MakeSize(const TSize< U > &size)