 |
Flutter Impeller
|
|
Go to the documentation of this file.
7 #include "fml/logging.h"
9 #include "impeller/entity/tiled_texture_fill.frag.h"
10 #include "impeller/entity/tiled_texture_fill_external.frag.h"
41 texture_ = std::move(texture);
46 x_tile_mode_ = x_tile_mode;
47 y_tile_mode_ = y_tile_mode;
51 sampler_descriptor_ = std::move(desc);
55 color_filter_ = std::move(color_filter);
58 std::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;
78 SamplerDescriptor 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();
92 bool TiledTextureContents::UsesEmulatedTileMode(
93 const Capabilities& capabilities)
const {
113 if (texture_ ==
nullptr) {
117 using VS = TextureUvFillVertexShader;
118 using FS = TiledTextureFillFragmentShader;
120 const auto texture_size = texture_->GetSize();
121 if (texture_size.IsEmpty()) {
125 VS::FrameInfo frame_info;
126 frame_info.texture_sampler_y_coord_scale = texture_->GetYCoordScale();
127 frame_info.uv_transform =
135 return ColorSourceContents::DrawGeometry<VS>(
136 renderer, entity, pass, pipeline_callback, frame_info,
137 [
this, &renderer, &entity](
RenderPass& pass) {
139 #ifdef IMPELLER_DEBUG
141 #endif // IMPELLER_DEBUG
143 FS::FragInfo frag_info;
144 frag_info.x_tile_mode =
static_cast<Scalar>(x_tile_mode_);
145 frag_info.y_tile_mode =
static_cast<Scalar>(y_tile_mode_);
149 FS::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info));
152 auto filtered_texture = CreateFilterTexture(renderer);
153 if (!filtered_texture) {
156 FS::BindTextureSampler(
157 pass, filtered_texture,
158 renderer.
GetContext()->GetSamplerLibrary()->GetSampler(
161 FS::BindTextureSampler(
163 renderer.
GetContext()->GetSamplerLibrary()->GetSampler(
174 std::optional<Rect> coverage_limit,
175 const std::optional<SamplerDescriptor>& sampler_descriptor,
178 const std::string& label)
const {
182 (!geometry_coverage.has_value() ||
184 .
Contains(geometry_coverage.value()))) {
186 if (!coverage.has_value()) {
195 .sampler_descriptor = sampler_descriptor.value_or(sampler_descriptor_),
204 sampler_descriptor.value_or(sampler_descriptor_),
std::function< std::shared_ptr< Pipeline< PipelineDescriptor > >(ContentContextOptions)> PipelineBuilderCallback
Scalar GetOpacityFactor() const
Get the opacity factor for this color source.
virtual Scalar ComputeAlphaCoverage(const Matrix &transform) const
const Matrix & GetTransform() const
Get the global transform matrix for this Entity.
virtual std::optional< Rect > GetCoverage(const Matrix &transform) const =0
bool IsOpaque(const Matrix &transform) const override
Whether this Contents only emits opaque source colors from the fragment stage. This value does not ac...
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,...
constexpr Matrix GetNormalizingTransform() const
Constructs a Matrix that will map all points in the coordinate space of the rectangle into a new norm...
void SetSamplerDescriptor(SamplerDescriptor desc)
std::shared_ptr< Pipeline< PipelineDescriptor > > GetTiledTexturePipeline(ContentContextOptions opts) const
static constexpr Matrix MakeTranslation(const Vector3 &t)
virtual void SetCommandLabel(std::string_view label)
The debugging label to use for the command.
std::shared_ptr< Context > GetContext() const
std::function< Color(Color)> ColorFilterProc
Represents a texture and its intended draw transform/sampler configuration.
void SetColorFilter(ColorFilterProc color_filter)
Set a color filter to apply directly to this tiled 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.
const Geometry * GetGeometry() const
Get the geometry that this contents will use to render.
Render passes encode render commands directed as one specific render target into an underlying comman...
const Capabilities & GetDeviceCapabilities() const
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.
constexpr static TRect MakeSize(const TSize< U > &size)
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,...
bool Render(const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
void SetTileModes(Entity::TileMode x_tile_mode, Entity::TileMode y_tile_mode)
~TiledTextureContents() override
static std::optional< SamplerAddressMode > TileModeToAddressMode(Entity::TileMode tile_mode, const Capabilities &capabilities)
std::shared_ptr< Texture > texture
bool AppliesAlphaForStrokeCoverage(const Matrix &transform) const
Whether the entity should be treated as non-opaque due to stroke geometry requiring alpha for coverag...
virtual bool SupportsDecalSamplerAddressMode() const =0
Whether the context backend supports SamplerAddressMode::Decal.
static constexpr Matrix MakeScale(const Vector3 &s)
A 4x4 matrix using column-major storage.
const Matrix & GetInverseEffectTransform() const
Set the inverted effect transform for this color source.
HostBuffer & GetTransientsBuffer() const
Retrieve the currnent host buffer for transient storage.
void SetTexture(std::shared_ptr< Texture > texture)
@ kDecal
decal sampling mode is only supported on devices that pass the Capabilities.SupportsDecalSamplerAddre...