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

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

Issue 2452523002: exo: Add zcr_linux_explicit_synchronization_v1
Patch Set: Created 4 years, 1 month 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
« no previous file with comments | « components/exo/wayland/BUILD.gn ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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> // NOLI NT
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 <vsync-feedback-unstable-v1-server-protocol.h> // NOLINT 22 #include <vsync-feedback-unstable-v1-server-protocol.h> // NOLINT
22 #include <xdg-shell-unstable-v5-server-protocol.h> // NOLINT 23 #include <xdg-shell-unstable-v5-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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 #include "third_party/skia/include/core/SkRegion.h" 65 #include "third_party/skia/include/core/SkRegion.h"
65 #include "ui/aura/window_property.h" 66 #include "ui/aura/window_property.h"
66 #include "ui/base/hit_test.h" 67 #include "ui/base/hit_test.h"
67 #include "ui/compositor/compositor_vsync_manager.h" 68 #include "ui/compositor/compositor_vsync_manager.h"
68 #include "ui/display/display_observer.h" 69 #include "ui/display/display_observer.h"
69 #include "ui/display/manager/managed_display_info.h" 70 #include "ui/display/manager/managed_display_info.h"
70 #include "ui/display/screen.h" 71 #include "ui/display/screen.h"
71 #include "ui/events/keycodes/dom/keycode_converter.h" 72 #include "ui/events/keycodes/dom/keycode_converter.h"
72 #include "ui/gfx/buffer_format_util.h" 73 #include "ui/gfx/buffer_format_util.h"
73 #include "ui/gfx/buffer_types.h" 74 #include "ui/gfx/buffer_types.h"
75 #include "ui/gfx/gpu_fence.h"
74 #include "ui/views/widget/widget.h" 76 #include "ui/views/widget/widget.h"
75 #include "ui/views/widget/widget_observer.h" 77 #include "ui/views/widget/widget_observer.h"
76 78
77 #if defined(USE_OZONE) 79 #if defined(USE_OZONE)
78 #include <drm_fourcc.h> 80 #include <drm_fourcc.h>
79 #include <linux-dmabuf-unstable-v1-server-protocol.h> 81 #include <linux-dmabuf-unstable-v1-server-protocol.h>
80 #include <wayland-drm-server-protocol.h> 82 #include <wayland-drm-server-protocol.h>
81 #endif 83 #endif
82 84
83 #if defined(USE_XKBCOMMON) 85 #if defined(USE_XKBCOMMON)
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 DEFINE_SURFACE_PROPERTY_KEY(bool, kSurfaceHasViewportKey, false); 149 DEFINE_SURFACE_PROPERTY_KEY(bool, kSurfaceHasViewportKey, false);
148 150
149 // A property key containing a boolean set to true if a security object is 151 // A property key containing a boolean set to true if a security object is
150 // associated with window. 152 // associated with window.
151 DEFINE_SURFACE_PROPERTY_KEY(bool, kSurfaceHasSecurityKey, false); 153 DEFINE_SURFACE_PROPERTY_KEY(bool, kSurfaceHasSecurityKey, false);
152 154
153 // A property key containing a boolean set to true if a blending object is 155 // A property key containing a boolean set to true if a blending object is
154 // associated with window. 156 // associated with window.
155 DEFINE_SURFACE_PROPERTY_KEY(bool, kSurfaceHasBlendingKey, false); 157 DEFINE_SURFACE_PROPERTY_KEY(bool, kSurfaceHasBlendingKey, false);
156 158
159 #if defined(USE_OZONE)
160 // A property key containing a boolean set to true if a blending object is
161 // associated with window.
162 DEFINE_SURFACE_PROPERTY_KEY(bool, kSurfaceHasSynchronizationKey, false);
163 #endif
164
157 wl_resource* GetSurfaceResource(Surface* surface) { 165 wl_resource* GetSurfaceResource(Surface* surface) {
158 return surface->GetProperty(kSurfaceResourceKey); 166 return surface->GetProperty(kSurfaceResourceKey);
159 } 167 }
160 168
161 //////////////////////////////////////////////////////////////////////////////// 169 ////////////////////////////////////////////////////////////////////////////////
162 // wl_buffer_interface: 170 // wl_buffer_interface:
163 171
164 void buffer_destroy(wl_client* client, wl_resource* resource) { 172 void buffer_destroy(wl_client* client, wl_resource* resource) {
165 wl_resource_destroy(resource); 173 wl_resource_destroy(resource);
166 } 174 }
(...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after
755 wl_resource* resource = 763 wl_resource* resource =
756 wl_resource_create(client, &zwp_linux_dmabuf_v1_interface, 1, id); 764 wl_resource_create(client, &zwp_linux_dmabuf_v1_interface, 1, id);
757 765
758 wl_resource_set_implementation(resource, &linux_dmabuf_implementation, data, 766 wl_resource_set_implementation(resource, &linux_dmabuf_implementation, data,
759 nullptr); 767 nullptr);
760 768
761 for (const auto& supported_format : dmabuf_supported_formats) 769 for (const auto& supported_format : dmabuf_supported_formats)
762 zwp_linux_dmabuf_v1_send_format(resource, supported_format.dmabuf_format); 770 zwp_linux_dmabuf_v1_send_format(resource, supported_format.dmabuf_format);
763 } 771 }
764 772
773 ////////////////////////////////////////////////////////////////////////////////
774 // synchronization interface:
775
776 // Implements the synchronization interface to a Surface. A window property
777 // will be set during the lifetime of this class to prevent multiple instances
778 // from being created for the same Surface.
779 class Synchronization : public SurfaceObserver {
780 public:
781 explicit Synchronization(Display* display, Surface* surface)
782 : surface_(surface), display_(display) {
783 surface_->AddSurfaceObserver(this);
784 surface_->SetProperty(kSurfaceHasSynchronizationKey, true);
785 }
786 ~Synchronization() override {
787 if (surface_) {
788 surface_->RemoveSurfaceObserver(this);
789 surface_->SetProperty(kSurfaceHasSynchronizationKey, false);
790 }
791 }
792
793 bool SetAcquireFence(base::ScopedFD fd) {
794 std::unique_ptr<gfx::GpuFence> fence =
795 display_->CreateLinuxFence(std::move(fd));
796 if (!fence)
797 return false;
798
799 surface_->SetAcquireFence(std::move(fence));
800 return true;
801 }
802
803 void OnSurfaceDestroying(Surface* surface) override {
804 surface->RemoveSurfaceObserver(this);
805 surface_ = nullptr;
806 }
807
808 private:
809 Surface* surface_;
810 Display* display_;
811
812 DISALLOW_COPY_AND_ASSIGN(Synchronization);
813 };
814
815 void synchronization_destroy(wl_client* client, wl_resource* resource) {
816 wl_resource_destroy(resource);
817 }
818
819 void synchronization_set_acquire_fence(wl_client* client,
820 wl_resource* resource,
821 int32_t fd) {
822 Synchronization* synchronization = GetUserDataAs<Synchronization>(resource);
823
824 if (!synchronization->SetAcquireFence(base::ScopedFD(fd))) {
825 wl_resource_post_error(resource, ZCR_SYNCHRONIZATION_V1_ERROR_INVALID_FENCE,
826 "fence creation failed");
827 }
828 }
829
830 const struct zcr_synchronization_v1_interface synchronization_implementation = {
831 synchronization_destroy, synchronization_set_acquire_fence};
832
833 ////////////////////////////////////////////////////////////////////////////////
834 // linux_explicit_synchronization interface:
835
836 void linux_explicit_synchronization_destroy(wl_client* client,
837 wl_resource* resource) {
838 wl_resource_destroy(resource);
839 }
840
841 void linux_explicit_synchronization_get_surface(wl_client* client,
842 wl_resource* resource,
843 uint32_t id,
844 wl_resource* surface_resource) {
845 Display* display = GetUserDataAs<Display>(resource);
846 Surface* surface = GetUserDataAs<Surface>(surface_resource);
847
848 if (surface->GetProperty(kSurfaceHasSynchronizationKey)) {
849 wl_resource_post_error(
850 resource,
851 ZCR_LINUX_EXPLICIT_SYNCHRONIZATION_V1_ERROR_SYNCHRONIZATION_EXISTS,
852 "a synchronization object for that surface already exists");
853 return;
854 }
855
856 wl_resource* synchronization_resource =
857 wl_resource_create(client, &zcr_synchronization_v1_interface, 1, id);
858
859 SetImplementation(synchronization_resource, &synchronization_implementation,
860 base::MakeUnique<Synchronization>(display, surface));
861 }
862
863 const struct zcr_linux_explicit_synchronization_v1_interface
864 linux_explicit_synchronization_implementation = {
865 linux_explicit_synchronization_destroy,
866 linux_explicit_synchronization_get_surface};
867
868 void bind_linux_explicit_synchronization(wl_client* client,
869 void* data,
870 uint32_t version,
871 uint32_t id) {
872 wl_resource* resource = wl_resource_create(
873 client, &zcr_linux_explicit_synchronization_v1_interface, 1, id);
874 wl_resource_set_implementation(
875 resource, &linux_explicit_synchronization_implementation, data, nullptr);
876 }
765 #endif 877 #endif
766 878
767 //////////////////////////////////////////////////////////////////////////////// 879 ////////////////////////////////////////////////////////////////////////////////
768 // wl_subsurface_interface: 880 // wl_subsurface_interface:
769 881
770 void subsurface_destroy(wl_client* client, wl_resource* resource) { 882 void subsurface_destroy(wl_client* client, wl_resource* resource) {
771 wl_resource_destroy(resource); 883 wl_resource_destroy(resource);
772 } 884 }
773 885
774 void subsurface_set_position(wl_client* client, 886 void subsurface_set_position(wl_client* client,
(...skipping 2199 matching lines...) Expand 10 before | Expand all | Expand 10 after
2974 Server::Server(Display* display) 3086 Server::Server(Display* display)
2975 : display_(display), wl_display_(wl_display_create()) { 3087 : display_(display), wl_display_(wl_display_create()) {
2976 wl_global_create(wl_display_.get(), &wl_compositor_interface, 3088 wl_global_create(wl_display_.get(), &wl_compositor_interface,
2977 compositor_version, display_, bind_compositor); 3089 compositor_version, display_, bind_compositor);
2978 wl_global_create(wl_display_.get(), &wl_shm_interface, 1, display_, bind_shm); 3090 wl_global_create(wl_display_.get(), &wl_shm_interface, 1, display_, bind_shm);
2979 #if defined(USE_OZONE) 3091 #if defined(USE_OZONE)
2980 wl_global_create(wl_display_.get(), &wl_drm_interface, drm_version, display_, 3092 wl_global_create(wl_display_.get(), &wl_drm_interface, drm_version, display_,
2981 bind_drm); 3093 bind_drm);
2982 wl_global_create(wl_display_.get(), &zwp_linux_dmabuf_v1_interface, 1, 3094 wl_global_create(wl_display_.get(), &zwp_linux_dmabuf_v1_interface, 1,
2983 display_, bind_linux_dmabuf); 3095 display_, bind_linux_dmabuf);
3096 wl_global_create(wl_display_.get(),
3097 &zcr_linux_explicit_synchronization_v1_interface, 1,
3098 display_, bind_linux_explicit_synchronization);
2984 #endif 3099 #endif
2985 wl_global_create(wl_display_.get(), &wl_subcompositor_interface, 1, display_, 3100 wl_global_create(wl_display_.get(), &wl_subcompositor_interface, 1, display_,
2986 bind_subcompositor); 3101 bind_subcompositor);
2987 wl_global_create(wl_display_.get(), &wl_shell_interface, 1, display_, 3102 wl_global_create(wl_display_.get(), &wl_shell_interface, 1, display_,
2988 bind_shell); 3103 bind_shell);
2989 wl_global_create(wl_display_.get(), &wl_output_interface, output_version, 3104 wl_global_create(wl_display_.get(), &wl_output_interface, output_version,
2990 display_, bind_output); 3105 display_, bind_output);
2991 wl_global_create(wl_display_.get(), &xdg_shell_interface, 1, display_, 3106 wl_global_create(wl_display_.get(), &xdg_shell_interface, 1, display_,
2992 bind_xdg_shell); 3107 bind_xdg_shell);
2993 wl_global_create(wl_display_.get(), &zcr_vsync_feedback_v1_interface, 1, 3108 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); 3187 DCHECK(event_loop);
3073 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds()); 3188 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds());
3074 } 3189 }
3075 3190
3076 void Server::Flush() { 3191 void Server::Flush() {
3077 wl_display_flush_clients(wl_display_.get()); 3192 wl_display_flush_clients(wl_display_.get());
3078 } 3193 }
3079 3194
3080 } // namespace wayland 3195 } // namespace wayland
3081 } // namespace exo 3196 } // namespace exo
OLDNEW
« no previous file with comments | « components/exo/wayland/BUILD.gn ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698