Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
vulkan
procs
vulkan_handle.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_VULKAN_PROCS_VULKAN_HANDLE_H_
6
#define FLUTTER_VULKAN_PROCS_VULKAN_HANDLE_H_
7
8
#include <functional>
9
10
#include "flutter/fml/logging.h"
11
#include "flutter/fml/macros.h"
12
#include "flutter/vulkan/procs/vulkan_interface.h"
13
14
namespace
vulkan
{
15
16
template
<
class
T>
17
class
VulkanHandle
{
18
public
:
19
using
Handle
=
T
;
20
using
Disposer
= std::function<void(
Handle
)>;
21
22
VulkanHandle
() : handle_(
VK_NULL_HANDLE
) {}
23
24
explicit
VulkanHandle
(
Handle
handle,
const
Disposer
& disposer =
nullptr
)
25
: handle_(handle), disposer_(disposer) {}
26
27
VulkanHandle
(
VulkanHandle
&& other)
28
: handle_(other.handle_), disposer_(
std
::move(other.disposer_)) {
29
other.handle_ =
VK_NULL_HANDLE
;
30
other.disposer_ =
nullptr
;
31
}
32
33
~VulkanHandle
() { DisposeIfNecessary(); }
34
35
VulkanHandle
&
operator=
(
VulkanHandle
&& other) {
36
if
(handle_ != other.handle_) {
37
DisposeIfNecessary();
38
}
39
40
handle_ = other.handle_;
41
disposer_ = other.disposer_;
42
43
other.handle_ =
VK_NULL_HANDLE
;
44
other.disposer_ =
nullptr
;
45
46
return
*
this
;
47
}
48
49
explicit
operator
bool()
const
{
return
handle_ !=
VK_NULL_HANDLE
; }
50
51
// NOLINTNEXTLINE(google-explicit-constructor)
52
operator
Handle
()
const
{
return
handle_; }
53
54
/// Relinquish responsibility of collecting the underlying handle when this
55
/// object is collected. It is the responsibility of the caller to ensure that
56
/// the lifetime of the handle extends past the lifetime of this object.
57
void
ReleaseOwnership
() { disposer_ =
nullptr
; }
58
59
void
Reset
() { DisposeIfNecessary(); }
60
61
private
:
62
Handle
handle_;
63
Disposer
disposer_;
64
65
void
DisposeIfNecessary() {
66
if
(handle_ ==
VK_NULL_HANDLE
) {
67
return
;
68
}
69
if
(disposer_) {
70
disposer_(handle_);
71
}
72
handle_
=
VK_NULL_HANDLE
;
73
disposer_ =
nullptr
;
74
}
75
76
FML_DISALLOW_COPY_AND_ASSIGN
(
VulkanHandle
);
77
};
78
79
}
// namespace vulkan
80
81
#endif
// FLUTTER_VULKAN_PROCS_VULKAN_HANDLE_H_
vulkan::VulkanHandle
Definition
vulkan_handle.h:17
vulkan::VulkanHandle::~VulkanHandle
~VulkanHandle()
Definition
vulkan_handle.h:33
vulkan::VulkanHandle::VulkanHandle
VulkanHandle()
Definition
vulkan_handle.h:22
vulkan::VulkanHandle::ReleaseOwnership
void ReleaseOwnership()
Definition
vulkan_handle.h:57
vulkan::VulkanHandle::VulkanHandle
VulkanHandle(Handle handle, const Disposer &disposer=nullptr)
Definition
vulkan_handle.h:24
vulkan::VulkanHandle::Handle
T Handle
Definition
vulkan_handle.h:19
vulkan::VulkanHandle::Reset
void Reset()
Definition
vulkan_handle.h:59
vulkan::VulkanHandle::VulkanHandle
VulkanHandle(VulkanHandle &&other)
Definition
vulkan_handle.h:27
vulkan::VulkanHandle::operator=
VulkanHandle & operator=(VulkanHandle &&other)
Definition
vulkan_handle.h:35
vulkan::VulkanHandle::Disposer
std::function< void(Handle)> Disposer
Definition
vulkan_handle.h:20
FML_DISALLOW_COPY_AND_ASSIGN
#define FML_DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition
macros.h:27
std
Definition
ref_ptr.h:256
vulkan
Definition
vulkan_handle.cc:7
handle_
fuchsia::ui::composition::ParentViewportWatcherHandle handle_
Definition
platform_view_unittest.cc:330
T
#define T
Definition
precompiler.cc:65
VK_NULL_HANDLE
#define VK_NULL_HANDLE
Definition
vulkan_core.h:46
Generated on Fri Apr 26 2024 06:18:17 for Flutter Engine by
1.9.8