Flutter Impeller
fence_waiter_vk.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_BACKEND_VULKAN_FENCE_WAITER_VK_H_
6 #define FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_FENCE_WAITER_VK_H_
7 
8 #include <condition_variable>
9 #include <functional>
10 #include <memory>
11 #include <thread>
12 #include <vector>
13 
14 #include "flutter/fml/closure.h"
15 #include "flutter/fml/status.h"
17 
18 namespace impeller {
19 
20 class ContextVK;
21 class WaitSetEntry;
22 
23 using WaitSet = std::vector<std::shared_ptr<WaitSetEntry>>;
24 
26  public:
28 
29  bool IsValid() const;
30 
31  void Terminate();
32 
33  /// @brief Invokes the [submit_callback] synchronously and adds the fence to
34  /// the wait set if it succeeds. The [completion_callback] will be
35  /// called when the submitted command completes and the fence is
36  /// signaled.
37  fml::Status AddFence(
38  vk::UniqueFence fence,
39  const std::function<fml::Status(vk::Fence)>& submit_callback,
40  fml::closure completion_callback);
41 
42  private:
43  friend class ContextVK;
44 
45  std::weak_ptr<DeviceHolderVK> device_holder_;
46  std::unique_ptr<std::thread> waiter_thread_;
47  std::mutex wait_set_mutex_;
48  std::condition_variable wait_set_cv_;
49  WaitSet wait_set_;
50  bool terminate_ = false;
51 
52  explicit FenceWaiterVK(std::weak_ptr<DeviceHolderVK> device_holder);
53 
54  void Main();
55 
56  bool Wait();
57  void WaitUntilEmpty();
58 
59  FenceWaiterVK(const FenceWaiterVK&) = delete;
60 
61  FenceWaiterVK& operator=(const FenceWaiterVK&) = delete;
62 };
63 
64 } // namespace impeller
65 
66 #endif // FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_FENCE_WAITER_VK_H_
fml::Status AddFence(vk::UniqueFence fence, const std::function< fml::Status(vk::Fence)> &submit_callback, fml::closure completion_callback)
Invokes the [submit_callback] synchronously and adds the fence to the wait set if it succeeds....
bool Main(const fml::CommandLine &command_line)
std::vector< std::shared_ptr< WaitSetEntry > > WaitSet