10#include "impeller/entity/tiled_texture_fill.frag.h"
11#include "impeller/entity/tiled_texture_fill_external.frag.h"
47 x_tile_mode_ = x_tile_mode;
48 y_tile_mode_ = y_tile_mode;
52 sampler_descriptor_ = desc;
56 color_filter_ = std::move(color_filter);
59std::shared_ptr<Texture> TiledTextureContents::CreateFilterTexture(
65 auto snapshot = color_filter_contents->RenderToSnapshot(
69 {.coverage_limit = std::nullopt,
70 .sampler_descriptor = std::nullopt,
73 .label =
"TiledTextureContents Snapshot"});
74 if (snapshot.has_value()) {
75 return snapshot.value().texture;
80SamplerDescriptor TiledTextureContents::CreateSamplerDescriptor(
81 const Capabilities& capabilities)
const {
82 SamplerDescriptor descriptor = sampler_descriptor_;
85 if (width_mode.has_value()) {
86 descriptor.width_address_mode = width_mode.value();
88 if (height_mode.has_value()) {
89 descriptor.height_address_mode = height_mode.value();
94bool TiledTextureContents::UsesEmulatedTileMode(
95 const Capabilities& capabilities)
const {
115 if (texture_ ==
nullptr) {
119 using VS = TextureUvFillVertexShader;
120 using FS = TiledTextureFillFragmentShader;
122 const auto texture_size = texture_->GetSize();
123 if (texture_size.IsEmpty()) {
127 VS::FrameInfo frame_info;
128 frame_info.texture_sampler_y_coord_scale = texture_->GetYCoordScale();
129 frame_info.uv_transform =
133#ifdef IMPELLER_ENABLE_OPENGLES
134 using FSExternal = TiledTextureFillExternalFragmentShader;
135 if (texture_->GetTextureDescriptor().type ==
137 return ColorSourceContents::DrawGeometry<VS>(
138 renderer, entity, pass,
140 return renderer.GetTiledTextureUvExternalPipeline(options);
150 FSExternal::FragInfo frag_info;
151 frag_info.x_tile_mode =
153 frag_info.y_tile_mode =
156 FSExternal::BindFragInfo(pass,
157 data_host_buffer.EmplaceUniform(frag_info));
169 FSExternal::BindSAMPLEREXTERNALOESTextureSampler(
171 renderer.
GetContext()->GetSamplerLibrary()->GetSampler(
182 return ColorSourceContents::DrawGeometry<VS>(
183 renderer, entity, pass, pipeline_callback, frame_info,
184 [
this, &renderer, &entity](
RenderPass& pass) {
190 FS::FragInfo frag_info;
191 frag_info.x_tile_mode =
static_cast<Scalar>(x_tile_mode_);
192 frag_info.y_tile_mode =
static_cast<Scalar>(y_tile_mode_);
196 FS::BindFragInfo(pass, data_host_buffer.EmplaceUniform(frag_info));
199 auto filtered_texture = CreateFilterTexture(renderer);
200 if (!filtered_texture) {
203 FS::BindTextureSampler(
204 pass, filtered_texture,
205 renderer.
GetContext()->GetSamplerLibrary()->GetSampler(
208 FS::BindTextureSampler(
210 renderer.
GetContext()->GetSamplerLibrary()->GetSampler(
225 (!geometry_coverage.has_value() ||
227 .
Contains(geometry_coverage.value()))) {
229 if (!coverage.has_value()) {
232 auto scale =
Vector2(coverage->GetSize() /
Size(texture_->GetSize()));
238 .sampler_descriptor =
246 {.coverage_limit = std::nullopt,
247 .sampler_descriptor =
249 .msaa_enabled =
true,
251 .label = options.
label});
virtual bool SupportsDecalSamplerAddressMode() const =0
Whether the context backend supports SamplerAddressMode::Decal.
const Geometry * GetGeometry() const
Get the geometry that this contents will use to render.
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.
bool AppliesAlphaForStrokeCoverage(const Matrix &transform) const
Whether the entity should be treated as non-opaque due to stroke geometry requiring alpha for coverag...
const Matrix & GetInverseEffectTransform() const
Set the inverted effect transform for this color source.
std::function< PipelineRef(ContentContextOptions)> PipelineBuilderCallback
PipelineRef GetTiledTexturePipeline(ContentContextOptions opts) const
HostBuffer & GetTransientsDataBuffer() const
Retrieve the current host buffer for transient storage of other non-index data.
const Capabilities & GetDeviceCapabilities() const
std::shared_ptr< Context > GetContext() const
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,...
const Matrix & GetTransform() const
Get the global transform matrix for this Entity.
virtual std::optional< Rect > GetCoverage(const Matrix &transform) const =0
virtual Scalar ComputeAlphaCoverage(const Matrix &transform) const
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.
~TiledTextureContents() override
bool Render(const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
std::optional< Snapshot > RenderToSnapshot(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,...
bool IsOpaque(const Matrix &transform) const override
Whether this Contents only emits opaque source colors from the fragment stage. This value does not ac...
void SetSamplerDescriptor(const SamplerDescriptor &desc)
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)
std::function< std::shared_ptr< ColorFilterContents >(FilterInput::Ref)> ColorFilterProc
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...
LinePipeline::FragmentShader FS
@ kBase
The texture is sampled as if it only had a single mipmap level.
static std::optional< SamplerAddressMode > TileModeToAddressMode(Entity::TileMode tile_mode, const Capabilities &capabilities)
LinePipeline::VertexShader VS
const std::optional< SamplerDescriptor > & sampler_descriptor
A 4x4 matrix using column-major storage.
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)