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