1 \documentclass{article}
4 \author{Kristian Høgsberg\\
5 \texttt{krh@bitplanet.net}
8 \title{The Wayland Display Server}
14 \section{Wayland Overview}
17 \item wayland is a protocol for a new display server.
18 \item wayland is an implementation
21 \subsection{Replacing X11}
23 Over the last 10 years, a lot of functionality have slowly moved out
24 of the X server and into libraries or kernel drivers. It started with
25 freetype and fontconfig providing an alternative to the core X fonts
26 and direct rendering OpenGL as a graphics driver in a client side
27 library. Then cairo came along and provided a modern 2D rendering
28 library independent of X and compositing managers took over control of
29 the rendering of the desktop. Recently with GEM and KMS in the Linux
30 kernel, we can do modesetting outside X and schedule several direct
31 rendering clients. The end result is a highly modular graphics stack.
33 Wayland is a new display server building on top of all those
34 components. We’re trying to distill out the functionality in the X
35 server that is still used by the modern Linux desktop. This turns out
36 to be not a whole lot. Applications can allocate their own off-screen
37 buffers and render their window contents by themselves. In the end,
38 what’s needed is a way to present the resulting window surface to a
39 compositor and a way to receive input. This is what Wayland provides,
40 by piecing together the components already in the eco-system in a
41 slightly different way.
43 X will always be relevant, in the same way Fortran compilers and VRML
44 browsers are, but it’s time that we think about moving it out of the
45 critical path and provide it as an optional component for legacy
49 \section{Wayland protocol}
51 \subsection{Basic Principles}
53 The wayland protocol is an asynchronous object oriented protocol. All
54 requests are method invocations on some object. The request include
55 an object id that uniquely identifies an object on the server. Each
56 object implements an interface and the requests include an opcode that
57 identifies which method in the interface to invoke.
59 The wire protocol is determined from the C prototypes of the requests
60 and events. There is a straight forward mapping from the C types to
61 packing the bytes in the request written to the socket. It is
62 possible to map the events and requests to function calls in other
63 languages, but that hasn't been done at this point.
65 The server sends back events to the client, each event is emitted from
66 an object. Events can be error conditions. The event includes the
67 object id and the event opcode, from which the client can determine
68 the type of event. Events are generated both in repsonse to a request
69 (in which case the request and the event constitutes a round trip) or
70 spontanously when the server state changes.
73 \item state is broadcast on connect, events sent out when state
74 change. client must listen for these changes and cache the state.
75 no need (or mechanism) to query server state.
77 \item server will broadcast presence of a number of global objects,
78 which in turn will broadcast their current state
81 \subsection{Connect Time}
84 \item no fixed format connect block, the server emits a bunch of
85 events at connect time
86 \item presence events for global objects: output, compositor, input
89 \subsection{Security and Authentication}
92 \item mostly about access to underlying buffers, need new drm auth
93 mechanism (the grant-to ioctl idea), need to check the cmd stream?
95 \item getting the server socket depends on the compositor type, could
96 be a system wide name, through fd passing on the session dbus. or
97 the client is forked by the compositor and the fd is already opened.
100 \subsection{Creating Objects}
103 \item client allocates object ID, uses range protocol
104 \item server tracks how many IDs are left in current range, sends new
105 range when client is about to run out.
108 \subsection{Compositor}
110 The compositor is a global object, advertised at connect time.
114 Interface \texttt{compositor} \\ \hline
116 \texttt{create\_surface(id)} \\
117 \texttt{commit()} \\ \hline
119 \texttt{device(device)} \\
120 \texttt{acknowledge(key, frame)} \\
121 \texttt{frame(frame, time)} \\ \hline
126 \item a global object
127 \item broadcasts drm file name, or at least a string like drm:/dev/card0
128 \item commit/ack/frame protocol
133 Created by the client.
137 Interface \texttt{surface} \\ \hline
139 \texttt{destroy()} \\
142 \texttt{damage()} \\ \hline
147 Needs a way to set input region, opaque region.
151 Represents a group of input devices, including mice, keyboards. Has a
152 keyboard and pointer focus. Global object. Pointer events are
153 delivered in both screen coordinates and surface local coordinates.
157 Interface \texttt{cache} \\ \hline
159 no requests \\ \hline
161 \texttt{motion(x, y, sx, sy)} \\
162 \texttt{button(button, state, x, y, sx, sy)} \\
163 \texttt{key(key, state)} \\
164 \texttt{pointer\_focus(surface)} \\
165 \texttt{keyboard\_focus(surface, keys)} \\ \hline
169 \item input group, keyboard, mouse
170 \item keyboard map, change events
172 \item enter, leave, focus
177 \item multi pointer wayland
180 A surface can change the pointer image when the surface is the pointer
181 focus of the input device. Wayland doesn't automatically change the
182 pointer image when a pointer enters a surface, but expects the
183 application to set the cursor it wants in response the the motion
184 event. The rationale is that a client has to manage changing pointer
185 images for UI elements within the surface in response to motion events
186 anyway, so we'll make that the only mechanism for setting changing the
187 pointer image. If the server receives a request to set the pointer
188 image after the surface loses pointer focus, the request is ignored.
189 To the client this will look like it successfully set the pointer
192 The compositor will revert the pointer image back to a default image
193 when no surface has the pointer focus for that device. Clients can
194 revert the pointer image back to the default image by setting a NULL
197 What if the pointer moves from one window which has set a special
198 pointer image to a surface that doesn't set an image in response to
199 the motion event? The new surface will be stuck with the special
200 pointer image. We can't just revert the pointer image on leaving a
201 surface, since if we immediately enter a surface that sets a different
202 image, the image will flicker. Broken app, I suppose.
206 A output is a global object, advertised at connect time or as they
211 Interface \texttt{output} \\ \hline
213 no requests \\ \hline
215 \texttt{geometry(width, height)} \\ \hline
219 \item laid out in a big (compositor) coordinate system
220 \item basically xrandr over wayland
221 \item geometry needs position in compositor coordinate system\
222 \item events to advertise available modes, requests to move and change
226 \subsection{Shared object cache}
228 Cache for sharing glyphs, icons, cursors across clients. Lets clients
229 share identical objects. The cache is a global object, advertised at
234 Interface \texttt{cache} \\ \hline
236 \texttt{upload(key, visual, bo, stride, width, height)} \\ \hline
238 \texttt{item(key, bo, x, y, stride)} \\
239 \texttt{retire(bo)} \\ \hline
244 \item Upload by passing a visual, bo, stride, width, height to the
247 \item Upload returns a bo name, stride, and x, y location of object in
248 the buffer. Clients take a reference on the atlas bo.
250 \item Shared objects are refcounted, freed by client (when purging
251 glyphs from the local cache) or when a client exits.
253 \item Server can't delete individual items from an atlas, but it can
254 throw out an entire atlas bo if it becomes too sparse. The server
255 sends out an \texttt{retire} event when this happens, and clients
256 must throw away any objects from that bo and reupload. Between the
257 server dropping the atlas and the client receiving the retire event,
258 clients can still legally use the old atlas since they have a ref on
261 \item cairo needs to hook into the glyph cache, and maybe also a way
262 to create a read-only surface based on an object form the cache
265 \texttt{cairo\_wayland\_create\_cached\_surface(surface-data)}.
270 \subsection{Drag and Drop}
272 Multi-device aware. Orthogonal to rest of wayland, as it is its own
273 toplevel object. Since the compositor determines the drag target, it
274 works with transformed surfaces (dragging to a scaled down window in
275 expose mode, for example).
280 \item we can set the cursor image to the current cursor + dragged
281 object, which will last as long as the drag, but maybe an request to
282 attach an image to the cursor will be more convenient?
284 \item Should drag.send() destroy the object? There's nothing to do
285 after the data has been transferred.
287 \item How do we marshall several mime-types? We could make the drag
288 setup a multi-step operation: dnd.create, drag.offer(mime-type1,
289 drag.offer(mime-type2), drag.activate(). The drag object could send
290 multiple offer events on each motion event. Or we could just
291 implement an array type, but that's a pain to work with.
293 \item Middle-click drag to pop up menu? Ctrl/Shift/Alt drag?
295 \item Send a file descriptor over the protocol to let initiator and
296 source exchange data out of band?
298 \item Action? Specify action when creating the drag object? Ask
302 New objects, requests and events:
305 \item New toplevel dnd global. One method, creates a drag object:
306 \texttt{dnd.start(new object id, surface, input device, mime
307 types)}. Starts drag for the device, if it's grabbed by the
308 surface. drag ends when button is released. Caller is responsible
309 for destroying the drag object.
311 \item Drag object methods:
313 \texttt{drag.destroy(id)}, destroy drag object.
315 \texttt{drag.send(id, data)}, send drag data.
317 \texttt{drag.accept(id, mime type)}, accept drag offer, called by
320 \item Drag object events:
322 \texttt{drag.offer(id, mime-types)}, sent to potential destination
323 surfaces to offer drag data. If the device leaves the window or the
324 originator cancels the drag, this event is sent with mime-types =
327 \texttt{drag.target(id, mime-type)}, sent to drag originator when a
328 target surface has accepted the offer. if a previous target goes
329 away, this event is sent with mime-type = NULL.
331 \texttt{drag.data(id, data)}, sent to target, contains dragged data.
332 ends transaction on the target side.
338 \item The initiator surface receives a click (which grabs the input
339 device to that surface) and then enough motion to decide that a drag
340 is starting. Wayland has no subwindows, so it's entirely up to the
341 application to decide whether or not a draggable object within the
344 \item The initiator creates a drag object by calling the
345 \texttt{create\_drag} method on the dnd global object. As for any
346 client created object, the client allocates the id. The
347 \texttt{create\_drag} method also takes the originating surface, the
348 device that's dragging and the mime-types supported. If the surface
349 has indeed grabbed the device passed in, the server will create an
350 active drag object for the device. If the grab was released in the
351 meantime, the drag object will be in-active, that is, the same state
352 as when the grab is released. In that case, the client will receive
353 a button up event, which will let it know that the drag finished.
354 To the client it will look like the drag was immediately cancelled
357 The special mime-type application/x-root-target indicates that the
358 initiator is looking for drag events to the root window as well.
360 \item To indicate the object being dragged, the initiator can replace
361 the pointer image with an larger image representing the data being
362 dragged with the cursor image overlaid. The pointer image will
363 remain in place as long as the grab is in effect, since the
364 initiating surface keeps pointer focus, and no other surface
365 receives enter events.
367 \item As long as the grab is active (or until the initiator cancels
368 the drag by destroying the drag object), the drag object will send
369 \texttt{offer} events to surfaces it moves across. As for motion
370 events, these events contain the surface local coordinates of the
371 device as well as the list of mime-types offered. When a device
372 leaves a surface, it will send an \texttt{offer} event with an empty
373 list of mime-types to indicate that the device left the surface.
375 \item If a surface receives an offer event and decides that it's in an
376 area that can accept a drag event, it should call the
377 \texttt{accept} method on the drag object in the event. The surface
378 passes a mime-type in the request, picked from the list in the offer
379 event, to indicate which of the types it wants. At this point, the
380 surface can update the appearance of the drop target to give
381 feedback to the user that the drag has a valid target. If the
382 \texttt{offer} event moves to a different drop target (the surface
383 decides the offer coordinates is outside the drop target) or leaves
384 the surface (the offer event has an empty list of mime-types) it
385 should revert the appearance of the drop target to the inactive
386 state. A surface can also decide to retract its drop target (if the
387 drop target disappears or moves, for example), by calling the accept
388 method with a NULL mime-type.
390 \item When a target surface sends an \texttt{accept} request, the drag
391 object will send a \texttt{target} event to the initiator surface.
392 This tells the initiator that the drag currently has a potential
393 target and which of the offered mime-types the target wants. The
394 initiator can change the pointer image or drag source appearance to
395 reflect this new state. If the target surface retracts its drop
396 target of if the surface disappears, a \texttt{target} event with a
397 NULL mime-type will be sent.
399 If the initiator listed application/x-root-target as a valid
400 mime-type, dragging into the root window will make the drag object
401 send a \texttt{target} event with the application/x-root-target
404 \item When the grab is released (indicated by the button release
405 event), if the drag has an active target, the initiator calls the
406 \texttt{send} method on the drag object to send the data to be
407 transferred by the drag operation, in the format requested by the
408 target. The initiator can then destroy the drag object by calling
409 the \texttt{destroy} method.
411 \item The drop target receives a \texttt{data} event from the drag
412 object with the requested data.
415 MIME is defined in RFC's 2045-2049. A registry of MIME types is
416 maintained by the Internet Assigned Numbers Authority (IANA).
418 ftp://ftp.isi.edu/in-notes/iana/assignments/media-types/
421 \section{Types of compositors}
423 \subsection{System Compositor}
426 \item ties in with graphical boot
427 \item hosts different types of session compositors
428 \item lets us switch between multiple sessions (fast user switching,
429 secure/personal desktop switching)
431 \item linux implementation using libudev, egl, kms, evdev, cairo
432 \item for fullscreen clients, the system compositor can reprogram the
433 video scanout address to source fromt the client provided buffer.
436 \subsection{Session Compositor}
439 \item nested under the system compositor. nesting is feasible because
440 protocol is async, roundtrip would break nesting
444 \item kde compositor?
445 \item text mode using vte
447 \item fullscreen X session under wayland
448 \item can run without system compositor, on the hw where it makes
450 \item root window less X server, bridging X windows into a wayland
454 \subsection{Embbedding Compositor}
456 X11 lets clients embed windows from other clients, or lets client copy
457 pixmap contents rendered by another client into their window. This is
458 often used for applets in a panel, browser plugins and similar.
459 Wayland doesn't directly allow this, but clients can communicate GEM
460 buffer names out-of-band, for example, using d-bus or as command line
461 arguments when the panel launches the applet. Another option is to
462 use a nested wayland instance. For this, the wayland server will have
463 to be a library that the host application links to. The host
464 application will then pass the wayland server socket name to the
465 embedded application, and will need to implement the wayland
466 compositor interface. The host application composites the client
467 surfaces as part of it's window, that is, in the web page or in the
468 panel. The benefit of nesting the wayland server is that it provides
469 the requests the embedded client needs to inform the host about buffer
470 updates and a mechanism for forwarding input events from the host
474 \item firefox embedding flash by being a special purpose compositor to
478 \section{Implementation}
480 what's currently implemented
482 \subsection{Wayland Server Library}
484 \texttt{libwayland-server.so}
487 \item implements protocol side of a compositor
488 \item minimal, doesn't include any rendering or input device handling
489 \item helpers for running on egl and evdev, and for nested wayland
492 \subsection{Wayland Client Library}
494 \texttt{libwayland.so}
497 \item minimal, designed to support integration with real toolkits such as
500 \item doesn't cache state, but lets the toolkits cache server state in
501 native objects (GObject or QObject or whatever).
504 \subsection{Wayland System Compositor}
507 \item implementation of the system compositor
509 \item uses libudev, eagle (egl), evdev and drm
511 \item integrates with ConsoleKit, can create new sessions
513 \item allows multi seat setups
515 \item configurable through udev rules and maybe /etc/wayland.d type thing
518 \subsection{X Server Session}
521 \item xserver module and driver support
523 \item uses wayland client library
525 \item same X.org server as we normally run, the front buffer is a wayland
526 surface but all accel code, 3d and extensions are there
528 \item when full screen the session compositor will scan out from the X
529 server wayland surface, at which point X is running pretty much as it