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.
|
|
|
|
*/
|
|
|
|
|
2019-12-18 15:00:11 +01:00
|
|
|
#include <xwayland-config.h>
|
2018-03-13 16:00:53 +01:00
|
|
|
|
2019-12-17 15:07:07 +01:00
|
|
|
#include <windowstr.h>
|
2018-03-13 16:00:53 +01:00
|
|
|
#include <present.h>
|
|
|
|
|
2019-12-17 17:18:11 +01:00
|
|
|
#include "xwayland-present.h"
|
2019-12-18 10:03:43 +01:00
|
|
|
#include "xwayland-screen.h"
|
2019-12-17 15:07:07 +01:00
|
|
|
#include "xwayland-window.h"
|
2019-12-17 17:07:58 +01:00
|
|
|
#include "xwayland-pixmap.h"
|
2019-12-17 15:07:07 +01:00
|
|
|
#include "glamor.h"
|
|
|
|
|
2021-04-19 18:26:55 +02:00
|
|
|
|
|
|
|
#define XWL_PRESENT_CAPS PresentCapabilityAsync
|
|
|
|
|
|
|
|
|
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->msc = 1;
|
|
|
|
xwl_present_window->ust = GetTimeInMicros();
|
|
|
|
|
2019-11-27 18:04:06 +01:00
|
|
|
xorg_list_init(&xwl_present_window->frame_callback_list);
|
2020-02-15 01:58:22 +01:00
|
|
|
xorg_list_init(&xwl_present_window->wait_list);
|
2021-04-21 12:50:02 +02:00
|
|
|
xorg_list_init(&xwl_present_window->flip_queue);
|
|
|
|
xorg_list_init(&xwl_present_window->idle_queue);
|
2018-05-04 03:07:31 +02:00
|
|
|
|
|
|
|
dixSetPrivate(&window->devPrivates,
|
|
|
|
&xwl_present_window_private_key,
|
|
|
|
xwl_present_window);
|
|
|
|
}
|
|
|
|
|
|
|
|
return xwl_present_window;
|
|
|
|
}
|
|
|
|
|
2021-04-23 12:59:55 +02:00
|
|
|
static struct xwl_present_event *
|
|
|
|
xwl_present_event_from_id(uint64_t event_id)
|
|
|
|
{
|
|
|
|
return (struct xwl_present_event*)(uintptr_t)event_id;
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
2021-05-06 18:42:46 +02:00
|
|
|
static present_vblank_ptr
|
|
|
|
xwl_present_get_pending_flip(struct xwl_present_window *xwl_present_window)
|
|
|
|
{
|
|
|
|
present_vblank_ptr flip_pending;
|
|
|
|
|
|
|
|
if (xorg_list_is_empty(&xwl_present_window->flip_queue))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
flip_pending = xorg_list_first_entry(&xwl_present_window->flip_queue, present_vblank_rec,
|
|
|
|
event_queue);
|
|
|
|
|
|
|
|
if (flip_pending->queued)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return flip_pending;
|
|
|
|
}
|
|
|
|
|
2018-03-13 16:00:55 +01:00
|
|
|
static inline Bool
|
2020-02-15 01:58:22 +01:00
|
|
|
xwl_present_has_pending_events(struct xwl_present_window *xwl_present_window)
|
2018-03-13 16:00:55 +01:00
|
|
|
{
|
2021-05-07 12:34:49 +02:00
|
|
|
present_vblank_ptr flip_pending = xwl_present_get_pending_flip(xwl_present_window);
|
|
|
|
|
|
|
|
return (flip_pending && flip_pending->sync_flip) ||
|
2020-02-15 01:58:22 +01:00
|
|
|
!xorg_list_is_empty(&xwl_present_window->wait_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
|
|
|
{
|
2020-02-15 01:58:22 +01:00
|
|
|
if (xwl_present_has_pending_events(xwl_present_window)) {
|
2018-11-01 18:44:24 +01:00
|
|
|
CARD32 timeout;
|
|
|
|
|
2019-11-27 18:04:06 +01:00
|
|
|
if (!xorg_list_is_empty(&xwl_present_window->frame_callback_list))
|
2018-11-01 18:44:24 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-21 12:50:02 +02:00
|
|
|
|
|
|
|
static void
|
2021-04-19 12:59:56 +02:00
|
|
|
xwl_present_execute(present_vblank_ptr vblank, uint64_t ust, uint64_t crtc_msc);
|
2021-04-21 12:50:02 +02:00
|
|
|
|
|
|
|
static uint32_t
|
2021-04-19 18:26:55 +02:00
|
|
|
xwl_present_query_capabilities(present_screen_priv_ptr screen_priv)
|
2021-04-21 12:50:02 +02:00
|
|
|
{
|
2021-04-19 18:26:55 +02:00
|
|
|
return XWL_PRESENT_CAPS;
|
2021-04-21 12:50:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2021-04-19 18:53:36 +02:00
|
|
|
xwl_present_get_ust_msc(ScreenPtr screen,
|
|
|
|
WindowPtr present_window,
|
|
|
|
uint64_t *ust,
|
|
|
|
uint64_t *msc)
|
2021-04-21 12:50:02 +02:00
|
|
|
{
|
2021-04-19 18:53:36 +02:00
|
|
|
struct xwl_present_window *xwl_present_window = xwl_present_window_get_priv(present_window);
|
|
|
|
if (!xwl_present_window)
|
|
|
|
return BadAlloc;
|
|
|
|
|
|
|
|
*ust = xwl_present_window->ust;
|
|
|
|
*msc = xwl_present_window->msc;
|
|
|
|
|
|
|
|
return Success;
|
2021-04-21 12:50:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* When the wait fence or previous flip is completed, it's time
|
|
|
|
* to re-try the request
|
|
|
|
*/
|
|
|
|
static void
|
2021-04-19 12:59:56 +02:00
|
|
|
xwl_present_re_execute(present_vblank_ptr vblank)
|
2021-04-21 12:50:02 +02:00
|
|
|
{
|
|
|
|
uint64_t ust = 0, crtc_msc = 0;
|
|
|
|
|
2021-04-19 18:53:36 +02:00
|
|
|
(void) xwl_present_get_ust_msc(vblank->screen, vblank->window, &ust, &crtc_msc);
|
2021-04-19 12:59:56 +02:00
|
|
|
xwl_present_execute(vblank, ust, crtc_msc);
|
2021-04-21 12:50:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2021-05-11 12:56:53 +02:00
|
|
|
xwl_present_flip_try_ready(struct xwl_present_window *xwl_present_window)
|
2021-04-21 12:50:02 +02:00
|
|
|
{
|
2021-05-11 12:56:53 +02:00
|
|
|
present_vblank_ptr vblank;
|
2021-04-21 12:50:02 +02:00
|
|
|
|
|
|
|
xorg_list_for_each_entry(vblank, &xwl_present_window->flip_queue, event_queue) {
|
|
|
|
if (vblank->queued) {
|
2021-04-19 12:59:56 +02:00
|
|
|
xwl_present_re_execute(vblank);
|
2021-04-21 12:50:02 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-23 12:59:55 +02:00
|
|
|
static void
|
|
|
|
xwl_present_release_pixmap(struct xwl_present_event *event)
|
|
|
|
{
|
|
|
|
if (!event->pixmap)
|
|
|
|
return;
|
|
|
|
|
|
|
|
xwl_pixmap_del_buffer_release_cb(event->pixmap);
|
|
|
|
dixDestroyPixmap(event->pixmap, event->pixmap->drawable.id);
|
|
|
|
event->pixmap = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2021-05-12 12:51:32 +02:00
|
|
|
xwl_present_free_event(struct xwl_present_event *event)
|
2021-04-23 12:59:55 +02:00
|
|
|
{
|
|
|
|
xwl_present_release_pixmap(event);
|
2021-05-07 18:16:23 +02:00
|
|
|
xorg_list_del(&event->vblank.event_queue);
|
2021-04-23 12:59:55 +02:00
|
|
|
present_vblank_destroy(&event->vblank);
|
|
|
|
}
|
|
|
|
|
2021-04-21 12:50:02 +02:00
|
|
|
static void
|
2021-04-19 12:59:56 +02:00
|
|
|
xwl_present_free_idle_vblank(present_vblank_ptr vblank)
|
2021-04-21 12:50:02 +02:00
|
|
|
{
|
|
|
|
present_pixmap_idle(vblank->pixmap, vblank->window, vblank->serial, vblank->idle_fence);
|
2021-04-23 12:59:55 +02:00
|
|
|
xwl_present_free_event(xwl_present_event_from_id((uintptr_t)vblank));
|
2021-04-21 12:50:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static WindowPtr
|
2021-04-19 12:59:56 +02:00
|
|
|
xwl_present_toplvl_pixmap_window(WindowPtr window)
|
2021-04-21 12:50:02 +02:00
|
|
|
{
|
|
|
|
ScreenPtr screen = window->drawable.pScreen;
|
|
|
|
PixmapPtr pixmap = (*screen->GetWindowPixmap)(window);
|
|
|
|
WindowPtr w = window;
|
|
|
|
WindowPtr next_w;
|
|
|
|
|
|
|
|
while(w->parent) {
|
|
|
|
next_w = w->parent;
|
|
|
|
if ( (*screen->GetWindowPixmap)(next_w) != pixmap) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
w = next_w;
|
|
|
|
}
|
|
|
|
return w;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2021-04-19 18:41:59 +02:00
|
|
|
xwl_present_flips_stop(WindowPtr window)
|
2021-04-21 12:50:02 +02:00
|
|
|
{
|
|
|
|
struct xwl_present_window *xwl_present_window = xwl_present_window_priv(window);
|
2021-05-11 12:56:53 +02:00
|
|
|
present_vblank_ptr vblank, tmp;
|
2021-04-21 12:50:02 +02:00
|
|
|
|
2021-04-19 18:41:59 +02:00
|
|
|
/* Change back to the fast refresh rate */
|
|
|
|
xwl_present_reset_timer(xwl_present_window);
|
2021-04-21 12:50:02 +02:00
|
|
|
|
2021-05-11 12:56:53 +02:00
|
|
|
/* Free any left over idle vblanks */
|
|
|
|
xorg_list_for_each_entry_safe(vblank, tmp, &xwl_present_window->idle_queue, event_queue)
|
|
|
|
xwl_present_free_idle_vblank(vblank);
|
|
|
|
|
|
|
|
if (xwl_present_window->flip_active) {
|
|
|
|
xwl_present_free_idle_vblank(xwl_present_window->flip_active);
|
|
|
|
xwl_present_window->flip_active = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
xwl_present_flip_try_ready(xwl_present_window);
|
2021-04-21 12:50:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2021-04-19 12:59:56 +02:00
|
|
|
xwl_present_flip_notify_vblank(present_vblank_ptr vblank, uint64_t ust, uint64_t crtc_msc)
|
2021-04-21 12:50:02 +02:00
|
|
|
{
|
|
|
|
WindowPtr window = vblank->window;
|
|
|
|
struct xwl_present_window *xwl_present_window = xwl_present_window_priv(window);
|
|
|
|
|
|
|
|
DebugPresent(("\tn %" PRIu64 " %p %" PRIu64 " %" PRIu64 ": %08" PRIx32 " -> %08" PRIx32 "\n",
|
|
|
|
vblank->event_id, vblank, vblank->exec_msc, vblank->target_msc,
|
|
|
|
vblank->pixmap ? vblank->pixmap->drawable.id : 0,
|
|
|
|
vblank->window ? vblank->window->drawable.id : 0));
|
|
|
|
|
2021-05-06 18:42:46 +02:00
|
|
|
assert (&vblank->event_queue == xwl_present_window->flip_queue.next);
|
2021-04-21 12:50:02 +02:00
|
|
|
|
|
|
|
xorg_list_del(&vblank->event_queue);
|
|
|
|
|
|
|
|
if (xwl_present_window->flip_active) {
|
2021-05-20 19:00:10 +02:00
|
|
|
struct xwl_present_event *event =
|
|
|
|
xwl_present_event_from_id((uintptr_t)xwl_present_window->flip_active);
|
|
|
|
|
|
|
|
if (!event->pixmap)
|
|
|
|
xwl_present_free_event(event);
|
2021-04-21 12:50:02 +02:00
|
|
|
else
|
|
|
|
/* Put the previous flip in the idle_queue and wait for further notice from
|
|
|
|
* the Wayland compositor
|
|
|
|
*/
|
|
|
|
xorg_list_append(&xwl_present_window->flip_active->event_queue, &xwl_present_window->idle_queue);
|
|
|
|
}
|
|
|
|
|
|
|
|
xwl_present_window->flip_active = vblank;
|
|
|
|
|
|
|
|
present_vblank_notify(vblank, PresentCompleteKindPixmap, PresentCompleteModeFlip, ust, crtc_msc);
|
|
|
|
|
|
|
|
if (vblank->abort_flip)
|
2021-04-19 18:41:59 +02:00
|
|
|
xwl_present_flips_stop(window);
|
2021-04-21 12:50:02 +02:00
|
|
|
|
2021-05-11 12:56:53 +02:00
|
|
|
xwl_present_flip_try_ready(xwl_present_window);
|
2021-04-21 12:50:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2021-05-11 12:56:53 +02:00
|
|
|
xwl_present_update_window_crtc(present_window_priv_ptr window_priv, RRCrtcPtr crtc, uint64_t new_msc)
|
2021-04-21 12:50:02 +02:00
|
|
|
{
|
|
|
|
/* Crtc unchanged, no offset. */
|
|
|
|
if (crtc == window_priv->crtc)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* No crtc earlier to offset against, just set the crtc. */
|
|
|
|
if (window_priv->crtc == PresentCrtcNeverSet) {
|
|
|
|
window_priv->msc_offset = 0;
|
|
|
|
window_priv->crtc = crtc;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* In window-mode the last correct msc-offset is always kept
|
|
|
|
* in window-priv struct because msc is saved per window and
|
|
|
|
* not per crtc as in screen-mode.
|
|
|
|
*/
|
|
|
|
window_priv->msc_offset += new_msc - window_priv->msc;
|
|
|
|
window_priv->crtc = crtc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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);
|
2021-04-23 12:59:55 +02:00
|
|
|
present_window_priv_ptr window_priv = 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;
|
|
|
|
|
2019-11-27 18:04:06 +01:00
|
|
|
xorg_list_del(&xwl_present_window->frame_callback_list);
|
2018-03-13 16:00:53 +01:00
|
|
|
|
2019-03-08 18:49:04 +01:00
|
|
|
if (xwl_present_window->sync_callback) {
|
|
|
|
wl_callback_destroy(xwl_present_window->sync_callback);
|
|
|
|
xwl_present_window->sync_callback = NULL;
|
|
|
|
}
|
|
|
|
|
2018-03-13 16:00:55 +01:00
|
|
|
/* Clear remaining events */
|
2021-04-23 12:59:55 +02:00
|
|
|
xorg_list_for_each_entry_safe(event, tmp, &window_priv->vblank, vblank.window_list)
|
2020-06-19 18:10:18 +02:00
|
|
|
xwl_present_free_event(event);
|
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
|
2020-06-25 17:56:41 +02:00
|
|
|
xwl_present_buffer_release(void *data)
|
2018-03-13 16:00:53 +01:00
|
|
|
{
|
2021-05-07 12:56:30 +02:00
|
|
|
struct xwl_present_window *xwl_present_window;
|
2018-03-13 16:00:53 +01:00
|
|
|
struct xwl_present_event *event = data;
|
2021-05-20 19:00:10 +02:00
|
|
|
present_vblank_ptr vblank;
|
2019-10-30 13:17:34 +01:00
|
|
|
|
2018-03-13 16:00:53 +01:00
|
|
|
if (!event)
|
|
|
|
return;
|
|
|
|
|
2021-05-20 19:00:10 +02:00
|
|
|
vblank = &event->vblank;
|
|
|
|
present_pixmap_idle(vblank->pixmap, vblank->window, vblank->serial, vblank->idle_fence);
|
2021-05-07 12:56:30 +02:00
|
|
|
|
2021-05-20 19:00:10 +02:00
|
|
|
xwl_present_window = xwl_present_window_priv(vblank->window);
|
|
|
|
if (xwl_present_window->flip_active == vblank ||
|
|
|
|
xwl_present_get_pending_flip(xwl_present_window) == vblank)
|
2021-05-10 19:04:07 +02:00
|
|
|
xwl_present_release_pixmap(event);
|
2021-05-20 19:00:10 +02:00
|
|
|
else
|
|
|
|
xwl_present_free_event(event);
|
2018-03-13 16:00:53 +01:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2021-05-07 12:34:49 +02:00
|
|
|
present_vblank_ptr flip_pending = xwl_present_get_pending_flip(xwl_present_window);
|
2018-10-18 17:36:24 +02:00
|
|
|
uint64_t msc = ++xwl_present_window->msc;
|
2021-05-12 15:25:51 +02:00
|
|
|
present_vblank_ptr vblank, tmp;
|
2018-03-13 16:00:55 +01:00
|
|
|
|
2018-10-18 17:36:24 +02:00
|
|
|
xwl_present_window->ust = GetTimeInMicros();
|
|
|
|
|
2021-05-12 12:51:32 +02:00
|
|
|
if (flip_pending && flip_pending->sync_flip)
|
2021-05-07 12:34:49 +02:00
|
|
|
xwl_present_flip_notify_vblank(flip_pending, xwl_present_window->ust, msc);
|
2018-10-18 17:42:01 +02:00
|
|
|
|
2021-05-12 15:25:51 +02:00
|
|
|
xorg_list_for_each_entry_safe(vblank, tmp, &xwl_present_window->wait_list, event_queue) {
|
|
|
|
if (vblank->exec_msc <= msc) {
|
2021-05-07 17:55:13 +02:00
|
|
|
DebugPresent(("\te %" PRIu64 " ust %" PRIu64 " msc %" PRIu64 "\n",
|
2021-05-12 15:25:51 +02:00
|
|
|
vblank->event_id, xwl_present_window->ust, msc));
|
2021-05-07 17:55:13 +02:00
|
|
|
|
2021-05-12 15:25:51 +02:00
|
|
|
xwl_present_execute(vblank, xwl_present_window->ust, msc);
|
2018-03-13 16:00:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2019-11-27 18:56:05 +01:00
|
|
|
/* If we were expecting a frame callback for this window, it didn't arrive
|
|
|
|
* in a second. Stop listening to it to avoid double-bumping the MSC
|
|
|
|
*/
|
|
|
|
xorg_list_del(&xwl_present_window->frame_callback_list);
|
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
|
|
|
}
|
|
|
|
|
2019-11-27 18:04:06 +01:00
|
|
|
void
|
|
|
|
xwl_present_frame_callback(struct xwl_present_window *xwl_present_window)
|
2018-03-13 16:00:53 +01:00
|
|
|
{
|
2019-11-27 18:04:06 +01:00
|
|
|
xorg_list_del(&xwl_present_window->frame_callback_list);
|
2018-03-13 16:00:53 +01:00
|
|
|
|
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 void
|
|
|
|
xwl_present_sync_callback(void *data,
|
|
|
|
struct wl_callback *callback,
|
|
|
|
uint32_t time)
|
|
|
|
{
|
2021-05-12 15:25:51 +02:00
|
|
|
present_vblank_ptr vblank = data;
|
|
|
|
struct xwl_present_window *xwl_present_window = xwl_present_window_get_priv(vblank->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;
|
|
|
|
|
2021-05-12 15:25:51 +02:00
|
|
|
xwl_present_flip_notify_vblank(vblank, xwl_present_window->ust, xwl_present_window->msc);
|
2018-03-13 16:00:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wl_callback_listener xwl_present_sync_listener = {
|
|
|
|
xwl_present_sync_callback
|
|
|
|
};
|
|
|
|
|
|
|
|
static RRCrtcPtr
|
2021-04-19 18:51:06 +02:00
|
|
|
xwl_present_get_crtc(present_screen_priv_ptr screen_priv,
|
|
|
|
WindowPtr present_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_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);
|
2019-01-08 12:48:53 +01:00
|
|
|
|
|
|
|
if (rr_private->numCrtcs == 0)
|
|
|
|
return NULL;
|
|
|
|
|
2018-05-07 23:21:17 +02:00
|
|
|
return rr_private->crtcs[0];
|
2018-03-13 16:00:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Queue an event to report back to the Present extension when the specified
|
2021-04-19 18:46:23 +02:00
|
|
|
* MSC has passed
|
2018-03-13 16:00:53 +01:00
|
|
|
*/
|
|
|
|
static int
|
2021-04-19 18:46:23 +02:00
|
|
|
xwl_present_queue_vblank(ScreenPtr screen,
|
|
|
|
WindowPtr present_window,
|
2018-03-13 16:00:53 +01:00
|
|
|
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);
|
2019-11-27 18:56:05 +01:00
|
|
|
struct xwl_window *xwl_window = xwl_window_from_window(present_window);
|
2021-04-23 12:59:55 +02:00
|
|
|
struct xwl_present_event *event = xwl_present_event_from_id(event_id);
|
2018-03-13 16:00:55 +01:00
|
|
|
|
2021-05-10 18:33:43 +02:00
|
|
|
event->vblank.exec_msc = msc;
|
2018-03-13 16:00:55 +01:00
|
|
|
|
2021-05-07 18:16:23 +02:00
|
|
|
xorg_list_del(&event->vblank.event_queue);
|
|
|
|
xorg_list_append(&event->vblank.event_queue, &xwl_present_window->wait_list);
|
2018-03-13 16:00:55 +01:00
|
|
|
|
2019-11-27 18:56:05 +01:00
|
|
|
/* If there's a pending frame callback, use that */
|
|
|
|
if (xwl_window && xwl_window->frame_callback &&
|
|
|
|
xorg_list_is_empty(&xwl_present_window->frame_callback_list)) {
|
|
|
|
xorg_list_add(&xwl_present_window->frame_callback_list,
|
|
|
|
&xwl_window->frame_callback_list);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((xwl_window && xwl_window->frame_callback) ||
|
|
|
|
!xwl_present_window->frame_timer)
|
2018-05-04 03:07:31 +02:00
|
|
|
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
|
2021-04-19 18:01:52 +02:00
|
|
|
xwl_present_abort_vblank(ScreenPtr screen,
|
|
|
|
WindowPtr present_window,
|
2018-03-13 16:00:53 +01:00
|
|
|
RRCrtcPtr crtc,
|
|
|
|
uint64_t event_id,
|
|
|
|
uint64_t msc)
|
|
|
|
{
|
2021-04-23 12:59:55 +02:00
|
|
|
static Bool called;
|
2018-03-13 16:00:53 +01:00
|
|
|
|
2021-04-23 12:59:55 +02:00
|
|
|
if (called)
|
|
|
|
return;
|
2018-03-13 16:00:55 +01:00
|
|
|
|
2021-04-23 12:59:55 +02:00
|
|
|
/* xwl_present_cleanup should have cleaned up everything,
|
|
|
|
* present_free_window_vblank shouldn't need to call this.
|
|
|
|
*/
|
|
|
|
ErrorF("Unexpected call to %s:\n", __func__);
|
|
|
|
xorg_backtrace();
|
2018-03-13 16:00:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
xwl_present_flush(WindowPtr window)
|
|
|
|
{
|
2019-11-29 09:40:13 +01:00
|
|
|
glamor_block_handler(window->drawable.pScreen);
|
2018-03-13 16:00:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static Bool
|
2021-04-19 18:34:07 +02:00
|
|
|
xwl_present_check_flip(RRCrtcPtr crtc,
|
|
|
|
WindowPtr present_window,
|
|
|
|
PixmapPtr pixmap,
|
|
|
|
Bool sync_flip,
|
|
|
|
RegionPtr valid,
|
|
|
|
int16_t x_off,
|
|
|
|
int16_t y_off,
|
|
|
|
PresentFlipReason *reason)
|
2018-03-13 16:00:53 +01:00
|
|
|
{
|
2021-04-19 12:59:56 +02:00
|
|
|
WindowPtr toplvl_window = xwl_present_toplvl_pixmap_window(present_window);
|
2018-04-18 16:02:02 +02:00
|
|
|
struct xwl_window *xwl_window = xwl_window_from_window(present_window);
|
2020-08-27 18:36:15 +02:00
|
|
|
ScreenPtr screen = pixmap->drawable.pScreen;
|
2018-03-13 16:00:53 +01:00
|
|
|
|
2021-04-19 18:34:07 +02:00
|
|
|
if (reason)
|
|
|
|
*reason = PRESENT_FLIP_REASON_UNKNOWN;
|
|
|
|
|
2018-03-13 16:00:53 +01:00
|
|
|
if (!xwl_window)
|
|
|
|
return FALSE;
|
|
|
|
|
2021-04-19 18:34:07 +02:00
|
|
|
if (!crtc)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* Source pixmap must align with window exactly */
|
|
|
|
if (x_off || y_off)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* Valid area must contain window (for simplicity for now just never flip when one is set). */
|
|
|
|
if (valid)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* Flip pixmap must have same dimensions as window */
|
|
|
|
if (present_window->drawable.width != pixmap->drawable.width ||
|
|
|
|
present_window->drawable.height != pixmap->drawable.height)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* Window must be same region as toplevel window */
|
|
|
|
if ( !RegionEqual(&present_window->winSize, &toplvl_window->winSize) )
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* Can't flip if window clipped by children */
|
|
|
|
if (!RegionEqual(&present_window->clipList, &present_window->winSize))
|
|
|
|
return FALSE;
|
|
|
|
|
2020-12-03 23:57:51 +01:00
|
|
|
if (!xwl_glamor_check_flip(pixmap))
|
|
|
|
return FALSE;
|
|
|
|
|
2020-08-27 18:36:15 +02:00
|
|
|
/* Can't flip if the window pixmap doesn't match the xwl_window parent
|
|
|
|
* window's, e.g. because a client redirected this window or one of its
|
|
|
|
* parents.
|
|
|
|
*/
|
|
|
|
if (screen->GetWindowPixmap(xwl_window->window) != screen->GetWindowPixmap(present_window))
|
|
|
|
return FALSE;
|
|
|
|
|
2018-03-13 16:00:53 +01:00
|
|
|
/*
|
|
|
|
* 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;
|
|
|
|
}
|
|
|
|
|
2021-04-19 18:34:07 +02:00
|
|
|
/*
|
|
|
|
* 'window' is being reconfigured. Check to see if it is involved
|
|
|
|
* in flipping and clean up as necessary.
|
|
|
|
*/
|
|
|
|
static void
|
2021-04-19 12:59:56 +02:00
|
|
|
xwl_present_check_flip_window (WindowPtr window)
|
2021-04-19 18:34:07 +02:00
|
|
|
{
|
|
|
|
struct xwl_present_window *xwl_present_window = xwl_present_window_priv(window);
|
|
|
|
present_window_priv_ptr window_priv = present_window_priv(window);
|
|
|
|
present_vblank_ptr flip_pending;
|
|
|
|
present_vblank_ptr flip_active;
|
|
|
|
present_vblank_ptr vblank;
|
|
|
|
PresentFlipReason reason;
|
|
|
|
|
|
|
|
/* If this window hasn't ever been used with Present, it can't be
|
|
|
|
* flipping
|
|
|
|
*/
|
|
|
|
if (!xwl_present_window || !window_priv)
|
|
|
|
return;
|
|
|
|
|
2021-05-06 18:42:46 +02:00
|
|
|
flip_pending = xwl_present_get_pending_flip(xwl_present_window);
|
2021-04-19 18:34:07 +02:00
|
|
|
flip_active = xwl_present_window->flip_active;
|
|
|
|
|
|
|
|
if (flip_pending) {
|
|
|
|
if (!xwl_present_check_flip(flip_pending->crtc, flip_pending->window, flip_pending->pixmap,
|
|
|
|
flip_pending->sync_flip, flip_pending->valid, 0, 0, NULL))
|
2021-05-06 18:42:46 +02:00
|
|
|
flip_pending->abort_flip = TRUE;
|
2021-04-19 18:34:07 +02:00
|
|
|
} else if (flip_active) {
|
|
|
|
if (!xwl_present_check_flip(flip_active->crtc, flip_active->window, flip_active->pixmap,
|
|
|
|
flip_active->sync_flip, flip_active->valid, 0, 0, NULL))
|
2021-04-19 18:41:59 +02:00
|
|
|
xwl_present_flips_stop(window);
|
2021-04-19 18:34:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Now check any queued vblanks */
|
|
|
|
xorg_list_for_each_entry(vblank, &window_priv->vblank, window_list) {
|
|
|
|
if (vblank->queued && vblank->flip &&
|
|
|
|
!xwl_present_check_flip(vblank->crtc, window, vblank->pixmap,
|
|
|
|
vblank->sync_flip, vblank->valid, 0, 0, &reason)) {
|
|
|
|
vblank->flip = FALSE;
|
|
|
|
vblank->reason = reason;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-23 12:59:55 +02:00
|
|
|
/*
|
|
|
|
* Clean up any pending or current flips for this window
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
xwl_present_clear_window_flip(WindowPtr window)
|
|
|
|
{
|
|
|
|
/* xwl_present_cleanup cleaned up everything */
|
|
|
|
}
|
|
|
|
|
2018-03-13 16:00:53 +01:00
|
|
|
static Bool
|
|
|
|
xwl_present_flip(WindowPtr present_window,
|
|
|
|
RRCrtcPtr crtc,
|
|
|
|
uint64_t event_id,
|
|
|
|
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
|
|
|
struct wl_buffer *buffer;
|
2021-04-23 12:59:55 +02:00
|
|
|
struct xwl_present_event *event = xwl_present_event_from_id(event_id);
|
2018-03-13 16:00:53 +01:00
|
|
|
|
2018-05-04 03:07:31 +02:00
|
|
|
if (!xwl_window)
|
|
|
|
return FALSE;
|
|
|
|
|
2021-03-29 15:01:15 +02:00
|
|
|
buffer = xwl_glamor_pixmap_get_wl_buffer(pixmap);
|
|
|
|
if (!buffer) {
|
|
|
|
ErrorF("present: Error getting buffer\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2018-03-13 16:00:53 +01:00
|
|
|
damage_box = RegionExtents(damage);
|
|
|
|
|
2020-06-19 18:10:18 +02:00
|
|
|
pixmap->refcnt++;
|
2018-03-13 16:00:53 +01:00
|
|
|
|
2020-06-19 18:10:18 +02:00
|
|
|
event->pixmap = pixmap;
|
2018-03-13 16:00:53 +01:00
|
|
|
|
2019-10-30 13:17:34 +01:00
|
|
|
xwl_pixmap_set_buffer_release_cb(pixmap, xwl_present_buffer_release, event);
|
2018-03-13 16:00:53 +01:00
|
|
|
|
|
|
|
/* We can flip directly to the main surface (full screen window without clips) */
|
|
|
|
wl_surface_attach(xwl_window->surface, buffer, 0, 0);
|
2020-09-03 13:17:06 +02:00
|
|
|
wl_surface_set_buffer_scale(xwl_window->surface,
|
|
|
|
xwl_window->xwl_screen->global_output_scale);
|
2018-03-13 16:00:53 +01:00
|
|
|
|
2019-11-27 18:04:06 +01:00
|
|
|
if (!xwl_window->frame_callback)
|
|
|
|
xwl_window_create_frame_callback(xwl_window);
|
|
|
|
|
|
|
|
if (xorg_list_is_empty(&xwl_present_window->frame_callback_list)) {
|
|
|
|
xorg_list_add(&xwl_present_window->frame_callback_list,
|
|
|
|
&xwl_window->frame_callback_list);
|
2018-03-13 16:00:53 +01:00
|
|
|
}
|
|
|
|
|
2018-11-01 18:44:24 +01:00
|
|
|
/* Realign timer */
|
|
|
|
xwl_present_reset_timer(xwl_present_window);
|
|
|
|
|
2020-03-17 12:58:12 +01:00
|
|
|
xwl_surface_damage(xwl_window->xwl_screen, xwl_window->surface,
|
2020-07-08 17:08:55 +02:00
|
|
|
damage_box->x1 - present_window->drawable.x,
|
|
|
|
damage_box->y1 - present_window->drawable.y,
|
2019-07-02 12:03:12 +02:00
|
|
|
damage_box->x2 - damage_box->x1,
|
|
|
|
damage_box->y2 - damage_box->y1);
|
2018-03-13 16:00:53 +01:00
|
|
|
|
|
|
|
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,
|
2021-05-12 15:25:51 +02:00
|
|
|
&event->vblank);
|
2018-10-18 17:42:01 +02:00
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
2021-04-19 19:02:32 +02:00
|
|
|
/*
|
|
|
|
* Once the required MSC has been reached, execute the pending request.
|
|
|
|
*
|
|
|
|
* For requests to actually present something, either blt contents to
|
|
|
|
* the window pixmap or queue a window buffer swap on the backend.
|
|
|
|
*
|
|
|
|
* For requests to just get the current MSC/UST combo, skip that part and
|
|
|
|
* go straight to event delivery.
|
|
|
|
*/
|
|
|
|
static void
|
2021-04-19 12:59:56 +02:00
|
|
|
xwl_present_execute(present_vblank_ptr vblank, uint64_t ust, uint64_t crtc_msc)
|
2021-04-19 19:02:32 +02:00
|
|
|
{
|
|
|
|
WindowPtr window = vblank->window;
|
|
|
|
struct xwl_present_window *xwl_present_window = xwl_present_window_get_priv(window);
|
2021-05-06 18:42:46 +02:00
|
|
|
present_vblank_ptr flip_pending = xwl_present_get_pending_flip(xwl_present_window);
|
2021-04-19 19:02:32 +02:00
|
|
|
|
2021-05-07 18:16:23 +02:00
|
|
|
xorg_list_del(&vblank->event_queue);
|
|
|
|
|
2021-04-19 19:02:32 +02:00
|
|
|
if (present_execute_wait(vblank, crtc_msc))
|
|
|
|
return;
|
|
|
|
|
2021-05-06 18:42:46 +02:00
|
|
|
if (flip_pending && vblank->flip && vblank->pixmap && vblank->window) {
|
|
|
|
DebugPresent(("\tr %" PRIu64 " %p (pending %p)\n",
|
|
|
|
vblank->event_id, vblank, flip_pending));
|
|
|
|
xorg_list_append(&vblank->event_queue, &xwl_present_window->flip_queue);
|
|
|
|
vblank->flip_ready = TRUE;
|
|
|
|
return;
|
2021-04-19 19:02:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
vblank->queued = FALSE;
|
|
|
|
|
|
|
|
if (vblank->pixmap && vblank->window) {
|
|
|
|
ScreenPtr screen = window->drawable.pScreen;
|
|
|
|
|
|
|
|
if (vblank->flip) {
|
|
|
|
RegionPtr damage;
|
|
|
|
|
|
|
|
DebugPresent(("\tf %" PRIu64 " %p %" PRIu64 ": %08" PRIx32 " -> %08" PRIx32 "\n",
|
|
|
|
vblank->event_id, vblank, crtc_msc,
|
|
|
|
vblank->pixmap->drawable.id, vblank->window->drawable.id));
|
|
|
|
|
|
|
|
/* Set update region as damaged */
|
|
|
|
if (vblank->update) {
|
|
|
|
damage = RegionDuplicate(vblank->update);
|
|
|
|
/* Translate update region to screen space */
|
|
|
|
assert(vblank->x_off == 0 && vblank->y_off == 0);
|
|
|
|
RegionTranslate(damage, window->drawable.x, window->drawable.y);
|
|
|
|
RegionIntersect(damage, damage, &window->clipList);
|
|
|
|
} else
|
|
|
|
damage = RegionDuplicate(&window->clipList);
|
|
|
|
|
|
|
|
if (xwl_present_flip(vblank->window, vblank->crtc, vblank->event_id,
|
2021-05-10 18:33:43 +02:00
|
|
|
vblank->pixmap, vblank->sync_flip, damage)) {
|
2021-04-19 12:59:56 +02:00
|
|
|
WindowPtr toplvl_window = xwl_present_toplvl_pixmap_window(vblank->window);
|
2021-04-19 19:02:32 +02:00
|
|
|
PixmapPtr old_pixmap = screen->GetWindowPixmap(window);
|
|
|
|
|
|
|
|
/* Replace window pixmap with flip pixmap */
|
|
|
|
#ifdef COMPOSITE
|
|
|
|
vblank->pixmap->screen_x = old_pixmap->screen_x;
|
|
|
|
vblank->pixmap->screen_y = old_pixmap->screen_y;
|
|
|
|
#endif
|
|
|
|
present_set_tree_pixmap(toplvl_window, old_pixmap, vblank->pixmap);
|
|
|
|
vblank->pixmap->refcnt++;
|
|
|
|
dixDestroyPixmap(old_pixmap, old_pixmap->drawable.id);
|
|
|
|
|
|
|
|
/* Report damage */
|
|
|
|
DamageDamageRegion(&vblank->window->drawable, damage);
|
|
|
|
RegionDestroy(damage);
|
2021-05-06 18:42:46 +02:00
|
|
|
|
|
|
|
/* Put pending flip at the flip queue head */
|
|
|
|
xorg_list_add(&vblank->event_queue, &xwl_present_window->flip_queue);
|
2021-04-19 19:02:32 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
vblank->flip = FALSE;
|
|
|
|
}
|
|
|
|
DebugPresent(("\tc %p %" PRIu64 ": %08" PRIx32 " -> %08" PRIx32 "\n",
|
|
|
|
vblank, crtc_msc, vblank->pixmap->drawable.id, vblank->window->drawable.id));
|
|
|
|
|
2021-05-06 18:42:46 +02:00
|
|
|
if (flip_pending)
|
|
|
|
flip_pending->abort_flip = TRUE;
|
2021-05-11 12:56:53 +02:00
|
|
|
else if (xwl_present_window->flip_active)
|
|
|
|
xwl_present_flips_stop(window);
|
2021-04-19 19:02:32 +02:00
|
|
|
|
|
|
|
present_execute_copy(vblank, crtc_msc);
|
|
|
|
assert(!vblank->queued);
|
|
|
|
|
2021-04-19 18:46:23 +02:00
|
|
|
if (xwl_present_queue_vblank(screen, window, vblank->crtc,
|
|
|
|
vblank->event_id, crtc_msc + 1)
|
2021-04-19 19:02:32 +02:00
|
|
|
== Success) {
|
2021-05-07 17:49:07 +02:00
|
|
|
/* Clear the pixmap field, so this will fall through to present_execute_post next time */
|
|
|
|
dixDestroyPixmap(vblank->pixmap, vblank->pixmap->drawable.id);
|
|
|
|
vblank->pixmap = NULL;
|
2021-04-19 19:02:32 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
present_execute_post(vblank, ust, crtc_msc);
|
|
|
|
}
|
|
|
|
|
2021-04-19 18:51:06 +02:00
|
|
|
static int
|
2021-04-19 12:59:56 +02:00
|
|
|
xwl_present_pixmap(WindowPtr window,
|
|
|
|
PixmapPtr pixmap,
|
|
|
|
CARD32 serial,
|
|
|
|
RegionPtr valid,
|
|
|
|
RegionPtr update,
|
|
|
|
int16_t x_off,
|
|
|
|
int16_t y_off,
|
|
|
|
RRCrtcPtr target_crtc,
|
|
|
|
SyncFence *wait_fence,
|
|
|
|
SyncFence *idle_fence,
|
|
|
|
uint32_t options,
|
|
|
|
uint64_t target_window_msc,
|
|
|
|
uint64_t divisor,
|
|
|
|
uint64_t remainder,
|
|
|
|
present_notify_ptr notifies,
|
|
|
|
int num_notifies)
|
2021-04-19 18:51:06 +02:00
|
|
|
{
|
|
|
|
uint64_t ust = 0;
|
|
|
|
uint64_t target_msc;
|
|
|
|
uint64_t crtc_msc = 0;
|
|
|
|
int ret;
|
|
|
|
present_vblank_ptr vblank, tmp;
|
|
|
|
ScreenPtr screen = window->drawable.pScreen;
|
|
|
|
present_window_priv_ptr window_priv = present_get_window_priv(window, TRUE);
|
|
|
|
present_screen_priv_ptr screen_priv = present_screen_priv(screen);
|
2021-04-23 12:59:55 +02:00
|
|
|
struct xwl_present_event *event;
|
2021-04-19 18:51:06 +02:00
|
|
|
|
|
|
|
if (!window_priv)
|
|
|
|
return BadAlloc;
|
|
|
|
|
|
|
|
target_crtc = xwl_present_get_crtc(screen_priv, window);
|
|
|
|
|
2021-04-19 18:53:36 +02:00
|
|
|
ret = xwl_present_get_ust_msc(screen, window, &ust, &crtc_msc);
|
2021-04-19 18:51:06 +02:00
|
|
|
|
2021-05-11 12:56:53 +02:00
|
|
|
xwl_present_update_window_crtc(window_priv, target_crtc, crtc_msc);
|
2021-04-19 18:51:06 +02:00
|
|
|
|
|
|
|
if (ret == Success) {
|
|
|
|
/* Stash the current MSC away in case we need it later
|
|
|
|
*/
|
|
|
|
window_priv->msc = crtc_msc;
|
|
|
|
}
|
|
|
|
|
|
|
|
target_msc = present_get_target_msc(target_window_msc + window_priv->msc_offset,
|
|
|
|
crtc_msc,
|
|
|
|
divisor,
|
|
|
|
remainder,
|
|
|
|
options);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Look for a matching presentation already on the list...
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (!update && pixmap) {
|
|
|
|
xorg_list_for_each_entry_safe(vblank, tmp, &window_priv->vblank, window_list) {
|
|
|
|
|
|
|
|
if (!vblank->pixmap)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!vblank->queued)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (vblank->target_msc != target_msc)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
present_vblank_scrap(vblank);
|
|
|
|
if (vblank->flip_ready)
|
2021-04-19 12:59:56 +02:00
|
|
|
xwl_present_re_execute(vblank);
|
2021-04-19 18:51:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-23 12:59:55 +02:00
|
|
|
event = calloc(1, sizeof(*event));
|
|
|
|
if (!event)
|
2021-04-19 18:51:06 +02:00
|
|
|
return BadAlloc;
|
|
|
|
|
2021-04-23 12:59:55 +02:00
|
|
|
vblank = &event->vblank;
|
|
|
|
if (!present_vblank_init(vblank, window, pixmap, serial, valid, update, x_off, y_off,
|
|
|
|
target_crtc, wait_fence, idle_fence, options, XWL_PRESENT_CAPS,
|
|
|
|
notifies, num_notifies, target_msc, crtc_msc)) {
|
|
|
|
present_vblank_destroy(vblank);
|
|
|
|
return BadAlloc;
|
|
|
|
}
|
|
|
|
|
|
|
|
vblank->event_id = (uintptr_t)event;
|
|
|
|
|
2021-04-19 12:59:56 +02:00
|
|
|
/* Xwayland presentations always complete (at least) one frame after they
|
2021-04-19 18:51:06 +02:00
|
|
|
* are executed
|
|
|
|
*/
|
|
|
|
vblank->exec_msc = vblank->target_msc - 1;
|
|
|
|
|
|
|
|
vblank->queued = TRUE;
|
|
|
|
if (crtc_msc < vblank->exec_msc) {
|
2021-04-19 18:46:23 +02:00
|
|
|
if (xwl_present_queue_vblank(screen, window, target_crtc, vblank->event_id, vblank->exec_msc) == Success)
|
2021-04-19 18:51:06 +02:00
|
|
|
return Success;
|
2021-04-19 18:46:23 +02:00
|
|
|
|
2021-04-19 18:51:06 +02:00
|
|
|
DebugPresent(("present_queue_vblank failed\n"));
|
|
|
|
}
|
|
|
|
|
2021-04-19 12:59:56 +02:00
|
|
|
xwl_present_execute(vblank, ust, crtc_msc);
|
2021-04-19 18:51:06 +02:00
|
|
|
return Success;
|
|
|
|
}
|
|
|
|
|
2018-11-01 18:24:28 +01:00
|
|
|
void
|
2020-03-17 11:45:22 +01:00
|
|
|
xwl_present_unrealize_window(struct xwl_present_window *xwl_present_window)
|
2018-11-01 18:24:28 +01:00
|
|
|
{
|
|
|
|
/* The pending frame callback may never be called, so drop it and shorten
|
|
|
|
* the frame timer interval.
|
|
|
|
*/
|
2019-11-27 18:04:06 +01:00
|
|
|
xorg_list_del(&xwl_present_window->frame_callback_list);
|
2018-11-01 18:24:28 +01:00
|
|
|
xwl_present_reset_timer(xwl_present_window);
|
|
|
|
}
|
|
|
|
|
2018-03-13 16:00:53 +01:00
|
|
|
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);
|
2021-04-20 19:01:12 +02:00
|
|
|
present_screen_priv_ptr screen_priv;
|
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
|
|
|
|
2020-12-03 23:57:51 +01:00
|
|
|
if (!xwl_screen->glamor || !xwl_screen->egl_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;
|
|
|
|
|
2021-04-20 19:01:12 +02:00
|
|
|
if (!present_screen_register_priv_keys())
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (present_screen_priv(screen))
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
screen_priv = present_screen_priv_init(screen);
|
|
|
|
if (!screen_priv)
|
|
|
|
return FALSE;
|
|
|
|
|
2018-05-04 03:07:31 +02:00
|
|
|
if (!dixRegisterPrivateKey(&xwl_present_window_private_key, PRIVATE_WINDOW, 0))
|
|
|
|
return FALSE;
|
|
|
|
|
2021-04-19 18:26:55 +02:00
|
|
|
screen_priv->query_capabilities = xwl_present_query_capabilities;
|
2021-04-19 18:51:06 +02:00
|
|
|
screen_priv->get_crtc = xwl_present_get_crtc;
|
2021-04-20 19:01:12 +02:00
|
|
|
|
2021-04-19 18:34:07 +02:00
|
|
|
screen_priv->check_flip = xwl_present_check_flip;
|
2021-04-19 12:59:56 +02:00
|
|
|
screen_priv->check_flip_window = xwl_present_check_flip_window;
|
|
|
|
screen_priv->clear_window_flip = xwl_present_clear_window_flip;
|
2021-04-20 19:01:12 +02:00
|
|
|
|
2021-04-19 12:59:56 +02:00
|
|
|
screen_priv->present_pixmap = xwl_present_pixmap;
|
2021-04-19 18:46:23 +02:00
|
|
|
screen_priv->queue_vblank = xwl_present_queue_vblank;
|
2021-04-19 18:06:22 +02:00
|
|
|
screen_priv->flush = xwl_present_flush;
|
2021-04-19 12:59:56 +02:00
|
|
|
screen_priv->re_execute = xwl_present_re_execute;
|
2021-04-20 19:01:12 +02:00
|
|
|
|
2021-04-19 18:01:52 +02:00
|
|
|
screen_priv->abort_vblank = xwl_present_abort_vblank;
|
2021-04-20 19:01:12 +02:00
|
|
|
|
|
|
|
return TRUE;
|
2018-03-13 16:00:53 +01:00
|
|
|
}
|