1 // Copyright 2017 The Chromium 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 COMPONENTS_EXO_WAYLAND_CLIENTS_CLIENT_HELPER_H_
6 #define COMPONENTS_EXO_WAYLAND_CLIENTS_CLIENT_HELPER_H_
7 
8 #include <aura-shell-client-protocol.h>
9 #include <color-space-unstable-v1-client-protocol.h>
10 #include <fullscreen-shell-unstable-v1-client-protocol.h>
11 #include <input-timestamps-unstable-v1-client-protocol.h>
12 #include <linux-dmabuf-unstable-v1-client-protocol.h>
13 #include <linux-explicit-synchronization-unstable-v1-client-protocol.h>
14 #include <presentation-time-client-protocol.h>
15 #include <vsync-feedback-unstable-v1-client-protocol.h>
16 #include <wayland-client-core.h>
17 #include <wayland-client-protocol.h>
18 
19 #include <memory>
20 
21 #include "base/scoped_generic.h"
22 
23 #if defined(USE_GBM)
24 #include <gbm.h>
25 #if defined(USE_VULKAN)
26 #include <vulkan/vulkan.h>
27 #endif  // defined(USE_GBM)
28 #endif  // defined(USE_VULKAN)
29 
30 // Default deleters template specialization forward decl.
31 #define DEFAULT_DELETER_FDECL(TypeName) \
32   namespace std {                       \
33   template <>                           \
34   struct default_delete<TypeName> {     \
35     void operator()(TypeName* ptr);     \
36   };                                    \
37   }
38 
39 DEFAULT_DELETER_FDECL(wl_buffer)
DEFAULT_DELETER_FDECL(wl_callback)40 DEFAULT_DELETER_FDECL(wl_callback)
41 DEFAULT_DELETER_FDECL(wl_compositor)
42 DEFAULT_DELETER_FDECL(wl_display)
43 DEFAULT_DELETER_FDECL(wl_pointer)
44 DEFAULT_DELETER_FDECL(wl_region)
45 DEFAULT_DELETER_FDECL(wl_registry)
46 DEFAULT_DELETER_FDECL(wl_seat)
47 DEFAULT_DELETER_FDECL(wl_shell)
48 DEFAULT_DELETER_FDECL(wl_shell_surface)
49 DEFAULT_DELETER_FDECL(wl_shm)
50 DEFAULT_DELETER_FDECL(wl_shm_pool)
51 DEFAULT_DELETER_FDECL(wl_subcompositor)
52 DEFAULT_DELETER_FDECL(wl_subsurface)
53 DEFAULT_DELETER_FDECL(wl_surface)
54 DEFAULT_DELETER_FDECL(wl_touch)
55 DEFAULT_DELETER_FDECL(wl_output)
56 DEFAULT_DELETER_FDECL(wp_presentation)
57 DEFAULT_DELETER_FDECL(struct wp_presentation_feedback)
58 DEFAULT_DELETER_FDECL(zaura_shell)
59 DEFAULT_DELETER_FDECL(zaura_surface)
60 DEFAULT_DELETER_FDECL(zaura_output)
61 DEFAULT_DELETER_FDECL(zwp_linux_buffer_release_v1)
62 DEFAULT_DELETER_FDECL(zwp_fullscreen_shell_v1)
63 DEFAULT_DELETER_FDECL(zwp_input_timestamps_manager_v1)
64 DEFAULT_DELETER_FDECL(zwp_input_timestamps_v1)
65 DEFAULT_DELETER_FDECL(zwp_linux_buffer_params_v1)
66 DEFAULT_DELETER_FDECL(zwp_linux_dmabuf_v1)
67 DEFAULT_DELETER_FDECL(zwp_linux_explicit_synchronization_v1)
68 DEFAULT_DELETER_FDECL(zwp_linux_surface_synchronization_v1)
69 DEFAULT_DELETER_FDECL(zcr_color_space_v1)
70 DEFAULT_DELETER_FDECL(zcr_vsync_feedback_v1)
71 DEFAULT_DELETER_FDECL(zcr_vsync_timing_v1)
72 
73 #if defined(USE_GBM)
74 DEFAULT_DELETER_FDECL(gbm_bo)
75 DEFAULT_DELETER_FDECL(gbm_device)
76 #endif
77 
78 namespace exo {
79 namespace wayland {
80 namespace clients {
81 
82 #if defined(USE_GBM)
83 struct DeleteTextureTraits {
84   static unsigned InvalidValue();
85   static void Free(unsigned texture);
86 };
87 using ScopedTexture = base::ScopedGeneric<unsigned, DeleteTextureTraits>;
88 
89 struct DeleteEglImageTraits {
90   static void* InvalidValue();
91   static void Free(void* image);
92 };
93 using ScopedEglImage = base::ScopedGeneric<void*, DeleteEglImageTraits>;
94 
95 struct DeleteEglSyncTraits {
96   static void* InvalidValue();
97   static void Free(void* sync);
98 };
99 using ScopedEglSync = base::ScopedGeneric<void*, DeleteEglSyncTraits>;
100 
101 #if defined(USE_VULKAN)
102 struct DeleteVkInstanceTraits {
103   static VkInstance InvalidValue();
104   static void Free(VkInstance instance);
105 };
106 using ScopedVkInstance =
107     base::ScopedGeneric<VkInstance, DeleteVkInstanceTraits>;
108 
109 struct DeleteVkDeviceTraits {
110   static VkDevice InvalidValue();
111   static void Free(VkDevice device);
112 };
113 using ScopedVkDevice = base::ScopedGeneric<VkDevice, DeleteVkDeviceTraits>;
114 
115 struct DeleteVkCommandPoolTraits {
116   VkDevice vk_device;
117   static VkCommandPool InvalidValue();
118   void Free(VkCommandPool command_pool);
119 };
120 using ScopedVkCommandPool =
121     base::ScopedGeneric<VkCommandPool, DeleteVkCommandPoolTraits>;
122 
123 struct DeleteVkRenderPassTraits {
124   VkDevice vk_device;
125   static VkRenderPass InvalidValue();
126   void Free(VkRenderPass render_pass);
127 };
128 using ScopedVkRenderPass =
129     base::ScopedGeneric<VkRenderPass, DeleteVkRenderPassTraits>;
130 
131 struct DeleteVkDeviceMemoryTraits {
132   VkDevice vk_device;
133   static VkDeviceMemory InvalidValue();
134   void Free(VkDeviceMemory device_memory);
135 };
136 using ScopedVkDeviceMemory =
137     base::ScopedGeneric<VkDeviceMemory, DeleteVkDeviceMemoryTraits>;
138 
139 struct DeleteVkImageTraits {
140   VkDevice vk_device;
141   static VkImage InvalidValue();
142   void Free(VkImage image);
143 };
144 using ScopedVkImage = base::ScopedGeneric<VkImage, DeleteVkImageTraits>;
145 
146 struct DeleteVkImageViewTraits {
147   VkDevice vk_device;
148   static VkImageView InvalidValue();
149   void Free(VkImageView image_view);
150 };
151 using ScopedVkImageView =
152     base::ScopedGeneric<VkImageView, DeleteVkImageViewTraits>;
153 
154 struct DeleteVkFramebufferTraits {
155   VkDevice vk_device;
156   static VkFramebuffer InvalidValue();
157   void Free(VkFramebuffer framebuffer);
158 };
159 using ScopedVkFramebuffer =
160     base::ScopedGeneric<VkFramebuffer, DeleteVkFramebufferTraits>;
161 
162 #endif  // defined(USE_VULKAN)
163 #endif  // defined(USE_GBM)
164 
165 }  // namespace clients
166 }  // namespace wayland
167 }  // namespace exo
168 
169 #endif  // COMPONENTS_EXO_WAYLAND_CLIENTS_CLIENT_HELPER_H_
170