Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(333)

Side by Side Diff: components/exo/wayland/server.cc

Issue 2404513002: exo: Implement zcr_linux_explicit_synchronization_v1
Patch Set: rebase, address review comments Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <linux-explicit-synchronization-unstable-v1-server-protocol.h> // NOL INT
17 #include <gaming-input-unstable-v1-server-protocol.h> // NOLINT 18 #include <gaming-input-unstable-v1-server-protocol.h> // NOLINT
18 #include <remote-shell-unstable-v1-server-protocol.h> // NOLINT 19 #include <remote-shell-unstable-v1-server-protocol.h> // NOLINT
19 #include <secure-output-unstable-v1-server-protocol.h> // NOLINT 20 #include <secure-output-unstable-v1-server-protocol.h> // NOLINT
20 #include <stylus-unstable-v1-server-protocol.h> // NOLINT 21 #include <stylus-unstable-v1-server-protocol.h> // NOLINT
21 #include <xdg-shell-unstable-v5-server-protocol.h> // NOLINT 22 #include <xdg-shell-unstable-v5-server-protocol.h> // NOLINT
22 #include <vsync-feedback-unstable-v1-server-protocol.h> // NOLINT 23 #include <vsync-feedback-unstable-v1-server-protocol.h> // NOLINT
23 24
24 #include <algorithm> 25 #include <algorithm>
25 #include <cstdlib> 26 #include <cstdlib>
26 #include <iterator> 27 #include <iterator>
(...skipping 26 matching lines...) Expand all
53 #include "components/exo/pointer_delegate.h" 54 #include "components/exo/pointer_delegate.h"
54 #include "components/exo/pointer_stylus_delegate.h" 55 #include "components/exo/pointer_stylus_delegate.h"
55 #include "components/exo/shared_memory.h" 56 #include "components/exo/shared_memory.h"
56 #include "components/exo/shell_surface.h" 57 #include "components/exo/shell_surface.h"
57 #include "components/exo/sub_surface.h" 58 #include "components/exo/sub_surface.h"
58 #include "components/exo/surface.h" 59 #include "components/exo/surface.h"
59 #include "components/exo/surface_property.h" 60 #include "components/exo/surface_property.h"
60 #include "components/exo/touch.h" 61 #include "components/exo/touch.h"
61 #include "components/exo/touch_delegate.h" 62 #include "components/exo/touch_delegate.h"
62 #include "components/exo/wm_helper.h" 63 #include "components/exo/wm_helper.h"
64 #include "gpu/command_buffer/client/gpu_memory_buffer_manager.h"
63 #include "ipc/unix_domain_socket_util.h" 65 #include "ipc/unix_domain_socket_util.h"
64 #include "third_party/skia/include/core/SkRegion.h" 66 #include "third_party/skia/include/core/SkRegion.h"
67 #include "ui/aura/env.h"
65 #include "ui/aura/window_property.h" 68 #include "ui/aura/window_property.h"
66 #include "ui/base/hit_test.h" 69 #include "ui/base/hit_test.h"
67 #include "ui/compositor/compositor_vsync_manager.h" 70 #include "ui/compositor/compositor_vsync_manager.h"
68 #include "ui/display/display_observer.h" 71 #include "ui/display/display_observer.h"
69 #include "ui/display/manager/managed_display_info.h" 72 #include "ui/display/manager/managed_display_info.h"
70 #include "ui/display/screen.h" 73 #include "ui/display/screen.h"
71 #include "ui/events/keycodes/dom/keycode_converter.h" 74 #include "ui/events/keycodes/dom/keycode_converter.h"
72 #include "ui/gfx/buffer_format_util.h" 75 #include "ui/gfx/buffer_format_util.h"
73 #include "ui/gfx/buffer_types.h" 76 #include "ui/gfx/buffer_types.h"
74 #include "ui/views/widget/widget.h" 77 #include "ui/views/widget/widget.h"
(...skipping 15 matching lines...) Expand all
90 93
91 namespace exo { 94 namespace exo {
92 namespace wayland { 95 namespace wayland {
93 namespace { 96 namespace {
94 97
95 // We don't send configure immediately after tablet mode switch 98 // We don't send configure immediately after tablet mode switch
96 // because layout can change due to orientation lock state or accelerometer. 99 // because layout can change due to orientation lock state or accelerometer.
97 const int kConfigureDelayAfterLayoutSwitchMs = 300; 100 const int kConfigureDelayAfterLayoutSwitchMs = 300;
98 101
99 // Default wayland socket name. 102 // Default wayland socket name.
100 const base::FilePath::CharType kSocketName[] = FILE_PATH_LITERAL("wayland-0"); 103 const base::FilePath::CharType kSocketName[] = FILE_PATH_LITERAL("exosphere-0");
fooishbar 2016/10/12 15:50:51 Sorry, this still crept in from git-cl having squa
reveman 2016/10/12 19:20:20 No problem. If you can remove it when you have a c
101 104
102 // Group used for wayland socket. 105 // Group used for wayland socket.
103 const char kWaylandSocketGroup[] = "wayland"; 106 const char kWaylandSocketGroup[] = "wayland";
104 107
105 template <class T> 108 template <class T>
106 T* GetUserDataAs(wl_resource* resource) { 109 T* GetUserDataAs(wl_resource* resource) {
107 return static_cast<T*>(wl_resource_get_user_data(resource)); 110 return static_cast<T*>(wl_resource_get_user_data(resource));
108 } 111 }
109 112
110 template <class T> 113 template <class T>
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 DEFINE_SURFACE_PROPERTY_KEY(bool, kSurfaceHasViewportKey, false); 150 DEFINE_SURFACE_PROPERTY_KEY(bool, kSurfaceHasViewportKey, false);
148 151
149 // A property key containing a boolean set to true if a security object is 152 // A property key containing a boolean set to true if a security object is
150 // associated with window. 153 // associated with window.
151 DEFINE_SURFACE_PROPERTY_KEY(bool, kSurfaceHasSecurityKey, false); 154 DEFINE_SURFACE_PROPERTY_KEY(bool, kSurfaceHasSecurityKey, false);
152 155
153 // A property key containing a boolean set to true if a blending object is 156 // A property key containing a boolean set to true if a blending object is
154 // associated with window. 157 // associated with window.
155 DEFINE_SURFACE_PROPERTY_KEY(bool, kSurfaceHasBlendingKey, false); 158 DEFINE_SURFACE_PROPERTY_KEY(bool, kSurfaceHasBlendingKey, false);
156 159
160 #if defined(USE_OZONE)
161 // A property key containing a boolean set to true if a blending object is
162 // associated with window.
163 DEFINE_SURFACE_PROPERTY_KEY(bool, kSurfaceHasSynchronizationKey, false);
164 #endif
165
157 wl_resource* GetSurfaceResource(Surface* surface) { 166 wl_resource* GetSurfaceResource(Surface* surface) {
158 return surface->GetProperty(kSurfaceResourceKey); 167 return surface->GetProperty(kSurfaceResourceKey);
159 } 168 }
160 169
161 //////////////////////////////////////////////////////////////////////////////// 170 ////////////////////////////////////////////////////////////////////////////////
162 // wl_buffer_interface: 171 // wl_buffer_interface:
163 172
164 void buffer_destroy(wl_client* client, wl_resource* resource) { 173 void buffer_destroy(wl_client* client, wl_resource* resource) {
165 wl_resource_destroy(resource); 174 wl_resource_destroy(resource);
166 } 175 }
(...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after
755 wl_resource* resource = 764 wl_resource* resource =
756 wl_resource_create(client, &zwp_linux_dmabuf_v1_interface, 1, id); 765 wl_resource_create(client, &zwp_linux_dmabuf_v1_interface, 1, id);
757 766
758 wl_resource_set_implementation(resource, &linux_dmabuf_implementation, data, 767 wl_resource_set_implementation(resource, &linux_dmabuf_implementation, data,
759 nullptr); 768 nullptr);
760 769
761 for (const auto& supported_format : dmabuf_supported_formats) 770 for (const auto& supported_format : dmabuf_supported_formats)
762 zwp_linux_dmabuf_v1_send_format(resource, supported_format.dmabuf_format); 771 zwp_linux_dmabuf_v1_send_format(resource, supported_format.dmabuf_format);
763 } 772 }
764 773
774 ////////////////////////////////////////////////////////////////////////////////
775 // synchronization interface:
776
777 class Synchronization : public SurfaceObserver {
reveman 2016/10/12 19:20:20 nit: add the following comment above this class:
778 public:
779 explicit Synchronization(Display* display, Surface* surface) :
780 surface_(surface),
781 display_(display) {
782 surface_->AddSurfaceObserver(this);
783 surface_->SetProperty(kSurfaceHasSynchronizationKey, true);
784 }
785 ~Synchronization() override {
786 if (surface_) {
787 surface_->RemoveSurfaceObserver(this);
788 surface_->SetProperty(kSurfaceHasSynchronizationKey, true);
reveman 2016/10/12 19:20:20 s/true/false/ here
789 }
790 }
791
792 bool SetAcquireFence(int fd_raw) {
reveman 2016/10/12 19:20:20 nit: s/int fd_raw/base::ScopedFD fd/ as it's best
793 std::unique_ptr<gfx::GpuFence> fence;
reveman 2016/10/12 19:20:20 nit: move down where it's first used
794 base::ScopedFD fd(fd_raw);
795
796 fence = display_->CreateLinuxFence(fd);
797 if (!fence)
798 return false;
799
800 surface_->SetAcquireFence(std::move(fence));
801 return true;
802 }
803
804 void OnSurfaceDestroying(Surface* surface) override {
805 surface->RemoveSurfaceObserver(this);
806 surface_ = nullptr;
807 }
808
809 private:
810 Surface* surface_;
811 Display* display_;
812
813 DISALLOW_COPY_AND_ASSIGN(Synchronization);
814 };
815
816 void synchronization_destroy(wl_client* client, wl_resource* resource) {
817 wl_resource_destroy(resource);
818 }
819
820 void synchronization_set_acquire_fence(wl_client* client, wl_resource* resource,
821 int fd_raw) {
reveman 2016/10/12 19:20:20 nit: s/int fd_raw/int32_t fd/
822 Synchronization* synchronization = GetUserDataAs<Synchronization>(resource);
823
824 if (!synchronization->SetAcquireFence(fd_raw)) {
reveman 2016/10/12 19:20:20 s/fd_raw/base::ScopedFD(fd)/
825 wl_resource_post_error(resource,
826 ZCR_SYNCHRONIZATION_V1_ERROR_INVALID_FENCE,
827 "fence creation failed");
828 }
829 }
830
831 const struct zcr_synchronization_v1_interface
832 synchronization_implementation = {
833 synchronization_destroy,
834 synchronization_set_acquire_fence};
835
836
837 ////////////////////////////////////////////////////////////////////////////////
838 // linux_explicit_synchronization interface:
839
840 void linux_explicit_synchronization_destroy(wl_client* client,
841 wl_resource* resource) {
842 wl_resource_destroy(resource);
843 }
844
845 void linux_explicit_synchronization_get_surface(wl_client* client,
846 wl_resource* resource,
847 uint32_t id,
848 wl_resource* surface_resource) {
849 Display* display = GetUserDataAs<Display>(resource);
850 Surface* surface = GetUserDataAs<Surface>(surface_resource);
851
852 if (surface->GetProperty(kSurfaceHasSynchronizationKey)) {
853 wl_resource_post_error(resource,
854 ZCR_LINUX_EXPLICIT_SYNCHRONIZATION_V1_ERROR_SYNCHRONI ZATION_EXISTS,
855 "a synchronization object for that surface already ex ists");
856 return;
857 }
858
859 wl_resource* synchronization_resource =
860 wl_resource_create(client, &zcr_synchronization_v1_interface, 1, id);
861
862 SetImplementation(synchronization_resource, &synchronization_implementation,
863 base::MakeUnique<Synchronization>(display, surface));
864 }
865
866 const struct zcr_linux_explicit_synchronization_v1_interface
867 linux_explicit_synchronization_implementation = {
868 linux_explicit_synchronization_destroy,
869 linux_explicit_synchronization_get_surface};
870
871 void bind_linux_explicit_synchronization(wl_client* client, void* data,
872 uint32_t version, uint32_t id) {
873 wl_resource* resource =
874 wl_resource_create(client,
875 &zcr_linux_explicit_synchronization_v1_interface,
876 1,
877 id);
878 wl_resource_set_implementation(resource,
879 &linux_explicit_synchronization_implementation,
880 data,
881 nullptr);
882 }
765 #endif 883 #endif
766 884
767 //////////////////////////////////////////////////////////////////////////////// 885 ////////////////////////////////////////////////////////////////////////////////
768 // wl_subsurface_interface: 886 // wl_subsurface_interface:
769 887
770 void subsurface_destroy(wl_client* client, wl_resource* resource) { 888 void subsurface_destroy(wl_client* client, wl_resource* resource) {
771 wl_resource_destroy(resource); 889 wl_resource_destroy(resource);
772 } 890 }
773 891
774 void subsurface_set_position(wl_client* client, 892 void subsurface_set_position(wl_client* client,
(...skipping 2184 matching lines...) Expand 10 before | Expand all | Expand 10 after
2959 const struct zcr_stylus_v1_interface stylus_implementation = { 3077 const struct zcr_stylus_v1_interface stylus_implementation = {
2960 stylus_get_pointer_stylus}; 3078 stylus_get_pointer_stylus};
2961 3079
2962 void bind_stylus(wl_client* client, void* data, uint32_t version, uint32_t id) { 3080 void bind_stylus(wl_client* client, void* data, uint32_t version, uint32_t id) {
2963 wl_resource* resource = 3081 wl_resource* resource =
2964 wl_resource_create(client, &zcr_stylus_v1_interface, version, id); 3082 wl_resource_create(client, &zcr_stylus_v1_interface, version, id);
2965 wl_resource_set_implementation(resource, &stylus_implementation, data, 3083 wl_resource_set_implementation(resource, &stylus_implementation, data,
2966 nullptr); 3084 nullptr);
2967 } 3085 }
2968 3086
3087
reveman 2016/10/12 19:20:20 nit: no need for this blank line
2969 } // namespace 3088 } // namespace
2970 3089
2971 //////////////////////////////////////////////////////////////////////////////// 3090 ////////////////////////////////////////////////////////////////////////////////
2972 // Server, public: 3091 // Server, public:
2973 3092
2974 Server::Server(Display* display) 3093 Server::Server(Display* display)
2975 : display_(display), wl_display_(wl_display_create()) { 3094 : display_(display), wl_display_(wl_display_create()) {
2976 wl_global_create(wl_display_.get(), &wl_compositor_interface, 3095 wl_global_create(wl_display_.get(), &wl_compositor_interface,
2977 compositor_version, display_, bind_compositor); 3096 compositor_version, display_, bind_compositor);
2978 wl_global_create(wl_display_.get(), &wl_shm_interface, 1, display_, bind_shm); 3097 wl_global_create(wl_display_.get(), &wl_shm_interface, 1, display_, bind_shm);
2979 #if defined(USE_OZONE) 3098 #if defined(USE_OZONE)
2980 wl_global_create(wl_display_.get(), &wl_drm_interface, drm_version, display_, 3099 wl_global_create(wl_display_.get(), &wl_drm_interface, drm_version, display_,
2981 bind_drm); 3100 bind_drm);
2982 wl_global_create(wl_display_.get(), &zwp_linux_dmabuf_v1_interface, 1, 3101 wl_global_create(wl_display_.get(), &zwp_linux_dmabuf_v1_interface, 1,
2983 display_, bind_linux_dmabuf); 3102 display_, bind_linux_dmabuf);
3103 wl_global_create(wl_display_.get(),
3104 &zcr_linux_explicit_synchronization_v1_interface, 1, display_ ,
3105 bind_linux_explicit_synchronization);
2984 #endif 3106 #endif
2985 wl_global_create(wl_display_.get(), &wl_subcompositor_interface, 1, display_, 3107 wl_global_create(wl_display_.get(), &wl_subcompositor_interface, 1, display_,
2986 bind_subcompositor); 3108 bind_subcompositor);
2987 wl_global_create(wl_display_.get(), &wl_shell_interface, 1, display_, 3109 wl_global_create(wl_display_.get(), &wl_shell_interface, 1, display_,
2988 bind_shell); 3110 bind_shell);
2989 wl_global_create(wl_display_.get(), &wl_output_interface, output_version, 3111 wl_global_create(wl_display_.get(), &wl_output_interface, output_version,
2990 display_, bind_output); 3112 display_, bind_output);
2991 wl_global_create(wl_display_.get(), &xdg_shell_interface, 1, display_, 3113 wl_global_create(wl_display_.get(), &xdg_shell_interface, 1, display_,
2992 bind_xdg_shell); 3114 bind_xdg_shell);
2993 wl_global_create(wl_display_.get(), &zcr_vsync_feedback_v1_interface, 1, 3115 wl_global_create(wl_display_.get(), &zcr_vsync_feedback_v1_interface, 1,
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
3072 DCHECK(event_loop); 3194 DCHECK(event_loop);
3073 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds()); 3195 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds());
3074 } 3196 }
3075 3197
3076 void Server::Flush() { 3198 void Server::Flush() {
3077 wl_display_flush_clients(wl_display_.get()); 3199 wl_display_flush_clients(wl_display_.get());
3078 } 3200 }
3079 3201
3080 } // namespace wayland 3202 } // namespace wayland
3081 } // namespace exo 3203 } // namespace exo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698