Flutter Impeller
shared_object_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_SHARED_OBJECT_VK_H_
6 #define FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_SHARED_OBJECT_VK_H_
7 
8 #include <memory>
9 
11 
12 namespace impeller {
13 
15  public:
16  virtual ~SharedObjectVK() = default;
17 };
18 
19 template <class T>
21  public:
22  using Resource = T;
24  vk::UniqueHandle<Resource, VULKAN_HPP_DEFAULT_DISPATCHER_TYPE>;
25 
26  explicit SharedObjectVKT(UniqueResource res) : resource_(std::move(res)) {}
27 
28  // NOLINTNEXTLINE(google-explicit-constructor)
29  operator Resource() const { return Get(); }
30 
31  const Resource& Get() const { return *resource_; }
32 
33  const UniqueResource& GetUniqueWrapper() const { return resource_; }
34 
35  private:
36  UniqueResource resource_;
37 
38  SharedObjectVKT(const SharedObjectVKT&) = delete;
39 
40  SharedObjectVKT& operator=(const SharedObjectVKT&) = delete;
41 };
42 
43 template <class T>
45  vk::UniqueHandle<T, VULKAN_HPP_DEFAULT_DISPATCHER_TYPE> handle) {
46  if (!handle) {
47  return std::shared_ptr<SharedObjectVKT<T>>{nullptr};
48  }
49  return std::make_shared<SharedObjectVKT<T>>(std::move(handle));
50 }
51 
52 template <class T>
53 using SharedHandleVK = std::shared_ptr<SharedObjectVKT<T>>;
54 
55 } // namespace impeller
56 
57 #endif // FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_SHARED_OBJECT_VK_H_
virtual ~SharedObjectVK()=default
const UniqueResource & GetUniqueWrapper() const
const Resource & Get() const
vk::UniqueHandle< Resource, VULKAN_HPP_DEFAULT_DISPATCHER_TYPE > UniqueResource
SharedObjectVKT(UniqueResource res)
std::shared_ptr< SharedObjectVKT< T > > SharedHandleVK
auto MakeSharedVK(vk::UniqueHandle< T, VULKAN_HPP_DEFAULT_DISPATCHER_TYPE > handle)
Definition: comparable.h:95