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()));
91 .needs_rasterization_for_runtime_effects =
92 snapshots_need_rasterization_for_runtime_effects_};
96 {.coverage_limit = std::nullopt,
101 .label = options.
label,
108 using VS = TextureFillVertexShader;
109 using FS = TextureFillFragmentShader;
110 using FSStrict = TextureFillStrictSrcFragmentShader;
113 texture_ ==
nullptr || texture_->GetSize().IsEmpty()) {
117#ifdef IMPELLER_ENABLE_OPENGLES
118 using FSExternal = TiledTextureFillExternalFragmentShader;
119 bool is_external_texture =
123 auto texture_coords =
127 std::array<VS::PerVertexData, 4> vertices = {
128 VS::PerVertexData{destination_rect_.
GetLeftTop(),
129 texture_coords.GetLeftTop()},
131 texture_coords.GetRightTop()},
133 texture_coords.GetLeftBottom()},
135 texture_coords.GetRightBottom()},
139 VS::FrameInfo frame_info;
141 frame_info.texture_sampler_y_coord_scale = texture_->GetYCoordScale();
144 if (label_.empty()) {
152 if (!stencil_enabled_) {
157 pipeline_options.depth_write_enabled =
160#ifdef IMPELLER_ENABLE_OPENGLES
161 if (is_external_texture) {
163 renderer.GetTiledTextureExternalPipeline(pipeline_options));
166 strict_source_rect_enabled_
177 VS::BindFrameInfo(pass, data_host_buffer.EmplaceUniform(frame_info));
179 if (strict_source_rect_enabled_) {
183 auto strict_texture_coords =
186 FSStrict::FragInfo frag_info;
187 frag_info.source_rect =
Vector4(strict_texture_coords.GetLTRB());
189 FSStrict::BindFragInfo(pass, data_host_buffer.EmplaceUniform((frag_info)));
190 FSStrict::BindTextureSampler(
192 renderer.
GetContext()->GetSamplerLibrary()->GetSampler(
193 sampler_descriptor_));
194#ifdef IMPELLER_ENABLE_OPENGLES
195 }
else if (is_external_texture) {
196 FSExternal::FragInfo frag_info;
197 frag_info.x_tile_mode =
199 frag_info.y_tile_mode =
202 FSExternal::BindFragInfo(pass, data_host_buffer.EmplaceUniform(frag_info));
214 FSExternal::BindSAMPLEREXTERNALOESTextureSampler(
216 renderer.
GetContext()->GetSamplerLibrary()->GetSampler(sampler_desc));
219 FS::FragInfo frag_info;
221 FS::BindFragInfo(pass, data_host_buffer.EmplaceUniform((frag_info)));
222 FS::BindTextureSampler(
224 renderer.
GetContext()->GetSamplerLibrary()->GetSampler(
225 sampler_descriptor_));
231 source_rect_ = source_rect;
239 strict_source_rect_enabled_ = strict;
243 return strict_source_rect_enabled_;
247 sampler_descriptor_ = desc;
251 return sampler_descriptor_;
255 defer_applying_opacity_ = defer_applying_opacity;
259 snapshots_need_rasterization_for_runtime_effects_ =
value;
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)
void SetNeedsRasterizationForRuntimeEffects(bool value)
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.