wayland: Use fifo and commit-timing for framebuffer Vsync

Provides proper frame pacing, and allows Vsync intervals above 1.
This commit is contained in:
Frank Praznik
2026-11-17 10:12:42 -05:00
parent 742645fe28
commit 729a3ea572
8 changed files with 778 additions and 25 deletions
+124 -7
View File
@@ -22,11 +22,17 @@
#ifdef SDL_VIDEO_DRIVER_WAYLAND
#include "SDL_waylandframebuffer.h"
#include <time.h>
#include "../../core/unix/SDL_poll.h"
#include "SDL_waylandframebuffer.h"
#include "SDL_waylandshmbuffer.h"
#include "SDL_waylandwindow.h"
#include "commit-timing-v1-client-protocol.h"
#include "fifo-v1-client-protocol.h"
#include "presentation-time-client-protocol.h"
#define BUFFER_COUNT 3
typedef struct Wayland_Buffer
@@ -41,6 +47,46 @@ struct Wayland_Framebuffer
Wayland_Buffer buffer[BUFFER_COUNT];
Wayland_SHMPool *pool;
void *pixels;
struct wp_presentation_feedback *feedback;
Uint64 last_presentation_time;
Uint32 refresh;
};
static void handle_sync_output(void *data, struct wp_presentation_feedback *wp_presentation_feedback, struct wl_output *output)
{
// NOP
}
static void handle_presented(void *data, struct wp_presentation_feedback *wp_presentation_feedback,
uint32_t tv_sec_hi, uint32_t tv_sec_lo, uint32_t tv_nsec, uint32_t refresh,
uint32_t seq_hi, uint32_t seq_lo, uint32_t flags)
{
Wayland_Framebuffer *framebuffer = data;
framebuffer->last_presentation_time = SDL_SECONDS_TO_NS(((Uint64)tv_sec_hi << 32) | (Uint64)tv_sec_lo) + tv_nsec;
framebuffer->refresh = refresh;
wp_presentation_feedback_destroy(framebuffer->feedback);
framebuffer->feedback = NULL;
}
static void handle_discarded(void *data, struct wp_presentation_feedback *wp_presentation_feedback)
{
SDL_VideoData *viddata = SDL_GetVideoDevice()->internal;
Wayland_Framebuffer *framebuffer = data;
struct timespec now;
clock_gettime(viddata->presentation_clock_id, &now);
framebuffer->last_presentation_time = SDL_SECONDS_TO_NS(now.tv_sec) + now.tv_nsec;
wp_presentation_feedback_destroy(framebuffer->feedback);
framebuffer->feedback = NULL;
}
static const struct wp_presentation_feedback_listener presentation_feedback_listener = {
handle_sync_output,
handle_presented,
handle_discarded
};
static void buffer_handle_release(void *data, struct wl_buffer *wl_buffer)
@@ -130,8 +176,14 @@ bool Wayland_SetWindowFramebufferVSync(SDL_VideoDevice *_this, SDL_Window *windo
return SDL_SetError("Unsupported vsync type");
}
SDL_VideoData *viddata = _this->internal;
SDL_WindowData *wind = window->internal;
wind->presentation.vsync = vsync > 0;
wind->presentation.vsync = vsync;
if (vsync > 1 && !viddata->wp_commit_timing_manager) {
SDL_LogWarn(SDL_LOG_CATEGORY_VIDEO, "The compositor lacks support for the commit-timing protocol; swap intervals above 1 are unsupported");
}
return true;
}
@@ -139,13 +191,14 @@ bool Wayland_GetWindowFramebufferVSync(SDL_VideoDevice *_this, SDL_Window *windo
{
if (vsync) {
SDL_WindowData *wind = window->internal;
*vsync = (int)wind->presentation.vsync;
*vsync = wind->presentation.vsync;
}
return true;
}
bool Wayland_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormat *format, void **pixels, int *pitch)
{
SDL_VideoData *viddata = _this->internal;
SDL_WindowData *wind = window->internal;
if (wind->framebuffer) {
Wayland_DestroyWindowFramebuffer(_this, window);
@@ -171,6 +224,16 @@ bool Wayland_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window,
CreatePresentationQueue(wind);
// Presentation feedback and FIFO are required for proper vsync, with commit-timing required for swap intervals above 1.
if (viddata->wp_fifo_manager && viddata->wp_presentation) {
if (!wind->presentation.fifo) {
wind->presentation.fifo = wp_fifo_manager_v1_get_fifo(viddata->wp_fifo_manager, wind->surface);
}
if (viddata->wp_commit_timing_manager && !wind->presentation.commit_timer) {
wind->presentation.commit_timer = wp_commit_timing_manager_v1_get_timer(viddata->wp_commit_timing_manager, wind->surface);
}
}
for (int i = 0; i < BUFFER_COUNT; ++i) {
framebuffer->buffer[i].wl_buffer = Wayland_AllocBufferFromPool(framebuffer->pool, w, h, &framebuffer->buffer[i].mem);
@@ -211,11 +274,20 @@ bool Wayland_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window,
int w, h;
SDL_GetWindowSizeInPixels(window, &w, &h);
// Process the presentation queue, as a buffer release event may have already occurred.
// Process any events already in the presentation queue.
if (WAYLAND_wl_display_dispatch_queue_pending(viddata->display, wind->presentation.queue) < 0) {
return false;
}
// Wait for feedback to get the next presentation time, and avoid getting too far ahead.
if (wind->presentation.vsync) {
while (framebuffer->feedback) {
if (WAYLAND_wl_display_dispatch_queue(viddata->display, wind->presentation.queue) < 0) {
return false;
}
}
}
// Find a free buffer.
Wayland_Buffer *buffer = NULL;
while (!buffer) {
@@ -239,20 +311,61 @@ bool Wayland_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window,
// Copy the image data.
SDL_memcpy(buffer->mem, framebuffer->pixels, w * h * 4);
if (wind->presentation.vsync) {
// Legacy synchronization that waits for the frame callback.
if (wind->presentation.vsync && !wind->presentation.fifo) {
Wayland_WaitForSwapInterval(wind);
}
// Attach the buffer and commit the surface.
// Attach the buffer and set the surface damage region.
buffer->busy = true;
wl_surface_attach(wind->surface, buffer->wl_buffer, 0, 0);
if (wl_surface_get_version(wind->surface) >= WL_SURFACE_DAMAGE_BUFFER_SINCE_VERSION) {
wl_surface_damage_buffer(wind->surface, 0, 0, SDL_MAX_SINT32, SDL_MAX_SINT32);
} else {
wl_surface_damage(wind->surface, 0, 0, SDL_MAX_SINT32, SDL_MAX_SINT32);
}
wl_surface_commit(wind->surface);
// If vsync is active, and fifo and presentation feedback are supported, use them to ensure proper frame pacing.
if (wind->presentation.vsync && wind->presentation.fifo) {
// Queue presentation feedback for this frame.
struct wp_presentation *presentation_wrapper = WAYLAND_wl_proxy_create_wrapper(viddata->wp_presentation);
WAYLAND_wl_proxy_set_queue((struct wl_proxy *)presentation_wrapper, wind->presentation.queue);
framebuffer->feedback = wp_presentation_feedback(presentation_wrapper, wind->surface);
wp_presentation_feedback_add_listener(framebuffer->feedback, &presentation_feedback_listener, framebuffer);
WAYLAND_wl_proxy_wrapper_destroy(presentation_wrapper);
// Set a FIFO barrier to wait for the next swap interval.
wp_fifo_v1_set_barrier(wind->presentation.fifo);
if (wind->presentation.commit_timer && framebuffer->last_presentation_time) {
const Uint32 interval = framebuffer->refresh * wind->presentation.vsync;
// Account for the rounding of refresh intervals by compositors.
if (interval >= SDL_MS_TO_NS(1)) {
const Uint64 next = framebuffer->last_presentation_time + interval - SDL_MS_TO_NS(1);
const Uint64 sec = SDL_NS_TO_SECONDS(next);
const Uint32 ns = (Uint32)(next % SDL_NS_PER_SECOND);
wp_commit_timer_v1_set_timestamp(wind->presentation.commit_timer, (Uint32)(sec >> 32), (Uint32)(sec & 0xFFFFFFFF), ns);
}
}
/* This weird double-commit is necessary to ensure that presented/discarded
* events are received under all conditions.
*
* Under normal conditions, where the frame is displayed, a presented event
* will be received as normal. If the window is occluded, the second commit
* will trigger a discarded event.
*
* It's ugly, but Mesa and Nvidia do the same thing...
*/
wp_fifo_v1_wait_barrier(wind->presentation.fifo);
wl_surface_commit(wind->surface);
wp_fifo_v1_wait_barrier(wind->presentation.fifo);
}
wl_surface_commit(wind->surface);
WAYLAND_wl_display_flush(viddata->display);
return true;
@@ -268,6 +381,10 @@ void Wayland_DestroyWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window
Wayland_Framebuffer *framebuffer = wind->framebuffer;
wind->framebuffer = NULL;
if (framebuffer->feedback) {
wp_presentation_feedback_destroy(framebuffer->feedback);
}
for (int i = 0; i < BUFFER_COUNT; ++i) {
wl_buffer_destroy(framebuffer->buffer[i].wl_buffer);
}
+43 -7
View File
@@ -49,15 +49,22 @@
#include <wayland-util.h>
#include "alpha-modifier-v1-client-protocol.h"
#include "color-management-v1-client-protocol.h"
#include "commit-timing-v1-client-protocol.h"
#include "cursor-shape-v1-client-protocol.h"
#include "fifo-v1-client-protocol.h"
#include "fractional-scale-v1-client-protocol.h"
#include "frog-color-management-v1-client-protocol.h"
#include "idle-inhibit-unstable-v1-client-protocol.h"
#include "input-timestamps-unstable-v1-client-protocol.h"
#include "keyboard-shortcuts-inhibit-unstable-v1-client-protocol.h"
#include "pointer-constraints-unstable-v1-client-protocol.h"
#include "pointer-gestures-unstable-v1-client-protocol.h"
#include "pointer-warp-v1-client-protocol.h"
#include "presentation-time-client-protocol.h"
#include "primary-selection-unstable-v1-client-protocol.h"
#include "relative-pointer-unstable-v1-client-protocol.h"
#include "single-pixel-buffer-v1-client-protocol.h"
#include "tablet-v2-client-protocol.h"
#include "text-input-unstable-v3-client-protocol.h"
#include "viewporter-client-protocol.h"
@@ -66,13 +73,9 @@
#include "xdg-dialog-v1-client-protocol.h"
#include "xdg-foreign-unstable-v2-client-protocol.h"
#include "xdg-output-unstable-v1-client-protocol.h"
#include "xdg-session-management-v1-client-protocol.h"
#include "xdg-shell-client-protocol.h"
#include "xdg-toplevel-icon-v1-client-protocol.h"
#include "color-management-v1-client-protocol.h"
#include "pointer-warp-v1-client-protocol.h"
#include "pointer-gestures-unstable-v1-client-protocol.h"
#include "single-pixel-buffer-v1-client-protocol.h"
#include "xdg-session-management-v1-client-protocol.h"
#include "xdg-toplevel-tag-v1-client-protocol.h"
#ifdef HAVE_LIBDECOR_H
@@ -555,7 +558,7 @@ static void wayland_preferred_check_handle_global(void *data, struct wl_registry
{
Wayland_PreferredData *d = data;
if (SDL_strcmp(interface, "wp_fifo_manager_v1") == 0) {
if (SDL_strcmp(interface, wp_fifo_manager_v1_interface.name) == 0) {
d->has_fifo_v1 = true;
}
#ifdef SDL_WL_FIXES_VERSION
@@ -1441,6 +1444,17 @@ static const struct xdg_wm_base_listener _xdg_wm_base_listener = {
handle_xdg_wm_base_ping
};
static void handle_presentation_clock_id(void *data, struct wp_presentation *wp_presentation, uint32_t clk_id)
{
SDL_VideoData *viddata = (SDL_VideoData *)data;
viddata->presentation_clock_id = clk_id;
}
static const struct wp_presentation_listener wp_presentation_listener = {
handle_presentation_clock_id
};
#ifdef HAVE_LIBDECOR_H
static void libdecor_error(struct libdecor *context, enum libdecor_error error, const char *message)
{
@@ -1532,6 +1546,13 @@ static void handle_registry_global(void *data, struct wl_registry *registry, uin
d->xdg_session_manager = wl_registry_bind(d->registry, id, &xdg_session_manager_v1_interface, 1);
} else if (SDL_strcmp(interface, xdg_toplevel_tag_manager_v1_interface.name) == 0) {
d->xdg_toplevel_tag_manager = wl_registry_bind(d->registry, id, &xdg_toplevel_tag_manager_v1_interface, 1);
} else if (SDL_strcmp(interface, wp_fifo_manager_v1_interface.name) == 0) {
d->wp_fifo_manager = wl_registry_bind(d->registry, id, &wp_fifo_manager_v1_interface, 1);
} else if (SDL_strcmp(interface, wp_commit_timing_manager_v1_interface.name) == 0) {
d->wp_commit_timing_manager = wl_registry_bind(d->registry, id, &wp_commit_timing_manager_v1_interface, 1);
} else if (SDL_strcmp(interface, wp_presentation_interface.name) == 0) {
d->wp_presentation = wl_registry_bind(d->registry, id, &wp_presentation_interface, SDL_min(version, 3));
wp_presentation_add_listener(d->wp_presentation, &wp_presentation_listener, d);
}
#ifdef SDL_WL_FIXES_VERSION
else if (SDL_strcmp(interface, wl_fixes_interface.name) == 0) {
@@ -1872,7 +1893,7 @@ static void VideoCleanup(SDL_VideoDevice *_this)
}
if (data->tablet_manager) {
zwp_tablet_manager_v2_destroy((struct zwp_tablet_manager_v2 *)data->tablet_manager);
zwp_tablet_manager_v2_destroy(data->tablet_manager);
data->tablet_manager = NULL;
}
@@ -1989,6 +2010,21 @@ static void VideoCleanup(SDL_VideoDevice *_this)
data->xdg_toplevel_tag_manager = NULL;
}
if (data->wp_fifo_manager) {
wp_fifo_manager_v1_destroy(data->wp_fifo_manager);
data->wp_fifo_manager = NULL;
}
if (data->wp_commit_timing_manager) {
wp_commit_timing_manager_v1_destroy(data->wp_commit_timing_manager);
data->wp_commit_timing_manager = NULL;
}
if (data->wp_presentation) {
wp_presentation_destroy(data->wp_presentation);
data->wp_presentation = NULL;
}
if (data->subcompositor) {
wl_subcompositor_destroy(data->subcompositor);
data->subcompositor = NULL;
+5
View File
@@ -87,6 +87,9 @@ struct SDL_VideoData
struct wp_single_pixel_buffer_manager_v1 *single_pixel_buffer_manager;
struct xdg_session_manager_v1 *xdg_session_manager;
struct xdg_toplevel_tag_manager_v1 *xdg_toplevel_tag_manager;
struct wp_fifo_manager_v1 *wp_fifo_manager;
struct wp_commit_timing_manager_v1 *wp_commit_timing_manager;
struct wp_presentation *wp_presentation;
struct xdg_session_v1 *xdg_session;
struct xkb_context *xkb_context;
@@ -102,6 +105,8 @@ struct SDL_VideoData
int output_count;
int output_max;
clockid_t presentation_clock_id;
bool initializing;
bool display_disconnected;
bool display_externally_owned;
+40 -10
View File
@@ -38,18 +38,20 @@
#include "SDL_waylandcolor.h"
#include "alpha-modifier-v1-client-protocol.h"
#include "xdg-shell-client-protocol.h"
#include "xdg-decoration-unstable-v1-client-protocol.h"
#include "idle-inhibit-unstable-v1-client-protocol.h"
#include "xdg-activation-v1-client-protocol.h"
#include "viewporter-client-protocol.h"
#include "fractional-scale-v1-client-protocol.h"
#include "xdg-foreign-unstable-v2-client-protocol.h"
#include "xdg-dialog-v1-client-protocol.h"
#include "frog-color-management-v1-client-protocol.h"
#include "xdg-toplevel-icon-v1-client-protocol.h"
#include "color-management-v1-client-protocol.h"
#include "commit-timing-v1-client-protocol.h"
#include "fifo-v1-client-protocol.h"
#include "fractional-scale-v1-client-protocol.h"
#include "frog-color-management-v1-client-protocol.h"
#include "idle-inhibit-unstable-v1-client-protocol.h"
#include "viewporter-client-protocol.h"
#include "xdg-activation-v1-client-protocol.h"
#include "xdg-decoration-unstable-v1-client-protocol.h"
#include "xdg-dialog-v1-client-protocol.h"
#include "xdg-foreign-unstable-v2-client-protocol.h"
#include "xdg-session-management-v1-client-protocol.h"
#include "xdg-shell-client-protocol.h"
#include "xdg-toplevel-icon-v1-client-protocol.h"
#include "xdg-toplevel-tag-v1-client-protocol.h"
#ifdef HAVE_LIBDECOR_H
@@ -3057,6 +3059,28 @@ bool Wayland_ReconfigureWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_W
// Window is already mapped; abort.
return false;
}
// Clear any presentation objects when reconfiguring.
if (data->presentation.frame_callback) {
wl_callback_destroy(data->presentation.frame_callback);
data->presentation.frame_callback = NULL;
}
if (data->presentation.fifo) {
wp_fifo_v1_destroy(data->presentation.fifo);
data->presentation.fifo = NULL;
}
if (data->presentation.commit_timer) {
wp_commit_timer_v1_destroy(data->presentation.commit_timer);
data->presentation.commit_timer = NULL;
}
if (data->presentation.surface_wrapper) {
WAYLAND_wl_proxy_wrapper_destroy(data->presentation.surface_wrapper);
data->presentation.surface_wrapper = NULL;
}
if (data->presentation.queue) {
WAYLAND_wl_event_queue_destroy(data->presentation.queue);
data->presentation.queue = NULL;
}
/* The caller guarantees that only one of the GL or Vulkan flags will be set.
* Note that Vulkan doesn't require any specific configuration, so only EGL
@@ -3837,6 +3861,12 @@ void Wayland_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window)
if (wind->presentation.frame_callback) {
wl_callback_destroy(wind->presentation.frame_callback);
}
if (wind->presentation.fifo) {
wp_fifo_v1_destroy(wind->presentation.fifo);
}
if (wind->presentation.commit_timer) {
wp_commit_timer_v1_destroy(wind->presentation.commit_timer);
}
if (wind->presentation.surface_wrapper) {
WAYLAND_wl_proxy_wrapper_destroy(wind->presentation.surface_wrapper);
}
+3 -1
View File
@@ -134,8 +134,10 @@ struct SDL_WindowData
struct wl_event_queue *queue;
struct wl_surface *surface_wrapper;
struct wl_callback *frame_callback;
struct wp_commit_timer_v1 *commit_timer;
struct wp_fifo_v1 *fifo;
SDL_AtomicInt swap_interval_ready;
bool vsync;
int vsync;
} presentation;
SDL_DisplayData **outputs;
+124
View File
@@ -0,0 +1,124 @@
<?xml version="1.0" encoding="UTF-8"?>
<protocol name="commit_timing_v1">
<copyright>
Copyright © 2023 Valve Corporation
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice (including the next
paragraph) shall be included in all copies or substantial portions of the
Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
</copyright>
<interface name="wp_commit_timing_manager_v1" version="1">
<description summary="commit timing">
When a compositor latches on to new content updates it will check for
any number of requirements of the available content updates (such as
fences of all buffers being signalled) to consider the update ready.
This protocol provides a method for adding a time constraint to surface
content. This constraint indicates to the compositor that a content
update should be presented as closely as possible to, but not before,
a specified time.
This protocol does not change the Wayland property that content
updates are applied in the order they are received, even when some
content updates contain timestamps and others do not.
To provide timestamps, this global factory interface must be used to
acquire a wp_commit_timing_v1 object for a surface, which may then be
used to provide timestamp information for commits.
Warning! The protocol described in this file is currently in the testing
phase. Backward compatible changes may be added together with the
corresponding interface version bump. Backward incompatible changes can
only be done by creating a new major version of the extension.
</description>
<enum name="error">
<entry name="commit_timer_exists" value="0"
summary="commit timer already exists for surface"/>
</enum>
<request name="destroy" type="destructor">
<description summary="unbind from the commit timing interface">
Informs the server that the client will no longer be using
this protocol object. Existing objects created by this object
are not affected.
</description>
</request>
<request name="get_timer">
<description summary="request commit timer interface for surface">
Establish a timing controller for a surface.
Only one commit timer can be created for a surface, or a
commit_timer_exists protocol error will be generated.
</description>
<arg name="id" type="new_id" interface="wp_commit_timer_v1"/>
<arg name="surface" type="object" interface="wl_surface"/>
</request>
</interface>
<interface name="wp_commit_timer_v1" version="1">
<description summary="Surface commit timer">
An object to set a time constraint for a content update on a surface.
</description>
<enum name="error">
<entry name="invalid_timestamp" value="0"
summary="timestamp contains an invalid value"/>
<entry name="timestamp_exists" value="1"
summary="timestamp exists"/>
<entry name="surface_destroyed" value="2"
summary="the associated surface no longer exists"/>
</enum>
<request name="set_timestamp">
<description summary="Specify time the following commit takes effect">
Provide a timing constraint for a surface content update.
A set_timestamp request may be made before a wl_surface.commit to
tell the compositor that the content is intended to be presented
as closely as possible to, but not before, the specified time.
The time is in the domain of the compositor's presentation clock.
An invalid_timestamp error will be generated for invalid tv_nsec.
If a timestamp already exists on the surface, a timestamp_exists
error is generated.
Requesting set_timestamp after the commit_timer object's surface is
destroyed will generate a "surface_destroyed" error.
</description>
<arg name="tv_sec_hi" type="uint"
summary="high 32 bits of the seconds part of target time"/>
<arg name="tv_sec_lo" type="uint"
summary="low 32 bits of the seconds part of target time"/>
<arg name="tv_nsec" type="uint"
summary="nanoseconds part of target time"/>
</request>
<request name="destroy" type="destructor">
<description summary="Destroy the timer">
Informs the server that the client will no longer be using
this protocol object.
Existing timing constraints are not affected by the destruction.
</description>
</request>
</interface>
</protocol>
+143
View File
@@ -0,0 +1,143 @@
<?xml version="1.0" encoding="UTF-8"?>
<protocol name="fifo_v1">
<copyright>
Copyright © 2023 Valve Corporation
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice (including the next
paragraph) shall be included in all copies or substantial portions of the
Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
</copyright>
<interface name="wp_fifo_manager_v1" version="1">
<description summary="protocol for fifo constraints">
When a Wayland compositor considers applying a content update,
it must ensure all the update's readiness constraints (fences, etc)
are met.
This protocol provides a way to use the completion of a display refresh
cycle as an additional readiness constraint.
Warning! The protocol described in this file is currently in the testing
phase. Backward compatible changes may be added together with the
corresponding interface version bump. Backward incompatible changes can
only be done by creating a new major version of the extension.
</description>
<enum name="error">
<description summary="fatal presentation error">
These fatal protocol errors may be emitted in response to
illegal requests.
</description>
<entry name="already_exists" value="0"
summary="fifo manager already exists for surface"/>
</enum>
<request name="destroy" type="destructor">
<description summary="unbind from the manager interface">
Informs the server that the client will no longer be using
this protocol object. Existing objects created by this object
are not affected.
</description>
</request>
<request name="get_fifo">
<description summary="request fifo interface for surface">
Establish a fifo object for a surface that may be used to add
display refresh constraints to content updates.
Only one such object may exist for a surface and attempting
to create more than one will result in an already_exists
protocol error. If a surface is acted on by multiple software
components, general best practice is that only the component
performing wl_surface.attach operations should use this protocol.
</description>
<arg name="id" type="new_id" interface="wp_fifo_v1"/>
<arg name="surface" type="object" interface="wl_surface"/>
</request>
</interface>
<interface name="wp_fifo_v1" version="1">
<description summary="fifo interface">
A fifo object for a surface that may be used to add
display refresh constraints to content updates.
</description>
<enum name="error">
<description summary="fatal error">
These fatal protocol errors may be emitted in response to
illegal requests.
</description>
<entry name="surface_destroyed" value="0"
summary="the associated surface no longer exists"/>
</enum>
<request name="set_barrier">
<description summary="sets the start point for a fifo constraint">
When the content update containing the "set_barrier" is applied,
it sets a "fifo_barrier" condition on the surface associated with
the fifo object. The condition is cleared immediately after the
following latching deadline for non-tearing presentation.
The compositor may clear the condition early if it must do so to
ensure client forward progress assumptions.
To wait for this condition to clear, use the "wait_barrier" request.
"set_barrier" is double-buffered state, see wl_surface.commit.
Requesting set_barrier after the fifo object's surface is
destroyed will generate a "surface_destroyed" error.
</description>
</request>
<request name="wait_barrier">
<description summary="adds a fifo constraint to a content update">
Indicate that this content update is not ready while a
"fifo_barrier" condition is present on the surface.
This means that when the content update containing "set_barrier"
was made active at a latching deadline, it will be active for
at least one refresh cycle. A content update which is allowed to
tear might become active after a latching deadline if no content
update became active at the deadline.
The constraint must be ignored if the surface is a subsurface in
synchronized mode. If the surface is not being updated by the
compositor (off-screen, occluded) the compositor may ignore the
constraint. Clients must use an additional mechanism such as
frame callbacks or timestamps to ensure throttling occurs under
all conditions.
"wait_barrier" is double-buffered state, see wl_surface.commit.
Requesting "wait_barrier" after the fifo object's surface is
destroyed will generate a "surface_destroyed" error.
</description>
</request>
<request name="destroy" type="destructor">
<description summary="destroy the fifo interface">
Informs the server that the client will no longer be using
this protocol object.
Surface state changes previously made by this protocol are
unaffected by this object's destruction.
</description>
</request>
</interface>
</protocol>
+296
View File
@@ -0,0 +1,296 @@
<?xml version="1.0" encoding="UTF-8"?>
<protocol name="presentation_time">
<!-- wrap:70 -->
<copyright>
Copyright © 2013-2014 Collabora, Ltd.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice (including the next
paragraph) shall be included in all copies or substantial portions of the
Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
</copyright>
<interface name="wp_presentation" version="3">
<description summary="timed presentation related wl_surface requests">
<!-- Introduction -->
The main feature of this interface is accurate presentation
timing feedback to ensure smooth video playback while maintaining
audio/video synchronization. Some features use the concept of a
presentation clock, which is defined in the
presentation.clock_id event.
A content update for a wl_surface is submitted by a
wl_surface.commit request. Request 'feedback' associates with
the wl_surface.commit and provides feedback on the content
update, particularly the final realized presentation time.
<!-- Completing presentation -->
When the final realized presentation time is available, e.g.
after a framebuffer flip completes, the requested
presentation_feedback.presented events are sent. The final
presentation time can differ from the compositor's predicted
display update time and the update's target time, especially
when the compositor misses its target vertical blanking period.
</description>
<enum name="error">
<description summary="fatal presentation errors">
These fatal protocol errors may be emitted in response to
illegal presentation requests.
</description>
<entry name="invalid_timestamp" value="0"
summary="invalid value in tv_nsec"/>
<entry name="invalid_flag" value="1"
summary="invalid flag"/>
</enum>
<request name="destroy" type="destructor">
<description summary="unbind from the presentation interface">
Informs the server that the client will no longer be using
this protocol object. Existing objects created by this object
are not affected.
</description>
</request>
<request name="feedback">
<description summary="request presentation feedback information">
Request presentation feedback for the current content submission
on the given surface. This creates a new presentation_feedback
object, which will deliver the feedback information once. If
multiple presentation_feedback objects are created for the same
submission, they will all deliver the same information.
For details on what information is returned, see the
presentation_feedback interface.
</description>
<arg name="surface" type="object" interface="wl_surface"
summary="target surface"/>
<arg name="callback" type="new_id" interface="wp_presentation_feedback"
summary="new feedback object"/>
</request>
<event name="clock_id">
<description summary="clock ID for timestamps">
This event tells the client in which clock domain the
compositor interprets the timestamps used by the presentation
extension. This clock is called the presentation clock.
The compositor sends this event when the client binds to the
presentation interface. The presentation clock does not change
during the lifetime of the client connection.
The clock identifier is platform dependent. On POSIX platforms, the
identifier value is one of the clockid_t values accepted by
clock_gettime(). clock_gettime() is defined by POSIX.1-2001.
Timestamps in this clock domain are expressed as tv_sec_hi,
tv_sec_lo, tv_nsec triples, each component being an unsigned
32-bit value. Whole seconds are in tv_sec which is a 64-bit
value combined from tv_sec_hi and tv_sec_lo, and the
additional fractional part in tv_nsec as nanoseconds. Hence,
for valid timestamps tv_nsec must be in [0, 999999999].
Note that clock_id applies only to the presentation clock,
and implies nothing about e.g. the timestamps used in the
Wayland core protocol input events.
Compositors should prefer a clock which does not jump and is
not slewed e.g. by NTP. The absolute value of the clock is
irrelevant. Precision of one millisecond or better is
recommended. Clients must be able to query the current clock
value directly, not by asking the compositor.
</description>
<arg name="clk_id" type="uint" summary="platform clock identifier"/>
</event>
</interface>
<interface name="wp_presentation_feedback" version="3">
<description summary="presentation time feedback event">
A presentation_feedback object returns an indication that a
wl_surface content update has become visible to the user.
One object corresponds to one content update submission
(wl_surface.commit). There are two possible outcomes: the
content update is presented to the user, and a presentation
timestamp delivered; or, the user did not see the content
update because it was superseded or its surface destroyed,
and the content update is discarded.
Once a presentation_feedback object has delivered a 'presented'
or 'discarded' event it is automatically destroyed.
</description>
<event name="sync_output">
<description summary="presentation synchronized to this output">
As presentation can be synchronized to only one output at a
time, this event tells which output it was. This event is only
sent prior to the presented event.
As clients may bind to the same global wl_output multiple
times, this event is sent for each bound instance that matches
the synchronized output. If a client has not bound to the
right wl_output global at all, this event is not sent.
</description>
<arg name="output" type="object" interface="wl_output"
summary="presentation output"/>
</event>
<enum name="kind" bitfield="true">
<description summary="bitmask of flags in presented event">
These flags provide information about how the presentation of
the related content update was done. The intent is to help
clients assess the reliability of the feedback and the visual
quality with respect to possible tearing and timings.
</description>
<entry name="vsync" value="0x1">
<description summary="presentation was vsync'd">
The presentation was synchronized to the "vertical retrace" by
the display hardware such that tearing does not happen.
Relying on software scheduling is not acceptable for this
flag. If presentation is done by a copy to the active
frontbuffer, then it must guarantee that tearing cannot
happen.
</description>
</entry>
<entry name="hw_clock" value="0x2">
<description summary="hardware provided the presentation timestamp">
The display hardware provided measurements that the hardware
driver converted into a presentation timestamp. Sampling a
clock in software is not acceptable for this flag.
</description>
</entry>
<entry name="hw_completion" value="0x4">
<description summary="hardware signalled the start of the presentation">
The display hardware signalled that it started using the new
image content. The opposite of this is e.g. a timer being used
to guess when the display hardware has switched to the new
image content.
</description>
</entry>
<entry name="zero_copy" value="0x8">
<description summary="presentation was done zero-copy">
The presentation of this update was done zero-copy. This means
the buffer from the client was given to display hardware as
is, without copying it. Compositing with OpenGL counts as
copying, even if textured directly from the client buffer.
Possible zero-copy cases include direct scanout of a
fullscreen surface and a surface on a hardware overlay.
</description>
</entry>
<entry name="fixed_rate" value="0x10" since="3">
<description summary="presentation is at a fixed refresh rate">
The display hardware is operating at a fixed refresh rate.
The presentation was aligned to a multiple of this event's
'refresh' argument.
If this is set, the refresh argument must not be 0.
</description>
</entry>
<entry name="variable_rate" value="0x20" since="3">
<description summary="presentation is at a variable refresh rate">
The display hardware is operating at a variable refresh rate, with
updates to this surface consistently determining the display refresh
timing. The definition of 'consistent' is compositor policy.
The content update was displayed as soon as possible after it became
ready, but no sooner than 'refresh' nanoseconds after the previous
presentation on this surface. In other words, the presentation time
was determined by when this surface's content became ready, not by
a periodic display refresh or by updates to other surfaces.
If this is set, the refresh argument must not be 0.
</description>
</entry>
</enum>
<event name="presented" type="destructor">
<description summary="the content update was displayed">
The associated content update was displayed to the user at the
indicated time (tv_sec_hi/lo, tv_nsec). For the interpretation of
the timestamp, see presentation.clock_id event.
The timestamp corresponds to the time when the content update
turned into light the first time on the surface's main output.
Compositors may approximate this from the framebuffer flip
completion events from the system, and the latency of the
physical display path if known.
This event is preceded by all related sync_output events
telling which output's refresh cycle the feedback corresponds
to, i.e. the main output for the surface. Compositors are
recommended to choose the output containing the largest part
of the wl_surface, or keeping the output they previously
chose. Having a stable presentation output association helps
clients predict future output refreshes (vblank).
The 'refresh' argument gives the compositor's prediction of how
many nanoseconds after tv_sec, tv_nsec the very next output
refresh may occur. This is to further aid clients in
predicting future refreshes, i.e., estimating the timestamps
targeting the next few vblanks. If such prediction cannot
usefully be done, the argument is zero.
For version 2 and later, if the output does not have a constant
refresh rate, explicit video mode switches excluded, then the
refresh argument must be either an appropriate rate picked by the
compositor (e.g. fastest rate), or 0 if no such rate exists.
For version 1, if the output does not have a constant refresh rate,
the refresh argument must be zero.
If the 'fixed_rate' flag is set, then the refresh argument is
the output's constant refresh rate. If the 'variable_rate' flag
is set, then the refresh argument is the output's fastest refresh
rate.
The 64-bit value combined from seq_hi and seq_lo is the value
of the output's vertical retrace counter when the content
update was first scanned out to the display. This value must
be compatible with the definition of MSC in
GLX_OML_sync_control specification. Note, that if the display
path has a non-zero latency, the time instant specified by
this counter may differ from the timestamp's.
If the output does not have a concept of vertical retrace or a
refresh cycle, or the output device is self-refreshing without
a way to query the refresh count, then the arguments seq_hi
and seq_lo must be zero.
</description>
<arg name="tv_sec_hi" type="uint"
summary="high 32 bits of the seconds part of the presentation timestamp"/>
<arg name="tv_sec_lo" type="uint"
summary="low 32 bits of the seconds part of the presentation timestamp"/>
<arg name="tv_nsec" type="uint"
summary="nanoseconds part of the presentation timestamp"/>
<arg name="refresh" type="uint" summary="nanoseconds till next refresh"/>
<arg name="seq_hi" type="uint"
summary="high 32 bits of refresh counter"/>
<arg name="seq_lo" type="uint"
summary="low 32 bits of refresh counter"/>
<arg name="flags" type="uint" enum="kind" summary="combination of 'kind' values"/>
</event>
<event name="discarded" type="destructor">
<description summary="the content update was not displayed">
The content update was never displayed to the user.
</description>
</event>
</interface>
</protocol>