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 template <> |
| 19 struct ObjectTraits<wl_buffer> { |
| 20 static constexpr const wl_interface* interface = &wl_buffer_interface; |
| 21 static constexpr void (*deleter)(wl_buffer*) = &wl_buffer_destroy; |
| 22 }; |
| 23 |
| 24 template <> |
| 25 struct ObjectTraits<wl_compositor> { |
| 26 static constexpr const wl_interface* interface = &wl_compositor_interface; |
| 27 static constexpr void (*deleter)(wl_compositor*) = &wl_compositor_destroy; |
| 28 }; |
| 29 |
| 30 template <> |
| 31 struct ObjectTraits<wl_display> { |
| 32 static constexpr const wl_interface* interface = &wl_display_interface; |
| 33 static constexpr void (*deleter)(wl_display*) = &wl_display_disconnect; |
| 34 }; |
| 35 |
| 36 template <> |
| 37 struct ObjectTraits<wl_registry> { |
| 38 static constexpr const wl_interface* interface = &wl_registry_interface; |
| 39 static constexpr void (*deleter)(wl_registry*) = &wl_registry_destroy; |
| 40 }; |
| 41 |
| 42 template <> |
| 43 struct ObjectTraits<wl_shm> { |
| 44 static constexpr const wl_interface* interface = &wl_shm_interface; |
| 45 static constexpr void (*deleter)(wl_shm*) = &wl_shm_destroy; |
| 46 }; |
| 47 |
| 48 template <> |
| 49 struct ObjectTraits<wl_shm_pool> { |
| 50 static constexpr const wl_interface* interface = &wl_shm_pool_interface; |
| 51 static constexpr void (*deleter)(wl_shm_pool*) = &wl_shm_pool_destroy; |
| 52 }; |
| 53 |
| 54 template <> |
| 55 struct ObjectTraits<wl_surface> { |
| 56 static constexpr const wl_interface* interface = &wl_surface_interface; |
| 57 static constexpr void (*deleter)(wl_surface*) = &wl_surface_destroy; |
| 58 }; |
| 59 |
| 60 template <> |
| 61 struct ObjectTraits<xdg_shell> { |
| 62 static constexpr const wl_interface* interface = &xdg_shell_interface; |
| 63 static constexpr void (*deleter)(xdg_shell*) = &xdg_shell_destroy; |
| 64 }; |
| 65 |
| 66 template <> |
| 67 struct ObjectTraits<xdg_surface> { |
| 68 static constexpr const wl_interface* interface = &xdg_surface_interface; |
| 69 static constexpr void (*deleter)(xdg_surface*) = &xdg_surface_destroy; |
| 70 }; |
| 71 |
| 72 struct Deleter { |
| 73 template <typename T> |
| 74 void operator()(T* obj) { |
| 75 ObjectTraits<T>::deleter(obj); |
| 76 } |
| 77 }; |
| 78 |
| 79 template <typename T> |
| 80 class Object : public scoped_ptr<T, Deleter> { |
| 81 public: |
| 82 Object() {} |
| 83 explicit Object(T* obj) : scoped_ptr<T, Deleter>(obj) {} |
| 84 |
| 85 uint32_t id() { |
| 86 return wl_proxy_get_id( |
| 87 reinterpret_cast<wl_proxy*>(scoped_ptr<T, Deleter>::get())); |
| 88 } |
| 89 }; |
| 90 |
| 91 template <typename T> |
| 92 wl::Object<T> Bind(wl_registry* registry, uint32_t name, uint32_t version) { |
| 93 return wl::Object<T>(static_cast<T*>( |
| 94 wl_registry_bind(registry, name, ObjectTraits<T>::interface, version))); |
| 95 } |
| 96 |
| 97 } // namespace wl |
| 98 |
| 99 #endif // UI_OZONE_PLATFORM_WAYLAND_WAYLAND_OBJECT_H_ |
OLD | NEW |