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 : texture_(
std::move(texture)),
29 destination_(destination),
31 blend_mode_(blend_mode),
46 using VS = TextureFillVertexShader;
47 constexpr
size_t indices[6] = {0, 1, 2, 1, 2, 3};
50 sizeof(VS::PerVertexData) * 6,
alignof(VS::PerVertexData),
51 [&](uint8_t* raw_data) {
52 VS::PerVertexData*
data =
53 reinterpret_cast<VS::PerVertexData*
>(raw_data);
55 std::array<TPoint<float>, 4> destination_points =
57 std::array<TPoint<float>, 4> texture_coords =
59 for (
size_t j = 0; j < 6; j++) {
60 data[
offset].position = destination_points[indices[j]];
61 data[
offset].texture_coords = texture_coords[indices[j]];
76 using VS = PorterDuffBlendVertexShader;
77 constexpr
size_t indices[6] = {0, 1, 2, 1, 2, 3};
80 sizeof(VS::PerVertexData) * 6,
alignof(VS::PerVertexData),
81 [&](uint8_t* raw_data) {
82 VS::PerVertexData*
data =
83 reinterpret_cast<VS::PerVertexData*
>(raw_data);
85 std::array<TPoint<float>, 4> texture_coords =
87 std::array<TPoint<float>, 4> destination_points =
89 for (
size_t j = 0; j < 6; j++) {
90 data[
offset].vertices = destination_points[indices[j]];
91 data[
offset].texture_coords = texture_coords[indices[j]];
140 geometry_ = geometry;
150 if (geometry_->
ShouldSkip() || alpha_ <= 0.0) {
157 renderer.
GetContext()->GetSamplerLibrary()->GetSampler(
158 dst_sampler_descriptor);
162 using VS = TextureFillVertexShader;
163 using FS = TextureFillFragmentShader;
166 renderer.
GetContext()->GetSamplerLibrary()->GetSampler(
167 dst_sampler_descriptor);
171 pipeline_options.depth_write_enabled =
176 #ifdef IMPELLER_DEBUG
180 VS::FrameInfo frame_info;
182 frame_info.texture_sampler_y_coord_scale =
183 geometry_->
GetAtlas()->GetYCoordScale();
185 VS::BindFrameInfo(pass, host_buffer.EmplaceUniform(frame_info));
187 FS::FragInfo frag_info;
188 frag_info.alpha = alpha_;
189 FS::BindFragInfo(pass, host_buffer.EmplaceUniform((frag_info)));
190 FS::BindTextureSampler(pass, geometry_->
GetAtlas(), dst_sampler);
191 return pass.
Draw().ok();
200 #ifdef IMPELLER_DEBUG
211 FS::FragInfo frag_info;
212 VS::FrameInfo frame_info;
214 FS::BindTextureSamplerDst(pass, geometry_->
GetAtlas(), dst_sampler);
215 frame_info.texture_sampler_y_coord_scale =
216 geometry_->
GetAtlas()->GetYCoordScale();
218 frag_info.output_alpha = alpha_;
219 frag_info.input_alpha = 1.0;
225 FS::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info));
229 auto uniform_view = host_buffer.EmplaceUniform(frame_info);
230 VS::BindFrameInfo(pass, uniform_view);
232 return pass.
Draw().ok();
238 #ifdef IMPELLER_DEBUG
245 FS::BindTextureSampler(pass, geometry_->
GetAtlas(), dst_sampler);
247 VUS::FrameInfo frame_info;
248 FS::FragInfo frag_info;
250 frame_info.texture_sampler_y_coord_scale =
251 geometry_->
GetAtlas()->GetYCoordScale();
254 frag_info.alpha = alpha_;
255 frag_info.blend_mode =
static_cast<int>(blend_mode);
261 FS::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info));
262 VUS::BindFrameInfo(pass, host_buffer.EmplaceUniform(frame_info));
264 return pass.
Draw().ok();
274 const Entity& entity)
const {
282 geometry_ = geometry;
296 if (geometry_->
ShouldSkip() || alpha_ <= 0.0) {
304 renderer.
GetContext()->GetSamplerLibrary()->GetSampler(
305 dst_sampler_descriptor);
312 #ifdef IMPELLER_DEBUG
319 FS::FragInfo frag_info;
320 VS::FrameInfo frame_info;
322 FS::BindInputTexture(pass, geometry_->
GetAtlas(), dst_sampler);
323 frame_info.texture_sampler_y_coord_scale =
324 geometry_->
GetAtlas()->GetYCoordScale();
326 frag_info.input_alpha = 1;
327 frag_info.output_alpha = alpha_;
328 const float* matrix = matrix_.
array;
329 frag_info.color_v =
Vector4(matrix[4], matrix[9], matrix[14], matrix[19]);
330 frag_info.color_m =
Matrix(matrix[0], matrix[5], matrix[10], matrix[15],
331 matrix[1], matrix[6], matrix[11], matrix[16],
332 matrix[2], matrix[7], matrix[12], matrix[17],
333 matrix[3], matrix[8], matrix[13], matrix[18]
336 FS::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info));
340 auto uniform_view = host_buffer.EmplaceUniform(frame_info);
341 VS::BindFrameInfo(pass, uniform_view);
343 return pass.
Draw().ok();
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 VertexBuffer CreateSimpleVertexBuffer(HostBuffer &host_buffer) const =0
virtual Rect ComputeBoundingBox() const =0
virtual bool ShouldInvertBlendMode() const
virtual bool ShouldUseBlend() const =0
virtual const SamplerDescriptor & GetSamplerDescriptor() const =0
virtual bool ShouldSkip() const =0
virtual VertexBuffer CreateBlendVertexBuffer(HostBuffer &host_buffer) const =0
virtual BlendMode GetBlendMode() const =0
virtual const std::shared_ptr< Texture > & GetAtlas() const =0
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 & GetTransientsBuffer() const
Retrieve the currnent host buffer for transient storage.
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
Rect ComputeBoundingBox() const override
const SamplerDescriptor & GetSamplerDescriptor() const override
bool ShouldUseBlend() const override
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()
DrawImageRectAtlasGeometry(std::shared_ptr< Texture > texture, const Rect &source, const Rect &destination, const Color &color, BlendMode blend_mode, const SamplerDescriptor &desc)
const std::shared_ptr< Texture > & GetAtlas() const override
Matrix GetShaderTransform(const RenderPass &pass) const
Get the vertex shader transform used for drawing this Entity.
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.
VertexShader_ VertexShader
FragmentShader_ FragmentShader
A wrapper around a raw ptr that adds additional unopt mode only checks.
@ 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 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 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 static TRect MakeSize(const TSize< U > &size)
std::shared_ptr< const fml::Mapping > data