1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:expandtab:shiftwidth=4:tabstop=4:
4 /* This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8 #ifndef __MOZ_WAYLAND_DISPLAY_H__
9 #define __MOZ_WAYLAND_DISPLAY_H__
11 #include "DMABufLibWrapper.h"
13 #include "mozilla/widget/mozwayland.h"
14 #include "mozilla/widget/gbm.h"
15 #include "mozilla/widget/gtk-primary-selection-client-protocol.h"
16 #include "mozilla/widget/idle-inhibit-unstable-v1-client-protocol.h"
17 #include "mozilla/widget/relative-pointer-unstable-v1-client-protocol.h"
18 #include "mozilla/widget/pointer-constraints-unstable-v1-client-protocol.h"
19 #include "mozilla/widget/linux-dmabuf-unstable-v1-client-protocol.h"
20 #include "mozilla/widget/primary-selection-unstable-v1-client-protocol.h"
21 #include "mozilla/widget/viewporter-client-protocol.h"
26 // Our general connection to Wayland display server,
27 // holds our display connection and runs event loop.
28 // We have a global nsWaylandDisplay object for each thread.
29 class nsWaylandDisplay
{
31 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(nsWaylandDisplay
)
33 // Create nsWaylandDisplay object on top of native Wayland wl_display
35 explicit nsWaylandDisplay(wl_display
* aDisplay
);
37 bool DispatchEventQueue();
40 void QueueSyncBegin();
42 void WaitForSyncEnd();
44 bool Matches(wl_display
* aDisplay
);
46 wl_display
* GetDisplay() { return mDisplay
; };
47 wl_event_queue
* GetEventQueue() { return mEventQueue
; };
48 wl_compositor
* GetCompositor(void) { return mCompositor
; };
49 wl_subcompositor
* GetSubcompositor(void) { return mSubcompositor
; };
50 wl_data_device_manager
* GetDataDeviceManager(void) {
51 return mDataDeviceManager
;
53 wl_seat
* GetSeat(void);
54 wl_shm
* GetShm(void) { return mShm
; };
55 gtk_primary_selection_device_manager
* GetPrimarySelectionDeviceManagerGtk(
57 return mPrimarySelectionDeviceManagerGtk
;
59 zwp_primary_selection_device_manager_v1
*
60 GetPrimarySelectionDeviceManagerZwpV1(void) {
61 return mPrimarySelectionDeviceManagerZwpV1
;
63 zwp_idle_inhibit_manager_v1
* GetIdleInhibitManager(void) {
64 return mIdleInhibitManager
;
66 wp_viewporter
* GetViewporter(void) { return mViewporter
; };
67 zwp_relative_pointer_manager_v1
* GetRelativePointerManager(void) {
68 return mRelativePointerManager
;
70 zwp_pointer_constraints_v1
* GetPointerConstraints(void) {
71 return mPointerConstraints
;
73 zwp_linux_dmabuf_v1
* GetDmabuf(void) { return mDmabuf
; };
75 bool IsMainThreadDisplay() { return mEventQueue
== nullptr; }
77 void SetShm(wl_shm
* aShm
);
78 void SetCompositor(wl_compositor
* aCompositor
);
79 void SetSubcompositor(wl_subcompositor
* aSubcompositor
);
80 void SetDataDeviceManager(wl_data_device_manager
* aDataDeviceManager
);
81 void SetPrimarySelectionDeviceManager(
82 gtk_primary_selection_device_manager
* aPrimarySelectionDeviceManager
);
83 void SetPrimarySelectionDeviceManager(
84 zwp_primary_selection_device_manager_v1
* aPrimarySelectionDeviceManager
);
85 void SetIdleInhibitManager(zwp_idle_inhibit_manager_v1
* aIdleInhibitManager
);
86 void SetViewporter(wp_viewporter
* aViewporter
);
87 void SetRelativePointerManager(
88 zwp_relative_pointer_manager_v1
* aRelativePointerManager
);
89 void SetPointerConstraints(zwp_pointer_constraints_v1
* aPointerConstraints
);
90 void SetDmabuf(zwp_linux_dmabuf_v1
* aDmabuf
);
92 bool IsExplicitSyncEnabled() { return mExplicitSync
; }
99 wl_event_queue
* mEventQueue
;
100 wl_data_device_manager
* mDataDeviceManager
;
101 wl_compositor
* mCompositor
;
102 wl_subcompositor
* mSubcompositor
;
104 wl_callback
* mSyncCallback
;
105 gtk_primary_selection_device_manager
* mPrimarySelectionDeviceManagerGtk
;
106 zwp_primary_selection_device_manager_v1
* mPrimarySelectionDeviceManagerZwpV1
;
107 zwp_idle_inhibit_manager_v1
* mIdleInhibitManager
;
108 zwp_relative_pointer_manager_v1
* mRelativePointerManager
;
109 zwp_pointer_constraints_v1
* mPointerConstraints
;
110 wp_viewporter
* mViewporter
;
111 zwp_linux_dmabuf_v1
* mDmabuf
;
115 void WaylandDispatchDisplays();
116 void WaylandDisplayRelease();
118 RefPtr
<nsWaylandDisplay
> WaylandDisplayGet(GdkDisplay
* aGdkDisplay
= nullptr);
119 wl_display
* WaylandDisplayGetWLDisplay(GdkDisplay
* aGdkDisplay
= nullptr);
121 } // namespace widget
122 } // namespace mozilla
125 static inline T
* WaylandRegistryBind(struct wl_registry
* wl_registry
,
127 const struct wl_interface
* interface
,
131 // When libwayland-client does not provide this symbol, it will be
132 // linked to the fallback in libmozwayland, which returns NULL.
133 id
= wl_proxy_marshal_constructor_versioned(
134 (struct wl_proxy
*)wl_registry
, WL_REGISTRY_BIND
, interface
, version
, name
,
135 interface
->name
, version
, nullptr);
138 id
= wl_proxy_marshal_constructor((struct wl_proxy
*)wl_registry
,
139 WL_REGISTRY_BIND
, interface
, name
,
140 interface
->name
, version
, nullptr);
143 return reinterpret_cast<T
*>(id
);
146 #endif // __MOZ_WAYLAND_DISPLAY_H__