mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 20:36:04 +00:00
Merge upstream main and preserve routed Home input
Integrate upstream 213c2da5, keeping Home/Guide player-slot handling compatible with remapped controls and disabled routing. Preserve the input-settings overlay gate for Home and Steam volume keys.
Validation: 2,707 JVM tests across 389 suites pass. Device validation and latency measurements were not repeated.
This commit is contained in:
commit
b245017593
121 files changed
+7170
-348
No files matched your search
@@ -207,6 +207,7 @@ struct surface {
|
||||
struct wl_resource *dmabuf;
|
||||
struct dmabuf_buffer *dmabuf_buf;
|
||||
struct wl_listener dmabuf_destroy;
|
||||
const void *last_dmabuf;
|
||||
int buf_w, buf_h, has_content;
|
||||
int buf_alpha;
|
||||
int opaque[4], pending_opaque[4], pending_opaque_set;
|
||||
@@ -261,6 +262,26 @@ static struct wl_event_source *g_render_idle, *g_frame_timer;
|
||||
|
||||
|
||||
static int g_dirty;
|
||||
static int64_t g_dirty_since_ns;
|
||||
volatile int g_render_on_commit = 1;
|
||||
static int64_t g_rendered_tick_ns;
|
||||
static int g_tick_held;
|
||||
static int64_t g_hold_missed_ns;
|
||||
#define HOLD_RETRY_NS 1000000000LL
|
||||
#define PACE_BUFFERS 32
|
||||
static struct {
|
||||
unsigned ticks, ticks_late_2ms, renders, commit_renders, null_attaches, reattaches, presented, replaced, undrawn, distinct;
|
||||
int64_t tick_late_ns, tick_late_max_ns, wait_ns, wait_max_ns;
|
||||
const void *buffers[PACE_BUFFERS];
|
||||
uint64_t game_frames_seen;
|
||||
} g_pace;
|
||||
|
||||
static void pace_note_buffer(const void *buffer) {
|
||||
for (unsigned i = 0; i < g_pace.distinct && i < PACE_BUFFERS; i++)
|
||||
if (g_pace.buffers[i] == buffer) return;
|
||||
if (g_pace.distinct < PACE_BUFFERS) g_pace.buffers[g_pace.distinct] = buffer;
|
||||
g_pace.distinct++;
|
||||
}
|
||||
static int64_t g_last_vsync_ns;
|
||||
static int64_t g_tick_vsync_ns;
|
||||
static int64_t g_refresh_ns = 16666667;
|
||||
@@ -311,6 +332,7 @@ static struct {
|
||||
} g_perf;
|
||||
|
||||
static void schedule_render(void);
|
||||
static void on_commit_idle(void *data);
|
||||
|
||||
static int64_t now_ns(void) {
|
||||
struct timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||
@@ -758,6 +780,9 @@ static void take_pixel(struct surface *s, const uint8_t bgra[4], struct wl_resou
|
||||
static void take_dmabuf(struct surface *s, struct dmabuf_buffer *b, struct wl_resource *buffer) {
|
||||
const int repeat = s->dmabuf == buffer && s->dmabuf_buf == b;
|
||||
if (!repeat) {
|
||||
if (!s->dmabuf && s->last_dmabuf == buffer) g_pace.reattaches++;
|
||||
s->last_dmabuf = buffer;
|
||||
pace_note_buffer(buffer);
|
||||
drop_dmabuf(s, 1);
|
||||
s->dmabuf = buffer;
|
||||
s->dmabuf_buf = b;
|
||||
@@ -919,12 +944,15 @@ static void feedback_resource_destroy(struct wl_resource *r) {
|
||||
wl_list_remove(wl_resource_get_link(r));
|
||||
}
|
||||
|
||||
static void feedback_discard_all(struct wl_list *list) {
|
||||
static unsigned feedback_discard_all(struct wl_list *list) {
|
||||
struct wl_resource *fb, *tmp;
|
||||
unsigned n = 0;
|
||||
wl_resource_for_each_safe(fb, tmp, list) {
|
||||
wp_presentation_feedback_send_discarded(fb);
|
||||
wl_resource_destroy(fb);
|
||||
n++;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
static uint32_t nominal_refresh_ns(void) {
|
||||
@@ -953,6 +981,7 @@ static void feedback_present_all(struct wl_list *list, int64_t t) {
|
||||
nominal_refresh_ns(), 0, 0,
|
||||
WP_PRESENTATION_FEEDBACK_KIND_VSYNC);
|
||||
wl_resource_destroy(fb);
|
||||
g_pace.presented++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1119,7 +1148,9 @@ static void surface_commit(struct wl_client *c, struct wl_resource *r) {
|
||||
struct wl_shm_buffer *shm = buffer && !db ? wl_shm_buffer_get(buffer) : NULL;
|
||||
uint8_t pixel[4];
|
||||
|
||||
feedback_discard_all(&s->feedback);
|
||||
g_pace.replaced += feedback_discard_all(&s->feedback);
|
||||
if (!buffer) g_pace.null_attaches++;
|
||||
else if (!db) s->last_dmabuf = NULL;
|
||||
|
||||
if (buffer) {
|
||||
wl_list_remove(&s->pending_buffer_destroy.link);
|
||||
@@ -2092,14 +2123,23 @@ void droiddeck_stream_frame(AHardwareBuffer *ahb) {
|
||||
unsigned droiddeck_stream_frames(void) { return atomic_load(&g_stream_frames); }
|
||||
|
||||
static void render_scene(void) {
|
||||
if (atomic_load(&g_stream_on)) { render_stream(); return; }
|
||||
if (atomic_load(&g_stream_on)) { g_dirty_since_ns = 0; render_stream(); return; }
|
||||
struct draw_list dl = {0};
|
||||
struct surface *s;
|
||||
int w, h;
|
||||
const int64_t t_scene = now_ns();
|
||||
int copy = 0;
|
||||
|
||||
if (g_dirty_since_ns) {
|
||||
const int64_t wait = t_scene - g_dirty_since_ns;
|
||||
g_pace.wait_ns += wait;
|
||||
if (wait > g_pace.wait_max_ns) g_pace.wait_max_ns = wait;
|
||||
g_pace.renders++;
|
||||
g_dirty_since_ns = 0;
|
||||
}
|
||||
g_dirty = 0;
|
||||
g_rendered_tick_ns = g_tick_vsync_ns;
|
||||
g_tick_held = 0;
|
||||
g_hud_fresh = 0;
|
||||
g_hdr_unimported = NULL;
|
||||
wl_list_for_each(s, &g_surfaces, link) s->drawn = 0;
|
||||
@@ -2239,7 +2279,7 @@ static void render_scene(void) {
|
||||
}
|
||||
wl_list_for_each(s, &g_surfaces, link) {
|
||||
if (s->drawn) feedback_present_all(&s->feedback, t);
|
||||
else feedback_discard_all(&s->feedback);
|
||||
else g_pace.undrawn += feedback_discard_all(&s->feedback);
|
||||
}
|
||||
fire_all_frames();
|
||||
} else {
|
||||
@@ -2264,10 +2304,25 @@ static int on_fallback_timer(void *data) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* A new frame is drawn when it arrives instead of at the next screen tick, at most once per refresh,
|
||||
while frames go straight back to the game (no compositor limit), without streaming or frame generation. */
|
||||
static int commit_renders_on(void) {
|
||||
return g_render_on_commit && g_release_unpaced && !atomic_load(&g_stream_on) && !vkp_framegen_active();
|
||||
}
|
||||
|
||||
static int render_on_commit(void) {
|
||||
return commit_renders_on() && !g_render_idle && g_rendered_tick_ns != g_tick_vsync_ns;
|
||||
}
|
||||
|
||||
static void schedule_render(void) {
|
||||
if (!g_dirty && !g_dirty_since_ns) g_dirty_since_ns = now_ns();
|
||||
g_dirty = 1;
|
||||
if (!g_display) return;
|
||||
if (g_last_vsync_ns && now_ns() - g_last_vsync_ns < 100000000LL) return;
|
||||
if (g_last_vsync_ns && now_ns() - g_last_vsync_ns < 100000000LL) {
|
||||
if (render_on_commit())
|
||||
g_render_idle = wl_event_loop_add_idle(wl_display_get_event_loop(g_display), on_commit_idle, NULL);
|
||||
return;
|
||||
}
|
||||
if (g_fallback_armed) return;
|
||||
if (!g_fallback_timer)
|
||||
g_fallback_timer = wl_event_loop_add_timer(wl_display_get_event_loop(g_display),
|
||||
@@ -2281,18 +2336,45 @@ static int scene_waits_for_game(int64_t now) {
|
||||
return g_hud_surface && !g_hud_fresh && now - g_hud_last_ns < 100000000LL && vkp_framegen_active();
|
||||
}
|
||||
|
||||
static void on_commit_idle(void *data) {
|
||||
g_render_idle = NULL;
|
||||
if (!g_dirty || !commit_renders_on() || g_rendered_tick_ns == g_tick_vsync_ns || scene_waits_for_game(now_ns())) return;
|
||||
g_pace.commit_renders++;
|
||||
render_scene();
|
||||
}
|
||||
|
||||
static void on_vsync(int64_t frame_time_ns) {
|
||||
int64_t now = now_ns();
|
||||
g_perf.ticks++;
|
||||
if (frame_time_ns > 0 && now >= frame_time_ns) {
|
||||
const int64_t late = now - frame_time_ns;
|
||||
g_pace.ticks++;
|
||||
g_pace.tick_late_ns += late;
|
||||
if (late > g_pace.tick_late_max_ns) g_pace.tick_late_max_ns = late;
|
||||
if (late > 2000000LL) g_pace.ticks_late_2ms++;
|
||||
}
|
||||
if (g_last_vsync_ns) {
|
||||
int64_t d = now - g_last_vsync_ns;
|
||||
if (d > 3000000LL && d < 40000000LL) g_refresh_ns = (g_refresh_ns * 7 + d) / 8;
|
||||
}
|
||||
g_last_vsync_ns = now;
|
||||
g_tick_vsync_ns = frame_time_ns;
|
||||
if (vkp_apply_window_request()) g_dirty = 1;
|
||||
if (vkp_effects_sync()) g_dirty = 1;
|
||||
if (vkp_cardboard_pose_changed()) g_dirty = 1;
|
||||
int tick_change = 0;
|
||||
if (vkp_apply_window_request()) tick_change = 1;
|
||||
if (vkp_effects_sync()) tick_change = 1;
|
||||
if (vkp_cardboard_pose_changed()) tick_change = 1;
|
||||
if (tick_change) g_dirty = 1;
|
||||
/* A frame that arrived after this refresh was already drawn is left for the next arrival to draw;
|
||||
drawing it here would block that arrival too and keep every frame waiting for the tick. A client
|
||||
that draws again only after its frame callback sends no such arrival: once a held frame is still
|
||||
waiting at the next tick, the tick draws every frame for a second before holding one again. */
|
||||
if (g_tick_held && g_dirty) g_hold_missed_ns = now;
|
||||
g_tick_held = 0;
|
||||
if (!tick_change && commit_renders_on() && g_dirty_since_ns && now - g_dirty_since_ns < g_refresh_ns &&
|
||||
now - g_hold_missed_ns >= HOLD_RETRY_NS) {
|
||||
g_tick_held = 1;
|
||||
return;
|
||||
}
|
||||
if (g_dirty && !scene_waits_for_game(now)) render_scene();
|
||||
}
|
||||
|
||||
@@ -3396,6 +3478,24 @@ static int on_stats_timer(void *data) {
|
||||
#undef PERF_MS
|
||||
memset(&g_perf, 0, sizeof(g_perf));
|
||||
}
|
||||
const uint64_t game = g_game_frames - g_pace.game_frames_seen;
|
||||
if (g_pace.ticks || g_pace.renders || game || g_pace.reattaches || g_pace.null_attaches || g_pace.distinct ||
|
||||
g_pace.presented || g_pace.replaced || g_pace.undrawn) {
|
||||
droiddeck_log("pacing", "last 10 s: tick reaches compositor %.2f/%.2f ms late (%u ticks, %u over 2 ms) | "
|
||||
"new frame waits %.2f/%.2f ms to be drawn (%u scenes, %u on arrival) | %llu game frames, %u re-attached after an "
|
||||
"empty attach, %u empty attaches, %u distinct buffers | feedback %u shown, %u replaced before drawing, "
|
||||
"%u not drawn",
|
||||
g_pace.ticks ? (double)g_pace.tick_late_ns / 1e6 / g_pace.ticks : 0.0, (double)g_pace.tick_late_max_ns / 1e6,
|
||||
g_pace.ticks, g_pace.ticks_late_2ms,
|
||||
g_pace.renders ? (double)g_pace.wait_ns / 1e6 / g_pace.renders : 0.0, (double)g_pace.wait_max_ns / 1e6,
|
||||
g_pace.renders, g_pace.commit_renders, (unsigned long long)game, g_pace.reattaches, g_pace.null_attaches, g_pace.distinct,
|
||||
g_pace.presented, g_pace.replaced, g_pace.undrawn);
|
||||
}
|
||||
{
|
||||
const uint64_t seen = g_game_frames;
|
||||
memset(&g_pace, 0, sizeof(g_pace));
|
||||
g_pace.game_frames_seen = seen;
|
||||
}
|
||||
g_stat_frames = g_stat_dmabuf = g_stat_shm = 0;
|
||||
droiddeck_color_stats_tick();
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@ extern void droiddeck_wayland_output_resized(void);
|
||||
extern void droiddeck_wayland_set_output_refresh_rate(int mhz);
|
||||
extern volatile int g_fps_limit;
|
||||
extern volatile int g_release_unpaced;
|
||||
extern volatile int g_render_on_commit;
|
||||
extern volatile int g_hide_shell;
|
||||
extern volatile int g_zero_copy;
|
||||
extern volatile unsigned g_zero_copy_last;
|
||||
@@ -587,6 +588,12 @@ Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeSetLookName(JNIEnv *
|
||||
free(s);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeSetRenderOnCommit(JNIEnv *env, jclass clazz, jboolean on) {
|
||||
g_render_on_commit = on ? 1 : 0;
|
||||
__android_log_print(ANDROID_LOG_INFO, TAG, "render on commit %s", on ? "on" : "off");
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeSetFpsLimit(JNIEnv *env, jclass clazz, jint fps) {
|
||||
g_fps_limit = fps > 0 ? fps : 0;
|
||||
|
||||
Reference in new issue
Block a user