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;
195 VS::BindFrameInfo(pass, data_host_buffer.EmplaceUniform(frame_info));
197 FS::FragInfo frag_info;
198 frag_info.alpha = alpha_;
199 FS::BindFragInfo(pass, data_host_buffer.EmplaceUniform((frag_info)));
200 FS::BindTextureSampler(pass, geometry_->
GetAtlas(), dst_sampler);
207 using VS = PorterDuffBlendPipeline::VertexShader;
208 using FS = PorterDuffBlendPipeline::FragmentShader;
221 FS::FragInfo frag_info;
222 VS::FrameInfo frame_info;
224 FS::BindTextureSamplerDst(pass, geometry_->
GetAtlas(), dst_sampler);
226 frag_info.input_alpha_output_alpha_tmx_tmy =
230 Rect src_rect = rect.value();
231 frag_info.source_rect =
234 frag_info.use_strict_source_rect = 1.0;
236 frag_info.use_strict_source_rect = 0.0;
239 FS::BindFragInfo(pass, data_host_buffer.EmplaceUniform(frag_info));
243 auto uniform_view = data_host_buffer.EmplaceUniform(frame_info);
244 VS::BindFrameInfo(pass, uniform_view);
249 using VUS = VerticesUber1Shader::VertexShader;
250 using FS = VerticesUber1Shader::FragmentShader;
259 FS::BindTextureSampler(pass, geometry_->
GetAtlas(), dst_sampler);
261 VUS::FrameInfo frame_info;
262 FS::FragInfo frag_info;
266 frag_info.alpha = alpha_;
267 frag_info.blend_mode =
static_cast<int>(blend_mode);
273 FS::BindFragInfo(pass, data_host_buffer.EmplaceUniform(frag_info));
274 VUS::BindFrameInfo(pass, data_host_buffer.EmplaceUniform(frame_info));
286 const Entity& entity)
const {
294 geometry_ = geometry;
308 if (geometry_->
ShouldSkip() || alpha_ <= 0.0) {
316 renderer.
GetContext()->GetSamplerLibrary()->GetSampler(
317 dst_sampler_descriptor);
321 using VS = ColorMatrixColorFilterPipeline::VertexShader;
322 using FS = ColorMatrixColorFilterPipeline::FragmentShader;
331 FS::FragInfo frag_info;
332 VS::FrameInfo frame_info;
334 FS::BindInputTexture(pass, geometry_->
GetAtlas(), dst_sampler);
336 frag_info.input_alpha = 1;
337 frag_info.output_alpha = alpha_;
338 const float* matrix = matrix_.
array;
339 frag_info.color_v =
Vector4(matrix[4], matrix[9], matrix[14], matrix[19]);
340 frag_info.color_m =
Matrix(matrix[0], matrix[5], matrix[10], matrix[15],
341 matrix[1], matrix[6], matrix[11], matrix[16],
342 matrix[2], matrix[7], matrix[12], matrix[17],
343 matrix[3], matrix[8], matrix[13], matrix[18]
346 FS::BindFragInfo(pass, data_host_buffer.EmplaceUniform(frag_info));
350 auto uniform_view = data_host_buffer.EmplaceUniform(frame_info);
351 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.