| Flutter Impeller |

checkerboard_contents.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "impeller/entity/contents/checkerboard_contents.h"
6
7 #include "impeller/core/formats.h"
8 #include "impeller/entity/contents/content_context.h"
9 #include "impeller/renderer/render_pass.h"
10 #include "impeller/renderer/vertex_buffer_builder.h"
11
12 namespace impeller {
13
14 CheckerboardContents::CheckerboardContents() = default;
15
16 CheckerboardContents::~CheckerboardContents() = default;
17
18 bool CheckerboardContents::Render(const ContentContext& renderer,
19 const Entity& entity,
20 RenderPass& pass) const {
21 auto& host_buffer = renderer.GetTransientsBuffer();
22
23 using VS = CheckerboardPipeline::VertexShader;
24 using FS = CheckerboardPipeline::FragmentShader;
25
26 auto options = OptionsFromPass(pass);
27 options.blend_mode = BlendMode::kSourceOver;
28 options.stencil_mode = ContentContextOptions::StencilMode::kIgnore;
29 options.primitive_type = PrimitiveType::kTriangleStrip;
30
31 VertexBufferBuilder<typename VS::PerVertexData> vtx_builder;
32 vtx_builder.AddVertices({
33 {Point(-1, -1)},
34 {Point(1, -1)},
35 {Point(-1, 1)},
36 {Point(1, 1)},
37 });
38
39 pass.SetCommandLabel("Checkerboard");
40 pass.SetPipeline(renderer.GetCheckerboardPipeline(options));
41 pass.SetVertexBuffer(vtx_builder.CreateVertexBuffer(host_buffer));
42
43 FS::FragInfo frag_info;
44 frag_info.color = color_;
45 frag_info.square_size = square_size_;
46 FS::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info));
47
48 return pass.Draw().ok();
49 }
50
51 std::optional<Rect> CheckerboardContents::GetCoverage(
52 const Entity& entity) const {
53 return std::nullopt;
54 }
55
56 void CheckerboardContents::SetColor(Color color) {
57 color_ = color;
58 }
59
60 void CheckerboardContents::SetSquareSize(Scalar square_size) {
61 square_size_ = square_size;
62 }
63
64 } // namespace impeller
impeller::ContentContextOptions::StencilMode::kIgnore
@ kIgnore
Turn the stencil test off. Used when drawing without stencil-then-cover.
impeller::OptionsFromPass
ContentContextOptions OptionsFromPass(const RenderPass &pass)
Definition: contents.cc:20
impeller::Scalar
float Scalar
Definition: scalar.h:18
impeller::CheckerboardContents::~CheckerboardContents
~CheckerboardContents() override
impeller::Color
Definition: color.h:124
formats.h
impeller::RenderPass::SetVertexBuffer
virtual bool SetVertexBuffer(VertexBuffer buffer)
Specify the vertex and index buffer to use for this command.
Definition: render_pass.cc:123
impeller::VertexBufferBuilder::AddVertices
VertexBufferBuilder & AddVertices(std::initializer_list< VertexType_ > vertices)
Definition: vertex_buffer_builder.h:70
checkerboard_contents.h
impeller::RenderPass::SetCommandLabel
virtual void SetCommandLabel(std::string_view label)
The debugging label to use for the command.
Definition: render_pass.cc:97
impeller::RenderPass::Draw
virtual fml::Status Draw()
Record the currently pending command.
Definition: render_pass.cc:127
impeller::VS
SolidFillVertexShader VS
Definition: stroke_path_geometry.cc:15
impeller::Entity
Definition: entity.h:21
impeller::CheckerboardContents::SetSquareSize
void SetSquareSize(Scalar square_size)
Definition: checkerboard_contents.cc:60
impeller::PrimitiveType::kTriangleStrip
@ kTriangleStrip
impeller::Point
TPoint< Scalar > Point
Definition: point.h:316
render_pass.h
impeller::VertexBufferBuilder
Definition: vertex_buffer_builder.h:24
impeller::CheckerboardContents::Render
bool Render(const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
Definition: checkerboard_contents.cc:18
impeller::VertexBufferBuilder::CreateVertexBuffer
VertexBuffer CreateVertexBuffer(HostBuffer &host_buffer) const
Definition: vertex_buffer_builder.h:84
impeller::RenderPass
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition: render_pass.h:33
impeller::CheckerboardContents::SetColor
void SetColor(Color color)
Definition: checkerboard_contents.cc:56
content_context.h
impeller::RenderPass::SetPipeline
virtual void SetPipeline(const std::shared_ptr< Pipeline< PipelineDescriptor >> &pipeline)
The pipeline to use for this command.
Definition: render_pass.cc:92
impeller::CheckerboardContents::GetCoverage
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.
Definition: checkerboard_contents.cc:51
impeller
Definition: aiks_blur_unittests.cc:20
impeller::ContentContext
Definition: content_context.h:392
impeller::BlendMode::kSourceOver
@ kSourceOver
impeller::ContentContext::GetTransientsBuffer
HostBuffer & GetTransientsBuffer() const
Retrieve the currnent host buffer for transient storage.
Definition: content_context.h:833
vertex_buffer_builder.h
impeller::CheckerboardContents::CheckerboardContents
CheckerboardContents()