| 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 <alpha-compositing-unstable-v1-server-protocol.h> |
| 8 #include <gaming-input-unstable-v1-server-protocol.h> |
| 7 #include <grp.h> | 9 #include <grp.h> |
| 10 #include <keyboard-configuration-unstable-v1-server-protocol.h> |
| 8 #include <linux/input.h> | 11 #include <linux/input.h> |
| 12 #include <presentation-time-server-protocol.h> |
| 13 #include <remote-shell-unstable-v1-server-protocol.h> |
| 14 #include <secure-output-unstable-v1-server-protocol.h> |
| 9 #include <stddef.h> | 15 #include <stddef.h> |
| 10 #include <stdint.h> | 16 #include <stdint.h> |
| 17 #include <stylus-unstable-v1-server-protocol.h> |
| 18 #include <stylus-unstable-v2-server-protocol.h> |
| 11 #include <viewporter-server-protocol.h> | 19 #include <viewporter-server-protocol.h> |
| 20 #include <vsync-feedback-unstable-v1-server-protocol.h> |
| 12 #include <wayland-server-core.h> | 21 #include <wayland-server-core.h> |
| 13 #include <wayland-server-protocol-core.h> | 22 #include <wayland-server-protocol-core.h> |
| 14 | 23 #include <xdg-shell-unstable-v5-server-protocol.h> |
| 15 // Note: core wayland headers need to be included before protocol headers. | |
| 16 #include <alpha-compositing-unstable-v1-server-protocol.h> // NOLINT | |
| 17 #include <keyboard-configuration-unstable-v1-server-protocol.h> // NOLINT | |
| 18 #include <gaming-input-unstable-v1-server-protocol.h> // NOLINT | |
| 19 #include <remote-shell-unstable-v1-server-protocol.h> // NOLINT | |
| 20 #include <secure-output-unstable-v1-server-protocol.h> // NOLINT | |
| 21 #include <stylus-unstable-v1-server-protocol.h> // NOLINT | |
| 22 #include <stylus-unstable-v2-server-protocol.h> // NOLINT | |
| 23 #include <vsync-feedback-unstable-v1-server-protocol.h> // NOLINT | |
| 24 #include <xdg-shell-unstable-v5-server-protocol.h> // NOLINT | |
| 25 | 24 |
| 26 #include <algorithm> | 25 #include <algorithm> |
| 27 #include <cstdlib> | 26 #include <cstdlib> |
| 28 #include <iterator> | 27 #include <iterator> |
| 29 #include <string> | 28 #include <string> |
| 30 #include <utility> | 29 #include <utility> |
| 31 | 30 |
| 32 #include "ash/common/shell_observer.h" | 31 #include "ash/common/shell_observer.h" |
| 33 #include "ash/public/cpp/shell_window_ids.h" | 32 #include "ash/public/cpp/shell_window_ids.h" |
| 34 #include "ash/shell.h" | 33 #include "ash/shell.h" |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 wl_resource_destroy(resource); | 215 wl_resource_destroy(resource); |
| 217 } | 216 } |
| 218 | 217 |
| 219 void surface_frame(wl_client* client, | 218 void surface_frame(wl_client* client, |
| 220 wl_resource* resource, | 219 wl_resource* resource, |
| 221 uint32_t callback) { | 220 uint32_t callback) { |
| 222 wl_resource* callback_resource = | 221 wl_resource* callback_resource = |
| 223 wl_resource_create(client, &wl_callback_interface, 1, callback); | 222 wl_resource_create(client, &wl_callback_interface, 1, callback); |
| 224 | 223 |
| 225 // base::Unretained is safe as the resource owns the callback. | 224 // base::Unretained is safe as the resource owns the callback. |
| 226 std::unique_ptr<base::CancelableCallback<void(base::TimeTicks)>> | 225 auto cancelable_callback = |
| 227 cancelable_callback( | 226 base::MakeUnique<base::CancelableCallback<void(base::TimeTicks)>>( |
| 228 new base::CancelableCallback<void(base::TimeTicks)>(base::Bind( | 227 base::Bind(&HandleSurfaceFrameCallback, |
| 229 &HandleSurfaceFrameCallback, base::Unretained(callback_resource)))); | 228 base::Unretained(callback_resource))); |
| 230 | 229 |
| 231 GetUserDataAs<Surface>(resource) | 230 GetUserDataAs<Surface>(resource) |
| 232 ->RequestFrameCallback(cancelable_callback->callback()); | 231 ->RequestFrameCallback(cancelable_callback->callback()); |
| 233 | 232 |
| 234 SetImplementation(callback_resource, nullptr, std::move(cancelable_callback)); | 233 SetImplementation(callback_resource, nullptr, std::move(cancelable_callback)); |
| 235 } | 234 } |
| 236 | 235 |
| 237 void surface_set_opaque_region(wl_client* client, | 236 void surface_set_opaque_region(wl_client* client, |
| 238 wl_resource* resource, | 237 wl_resource* resource, |
| 239 wl_resource* region_resource) { | 238 wl_resource* region_resource) { |
| (...skipping 2402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2642 uint32_t version, | 2641 uint32_t version, |
| 2643 uint32_t id) { | 2642 uint32_t id) { |
| 2644 wl_resource* resource = | 2643 wl_resource* resource = |
| 2645 wl_resource_create(client, &wp_viewporter_interface, 1, id); | 2644 wl_resource_create(client, &wp_viewporter_interface, 1, id); |
| 2646 | 2645 |
| 2647 wl_resource_set_implementation(resource, &viewporter_implementation, data, | 2646 wl_resource_set_implementation(resource, &viewporter_implementation, data, |
| 2648 nullptr); | 2647 nullptr); |
| 2649 } | 2648 } |
| 2650 | 2649 |
| 2651 //////////////////////////////////////////////////////////////////////////////// | 2650 //////////////////////////////////////////////////////////////////////////////// |
| 2651 // presentation_interface: |
| 2652 |
| 2653 void HandleSurfacePresentationCallback(wl_resource* resource, |
| 2654 base::TimeTicks presentation_time, |
| 2655 base::TimeDelta refresh) { |
| 2656 if (presentation_time.is_null()) { |
| 2657 wp_presentation_feedback_send_discarded(resource); |
| 2658 } else { |
| 2659 int64_t presentation_time_us = presentation_time.ToInternalValue(); |
| 2660 int64_t seconds = presentation_time_us / base::Time::kMicrosecondsPerSecond; |
| 2661 int64_t microseconds = |
| 2662 presentation_time_us % base::Time::kMicrosecondsPerSecond; |
| 2663 wp_presentation_feedback_send_presented( |
| 2664 resource, seconds >> 32, seconds & 0xffffffff, |
| 2665 microseconds * base::Time::kNanosecondsPerMicrosecond, |
| 2666 refresh.InMicroseconds() * base::Time::kNanosecondsPerMicrosecond, 0, 0, |
| 2667 WP_PRESENTATION_FEEDBACK_KIND_VSYNC | |
| 2668 WP_PRESENTATION_FEEDBACK_KIND_HW_CLOCK | |
| 2669 WP_PRESENTATION_FEEDBACK_KIND_HW_COMPLETION); |
| 2670 } |
| 2671 wl_client_flush(wl_resource_get_client(resource)); |
| 2672 } |
| 2673 |
| 2674 void presentation_destroy(wl_client* client, wl_resource* resource) { |
| 2675 wl_resource_destroy(resource); |
| 2676 } |
| 2677 |
| 2678 void presentation_feedback(wl_client* client, |
| 2679 wl_resource* resource, |
| 2680 wl_resource* surface_resource, |
| 2681 uint32_t id) { |
| 2682 wl_resource* presentation_feedback_resource = |
| 2683 wl_resource_create(client, &wp_presentation_feedback_interface, |
| 2684 wl_resource_get_version(resource), id); |
| 2685 |
| 2686 // base::Unretained is safe as the resource owns the callback. |
| 2687 auto cancelable_callback = base::MakeUnique< |
| 2688 base::CancelableCallback<void(base::TimeTicks, base::TimeDelta)>>( |
| 2689 base::Bind(&HandleSurfacePresentationCallback, |
| 2690 base::Unretained(presentation_feedback_resource))); |
| 2691 |
| 2692 GetUserDataAs<Surface>(surface_resource) |
| 2693 ->RequestPresentationCallback(cancelable_callback->callback()); |
| 2694 |
| 2695 SetImplementation(presentation_feedback_resource, nullptr, |
| 2696 std::move(cancelable_callback)); |
| 2697 } |
| 2698 |
| 2699 const struct wp_presentation_interface presentation_implementation = { |
| 2700 presentation_destroy, presentation_feedback}; |
| 2701 |
| 2702 void bind_presentation(wl_client* client, |
| 2703 void* data, |
| 2704 uint32_t version, |
| 2705 uint32_t id) { |
| 2706 wl_resource* resource = |
| 2707 wl_resource_create(client, &wp_presentation_interface, 1, id); |
| 2708 |
| 2709 wl_resource_set_implementation(resource, &presentation_implementation, data, |
| 2710 nullptr); |
| 2711 |
| 2712 wp_presentation_send_clock_id(resource, CLOCK_MONOTONIC); |
| 2713 } |
| 2714 |
| 2715 //////////////////////////////////////////////////////////////////////////////// |
| 2652 // security_interface: | 2716 // security_interface: |
| 2653 | 2717 |
| 2654 // Implements the security interface to a Surface. The "only visible on secure | 2718 // Implements the security interface to a Surface. The "only visible on secure |
| 2655 // output"-state is set to false upon destruction. A window property will be set | 2719 // output"-state is set to false upon destruction. A window property will be set |
| 2656 // during the lifetime of this class to prevent multiple instances from being | 2720 // during the lifetime of this class to prevent multiple instances from being |
| 2657 // created for the same Surface. | 2721 // created for the same Surface. |
| 2658 class Security : public SurfaceObserver { | 2722 class Security : public SurfaceObserver { |
| 2659 public: | 2723 public: |
| 2660 explicit Security(Surface* surface) : surface_(surface) { | 2724 explicit Security(Surface* surface) : surface_(surface) { |
| 2661 surface_->AddSurfaceObserver(this); | 2725 surface_->AddSurfaceObserver(this); |
| (...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3182 wl_global_create(wl_display_.get(), &xdg_shell_interface, 1, display_, | 3246 wl_global_create(wl_display_.get(), &xdg_shell_interface, 1, display_, |
| 3183 bind_xdg_shell); | 3247 bind_xdg_shell); |
| 3184 wl_global_create(wl_display_.get(), &zcr_vsync_feedback_v1_interface, 1, | 3248 wl_global_create(wl_display_.get(), &zcr_vsync_feedback_v1_interface, 1, |
| 3185 display_, bind_vsync_feedback); | 3249 display_, bind_vsync_feedback); |
| 3186 wl_global_create(wl_display_.get(), &wl_data_device_manager_interface, 1, | 3250 wl_global_create(wl_display_.get(), &wl_data_device_manager_interface, 1, |
| 3187 display_, bind_data_device_manager); | 3251 display_, bind_data_device_manager); |
| 3188 wl_global_create(wl_display_.get(), &wl_seat_interface, seat_version, | 3252 wl_global_create(wl_display_.get(), &wl_seat_interface, seat_version, |
| 3189 display_, bind_seat); | 3253 display_, bind_seat); |
| 3190 wl_global_create(wl_display_.get(), &wp_viewporter_interface, 1, display_, | 3254 wl_global_create(wl_display_.get(), &wp_viewporter_interface, 1, display_, |
| 3191 bind_viewporter); | 3255 bind_viewporter); |
| 3256 wl_global_create(wl_display_.get(), &wp_presentation_interface, 1, display_, |
| 3257 bind_presentation); |
| 3192 wl_global_create(wl_display_.get(), &zcr_secure_output_v1_interface, 1, | 3258 wl_global_create(wl_display_.get(), &zcr_secure_output_v1_interface, 1, |
| 3193 display_, bind_secure_output); | 3259 display_, bind_secure_output); |
| 3194 wl_global_create(wl_display_.get(), &zcr_alpha_compositing_v1_interface, 1, | 3260 wl_global_create(wl_display_.get(), &zcr_alpha_compositing_v1_interface, 1, |
| 3195 display_, bind_alpha_compositing); | 3261 display_, bind_alpha_compositing); |
| 3196 wl_global_create(wl_display_.get(), &zcr_remote_shell_v1_interface, | 3262 wl_global_create(wl_display_.get(), &zcr_remote_shell_v1_interface, |
| 3197 remote_shell_version, display_, bind_remote_shell); | 3263 remote_shell_version, display_, bind_remote_shell); |
| 3198 wl_global_create(wl_display_.get(), &zcr_gaming_input_v1_interface, 1, | 3264 wl_global_create(wl_display_.get(), &zcr_gaming_input_v1_interface, 1, |
| 3199 display_, bind_gaming_input); | 3265 display_, bind_gaming_input); |
| 3200 wl_global_create(wl_display_.get(), &zcr_stylus_v1_interface, 2, display_, | 3266 wl_global_create(wl_display_.get(), &zcr_stylus_v1_interface, 2, display_, |
| 3201 bind_stylus_v1_DEPRECATED); | 3267 bind_stylus_v1_DEPRECATED); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3267 DCHECK(event_loop); | 3333 DCHECK(event_loop); |
| 3268 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds()); | 3334 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds()); |
| 3269 } | 3335 } |
| 3270 | 3336 |
| 3271 void Server::Flush() { | 3337 void Server::Flush() { |
| 3272 wl_display_flush_clients(wl_display_.get()); | 3338 wl_display_flush_clients(wl_display_.get()); |
| 3273 } | 3339 } |
| 3274 | 3340 |
| 3275 } // namespace wayland | 3341 } // namespace wayland |
| 3276 } // namespace exo | 3342 } // namespace exo |
| OLD | NEW |