 |
Flutter Impeller
|
|
Go to the documentation of this file.
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;
42 texture_ = std::move(texture);
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 =
123 FML_DCHECK(!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()},
138 VS::FrameInfo frame_info;
140 frame_info.texture_sampler_y_coord_scale = texture_->GetYCoordScale();
142 #ifdef IMPELLER_DEBUG
143 if (label_.empty()) {
148 #endif // IMPELLER_DEBUG
151 if (!stencil_enabled_) {
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_));
187 return pass.
Draw().ok();
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;
std::shared_ptr< Pipeline< PipelineDescriptor > > GetTexturePipeline(ContentContextOptions opts) const
std::shared_ptr< Pipeline< PipelineDescriptor > > GetTextureStrictSrcPipeline(ContentContextOptions opts) const
Matrix GetShaderTransform(const RenderPass &pass) const
Get the vertex shader transform used for drawing this Entity.
void SetSamplerDescriptor(SamplerDescriptor desc)
void SetStrictSourceRect(bool strict)
void SetOpacity(Scalar opacity)
const Matrix & GetTransform() const
Get the global transform matrix for this Entity.
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,...
constexpr float kEhCloseEnough
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 TRect TransformBounds(const Matrix &transform) const
Creates a new bounding box that contains this transformed rectangle.
constexpr TPoint< T > GetLeftTop() const
bool GetStrictSourceRect() 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.
virtual bool SetVertexBuffer(VertexBuffer buffer)
Specify the vertex and index buffer to use for this command.
void SetSourceRect(const Rect &source_rect)
void SetStencilEnabled(bool enabled)
VertexBufferBuilder & AddVertices(std::initializer_list< VertexType_ > vertices)
static constexpr Matrix MakeTranslation(const Vector3 &t)
virtual void SetCommandLabel(std::string_view label)
The debugging label to use for the command.
constexpr TPoint< T > GetRightTop() const
Scalar GetOpacity() const
virtual fml::Status Draw()
Record the currently pending command.
constexpr bool IsEmpty() const
Returns true if either of the width or height are 0, negative, or NaN.
ContentContextOptions OptionsFromPassAndEntity(const RenderPass &pass, const Entity &entity)
~TextureContents() override
const Rect & GetSourceRect() const
bool CanInheritOpacity(const Entity &entity) const override
Whether or not this contents can accept the opacity peephole optimization.
std::shared_ptr< Context > GetContext() const
void SetLabel(std::string label)
constexpr TPoint< T > GetLeftBottom() const
Represents a texture and its intended draw transform/sampler configuration.
std::shared_ptr< Texture > GetTexture() const
VertexBuffer CreateVertexBuffer(HostBuffer &host_buffer) const
Render passes encode render commands directed as one specific render target into an underlying comman...
void SetDeferApplyingOpacity(bool defer_applying_opacity)
bool Render(const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
constexpr static TRect MakeSize(const TSize< U > &size)
constexpr TRect< T > Project(TRect< T > source) const
Returns a new rectangle that represents the projection of the source rectangle onto this rectangle....
void SetTexture(std::shared_ptr< Texture > texture)
virtual void SetPipeline(const std::shared_ptr< Pipeline< PipelineDescriptor >> &pipeline)
The pipeline to use for this command.
std::shared_ptr< Texture > texture
constexpr TPoint< T > GetRightBottom() const
void SetDestinationRect(Rect rect)
static std::shared_ptr< TextureContents > MakeRect(Rect destination)
A common case factory that marks the texture contents as having a destination rectangle....
const SamplerDescriptor & GetSamplerDescriptor() const
static constexpr Matrix MakeScale(const Vector3 &s)
HostBuffer & GetTransientsBuffer() const
Retrieve the currnent host buffer for transient storage.
constexpr TRect< T > Expand(T left, T top, T right, T bottom) const
Returns a rectangle with expanded edges. Negative expansion results in shrinking.