2018-03-13 16:00:53 +01:00
|
|
|
/*
|
|
|
|
* Copyright © 2018 Roman Gilg
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, distribute, and sell this software
|
|
|
|
* and its documentation for any purpose is hereby granted without
|
|
|
|
* fee, provided that the above copyright notice appear in all copies
|
|
|
|
* and that both that copyright notice and this permission notice
|
|
|
|
* appear in supporting documentation, and that the name of the
|
|
|
|
* copyright holders not be used in advertising or publicity
|
|
|
|
* pertaining to distribution of the software without specific,
|
|
|
|
* written prior permission. The copyright holders make no
|
|
|
|
* representations about the suitability of this software for any
|
|
|
|
* purpose. It is provided "as is" without express or implied
|
|
|
|
* warranty.
|
|
|
|
*
|
|
|
|
* THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
|
|
|
|
* SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
|
|
* FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
|
|
* SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
|
|
|
|
* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
|
|
|
* SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "xwayland.h"
|
|
|
|
|
|
|
|
#include <present.h>
|
|
|
|
|
2018-03-13 16:00:55 +01:00
|
|
|
/*
|
|
|
|
* When not flipping let Present copy with 60fps.
|
|
|
|
* When flipping wait on frame_callback, otherwise
|
|
|
|
* the surface is not visible, in this case update
|
|
|
|
* with long interval.
|
|
|
|
*/
|
|
|
|
#define TIMER_LEN_COPY 17 // ~60fps
|
2018-03-13 16:00:54 +01:00
|
|
|
#define TIMER_LEN_FLIP 1000 // 1fps
|
|
|
|
|
2018-05-04 03:07:31 +02:00
|
|
|
static DevPrivateKeyRec xwl_present_window_private_key;
|
|
|
|
|
|
|
|
static struct xwl_present_window *
|
|
|
|
xwl_present_window_priv(WindowPtr window)
|
|
|
|
{
|
|
|
|
return dixGetPrivate(&window->devPrivates,
|
|
|
|
&xwl_present_window_private_key);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct xwl_present_window *
|
|
|
|
xwl_present_window_get_priv(WindowPtr window)
|
|
|
|
{
|
|
|
|
struct xwl_present_window *xwl_present_window = xwl_present_window_priv(window);
|
|
|
|
|
|
|
|
if (xwl_present_window == NULL) {
|
|
|
|
xwl_present_window = calloc (1, sizeof (struct xwl_present_window));
|
|
|
|
if (!xwl_present_window)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
xwl_present_window->window = window;
|
|
|
|
xwl_present_window->msc = 1;
|
|
|
|
xwl_present_window->ust = GetTimeInMicros();
|
|
|
|
|
|
|
|
xorg_list_init(&xwl_present_window->event_list);
|
|
|
|
xorg_list_init(&xwl_present_window->release_queue);
|
|
|
|
|
|
|
|
dixSetPrivate(&window->devPrivates,
|
|
|
|
&xwl_present_window_private_key,
|
|
|
|
xwl_present_window);
|
|
|
|
}
|
|
|
|
|
|
|
|
return xwl_present_window;
|
|
|
|
}
|
|
|
|
|
2018-03-13 16:00:54 +01:00
|
|
|
static void
|
2018-05-04 03:07:31 +02:00
|
|
|
xwl_present_free_timer(struct xwl_present_window *xwl_present_window)
|
2018-03-13 16:00:54 +01:00
|
|
|
{
|
2018-05-04 03:07:31 +02:00
|
|
|
TimerFree(xwl_present_window->frame_timer);
|
|
|
|
xwl_present_window->frame_timer = NULL;
|
2018-03-13 16:00:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static CARD32
|
|
|
|
xwl_present_timer_callback(OsTimerPtr timer,
|
|
|
|
CARD32 time,
|
|
|
|
void *arg);
|
|
|
|
|
2018-03-13 16:00:55 +01:00
|
|
|
static inline Bool
|
2018-05-04 03:07:31 +02:00
|
|
|
xwl_present_has_events(struct xwl_present_window *xwl_present_window)
|
2018-03-13 16:00:55 +01:00
|
|
|
{
|
2018-10-18 17:42:01 +02:00
|
|
|
return !!xwl_present_window->sync_flip ||
|
2018-11-15 17:16:59 +01:00
|
|
|
!xorg_list_is_empty(&xwl_present_window->event_list);
|
2018-05-04 03:07:31 +02:00
|
|
|
}
|
|
|
|
|
2018-03-13 16:00:54 +01:00
|
|
|
static void
|
2018-05-04 03:07:31 +02:00
|
|
|
xwl_present_reset_timer(struct xwl_present_window *xwl_present_window)
|
2018-03-13 16:00:54 +01:00
|
|
|
{
|
2018-05-04 03:07:31 +02:00
|
|
|
if (xwl_present_has_events(xwl_present_window)) {
|
2018-11-01 18:44:24 +01:00
|
|
|
CARD32 timeout;
|
|
|
|
|
|
|
|
if (xwl_present_window->frame_callback)
|
|
|
|
timeout = TIMER_LEN_FLIP;
|
|
|
|
else
|
|
|
|
timeout = TIMER_LEN_COPY;
|
2018-05-04 03:07:31 +02:00
|
|
|
|
|
|
|
xwl_present_window->frame_timer = TimerSet(xwl_present_window->frame_timer,
|
2018-11-01 18:44:24 +01:00
|
|
|
0, timeout,
|
2018-05-04 03:07:31 +02:00
|
|
|
&xwl_present_timer_callback,
|
|
|
|
xwl_present_window);
|
2018-03-13 16:00:54 +01:00
|
|
|
} else {
|
2018-05-04 03:07:31 +02:00
|
|
|
xwl_present_free_timer(xwl_present_window);
|
2018-03-13 16:00:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-13 16:00:53 +01:00
|
|
|
void
|
2018-05-04 03:07:31 +02:00
|
|
|
xwl_present_cleanup(WindowPtr window)
|
2018-03-13 16:00:53 +01:00
|
|
|
{
|
2018-05-04 03:07:31 +02:00
|
|
|
struct xwl_present_window *xwl_present_window = xwl_present_window_priv(window);
|
2018-04-18 16:02:02 +02:00
|
|
|
struct xwl_present_event *event, *tmp;
|
2018-03-13 16:00:53 +01:00
|
|
|
|
2018-05-04 03:07:31 +02:00
|
|
|
if (!xwl_present_window)
|
2018-04-20 17:07:42 +02:00
|
|
|
return;
|
|
|
|
|
2018-05-04 03:07:31 +02:00
|
|
|
if (xwl_present_window->frame_callback) {
|
|
|
|
wl_callback_destroy(xwl_present_window->frame_callback);
|
|
|
|
xwl_present_window->frame_callback = NULL;
|
2018-03-13 16:00:53 +01:00
|
|
|
}
|
|
|
|
|
2018-03-13 16:00:55 +01:00
|
|
|
/* Clear remaining events */
|
2018-05-04 03:07:31 +02:00
|
|
|
xorg_list_for_each_entry_safe(event, tmp, &xwl_present_window->event_list, list) {
|
2018-04-18 16:02:02 +02:00
|
|
|
xorg_list_del(&event->list);
|
|
|
|
free(event);
|
2018-03-13 16:00:55 +01:00
|
|
|
}
|
|
|
|
|
2018-03-13 16:00:53 +01:00
|
|
|
/* Clear remaining buffer releases and inform Present about free ressources */
|
2018-10-18 17:42:01 +02:00
|
|
|
event = xwl_present_window->sync_flip;
|
|
|
|
xwl_present_window->sync_flip = NULL;
|
|
|
|
if (event) {
|
|
|
|
if (event->buffer_released) {
|
|
|
|
free(event);
|
|
|
|
} else {
|
|
|
|
event->pending = FALSE;
|
|
|
|
event->abort = TRUE;
|
|
|
|
}
|
|
|
|
}
|
2018-05-04 03:07:31 +02:00
|
|
|
xorg_list_for_each_entry_safe(event, tmp, &xwl_present_window->release_queue, list) {
|
2018-04-18 16:02:02 +02:00
|
|
|
xorg_list_del(&event->list);
|
|
|
|
event->abort = TRUE;
|
2018-03-13 16:00:53 +01:00
|
|
|
}
|
2018-03-13 16:00:54 +01:00
|
|
|
|
|
|
|
/* Clear timer */
|
2018-05-04 03:07:31 +02:00
|
|
|
xwl_present_free_timer(xwl_present_window);
|
|
|
|
|
2018-09-05 10:49:27 +02:00
|
|
|
/* Remove from privates so we don't try to access it later */
|
|
|
|
dixSetPrivate(&window->devPrivates,
|
|
|
|
&xwl_present_window_private_key,
|
|
|
|
NULL);
|
|
|
|
|
2018-05-04 03:07:31 +02:00
|
|
|
free(xwl_present_window);
|
2018-03-13 16:00:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
xwl_present_free_event(struct xwl_present_event *event)
|
|
|
|
{
|
|
|
|
xorg_list_del(&event->list);
|
|
|
|
free(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
xwl_present_buffer_release(void *data, struct wl_buffer *buffer)
|
|
|
|
{
|
|
|
|
struct xwl_present_event *event = data;
|
|
|
|
if (!event)
|
|
|
|
return;
|
|
|
|
|
2018-05-04 03:07:31 +02:00
|
|
|
wl_buffer_set_user_data(buffer, NULL);
|
2018-03-13 16:00:53 +01:00
|
|
|
event->buffer_released = TRUE;
|
|
|
|
|
|
|
|
if (event->abort) {
|
|
|
|
if (!event->pending)
|
|
|
|
xwl_present_free_event(event);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!event->pending) {
|
2018-05-04 03:07:31 +02:00
|
|
|
present_wnmd_event_notify(event->xwl_present_window->window,
|
2018-03-13 16:00:53 +01:00
|
|
|
event->event_id,
|
2018-05-04 03:07:31 +02:00
|
|
|
event->xwl_present_window->ust,
|
|
|
|
event->xwl_present_window->msc);
|
2018-03-13 16:00:53 +01:00
|
|
|
xwl_present_free_event(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wl_buffer_listener xwl_present_release_listener = {
|
|
|
|
xwl_present_buffer_release
|
|
|
|
};
|
|
|
|
|
2018-03-13 16:00:55 +01:00
|
|
|
static void
|
2018-10-18 17:36:24 +02:00
|
|
|
xwl_present_msc_bump(struct xwl_present_window *xwl_present_window)
|
2018-03-13 16:00:55 +01:00
|
|
|
{
|
2018-10-18 17:36:24 +02:00
|
|
|
uint64_t msc = ++xwl_present_window->msc;
|
2018-03-13 16:00:55 +01:00
|
|
|
struct xwl_present_event *event, *tmp;
|
|
|
|
|
2018-10-18 17:36:24 +02:00
|
|
|
xwl_present_window->ust = GetTimeInMicros();
|
|
|
|
|
2018-10-18 17:42:01 +02:00
|
|
|
event = xwl_present_window->sync_flip;
|
|
|
|
xwl_present_window->sync_flip = NULL;
|
|
|
|
if (event) {
|
|
|
|
event->pending = FALSE;
|
|
|
|
|
|
|
|
present_wnmd_event_notify(xwl_present_window->window, event->event_id,
|
|
|
|
xwl_present_window->ust, msc);
|
|
|
|
|
|
|
|
if (event->buffer_released) {
|
|
|
|
/* If the buffer was already released, clean up now */
|
|
|
|
present_wnmd_event_notify(xwl_present_window->window, event->event_id,
|
|
|
|
xwl_present_window->ust, msc);
|
|
|
|
free(event);
|
|
|
|
} else {
|
|
|
|
xorg_list_add(&event->list, &xwl_present_window->release_queue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-13 16:00:55 +01:00
|
|
|
xorg_list_for_each_entry_safe(event, tmp,
|
2018-05-04 03:07:31 +02:00
|
|
|
&xwl_present_window->event_list,
|
2018-03-13 16:00:55 +01:00
|
|
|
list) {
|
|
|
|
if (event->target_msc <= msc) {
|
2018-05-04 03:07:31 +02:00
|
|
|
present_wnmd_event_notify(xwl_present_window->window,
|
2018-03-13 16:00:55 +01:00
|
|
|
event->event_id,
|
2018-05-04 03:07:31 +02:00
|
|
|
xwl_present_window->ust,
|
2018-03-13 16:00:55 +01:00
|
|
|
msc);
|
|
|
|
xwl_present_free_event(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-08 16:38:01 +02:00
|
|
|
static CARD32
|
2018-03-13 16:00:54 +01:00
|
|
|
xwl_present_timer_callback(OsTimerPtr timer,
|
|
|
|
CARD32 time,
|
|
|
|
void *arg)
|
|
|
|
{
|
2018-05-04 03:07:31 +02:00
|
|
|
struct xwl_present_window *xwl_present_window = arg;
|
2018-03-13 16:00:54 +01:00
|
|
|
|
2018-05-04 03:07:31 +02:00
|
|
|
xwl_present_window->frame_timer_firing = TRUE;
|
2018-03-13 16:00:54 +01:00
|
|
|
|
2018-10-18 17:36:24 +02:00
|
|
|
xwl_present_msc_bump(xwl_present_window);
|
2018-10-24 11:23:05 +02:00
|
|
|
xwl_present_reset_timer(xwl_present_window);
|
2018-03-13 16:00:55 +01:00
|
|
|
|
2018-10-24 11:23:05 +02:00
|
|
|
return 0;
|
2018-03-13 16:00:54 +01:00
|
|
|
}
|
|
|
|
|
2018-03-13 16:00:53 +01:00
|
|
|
static void
|
|
|
|
xwl_present_frame_callback(void *data,
|
|
|
|
struct wl_callback *callback,
|
|
|
|
uint32_t time)
|
|
|
|
{
|
2018-05-04 03:07:31 +02:00
|
|
|
struct xwl_present_window *xwl_present_window = data;
|
2018-03-13 16:00:53 +01:00
|
|
|
|
2018-05-04 03:07:31 +02:00
|
|
|
wl_callback_destroy(xwl_present_window->frame_callback);
|
|
|
|
xwl_present_window->frame_callback = NULL;
|
2018-03-13 16:00:53 +01:00
|
|
|
|
2018-05-04 03:07:31 +02:00
|
|
|
if (xwl_present_window->frame_timer_firing) {
|
2018-03-13 16:00:54 +01:00
|
|
|
/* If the timer is firing, this frame callback is too late */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-10-18 17:36:24 +02:00
|
|
|
xwl_present_msc_bump(xwl_present_window);
|
2018-03-13 16:00:55 +01:00
|
|
|
|
2018-03-13 16:00:54 +01:00
|
|
|
/* we do not need the timer anymore for this frame,
|
|
|
|
* reset it for potentially the next one
|
|
|
|
*/
|
2018-05-04 03:07:31 +02:00
|
|
|
xwl_present_reset_timer(xwl_present_window);
|
2018-03-13 16:00:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wl_callback_listener xwl_present_frame_listener = {
|
|
|
|
xwl_present_frame_callback
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
xwl_present_sync_callback(void *data,
|
|
|
|
struct wl_callback *callback,
|
|
|
|
uint32_t time)
|
|
|
|
{
|
|
|
|
struct xwl_present_event *event = data;
|
2018-05-04 03:07:31 +02:00
|
|
|
struct xwl_present_window *xwl_present_window = event->xwl_present_window;
|
2018-03-13 16:00:53 +01:00
|
|
|
|
2018-10-19 18:27:37 +02:00
|
|
|
wl_callback_destroy(xwl_present_window->sync_callback);
|
|
|
|
xwl_present_window->sync_callback = NULL;
|
|
|
|
|
2018-03-13 16:00:53 +01:00
|
|
|
event->pending = FALSE;
|
|
|
|
|
|
|
|
if (event->abort) {
|
|
|
|
/* Event might have been aborted */
|
|
|
|
if (event->buffer_released)
|
|
|
|
/* Buffer was already released, cleanup now */
|
|
|
|
xwl_present_free_event(event);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-05-04 03:07:31 +02:00
|
|
|
present_wnmd_event_notify(xwl_present_window->window,
|
2018-03-13 16:00:53 +01:00
|
|
|
event->event_id,
|
2018-05-04 03:07:31 +02:00
|
|
|
xwl_present_window->ust,
|
|
|
|
xwl_present_window->msc);
|
2018-03-13 16:00:53 +01:00
|
|
|
|
2018-10-19 18:27:37 +02:00
|
|
|
if (event->buffer_released) {
|
2018-03-13 16:00:53 +01:00
|
|
|
/* If the buffer was already released, send the event now again */
|
2018-05-04 03:07:31 +02:00
|
|
|
present_wnmd_event_notify(xwl_present_window->window,
|
2018-03-13 16:00:53 +01:00
|
|
|
event->event_id,
|
2018-05-04 03:07:31 +02:00
|
|
|
xwl_present_window->ust,
|
|
|
|
xwl_present_window->msc);
|
2018-10-19 18:27:37 +02:00
|
|
|
xwl_present_free_event(event);
|
|
|
|
}
|
2018-03-13 16:00:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wl_callback_listener xwl_present_sync_listener = {
|
|
|
|
xwl_present_sync_callback
|
|
|
|
};
|
|
|
|
|
|
|
|
static RRCrtcPtr
|
|
|
|
xwl_present_get_crtc(WindowPtr present_window)
|
|
|
|
{
|
2018-05-04 03:07:31 +02:00
|
|
|
struct xwl_present_window *xwl_present_window = xwl_present_window_get_priv(present_window);
|
2018-05-07 23:21:17 +02:00
|
|
|
rrScrPrivPtr rr_private;
|
|
|
|
|
2018-05-04 03:07:31 +02:00
|
|
|
if (xwl_present_window == NULL)
|
2018-03-13 16:00:53 +01:00
|
|
|
return NULL;
|
|
|
|
|
2018-05-07 23:21:17 +02:00
|
|
|
rr_private = rrGetScrPriv(present_window->drawable.pScreen);
|
|
|
|
return rr_private->crtcs[0];
|
2018-03-13 16:00:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
xwl_present_get_ust_msc(WindowPtr present_window, uint64_t *ust, uint64_t *msc)
|
|
|
|
{
|
2018-05-04 03:07:31 +02:00
|
|
|
struct xwl_present_window *xwl_present_window = xwl_present_window_get_priv(present_window);
|
|
|
|
if (!xwl_present_window)
|
2018-03-13 16:00:53 +01:00
|
|
|
return BadAlloc;
|
|
|
|
|
2018-05-04 03:07:31 +02:00
|
|
|
*ust = xwl_present_window->ust;
|
|
|
|
*msc = xwl_present_window->msc;
|
2018-03-13 16:00:53 +01:00
|
|
|
|
2018-05-04 03:07:31 +02:00
|
|
|
return Success;
|
2018-03-13 16:00:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Queue an event to report back to the Present extension when the specified
|
|
|
|
* MSC has past
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
xwl_present_queue_vblank(WindowPtr present_window,
|
|
|
|
RRCrtcPtr crtc,
|
|
|
|
uint64_t event_id,
|
|
|
|
uint64_t msc)
|
|
|
|
{
|
2018-05-04 03:07:31 +02:00
|
|
|
struct xwl_present_window *xwl_present_window = xwl_present_window_get_priv(present_window);
|
2018-03-13 16:00:55 +01:00
|
|
|
struct xwl_present_event *event;
|
|
|
|
|
|
|
|
event = malloc(sizeof *event);
|
|
|
|
if (!event)
|
|
|
|
return BadAlloc;
|
|
|
|
|
|
|
|
event->event_id = event_id;
|
2018-05-04 03:07:31 +02:00
|
|
|
event->xwl_present_window = xwl_present_window;
|
2018-03-13 16:00:55 +01:00
|
|
|
event->target_msc = msc;
|
|
|
|
|
2018-05-04 03:07:31 +02:00
|
|
|
xorg_list_append(&event->list, &xwl_present_window->event_list);
|
2018-03-13 16:00:55 +01:00
|
|
|
|
2018-05-04 03:07:31 +02:00
|
|
|
if (!xwl_present_window->frame_timer)
|
|
|
|
xwl_present_reset_timer(xwl_present_window);
|
2018-03-13 16:00:55 +01:00
|
|
|
|
|
|
|
return Success;
|
2018-03-13 16:00:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Remove a pending vblank event so that it is not reported
|
|
|
|
* to the extension
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
xwl_present_abort_vblank(WindowPtr present_window,
|
|
|
|
RRCrtcPtr crtc,
|
|
|
|
uint64_t event_id,
|
|
|
|
uint64_t msc)
|
|
|
|
{
|
2018-05-04 03:07:31 +02:00
|
|
|
struct xwl_present_window *xwl_present_window = xwl_present_window_priv(present_window);
|
2018-03-13 16:00:55 +01:00
|
|
|
struct xwl_present_event *event, *tmp;
|
2018-03-13 16:00:53 +01:00
|
|
|
|
2018-05-04 03:07:31 +02:00
|
|
|
if (!xwl_present_window)
|
2018-03-13 16:00:53 +01:00
|
|
|
return;
|
|
|
|
|
2018-05-04 03:07:31 +02:00
|
|
|
xorg_list_for_each_entry_safe(event, tmp, &xwl_present_window->event_list, list) {
|
2018-03-13 16:00:55 +01:00
|
|
|
if (event->event_id == event_id) {
|
|
|
|
xorg_list_del(&event->list);
|
|
|
|
free(event);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-04 03:07:31 +02:00
|
|
|
xorg_list_for_each_entry(event, &xwl_present_window->release_queue, list) {
|
2018-03-13 16:00:53 +01:00
|
|
|
if (event->event_id == event_id) {
|
|
|
|
event->abort = TRUE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
xwl_present_flush(WindowPtr window)
|
|
|
|
{
|
|
|
|
/* Only called when a Pixmap is copied instead of flipped,
|
|
|
|
* but in this case we wait on the next block_handler.
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
static Bool
|
|
|
|
xwl_present_check_flip2(RRCrtcPtr crtc,
|
|
|
|
WindowPtr present_window,
|
|
|
|
PixmapPtr pixmap,
|
|
|
|
Bool sync_flip,
|
|
|
|
PresentFlipReason *reason)
|
|
|
|
{
|
2018-04-18 16:02:02 +02:00
|
|
|
struct xwl_window *xwl_window = xwl_window_from_window(present_window);
|
2018-03-13 16:00:53 +01:00
|
|
|
|
|
|
|
if (!xwl_window)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We currently only allow flips of windows, that have the same
|
|
|
|
* dimensions as their xwl_window parent window. For the case of
|
|
|
|
* different sizes subsurfaces are presumably the way forward.
|
|
|
|
*/
|
|
|
|
if (!RegionEqual(&xwl_window->window->winSize, &present_window->winSize))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Bool
|
|
|
|
xwl_present_flip(WindowPtr present_window,
|
|
|
|
RRCrtcPtr crtc,
|
|
|
|
uint64_t event_id,
|
|
|
|
uint64_t target_msc,
|
|
|
|
PixmapPtr pixmap,
|
|
|
|
Bool sync_flip,
|
|
|
|
RegionPtr damage)
|
|
|
|
{
|
2018-04-18 16:02:02 +02:00
|
|
|
struct xwl_window *xwl_window = xwl_window_from_window(present_window);
|
2018-05-04 03:07:31 +02:00
|
|
|
struct xwl_present_window *xwl_present_window = xwl_present_window_priv(present_window);
|
2018-06-08 16:23:44 +02:00
|
|
|
BoxPtr damage_box;
|
2018-03-13 16:00:53 +01:00
|
|
|
Bool buffer_created;
|
|
|
|
struct wl_buffer *buffer;
|
|
|
|
struct xwl_present_event *event;
|
|
|
|
|
2018-05-04 03:07:31 +02:00
|
|
|
if (!xwl_window)
|
|
|
|
return FALSE;
|
|
|
|
|
2018-03-13 16:00:53 +01:00
|
|
|
damage_box = RegionExtents(damage);
|
|
|
|
|
|
|
|
event = malloc(sizeof *event);
|
|
|
|
if (!event)
|
|
|
|
return FALSE;
|
|
|
|
|
2018-06-11 09:13:30 +02:00
|
|
|
buffer = xwl_glamor_pixmap_get_wl_buffer(pixmap, &buffer_created);
|
2018-03-13 16:00:53 +01:00
|
|
|
|
|
|
|
event->event_id = event_id;
|
2018-05-04 03:07:31 +02:00
|
|
|
event->xwl_present_window = xwl_present_window;
|
2018-03-13 16:00:53 +01:00
|
|
|
event->buffer = buffer;
|
2018-10-18 17:42:01 +02:00
|
|
|
event->target_msc = target_msc;
|
2018-03-13 16:00:53 +01:00
|
|
|
event->pending = TRUE;
|
|
|
|
event->abort = FALSE;
|
|
|
|
event->buffer_released = FALSE;
|
|
|
|
|
2018-10-18 17:42:01 +02:00
|
|
|
if (sync_flip) {
|
|
|
|
xorg_list_init(&event->list);
|
|
|
|
xwl_present_window->sync_flip = event;
|
|
|
|
} else {
|
|
|
|
xorg_list_add(&event->list, &xwl_present_window->release_queue);
|
|
|
|
}
|
2018-03-13 16:00:53 +01:00
|
|
|
|
|
|
|
if (buffer_created)
|
|
|
|
wl_buffer_add_listener(buffer, &xwl_present_release_listener, NULL);
|
|
|
|
wl_buffer_set_user_data(buffer, event);
|
|
|
|
|
|
|
|
/* We can flip directly to the main surface (full screen window without clips) */
|
|
|
|
wl_surface_attach(xwl_window->surface, buffer, 0, 0);
|
|
|
|
|
2018-05-04 03:07:31 +02:00
|
|
|
if (!xwl_present_window->frame_callback) {
|
|
|
|
xwl_present_window->frame_callback = wl_surface_frame(xwl_window->surface);
|
|
|
|
wl_callback_add_listener(xwl_present_window->frame_callback,
|
2018-03-13 16:00:53 +01:00
|
|
|
&xwl_present_frame_listener,
|
2018-05-04 03:07:31 +02:00
|
|
|
xwl_present_window);
|
2018-03-13 16:00:53 +01:00
|
|
|
}
|
|
|
|
|
2018-11-01 18:44:24 +01:00
|
|
|
/* Realign timer */
|
|
|
|
xwl_present_window->frame_timer_firing = FALSE;
|
|
|
|
xwl_present_reset_timer(xwl_present_window);
|
|
|
|
|
2018-03-13 16:00:53 +01:00
|
|
|
wl_surface_damage(xwl_window->surface, 0, 0,
|
|
|
|
damage_box->x2 - damage_box->x1,
|
|
|
|
damage_box->y2 - damage_box->y1);
|
|
|
|
|
|
|
|
wl_surface_commit(xwl_window->surface);
|
|
|
|
|
2018-10-18 17:42:01 +02:00
|
|
|
if (!sync_flip) {
|
|
|
|
xwl_present_window->sync_callback =
|
|
|
|
wl_display_sync(xwl_window->xwl_screen->display);
|
|
|
|
wl_callback_add_listener(xwl_present_window->sync_callback,
|
|
|
|
&xwl_present_sync_listener,
|
|
|
|
event);
|
|
|
|
}
|
2018-03-13 16:00:53 +01:00
|
|
|
|
|
|
|
wl_display_flush(xwl_window->xwl_screen->display);
|
2018-11-01 18:44:24 +01:00
|
|
|
xwl_window->present_flipped = TRUE;
|
2018-03-13 16:00:53 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
xwl_present_flips_stop(WindowPtr window)
|
|
|
|
{
|
2018-05-04 03:07:31 +02:00
|
|
|
struct xwl_present_window *xwl_present_window = xwl_present_window_priv(window);
|
2018-03-13 16:00:53 +01:00
|
|
|
|
2018-03-13 16:00:55 +01:00
|
|
|
/* Change back to the fast refresh rate */
|
2018-05-04 03:07:31 +02:00
|
|
|
xwl_present_reset_timer(xwl_present_window);
|
2018-03-13 16:00:53 +01:00
|
|
|
}
|
|
|
|
|
2018-11-01 18:24:28 +01:00
|
|
|
void
|
|
|
|
xwl_present_unrealize_window(WindowPtr window)
|
|
|
|
{
|
|
|
|
struct xwl_present_window *xwl_present_window = xwl_present_window_priv(window);
|
|
|
|
|
|
|
|
if (!xwl_present_window || !xwl_present_window->frame_callback)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* The pending frame callback may never be called, so drop it and shorten
|
|
|
|
* the frame timer interval.
|
|
|
|
*/
|
|
|
|
wl_callback_destroy(xwl_present_window->frame_callback);
|
|
|
|
xwl_present_window->frame_callback = NULL;
|
|
|
|
xwl_present_reset_timer(xwl_present_window);
|
|
|
|
}
|
|
|
|
|
2018-03-13 16:00:53 +01:00
|
|
|
static present_wnmd_info_rec xwl_present_info = {
|
|
|
|
.version = PRESENT_SCREEN_INFO_VERSION,
|
|
|
|
.get_crtc = xwl_present_get_crtc,
|
|
|
|
|
|
|
|
.get_ust_msc = xwl_present_get_ust_msc,
|
|
|
|
.queue_vblank = xwl_present_queue_vblank,
|
|
|
|
.abort_vblank = xwl_present_abort_vblank,
|
|
|
|
|
|
|
|
.flush = xwl_present_flush,
|
|
|
|
|
|
|
|
.capabilities = PresentCapabilityAsync,
|
|
|
|
.check_flip2 = xwl_present_check_flip2,
|
|
|
|
.flip = xwl_present_flip,
|
|
|
|
.flips_stop = xwl_present_flips_stop
|
|
|
|
};
|
|
|
|
|
|
|
|
Bool
|
|
|
|
xwl_present_init(ScreenPtr screen)
|
|
|
|
{
|
xwayland: Add glamor egl_backend for EGLStreams
This adds initial support for displaying Xwayland applications through
the use of EGLStreams and nvidia's custom wayland protocol by adding
another egl_backend driver. This also adds some additional egl_backend
hooks that are required to make things work properly.
EGLStreams work a lot differently then the traditional way of handling
buffers with wayland. Unfortunately, there are also a LOT of various
pitfalls baked into it's design that need to be explained.
This has a very large and unfortunate implication: direct rendering is,
for the time being at least, impossible to do through EGLStreams. The
main reason being that the EGLStream spec mandates that we lose the
entire color buffer contents with each eglSwapBuffers(), which goes
against X's requirement of not losing data with pixmaps. no way to use
an allocated EGLSurface as the storage for glamor rendering like we do
with GBM, we have to rely on blitting each pixmap to it's respective
EGLSurface producer each frame. In order to pull this off, we add two
different additional egl_backend hooks that GBM opts out of
implementing:
- egl_backend.allow_commits for holding off displaying any EGLStream
backed pixmaps until the point where it's stream is completely
initialized and ready for use
- egl_backend.post_damage for blitting the content of the EGLStream
surface producer before Xwayland actually damages and commits the
wl_surface to the screen.
The other big pitfall here is that using nvidia's wayland-eglstreams
helper library is also not possible for the most part. All of it's API
for creating and destroying streams rely on being able to perform a
roundtrip in order to bring each stream to completion since the wayland
compositor must perform it's job of connecting a consumer to each
EGLstream. Because Xwayland has to potentially handle both responding to
the wayland compositor and it's own X clients, the situation of the
wayland compositor being one of our X clients must be considered. If we
perform a roundtrip with the Wayland compositor, it's possible that the
wayland compositor might currently be connected to us as an X client and
thus hang while both Xwayland and the wayland compositor await responses
from eachother. To avoid this, we work directly with the wayland
protocol and use wl_display_sync() events along with release() events to
set up and destroy EGLStreams asynchronously alongside handling X
clients.
Additionally, since setting up EGLStreams is not an atomic operation we
have to take into consideration the fact that an EGLStream can
potentially be created in response to a window resize, then immediately
deleted due to another pending window resize in the same X client's
pending reqests before Xwayland hits the part of it's event loop where
we read from the wayland compositor. To make this even more painful, we
also have to take into consideration that since EGLStreams are not
atomic that it's possible we could delete wayland resources for an
EGLStream before the compositor even finishes using them and thus run
into errors. So, we use quite a bit of tracking logic to keep EGLStream
objects alive until we know the compositor isn't using them (even if
this means the stream outlives the pixmap it backed).
While the default backend for glamor remains GBM, this patch exists for
users who have had to deal with the reprecussion of their GPU
manufacturers ignoring the advice of upstream and the standardization of
GBM across most major GPU manufacturers. It is not intended to be a
final solution to the GBM debate, but merely a baindaid so our users
don't have to suffer from the consequences of companies avoiding working
upstream. New drivers are strongly encouraged not to use this as a
backend, and use GBM like everyone else. We even spit this out as an
error from Xwayland when using the eglstream backend.
Signed-off-by: Lyude Paul <lyude@redhat.com>
Acked-by: Daniel Stone <daniels@collabora.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2018-04-20 20:38:05 +02:00
|
|
|
struct xwl_screen *xwl_screen = xwl_screen_get(screen);
|
|
|
|
|
|
|
|
/*
|
2018-06-05 19:38:44 +02:00
|
|
|
* doesn't work with the EGLStream backend.
|
xwayland: Add glamor egl_backend for EGLStreams
This adds initial support for displaying Xwayland applications through
the use of EGLStreams and nvidia's custom wayland protocol by adding
another egl_backend driver. This also adds some additional egl_backend
hooks that are required to make things work properly.
EGLStreams work a lot differently then the traditional way of handling
buffers with wayland. Unfortunately, there are also a LOT of various
pitfalls baked into it's design that need to be explained.
This has a very large and unfortunate implication: direct rendering is,
for the time being at least, impossible to do through EGLStreams. The
main reason being that the EGLStream spec mandates that we lose the
entire color buffer contents with each eglSwapBuffers(), which goes
against X's requirement of not losing data with pixmaps. no way to use
an allocated EGLSurface as the storage for glamor rendering like we do
with GBM, we have to rely on blitting each pixmap to it's respective
EGLSurface producer each frame. In order to pull this off, we add two
different additional egl_backend hooks that GBM opts out of
implementing:
- egl_backend.allow_commits for holding off displaying any EGLStream
backed pixmaps until the point where it's stream is completely
initialized and ready for use
- egl_backend.post_damage for blitting the content of the EGLStream
surface producer before Xwayland actually damages and commits the
wl_surface to the screen.
The other big pitfall here is that using nvidia's wayland-eglstreams
helper library is also not possible for the most part. All of it's API
for creating and destroying streams rely on being able to perform a
roundtrip in order to bring each stream to completion since the wayland
compositor must perform it's job of connecting a consumer to each
EGLstream. Because Xwayland has to potentially handle both responding to
the wayland compositor and it's own X clients, the situation of the
wayland compositor being one of our X clients must be considered. If we
perform a roundtrip with the Wayland compositor, it's possible that the
wayland compositor might currently be connected to us as an X client and
thus hang while both Xwayland and the wayland compositor await responses
from eachother. To avoid this, we work directly with the wayland
protocol and use wl_display_sync() events along with release() events to
set up and destroy EGLStreams asynchronously alongside handling X
clients.
Additionally, since setting up EGLStreams is not an atomic operation we
have to take into consideration the fact that an EGLStream can
potentially be created in response to a window resize, then immediately
deleted due to another pending window resize in the same X client's
pending reqests before Xwayland hits the part of it's event loop where
we read from the wayland compositor. To make this even more painful, we
also have to take into consideration that since EGLStreams are not
atomic that it's possible we could delete wayland resources for an
EGLStream before the compositor even finishes using them and thus run
into errors. So, we use quite a bit of tracking logic to keep EGLStream
objects alive until we know the compositor isn't using them (even if
this means the stream outlives the pixmap it backed).
While the default backend for glamor remains GBM, this patch exists for
users who have had to deal with the reprecussion of their GPU
manufacturers ignoring the advice of upstream and the standardization of
GBM across most major GPU manufacturers. It is not intended to be a
final solution to the GBM debate, but merely a baindaid so our users
don't have to suffer from the consequences of companies avoiding working
upstream. New drivers are strongly encouraged not to use this as a
backend, and use GBM like everyone else. We even spit this out as an
error from Xwayland when using the eglstream backend.
Signed-off-by: Lyude Paul <lyude@redhat.com>
Acked-by: Daniel Stone <daniels@collabora.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2018-04-20 20:38:05 +02:00
|
|
|
*/
|
2018-06-05 19:38:44 +02:00
|
|
|
if (xwl_screen->egl_backend == &xwl_screen->eglstream_backend)
|
xwayland: Add glamor egl_backend for EGLStreams
This adds initial support for displaying Xwayland applications through
the use of EGLStreams and nvidia's custom wayland protocol by adding
another egl_backend driver. This also adds some additional egl_backend
hooks that are required to make things work properly.
EGLStreams work a lot differently then the traditional way of handling
buffers with wayland. Unfortunately, there are also a LOT of various
pitfalls baked into it's design that need to be explained.
This has a very large and unfortunate implication: direct rendering is,
for the time being at least, impossible to do through EGLStreams. The
main reason being that the EGLStream spec mandates that we lose the
entire color buffer contents with each eglSwapBuffers(), which goes
against X's requirement of not losing data with pixmaps. no way to use
an allocated EGLSurface as the storage for glamor rendering like we do
with GBM, we have to rely on blitting each pixmap to it's respective
EGLSurface producer each frame. In order to pull this off, we add two
different additional egl_backend hooks that GBM opts out of
implementing:
- egl_backend.allow_commits for holding off displaying any EGLStream
backed pixmaps until the point where it's stream is completely
initialized and ready for use
- egl_backend.post_damage for blitting the content of the EGLStream
surface producer before Xwayland actually damages and commits the
wl_surface to the screen.
The other big pitfall here is that using nvidia's wayland-eglstreams
helper library is also not possible for the most part. All of it's API
for creating and destroying streams rely on being able to perform a
roundtrip in order to bring each stream to completion since the wayland
compositor must perform it's job of connecting a consumer to each
EGLstream. Because Xwayland has to potentially handle both responding to
the wayland compositor and it's own X clients, the situation of the
wayland compositor being one of our X clients must be considered. If we
perform a roundtrip with the Wayland compositor, it's possible that the
wayland compositor might currently be connected to us as an X client and
thus hang while both Xwayland and the wayland compositor await responses
from eachother. To avoid this, we work directly with the wayland
protocol and use wl_display_sync() events along with release() events to
set up and destroy EGLStreams asynchronously alongside handling X
clients.
Additionally, since setting up EGLStreams is not an atomic operation we
have to take into consideration the fact that an EGLStream can
potentially be created in response to a window resize, then immediately
deleted due to another pending window resize in the same X client's
pending reqests before Xwayland hits the part of it's event loop where
we read from the wayland compositor. To make this even more painful, we
also have to take into consideration that since EGLStreams are not
atomic that it's possible we could delete wayland resources for an
EGLStream before the compositor even finishes using them and thus run
into errors. So, we use quite a bit of tracking logic to keep EGLStream
objects alive until we know the compositor isn't using them (even if
this means the stream outlives the pixmap it backed).
While the default backend for glamor remains GBM, this patch exists for
users who have had to deal with the reprecussion of their GPU
manufacturers ignoring the advice of upstream and the standardization of
GBM across most major GPU manufacturers. It is not intended to be a
final solution to the GBM debate, but merely a baindaid so our users
don't have to suffer from the consequences of companies avoiding working
upstream. New drivers are strongly encouraged not to use this as a
backend, and use GBM like everyone else. We even spit this out as an
error from Xwayland when using the eglstream backend.
Signed-off-by: Lyude Paul <lyude@redhat.com>
Acked-by: Daniel Stone <daniels@collabora.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2018-04-20 20:38:05 +02:00
|
|
|
return FALSE;
|
|
|
|
|
2018-05-04 03:07:31 +02:00
|
|
|
if (!dixRegisterPrivateKey(&xwl_present_window_private_key, PRIVATE_WINDOW, 0))
|
|
|
|
return FALSE;
|
|
|
|
|
2018-03-13 16:00:53 +01:00
|
|
|
return present_wnmd_screen_init(screen, &xwl_present_info);
|
|
|
|
}
|