 |
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_external.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_),
114 using VS = TextureFillVertexShader;
115 using FS = TextureFillFragmentShader;
116 using FSStrictSrc = TextureFillStrictSrcFragmentShader;
117 using FSExternal = TextureFillExternalFragmentShader;
120 texture_ ==
nullptr || texture_->GetSize().IsEmpty()) {
124 bool is_external_texture =
127 auto source_rect = capture.AddRect(
"Source rect", source_rect_);
128 auto texture_coords =
133 auto destination_rect =
134 capture.AddRect(
"Destination rect", destination_rect_);
136 {destination_rect.GetLeftTop(), texture_coords.GetLeftTop()},
137 {destination_rect.GetRightTop(), texture_coords.GetRightTop()},
138 {destination_rect.GetLeftBottom(), texture_coords.GetLeftBottom()},
139 {destination_rect.GetRightBottom(), texture_coords.GetRightBottom()},
144 VS::FrameInfo frame_info;
146 frame_info.texture_sampler_y_coord_scale = texture_->GetYCoordScale();
147 frame_info.alpha = capture.AddScalar(
"Alpha",
GetOpacity());
149 #ifdef IMPELLER_DEBUG
150 if (label_.empty()) {
155 #endif // IMPELLER_DEBUG
158 if (!stencil_enabled_) {
163 std::shared_ptr<Pipeline<PipelineDescriptor>> pipeline;
164 #ifdef IMPELLER_ENABLE_OPENGLES
165 if (is_external_texture) {
166 pipeline = renderer.GetTextureExternalPipeline(pipeline_options);
168 #endif // IMPELLER_ENABLE_OPENGLES
171 if (strict_source_rect_enabled_) {
181 VS::BindFrameInfo(pass, host_buffer.EmplaceUniform(frame_info));
182 if (is_external_texture) {
183 FSExternal::BindSAMPLEREXTERNALOESTextureSampler(
185 renderer.
GetContext()->GetSamplerLibrary()->GetSampler(
186 sampler_descriptor_));
187 }
else if (strict_source_rect_enabled_) {
191 auto strict_texture_coords =
194 FSStrictSrc::FragInfo frag_info;
195 frag_info.source_rect =
Vector4(strict_texture_coords.GetLTRB());
196 FSStrictSrc::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info));
197 FSStrictSrc::BindTextureSampler(
199 renderer.
GetContext()->GetSamplerLibrary()->GetSampler(
200 sampler_descriptor_));
202 FS::BindTextureSampler(
204 renderer.
GetContext()->GetSamplerLibrary()->GetSampler(
205 sampler_descriptor_));
207 return pass.
Draw().ok();
211 source_rect_ = source_rect;
219 strict_source_rect_enabled_ = strict;
223 return strict_source_rect_enabled_;
227 sampler_descriptor_ = std::move(desc);
231 return sampler_descriptor_;
235 defer_applying_opacity_ = defer_applying_opacity;
std::shared_ptr< Pipeline< PipelineDescriptor > > GetTexturePipeline(ContentContextOptions opts) const
@ kIgnore
Turn the stencil test off. Used when drawing without stencil-then-cover.
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)
Capture & GetCapture() const
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.
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.
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)
Represents a texture and its intended draw transform/sampler configuration.
std::shared_ptr< Texture > GetTexture() const
virtual void SetStencilReference(uint32_t value)
VertexBuffer CreateVertexBuffer(HostBuffer &host_buffer) const
Render passes encode render commands directed as one specific render target into an underlying comman...
uint32_t GetClipDepth() const
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
Capture CreateChild(std::string_view label)
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.