return false;
if (a->vdisplay != b->vdisplay)
return false;
+ if (a->vrefresh != b->vrefresh)
+ return false;
return true;
}
pipe = crtc->pipe;
if (pipe) {
if (pipe->base.width != crtc->set.mode.hdisplay ||
- pipe->base.height != crtc->set.mode.vdisplay) {
+ pipe->base.height != crtc->set.mode.vdisplay ||
+ pipe->base.vrefresh != crtc->set.mode.vrefresh) {
grdev_pipe_free(&pipe->base);
crtc->pipe = NULL;
pipe = NULL;
pipe->base.flipping = false;
pipe->base.flip = false;
+ /* We cannot schedule dummy page-flips on pipes, hence, the
+ * application would have to schedule their own frame-timers.
+ * To avoid duplicating that everywhere, we schedule our own
+ * timer and raise a fake FRAME event when it fires. */
+ grdev_pipe_schedule(&pipe->base, 1);
+
if (!pipe->base.back) {
for (i = 0; i < pipe->base.max_fbs; ++i) {
if (!pipe->base.fbs[i])
fb->flipid = cnt;
*slot = NULL;
+ /* Raise fake FRAME event if it takes longer than 2
+ * frames to receive the pageflip event. We assume the
+ * queue ran over or some other error happened. */
+ grdev_pipe_schedule(&pipe->base, 2);
+
if (!pipe->base.back) {
for (i = 0; i < pipe->base.max_fbs; ++i) {
if (!pipe->base.fbs[i])
pipe->crtc = crtc;
pipe->base.width = mode->hdisplay;
pipe->base.height = mode->vdisplay;
+ pipe->base.vrefresh = mode->vrefresh ? : 25;
grdrm_pipe_name(name, crtc);
r = grdev_pipe_add(&pipe->base, name, n_fbs);
return hashmap_get(card->pipe_map, name);
}
+static int pipe_vsync_fn(sd_event_source *src, uint64_t usec, void *userdata) {
+ grdev_pipe *pipe = userdata;
+
+ grdev_pipe_frame(pipe);
+ return 0;
+}
+
int grdev_pipe_add(grdev_pipe *pipe, const char *name, size_t n_fbs) {
int r;
assert_return(!pipe->cache, -EINVAL);
assert_return(pipe->width > 0, -EINVAL);
assert_return(pipe->height > 0, -EINVAL);
+ assert_return(pipe->vrefresh > 0, -EINVAL);
assert_return(!pipe->enabled, -EINVAL);
assert_return(!pipe->running, -EINVAL);
assert_return(name, -EINVAL);
if (r < 0)
return r;
+ r = sd_event_add_time(pipe->card->session->context->event,
+ &pipe->vsync_src,
+ CLOCK_MONOTONIC,
+ 0,
+ 10 * USEC_PER_MSEC,
+ pipe_vsync_fn,
+ pipe);
+ if (r < 0)
+ return r;
+
+ r = sd_event_source_set_enabled(pipe->vsync_src, SD_EVENT_OFF);
+ if (r < 0)
+ return r;
+
r = hashmap_put(pipe->card->pipe_map, pipe->name, pipe);
if (r < 0)
return r;
tmp = *pipe;
pipe->vtable->free(pipe);
+ sd_event_source_unref(tmp.vsync_src);
grdev_tile_free(tmp.tile);
card_modified(tmp.card);
free(tmp.fbs);
pipe->running = running;
/* runtime events for unused pipes are not interesting */
- if (pipe->cache) {
+ if (pipe->cache && pipe->enabled) {
grdev_display *display = pipe->tile->display;
assert(display);
- if (running) {
- if (pipe->enabled)
- session_frame(display->session, display);
- } else {
+ if (running)
+ session_frame(display->session, display);
+ else
pipe->cache->incomplete = true;
- }
}
}
assert(pipe);
/* if pipe is unused, ignore any frame events */
- if (!pipe->cache)
+ if (!pipe->cache || !pipe->enabled)
return;
display = pipe->tile->display;
assert(display);
- if (pipe->enabled)
- session_frame(display->session, display);
+ grdev_pipe_schedule(pipe, 0);
+ session_frame(display->session, display);
+}
+
+void grdev_pipe_schedule(grdev_pipe *pipe, uint64_t frames) {
+ int r;
+ uint64_t ts;
+
+ if (!frames) {
+ sd_event_source_set_enabled(pipe->vsync_src, SD_EVENT_OFF);
+ return;
+ }
+
+ r = sd_event_now(pipe->card->session->context->event, CLOCK_MONOTONIC, &ts);
+ if (r < 0)
+ goto error;
+
+ ts += frames * USEC_PER_MSEC * 1000ULL / pipe->vrefresh;
+
+ r = sd_event_source_set_time(pipe->vsync_src, ts);
+ if (r < 0)
+ goto error;
+
+ r = sd_event_source_set_enabled(pipe->vsync_src, SD_EVENT_ONESHOT);
+ if (r < 0)
+ goto error;
+
+ return;
+
+error:
+ log_debug("grdev: %s/%s/%s: cannot schedule vsync timer: %s",
+ pipe->card->session->name, pipe->card->name, pipe->name, strerror(-r));
}
/*