11 #include "fml/logging.h"
15 #include "impeller/entity/texture_fill.frag.h"
16 #include "impeller/entity/texture_fill.vert.h"
17 #include "impeller/entity/texture_fill_strict_src.frag.h"
18 #include "impeller/entity/tiled_texture_fill_external.frag.h"
30 auto contents = std::make_shared<TextureContents>();
31 contents->destination_rect_ = destination;
40 destination_rect_ = rect;
44 texture_ = std::move(texture);
56 stencil_enabled_ = enabled;
60 inherited_opacity_ = opacity;
64 return opacity_ * inherited_opacity_;
80 auto bounds = destination_rect_;
84 auto scale =
Vector2(bounds.GetSize() /
Size(texture_->GetSize()));
92 .needs_rasterization_for_runtime_effects =
93 snapshots_need_rasterization_for_runtime_effects_};
97 {.coverage_limit = std::nullopt,
100 .msaa_enabled =
true,
102 .label = options.
label,
109 using VS = TextureFillVertexShader;
110 using FS = TextureFillFragmentShader;
111 using FSStrict = TextureFillStrictSrcFragmentShader;
114 texture_ ==
nullptr || texture_->GetSize().IsEmpty()) {
118 #if defined(IMPELLER_ENABLE_OPENGLES) && !defined(FML_OS_EMSCRIPTEN)
119 using FSExternal = TiledTextureFillExternalFragmentShader;
120 bool is_external_texture =
124 auto texture_coords =
128 std::array<VS::PerVertexData, 4> vertices = {
129 VS::PerVertexData{destination_rect_.
GetLeftTop(),
130 texture_coords.GetLeftTop()},
132 texture_coords.GetRightTop()},
134 texture_coords.GetLeftBottom()},
136 texture_coords.GetRightBottom()},
140 VS::FrameInfo frame_info;
142 frame_info.texture_sampler_y_coord_scale = texture_->GetYCoordScale();
144 #ifdef IMPELLER_DEBUG
145 if (label_.empty()) {
153 if (!stencil_enabled_) {
158 pipeline_options.depth_write_enabled =
161 #if defined(IMPELLER_ENABLE_OPENGLES) && !defined(FML_OS_EMSCRIPTEN)
162 if (is_external_texture) {
164 renderer.GetTiledTextureExternalPipeline(pipeline_options));
167 strict_source_rect_enabled_
178 VS::BindFrameInfo(pass, data_host_buffer.EmplaceUniform(frame_info));
180 if (strict_source_rect_enabled_) {
184 auto strict_texture_coords =
187 FSStrict::FragInfo frag_info;
188 if (texture_->GetYCoordScale() < 0.0) {
189 FML_DCHECK(texture_->GetYCoordScale() == -1.0f);
190 frag_info.source_rect =
Vector4(strict_texture_coords.GetLeft(),
191 1.0f - strict_texture_coords.GetBottom(),
192 strict_texture_coords.GetRight(),
193 1.0f - strict_texture_coords.GetTop());
195 frag_info.source_rect =
Vector4(strict_texture_coords.GetLTRB());
198 FSStrict::BindFragInfo(pass, data_host_buffer.EmplaceUniform((frag_info)));
199 FSStrict::BindTextureSampler(
201 renderer.
GetContext()->GetSamplerLibrary()->GetSampler(
202 sampler_descriptor_));
203 #if defined(IMPELLER_ENABLE_OPENGLES) && !defined(FML_OS_EMSCRIPTEN)
204 }
else if (is_external_texture) {
205 FSExternal::FragInfo frag_info;
206 frag_info.x_tile_mode =
208 frag_info.y_tile_mode =
211 FSExternal::BindFragInfo(pass, data_host_buffer.EmplaceUniform(frag_info));
223 FSExternal::BindSAMPLEREXTERNALOESTextureSampler(
225 renderer.
GetContext()->GetSamplerLibrary()->GetSampler(sampler_desc));
228 FS::FragInfo frag_info;
230 FS::BindFragInfo(pass, data_host_buffer.EmplaceUniform((frag_info)));
231 FS::BindTextureSampler(
233 renderer.
GetContext()->GetSamplerLibrary()->GetSampler(
234 sampler_descriptor_));
236 return pass.
Draw().ok();
240 source_rect_ = source_rect;
248 strict_source_rect_enabled_ = strict;
252 return strict_source_rect_enabled_;
256 sampler_descriptor_ = desc;
260 return sampler_descriptor_;
264 defer_applying_opacity_ = defer_applying_opacity;
268 snapshots_need_rasterization_for_runtime_effects_ =
value;
PipelineRef GetTextureStrictSrcPipeline(ContentContextOptions opts) const
PipelineRef GetTexturePipeline(ContentContextOptions opts) const
HostBuffer & GetTransientsDataBuffer() const
Retrieve the current host buffer for transient storage of other non-index data.
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)
@ kIgnore
Turn the stencil test off. Used when drawing without stencil-then-cover.
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< T > Expand(T left, T top, T right, T bottom) const
Returns a rectangle with expanded edges. Negative expansion results in shrinking.
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 > GetLeftBottom() const
constexpr TPoint< T > GetRightTop() const
constexpr static TRect MakeSize(const TSize< U > &size)
constexpr TPoint< T > GetRightBottom() const
constexpr TPoint< T > GetLeftTop() const