14#include "impeller/entity/texture_fill.frag.h"
15#include "impeller/entity/texture_fill.vert.h"
16#include "impeller/entity/texture_fill_strict_src.frag.h"
28 auto contents = std::make_shared<TextureContents>();
29 contents->destination_rect_ = destination;
34 label_ = std::move(label);
38 destination_rect_ = rect;
54 stencil_enabled_ = enabled;
62 inherited_opacity_ = opacity;
66 return opacity_ * inherited_opacity_;
79 std::optional<Rect> coverage_limit,
80 const std::optional<SamplerDescriptor>& sampler_descriptor,
83 const std::string& label)
const {
86 auto bounds = destination_rect_;
96 .sampler_descriptor = sampler_descriptor.value_or(sampler_descriptor_),
103 sampler_descriptor.value_or(sampler_descriptor_),
114 using VS = TextureFillVertexShader;
115 using FS = TextureFillFragmentShader;
116 using FSStrict = TextureFillStrictSrcFragmentShader;
119 texture_ ==
nullptr || texture_->GetSize().IsEmpty()) {
123 [[maybe_unused]]
bool is_external_texture =
127 auto source_rect = capture.AddRect(
"Source rect", source_rect_);
128 auto texture_coords =
132 auto destination_rect =
133 capture.AddRect(
"Destination rect", destination_rect_);
135 {destination_rect.GetLeftTop(), texture_coords.GetLeftTop()},
136 {destination_rect.GetRightTop(), texture_coords.GetRightTop()},
137 {destination_rect.GetLeftBottom(), texture_coords.GetLeftBottom()},
138 {destination_rect.GetRightBottom(), texture_coords.GetRightBottom()},
141 auto& host_buffer = renderer.GetTransientsBuffer();
143 VS::FrameInfo frame_info;
145 frame_info.texture_sampler_y_coord_scale = texture_->GetYCoordScale();
148 if (label_.empty()) {
156 if (!stencil_enabled_) {
162 ? renderer.GetTextureStrictSrcPipeline(pipeline_options)
163 : renderer.GetTexturePipeline(pipeline_options));
166 VS::BindFrameInfo(pass, host_buffer.EmplaceUniform(frame_info));
168 if (strict_source_rect_enabled_) {
172 auto strict_texture_coords =
175 FSStrict::FragInfo frag_info;
176 frag_info.source_rect =
Vector4(strict_texture_coords.GetLTRB());
177 frag_info.alpha = capture.AddScalar(
"Alpha",
GetOpacity());
178 FSStrict::BindFragInfo(pass, host_buffer.EmplaceUniform((frag_info)));
179 FSStrict::BindTextureSampler(
181 renderer.GetContext()->GetSamplerLibrary()->GetSampler(
182 sampler_descriptor_));
184 FS::FragInfo frag_info;
185 frag_info.alpha = capture.AddScalar(
"Alpha",
GetOpacity());
186 FS::BindFragInfo(pass, host_buffer.EmplaceUniform((frag_info)));
187 FS::BindTextureSampler(
189 renderer.GetContext()->GetSamplerLibrary()->GetSampler(
190 sampler_descriptor_));
196 source_rect_ = source_rect;
204 strict_source_rect_enabled_ = strict;
208 return strict_source_rect_enabled_;
212 sampler_descriptor_ = std::move(desc);
216 return sampler_descriptor_;
220 defer_applying_opacity_ = defer_applying_opacity;
Capture CreateChild(std::string_view label)
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,...
Matrix GetShaderTransform(const RenderPass &pass) const
Get the vertex shader transform used for drawing this Entity.
Capture & GetCapture() const
const Matrix & GetTransform() const
Get the global transform matrix for this Entity.
Render passes encode render commands directed as one specific render target into an underlying comman...
virtual bool SetVertexBuffer(VertexBuffer buffer)
Specify the vertex and index buffer to use for this command.
virtual void SetPipeline(const std::shared_ptr< Pipeline< PipelineDescriptor > > &pipeline)
The pipeline to use for this command.
virtual fml::Status Draw()
Record the currently pending command.
virtual void SetCommandLabel(std::string_view label)
The debugging label to use for the command.
std::shared_ptr< Texture > GetTexture() const
void SetSourceRect(const Rect &source_rect)
bool Render(const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
Scalar GetOpacity() const
void SetStrictSourceRect(bool strict)
void SetLabel(std::string label)
void SetDeferApplyingOpacity(bool defer_applying_opacity)
const SamplerDescriptor & GetSamplerDescriptor() const
void SetOpacity(Scalar opacity)
void SetSamplerDescriptor(SamplerDescriptor desc)
bool GetStrictSourceRect() const
static std::shared_ptr< TextureContents > MakeRect(Rect destination)
A common case factory that marks the texture contents as having a destination rectangle....
const Rect & GetSourceRect() const
void SetInheritedOpacity(Scalar opacity) override
Inherit the provided opacity.
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="Texture Snapshot") const override
Render this contents to a snapshot, respecting the entity's transform, path, clip depth,...
bool CanInheritOpacity(const Entity &entity) const override
Whether or not this contents can accept the opacity peephole optimization.
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.
void SetTexture(std::shared_ptr< Texture > texture)
~TextureContents() override
void SetStencilEnabled(bool enabled)
void SetDestinationRect(Rect rect)
VertexBuffer CreateVertexBuffer(HostBuffer &host_buffer) const
VertexBufferBuilder & AddVertices(std::initializer_list< VertexType_ > vertices)
#define FML_DCHECK(condition)
constexpr float kEhCloseEnough
ContentContextOptions OptionsFromPassAndEntity(const RenderPass &pass, const Entity &entity)
static constexpr Matrix MakeTranslation(const Vector3 &t)
static constexpr Matrix MakeScale(const Vector3 &s)
Represents a texture and its intended draw transform/sampler configuration.
std::shared_ptr< Texture > texture
constexpr TRect TransformBounds(const Matrix &transform) const
Creates a new bounding box that contains this transformed rectangle.
constexpr TRect< T > Project(TRect< T > source) const
Returns a new rectangle that represents the projection of the source rectangle onto this rectangle....
constexpr bool IsEmpty() const
Returns true if either of the width or height are 0, negative, or NaN.
static constexpr TRect MakeSize(const TSize< U > &size)