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