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"
17#include "impeller/entity/tiled_texture_fill_external.frag.h"
29 auto contents = std::make_shared<TextureContents>();
30 contents->destination_rect_ = destination;
39 destination_rect_ = rect;
55 stencil_enabled_ = enabled;
59 inherited_opacity_ = opacity;
63 return opacity_ * inherited_opacity_;
79 auto bounds = destination_rect_;
83 auto scale =
Vector2(bounds.GetSize() /
Size(texture_->GetSize()));
94 {.coverage_limit = std::nullopt,
99 .label = options.
label,
106 using VS = TextureFillVertexShader;
107 using FS = TextureFillFragmentShader;
108 using FSStrict = TextureFillStrictSrcFragmentShader;
111 texture_ ==
nullptr || texture_->GetSize().IsEmpty()) {
115#ifdef IMPELLER_ENABLE_OPENGLES
116 using FSExternal = TiledTextureFillExternalFragmentShader;
117 bool is_external_texture =
121 auto texture_coords =
125 std::array<VS::PerVertexData, 4> vertices = {
126 VS::PerVertexData{destination_rect_.
GetLeftTop(),
127 texture_coords.GetLeftTop()},
129 texture_coords.GetRightTop()},
131 texture_coords.GetLeftBottom()},
133 texture_coords.GetRightBottom()},
137 VS::FrameInfo frame_info;
139 frame_info.texture_sampler_y_coord_scale = texture_->GetYCoordScale();
142 if (label_.empty()) {
150 if (!stencil_enabled_) {
155 pipeline_options.depth_write_enabled =
158#ifdef IMPELLER_ENABLE_OPENGLES
159 if (is_external_texture) {
161 renderer.GetTiledTextureExternalPipeline(pipeline_options));
164 strict_source_rect_enabled_
175 VS::BindFrameInfo(pass, data_host_buffer.EmplaceUniform(frame_info));
177 if (strict_source_rect_enabled_) {
181 auto strict_texture_coords =
184 FSStrict::FragInfo frag_info;
185 frag_info.source_rect =
Vector4(strict_texture_coords.GetLTRB());
187 FSStrict::BindFragInfo(pass, data_host_buffer.EmplaceUniform((frag_info)));
188 FSStrict::BindTextureSampler(
190 renderer.
GetContext()->GetSamplerLibrary()->GetSampler(
191 sampler_descriptor_));
192#ifdef IMPELLER_ENABLE_OPENGLES
193 }
else if (is_external_texture) {
194 FSExternal::FragInfo frag_info;
195 frag_info.x_tile_mode =
197 frag_info.y_tile_mode =
200 FSExternal::BindFragInfo(pass, data_host_buffer.EmplaceUniform(frag_info));
212 FSExternal::BindSAMPLEREXTERNALOESTextureSampler(
214 renderer.
GetContext()->GetSamplerLibrary()->GetSampler(sampler_desc));
217 FS::FragInfo frag_info;
219 FS::BindFragInfo(pass, data_host_buffer.EmplaceUniform((frag_info)));
220 FS::BindTextureSampler(
222 renderer.
GetContext()->GetSamplerLibrary()->GetSampler(
223 sampler_descriptor_));
229 source_rect_ = source_rect;
237 strict_source_rect_enabled_ = strict;
241 return strict_source_rect_enabled_;
245 sampler_descriptor_ = desc;
249 return sampler_descriptor_;
253 defer_applying_opacity_ = defer_applying_opacity;
HostBuffer & GetTransientsDataBuffer() const
Retrieve the current host buffer for transient storage of other non-index data.
PipelineRef GetTextureStrictSrcPipeline(ContentContextOptions opts) const
PipelineRef GetTexturePipeline(ContentContextOptions opts) 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,...
Matrix GetShaderTransform(const RenderPass &pass) 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(PipelineRef 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
void SetSamplerDescriptor(const SamplerDescriptor &desc)
Scalar GetOpacity() const
void SetStrictSourceRect(bool strict)
void SetDeferApplyingOpacity(bool defer_applying_opacity)
const SamplerDescriptor & GetSamplerDescriptor() const
void SetOpacity(Scalar opacity)
bool GetStrictSourceRect() const
static std::shared_ptr< TextureContents > MakeRect(Rect destination)
const Rect & GetSourceRect() const
void SetInheritedOpacity(Scalar opacity) override
Inherit the provided opacity.
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 SetLabel(std::string_view label)
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,...
void SetStencilEnabled(bool enabled)
void SetDestinationRect(Rect rect)
constexpr float kEhCloseEnough
LinePipeline::FragmentShader FS
VertexBuffer CreateVertexBuffer(std::array< VertexType, size > input, HostBuffer &data_host_buffer)
Create an index-less vertex buffer from a fixed size array.
@ kBase
The texture is sampled as if it only had a single mipmap level.
LinePipeline::VertexShader VS
ContentContextOptions OptionsFromPassAndEntity(const RenderPass &pass, const Entity &entity)
const std::optional< SamplerDescriptor > & sampler_descriptor
int32_t coverage_expansion
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 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.