| 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 <memory>
8
9 #include "impeller/core/formats.h"
10 #include "impeller/entity/contents/content_context.h"
11 #include "impeller/renderer/command.h"
12 #include "impeller/renderer/render_pass.h"
13
14 namespace impeller {
15
16 CheckerboardContents::CheckerboardContents() = default;
17
18 CheckerboardContents::~CheckerboardContents() = default;
19
20 bool CheckerboardContents::Render(const ContentContext& renderer,
21 const Entity& entity,
22 RenderPass& pass) const {
23 auto& host_buffer = pass.GetTransientsBuffer();
24
25 using VS = CheckerboardPipeline::VertexShader;
26 using FS = CheckerboardPipeline::FragmentShader;
27
28 Command cmd;
29 DEBUG_COMMAND_INFO(cmd, "Checkerboard");
30
31 auto options = OptionsFromPass(pass);
32 options.blend_mode = BlendMode::kSourceOver;
33 options.stencil_compare = CompareFunction::kAlways; // Ignore all clips.
34 options.stencil_operation = StencilOperation::kKeep;
35 options.primitive_type = PrimitiveType::kTriangleStrip;
36 cmd.pipeline = renderer.GetCheckerboardPipeline(options);
37
38 VertexBufferBuilder<typename VS::PerVertexData> vtx_builder;
39 vtx_builder.AddVertices({
40 {Point(-1, -1)},
41 {Point(1, -1)},
42 {Point(-1, 1)},
43 {Point(1, 1)},
44 });
45 cmd.BindVertices(vtx_builder.CreateVertexBuffer(host_buffer));
46
47 FS::FragInfo frag_info;
48 frag_info.color = color_;
49 frag_info.square_size = square_size_;
50 FS::BindFragInfo(cmd, host_buffer.EmplaceUniform(frag_info));
51
52 pass.AddCommand(std::move(cmd));
53
54 return true;
55 }
56
57 std::optional<Rect> CheckerboardContents::GetCoverage(
58 const Entity& entity) const {
59 return std::nullopt;
60 }
61
62 void CheckerboardContents::SetColor(Color color) {
63 color_ = color;
64 }
65
66 void CheckerboardContents::SetSquareSize(Scalar square_size) {
67 square_size_ = square_size;
68 }
69
70 } // namespace impeller
impeller::OptionsFromPass
ContentContextOptions OptionsFromPass(const RenderPass &pass)
Definition: contents.cc:20
impeller::Command
An object used to specify work to the GPU along with references to resources the GPU will used when d...
Definition: command.h:99
DEBUG_COMMAND_INFO
#define DEBUG_COMMAND_INFO(obj, arg)
Definition: command.h:31
impeller::Scalar
float Scalar
Definition: scalar.h:15
impeller::CheckerboardContents::~CheckerboardContents
~CheckerboardContents() override
impeller::Color
Definition: color.h:122
formats.h
impeller::VertexBufferBuilder::AddVertices
VertexBufferBuilder & AddVertices(std::initializer_list< VertexType_ > vertices)
Definition: vertex_buffer_builder.h:64
checkerboard_contents.h
impeller::PrimitiveType::kTriangleStrip
@ kTriangleStrip
impeller::Entity
Definition: entity.h:21
command.h
impeller::StencilOperation::kKeep
@ kKeep
Don't modify the current stencil value.
impeller::CheckerboardContents::SetSquareSize
void SetSquareSize(Scalar square_size)
Definition: checkerboard_contents.cc:66
impeller::Point
TPoint< Scalar > Point
Definition: point.h:306
render_pass.h
impeller::BlendMode::kSourceOver
@ kSourceOver
impeller::VertexBufferBuilder
Definition: vertex_buffer_builder.h:23
impeller::CheckerboardContents::Render
bool Render(const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
Definition: checkerboard_contents.cc:20
impeller::VertexBufferBuilder::CreateVertexBuffer
VertexBuffer CreateVertexBuffer(HostBuffer &host_buffer) const
Definition: vertex_buffer_builder.h:78
impeller::RenderPass
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition: render_pass.h:27
impeller::CheckerboardContents::SetColor
void SetColor(Color color)
Definition: checkerboard_contents.cc:62
content_context.h
impeller::CompareFunction::kAlways
@ kAlways
Comparison test passes always passes.
impeller::CheckerboardContents::GetCoverage
std::optional< Rect > GetCoverage(const Entity &entity) const override
Get the screen space bounding rectangle that this contents affects.
Definition: checkerboard_contents.cc:57
impeller::Command::BindVertices
bool BindVertices(const VertexBuffer &buffer)
Specify the vertex and index buffer to use for this command.
Definition: command.cc:15
impeller::Command::pipeline
std::shared_ptr< Pipeline< PipelineDescriptor > > pipeline
Definition: command.h:103
impeller::RenderPass::AddCommand
bool AddCommand(Command &&command)
Record a command for subsequent encoding to the underlying command buffer. No work is encoded into th...
Definition: render_pass.cc:46
impeller
Definition: aiks_context.cc:10
impeller::ContentContext
Definition: content_context.h:344
impeller::RenderPass::GetTransientsBuffer
HostBuffer & GetTransientsBuffer()
Definition: render_pass.cc:34
impeller::CheckerboardContents::CheckerboardContents
CheckerboardContents()