Flutter Impeller
command_buffer_vk.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 #include <memory>
8 #include <utility>
9 
10 #include "flutter/fml/logging.h"
20 
21 namespace impeller {
22 
23 CommandBufferVK::CommandBufferVK(
24  std::weak_ptr<const Context> context,
25  std::shared_ptr<CommandEncoderFactoryVK> encoder_factory)
26  : CommandBuffer(std::move(context)),
27  encoder_factory_(std::move(encoder_factory)) {}
28 
30 
31 void CommandBufferVK::SetLabel(const std::string& label) const {
32  if (!encoder_) {
33  encoder_factory_->SetLabel(label);
34  } else {
35  auto context = context_.lock();
36  if (!context || !encoder_) {
37  return;
38  }
39  ContextVK::Cast(*context).SetDebugName(encoder_->GetCommandBuffer(), label);
40  }
41 }
42 
43 bool CommandBufferVK::IsValid() const {
44  return true;
45 }
46 
47 const std::shared_ptr<CommandEncoderVK>& CommandBufferVK::GetEncoder() {
48  if (!encoder_) {
49  encoder_ = encoder_factory_->Create();
50  }
51  return encoder_;
52 }
53 
54 bool CommandBufferVK::OnSubmitCommands(CompletionCallback callback) {
55  if (!encoder_) {
56  encoder_ = encoder_factory_->Create();
57  }
58  if (!callback) {
59  return encoder_->Submit();
60  }
61  return encoder_->Submit([callback](bool submitted) {
62  callback(submitted ? CommandBuffer::Status::kCompleted
64  });
65 }
66 
67 void CommandBufferVK::OnWaitUntilScheduled() {}
68 
69 std::shared_ptr<RenderPass> CommandBufferVK::OnCreateRenderPass(
70  RenderTarget target) {
71  auto context = context_.lock();
72  if (!context) {
73  return nullptr;
74  }
75  auto pass =
76  std::shared_ptr<RenderPassVK>(new RenderPassVK(context, //
77  target, //
78  weak_from_this() //
79  ));
80  if (!pass->IsValid()) {
81  return nullptr;
82  }
83  return pass;
84 }
85 
86 std::shared_ptr<BlitPass> CommandBufferVK::OnCreateBlitPass() {
87  if (!IsValid()) {
88  return nullptr;
89  }
90  auto pass = std::shared_ptr<BlitPassVK>(new BlitPassVK(weak_from_this()));
91  if (!pass->IsValid()) {
92  return nullptr;
93  }
94  return pass;
95 }
96 
97 std::shared_ptr<ComputePass> CommandBufferVK::OnCreateComputePass() {
98  if (!IsValid()) {
99  return nullptr;
100  }
101  auto context = context_.lock();
102  if (!context) {
103  return nullptr;
104  }
105  auto pass =
106  std::shared_ptr<ComputePassVK>(new ComputePassVK(context, //
107  weak_from_this() //
108  ));
109  if (!pass->IsValid()) {
110  return nullptr;
111  }
112  return pass;
113 }
114 
115 } // namespace impeller
impeller::CommandBuffer::Status::kError
@ kError
impeller::CommandBufferVK::GetEncoder
const std::shared_ptr< CommandEncoderVK > & GetEncoder()
Definition: command_buffer_vk.cc:47
compute_pass_vk.h
command_encoder_vk.h
formats_vk.h
render_pass_vk.h
validation.h
command_buffer_vk.h
impeller::CommandBuffer::context_
std::weak_ptr< const Context > context_
Definition: command_buffer.h:130
impeller::CommandBufferVK::~CommandBufferVK
~CommandBufferVK() override
impeller::ContextVK::SetDebugName
bool SetDebugName(T handle, std::string_view label) const
Definition: context_vk.h:100
blit_pass_vk.h
command_buffer.h
std
Definition: comparable.h:95
impeller::CommandBuffer::Status::kCompleted
@ kCompleted
impeller::BackendCast< ContextVK, Context >::Cast
static ContextVK & Cast(Context &base)
Definition: backend_cast.h:15
render_target.h
context_vk.h
impeller
Definition: aiks_context.cc:10