Flutter Impeller
render_pass.h
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 #ifndef FLUTTER_IMPELLER_RENDERER_RENDER_PASS_H_
6 #define FLUTTER_IMPELLER_RENDERER_RENDER_PASS_H_
7 
8 #include <string>
9 
10 #include "impeller/core/formats.h"
14 
15 namespace impeller {
16 
17 class HostBuffer;
18 class Allocator;
19 
20 //------------------------------------------------------------------------------
21 /// @brief Render passes encode render commands directed as one specific
22 /// render target into an underlying command buffer.
23 ///
24 /// Render passes can be obtained from the command buffer in which
25 /// the pass is meant to encode commands into.
26 ///
27 /// @see `CommandBuffer`
28 ///
29 class RenderPass {
30  public:
31  virtual ~RenderPass();
32 
33  const std::weak_ptr<const Context>& GetContext() const;
34 
35  const RenderTarget& GetRenderTarget() const;
36 
37  ISize GetRenderTargetSize() const;
38 
39  const Matrix& GetOrthographicTransform() const;
40 
41  virtual bool IsValid() const = 0;
42 
43  void SetLabel(std::string label);
44 
45  /// @brief Reserve [command_count] commands in the HAL command buffer.
46  ///
47  /// Note: this is not the native command buffer.
48  void ReserveCommands(size_t command_count) {
49  commands_.reserve(command_count);
50  }
51 
53 
54  //----------------------------------------------------------------------------
55  /// @brief Record a command for subsequent encoding to the underlying
56  /// command buffer. No work is encoded into the command buffer at
57  /// this time.
58  ///
59  /// @param[in] command The command
60  ///
61  /// @return If the command was valid for subsequent commitment.
62  ///
63  bool AddCommand(Command&& command);
64 
65  //----------------------------------------------------------------------------
66  /// @brief Encode the recorded commands to the underlying command buffer.
67  ///
68  /// @return If the commands were encoded to the underlying command
69  /// buffer.
70  ///
71  bool EncodeCommands() const;
72 
73  //----------------------------------------------------------------------------
74  /// @brief Accessor for the current Commands.
75  ///
76  /// @details Visible for testing.
77  ///
78  const std::vector<Command>& GetCommands() const { return commands_; }
79 
80  //----------------------------------------------------------------------------
81  /// @brief The sample count of the attached render target.
83 
84  //----------------------------------------------------------------------------
85  /// @brief The pixel format of the attached render target.
87 
88  //----------------------------------------------------------------------------
89  /// @brief Whether the render target has an stencil attachment.
90  bool HasStencilAttachment() const;
91 
92  protected:
93  const std::weak_ptr<const Context> context_;
94  // The following properties: sample_count, pixel_format,
95  // has_stencil_attachment, and render_target_size are cached on the
96  // RenderTarget to speed up numerous lookups during rendering. This is safe as
97  // the RenderTarget itself is copied into the RenderTarget and only exposed as
98  // a const reference.
104  std::shared_ptr<HostBuffer> transients_buffer_;
105  std::vector<Command> commands_;
107 
108  RenderPass(std::weak_ptr<const Context> context, const RenderTarget& target);
109 
110  virtual void OnSetLabel(std::string label) = 0;
111 
112  virtual bool OnEncodeCommands(const Context& context) const = 0;
113 
114  private:
115  RenderPass(const RenderPass&) = delete;
116 
117  RenderPass& operator=(const RenderPass&) = delete;
118 };
119 
120 } // namespace impeller
121 
122 #endif // FLUTTER_IMPELLER_RENDERER_RENDER_PASS_H_
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:92
impeller::RenderPass::GetRenderTarget
const RenderTarget & GetRenderTarget() const
Definition: render_pass.cc:43
impeller::HostBuffer
Definition: host_buffer.h:20
formats.h
impeller::RenderPass::GetOrthographicTransform
const Matrix & GetOrthographicTransform() const
Definition: render_pass.cc:51
impeller::RenderPass::GetCommands
const std::vector< Command > & GetCommands() const
Accessor for the current Commands.
Definition: render_pass.h:78
impeller::RenderPass::RenderPass
RenderPass(std::weak_ptr< const Context > context, const RenderTarget &target)
Definition: render_pass.cc:9
impeller::RenderPass::pixel_format_
const PixelFormat pixel_format_
Definition: render_pass.h:100
impeller::PixelFormat
PixelFormat
The Pixel formats supported by Impeller. The naming convention denotes the usage of the component,...
Definition: formats.h:94
impeller::RenderPass::EncodeCommands
bool EncodeCommands() const
Encode the recorded commands to the underlying command buffer.
Definition: render_pass.cc:93
command.h
impeller::RenderPass::GetRenderTargetSize
ISize GetRenderTargetSize() const
Definition: render_pass.cc:47
impeller::TSize< int64_t >
impeller::RenderPass::OnEncodeCommands
virtual bool OnEncodeCommands(const Context &context) const =0
impeller::RenderPass::GetSampleCount
SampleCount GetSampleCount() const
The sample count of the attached render target.
Definition: render_pass.cc:31
impeller::RenderTarget
Definition: render_target.h:49
impeller::RenderPass::render_target_
const RenderTarget render_target_
Definition: render_pass.h:103
impeller::RenderPass::~RenderPass
virtual ~RenderPass()
Definition: render_pass.cc:24
impeller::RenderPass::commands_
std::vector< Command > commands_
Definition: render_pass.h:105
impeller::RenderPass::render_target_size_
const ISize render_target_size_
Definition: render_pass.h:102
impeller::RenderPass
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition: render_pass.h:29
command_buffer.h
impeller::RenderPass::SetLabel
void SetLabel(std::string label)
Definition: render_pass.cc:59
impeller::Context
To do anything rendering related with Impeller, you need a context.
Definition: context.h:47
impeller::SampleCount
SampleCount
Definition: formats.h:290
impeller::RenderPass::HasStencilAttachment
bool HasStencilAttachment() const
Whether the render target has an stencil attachment.
Definition: render_pass.cc:39
impeller::RenderPass::OnSetLabel
virtual void OnSetLabel(std::string label)=0
render_target.h
impeller::RenderPass::has_stencil_attachment_
const bool has_stencil_attachment_
Definition: render_pass.h:101
impeller::RenderPass::IsValid
virtual bool IsValid() const =0
impeller::RenderPass::orthographic_
const Matrix orthographic_
Definition: render_pass.h:106
impeller::RenderPass::GetContext
const std::weak_ptr< const Context > & GetContext() const
Definition: render_pass.cc:102
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:67
impeller
Definition: aiks_context.cc:10
impeller::RenderPass::context_
const std::weak_ptr< const Context > context_
Definition: render_pass.h:93
impeller::RenderPass::ReserveCommands
void ReserveCommands(size_t command_count)
Reserve [command_count] commands in the HAL command buffer.
Definition: render_pass.h:48
impeller::Matrix
A 4x4 matrix using column-major storage.
Definition: matrix.h:37
impeller::RenderPass::GetTransientsBuffer
HostBuffer & GetTransientsBuffer()
Definition: render_pass.cc:55
impeller::RenderPass::transients_buffer_
std::shared_ptr< HostBuffer > transients_buffer_
Definition: render_pass.h:104
impeller::RenderPass::GetRenderTargetPixelFormat
PixelFormat GetRenderTargetPixelFormat() const
The pixel format of the attached render target.
Definition: render_pass.cc:35
impeller::RenderPass::sample_count_
const SampleCount sample_count_
Definition: render_pass.h:99