7 #include "fml/logging.h"
10 #include "impeller/entity/tiled_texture_fill.frag.h"
11 #include "impeller/entity/tiled_texture_fill_external.frag.h"
38 : geometry_(geometry) {}
47 texture_ = std::move(texture);
52 x_tile_mode_ = x_tile_mode;
53 y_tile_mode_ = y_tile_mode;
57 sampler_descriptor_ = desc;
61 color_filter_ = std::move(color_filter);
64 std::shared_ptr<Texture> TiledTextureContents::CreateFilterTexture(
70 auto snapshot = color_filter_contents->RenderToSnapshot(
74 {.coverage_limit = std::nullopt,
75 .sampler_descriptor = std::nullopt,
78 .label =
"TiledTextureContents Snapshot"});
79 if (snapshot.has_value()) {
80 return snapshot.value().texture;
85 SamplerDescriptor TiledTextureContents::CreateSamplerDescriptor(
86 const Capabilities& capabilities)
const {
87 SamplerDescriptor descriptor = sampler_descriptor_;
90 if (width_mode.has_value()) {
91 descriptor.width_address_mode = width_mode.value();
93 if (height_mode.has_value()) {
94 descriptor.height_address_mode = height_mode.value();
99 bool TiledTextureContents::UsesEmulatedTileMode(
100 const Capabilities& capabilities)
const {
120 if (texture_ ==
nullptr) {
124 using VS = TextureUvFillVertexShader;
125 using FS = TiledTextureFillFragmentShader;
127 const auto texture_size = texture_->GetSize();
128 if (texture_size.IsEmpty()) {
132 VS::FrameInfo frame_info;
133 frame_info.texture_sampler_y_coord_scale = texture_->GetYCoordScale();
134 frame_info.uv_transform =
138 #if defined(IMPELLER_ENABLE_OPENGLES) && !defined(FML_OS_EMSCRIPTEN)
139 using FSExternal = TiledTextureFillExternalFragmentShader;
140 if (texture_->GetTextureDescriptor().type ==
142 return ColorSourceContents::DrawGeometry<VS>(
143 renderer, entity, pass,
145 return renderer.GetTiledTextureUvExternalPipeline(options);
150 #ifdef IMPELLER_DEBUG
154 FML_DCHECK(!color_filter_);
155 FSExternal::FragInfo frag_info;
156 frag_info.x_tile_mode =
158 frag_info.y_tile_mode =
161 FSExternal::BindFragInfo(pass,
162 data_host_buffer.EmplaceUniform(frag_info));
174 FSExternal::BindSAMPLEREXTERNALOESTextureSampler(
176 renderer.
GetContext()->GetSamplerLibrary()->GetSampler(
187 return ColorSourceContents::DrawGeometry<VS>(
188 renderer, entity, pass, pipeline_callback, frame_info,
189 [
this, &renderer, &entity](
RenderPass& pass) {
191 #ifdef IMPELLER_DEBUG
195 FS::FragInfo frag_info;
196 frag_info.x_tile_mode =
static_cast<Scalar>(x_tile_mode_);
197 frag_info.y_tile_mode =
static_cast<Scalar>(y_tile_mode_);
201 FS::BindFragInfo(pass, data_host_buffer.EmplaceUniform(frag_info));
204 auto filtered_texture = CreateFilterTexture(renderer);
205 if (!filtered_texture) {
208 FS::BindTextureSampler(
209 pass, filtered_texture,
210 renderer.
GetContext()->GetSamplerLibrary()->GetSampler(
213 FS::BindTextureSampler(
215 renderer.
GetContext()->GetSamplerLibrary()->GetSampler(
230 (!geometry_coverage.has_value() ||
232 .
Contains(geometry_coverage.value()))) {
234 if (!coverage.has_value()) {
237 auto scale =
Vector2(coverage->GetSize() /
Size(texture_->GetSize()));
243 .sampler_descriptor =
251 {.coverage_limit = std::nullopt,
252 .sampler_descriptor =
254 .msaa_enabled =
true,
256 .label = options.
label});
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.
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
const Capabilities & GetDeviceCapabilities() const
HostBuffer & GetTransientsDataBuffer() const
Retrieve the current host buffer for transient storage of other non-index data.
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,...
std::function< Color(Color)> ColorFilterProc
const Matrix & GetTransform() const
Get the global transform matrix for this Entity.
virtual Scalar ComputeAlphaCoverage(const Matrix &transform) const
virtual std::optional< Rect > GetCoverage(const Matrix &transform) const =0
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
TiledTextureContents(const Geometry *geometry)
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)
const Geometry * GetGeometry() const override
Get the geometry that this contents will use to render.
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)
@ 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...
constexpr static TRect MakeSize(const TSize< U > &size)