mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 20:36:04 +00:00
fix(session): preserve guest monotonic time after long pauses (#2393)
This commit is contained in:
1 parent
cd05c96d10
commit
01bfe8519e
14 files changed
+519
-13
No files matched your search
@@ -1,5 +1,6 @@
|
||||
add_library(droiddeckwayland SHARED
|
||||
src/compositor.c
|
||||
src/clock_domain.c
|
||||
src/vk_present.c
|
||||
src/effects_chain.c
|
||||
src/cardboard.c
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
#define _GNU_SOURCE
|
||||
#include "clock_domain.h"
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <pthread.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/stat.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static const int64_t *g_shift;
|
||||
static pthread_mutex_t g_control_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
static dev_t g_device;
|
||||
static ino_t g_inode;
|
||||
|
||||
void droiddeck_clock_domain_set_control(const char *path) {
|
||||
int fd;
|
||||
struct stat st;
|
||||
pthread_mutex_lock(&g_control_lock);
|
||||
if (!path || !*path) {
|
||||
const int64_t *previous = g_shift;
|
||||
g_shift = NULL;
|
||||
if (previous) munmap((void *)previous, sizeof(*previous));
|
||||
pthread_mutex_unlock(&g_control_lock);
|
||||
return;
|
||||
}
|
||||
fd = open(path, O_RDONLY | O_CLOEXEC);
|
||||
if (fd < 0 || fstat(fd, &st) != 0 || st.st_size < (off_t)sizeof(int64_t)) {
|
||||
if (fd >= 0) close(fd);
|
||||
pthread_mutex_unlock(&g_control_lock);
|
||||
return;
|
||||
}
|
||||
if (g_shift && st.st_dev == g_device && st.st_ino == g_inode) {
|
||||
close(fd);
|
||||
pthread_mutex_unlock(&g_control_lock);
|
||||
return;
|
||||
}
|
||||
const int64_t *shift = mmap(NULL, sizeof(*shift), PROT_READ, MAP_SHARED, fd, 0);
|
||||
close(fd);
|
||||
if (shift != MAP_FAILED) {
|
||||
g_device = st.st_dev;
|
||||
g_inode = st.st_ino;
|
||||
const int64_t *previous = g_shift;
|
||||
g_shift = shift;
|
||||
if (previous) munmap((void *)previous, sizeof(*previous));
|
||||
}
|
||||
pthread_mutex_unlock(&g_control_lock);
|
||||
}
|
||||
|
||||
static int64_t shift_ns(void) {
|
||||
pthread_mutex_lock(&g_control_lock);
|
||||
const int64_t *mapping = g_shift;
|
||||
int64_t shift = mapping ? __atomic_load_n(mapping, __ATOMIC_RELAXED) : 0;
|
||||
pthread_mutex_unlock(&g_control_lock);
|
||||
return shift > 0 ? shift : 0;
|
||||
}
|
||||
|
||||
int64_t droiddeck_clock_domain_adjust_ns(int64_t value) {
|
||||
int64_t shift = shift_ns();
|
||||
return value > shift ? value - shift : 0;
|
||||
}
|
||||
|
||||
int64_t droiddeck_clock_domain_now_ns(void) {
|
||||
struct timespec ts;
|
||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||
return droiddeck_clock_domain_adjust_ns((int64_t)ts.tv_sec * 1000000000LL + ts.tv_nsec);
|
||||
}
|
||||
|
||||
uint32_t droiddeck_clock_domain_now_ms(void) {
|
||||
return (uint32_t)(droiddeck_clock_domain_now_ns() / 1000000LL);
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
#ifndef DROIDDECK_CLOCK_DOMAIN_H
|
||||
#define DROIDDECK_CLOCK_DOMAIN_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
void droiddeck_clock_domain_set_control(const char *path);
|
||||
int64_t droiddeck_clock_domain_now_ns(void);
|
||||
uint32_t droiddeck_clock_domain_now_ms(void);
|
||||
int64_t droiddeck_clock_domain_adjust_ns(int64_t value);
|
||||
|
||||
#endif
|
||||
@@ -36,6 +36,7 @@
|
||||
#include "droiddeck_ext.h"
|
||||
#include "droiddeck_color.h"
|
||||
#include "compositor_internal.h"
|
||||
#include "clock_domain.h"
|
||||
|
||||
#define WLOGI(...) __android_log_print(ANDROID_LOG_INFO, "DroidDeckWayland", __VA_ARGS__)
|
||||
#define WLOGE(...) __android_log_print(ANDROID_LOG_ERROR, "DroidDeckWayland", __VA_ARGS__)
|
||||
@@ -727,9 +728,7 @@ static void on_pending_buffer_destroyed(struct wl_listener *l, void *data) {
|
||||
static void fire_frames(struct wl_list *frames) {
|
||||
struct wl_resource *cb, *tmp;
|
||||
uint32_t t;
|
||||
struct timespec ts;
|
||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||
t = (uint32_t)(ts.tv_sec * 1000 + ts.tv_nsec / 1000000);
|
||||
t = droiddeck_clock_domain_now_ms();
|
||||
wl_resource_for_each_safe(cb, tmp, frames) {
|
||||
wl_callback_send_done(cb, t);
|
||||
wl_resource_destroy(cb);
|
||||
@@ -1061,6 +1060,7 @@ static int64_t presented_ns(int64_t render_ns) {
|
||||
|
||||
static void feedback_present_all(struct wl_list *list, int64_t t) {
|
||||
struct wl_resource *fb, *tmp;
|
||||
t = droiddeck_clock_domain_adjust_ns(t);
|
||||
uint64_t sec = (uint64_t)(t / 1000000000LL);
|
||||
uint32_t nsec = (uint32_t)(t % 1000000000LL);
|
||||
wl_resource_for_each_safe(fb, tmp, list) {
|
||||
@@ -2493,8 +2493,7 @@ static void on_vsync(int64_t frame_time_ns) {
|
||||
|
||||
|
||||
static uint32_t now_ms(void) {
|
||||
struct timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||
return (uint32_t)(ts.tv_sec * 1000 + ts.tv_nsec / 1000000);
|
||||
return droiddeck_clock_domain_now_ms();
|
||||
}
|
||||
|
||||
static void pointer_set_cursor(struct wl_client *c, struct wl_resource *r, uint32_t serial,
|
||||
@@ -3114,12 +3113,10 @@ static void relative_pointers_pointer_gone(struct wl_resource *pointer) {
|
||||
|
||||
static int send_relative_motion(struct wl_client *client, double dx, double dy) {
|
||||
struct relative_pointer *rp;
|
||||
struct timespec ts;
|
||||
uint64_t ut;
|
||||
int sent = 0;
|
||||
if (dx == 0 && dy == 0) return 0;
|
||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||
ut = (uint64_t)ts.tv_sec * 1000000ULL + (uint64_t)ts.tv_nsec / 1000;
|
||||
ut = (uint64_t)(droiddeck_clock_domain_now_ns() / 1000);
|
||||
wl_list_for_each(rp, &g_relative_pointers, link) {
|
||||
if (!rp->pointer || wl_resource_get_client(rp->pointer) != client) continue;
|
||||
zwp_relative_pointer_v1_send_relative_motion(rp->resource, (uint32_t)(ut >> 32), (uint32_t)ut,
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include "cardboard.h"
|
||||
#include "droiddeck_color.h"
|
||||
#include "gpu_clock_pin.h"
|
||||
#include "clock_domain.h"
|
||||
|
||||
extern int droiddeck_wayland_run(void);
|
||||
extern void droiddeck_wayland_set_scale_mode(int mode, int alignment);
|
||||
@@ -354,6 +355,13 @@ Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeVsync(JNIEnv *env, j
|
||||
droiddeck_wayland_vsync((int64_t)frameTimeNanos);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeSetClockControl(JNIEnv *env, jclass clazz, jstring path) {
|
||||
const char *value = path ? (*env)->GetStringUTFChars(env, path, NULL) : NULL;
|
||||
droiddeck_clock_domain_set_control(value);
|
||||
if (value) (*env)->ReleaseStringUTFChars(env, path, value);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeSetHideShell(JNIEnv *env, jclass clazz, jboolean hide) {
|
||||
g_hide_shell = hide ? 1 : 0;
|
||||
|
||||
Reference in new issue
Block a user