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

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

Issue 2404513002: exo: Implement zcr_linux_explicit_synchronization_v1
Patch Set: rebase, pull in cl 2443823002 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
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 // A property key containing a boolean set to true if a synchronization object
160 // is associated with window.
161 DEFINE_SURFACE_PROPERTY_KEY(bool, kSurfaceHasSynchronizationKey, false);
162
157 wl_resource* GetSurfaceResource(Surface* surface) { 163 wl_resource* GetSurfaceResource(Surface* surface) {
158 return surface->GetProperty(kSurfaceResourceKey); 164 return surface->GetProperty(kSurfaceResourceKey);
159 } 165 }
160 166
161 //////////////////////////////////////////////////////////////////////////////// 167 ////////////////////////////////////////////////////////////////////////////////
162 // wl_buffer_interface: 168 // wl_buffer_interface:
163 169
164 void buffer_destroy(wl_client* client, wl_resource* resource) { 170 void buffer_destroy(wl_client* client, wl_resource* resource) {
165 wl_resource_destroy(resource); 171 wl_resource_destroy(resource);
166 } 172 }
(...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after
754 uint32_t id) { 760 uint32_t id) {
755 wl_resource* resource = 761 wl_resource* resource =
756 wl_resource_create(client, &zwp_linux_dmabuf_v1_interface, 1, id); 762 wl_resource_create(client, &zwp_linux_dmabuf_v1_interface, 1, id);
757 763
758 wl_resource_set_implementation(resource, &linux_dmabuf_implementation, data, 764 wl_resource_set_implementation(resource, &linux_dmabuf_implementation, data,
759 nullptr); 765 nullptr);
760 766
761 for (const auto& supported_format : dmabuf_supported_formats) 767 for (const auto& supported_format : dmabuf_supported_formats)
762 zwp_linux_dmabuf_v1_send_format(resource, supported_format.dmabuf_format); 768 zwp_linux_dmabuf_v1_send_format(resource, supported_format.dmabuf_format);
763 } 769 }
770 #endif // defined(USE_OZONE)
764 771
765 #endif 772 ////////////////////////////////////////////////////////////////////////////////
773 // synchronization interface:
774
775 // Implements the synchronization interface to a Surface. A window property
776 // will be set during the lifetime of this class to prevent multiple instances
777 // from being created for the same Surface.
778 class Synchronization : public SurfaceObserver {
779 public:
780 explicit Synchronization(Display* display, Surface* surface)
781 : surface_(surface), 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, false);
789 }
790 }
791
792 bool SetAcquireFence(base::ScopedFD fd) {
793 std::unique_ptr<gfx::GpuFence> fence =
794 display_->CreateLinuxFence(std::move(fd));
795 if (!fence)
796 return false;
797
798 surface_->SetAcquireFence(std::move(fence));
799 return true;
800 }
801
802 void OnSurfaceDestroying(Surface* surface) override {
803 surface->RemoveSurfaceObserver(this);
804 surface_ = nullptr;
805 }
806
807 private:
808 Surface* surface_;
809 Display* display_;
810
811 DISALLOW_COPY_AND_ASSIGN(Synchronization);
812 };
813
814 void synchronization_destroy(wl_client* client, wl_resource* resource) {
815 wl_resource_destroy(resource);
816 }
817
818 void synchronization_set_acquire_fence(wl_client* client,
819 wl_resource* resource,
820 int32_t fd) {
821 Synchronization* synchronization = GetUserDataAs<Synchronization>(resource);
822
823 if (!synchronization->SetAcquireFence(base::ScopedFD(fd))) {
824 wl_resource_post_error(resource, ZCR_SYNCHRONIZATION_V1_ERROR_INVALID_FENCE,
825 "fence creation failed");
826 }
827 }
828
829 const struct zcr_synchronization_v1_interface synchronization_implementation = {
830 synchronization_destroy, synchronization_set_acquire_fence};
831
832 ////////////////////////////////////////////////////////////////////////////////
833 // linux_explicit_synchronization interface:
834
835 void linux_explicit_synchronization_destroy(wl_client* client,
836 wl_resource* resource) {
837 wl_resource_destroy(resource);
838 }
839
840 void linux_explicit_synchronization_get_surface(wl_client* client,
841 wl_resource* resource,
842 uint32_t id,
843 wl_resource* surface_resource) {
844 Display* display = GetUserDataAs<Display>(resource);
845 Surface* surface = GetUserDataAs<Surface>(surface_resource);
846
847 if (surface->GetProperty(kSurfaceHasSynchronizationKey)) {
848 wl_resource_post_error(
849 resource,
850 ZCR_LINUX_EXPLICIT_SYNCHRONIZATION_V1_ERROR_SYNCHRONIZATION_EXISTS,
851 "a synchronization object for that surface already exists");
852 return;
853 }
854
855 wl_resource* synchronization_resource =
856 wl_resource_create(client, &zcr_synchronization_v1_interface, 1, id);
857
858 SetImplementation(synchronization_resource, &synchronization_implementation,
859 base::MakeUnique<Synchronization>(display, surface));
860 }
861
862 const struct zcr_linux_explicit_synchronization_v1_interface
863 linux_explicit_synchronization_implementation = {
864 linux_explicit_synchronization_destroy,
865 linux_explicit_synchronization_get_surface};
866
867 void bind_linux_explicit_synchronization(wl_client* client,
868 void* data,
869 uint32_t version,
870 uint32_t id) {
871 wl_resource* resource = wl_resource_create(
872 client, &zcr_linux_explicit_synchronization_v1_interface, 1, id);
873 wl_resource_set_implementation(
874 resource, &linux_explicit_synchronization_implementation, data, nullptr);
875 }
766 876
767 //////////////////////////////////////////////////////////////////////////////// 877 ////////////////////////////////////////////////////////////////////////////////
768 // wl_subsurface_interface: 878 // wl_subsurface_interface:
769 879
770 void subsurface_destroy(wl_client* client, wl_resource* resource) { 880 void subsurface_destroy(wl_client* client, wl_resource* resource) {
771 wl_resource_destroy(resource); 881 wl_resource_destroy(resource);
772 } 882 }
773 883
774 void subsurface_set_position(wl_client* client, 884 void subsurface_set_position(wl_client* client,
775 wl_resource* resource, 885 wl_resource* resource,
(...skipping 2198 matching lines...) Expand 10 before | Expand all | Expand 10 after
2974 Server::Server(Display* display) 3084 Server::Server(Display* display)
2975 : display_(display), wl_display_(wl_display_create()) { 3085 : display_(display), wl_display_(wl_display_create()) {
2976 wl_global_create(wl_display_.get(), &wl_compositor_interface, 3086 wl_global_create(wl_display_.get(), &wl_compositor_interface,
2977 compositor_version, display_, bind_compositor); 3087 compositor_version, display_, bind_compositor);
2978 wl_global_create(wl_display_.get(), &wl_shm_interface, 1, display_, bind_shm); 3088 wl_global_create(wl_display_.get(), &wl_shm_interface, 1, display_, bind_shm);
2979 #if defined(USE_OZONE) 3089 #if defined(USE_OZONE)
2980 wl_global_create(wl_display_.get(), &wl_drm_interface, drm_version, display_, 3090 wl_global_create(wl_display_.get(), &wl_drm_interface, drm_version, display_,
2981 bind_drm); 3091 bind_drm);
2982 wl_global_create(wl_display_.get(), &zwp_linux_dmabuf_v1_interface, 1, 3092 wl_global_create(wl_display_.get(), &zwp_linux_dmabuf_v1_interface, 1,
2983 display_, bind_linux_dmabuf); 3093 display_, bind_linux_dmabuf);
2984 #endif 3094 #endif // defined(USE_OZONE)
3095 wl_global_create(wl_display_.get(),
3096 &zcr_linux_explicit_synchronization_v1_interface, 1,
3097 display_, bind_linux_explicit_synchronization);
2985 wl_global_create(wl_display_.get(), &wl_subcompositor_interface, 1, display_, 3098 wl_global_create(wl_display_.get(), &wl_subcompositor_interface, 1, display_,
2986 bind_subcompositor); 3099 bind_subcompositor);
2987 wl_global_create(wl_display_.get(), &wl_shell_interface, 1, display_, 3100 wl_global_create(wl_display_.get(), &wl_shell_interface, 1, display_,
2988 bind_shell); 3101 bind_shell);
2989 wl_global_create(wl_display_.get(), &wl_output_interface, output_version, 3102 wl_global_create(wl_display_.get(), &wl_output_interface, output_version,
2990 display_, bind_output); 3103 display_, bind_output);
2991 wl_global_create(wl_display_.get(), &xdg_shell_interface, 1, display_, 3104 wl_global_create(wl_display_.get(), &xdg_shell_interface, 1, display_,
2992 bind_xdg_shell); 3105 bind_xdg_shell);
2993 wl_global_create(wl_display_.get(), &zcr_vsync_feedback_v1_interface, 1, 3106 wl_global_create(wl_display_.get(), &zcr_vsync_feedback_v1_interface, 1,
2994 display_, bind_vsync_feedback); 3107 display_, bind_vsync_feedback);
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
3072 DCHECK(event_loop); 3185 DCHECK(event_loop);
3073 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds()); 3186 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds());
3074 } 3187 }
3075 3188
3076 void Server::Flush() { 3189 void Server::Flush() {
3077 wl_display_flush_clients(wl_display_.get()); 3190 wl_display_flush_clients(wl_display_.get());
3078 } 3191 }
3079 3192
3080 } // namespace wayland 3193 } // namespace wayland
3081 } // namespace exo 3194 } // namespace exo
OLDNEW
« no previous file with comments | « components/exo/wayland/BUILD.gn ('k') | third_party/WebKit/Source/platform/graphics/gpu/DrawingBufferTestHelpers.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698