Chromium Code Reviews| 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 2607 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 microseconds = presentation_time.ToInternalValue(); | |
| 2660 int64_t seconds = 0; | |
| 2661 if (microseconds >= base::Time::kMicrosecondsPerSecond) { | |
|
Daniele Castagna
2017/01/09 17:01:33
Isn't this just:
seconds = presentation_time / bas
reveman
2017/01/09 17:55:15
Good call. Removed the branch.
| |
| 2662 seconds = microseconds / base::Time::kMicrosecondsPerSecond; | |
| 2663 microseconds -= seconds * base::Time::kMicrosecondsPerSecond; | |
| 2664 } | |
| 2665 wp_presentation_feedback_send_presented( | |
| 2666 resource, seconds >> 32, seconds & 0xffffffff, | |
| 2667 microseconds * base::Time::kNanosecondsPerMicrosecond, | |
| 2668 refresh.InMicroseconds() * base::Time::kNanosecondsPerMicrosecond, 0, 0, | |
| 2669 WP_PRESENTATION_FEEDBACK_KIND_VSYNC | | |
| 2670 WP_PRESENTATION_FEEDBACK_KIND_HW_CLOCK | | |
| 2671 WP_PRESENTATION_FEEDBACK_KIND_HW_COMPLETION); | |
| 2672 } | |
| 2673 wl_client_flush(wl_resource_get_client(resource)); | |
| 2674 } | |
| 2675 | |
| 2676 void presentation_destroy(wl_client* client, wl_resource* resource) { | |
| 2677 wl_resource_destroy(resource); | |
| 2678 } | |
| 2679 | |
| 2680 void presentation_feedback(wl_client* client, | |
| 2681 wl_resource* resource, | |
| 2682 wl_resource* surface_resource, | |
| 2683 uint32_t id) { | |
| 2684 wl_resource* presentation_feedback_resource = | |
| 2685 wl_resource_create(client, &wp_presentation_feedback_interface, | |
| 2686 wl_resource_get_version(resource), id); | |
| 2687 | |
| 2688 // base::Unretained is safe as the resource owns the callback. | |
| 2689 std::unique_ptr< | |
| 2690 base::CancelableCallback<void(base::TimeTicks, base::TimeDelta)>> | |
|
Daniele Castagna
2017/01/09 17:01:33
nit: auto cancelable_callback = make_unique... to
reveman
2017/01/09 17:55:15
Done.
| |
| 2691 cancelable_callback( | |
| 2692 new base::CancelableCallback<void(base::TimeTicks, base::TimeDelta)>( | |
| 2693 base::Bind(&HandleSurfacePresentationCallback, | |
| 2694 base::Unretained(presentation_feedback_resource)))); | |
| 2695 | |
| 2696 GetUserDataAs<Surface>(surface_resource) | |
| 2697 ->RequestPresentationCallback(cancelable_callback->callback()); | |
| 2698 | |
| 2699 SetImplementation(presentation_feedback_resource, nullptr, | |
| 2700 std::move(cancelable_callback)); | |
| 2701 } | |
| 2702 | |
| 2703 const struct wp_presentation_interface presentation_implementation = { | |
| 2704 presentation_destroy, presentation_feedback}; | |
| 2705 | |
| 2706 void bind_presentation(wl_client* client, | |
| 2707 void* data, | |
| 2708 uint32_t version, | |
| 2709 uint32_t id) { | |
| 2710 wl_resource* resource = | |
| 2711 wl_resource_create(client, &wp_presentation_interface, 1, id); | |
| 2712 | |
| 2713 wl_resource_set_implementation(resource, &presentation_implementation, data, | |
| 2714 nullptr); | |
| 2715 | |
| 2716 wp_presentation_send_clock_id(resource, CLOCK_MONOTONIC); | |
| 2717 } | |
| 2718 | |
| 2719 //////////////////////////////////////////////////////////////////////////////// | |
| 2652 // security_interface: | 2720 // security_interface: |
| 2653 | 2721 |
| 2654 // Implements the security interface to a Surface. The "only visible on secure | 2722 // 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 | 2723 // 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 | 2724 // during the lifetime of this class to prevent multiple instances from being |
| 2657 // created for the same Surface. | 2725 // created for the same Surface. |
| 2658 class Security : public SurfaceObserver { | 2726 class Security : public SurfaceObserver { |
| 2659 public: | 2727 public: |
| 2660 explicit Security(Surface* surface) : surface_(surface) { | 2728 explicit Security(Surface* surface) : surface_(surface) { |
| 2661 surface_->AddSurfaceObserver(this); | 2729 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_, | 3250 wl_global_create(wl_display_.get(), &xdg_shell_interface, 1, display_, |
| 3183 bind_xdg_shell); | 3251 bind_xdg_shell); |
| 3184 wl_global_create(wl_display_.get(), &zcr_vsync_feedback_v1_interface, 1, | 3252 wl_global_create(wl_display_.get(), &zcr_vsync_feedback_v1_interface, 1, |
| 3185 display_, bind_vsync_feedback); | 3253 display_, bind_vsync_feedback); |
| 3186 wl_global_create(wl_display_.get(), &wl_data_device_manager_interface, 1, | 3254 wl_global_create(wl_display_.get(), &wl_data_device_manager_interface, 1, |
| 3187 display_, bind_data_device_manager); | 3255 display_, bind_data_device_manager); |
| 3188 wl_global_create(wl_display_.get(), &wl_seat_interface, seat_version, | 3256 wl_global_create(wl_display_.get(), &wl_seat_interface, seat_version, |
| 3189 display_, bind_seat); | 3257 display_, bind_seat); |
| 3190 wl_global_create(wl_display_.get(), &wp_viewporter_interface, 1, display_, | 3258 wl_global_create(wl_display_.get(), &wp_viewporter_interface, 1, display_, |
| 3191 bind_viewporter); | 3259 bind_viewporter); |
| 3260 wl_global_create(wl_display_.get(), &wp_presentation_interface, 1, display_, | |
| 3261 bind_presentation); | |
| 3192 wl_global_create(wl_display_.get(), &zcr_secure_output_v1_interface, 1, | 3262 wl_global_create(wl_display_.get(), &zcr_secure_output_v1_interface, 1, |
| 3193 display_, bind_secure_output); | 3263 display_, bind_secure_output); |
| 3194 wl_global_create(wl_display_.get(), &zcr_alpha_compositing_v1_interface, 1, | 3264 wl_global_create(wl_display_.get(), &zcr_alpha_compositing_v1_interface, 1, |
| 3195 display_, bind_alpha_compositing); | 3265 display_, bind_alpha_compositing); |
| 3196 wl_global_create(wl_display_.get(), &zcr_remote_shell_v1_interface, | 3266 wl_global_create(wl_display_.get(), &zcr_remote_shell_v1_interface, |
| 3197 remote_shell_version, display_, bind_remote_shell); | 3267 remote_shell_version, display_, bind_remote_shell); |
| 3198 wl_global_create(wl_display_.get(), &zcr_gaming_input_v1_interface, 1, | 3268 wl_global_create(wl_display_.get(), &zcr_gaming_input_v1_interface, 1, |
| 3199 display_, bind_gaming_input); | 3269 display_, bind_gaming_input); |
| 3200 wl_global_create(wl_display_.get(), &zcr_stylus_v1_interface, 2, display_, | 3270 wl_global_create(wl_display_.get(), &zcr_stylus_v1_interface, 2, display_, |
| 3201 bind_stylus_v1_DEPRECATED); | 3271 bind_stylus_v1_DEPRECATED); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3267 DCHECK(event_loop); | 3337 DCHECK(event_loop); |
| 3268 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds()); | 3338 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds()); |
| 3269 } | 3339 } |
| 3270 | 3340 |
| 3271 void Server::Flush() { | 3341 void Server::Flush() { |
| 3272 wl_display_flush_clients(wl_display_.get()); | 3342 wl_display_flush_clients(wl_display_.get()); |
| 3273 } | 3343 } |
| 3274 | 3344 |
| 3275 } // namespace wayland | 3345 } // namespace wayland |
| 3276 } // namespace exo | 3346 } // namespace exo |
| OLD | NEW |