 |
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,
82 const std::string& label)
const {
85 auto bounds = destination_rect_;
89 auto scale =
Vector2(bounds.GetSize() /
Size(texture_->GetSize()));
95 .sampler_descriptor = sampler_descriptor.value_or(sampler_descriptor_),
102 sampler_descriptor.value_or(sampler_descriptor_),
112 using VS = TextureFillVertexShader;
113 using FS = TextureFillFragmentShader;
114 using FSExternal = TextureFillExternalFragmentShader;
117 texture_ ==
nullptr || texture_->GetSize().IsEmpty()) {
121 bool is_external_texture =
126 auto texture_coords =
128 .
Project(capture.AddRect(
"Source rect", source_rect_).Expand(0.5));
132 auto destination_rect =
133 capture.AddRect(
"Destination rect", destination_rect_);
135 {destination_rect.GetLeftTop(), texture_coords.GetLeftTop()},
136 {destination_rect.GetRightTop(), texture_coords.GetRightTop()},
137 {destination_rect.GetLeftBottom(), texture_coords.GetLeftBottom()},
138 {destination_rect.GetRightBottom(), texture_coords.GetRightBottom()},
143 VS::FrameInfo frame_info;
146 frame_info.texture_sampler_y_coord_scale = texture_->GetYCoordScale();
147 frame_info.alpha = capture.AddScalar(
"Alpha",
GetOpacity());
150 if (label_.empty()) {
157 if (!stencil_enabled_) {
162 #ifdef IMPELLER_ENABLE_OPENGLES
163 if (is_external_texture) {
164 cmd.
pipeline = renderer.GetTextureExternalPipeline(pipeline_options);
170 #endif // IMPELLER_ENABLE_OPENGLES
174 VS::BindFrameInfo(cmd, host_buffer.EmplaceUniform(frame_info));
175 if (is_external_texture) {
176 FSExternal::BindSAMPLEREXTERNALOESTextureSampler(
178 renderer.
GetContext()->GetSamplerLibrary()->GetSampler(
179 sampler_descriptor_));
181 FS::BindTextureSampler(
183 renderer.
GetContext()->GetSamplerLibrary()->GetSampler(
184 sampler_descriptor_));
192 source_rect_ = source_rect;
200 sampler_descriptor_ = std::move(desc);
204 return sampler_descriptor_;
208 defer_applying_opacity_ = defer_applying_opacity;
std::shared_ptr< Pipeline< PipelineDescriptor > > GetTexturePipeline(ContentContextOptions opts) const
void SetSamplerDescriptor(SamplerDescriptor desc)
An object used to specify work to the GPU along with references to resources the GPU will used when d...
#define DEBUG_COMMAND_INFO(obj, arg)
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.
constexpr float kEhCloseEnough
constexpr TRect TransformBounds(const Matrix &transform) const
Creates a new bounding box that contains this transformed rectangle.
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 SetSourceRect(const Rect &source_rect)
void SetStencilEnabled(bool enabled)
VertexBufferBuilder & AddVertices(std::initializer_list< VertexType_ > vertices)
static constexpr Matrix MakeTranslation(const Vector3 &t)
const Matrix & GetOrthographicTransform() const
Scalar GetOpacity() const
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.
bool BindVertices(VertexBuffer buffer)
Specify the vertex and index buffer to use for this command.
std::shared_ptr< Texture > GetTexture() const
@ kAlways
Comparison test passes always passes.
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)
uint32_t stencil_reference
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)
std::shared_ptr< Texture > texture
Capture CreateChild(std::string_view label)
std::shared_ptr< Pipeline< PipelineDescriptor > > pipeline
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
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, const std::string &label="Texture Snapshot") const override
Render this contents to a snapshot, respecting the entity's transform, path, clip depth,...
bool AddCommand(Command &&command)
Record a command for subsequent encoding to the underlying command buffer. No work is encoded into th...
static constexpr Matrix MakeScale(const Vector3 &s)
HostBuffer & GetTransientsBuffer()
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, const std::string &label="Snapshot") const
Render this contents to a snapshot, respecting the entity's transform, path, clip depth,...