| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/exo/wayland/server.h" | 5 #include "components/exo/wayland/server.h" |
| 6 | 6 |
| 7 #include <grp.h> | 7 #include <grp.h> |
| 8 #include <linux/input.h> | 8 #include <linux/input.h> |
| 9 #include <stddef.h> | 9 #include <stddef.h> |
| 10 #include <stdint.h> | 10 #include <stdint.h> |
| 11 #include <viewporter-server-protocol.h> | 11 #include <viewporter-server-protocol.h> |
| 12 #include <wayland-server-core.h> | 12 #include <wayland-server-core.h> |
| 13 #include <wayland-server-protocol-core.h> | 13 #include <wayland-server-protocol-core.h> |
| 14 | 14 |
| 15 // Note: core wayland headers need to be included before protocol headers. | 15 // Note: core wayland headers need to be included before protocol headers. |
| 16 #include <alpha-compositing-unstable-v1-server-protocol.h> // NOLINT | 16 #include <alpha-compositing-unstable-v1-server-protocol.h> // NOLINT |
| 17 #include <gaming-input-unstable-v1-server-protocol.h> // NOLINT |
| 17 #include <remote-shell-unstable-v1-server-protocol.h> // NOLINT | 18 #include <remote-shell-unstable-v1-server-protocol.h> // NOLINT |
| 18 #include <secure-output-unstable-v1-server-protocol.h> // NOLINT | 19 #include <secure-output-unstable-v1-server-protocol.h> // NOLINT |
| 19 #include <xdg-shell-unstable-v5-server-protocol.h> // NOLINT | 20 #include <xdg-shell-unstable-v5-server-protocol.h> // NOLINT |
| 20 #include <vsync-feedback-unstable-v1-server-protocol.h> // NOLINT | 21 #include <vsync-feedback-unstable-v1-server-protocol.h> // NOLINT |
| 21 | 22 |
| 22 #include <algorithm> | 23 #include <algorithm> |
| 23 #include <cstdlib> | 24 #include <cstdlib> |
| 24 #include <iterator> | 25 #include <iterator> |
| 25 #include <string> | 26 #include <string> |
| 26 #include <utility> | 27 #include <utility> |
| 27 | 28 |
| 28 #include "ash/common/display/display_info.h" | 29 #include "ash/common/display/display_info.h" |
| 29 #include "ash/common/shell_observer.h" | 30 #include "ash/common/shell_observer.h" |
| 30 #include "ash/common/shell_window_ids.h" | 31 #include "ash/common/shell_window_ids.h" |
| 31 #include "ash/common/wm_shell.h" | 32 #include "ash/common/wm_shell.h" |
| 32 #include "ash/display/display_manager.h" | 33 #include "ash/display/display_manager.h" |
| 33 #include "ash/shell.h" | 34 #include "ash/shell.h" |
| 34 #include "base/bind.h" | 35 #include "base/bind.h" |
| 35 #include "base/cancelable_callback.h" | 36 #include "base/cancelable_callback.h" |
| 36 #include "base/files/file_path.h" | 37 #include "base/files/file_path.h" |
| 37 #include "base/macros.h" | 38 #include "base/macros.h" |
| 38 #include "base/memory/free_deleter.h" | 39 #include "base/memory/free_deleter.h" |
| 39 #include "base/memory/ptr_util.h" | 40 #include "base/memory/ptr_util.h" |
| 40 #include "base/memory/weak_ptr.h" | 41 #include "base/memory/weak_ptr.h" |
| 41 #include "base/strings/stringprintf.h" | 42 #include "base/strings/stringprintf.h" |
| 42 #include "base/strings/utf_string_conversions.h" | 43 #include "base/strings/utf_string_conversions.h" |
| 44 #include "base/threading/thread.h" |
| 43 #include "base/threading/thread_task_runner_handle.h" | 45 #include "base/threading/thread_task_runner_handle.h" |
| 44 #include "components/exo/buffer.h" | 46 #include "components/exo/buffer.h" |
| 45 #include "components/exo/display.h" | 47 #include "components/exo/display.h" |
| 48 #include "components/exo/gamepad.h" |
| 49 #include "components/exo/gamepad_delegate.h" |
| 46 #include "components/exo/keyboard.h" | 50 #include "components/exo/keyboard.h" |
| 47 #include "components/exo/keyboard_delegate.h" | 51 #include "components/exo/keyboard_delegate.h" |
| 48 #include "components/exo/notification_surface.h" | 52 #include "components/exo/notification_surface.h" |
| 49 #include "components/exo/notification_surface_manager.h" | 53 #include "components/exo/notification_surface_manager.h" |
| 50 #include "components/exo/pointer.h" | 54 #include "components/exo/pointer.h" |
| 51 #include "components/exo/pointer_delegate.h" | 55 #include "components/exo/pointer_delegate.h" |
| 52 #include "components/exo/shared_memory.h" | 56 #include "components/exo/shared_memory.h" |
| 53 #include "components/exo/shell_surface.h" | 57 #include "components/exo/shell_surface.h" |
| 54 #include "components/exo/sub_surface.h" | 58 #include "components/exo/sub_surface.h" |
| 55 #include "components/exo/surface.h" | 59 #include "components/exo/surface.h" |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 DestroyUserData<T>); | 128 DestroyUserData<T>); |
| 125 } | 129 } |
| 126 | 130 |
| 127 // Convert a timestamp to a time value that can be used when interfacing | 131 // Convert a timestamp to a time value that can be used when interfacing |
| 128 // with wayland. Note that we cast a int64_t value to uint32_t which can | 132 // with wayland. Note that we cast a int64_t value to uint32_t which can |
| 129 // potentially overflow. | 133 // potentially overflow. |
| 130 uint32_t TimeTicksToMilliseconds(base::TimeTicks ticks) { | 134 uint32_t TimeTicksToMilliseconds(base::TimeTicks ticks) { |
| 131 return (ticks - base::TimeTicks()).InMilliseconds(); | 135 return (ticks - base::TimeTicks()).InMilliseconds(); |
| 132 } | 136 } |
| 133 | 137 |
| 138 uint32_t NowInMilliseconds() { |
| 139 return TimeTicksToMilliseconds(base::TimeTicks::Now()); |
| 140 } |
| 141 |
| 134 // A property key containing the surface resource that is associated with | 142 // A property key containing the surface resource that is associated with |
| 135 // window. If unset, no surface resource is associated with window. | 143 // window. If unset, no surface resource is associated with window. |
| 136 DEFINE_SURFACE_PROPERTY_KEY(wl_resource*, kSurfaceResourceKey, nullptr); | 144 DEFINE_SURFACE_PROPERTY_KEY(wl_resource*, kSurfaceResourceKey, nullptr); |
| 137 | 145 |
| 138 // A property key containing a boolean set to true if a viewport is associated | 146 // A property key containing a boolean set to true if a viewport is associated |
| 139 // with window. | 147 // with window. |
| 140 DEFINE_SURFACE_PROPERTY_KEY(bool, kSurfaceHasViewportKey, false); | 148 DEFINE_SURFACE_PROPERTY_KEY(bool, kSurfaceHasViewportKey, false); |
| 141 | 149 |
| 142 // A property key containing a boolean set to true if a security object is | 150 // A property key containing a boolean set to true if a security object is |
| 143 // associated with window. | 151 // associated with window. |
| (...skipping 2644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2788 void* data, | 2796 void* data, |
| 2789 uint32_t version, | 2797 uint32_t version, |
| 2790 uint32_t id) { | 2798 uint32_t id) { |
| 2791 wl_resource* resource = | 2799 wl_resource* resource = |
| 2792 wl_resource_create(client, &zwp_alpha_compositing_v1_interface, 1, id); | 2800 wl_resource_create(client, &zwp_alpha_compositing_v1_interface, 1, id); |
| 2793 | 2801 |
| 2794 wl_resource_set_implementation(resource, &alpha_compositing_implementation, | 2802 wl_resource_set_implementation(resource, &alpha_compositing_implementation, |
| 2795 data, nullptr); | 2803 data, nullptr); |
| 2796 } | 2804 } |
| 2797 | 2805 |
| 2806 //////////////////////////////////////////////////////////////////////////////// |
| 2807 // gaming_input_interface: |
| 2808 |
| 2809 // Gamepad delegate class that forwards gamepad events to the client resource. |
| 2810 class WaylandGamepadDelegate : public GamepadDelegate { |
| 2811 public: |
| 2812 explicit WaylandGamepadDelegate(wl_resource* gamepad_resource) |
| 2813 : gamepad_resource_(gamepad_resource) {} |
| 2814 |
| 2815 // Overridden from GamepadDelegate: |
| 2816 void OnGamepadDestroying(Gamepad* gamepad) override { delete this; } |
| 2817 bool CanAcceptGamepadEventsForSurface(Surface* surface) const override { |
| 2818 wl_resource* surface_resource = GetSurfaceResource(surface); |
| 2819 return surface_resource && |
| 2820 wl_resource_get_client(surface_resource) == client(); |
| 2821 } |
| 2822 void OnStateChange(bool connected) override { |
| 2823 uint32_t status = connected ? ZWP_GAMEPAD_V1_GAMEPAD_STATE_ON |
| 2824 : ZWP_GAMEPAD_V1_GAMEPAD_STATE_OFF; |
| 2825 zwp_gamepad_v1_send_state_change(gamepad_resource_, status); |
| 2826 wl_client_flush(client()); |
| 2827 } |
| 2828 void OnAxis(int axis, double value) override { |
| 2829 zwp_gamepad_v1_send_axis(gamepad_resource_, NowInMilliseconds(), axis, |
| 2830 wl_fixed_from_double(value)); |
| 2831 } |
| 2832 void OnButton(int button, bool pressed, double value) override { |
| 2833 uint32_t state = pressed ? ZWP_GAMEPAD_V1_BUTTON_STATE_PRESSED |
| 2834 : ZWP_GAMEPAD_V1_BUTTON_STATE_RELEASED; |
| 2835 zwp_gamepad_v1_send_button(gamepad_resource_, NowInMilliseconds(), button, |
| 2836 state, wl_fixed_from_double(value)); |
| 2837 } |
| 2838 void OnFrame() override { |
| 2839 zwp_gamepad_v1_send_frame(gamepad_resource_, NowInMilliseconds()); |
| 2840 wl_client_flush(client()); |
| 2841 } |
| 2842 |
| 2843 private: |
| 2844 // The client who own this gamepad instance. |
| 2845 wl_client* client() const { |
| 2846 return wl_resource_get_client(gamepad_resource_); |
| 2847 } |
| 2848 |
| 2849 // The gamepad resource associated with the gamepad. |
| 2850 wl_resource* const gamepad_resource_; |
| 2851 |
| 2852 DISALLOW_COPY_AND_ASSIGN(WaylandGamepadDelegate); |
| 2853 }; |
| 2854 |
| 2855 void gamepad_destroy(wl_client* client, wl_resource* resource) { |
| 2856 wl_resource_destroy(resource); |
| 2857 } |
| 2858 |
| 2859 const struct zwp_gamepad_v1_interface gamepad_implementation = { |
| 2860 gamepad_destroy}; |
| 2861 |
| 2862 void gaming_input_get_gamepad(wl_client* client, |
| 2863 wl_resource* resource, |
| 2864 uint32_t id, |
| 2865 wl_resource* seat) { |
| 2866 wl_resource* gamepad_resource = wl_resource_create( |
| 2867 client, &zwp_gamepad_v1_interface, wl_resource_get_version(resource), id); |
| 2868 |
| 2869 base::Thread* gaming_input_thread = GetUserDataAs<base::Thread>(resource); |
| 2870 |
| 2871 SetImplementation( |
| 2872 gamepad_resource, &gamepad_implementation, |
| 2873 base::WrapUnique(new Gamepad(new WaylandGamepadDelegate(gamepad_resource), |
| 2874 gaming_input_thread->task_runner().get()))); |
| 2875 } |
| 2876 |
| 2877 const struct zwp_gaming_input_v1_interface gaming_input_implementation = { |
| 2878 gaming_input_get_gamepad}; |
| 2879 |
| 2880 void bind_gaming_input(wl_client* client, |
| 2881 void* data, |
| 2882 uint32_t version, |
| 2883 uint32_t id) { |
| 2884 wl_resource* resource = |
| 2885 wl_resource_create(client, &zwp_gaming_input_v1_interface, version, id); |
| 2886 |
| 2887 std::unique_ptr<base::Thread> gaming_input_thread( |
| 2888 new base::Thread("Exo gaming input polling thread.")); |
| 2889 gaming_input_thread->StartWithOptions( |
| 2890 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)); |
| 2891 |
| 2892 SetImplementation(resource, &gaming_input_implementation, |
| 2893 std::move(gaming_input_thread)); |
| 2894 } |
| 2895 |
| 2798 } // namespace | 2896 } // namespace |
| 2799 | 2897 |
| 2800 //////////////////////////////////////////////////////////////////////////////// | 2898 //////////////////////////////////////////////////////////////////////////////// |
| 2801 // Server, public: | 2899 // Server, public: |
| 2802 | 2900 |
| 2803 Server::Server(Display* display) | 2901 Server::Server(Display* display) |
| 2804 : display_(display), wl_display_(wl_display_create()) { | 2902 : display_(display), wl_display_(wl_display_create()) { |
| 2805 wl_global_create(wl_display_.get(), &wl_compositor_interface, | 2903 wl_global_create(wl_display_.get(), &wl_compositor_interface, |
| 2806 compositor_version, display_, bind_compositor); | 2904 compositor_version, display_, bind_compositor); |
| 2807 wl_global_create(wl_display_.get(), &wl_shm_interface, 1, display_, bind_shm); | 2905 wl_global_create(wl_display_.get(), &wl_shm_interface, 1, display_, bind_shm); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 2826 wl_global_create(wl_display_.get(), &wl_seat_interface, seat_version, | 2924 wl_global_create(wl_display_.get(), &wl_seat_interface, seat_version, |
| 2827 display_, bind_seat); | 2925 display_, bind_seat); |
| 2828 wl_global_create(wl_display_.get(), &wp_viewporter_interface, 1, display_, | 2926 wl_global_create(wl_display_.get(), &wp_viewporter_interface, 1, display_, |
| 2829 bind_viewporter); | 2927 bind_viewporter); |
| 2830 wl_global_create(wl_display_.get(), &zwp_secure_output_v1_interface, 1, | 2928 wl_global_create(wl_display_.get(), &zwp_secure_output_v1_interface, 1, |
| 2831 display_, bind_secure_output); | 2929 display_, bind_secure_output); |
| 2832 wl_global_create(wl_display_.get(), &zwp_alpha_compositing_v1_interface, 1, | 2930 wl_global_create(wl_display_.get(), &zwp_alpha_compositing_v1_interface, 1, |
| 2833 display_, bind_alpha_compositing); | 2931 display_, bind_alpha_compositing); |
| 2834 wl_global_create(wl_display_.get(), &zwp_remote_shell_v1_interface, | 2932 wl_global_create(wl_display_.get(), &zwp_remote_shell_v1_interface, |
| 2835 remote_shell_version, display_, bind_remote_shell); | 2933 remote_shell_version, display_, bind_remote_shell); |
| 2934 wl_global_create(wl_display_.get(), &zwp_gaming_input_v1_interface, 1, |
| 2935 display_, bind_gaming_input); |
| 2836 } | 2936 } |
| 2837 | 2937 |
| 2838 Server::~Server() {} | 2938 Server::~Server() {} |
| 2839 | 2939 |
| 2840 // static | 2940 // static |
| 2841 std::unique_ptr<Server> Server::Create(Display* display) { | 2941 std::unique_ptr<Server> Server::Create(Display* display) { |
| 2842 std::unique_ptr<Server> server(new Server(display)); | 2942 std::unique_ptr<Server> server(new Server(display)); |
| 2843 | 2943 |
| 2844 char* runtime_dir = getenv("XDG_RUNTIME_DIR"); | 2944 char* runtime_dir = getenv("XDG_RUNTIME_DIR"); |
| 2845 if (!runtime_dir) { | 2945 if (!runtime_dir) { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2897 DCHECK(event_loop); | 2997 DCHECK(event_loop); |
| 2898 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds()); | 2998 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds()); |
| 2899 } | 2999 } |
| 2900 | 3000 |
| 2901 void Server::Flush() { | 3001 void Server::Flush() { |
| 2902 wl_display_flush_clients(wl_display_.get()); | 3002 wl_display_flush_clients(wl_display_.get()); |
| 2903 } | 3003 } |
| 2904 | 3004 |
| 2905 } // namespace wayland | 3005 } // namespace wayland |
| 2906 } // namespace exo | 3006 } // namespace exo |
| OLD | NEW |