| Flutter Impeller |

render_pass.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/renderer/render_pass.h"
6
7 namespace impeller {
8
9 RenderPass::RenderPass(std::weak_ptr<const Context> context,
10 const RenderTarget& target)
11 : context_(std::move(context)),
12 sample_count_(target.GetSampleCount()),
13 pixel_format_(target.GetRenderTargetPixelFormat()),
14 has_stencil_attachment_(target.GetStencilAttachment().has_value()),
15 render_target_size_(target.GetRenderTargetSize()),
16 render_target_(target),
17 transients_buffer_(),
18 orthographic_(Matrix::MakeOrthographic(render_target_size_)) {
19 auto strong_context = context_.lock();
20 FML_DCHECK(strong_context);
21 transients_buffer_ = strong_context->GetHostBufferPool().Grab();
22 }
23
24 RenderPass::~RenderPass() {
25 auto strong_context = context_.lock();
26 if (strong_context) {
27 strong_context->GetHostBufferPool().Recycle(transients_buffer_);
28 }
29 }
30
31 SampleCount RenderPass::GetSampleCount() const {
32 return sample_count_;
33 }
34
35 PixelFormat RenderPass::GetRenderTargetPixelFormat() const {
36 return pixel_format_;
37 }
38
39 bool RenderPass::HasStencilAttachment() const {
40 return has_stencil_attachment_;
41 }
42
43 const RenderTarget& RenderPass::GetRenderTarget() const {
44 return render_target_;
45 }
46
47 ISize RenderPass::GetRenderTargetSize() const {
48 return render_target_size_;
49 }
50
51 const Matrix& RenderPass::GetOrthographicTransform() const {
52 return orthographic_;
53 }
54
55 HostBuffer& RenderPass::GetTransientsBuffer() {
56 return *transients_buffer_;
57 }
58
59 void RenderPass::SetLabel(std::string label) {
60 if (label.empty()) {
61 return;
62 }
63 transients_buffer_->SetLabel(SPrintF("%s Transients", label.c_str()));
64 OnSetLabel(std::move(label));
65 }
66
67 bool RenderPass::AddCommand(Command&& command) {
68 if (!command.IsValid()) {
69 VALIDATION_LOG << "Attempted to add an invalid command to the render pass.";
70 return false;
71 }
72
73 if (command.scissor.has_value()) {
74 auto target_rect = IRect::MakeSize(render_target_.GetRenderTargetSize());
75 if (!target_rect.Contains(command.scissor.value())) {
76 VALIDATION_LOG << "Cannot apply a scissor that lies outside the bounds "
77 "of the render target.";
78 return false;
79 }
80 }
81
82 if (command.vertex_buffer.vertex_count == 0u ||
83 command.instance_count == 0u) {
84 // Essentially a no-op. Don't record the command but this is not necessary
85 // an error either.
86 return true;
87 }
88
89 commands_.emplace_back(std::move(command));
90 return true;
91 }
92
93 bool RenderPass::EncodeCommands() const {
94 auto context = context_.lock();
95 // The context could have been collected in the meantime.
96 if (!context) {
97 return false;
98 }
99 return OnEncodeCommands(*context);
100 }
101
102 const std::weak_ptr<const Context>& RenderPass::GetContext() const {
103 return context_;
104 }
105
106 } // namespace impeller
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
impeller::RenderPass::GetOrthographicTransform
const Matrix & GetOrthographicTransform() const
Definition: render_pass.cc:51
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
impeller::RenderPass::GetRenderTargetSize
ISize GetRenderTargetSize() const
Definition: render_pass.cc:47
impeller::TSize< int64_t >
render_pass.h
impeller::SPrintF
std::string SPrintF(const char *format,...)
Definition: strings.cc:12
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::RenderTarget::GetRenderTargetSize
ISize GetRenderTargetSize() const
Definition: render_target.cc:150
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:67
impeller::RenderPass::SetLabel
void SetLabel(std::string label)
Definition: render_pass.cc:59
impeller::TRect< int64_t >::MakeSize
constexpr static TRect MakeSize(const TSize< U > &size)
Definition: rect.h:44
std
Definition: comparable.h:95
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
impeller::RenderPass::has_stencil_attachment_
const bool has_stencil_attachment_
Definition: render_pass.h:101
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::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