| 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
10 #include "impeller/renderer/backend/vulkan/vk.h"
11
12 namespace impeller {
13
14 class SharedObjectVK {
15 public:
16 virtual ~SharedObjectVK() = default;
17 };
18
19 template <class T>
20 class SharedObjectVKT : public SharedObjectVK {
21 public:
22 using Resource = T;
23 using UniqueResource =
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>
44 auto MakeSharedVK(
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_
impeller::SharedObjectVK
Definition: shared_object_vk.h:14
impeller::SharedObjectVK::~SharedObjectVK
virtual ~SharedObjectVK()=default
impeller::SharedObjectVKT
Definition: shared_object_vk.h:20
impeller::SharedObjectVKT::GetUniqueWrapper
const UniqueResource & GetUniqueWrapper() const
Definition: shared_object_vk.h:33
impeller::SharedObjectVKT::Get
const Resource & Get() const
Definition: shared_object_vk.h:31
impeller::SharedObjectVKT::UniqueResource
vk::UniqueHandle< Resource, VULKAN_HPP_DEFAULT_DISPATCHER_TYPE > UniqueResource
Definition: shared_object_vk.h:24
impeller::SharedObjectVKT::Resource
T Resource
Definition: shared_object_vk.h:22
impeller::SharedObjectVKT::SharedObjectVKT
SharedObjectVKT(UniqueResource res)
Definition: shared_object_vk.h:26
impeller
Definition: allocation.cc:12
impeller::SharedHandleVK
std::shared_ptr< SharedObjectVKT< T > > SharedHandleVK
Definition: shared_object_vk.h:53
impeller::MakeSharedVK
auto MakeSharedVK(vk::UniqueHandle< T, VULKAN_HPP_DEFAULT_DISPATCHER_TYPE > handle)
Definition: shared_object_vk.h:44
std
Definition: comparable.h:95
vk.h