13#include "impeller/entity/texture_fill.frag.h"
14#include "impeller/entity/texture_fill.vert.h"
21 std::shared_ptr<Texture>
texture,
23 const Rect& destination,
27 bool use_strict_src_rect)
30 destination_(destination),
32 blend_mode_(blend_mode),
34 use_strict_src_rect_(use_strict_src_rect) {}
48 using VS = TextureFillVertexShader;
49 constexpr size_t indices[6] = {0, 1, 2, 1, 2, 3};
52 sizeof(VS::PerVertexData) * 6,
alignof(VS::PerVertexData),
53 [&](uint8_t* raw_data) {
54 VS::PerVertexData*
data =
55 reinterpret_cast<VS::PerVertexData*
>(raw_data);
57 std::array<TPoint<float>, 4> destination_points =
59 std::array<TPoint<float>, 4> texture_coords =
61 for (
size_t j = 0; j < 6; j++) {
62 data[offset].position = destination_points[indices[j]];
63 data[offset].texture_coords = texture_coords[indices[j]];
78 using VS = PorterDuffBlendVertexShader;
79 constexpr size_t indices[6] = {0, 1, 2, 1, 2, 3};
82 sizeof(VS::PerVertexData) * 6,
alignof(VS::PerVertexData),
83 [&](uint8_t* raw_data) {
84 VS::PerVertexData*
data =
85 reinterpret_cast<VS::PerVertexData*
>(raw_data);
87 std::array<TPoint<float>, 4> texture_coords =
89 std::array<TPoint<float>, 4> destination_points =
91 for (
size_t j = 0; j < 6; j++) {
92 data[offset].vertices = destination_points[indices[j]];
93 data[offset].texture_coords = texture_coords[indices[j]];
129 if (use_strict_src_rect_) {
152 geometry_ = geometry;
162 if (geometry_->
ShouldSkip() || alpha_ <= 0.0) {
169 renderer.
GetContext()->GetSamplerLibrary()->GetSampler(
170 dst_sampler_descriptor);
174 using VS = TextureFillVertexShader;
175 using FS = TextureFillFragmentShader;
178 renderer.
GetContext()->GetSamplerLibrary()->GetSampler(
179 dst_sampler_descriptor);
183 pipeline_options.depth_write_enabled =
192 VS::FrameInfo frame_info;
194 frame_info.texture_sampler_y_coord_scale =
195 geometry_->
GetAtlas()->GetYCoordScale();
197 VS::BindFrameInfo(pass, data_host_buffer.EmplaceUniform(frame_info));
199 FS::FragInfo frag_info;
200 frag_info.alpha = alpha_;
201 FS::BindFragInfo(pass, data_host_buffer.EmplaceUniform((frag_info)));
202 FS::BindTextureSampler(pass, geometry_->
GetAtlas(), dst_sampler);
209 using VS = PorterDuffBlendPipeline::VertexShader;
210 using FS = PorterDuffBlendPipeline::FragmentShader;
223 FS::FragInfo frag_info;
224 VS::FrameInfo frame_info;
226 FS::BindTextureSamplerDst(pass, geometry_->
GetAtlas(), dst_sampler);
227 frame_info.texture_sampler_y_coord_scale =
228 geometry_->
GetAtlas()->GetYCoordScale();
230 frag_info.input_alpha_output_alpha_tmx_tmy =
234 Rect src_rect = rect.value();
235 frag_info.source_rect =
238 frag_info.use_strict_source_rect = 1.0;
240 frag_info.use_strict_source_rect = 0.0;
243 FS::BindFragInfo(pass, data_host_buffer.EmplaceUniform(frag_info));
247 auto uniform_view = data_host_buffer.EmplaceUniform(frame_info);
248 VS::BindFrameInfo(pass, uniform_view);
253 using VUS = VerticesUber1Shader::VertexShader;
254 using FS = VerticesUber1Shader::FragmentShader;
263 FS::BindTextureSampler(pass, geometry_->
GetAtlas(), dst_sampler);
265 VUS::FrameInfo frame_info;
266 FS::FragInfo frag_info;
268 frame_info.texture_sampler_y_coord_scale =
269 geometry_->
GetAtlas()->GetYCoordScale();
272 frag_info.alpha = alpha_;
273 frag_info.blend_mode =
static_cast<int>(blend_mode);
279 FS::BindFragInfo(pass, data_host_buffer.EmplaceUniform(frag_info));
280 VUS::BindFrameInfo(pass, data_host_buffer.EmplaceUniform(frame_info));
292 const Entity& entity)
const {
300 geometry_ = geometry;
314 if (geometry_->
ShouldSkip() || alpha_ <= 0.0) {
322 renderer.
GetContext()->GetSamplerLibrary()->GetSampler(
323 dst_sampler_descriptor);
327 using VS = ColorMatrixColorFilterPipeline::VertexShader;
328 using FS = ColorMatrixColorFilterPipeline::FragmentShader;
337 FS::FragInfo frag_info;
338 VS::FrameInfo frame_info;
340 FS::BindInputTexture(pass, geometry_->
GetAtlas(), dst_sampler);
341 frame_info.texture_sampler_y_coord_scale =
342 geometry_->
GetAtlas()->GetYCoordScale();
344 frag_info.input_alpha = 1;
345 frag_info.output_alpha = alpha_;
346 const float* matrix = matrix_.
array;
347 frag_info.color_v =
Vector4(matrix[4], matrix[9], matrix[14], matrix[19]);
348 frag_info.color_m =
Matrix(matrix[0], matrix[5], matrix[10], matrix[15],
349 matrix[1], matrix[6], matrix[11], matrix[16],
350 matrix[2], matrix[7], matrix[12], matrix[17],
351 matrix[3], matrix[8], matrix[13], matrix[18]
354 FS::BindFragInfo(pass, data_host_buffer.EmplaceUniform(frag_info));
358 auto uniform_view = data_host_buffer.EmplaceUniform(frame_info);
359 VS::BindFrameInfo(pass, uniform_view);
bool Render(const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
void SetGeometry(AtlasGeometry *geometry)
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 SetAlpha(Scalar alpha)
~AtlasContents() override
virtual const SamplerDescriptor & GetSamplerDescriptor() const =0
virtual VertexBuffer CreateSimpleVertexBuffer(HostBuffer &host_buffer) const =0
virtual Rect ComputeBoundingBox() const =0
virtual const std::shared_ptr< Texture > & GetAtlas() const =0
virtual bool ShouldInvertBlendMode() const
virtual bool ShouldUseBlend() const =0
virtual bool ShouldSkip() const =0
virtual VertexBuffer CreateBlendVertexBuffer(HostBuffer &host_buffer) const =0
virtual BlendMode GetBlendMode() const =0
virtual std::optional< Rect > GetStrictSrcRect() const
The source rect of the draw in texture coordinates if a strict source rect should be applied,...
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 SetGeometry(AtlasGeometry *geometry)
ColorFilterAtlasContents()
void SetAlpha(Scalar alpha)
~ColorFilterAtlasContents() override
void SetMatrix(ColorMatrix matrix)
bool Render(const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
HostBuffer & GetTransientsDataBuffer() const
Retrieve the current host buffer for transient storage of other non-index data.
PipelineRef GetPorterDuffPipeline(BlendMode mode, ContentContextOptions opts) const
PipelineRef GetTexturePipeline(ContentContextOptions opts) const
PipelineRef GetColorMatrixColorFilterPipeline(ContentContextOptions opts) const
std::shared_ptr< Context > GetContext() const
PipelineRef GetDrawVerticesUberPipeline(BlendMode blend_mode, ContentContextOptions opts) const
DrawImageRectAtlasGeometry(std::shared_ptr< Texture > texture, const Rect &source, const Rect &destination, const Color &color, BlendMode blend_mode, const SamplerDescriptor &desc, bool use_strict_src_rect=false)
Rect ComputeBoundingBox() const override
const SamplerDescriptor & GetSamplerDescriptor() const override
bool ShouldUseBlend() const override
std::optional< Rect > GetStrictSrcRect() const override
The source rect of the draw in texture coordinates if a strict source rect should be applied,...
BlendMode GetBlendMode() const override
bool ShouldInvertBlendMode() const override
VertexBuffer CreateBlendVertexBuffer(HostBuffer &host_buffer) const override
VertexBuffer CreateSimpleVertexBuffer(HostBuffer &host_buffer) const override
bool ShouldSkip() const override
~DrawImageRectAtlasGeometry()
const std::shared_ptr< Texture > & GetAtlas() const override
Matrix GetShaderTransform(const RenderPass &pass) const
const Matrix & GetTransform() const
Get the global transform matrix for this Entity.
BufferView Emplace(const BufferType &buffer, size_t alignment=0)
Emplace non-uniform data (like contiguous vertices) onto the host buffer.
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.
A wrapper around a raw ptr that adds additional unopt mode only checks.
std::optional< PipelineDescriptor > desc_
@ kNone
Does not use the index buffer.
LinePipeline::FragmentShader FS
std::optional< BlendMode > InvertPorterDuffBlend(BlendMode blend_mode)
LinePipeline::VertexShader VS
ContentContextOptions OptionsFromPassAndEntity(const RenderPass &pass, const Entity &entity)
ContentContextOptions OptionsFromPass(const RenderPass &pass)
constexpr Color Premultiply() const
A 4x4 matrix using column-major storage.
constexpr auto GetBottom() const
constexpr Type GetY() const
Returns the Y coordinate of the upper left corner, equivalent to |GetOrigin().y|.
constexpr TRect TransformBounds(const Matrix &transform) const
Creates a new bounding box that contains this transformed rectangle.
constexpr std::array< TPoint< T >, 4 > GetPoints() const
Get the points that represent the 4 corners of this rectangle in a Z order that is compatible with tr...
constexpr TRect< T > Project(TRect< T > source) const
Returns a new rectangle that represents the projection of the source rectangle onto this rectangle....
constexpr Type GetX() const
Returns the X coordinate of the upper left corner, equivalent to |GetOrigin().x|.
constexpr auto GetRight() const
static constexpr TRect MakeSize(const TSize< U > &size)
constexpr TRect< T > Expand(T left, T top, T right, T bottom) const
Returns a rectangle with expanded edges. Negative expansion results in shrinking.
std::shared_ptr< const fml::Mapping > data