OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 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 UI_OZONE_PLATFORM_WAYLAND_WAYLAND_OBJECT_H_ | |
6 #define UI_OZONE_PLATFORM_WAYLAND_WAYLAND_OBJECT_H_ | |
7 | |
8 #include <wayland-client.h> | |
9 #include <xdg-shell-unstable-v5-client-protocol.h> | |
10 | |
11 #include "base/memory/scoped_ptr.h" | |
12 | |
13 namespace wl { | |
14 | |
15 template <typename T> | |
16 struct ObjectTraits; | |
17 | |
18 #define DEFINE_TRAITS_WITH_DELETER(name, deleter_fn) \ | |
Michael Forney
2016/01/21 22:11:48
If this is not acceptable, I can either expand the
spang
2016/01/22 23:42:32
I'd prefer the macros expanded because token pasti
Michael Forney
2016/01/23 01:08:05
Done.
| |
19 template <> \ | |
20 struct ObjectTraits<name> { \ | |
21 static constexpr const wl_interface* interface = &name##_interface; \ | |
22 static constexpr void (*deleter)(name*) = &deleter_fn; \ | |
23 } | |
24 | |
25 #define DEFINE_TRAITS(name) DEFINE_TRAITS_WITH_DELETER(name, name##_destroy) | |
26 | |
27 DEFINE_TRAITS(wl_buffer); | |
28 DEFINE_TRAITS(wl_compositor); | |
29 DEFINE_TRAITS(wl_registry); | |
30 DEFINE_TRAITS(wl_seat); | |
31 DEFINE_TRAITS(wl_shell); | |
32 DEFINE_TRAITS(wl_shm); | |
33 DEFINE_TRAITS(wl_shm_pool); | |
34 DEFINE_TRAITS(wl_surface); | |
35 DEFINE_TRAITS(xdg_shell); | |
36 DEFINE_TRAITS(xdg_surface); | |
37 | |
38 DEFINE_TRAITS_WITH_DELETER(wl_display, wl_display_disconnect); | |
39 DEFINE_TRAITS_WITH_DELETER(wl_keyboard, wl_keyboard_release); | |
40 DEFINE_TRAITS_WITH_DELETER(wl_pointer, wl_pointer_release); | |
41 | |
42 #undef DEFINE_TRAITS | |
43 #undef DEFINE_TRAITS_WITH_DELETER | |
44 | |
45 struct Deleter { | |
46 template <typename T> | |
47 void operator()(T* obj) { | |
48 ObjectTraits<T>::deleter(obj); | |
49 } | |
50 }; | |
51 | |
52 template <typename T> | |
53 class Object : public scoped_ptr<T, Deleter> { | |
54 public: | |
55 Object() {} | |
56 explicit Object(T* obj) : scoped_ptr<T, Deleter>(obj) {} | |
57 | |
58 uint32_t id() { | |
59 return wl_proxy_get_id( | |
60 reinterpret_cast<wl_proxy*>(scoped_ptr<T, Deleter>::get())); | |
61 } | |
62 }; | |
63 | |
64 template <typename T> | |
65 wl::Object<T> Bind(wl_registry* registry, uint32_t name, uint32_t version) { | |
66 return wl::Object<T>(static_cast<T*>( | |
67 wl_registry_bind(registry, name, ObjectTraits<T>::interface, version))); | |
68 } | |
69 | |
70 } // namespace wl | |
71 | |
72 #endif // UI_OZONE_PLATFORM_WAYLAND_WAYLAND_OBJECT_H_ | |
OLD | NEW |