[PATCH 2/5] present: Put vblank and execute code in separate files
Roman Gilg
subdiff at gmail.com
Tue Aug 29 15:24:29 UTC 2017
The vblank and execute functions aren't static anymore. Therefore we
can put them into separate files in order to increase clarity.
Signed-off-by: Roman Gilg <subdiff at gmail.com>
---
present/Makefile.am | 4 +-
present/meson.build | 2 +
present/present.c | 264 ----------------------------------------------
present/present_execute.c | 124 ++++++++++++++++++++++
present/present_vblank.c | 200 +++++++++++++++++++++++++++++++++++
5 files changed, 329 insertions(+), 265 deletions(-)
create mode 100644 present/present_execute.c
create mode 100644 present/present_vblank.c
diff --git a/present/Makefile.am b/present/Makefile.am
index 14b2fac..543d7ff 100644
--- a/present/Makefile.am
+++ b/present/Makefile.am
@@ -7,12 +7,14 @@ libpresent_la_SOURCES = \
present.h \
present.c \
present_event.c \
+ present_execute.c \
present_fake.c \
present_fence.c \
present_notify.c \
present_priv.h \
present_request.c \
present_screen.c \
- present_scrmode.c
+ present_scrmode.c \
+ present_vblank.c
sdk_HEADERS = present.h presentext.h
diff --git a/present/meson.build b/present/meson.build
index 4296327..2cf1bf8 100644
--- a/present/meson.build
+++ b/present/meson.build
@@ -1,12 +1,14 @@
srcs_present = [
'present.c',
'present_event.c',
+ 'present_execute.c',
'present_fake.c',
'present_fence.c',
'present_notify.c',
'present_request.c',
'present_screen.c',
'present_scrmode.c',
+ 'present_vblank.c',
]
libxserver_present = static_library('libxserver_present',
diff --git a/present/present.c b/present/present.c
index 5a2fd93..9c1bc49 100644
--- a/present/present.c
+++ b/present/present.c
@@ -80,22 +80,6 @@ present_copy_region(DrawablePtr drawable,
}
void
-present_vblank_notify(present_vblank_ptr vblank, CARD8 kind, CARD8 mode, uint64_t ust, uint64_t crtc_msc)
-{
- int n;
-
- if (vblank->window)
- present_send_complete_notify(vblank->window, kind, mode, vblank->serial, ust, crtc_msc - vblank->msc_offset);
- for (n = 0; n < vblank->num_notifies; n++) {
- WindowPtr window = vblank->notifies[n].window;
- CARD32 serial = vblank->notifies[n].serial;
-
- if (window)
- present_send_complete_notify(window, kind, mode, serial, ust, crtc_msc - vblank->msc_offset);
- }
-}
-
-void
present_pixmap_idle(PixmapPtr pixmap, WindowPtr window, CARD32 serial, struct present_fence *present_fence)
{
if (present_fence)
@@ -169,97 +153,6 @@ present_set_tree_pixmap(WindowPtr window,
TraverseTree(window, present_set_tree_pixmap_visit, &visit);
}
-/*
- * Called when the wait fence is triggered; just gets the current msc/ust and
- * calls the proper execute again. That will re-check the fence and pend the
- * request again if it's still not actually ready
- */
-static void
-present_wait_fence_triggered(void *param)
-{
- present_vblank_ptr vblank = param;
- ScreenPtr screen = vblank->screen;
- present_screen_priv_ptr screen_priv = present_screen_priv(screen);
-
- screen_priv->re_execute(vblank);
-}
-
-Bool
-present_execute_wait(present_vblank_ptr vblank, uint64_t crtc_msc)
-{
- WindowPtr window = vblank->window;
- ScreenPtr screen = window->drawable.pScreen;
- present_screen_priv_ptr screen_priv = present_screen_priv(screen);
-
- if (vblank->requeue) {
- vblank->requeue = FALSE;
- if (msc_is_after(vblank->target_msc, crtc_msc) &&
- Success == screen_priv->queue_vblank(screen,
- vblank->window,
- vblank->crtc,
- vblank->event_id,
- vblank->target_msc))
- return TRUE;
- }
-
- if (vblank->wait_fence) {
- if (!present_fence_check_triggered(vblank->wait_fence)) {
- present_fence_set_callback(vblank->wait_fence, present_wait_fence_triggered, vblank);
- return TRUE;
- }
- }
- return FALSE;
-}
-
-void
-present_execute_copy(present_vblank_ptr vblank, uint64_t crtc_msc)
-{
- WindowPtr window = vblank->window;
- ScreenPtr screen = window->drawable.pScreen;
- present_screen_priv_ptr screen_priv = present_screen_priv(screen);
-
- /* If present_flip failed, we may have to requeue for the target MSC */
- if (vblank->target_msc == crtc_msc + 1 &&
- Success == screen_priv->queue_vblank(screen,
- vblank->window,
- vblank->crtc,
- vblank->event_id,
- vblank->target_msc)) {
- vblank->queued = TRUE;
- return;
- }
-
- present_copy_region(&window->drawable, vblank->pixmap, vblank->update, vblank->x_off, vblank->y_off);
-
- /* present_copy_region sticks the region into a scratch GC,
- * which is then freed, freeing the region
- */
- vblank->update = NULL;
- screen_priv->flush(window);
-
- present_pixmap_idle(vblank->pixmap, vblank->window, vblank->serial, vblank->idle_fence);
-}
-
-void
-present_execute_post(present_vblank_ptr vblank, uint64_t ust, uint64_t crtc_msc)
-{
- uint8_t mode;
-
- /* Compute correct CompleteMode
- */
- if (vblank->kind == PresentCompleteKindPixmap) {
- if (vblank->pixmap && vblank->window)
- mode = PresentCompleteModeCopy;
- else
- mode = PresentCompleteModeSkip;
- }
- else
- mode = PresentCompleteModeCopy;
-
- present_vblank_notify(vblank, vblank->kind, mode, ust, crtc_msc);
- present_vblank_destroy(vblank);
-}
-
void
present_adjust_timings(uint32_t options,
uint64_t *crtc_msc,
@@ -347,160 +240,3 @@ present_notify_msc(WindowPtr window,
divisor == 0 ? PresentOptionAsync : 0,
target_msc, divisor, remainder, NULL, 0);
}
-
-present_vblank_ptr
-present_vblank_create(present_window_priv_ptr window_priv,
- 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,
- const uint32_t *capabilities,
- present_notify_ptr notifies,
- int num_notifies,
- uint64_t *target_msc,
- uint64_t crtc_msc)
-{
- WindowPtr window = window_priv->window;
- ScreenPtr screen = window->drawable.pScreen;
- present_screen_priv_ptr screen_priv = present_screen_priv(screen);
- present_vblank_ptr vblank;
-
- vblank = calloc (1, sizeof (present_vblank_rec));
- if (!vblank)
- return NULL;
-
- xorg_list_append(&vblank->window_list, &window_priv->vblank_queue);
- xorg_list_init(&vblank->event_queue);
-
- vblank->screen = screen;
- vblank->window = window;
- vblank->pixmap = pixmap;
-
- screen_priv->create_event_id(window_priv, vblank);
-
- if (pixmap) {
- vblank->kind = PresentCompleteKindPixmap;
- pixmap->refcnt++;
- } else
- vblank->kind = PresentCompleteKindNotifyMSC;
-
- vblank->serial = serial;
-
- if (valid) {
- vblank->valid = RegionDuplicate(valid);
- if (!vblank->valid)
- goto no_mem;
- }
- if (update) {
- vblank->update = RegionDuplicate(update);
- if (!vblank->update)
- goto no_mem;
- }
-
- vblank->x_off = x_off;
- vblank->y_off = y_off;
- vblank->target_msc = *target_msc;
- vblank->crtc = target_crtc;
- vblank->msc_offset = window_priv->msc_offset;
- vblank->notifies = notifies;
- vblank->num_notifies = num_notifies;
-
- if (pixmap != NULL &&
- !(options & PresentOptionCopy) &&
- capabilities) {
- if (msc_is_after(*target_msc, crtc_msc) &&
- screen_priv->check_flip (target_crtc, window, pixmap, TRUE, valid, x_off, y_off))
- {
- vblank->flip = TRUE;
- vblank->sync_flip = TRUE;
- *target_msc = *target_msc - 1;
- } else if ((*capabilities & PresentCapabilityAsync) &&
- screen_priv->check_flip (target_crtc, window, pixmap, FALSE, valid, x_off, y_off))
- {
- vblank->flip = TRUE;
- }
- }
-
- if (wait_fence) {
- vblank->wait_fence = present_fence_create(wait_fence);
- if (!vblank->wait_fence)
- goto no_mem;
- }
-
- if (idle_fence) {
- vblank->idle_fence = present_fence_create(idle_fence);
- if (!vblank->idle_fence)
- goto no_mem;
- }
-
- if (pixmap)
- DebugPresent(("q %lld %p %8lld: %08lx -> %08lx (crtc %p) flip %d vsync %d serial %d\n",
- vblank->event_id, vblank, *target_msc,
- vblank->pixmap->drawable.id, vblank->window->drawable.id,
- target_crtc, vblank->flip, vblank->sync_flip, vblank->serial));
-
- return vblank;
-
-no_mem:
- vblank->notifies = NULL;
- present_vblank_destroy(vblank);
- return NULL;
-}
-
-void
-present_vblank_scrap(present_vblank_ptr vblank)
-{
- DebugPresent(("\tx %lld %p %8lld: %08lx -> %08lx (crtc %p)\n",
- vblank->event_id, vblank, vblank->target_msc,
- vblank->pixmap->drawable.id, vblank->window->drawable.id,
- vblank->crtc));
-
- present_pixmap_idle(vblank->pixmap, vblank->window, vblank->serial, vblank->idle_fence);
- present_fence_destroy(vblank->idle_fence);
- dixDestroyPixmap(vblank->pixmap, vblank->pixmap->drawable.id);
-
- vblank->pixmap = NULL;
- vblank->idle_fence = NULL;
- vblank->flip = FALSE;
-}
-
-void
-present_vblank_destroy(present_vblank_ptr vblank)
-{
- /* Remove vblank from window and screen lists */
- xorg_list_del(&vblank->window_list);
-
- xorg_list_del(&vblank->event_queue);
-
- DebugPresent(("\td %lld %p %8lld: %08lx -> %08lx\n",
- vblank->event_id, vblank, vblank->target_msc,
- vblank->pixmap ? vblank->pixmap->drawable.id : 0,
- vblank->window ? vblank->window->drawable.id : 0));
-
- /* Drop pixmap reference */
- if (vblank->pixmap && vblank->pixmap->refcnt > 1)
- dixDestroyPixmap(vblank->pixmap, vblank->pixmap->drawable.id);
-
- /* Free regions */
- if (vblank->valid)
- RegionDestroy(vblank->valid);
- if (vblank->update)
- RegionDestroy(vblank->update);
-
- if (vblank->wait_fence)
- present_fence_destroy(vblank->wait_fence);
-
- if (vblank->idle_fence)
- present_fence_destroy(vblank->idle_fence);
-
- if (vblank->notifies)
- present_destroy_notifies(vblank->notifies, vblank->num_notifies);
-
- free(vblank);
-}
diff --git a/present/present_execute.c b/present/present_execute.c
new file mode 100644
index 0000000..0123ec9
--- /dev/null
+++ b/present/present_execute.c
@@ -0,0 +1,124 @@
+/*
+ * Copyright © 2013 Keith Packard
+ *
+ * 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.
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include "present_priv.h"
+#include <gcstruct.h>
+#include <misync.h>
+#include <misyncstr.h>
+#ifdef MONOTONIC_CLOCK
+#include <time.h>
+#endif
+
+/*
+ * Called when the wait fence is triggered; just gets the current msc/ust and
+ * calls the proper execute again. That will re-check the fence and pend the
+ * request again if it's still not actually ready
+ */
+static void
+present_wait_fence_triggered(void *param)
+{
+ present_vblank_ptr vblank = param;
+ ScreenPtr screen = vblank->screen;
+ present_screen_priv_ptr screen_priv = present_screen_priv(screen);
+
+ screen_priv->re_execute(vblank);
+}
+
+Bool
+present_execute_wait(present_vblank_ptr vblank, uint64_t crtc_msc)
+{
+ WindowPtr window = vblank->window;
+ ScreenPtr screen = window->drawable.pScreen;
+ present_screen_priv_ptr screen_priv = present_screen_priv(screen);
+
+ if (vblank->requeue) {
+ vblank->requeue = FALSE;
+ if (msc_is_after(vblank->target_msc, crtc_msc) &&
+ Success == screen_priv->queue_vblank(screen,
+ vblank->window,
+ vblank->crtc,
+ vblank->event_id,
+ vblank->target_msc))
+ return TRUE;
+ }
+
+ if (vblank->wait_fence) {
+ if (!present_fence_check_triggered(vblank->wait_fence)) {
+ present_fence_set_callback(vblank->wait_fence, present_wait_fence_triggered, vblank);
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+void
+present_execute_copy(present_vblank_ptr vblank, uint64_t crtc_msc)
+{
+ WindowPtr window = vblank->window;
+ ScreenPtr screen = window->drawable.pScreen;
+ present_screen_priv_ptr screen_priv = present_screen_priv(screen);
+
+ /* If present_flip failed, we may have to requeue for the target MSC */
+ if (vblank->target_msc == crtc_msc + 1 &&
+ Success == screen_priv->queue_vblank(screen,
+ vblank->window,
+ vblank->crtc,
+ vblank->event_id,
+ vblank->target_msc)) {
+ vblank->queued = TRUE;
+ return;
+ }
+
+ present_copy_region(&window->drawable, vblank->pixmap, vblank->update, vblank->x_off, vblank->y_off);
+
+ /* present_copy_region sticks the region into a scratch GC,
+ * which is then freed, freeing the region
+ */
+ vblank->update = NULL;
+ screen_priv->flush(window);
+
+ present_pixmap_idle(vblank->pixmap, vblank->window, vblank->serial, vblank->idle_fence);
+}
+
+void
+present_execute_post(present_vblank_ptr vblank, uint64_t ust, uint64_t crtc_msc)
+{
+ uint8_t mode;
+
+ /* Compute correct CompleteMode
+ */
+ if (vblank->kind == PresentCompleteKindPixmap) {
+ if (vblank->pixmap && vblank->window)
+ mode = PresentCompleteModeCopy;
+ else
+ mode = PresentCompleteModeSkip;
+ }
+ else
+ mode = PresentCompleteModeCopy;
+
+ present_vblank_notify(vblank, vblank->kind, mode, ust, crtc_msc);
+ present_vblank_destroy(vblank);
+}
diff --git a/present/present_vblank.c b/present/present_vblank.c
new file mode 100644
index 0000000..96a9bc6
--- /dev/null
+++ b/present/present_vblank.c
@@ -0,0 +1,200 @@
+/*
+ * Copyright © 2013 Keith Packard
+ *
+ * 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.
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include "present_priv.h"
+
+void
+present_vblank_notify(present_vblank_ptr vblank, CARD8 kind, CARD8 mode, uint64_t ust, uint64_t crtc_msc)
+{
+ int n;
+
+ if (vblank->window)
+ present_send_complete_notify(vblank->window, kind, mode, vblank->serial, ust, crtc_msc - vblank->msc_offset);
+ for (n = 0; n < vblank->num_notifies; n++) {
+ WindowPtr window = vblank->notifies[n].window;
+ CARD32 serial = vblank->notifies[n].serial;
+
+ if (window)
+ present_send_complete_notify(window, kind, mode, serial, ust, crtc_msc - vblank->msc_offset);
+ }
+}
+
+present_vblank_ptr
+present_vblank_create(present_window_priv_ptr window_priv,
+ 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,
+ const uint32_t *capabilities,
+ present_notify_ptr notifies,
+ int num_notifies,
+ uint64_t *target_msc,
+ uint64_t crtc_msc)
+{
+ WindowPtr window = window_priv->window;
+ ScreenPtr screen = window->drawable.pScreen;
+ present_screen_priv_ptr screen_priv = present_screen_priv(screen);
+ present_vblank_ptr vblank;
+
+ vblank = calloc (1, sizeof (present_vblank_rec));
+ if (!vblank)
+ return NULL;
+
+ xorg_list_append(&vblank->window_list, &window_priv->vblank_queue);
+ xorg_list_init(&vblank->event_queue);
+
+ vblank->screen = screen;
+ vblank->window = window;
+ vblank->pixmap = pixmap;
+
+ screen_priv->create_event_id(window_priv, vblank);
+
+ if (pixmap) {
+ vblank->kind = PresentCompleteKindPixmap;
+ pixmap->refcnt++;
+ } else
+ vblank->kind = PresentCompleteKindNotifyMSC;
+
+ vblank->serial = serial;
+
+ if (valid) {
+ vblank->valid = RegionDuplicate(valid);
+ if (!vblank->valid)
+ goto no_mem;
+ }
+ if (update) {
+ vblank->update = RegionDuplicate(update);
+ if (!vblank->update)
+ goto no_mem;
+ }
+
+ vblank->x_off = x_off;
+ vblank->y_off = y_off;
+ vblank->target_msc = *target_msc;
+ vblank->crtc = target_crtc;
+ vblank->msc_offset = window_priv->msc_offset;
+ vblank->notifies = notifies;
+ vblank->num_notifies = num_notifies;
+
+ if (pixmap != NULL &&
+ !(options & PresentOptionCopy) &&
+ capabilities) {
+ if (msc_is_after(*target_msc, crtc_msc) &&
+ screen_priv->check_flip (target_crtc, window, pixmap, TRUE, valid, x_off, y_off))
+ {
+ vblank->flip = TRUE;
+ vblank->sync_flip = TRUE;
+ *target_msc = *target_msc - 1;
+ } else if ((*capabilities & PresentCapabilityAsync) &&
+ screen_priv->check_flip (target_crtc, window, pixmap, FALSE, valid, x_off, y_off))
+ {
+ vblank->flip = TRUE;
+ }
+ }
+
+ if (wait_fence) {
+ vblank->wait_fence = present_fence_create(wait_fence);
+ if (!vblank->wait_fence)
+ goto no_mem;
+ }
+
+ if (idle_fence) {
+ vblank->idle_fence = present_fence_create(idle_fence);
+ if (!vblank->idle_fence)
+ goto no_mem;
+ }
+
+ if (pixmap)
+ DebugPresent(("q %lld %p %8lld: %08lx -> %08lx (crtc %p) flip %d vsync %d serial %d\n",
+ vblank->event_id, vblank, *target_msc,
+ vblank->pixmap->drawable.id, vblank->window->drawable.id,
+ target_crtc, vblank->flip, vblank->sync_flip, vblank->serial));
+
+ return vblank;
+
+no_mem:
+ vblank->notifies = NULL;
+ present_vblank_destroy(vblank);
+ return NULL;
+}
+
+void
+present_vblank_scrap(present_vblank_ptr vblank)
+{
+ DebugPresent(("\tx %lld %p %8lld: %08lx -> %08lx (crtc %p)\n",
+ vblank->event_id, vblank, vblank->target_msc,
+ vblank->pixmap->drawable.id, vblank->window->drawable.id,
+ vblank->crtc));
+
+ present_pixmap_idle(vblank->pixmap, vblank->window, vblank->serial, vblank->idle_fence);
+ present_fence_destroy(vblank->idle_fence);
+ dixDestroyPixmap(vblank->pixmap, vblank->pixmap->drawable.id);
+
+ vblank->pixmap = NULL;
+ vblank->idle_fence = NULL;
+ vblank->flip = FALSE;
+}
+
+void
+present_vblank_destroy(present_vblank_ptr vblank)
+{
+ /* Remove vblank from window and screen lists */
+ xorg_list_del(&vblank->window_list);
+
+ xorg_list_del(&vblank->event_queue);
+
+ DebugPresent(("\td %lld %p %8lld: %08lx -> %08lx\n",
+ vblank->event_id, vblank, vblank->target_msc,
+ vblank->pixmap ? vblank->pixmap->drawable.id : 0,
+ vblank->window ? vblank->window->drawable.id : 0));
+
+ /* Drop pixmap reference */
+ if (vblank->pixmap)
+ dixDestroyPixmap(vblank->pixmap, vblank->pixmap->drawable.id);
+
+ /* Free regions */
+ if (vblank->valid)
+ RegionDestroy(vblank->valid);
+ if (vblank->update)
+ RegionDestroy(vblank->update);
+
+ if (vblank->wait_fence)
+ present_fence_destroy(vblank->wait_fence);
+
+ if (vblank->idle_fence)
+ present_fence_destroy(vblank->idle_fence);
+
+ if (vblank->notifies)
+ present_destroy_notifies(vblank->notifies, vblank->num_notifies);
+
+ free(vblank);
+}
--
2.7.4
More information about the xorg-devel
mailing list