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_),
112 using VS = TextureFillVertexShader;
113 using FS = TextureFillFragmentShader;
114 using FSStrict = TextureFillStrictSrcFragmentShader;
117 texture_ ==
nullptr || texture_->GetSize().IsEmpty()) {
121 [[maybe_unused]]
bool is_external_texture =
125 auto texture_coords =
130 {destination_rect_.
GetLeftTop(), texture_coords.GetLeftTop()},
131 {destination_rect_.
GetRightTop(), texture_coords.GetRightTop()},
132 {destination_rect_.
GetLeftBottom(), texture_coords.GetLeftBottom()},
133 {destination_rect_.
GetRightBottom(), texture_coords.GetRightBottom()},
136 auto& host_buffer =
renderer.GetTransientsBuffer();
138 VS::FrameInfo frame_info;
140 frame_info.texture_sampler_y_coord_scale = texture_->GetYCoordScale();
143 if (label_.empty()) {
151 if (!stencil_enabled_) {
157 ?
renderer.GetTextureStrictSrcPipeline(pipeline_options)
158 :
renderer.GetTexturePipeline(pipeline_options));
161 VS::BindFrameInfo(pass, host_buffer.EmplaceUniform(frame_info));
163 if (strict_source_rect_enabled_) {
167 auto strict_texture_coords =
170 FSStrict::FragInfo frag_info;
171 frag_info.source_rect =
Vector4(strict_texture_coords.GetLTRB());
173 FSStrict::BindFragInfo(pass, host_buffer.EmplaceUniform((frag_info)));
174 FSStrict::BindTextureSampler(
176 renderer.GetContext()->GetSamplerLibrary()->GetSampler(
177 sampler_descriptor_));
179 FS::FragInfo frag_info;
181 FS::BindFragInfo(pass, host_buffer.EmplaceUniform((frag_info)));
182 FS::BindTextureSampler(
184 renderer.GetContext()->GetSamplerLibrary()->GetSampler(
185 sampler_descriptor_));
191 source_rect_ = source_rect;
199 strict_source_rect_enabled_ = strict;
203 return strict_source_rect_enabled_;
207 sampler_descriptor_ = std::move(
desc);
211 return sampler_descriptor_;
215 defer_applying_opacity_ = defer_applying_opacity;
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.
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)
Optional< SkRect > bounds
sk_sp< SkBlender > blender SkRect rect
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.
constexpr TPoint< T > GetLeftTop() const
constexpr TPoint< T > GetRightBottom() const
constexpr TPoint< T > GetLeftBottom() const
static constexpr TRect MakeSize(const TSize< U > &size)
constexpr TPoint< T > GetRightTop() const
constexpr TRect< T > Expand(T left, T top, T right, T bottom) const
Returns a rectangle with expanded edges. Negative expansion results in shrinking.