mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-02 11:05:39 +00:00
Compare commits
7
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9ca6fa064e | ||
|
|
aab15f3146 | ||
|
|
11af78340a | ||
|
|
2c95ebd22d | ||
|
|
7ce53ccbed | ||
|
|
1b4aaf8a3b | ||
|
|
4793d1df62 |
No files matched your search
@@ -205,15 +205,19 @@ int ahb_swapchain_present(struct dmabuf_buffer *b, struct surface *s, int scene_
|
||||
struct droiddeck_dma_buf_sync_file exp = {.flags = DROIDDECK_DMA_BUF_SYNC_READ, .fd = -1};
|
||||
if (dmabuf_fd >= 0 && ioctl(dmabuf_fd, DROIDDECK_DMA_BUF_IOCTL_EXPORT_SYNC_FILE, &exp) == 0 && exp.fd >= 0) {
|
||||
acquire = exp.fd;
|
||||
} else if (dmabuf_fd >= 0) {
|
||||
} else {
|
||||
if (!g_export_failed_logged) {
|
||||
g_export_failed_logged = 1;
|
||||
droiddeck_log("layer", "zero-copy: DMA_BUF_IOCTL_EXPORT_SYNC_FILE failed (%s): waiting for each frame on the CPU instead",
|
||||
strerror(errno));
|
||||
droiddeck_log("layer", "zero-copy: no acquire fence from the game's dma-buf (%s): %s",
|
||||
dmabuf_fd >= 0 ? strerror(errno) : "no dma-buf fd",
|
||||
draw ? "its frames are copied instead" : "it cannot be copied, so each frame is waited for on the CPU");
|
||||
}
|
||||
struct pollfd p = {.fd = dmabuf_fd, .events = POLLIN};
|
||||
int r;
|
||||
do { r = poll(&p, 1, 100); } while (r < 0 && errno == EINTR);
|
||||
if (dmabuf_fd >= 0) {
|
||||
struct pollfd p = {.fd = dmabuf_fd, .events = POLLIN};
|
||||
int r;
|
||||
do { r = poll(&p, 1, 100); } while (r < 0 && errno == EINTR);
|
||||
}
|
||||
if (draw) return -1;
|
||||
}
|
||||
int r = sc_layer_present_ahb(ab->ahb, ab->w, ab->h, acquire, (void *)(uintptr_t)ab->id, scene_w, scene_h, draw,
|
||||
s ? droiddeck_surface_color(s) : NULL, ab->format);
|
||||
|
||||
@@ -2272,6 +2272,69 @@ static void bind_output(struct wl_client *c, void *data, uint32_t ver, uint32_t
|
||||
|
||||
struct draw_list { struct vkp_draw *d; int n, cap; };
|
||||
|
||||
#define ZERO_COPY_FALLBACK_SIGNATURES 32u
|
||||
enum zero_copy_fallback_reason {
|
||||
ZERO_COPY_NO_SURFACE_BUFFER = 1,
|
||||
ZERO_COPY_NO_GRALLOC_AHB = 2,
|
||||
ZERO_COPY_AHB_PRESENT_FAILED = 3
|
||||
};
|
||||
struct zero_copy_fallback_signature {
|
||||
uint32_t reason, format, stride, offset;
|
||||
int width, height;
|
||||
uint64_t modifier;
|
||||
};
|
||||
static struct zero_copy_fallback_signature g_zero_copy_fallbacks[ZERO_COPY_FALLBACK_SIGNATURES];
|
||||
static uint32_t g_zero_copy_fallback_count;
|
||||
static int g_zero_copy_fallback_limit_logged;
|
||||
|
||||
static int zero_copy_fallback_should_log(const struct dmabuf_buffer *b, uint32_t reason) {
|
||||
const struct zero_copy_fallback_signature key = {
|
||||
.reason = reason, .format = b ? b->format : 0,
|
||||
.stride = b && b->n_planes ? b->stride[0] : 0,
|
||||
.offset = b && b->n_planes ? b->offset[0] : 0,
|
||||
.width = b ? b->width : 0, .height = b ? b->height : 0,
|
||||
.modifier = b ? b->modifier : 0};
|
||||
for (uint32_t i = 0; i < g_zero_copy_fallback_count; i++) {
|
||||
const struct zero_copy_fallback_signature *seen = &g_zero_copy_fallbacks[i];
|
||||
if (seen->reason == key.reason && seen->format == key.format && seen->stride == key.stride &&
|
||||
seen->offset == key.offset && seen->width == key.width && seen->height == key.height &&
|
||||
seen->modifier == key.modifier)
|
||||
return 0;
|
||||
}
|
||||
if (g_zero_copy_fallback_count >= ZERO_COPY_FALLBACK_SIGNATURES) {
|
||||
if (!g_zero_copy_fallback_limit_logged) {
|
||||
g_zero_copy_fallback_limit_logged = 1;
|
||||
droiddeck_log("layer", "zero-copy: further fallback diagnostics suppressed after %u distinct buffer signatures",
|
||||
ZERO_COPY_FALLBACK_SIGNATURES);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
g_zero_copy_fallbacks[g_zero_copy_fallback_count++] = key;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void note_zero_copy_fallback(struct surface *s, const struct dmabuf_buffer *b, uint32_t reason,
|
||||
int scene_w, int scene_h, int present_result) {
|
||||
if (!zero_copy_fallback_should_log(b, reason)) return;
|
||||
char name[160] = "unknown surface";
|
||||
if (s) describe(s, name, sizeof(name));
|
||||
if (reason == ZERO_COPY_NO_SURFACE_BUFFER) {
|
||||
droiddeck_log("layer", "zero-copy: layer candidate %s has no associated Wayland surface buffer; using the layer-copy path",
|
||||
name);
|
||||
} else {
|
||||
droiddeck_log("layer", "zero-copy: %s buffer %c%c%c%c %dx%d stride %u offset %u modifier 0x%llx %s; "
|
||||
"scene %dx%d will use the layer-copy path (direct-present result %d)",
|
||||
name, b->format & 0xff, (b->format >> 8) & 0xff, (b->format >> 16) & 0xff,
|
||||
(b->format >> 24) & 0xff, b->width, b->height,
|
||||
b->n_planes ? b->stride[0] : 0, b->n_planes ? b->offset[0] : 0,
|
||||
(unsigned long long)b->modifier,
|
||||
reason == ZERO_COPY_NO_GRALLOC_AHB
|
||||
? "has no registered gralloc AHardwareBuffer"
|
||||
: "has a registered gralloc AHardwareBuffer but direct presentation failed",
|
||||
scene_w, scene_h, present_result);
|
||||
}
|
||||
}
|
||||
|
||||
static int add_cursor(struct draw_list *dl, int scene_w);
|
||||
|
||||
static struct vkp_image *surface_image(struct surface *s) {
|
||||
@@ -2391,17 +2454,53 @@ static int black_fill_below(const struct draw_list *dl, int n) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
#define LAYER_CANDIDATE_DIAGNOSTICS 32u
|
||||
static unsigned g_layer_candidate_diag_count;
|
||||
static int g_layer_candidate_diag_limit;
|
||||
|
||||
static void note_layer_candidate_skip(const struct vkp_draw *d, int index, int reason,
|
||||
int scene_w, int scene_h) {
|
||||
static int seen[LAYER_CANDIDATE_DIAGNOSTICS][8];
|
||||
const int key[8] = {index, reason, scene_w, scene_h, d->dx, d->dy, d->dw, d->dh};
|
||||
for (unsigned i = 0; i < g_layer_candidate_diag_count; i++)
|
||||
if (!memcmp(seen[i], key, sizeof(key))) return;
|
||||
if (g_layer_candidate_diag_count >= LAYER_CANDIDATE_DIAGNOSTICS) {
|
||||
if (!g_layer_candidate_diag_limit++) droiddeck_log("layer", "zero-copy: further candidate-rejection details suppressed after %u signatures",
|
||||
LAYER_CANDIDATE_DIAGNOSTICS);
|
||||
return;
|
||||
}
|
||||
memcpy(seen[g_layer_candidate_diag_count++], key, sizeof(key));
|
||||
const char *why = reason == 1 ? "translucent draw" :
|
||||
reason == 2 ? "image is not DMA-BUF" :
|
||||
reason == 3 ? "source rectangle is outside/invalid" :
|
||||
reason == 4 ? "draw rectangle is outside scene or invalid" :
|
||||
"not fullscreen and no black backing below";
|
||||
droiddeck_log("layer", "zero-copy: candidate draw %d rejected: %s; scene %dx%d, dst %dx%d at %d,%d, src %.2f,%.2f %.2fx%.2f, image %dx%d",
|
||||
index, why, scene_w, scene_h, d->dw, d->dh, d->dx, d->dy,
|
||||
d->sx, d->sy, d->sw, d->sh, vkp_image_width(d->img), vkp_image_height(d->img));
|
||||
}
|
||||
|
||||
static int layer_candidate(const struct draw_list *dl, int scene_w, int scene_h) {
|
||||
for (int i = dl->n - 1; i >= 0 && i >= dl->n - 2; i--) {
|
||||
const struct vkp_draw *d = &dl->d[i];
|
||||
if (d->blend) continue;
|
||||
if (!vkp_image_is_dmabuf(d->img)) continue;
|
||||
if (d->blend) { note_layer_candidate_skip(d, i, 1, scene_w, scene_h); continue; }
|
||||
if (!vkp_image_is_dmabuf(d->img)) { note_layer_candidate_skip(d, i, 2, scene_w, scene_h); continue; }
|
||||
if (d->sx < 0 || d->sy < 0 || d->sw < 1.0f || d->sh < 1.0f ||
|
||||
d->sx + d->sw >= vkp_image_width(d->img) + 1.0f ||
|
||||
d->sy + d->sh >= vkp_image_height(d->img) + 1.0f) continue;
|
||||
d->sy + d->sh >= vkp_image_height(d->img) + 1.0f) {
|
||||
note_layer_candidate_skip(d, i, 3, scene_w, scene_h);
|
||||
continue;
|
||||
}
|
||||
if (d->dx == 0 && d->dy == 0 && d->dw == scene_w && d->dh == scene_h) return i;
|
||||
if (d->dx < 0 || d->dy < 0 || d->dw <= 0 || d->dh <= 0 || d->dx + d->dw > scene_w ||
|
||||
d->dy + d->dh > scene_h || !black_fill_below(dl, i)) continue;
|
||||
d->dy + d->dh > scene_h) {
|
||||
note_layer_candidate_skip(d, i, 4, scene_w, scene_h);
|
||||
continue;
|
||||
}
|
||||
if (!black_fill_below(dl, i)) {
|
||||
note_layer_candidate_skip(d, i, 5, scene_w, scene_h);
|
||||
continue;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
@@ -2422,6 +2521,56 @@ static void note_copy_scene(const struct draw_list *dl, int scene_w, int scene_h
|
||||
vkp_image_is_dmabuf(t->img) ? "GPU" : "memory", t->blend ? ", translucent" : "");
|
||||
}
|
||||
|
||||
static struct surface *surface_for_image(const struct vkp_image *img);
|
||||
|
||||
static void note_layer_candidate_rejected(const struct draw_list *dl, int scene_w, int scene_h) {
|
||||
static int seen[32][14];
|
||||
static unsigned seen_count;
|
||||
static int limit_logged;
|
||||
static time_t window_start;
|
||||
struct timespec now_ts;
|
||||
const struct vkp_draw *a = dl->n > 0 ? &dl->d[dl->n - 1] : NULL;
|
||||
const struct vkp_draw *b = dl->n > 1 ? &dl->d[dl->n - 2] : NULL;
|
||||
struct surface *sa = a ? surface_for_image(a->img) : NULL;
|
||||
struct surface *sb = b ? surface_for_image(b->img) : NULL;
|
||||
const int signature[14] = {
|
||||
dl->n, scene_w, scene_h,
|
||||
a ? a->dw : 0, a ? a->dh : 0,
|
||||
a ? vkp_image_width(a->img) : 0, a ? vkp_image_height(a->img) : 0,
|
||||
a ? vkp_image_is_dmabuf(a->img) : 0, a ? a->blend : 0, sa && sa->dmabuf_buf ? 1 : 0,
|
||||
b ? b->dw : 0, b ? b->dh : 0, b ? vkp_image_is_dmabuf(b->img) : 0, sb && sb->dmabuf_buf ? 1 : 0
|
||||
};
|
||||
clock_gettime(CLOCK_MONOTONIC, &now_ts);
|
||||
if (!window_start || now_ts.tv_sec - window_start >= 30) {
|
||||
seen_count = 0;
|
||||
limit_logged = 0;
|
||||
window_start = now_ts.tv_sec;
|
||||
}
|
||||
for (unsigned i = 0; i < seen_count; i++)
|
||||
if (!memcmp(signature, seen[i], sizeof(signature))) return;
|
||||
if (seen_count >= 32) {
|
||||
if (!limit_logged++) droiddeck_log("layer", "zero-copy: further fullscreen-candidate rejection details suppressed after 32 signatures in 30 seconds");
|
||||
return;
|
||||
}
|
||||
memcpy(seen[seen_count++], signature, sizeof(signature));
|
||||
char below[48];
|
||||
if (b)
|
||||
snprintf(below, sizeof(below), "%s %dx%d",
|
||||
vkp_image_is_dmabuf(b->img) ? "DMA-BUF" : "non-DMA-BUF", b->dw, b->dh);
|
||||
else
|
||||
snprintf(below, sizeof(below), "none");
|
||||
droiddeck_log("layer", "zero-copy: no eligible fullscreen DMA-BUF layer candidate: scene %dx%d, %d draws; "
|
||||
"top draw %dx%d at %d,%d image %dx%d %s%s surface=%s dmabuf=%s; "
|
||||
"draw below %s",
|
||||
scene_w, scene_h, dl->n, a ? a->dw : 0, a ? a->dh : 0, a ? a->dx : 0, a ? a->dy : 0,
|
||||
a ? vkp_image_width(a->img) : 0, a ? vkp_image_height(a->img) : 0,
|
||||
a && vkp_image_is_dmabuf(a->img) ? "DMA-BUF" : "non-DMA-BUF",
|
||||
a && a->blend ? " blended" : "",
|
||||
sa ? "associated" : "unassociated",
|
||||
sa && sa->dmabuf_buf ? "yes" : "no",
|
||||
below);
|
||||
}
|
||||
|
||||
static struct surface *surface_for_image(const struct vkp_image *img) {
|
||||
struct surface *s;
|
||||
wl_list_for_each(s, &g_surfaces, link)
|
||||
@@ -2430,16 +2579,56 @@ static struct surface *surface_for_image(const struct vkp_image *img) {
|
||||
}
|
||||
|
||||
static struct surface *ahb_layer_only_candidate(int scene_w, int scene_h) {
|
||||
static struct {
|
||||
const struct surface *surface;
|
||||
int reason, scene_w, scene_h, w, h, buf_w, buf_h, x, y, src_set, dst_set, children;
|
||||
} seen[32];
|
||||
static unsigned seen_count;
|
||||
static int limit_logged;
|
||||
struct surface *s;
|
||||
int w, h;
|
||||
int w = 0, h = 0, reason = 0;
|
||||
if (wl_list_empty(&g_toplevels)) return NULL;
|
||||
s = wl_container_of(g_toplevels.prev, s, toplevel_link);
|
||||
if (!s->dmabuf_buf || s->dmabuf_buf->img || !ahb_swapchain_has_ahb(s->dmabuf_buf)) return NULL;
|
||||
if ((g_desktop && !s->placed) || s->x != 0 || s->y != 0 || s->src_set || s->dst_set) return NULL;
|
||||
if (!wl_list_empty(&s->children)) return NULL;
|
||||
if (g_hide_shell && !strcmp(client_name(wl_resource_get_client(s->resource)), "explorer.exe")) return NULL;
|
||||
if (!s->dmabuf_buf) reason = 1;
|
||||
else if (s->dmabuf_buf->img) reason = 2;
|
||||
else if (!ahb_swapchain_has_ahb(s->dmabuf_buf)) reason = 3;
|
||||
else if ((g_desktop && !s->placed) || s->x != 0 || s->y != 0 || s->src_set || s->dst_set) reason = 4;
|
||||
else if (!wl_list_empty(&s->children)) reason = 5;
|
||||
else if (g_hide_shell && !strcmp(client_name(wl_resource_get_client(s->resource)), "explorer.exe")) reason = 6;
|
||||
surface_size(s, &w, &h);
|
||||
if (w != scene_w || h != scene_h || s->buf_w != scene_w || s->buf_h != scene_h) return NULL;
|
||||
if (!reason && (w != scene_w || h != scene_h || s->buf_w != scene_w || s->buf_h != scene_h)) reason = 7;
|
||||
if (reason) {
|
||||
int found = 0;
|
||||
for (unsigned i = 0; i < seen_count; i++) {
|
||||
if (seen[i].surface == s && seen[i].reason == reason && seen[i].scene_w == scene_w &&
|
||||
seen[i].scene_h == scene_h && seen[i].w == w && seen[i].h == h &&
|
||||
seen[i].buf_w == s->buf_w && seen[i].buf_h == s->buf_h && seen[i].x == s->x &&
|
||||
seen[i].y == s->y && seen[i].src_set == s->src_set && seen[i].dst_set == s->dst_set &&
|
||||
seen[i].children == !wl_list_empty(&s->children)) { found = 1; break; }
|
||||
}
|
||||
if (!found && seen_count < 32) {
|
||||
seen[seen_count].surface = s; seen[seen_count].reason = reason;
|
||||
seen[seen_count].scene_w = scene_w; seen[seen_count].scene_h = scene_h;
|
||||
seen[seen_count].w = w; seen[seen_count].h = h; seen[seen_count].buf_w = s->buf_w; seen[seen_count].buf_h = s->buf_h;
|
||||
seen[seen_count].x = s->x; seen[seen_count].y = s->y; seen[seen_count].src_set = s->src_set;
|
||||
seen[seen_count].dst_set = s->dst_set; seen[seen_count].children = !wl_list_empty(&s->children);
|
||||
seen_count++;
|
||||
const char *why = reason == 1 ? "no DMA-BUF buffer" :
|
||||
reason == 2 ? "buffer is already importable by Vulkan" :
|
||||
reason == 3 ? "no registered gralloc AHardwareBuffer" :
|
||||
reason == 4 ? "surface is positioned/cropped/scaled" :
|
||||
reason == 5 ? "surface has child surfaces" :
|
||||
reason == 6 ? "hidden shell surface" : "surface or buffer dimensions differ from scene";
|
||||
char name[160]; describe(s, name, sizeof(name));
|
||||
droiddeck_log("layer", "zero-copy: AHardwareBuffer-only candidate rejected: %s; %s, scene %dx%d, surface %dx%d at %d,%d, buffer %dx%d, crop=%d destination=%d children=%d",
|
||||
why, name, scene_w, scene_h, w, h, s->x, s->y, s->buf_w, s->buf_h,
|
||||
s->src_set, s->dst_set, !wl_list_empty(&s->children));
|
||||
} else if (!found && !limit_logged) {
|
||||
limit_logged = 1;
|
||||
droiddeck_log("layer", "zero-copy: further AHardwareBuffer-only candidate diagnostics suppressed after 32 signatures");
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
@@ -2882,7 +3071,10 @@ static void render_scene(void) {
|
||||
struct surface *ls = li >= 0 ? surface_for_image(dl.d[li].img) : NULL;
|
||||
const struct vkp_draw *ld = li >= 0 ? &dl.d[li] : NULL;
|
||||
if (li < 0) ls = layer_only;
|
||||
if (g_zero_copy && li < 0 && !ls && !blocked && !cardboard) note_copy_scene(&dl, w, h, cursor_on);
|
||||
if (g_zero_copy && li < 0 && !ls && !blocked && !cardboard) {
|
||||
if (!cursor_on && !bfi) note_layer_candidate_rejected(&dl, w, h);
|
||||
note_copy_scene(&dl, w, h, cursor_on);
|
||||
}
|
||||
if (cardboard) ls = NULL;
|
||||
if (cursor_on) ls = NULL;
|
||||
if (bfi) ls = NULL;
|
||||
@@ -2910,6 +3102,14 @@ static void render_scene(void) {
|
||||
r = generated >= 0 ? 0 : -1;
|
||||
else if (generated >= 0 && !(fx_on && li >= 0) && ls && ls->dmabuf_buf && ahb_swapchain_has_ahb(ls->dmabuf_buf))
|
||||
r = ahb_swapchain_present(ls->dmabuf_buf, ls, w, h, ld);
|
||||
if (!fg_pass && generated >= 0 && !fx_on && !framegen && r != 0) {
|
||||
if (!ls || !ls->dmabuf_buf)
|
||||
note_zero_copy_fallback(ls, NULL, ZERO_COPY_NO_SURFACE_BUFFER, w, h, r);
|
||||
else if (!ahb_swapchain_has_ahb(ls->dmabuf_buf))
|
||||
note_zero_copy_fallback(ls, ls->dmabuf_buf, ZERO_COPY_NO_GRALLOC_AHB, w, h, r);
|
||||
else
|
||||
note_zero_copy_fallback(ls, ls->dmabuf_buf, ZERO_COPY_AHB_PRESENT_FAILED, w, h, r);
|
||||
}
|
||||
if (r == 0 && !fg_pass) g_zero_copy_shown = ls;
|
||||
else settle_unwaited();
|
||||
if (!fg_pass && generated >= 0 && r != 0 && li >= 0)
|
||||
|
||||
@@ -62,8 +62,40 @@ struct entry {
|
||||
static struct wl_list g_entries;
|
||||
static struct wl_event_loop *g_loop;
|
||||
static uint64_t g_next_id = 1;
|
||||
static int g_refused_logged;
|
||||
static int g_ubwc_promised;
|
||||
|
||||
#define DISPLAY_BUFFER_MISMATCH_SIGNATURES 64u
|
||||
struct display_buffer_mismatch_signature {
|
||||
uint32_t kind, format, stride, offset;
|
||||
int width, height;
|
||||
uint64_t modifier;
|
||||
};
|
||||
static struct display_buffer_mismatch_signature g_mismatch_signatures[DISPLAY_BUFFER_MISMATCH_SIGNATURES];
|
||||
static uint32_t g_mismatch_signature_count;
|
||||
static int g_mismatch_limit_logged;
|
||||
|
||||
static int mismatch_should_log(const struct dmabuf_buffer *b, uint32_t kind) {
|
||||
const struct display_buffer_mismatch_signature key = {
|
||||
.kind = kind, .format = b->format, .stride = b->stride[0], .offset = b->offset[0],
|
||||
.width = b->width, .height = b->height, .modifier = b->modifier};
|
||||
for (uint32_t i = 0; i < g_mismatch_signature_count; i++) {
|
||||
const struct display_buffer_mismatch_signature *seen = &g_mismatch_signatures[i];
|
||||
if (seen->kind == key.kind && seen->format == key.format && seen->stride == key.stride &&
|
||||
seen->offset == key.offset && seen->width == key.width && seen->height == key.height &&
|
||||
seen->modifier == key.modifier)
|
||||
return 0;
|
||||
}
|
||||
if (g_mismatch_signature_count >= DISPLAY_BUFFER_MISMATCH_SIGNATURES) {
|
||||
if (!g_mismatch_limit_logged) {
|
||||
g_mismatch_limit_logged = 1;
|
||||
droiddeck_log("layer", "display buffers: further mismatch diagnostics suppressed after %u distinct buffer signatures",
|
||||
DISPLAY_BUFFER_MISMATCH_SIGNATURES);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
g_mismatch_signatures[g_mismatch_signature_count++] = key;
|
||||
return 1;
|
||||
}
|
||||
static int g_ubwc_probed[2];
|
||||
|
||||
static uint32_t ahb_format_of(uint32_t drm, uint64_t modifier) {
|
||||
@@ -238,16 +270,51 @@ static void handle_alloc(struct peer *p, const struct display_buffers_request *q
|
||||
} else {
|
||||
if (ahb) AHardwareBuffer_release(ahb);
|
||||
fd = -1;
|
||||
if (sized && wanted && (compressed || !g_refused_logged)) {
|
||||
g_refused_logged = 1;
|
||||
droiddeck_log(compressed ? "error" : "layer", "display buffers: no gralloc buffer matches pid %d's %ux%u "
|
||||
"%c%c%c%c %s layout (stride %u bytes, pixels at %u, %llu bytes; gralloc's layout has pixels at "
|
||||
"%llu, %llu bytes): %s", (int)p->pid, q->width, q->height,
|
||||
q->format & 0xff, (q->format >> 8) & 0xff, (q->format >> 16) & 0xff, (q->format >> 24) & 0xff,
|
||||
compressed ? "UBWC" : "linear", q->stride, q->offset, (unsigned long long)q->size,
|
||||
(unsigned long long)(compressed ? ubwc_meta_size(q->width, q->height) : 0),
|
||||
(unsigned long long)(compressed ? ubwc_size(q->width, q->height, q->stride) : q->size),
|
||||
compressed ? "its compressed frames cannot be shown" : "its frames keep the copy path");
|
||||
static struct {
|
||||
pid_t pid;
|
||||
uint32_t width, height, format, stride, offset, reason;
|
||||
uint64_t size, modifier;
|
||||
} refused[32];
|
||||
static unsigned refused_count;
|
||||
static int refused_limit_logged;
|
||||
uint32_t reason = !sized ? 1u : !sane ? 2u : !wanted ? 3u :
|
||||
!ahb_swapchain_advertised() ? 4u :
|
||||
p->count >= DISPLAY_BUFFERS_MAX_PER_CLIENT ? 5u : 6u;
|
||||
int seen = 0;
|
||||
for (unsigned i = 0; i < refused_count; i++) {
|
||||
if (refused[i].pid == p->pid && refused[i].width == q->width && refused[i].height == q->height &&
|
||||
refused[i].format == q->format && refused[i].stride == q->stride && refused[i].offset == q->offset &&
|
||||
refused[i].size == q->size && refused[i].modifier == q->modifier && refused[i].reason == reason) {
|
||||
seen = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!seen && refused_count < 32) {
|
||||
refused[refused_count].pid = p->pid;
|
||||
refused[refused_count].width = q->width;
|
||||
refused[refused_count].height = q->height;
|
||||
refused[refused_count].format = q->format;
|
||||
refused[refused_count].stride = q->stride;
|
||||
refused[refused_count].offset = q->offset;
|
||||
refused[refused_count].size = q->size;
|
||||
refused[refused_count].modifier = q->modifier;
|
||||
refused[refused_count].reason = reason;
|
||||
refused_count++;
|
||||
const char *why = reason == 1 ? "invalid dimensions, format, or stride" :
|
||||
reason == 2 ? "size/offset/layout sanity check failed" :
|
||||
reason == 3 ? "zero-copy or UBWC offering is disabled" :
|
||||
reason == 4 ? "AHardwareBuffer swapchain is not advertised" :
|
||||
reason == 5 ? "per-client allocation limit reached" :
|
||||
"gralloc allocation/fd/size validation failed";
|
||||
droiddeck_log(compressed ? "error" : "layer",
|
||||
"display buffers: allocation refused for pid %d: %s; request %ux%u %c%c%c%c %s stride=%u offset=%u size=%llu modifier=0x%llx (client has %d allocations)",
|
||||
(int)p->pid, why, q->width, q->height,
|
||||
q->format & 0xff, (q->format >> 8) & 0xff, (q->format >> 16) & 0xff, (q->format >> 24) & 0xff,
|
||||
compressed ? "UBWC" : "linear", q->stride, q->offset,
|
||||
(unsigned long long)q->size, (unsigned long long)q->modifier, p->count);
|
||||
} else if (!seen && !refused_limit_logged) {
|
||||
refused_limit_logged = 1;
|
||||
droiddeck_log("layer", "display buffers: further allocation-refusal diagnostics suppressed after 32 signatures");
|
||||
}
|
||||
}
|
||||
if (reply(p, &r, fd) != 0 && e) entry_free(e);
|
||||
@@ -299,9 +366,18 @@ static int on_listen(int fd, uint32_t mask, void *data) {
|
||||
}
|
||||
|
||||
void display_buffers_match(struct wl_client *c, struct wl_resource *buffer, struct dmabuf_buffer *b) {
|
||||
static int invalid_logged;
|
||||
struct stat st;
|
||||
struct entry *e;
|
||||
if (!g_loop || wl_list_empty(&g_entries) || b->n_planes != 1 || b->offset[0] != 0 || fstat(b->fd[0], &st) != 0) return;
|
||||
if (!g_loop || wl_list_empty(&g_entries)) return;
|
||||
if (b->n_planes != 1 || b->offset[0] != 0 || fstat(b->fd[0], &st) != 0) {
|
||||
if (!invalid_logged) {
|
||||
invalid_logged = 1;
|
||||
droiddeck_log("layer", "display buffers: cannot associate %s's DMA-BUF with gralloc (plane count %u; expected one plane at offset 0, or fstat failed)",
|
||||
droiddeck_client_name(c), b->n_planes);
|
||||
}
|
||||
return;
|
||||
}
|
||||
wl_list_for_each(e, &g_entries, link) {
|
||||
if (e->dev != st.st_dev || e->ino != st.st_ino) continue;
|
||||
AHardwareBuffer_Desc d;
|
||||
@@ -311,11 +387,27 @@ void display_buffers_match(struct wl_client *c, struct wl_resource *buffer, stru
|
||||
(uint32_t)b->height == e->height
|
||||
: (b->modifier == MOD_LINEAR || b->modifier == MOD_INVALID) &&
|
||||
e->stride == b->stride[0];
|
||||
if (laid_out && e->format == ahb_format_of(b->format, e->modifier) && b->width > 0 && b->height > 0 &&
|
||||
(uint32_t)b->width <= d.width && (uint32_t)b->height <= d.height)
|
||||
const uint32_t expected_format = ahb_format_of(b->format, e->modifier);
|
||||
const int dimensions = b->width > 0 && b->height > 0 &&
|
||||
(uint32_t)b->width <= d.width && (uint32_t)b->height <= d.height;
|
||||
if (laid_out && e->format == expected_format && dimensions) {
|
||||
ahb_swapchain_adopt(c, buffer, b, e->ahb, e->modifier);
|
||||
} else if (mismatch_should_log(b, 2)) {
|
||||
droiddeck_log("layer", "display buffers: gralloc DMA-BUF identity matched but layout was rejected for %s: %c%c%c%c %dx%d stride %u offset %u modifier 0x%llx; gralloc %ux%u stride %u format 0x%x, expected format 0x%x (layout %s, dimensions %s)",
|
||||
droiddeck_client_name(c), b->format & 0xff, (b->format >> 8) & 0xff,
|
||||
(b->format >> 16) & 0xff, (b->format >> 24) & 0xff, b->width, b->height,
|
||||
b->stride[0], b->offset[0], (unsigned long long)b->modifier,
|
||||
e->width, e->height, e->stride, e->format, expected_format,
|
||||
laid_out ? "ok" : "mismatch", dimensions ? "ok" : "mismatch");
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (mismatch_should_log(b, 1)) {
|
||||
droiddeck_log("layer", "display buffers: no registered gralloc allocation matches %s's DMA-BUF identity: %c%c%c%c %dx%d stride %u offset %u modifier 0x%llx; imported normally, copy path only",
|
||||
droiddeck_client_name(c), b->format & 0xff, (b->format >> 8) & 0xff,
|
||||
(b->format >> 16) & 0xff, (b->format >> 24) & 0xff, b->width, b->height,
|
||||
b->stride[0], b->offset[0], (unsigned long long)b->modifier);
|
||||
}
|
||||
}
|
||||
|
||||
void display_buffers_init(struct wl_display *display) {
|
||||
|
||||
@@ -807,6 +807,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
}
|
||||
private var isHomeApp by mutableStateOf(false)
|
||||
private var androidApps by mutableStateOf<List<HomeApp.LaunchableApp>>(emptyList())
|
||||
private var padConnected by mutableStateOf(false)
|
||||
|
||||
private val deviceListener = object : InputManager.InputDeviceListener {
|
||||
override fun onInputDeviceAdded(deviceId: Int) {
|
||||
@@ -1264,7 +1265,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
) { headTracker?.recenter() }
|
||||
if (!phonePanel && glasses.present && !drawerOpen && !pcKeyboardOpen && !loading.visible) com.droiddeck.launcher.ui.GlassesCornerButton(glassesSlot,
|
||||
controllerSettings?.tint ?: android.graphics.Color.rgb(90, 160, 255), controllerSettings?.opacity ?: 100) {
|
||||
drawerPage = com.droiddeck.launcher.ui.SessionDrawerPage.GLASSES
|
||||
drawerPage = com.droiddeck.launcher.ui.SessionDrawerPage.VR
|
||||
drawerOpen = true
|
||||
}
|
||||
if (!drawerOpen && !pcKeyboardOpen && !loading.visible) {
|
||||
@@ -1451,7 +1452,10 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
}
|
||||
}
|
||||
LaunchedEffect(drawerOpen, achievementsOpen, AgentGuest.focusRevision, StoreAchievements.revision) {
|
||||
if (!drawerOpen && !achievementsOpen) return@LaunchedEffect
|
||||
if (!drawerOpen && !achievementsOpen) {
|
||||
achievementsInFront = null
|
||||
return@LaunchedEffect
|
||||
}
|
||||
val found = kotlinx.coroutines.withContext(kotlinx.coroutines.Dispatchers.IO) {
|
||||
runCatching { resolveAchievementsInFront() }
|
||||
.onFailure { Log.w(TAG, "achievements in front: ${it.javaClass.simpleName}") }.getOrNull()
|
||||
@@ -1787,7 +1791,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
onBlackFrameInsertion = { on ->
|
||||
SessionPrefs.setBlackFrameInsertion(this@SessionActivity, on)
|
||||
blackFrameInsertion = on
|
||||
CompositorHost.setBlackFrameInsertion(on, refreshHz(), outputFpsLimit())
|
||||
CompositorHost.setBlackFrameInsertion(on, refreshHz(), compositorFpsLimit())
|
||||
},
|
||||
hdr = hdrWanted,
|
||||
hdrAvailable = hdrAvailable,
|
||||
@@ -1824,7 +1828,9 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
onRumble = { on -> updateControllerPrefs { ControllerPrefs.setRumble(this@SessionActivity, on) } },
|
||||
onSteamMenu = if (SessionState.mode == SessionService.MODE_STEAM) ({ sendSteamGuide() }) else null,
|
||||
onQam = if (SessionState.mode == SessionService.MODE_STEAM) ({ triggerSteamQam() }) else null,
|
||||
onAchievements = achievementsInFront?.let { { drawerOpen = false; achievementsOpen = true } },
|
||||
controllerConnected = padConnected,
|
||||
achievementsGame = achievementsInFront?.game,
|
||||
achievementsTitle = achievementsInFront?.title,
|
||||
achievementsProgress = achievementsInFront?.progress,
|
||||
padType = if (SessionState.mode == SessionService.MODE_STEAM && SessionState.deckPad) padType else null,
|
||||
onPadType = { id ->
|
||||
@@ -2990,7 +2996,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
CompositorHost.startOrAttach(
|
||||
this, holder.surface, runtimeDir.path,
|
||||
driverId?.let { turnip.driverPath(it) }, driverId?.let { turnip.libraryName(it) },
|
||||
applicationInfo.nativeLibraryDir, size.first, size.second, refreshHz(holder), outputFpsLimit(),
|
||||
applicationInfo.nativeLibraryDir, size.first, size.second, refreshHz(holder), compositorFpsLimit(),
|
||||
)
|
||||
onOutputAttached(holder)
|
||||
if (SessionState.running && size != previous) {
|
||||
@@ -3181,6 +3187,18 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
|
||||
private fun outputFpsLimit(): Int = outputFpsLimit(pipUi)
|
||||
|
||||
// Android holds the window to the Game Mode override while the panel runs faster; the guest paces to the panel,
|
||||
// so without this cap every frame past the override is drawn and dropped.
|
||||
private fun hostFrameCap(): Int {
|
||||
if (glassesScreen != null || bottomOutputActive) return 0
|
||||
val display = (if (Build.VERSION.SDK_INT >= 30) display else @Suppress("DEPRECATION") windowManager.defaultDisplay) ?: return 0
|
||||
return SessionPrefs.hostFrameCap(display.refreshRate, display.mode.refreshRate)
|
||||
}
|
||||
|
||||
private fun compositorFpsLimit(): Int = SessionPrefs.compositorFpsLimit(
|
||||
mirrorRefreshLimit(), if (noSteamSession()) SessionState.fpsLimit else 0, pipUi, hostFrameCap(),
|
||||
)
|
||||
|
||||
private fun outputFpsLimit(pip: Boolean): Int =
|
||||
SessionPrefs.compositorFpsLimit(mirrorRefreshLimit(), if (noSteamSession()) SessionState.fpsLimit else 0, pip)
|
||||
|
||||
@@ -3218,7 +3236,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
)
|
||||
val hz = refreshHz()
|
||||
val changed = kotlin.math.abs(SessionState.refreshHz - hz) > 0.1f
|
||||
CompositorHost.updatePacing(hz, outputFpsLimit())
|
||||
CompositorHost.updatePacing(hz, compositorFpsLimit())
|
||||
pushCardboard(activeCardboard)
|
||||
if (changed && ::surfaceView.isInitialized) applyFrameGen()
|
||||
}
|
||||
@@ -3789,7 +3807,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
if (fromController && (event.keyCode == KeyEvent.KEYCODE_BUTTON_L1 || event.keyCode == KeyEvent.KEYCODE_BUTTON_R1)) {
|
||||
if (event.action == KeyEvent.ACTION_DOWN && event.repeatCount == 0) {
|
||||
// The bumpers walk the tabs on the strip; a page kept inside More counts as the More tab.
|
||||
val pages = sessionDrawerPages(glasses.present)
|
||||
val pages = sessionDrawerPages(achievementsInFront != null)
|
||||
drawerPage = pages.strip().step(pages.tabFor(drawerPage), if (event.keyCode == KeyEvent.KEYCODE_BUTTON_R1) 1 else -1)
|
||||
releaseDrawerDirection()
|
||||
}
|
||||
@@ -4945,6 +4963,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
}
|
||||
|
||||
private fun refreshControls() {
|
||||
padConnected = controllerConnected()
|
||||
applyUnfoldedControls()
|
||||
updateOnScreenControls()
|
||||
}
|
||||
@@ -6385,6 +6404,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
}
|
||||
(getSystemService(INPUT_SERVICE) as? InputManager)
|
||||
?.registerInputDeviceListener(deviceListener, Handler(Looper.getMainLooper()))
|
||||
padConnected = controllerConnected()
|
||||
padBridge?.setStickDeadZone(ControllerPrefs.deadZone(this))
|
||||
refreshSecondScreenDisplays()
|
||||
if (SessionState.guestPid > 1) padBridge?.syncConnectedControllers()
|
||||
|
||||
@@ -108,11 +108,7 @@ public class HudMetrics {
|
||||
}
|
||||
|
||||
private List<String> discoverGpuUsagePaths() {
|
||||
if (gpuUsagePathsCache == null) gpuUsagePathsCache = gpuUsagePaths();
|
||||
return gpuUsagePathsCache;
|
||||
}
|
||||
|
||||
public static List<String> gpuUsagePaths() {
|
||||
if (gpuUsagePathsCache != null) return gpuUsagePathsCache;
|
||||
LinkedHashSet<String> candidates = new LinkedHashSet<>();
|
||||
|
||||
for (String p : GPU_USAGE_STATIC_PATHS) {
|
||||
@@ -161,7 +157,8 @@ public class HudMetrics {
|
||||
}
|
||||
}
|
||||
|
||||
return new ArrayList<>(candidates);
|
||||
gpuUsagePathsCache = new ArrayList<>(candidates);
|
||||
return gpuUsagePathsCache;
|
||||
}
|
||||
|
||||
private static final String[] GPU_USAGE_STATIC_PATHS = {
|
||||
|
||||
@@ -3,18 +3,11 @@ package com.droiddeck.launcher.session
|
||||
import android.os.SystemClock
|
||||
import android.util.Log
|
||||
import com.droiddeck.launcher.core.SessionPart
|
||||
import com.droiddeck.launcher.hud.HudMetrics
|
||||
import com.droiddeck.launcher.runtime.LinuxRuntime
|
||||
import java.io.File
|
||||
import java.io.RandomAccessFile
|
||||
|
||||
class GpuStatsComponent(
|
||||
val dir: File,
|
||||
private val root: File,
|
||||
private val metrics: HudMetrics? = null,
|
||||
private val kgsl: Boolean = File(KGSL).exists(),
|
||||
private val loadNodes: () -> List<String> = HudMetrics::gpuUsagePaths,
|
||||
) : SessionPart() {
|
||||
class GpuStatsComponent(val dir: File, private val root: File) : SessionPart() {
|
||||
@Volatile private var running = false
|
||||
private var thread: Thread? = null
|
||||
private val feeds = ArrayList<Feed>()
|
||||
@@ -30,7 +23,6 @@ class GpuStatsComponent(
|
||||
)
|
||||
|
||||
fun binds(): List<String> {
|
||||
if (!kgsl) return emptyList()
|
||||
val list = mutableListOf(dir.path + ":" + KGSL)
|
||||
if (File(dir, "perf_now").exists()) list.add(File(dir, "perf_now").path + ":" + MSM_LOAD)
|
||||
if (File(dir, "cur_freq").exists()) list.add(File(dir, "cur_freq").path + ":" + MSM_CLOCK)
|
||||
@@ -41,9 +33,10 @@ class GpuStatsComponent(
|
||||
sources = ""
|
||||
KgslBusy.status = "not tried"
|
||||
KgslClock.status = "not tried"
|
||||
if (!File(KGSL).exists()) return false
|
||||
val unreadable = MANGOHUD_FILES.any { File(KGSL, it).let { f -> f.exists() && !f.canRead() } }
|
||||
// Where SELinux hides the kgsl nodes completely (exists() is false too), the layer and cycle-counter feeds stand in.
|
||||
if (kgsl && !unreadable && !File(GPUBUSY).canRead() && !loadBlocked()) return false
|
||||
if (!unreadable && !File(GPUBUSY).canRead() && !loadBlocked()) return false
|
||||
return try {
|
||||
dir.mkdirs()
|
||||
dir.listFiles()?.forEach { java.nio.file.Files.deleteIfExists(it.toPath()) }
|
||||
@@ -51,20 +44,19 @@ class GpuStatsComponent(
|
||||
PASSTHROUGH_FILES.forEach { name ->
|
||||
runCatching { File(dir, name).writeText(File(KGSL, name).readText()) }
|
||||
}
|
||||
((if (kgsl) loadFeed() else nodeLoadFeed()) ?: blockedLoadFeed())?.let { load ->
|
||||
(loadFeed() ?: blockedLoadFeed())?.let { load ->
|
||||
feeds.add(load)
|
||||
feeds.add(Feed(File(dir, "perf_now"), load.source, load.read, "%-6s\n", percent = true))
|
||||
}
|
||||
(pick("clock_mhz", clockSources(), "%5d\n") { mhz(it) } ?: (if (kgsl) cycleClockFeed() else null))?.let { clock ->
|
||||
(pick("clock_mhz", clockSources(), "%5d\n") { mhz(it) } ?: cycleClockFeed())?.let { clock ->
|
||||
feeds.add(clock)
|
||||
feeds.add(Feed(File(dir, "cur_freq"), clock.source, { clock.read()?.times(1_000_000) }, "%-10d\n"))
|
||||
}
|
||||
if (kgsl) pick("temp", tempSources(), "%6d\n") { milliCelsius(it) }?.let { feeds.add(it) }
|
||||
if (!kgsl && feeds.isEmpty()) return false
|
||||
pick("temp", tempSources(), "%6d\n") { milliCelsius(it) }?.let { feeds.add(it) }
|
||||
refresh()
|
||||
createMissing(feeds.map { it.file })
|
||||
describeSources()
|
||||
Log.i(TAG, "hud: GPU stats from the session's own: $sources")
|
||||
Log.i(TAG, "hud: kgsl stats from the session's own: $sources")
|
||||
true
|
||||
} catch (e: Exception) {
|
||||
Log.w(TAG, "hud: could not stand in for kgsl stats: $e")
|
||||
@@ -154,10 +146,10 @@ class GpuStatsComponent(
|
||||
// Vulkan layer and the compositor time their own GPU work until the memstore timestamps are seen moving, and
|
||||
// for the whole session where they never move.
|
||||
private fun blockedLoadFeed(): Feed? {
|
||||
if (!noLoadNode(kgsl, loadNodes)) return null
|
||||
if (!loadBlocked()) return null
|
||||
val load = LayerLoad(guestLoadDir(root), extra = ::compositorBusyNs, onWanted = ::compositorTiming)
|
||||
.also { it.clear(); layerLoad = it }
|
||||
val sampled = if (!kgsl) null else KgslBusy.open()?.let { reader ->
|
||||
val sampled = KgslBusy.open()?.let { reader ->
|
||||
memstore = reader
|
||||
MemstoreLoad(reader::counts).also { memstoreLoad = it }
|
||||
}
|
||||
@@ -297,12 +289,6 @@ class GpuStatsComponent(
|
||||
}
|
||||
}
|
||||
|
||||
private fun nodeLoadFeed(): Feed? {
|
||||
val metrics = metrics ?: return null
|
||||
val node = loadNodes().firstOrNull() ?: return null
|
||||
return Feed(File(dir, "gpu_busy_percentage"), node, { metrics.gpuUsagePercent?.toLong() }, "%3d %%\n")
|
||||
}
|
||||
|
||||
private fun loadFeed(): Feed? {
|
||||
latchedBusyFeed()?.let { return it }
|
||||
return pick("gpu_busy_percentage", LOAD_SOURCES, "%3d %%\n") { it.coerceIn(0, 100) }
|
||||
@@ -376,14 +362,9 @@ class GpuStatsComponent(
|
||||
/** True when this app can see kgsl but none of its GPU load nodes (SELinux-blocked, e.g. the Retroid Pocket Duo). */
|
||||
fun loadBlocked(): Boolean = File(KGSL).exists() && !File(GPUBUSY).canRead() && LOAD_SOURCES.none { File(it).canRead() }
|
||||
|
||||
private fun noLoadNode(): Boolean = noLoadNode(File(KGSL).exists(), HudMetrics::gpuUsagePaths)
|
||||
|
||||
internal fun noLoadNode(kgsl: Boolean, loadNodes: () -> List<String>): Boolean =
|
||||
if (kgsl) loadBlocked() else loadNodes().isEmpty()
|
||||
|
||||
/** Turns on the in-game layer (tools/gpuload) where the load is blocked; empty elsewhere. */
|
||||
fun guestEnv(root: File): List<String> {
|
||||
if (!noLoadNode()) return emptyList()
|
||||
if (!loadBlocked()) return emptyList()
|
||||
guestLoadDir(root).mkdirs()
|
||||
return listOf("DROIDDECK_GPU_LOAD=1", "DROIDDECK_GPU_LOAD_DIR=$GUEST_LOAD_DIR")
|
||||
}
|
||||
|
||||
@@ -493,6 +493,17 @@ object SessionPrefs {
|
||||
prefs(context).edit().putString("drawerPageHidden", keys.joinToString(",")).apply()
|
||||
}
|
||||
|
||||
fun drawerSections(context: Context): Map<String, Boolean> =
|
||||
idList(prefs(context).getString("drawerSections", null)).mapNotNull { entry ->
|
||||
val at = entry.lastIndexOf('=').takeIf { it > 0 } ?: return@mapNotNull null
|
||||
entry.substring(0, at) to (entry.substring(at + 1) == "1")
|
||||
}.toMap()
|
||||
|
||||
fun setDrawerSections(context: Context, sections: Map<String, Boolean>) {
|
||||
prefs(context).edit().putString("drawerSections", sections.entries.filter { ',' !in it.key }
|
||||
.joinToString(",") { "${it.key}=${if (it.value) 1 else 0}" }).apply()
|
||||
}
|
||||
|
||||
fun setNavTabHidden(context: Context, keys: Set<String>) {
|
||||
prefs(context).edit().putString("navTabHidden", keys.joinToString(",")).apply()
|
||||
}
|
||||
@@ -1807,16 +1818,15 @@ object SessionPrefs {
|
||||
|
||||
const val PIP_FPS = 30
|
||||
|
||||
fun compositorFpsLimit(mirrorRefreshLimit: Int, sessionLimit: Int = 0, pip: Boolean = false): Int {
|
||||
val limit = when {
|
||||
mirrorRefreshLimit <= 0 && sessionLimit <= 0 -> FPS_UNPACED
|
||||
mirrorRefreshLimit <= 0 -> sessionLimit
|
||||
sessionLimit <= 0 -> mirrorRefreshLimit
|
||||
else -> minOf(mirrorRefreshLimit, sessionLimit)
|
||||
}
|
||||
fun compositorFpsLimit(mirrorRefreshLimit: Int, sessionLimit: Int = 0, pip: Boolean = false, hostCap: Int = 0): Int {
|
||||
val limit = listOf(mirrorRefreshLimit, sessionLimit, hostCap).filter { it > 0 }.minOrNull() ?: FPS_UNPACED
|
||||
return if (pip && mirrorRefreshLimit <= 0 && (limit <= 0 || limit > PIP_FPS)) PIP_FPS else limit
|
||||
}
|
||||
|
||||
/** The per-app rate Android holds this window to (Game Mode's FPS override), or 0 when the panel's rate applies. */
|
||||
fun hostFrameCap(overrideHz: Float, panelHz: Float): Int =
|
||||
if (overrideHz > 1f && panelHz - overrideHz > 1f) Math.round(overrideHz) else 0
|
||||
|
||||
val upscalerChoices = listOf(
|
||||
2 to "Nearest", 0 to "Linear", 4 to "AMD FSR 1", 3 to "Snapdragon GSR",
|
||||
8 to "Snapdragon GSR (quality)", 7 to "NVIDIA NIS", 6 to "Sharpen only",
|
||||
|
||||
@@ -4,7 +4,6 @@ import com.droiddeck.launcher.core.AddonPack
|
||||
import com.droiddeck.launcher.gpu.LinuxVulkanDriver
|
||||
import com.droiddeck.launcher.gpu.LinuxVulkanDriverManager
|
||||
import com.droiddeck.launcher.gpu.SystemVulkanDriver
|
||||
import com.droiddeck.launcher.hud.HudMetrics
|
||||
|
||||
import android.app.Notification
|
||||
import android.app.NotificationChannel
|
||||
@@ -1294,7 +1293,7 @@ class SessionService : Service() {
|
||||
gpuMem.attach(this)
|
||||
components.add(gpuMem)
|
||||
}
|
||||
val gpuStats = GpuStatsComponent(File(filesDir, "session/sys/kgsl-3d0"), LinuxRuntime.rootDir(this), HudMetrics(this))
|
||||
val gpuStats = GpuStatsComponent(File(filesDir, "session/sys/kgsl-3d0"), LinuxRuntime.rootDir(this))
|
||||
if (gpuStats.prepare()) {
|
||||
gpuStats.attach(this)
|
||||
components.add(gpuStats)
|
||||
|
||||
@@ -18,7 +18,7 @@ object SettingsReset {
|
||||
"storesInstallLanguage",
|
||||
"hud", "hudDeck", "hudFps", "hudBattery", "hudGraph", "hudColor", "hudOpacity", "__KEEP_droidDeckHud__", "__KEEP_droidDeckHudPos__", "backHold", "dockedMenuController", "backActionsInverted", "backDoubleTapMs", "touch", "pen", "penButton", "osc", "shape", "steamController",
|
||||
"gamepadLeft", "gamepadRight", "pipAutoEnter", "unfoldedControls", "unfoldedControlsWithController",
|
||||
"stretch16x9", "avoidNotch", "picturePosition", "integerScaling", "railLabels", "developerTools", "navTabOrder", "navTabShelved", "navTabHidden", "drawerPageOrder", "drawerPageHidden", "pcKeyboardSize", "pcKeyboardOpacity", "pcKeyboardHiddenKeys",
|
||||
"stretch16x9", "avoidNotch", "picturePosition", "integerScaling", "railLabels", "developerTools", "navTabOrder", "navTabShelved", "navTabHidden", "drawerPageOrder", "drawerPageHidden", "drawerSections", "pcKeyboardSize", "pcKeyboardOpacity", "pcKeyboardHiddenKeys",
|
||||
"gpuDriverMode", "androidDriver", "linuxDriver", "linuxDriver.steam", "linuxDriver.desktop",
|
||||
"tuSysmem", "glThread", "noGlError", "zinkLazy", "mangoapp", "gpuClockPin", "gamescopeRealtime", "paceCores",
|
||||
"directAudio", "mic", "wifiDiscovery", "clientCpusOverride", "clientCpus", "gameCpus",
|
||||
|
||||
@@ -0,0 +1,142 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import android.content.Context
|
||||
import androidx.compose.animation.AnimatedVisibility
|
||||
import androidx.compose.animation.core.animateFloatAsState
|
||||
import androidx.compose.animation.expandVertically
|
||||
import androidx.compose.animation.fadeIn
|
||||
import androidx.compose.animation.fadeOut
|
||||
import androidx.compose.animation.shrinkVertically
|
||||
import androidx.compose.foundation.LocalIndication
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.hoverable
|
||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||
import androidx.compose.foundation.interaction.collectIsFocusedAsState
|
||||
import androidx.compose.foundation.interaction.collectIsHoveredAsState
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.ColumnScope
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.heightIn
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.outlined.ExpandMore
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.runtime.compositionLocalOf
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateMapOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.draw.rotate
|
||||
import androidx.compose.ui.platform.testTag
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.semantics.Role
|
||||
import androidx.compose.ui.semantics.contentDescription
|
||||
import androidx.compose.ui.semantics.semantics
|
||||
import androidx.compose.ui.semantics.stateDescription
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import com.droiddeck.launcher.R
|
||||
import com.droiddeck.launcher.session.SessionPrefs
|
||||
|
||||
/**
|
||||
* Inside the session menu every top-level settings group folds to its header and a summary of its values.
|
||||
* Groups start folded; a group the player opens or folds stays that way across sessions.
|
||||
*/
|
||||
internal object DrawerSectionState {
|
||||
private val chosen = mutableStateMapOf<String, Boolean>()
|
||||
|
||||
fun load(context: Context) {
|
||||
if (DevPreview.drawer != null) return
|
||||
chosen.clear()
|
||||
chosen.putAll(SessionPrefs.drawerSections(context))
|
||||
}
|
||||
|
||||
fun isOpen(key: String) = chosen[key] ?: false
|
||||
|
||||
fun toggle(context: Context, key: String) {
|
||||
chosen[key] = !isOpen(key)
|
||||
if (DevPreview.drawer == null) SessionPrefs.setDrawerSections(context, chosen.toMap())
|
||||
}
|
||||
}
|
||||
|
||||
internal class DrawerSections(val context: Context, val track: (String) -> Modifier)
|
||||
|
||||
internal val LocalDrawerSections = compositionLocalOf<DrawerSections?> { null }
|
||||
|
||||
@Composable
|
||||
internal fun DrawerSection(
|
||||
sections: DrawerSections, key: String, title: String, summary: String?, tag: String?,
|
||||
content: @Composable ColumnScope.() -> Unit,
|
||||
) {
|
||||
val colors = MaterialTheme.colorScheme
|
||||
val pal = LocalPalette.current
|
||||
val open = DrawerSectionState.isOpen(key)
|
||||
val source = remember { MutableInteractionSource() }
|
||||
val hot = source.collectIsFocusedAsState().value || source.collectIsHoveredAsState().value
|
||||
val rotation by animateFloatAsState(if (open) 180f else 0f, Motion.tw(180), label = "sectionArrow")
|
||||
val state = stringResource(if (open) R.string.widgets_expanded else R.string.widgets_collapsed)
|
||||
val toggle = { DrawerSectionState.toggle(sections.context, key) }
|
||||
val shape = RoundedCornerShape(14.dp)
|
||||
Column(
|
||||
Modifier.fillMaxWidth().padding(top = 6.dp).clip(shape)
|
||||
.background(colors.surface).border(1.dp, if (open) pal.line2 else pal.line, shape),
|
||||
) {
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||
modifier = Modifier.fillMaxWidth().heightIn(min = 48.dp)
|
||||
.then(sections.track("section-$key"))
|
||||
.testTag("drawer-section-$key")
|
||||
.background(if (hot) pal.signal.copy(alpha = 0.12f) else androidx.compose.ui.graphics.Color.Transparent)
|
||||
.glideBorder(hot, shape, pal.signal)
|
||||
.hoverable(source)
|
||||
.clickable(interactionSource = source, indication = LocalIndication.current, role = Role.Button, onClick = toggle)
|
||||
.controllerConfirm(onClick = toggle)
|
||||
.semantics { contentDescription = title; stateDescription = state }
|
||||
.padding(start = 12.dp, end = 8.dp, top = 6.dp, bottom = 6.dp),
|
||||
) {
|
||||
Column(Modifier.weight(1f)) {
|
||||
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(6.dp)) {
|
||||
Text(title.uppercase(), fontSize = 12.sp, fontWeight = FontWeight.SemiBold, letterSpacing = 1.2.sp,
|
||||
color = if (open) colors.onBackground else colors.onSurfaceVariant, maxLines = 1, overflow = TextOverflow.Ellipsis,
|
||||
modifier = Modifier.weight(1f, fill = false))
|
||||
if (tag != null) Text(
|
||||
tag, fontSize = 10.sp, fontWeight = FontWeight.SemiBold, color = pal.signal, maxLines = 1,
|
||||
modifier = Modifier.clip(RoundedCornerShape(6.dp)).background(pal.signal.copy(alpha = 0.14f))
|
||||
.padding(horizontal = 6.dp, vertical = 2.dp),
|
||||
)
|
||||
}
|
||||
if (!open && !summary.isNullOrEmpty()) Text(
|
||||
summary, fontSize = 12.sp, color = colors.onSurfaceVariant, maxLines = 1, overflow = TextOverflow.Ellipsis,
|
||||
modifier = Modifier.padding(top = 2.dp),
|
||||
)
|
||||
}
|
||||
Icon(Icons.Outlined.ExpandMore, contentDescription = null, tint = colors.onSurfaceVariant,
|
||||
modifier = Modifier.size(22.dp).rotate(rotation))
|
||||
}
|
||||
AnimatedVisibility(open, enter = expandVertically(Motion.tw(200)) + fadeIn(Motion.tw(160)),
|
||||
exit = shrinkVertically(Motion.tw(160)) + fadeOut(Motion.tw(120))) {
|
||||
Column(Modifier.fillMaxWidth()) {
|
||||
Box(Modifier.fillMaxWidth().height(1.dp).background(pal.line))
|
||||
// Only top-level groups fold; groups and dialogs opened from inside one draw normally.
|
||||
CompositionLocalProvider(LocalDrawerSections provides null) { content() }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,8 @@ internal fun DroidDeckHudSettings(host: MenuHost, a: DrawerActions, track: (Stri
|
||||
fun on(key: String) = cfg[key] == "1"
|
||||
fun int(key: String, fallback: Int) = cfg[key]?.toIntOrNull() ?: fallback
|
||||
|
||||
SettingsGroup(stringResource(R.string.drawer_hud)) {
|
||||
SettingsGroup(stringResource(R.string.drawer_hud), key = "performance-hud",
|
||||
detail = stringResource(if (a.hudOn) R.string.widgets_on else R.string.widgets_off)) {
|
||||
ToggleRow(host, "hud", stringResource(R.string.drawer_hud), null, a.hudOn, chipModifier = track("hud"), onChange = a.onHud)
|
||||
if (a.hudOn) ToggleRow(
|
||||
host, "hud-only-during-game", stringResource(R.string.hud_only_during_game),
|
||||
@@ -62,7 +63,7 @@ internal fun DroidDeckHudSettings(host: MenuHost, a: DrawerActions, track: (Stri
|
||||
if (a.dashboardAvailable && a.secondScreenDisplays.isNotEmpty()) BottomStripSettings(host, track)
|
||||
if (!a.hudOn) return
|
||||
|
||||
SettingsGroup(stringResource(R.string.hud_group_look)) {
|
||||
SettingsGroup(stringResource(R.string.hud_group_look), key = "performance-hud-look") {
|
||||
SliderRow(stringResource(R.string.hud_scale), null, int("hudScale", 100), 50..150, step = 5, format = { "$it%" },
|
||||
modifier = track("hud-scale")) { a.onHudSetting("hudScale", it.toString()) }
|
||||
SliderRow(stringResource(R.string.drawer_hud_opacity), null, int("hudOpacity", 80), 0..100, step = 5, format = { "$it%" },
|
||||
@@ -85,7 +86,7 @@ internal fun DroidDeckHudSettings(host: MenuHost, a: DrawerActions, track: (Stri
|
||||
}
|
||||
|
||||
var editing by remember { mutableStateOf(false) }
|
||||
SettingsGroup(stringResource(R.string.hud_group_metrics)) {
|
||||
SettingsGroup(stringResource(R.string.hud_group_metrics), key = "performance-hud-metrics") {
|
||||
ActionRow(stringResource(R.string.hud_group_metrics), null, stringResource(R.string.common_edit),
|
||||
onClick = { editing = true }, modifier = track("hud-readings"))
|
||||
val rows = DroidDeckHudSize.rowsFor(DroidDeckHudSize.from(cfg["hudSize"]), cfg)
|
||||
@@ -103,7 +104,7 @@ internal fun DroidDeckHudSettings(host: MenuHost, a: DrawerActions, track: (Stri
|
||||
)
|
||||
}
|
||||
|
||||
if (on("showTemp") || on("showGpuTemp") || on("showBatteryTemp")) SettingsGroup(stringResource(R.string.hud_group_temps)) {
|
||||
if (on("showTemp") || on("showGpuTemp") || on("showBatteryTemp")) SettingsGroup(stringResource(R.string.hud_group_temps), key = "performance-hud-temps") {
|
||||
ChoiceRow(host, "hud-temp-unit", stringResource(R.string.hud_temp_unit), null,
|
||||
listOf("c" to "°C", "f" to "°F"), if (cfg["tempUnit"].equals("f", true)) "f" else "c",
|
||||
chipModifier = track("hud-temp-unit")) { a.onHudSetting("tempUnit", it) }
|
||||
@@ -129,7 +130,7 @@ internal fun DroidDeckHudSettings(host: MenuHost, a: DrawerActions, track: (Stri
|
||||
}
|
||||
}
|
||||
|
||||
SettingsGroup(stringResource(R.string.hud_group_more)) {
|
||||
SettingsGroup(stringResource(R.string.hud_group_more), key = "performance-hud-more") {
|
||||
ActionRow(stringResource(R.string.hud_export), stringResource(R.string.hud_export_hint),
|
||||
stringResource(R.string.hud_export_button), onClick = a.onHudExport, modifier = track("hud-export"))
|
||||
ActionRow(stringResource(R.string.hud_reset), null, stringResource(R.string.hud_reset_button),
|
||||
@@ -145,7 +146,7 @@ private fun BottomStripSettings(host: MenuHost, track: (String) -> Modifier) {
|
||||
var hudOn by remember { mutableStateOf(SessionPrefs.bottomHud(context)) }
|
||||
var onTabs by remember { mutableStateOf(SessionPrefs.bottomStripOnTabs(context)) }
|
||||
var shown by remember { mutableStateOf(SessionPrefs.bottomStripMetrics(context)) }
|
||||
SettingsGroup(stringResource(R.string.bottom_hud_group)) {
|
||||
SettingsGroup(stringResource(R.string.bottom_hud_group), key = "performance-bottom-hud") {
|
||||
ToggleRow(host, "bottom-hud", stringResource(R.string.bottom_hud_group), null, hudOn,
|
||||
chipModifier = track("bottom-hud")) { on ->
|
||||
hudOn = on
|
||||
|
||||
@@ -88,7 +88,7 @@ internal fun VrControllerGroups(host: MenuHost, track: (String) -> Modifier = {
|
||||
androidx.compose.runtime.LaunchedEffect(Unit) { com.droiddeck.launcher.input.VrControllers.load(context) }
|
||||
val c by com.droiddeck.launcher.input.VrControllers.settings.collectAsState()
|
||||
val emulate = com.droiddeck.launcher.input.VrControllers.Emulate.entries
|
||||
SettingsGroup(stringResource(R.string.vr_controllers_group)) {
|
||||
SettingsGroup(stringResource(R.string.vr_controllers_group), key = "vr-controllers") {
|
||||
ChoiceRow(host, "vr-emulate", stringResource(R.string.vr_controllers_emulate), stringResource(R.string.vr_controllers_emulate_hint),
|
||||
emulate.map { it to stringResource(when (it) {
|
||||
com.droiddeck.launcher.input.VrControllers.Emulate.OFF -> R.string.vr_controllers_off
|
||||
@@ -142,13 +142,13 @@ internal fun GlassesGroups(
|
||||
val directView = usesGlasses && picture == GlassesRendering.Picture.STEREO
|
||||
val menuScreen = !inSession && g.usable && s.gameOnGlasses && s.screen3dof
|
||||
if (g.canControl && onRecenter != null && s.headTracking && (virtualScreen || menuScreen || (directView && steamVrRunning))) {
|
||||
SettingsGroup(stringResource(R.string.glasses_quick_actions), compact = true) {
|
||||
SettingsGroup(stringResource(R.string.glasses_quick_actions), compact = true, key = "vr-glasses-quick") {
|
||||
ActionRow(stringResource(R.string.glasses_recenter),
|
||||
if (virtualScreen || menuScreen) stringResource(R.string.glasses_recenter_screen_hint) else null,
|
||||
stringResource(R.string.cardboard_recenter_button), onRecenter)
|
||||
}
|
||||
}
|
||||
if (display) SettingsGroup(g.model) {
|
||||
if (display) SettingsGroup(g.model, key = "vr-glasses") {
|
||||
if (g.experimental) SettingsRow(stringResource(R.string.glasses_control), stringResource(
|
||||
if (g.supportsDisplayModeControl) R.string.glasses_xreal_experimental else R.string.glasses_pro2_experimental)) {}
|
||||
val status = if (g.hasDisplay) stringResource(R.string.glasses_status, g.width, g.height, kotlin.math.round(g.hz).toInt(),
|
||||
@@ -170,7 +170,7 @@ internal fun GlassesGroups(
|
||||
s.gameOnGlasses, chipModifier = track("glasses-game")) { Glasses.setGameOnGlasses(it) }
|
||||
}
|
||||
if (display && g.canControl && g.supportsDisplayModeControl && (inSession || g.sbs || g.sbsSupport == GlassesState.SBS_FAILS)) {
|
||||
SettingsGroup(stringResource(R.string.glasses_display_mode)) {
|
||||
SettingsGroup(stringResource(R.string.glasses_display_mode), key = "vr-glasses-mode") {
|
||||
if (g.sbsSupport == GlassesState.SBS_FAILS && !g.sbs) {
|
||||
ActionRow(stringResource(R.string.glasses_3d), stringResource(R.string.glasses_3d_failed),
|
||||
stringResource(R.string.stores_dl_retry), { Glasses.set3d(true) })
|
||||
@@ -182,12 +182,12 @@ internal fun GlassesGroups(
|
||||
val profiles = if (inSession) listOf(GlassesDisplayModes.profile(g.sbs, false))
|
||||
else listOf(GlassesDisplayProfile.TWO_D, GlassesDisplayProfile.THREE_D)
|
||||
for (profile in profiles) SettingsGroup(stringResource(if (profile == GlassesDisplayProfile.TWO_D)
|
||||
R.string.glasses_output_2d else R.string.glasses_output_3d)) {
|
||||
R.string.glasses_output_2d else R.string.glasses_output_3d), key = "vr-glasses-output-${profile.name.lowercase()}") {
|
||||
GlassesResolutionRow(host, g, s, profile, track)
|
||||
if ((profile == GlassesDisplayProfile.THREE_D) == g.sbs) GlassesRefreshRow(host, g, s, track)
|
||||
}
|
||||
}
|
||||
if (display && (g.canControl || g.hasDisplay)) SettingsGroup(stringResource(R.string.glasses_picture_group)) {
|
||||
if (display && (g.canControl || g.hasDisplay)) SettingsGroup(stringResource(R.string.glasses_picture_group), key = "vr-glasses-picture") {
|
||||
ChoiceRow(host, "glasses-picture", stringResource(R.string.glasses_picture), stringResource(R.string.glasses_picture_hint),
|
||||
listOf(
|
||||
GlassesSettings.PICTURE_AUTO to stringResource(R.string.glasses_picture_auto),
|
||||
@@ -213,7 +213,7 @@ internal fun GlassesGroups(
|
||||
format = { SpatialMeasurements.distance(it / 10f) }, modifier = track("glasses-distance")) { Glasses.setScreenDistanceDm(it) }
|
||||
}
|
||||
}
|
||||
if (vr && (g.canControl || g.hasDisplay)) SettingsGroup(stringResource(R.string.cardboard_steamvr)) {
|
||||
if (vr && (g.canControl || g.hasDisplay)) SettingsGroup(stringResource(R.string.cardboard_steamvr), key = "vr-glasses-steamvr") {
|
||||
steamVr()
|
||||
if (g.supportsDisplayModeControl) ToggleRow(host, "glasses-auto3d", stringResource(R.string.glasses_auto3d),
|
||||
stringResource(R.string.glasses_auto3d_hint), s.auto3d, chipModifier = track("glasses-auto3d")) { Glasses.setAuto3d(it) }
|
||||
@@ -226,7 +226,7 @@ internal fun GlassesGroups(
|
||||
format = { "$it°" }, modifier = track("glasses-vr-fov")) { Glasses.setVrFovDeg(it) }
|
||||
}
|
||||
if ((tab == null || tab == GlassesTab.TRACKING) && g.canControl) {
|
||||
SettingsGroup(stringResource(R.string.glasses_head_tracking)) {
|
||||
SettingsGroup(stringResource(R.string.glasses_head_tracking), key = "vr-glasses-tracking") {
|
||||
val trackingHint = when {
|
||||
inSession && !usesGlasses -> R.string.glasses_screen_no_output
|
||||
spatialVr -> R.string.glasses_head_tracking_spatial_vr_hint
|
||||
@@ -240,13 +240,13 @@ internal fun GlassesGroups(
|
||||
chipModifier = track("glasses-tracking")) { Glasses.setHeadTracking(it) }
|
||||
}
|
||||
val calibration by Glasses.calibration.collectAsState()
|
||||
if (calibration.supported) SettingsGroup(stringResource(R.string.glasses_calibration)) {
|
||||
if (calibration.supported) SettingsGroup(stringResource(R.string.glasses_calibration), key = "vr-glasses-calibration") {
|
||||
GlassesCalibrationControls(calibration,
|
||||
onStart = Glasses::startCalibration, onCancel = Glasses::cancelCalibration,
|
||||
onReset = Glasses::resetCalibration, onDone = { onRecenter?.invoke() })
|
||||
}
|
||||
}
|
||||
if ((tab == null || tab == GlassesTab.HARDWARE) && g.canControl && g.hardwareControls) SettingsGroup(stringResource(R.string.glasses_hardware)) {
|
||||
if ((tab == null || tab == GlassesTab.HARDWARE) && g.canControl && g.hardwareControls) SettingsGroup(stringResource(R.string.glasses_hardware), key = "vr-glasses-hardware") {
|
||||
if (g.brightnessMax > 0) SliderRow(stringResource(R.string.glasses_brightness), null, g.brightness.coerceAtLeast(0), 0..g.brightnessMax, step = 1,
|
||||
modifier = track("glasses-brightness")) { Glasses.setBrightness(it) }
|
||||
if (g.volumeMax > 0) SliderRow(stringResource(R.string.glasses_volume), null, g.volume.coerceAtLeast(0), 0..g.volumeMax, step = 1,
|
||||
@@ -259,7 +259,7 @@ internal fun GlassesGroups(
|
||||
androidx.compose.runtime.LaunchedEffect(Unit) { HandTracking.load(context) }
|
||||
if ((tab == null || tab == GlassesTab.TRACKING) && g.canControl) {
|
||||
if (g.spatialConnected) {
|
||||
SettingsGroup(stringResource(R.string.glasses_experimental)) {
|
||||
SettingsGroup(stringResource(R.string.glasses_experimental), key = "vr-glasses-experimental") {
|
||||
val spatial by SpatialTracking.status.collectAsState()
|
||||
ToggleRow(host, "glasses-position", stringResource(R.string.glasses_position), stringResource(R.string.glasses_position_hint),
|
||||
s.positionalTracking, chipModifier = track("glasses-position")) { Glasses.setPositionalTracking(it) }
|
||||
@@ -282,7 +282,7 @@ internal fun GlassesGroups(
|
||||
s.joyConTracking, enabled = s.positionalTracking, chipModifier = track("glasses-joycons")) { Glasses.setJoyConTracking(it) }
|
||||
}
|
||||
}
|
||||
if (hands.usable) SettingsGroup(stringResource(R.string.phone_camera_tracking_group)) {
|
||||
if (hands.usable) SettingsGroup(stringResource(R.string.phone_camera_tracking_group), key = "vr-hand-camera") {
|
||||
HandCameraRows(host, track, inSession)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,6 +44,7 @@ import com.droiddeck.launcher.session.SessionPrefs
|
||||
import kotlin.math.abs
|
||||
import kotlin.math.atan2
|
||||
import kotlin.math.hypot
|
||||
import kotlin.math.max
|
||||
import kotlin.math.min
|
||||
|
||||
@SuppressLint("ViewConstructor")
|
||||
@@ -63,6 +64,7 @@ class InputSurfaceView(
|
||||
private val art by lazy(LazyThreadSafetyMode.NONE) { PadArt(context) }
|
||||
private var artworkDpad = emptyList<HoldButton>()
|
||||
private val artworkDpadBounds = RectF()
|
||||
private var crossDpads = emptyList<Pair<List<HoldButton>, RectF>>()
|
||||
private var requestedLayout = customLayout
|
||||
init { customLayout = surfaceStyle.shown(customLayout); addView(content, LayoutParams(-1, -1)); renderCustom(pad) }
|
||||
|
||||
@@ -185,6 +187,7 @@ class InputSurfaceView(
|
||||
|
||||
private fun renderCustom(pad: PadBridge?) {
|
||||
artworkDpad = emptyList()
|
||||
crossDpads = emptyList()
|
||||
val canvas = object : ViewGroup(context) {
|
||||
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
|
||||
val layout = customLayout
|
||||
@@ -203,6 +206,7 @@ class InputSurfaceView(
|
||||
child.layout(x, y, x + child.measuredWidth, y + child.measuredHeight)
|
||||
}
|
||||
updateArtworkDpad(this)
|
||||
updateCrossDpad(this)
|
||||
}
|
||||
|
||||
override fun dispatchDraw(canvas: Canvas) {
|
||||
@@ -244,11 +248,39 @@ class InputSurfaceView(
|
||||
canvas.getChildAt(index) as? HoldButton
|
||||
}
|
||||
val previous = artworkDpad
|
||||
artworkDpad = if (crossed(buttons)) buttons else emptyList()
|
||||
artworkDpad = if (crossed(buttons, artworkDpadBounds)) buttons else emptyList()
|
||||
if (artworkDpad != previous) (previous + artworkDpad).forEach { it.invalidate() }
|
||||
}
|
||||
|
||||
private fun crossed(buttons: List<HoldButton>): Boolean {
|
||||
private fun updateCrossDpad(canvas: ViewGroup) {
|
||||
val buttons = (0 until canvas.childCount).map(canvas::getChildAt).filterIsInstance<HoldButton>()
|
||||
val (ups, rights, downs, lefts) = DIRECTIONS.map { direction -> buttons.filter { (it.tag as? InputSurfaceElement)?.control == direction } }
|
||||
crossDpads = ups.flatMap { up -> rights.flatMap { right -> downs.flatMap { down ->
|
||||
lefts.mapNotNull { left -> listOf(up, right, down, left).let { arms -> hole(arms)?.let { arms to it } } } } } }
|
||||
}
|
||||
|
||||
private fun hole(buttons: List<HoldButton>): RectF? {
|
||||
val (up, right, down, left) = buttons
|
||||
val hole = RectF(left.right.toFloat(), up.bottom.toFloat(), right.left.toFloat(), down.top.toFloat())
|
||||
val across = max(up.left, down.left) to min(up.right, down.right)
|
||||
val along = max(left.top, right.top) to min(left.bottom, right.bottom)
|
||||
return hole.takeIf {
|
||||
!it.isEmpty && across.first < across.second && along.first < along.second &&
|
||||
across.first < it.right && across.second > it.left && along.first < it.bottom && along.second > it.top
|
||||
}
|
||||
}
|
||||
|
||||
private fun crossTarget(x: Float, y: Float): HoldButton? {
|
||||
val first = crossDpads.firstOrNull()?.first?.first() ?: return null
|
||||
val hx = x - (originX(first) - first.left)
|
||||
val hy = y - (originY(first) - first.top)
|
||||
return crossDpads.filter { (arms, hole) -> arms.all { it.visibility == VISIBLE } && hole.contains(hx, hy) }
|
||||
.flatMap { it.first }.distinct().minByOrNull { arm ->
|
||||
hypot(max(max(arm.left - hx, hx - arm.right), 0f), max(max(arm.top - hy, hy - arm.bottom), 0f))
|
||||
}
|
||||
}
|
||||
|
||||
private fun crossed(buttons: List<HoldButton>, bounds: RectF): Boolean {
|
||||
if (buttons.size != DIRECTIONS.size) return false
|
||||
val (up, right, down, left) = buttons
|
||||
val centerX = (left.left + right.right) / 2f
|
||||
@@ -258,7 +290,7 @@ class InputSurfaceView(
|
||||
kotlin.math.abs((left.top + left.bottom) / 2f - centerY) > 2f ||
|
||||
kotlin.math.abs((right.top + right.bottom) / 2f - centerY) > 2f ||
|
||||
up.bottom >= down.top || left.right >= right.left) return false
|
||||
artworkDpadBounds.set(left.left.toFloat(), up.top.toFloat(), right.right.toFloat(), down.bottom.toFloat())
|
||||
bounds.set(left.left.toFloat(), up.top.toFloat(), right.right.toFloat(), down.bottom.toFloat())
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -284,6 +316,7 @@ class InputSurfaceView(
|
||||
val views = (canvas.childCount - 1 downTo 0).map(canvas::getChildAt).filter { it.visibility == VISIBLE }
|
||||
views.firstOrNull { !(it is StickView && it.adaptive) && hits(it, x, y, 0f) }?.let { return it }
|
||||
views.filter { it is HoldButton && hits(it, x, y, slack(it)) }.minByOrNull { distance(it, x, y) }?.let { return it }
|
||||
crossTarget(x, y)?.let { return it }
|
||||
if (views.any { it is HoldButton && hits(it, x, y, slack(it) + ADAPTIVE_CLEARANCE_PX) }) return null
|
||||
return views.filter { it is StickView && it.adaptive && it !in owners.values && (hits(it, x, y, 0f) || it.captures(x - originX(it), y - originY(it))) }
|
||||
.minByOrNull { distance(it, x, y) }
|
||||
|
||||
@@ -116,10 +116,7 @@ internal object NavTabs {
|
||||
|
||||
fun more(s: FrontEndState) = listed(s).filter { place(s, it) == TabPlace.MORE }
|
||||
|
||||
fun bar(s: FrontEndState): List<String> {
|
||||
val shown = listed(s).filter { place(s, it) == TabPlace.BAR }
|
||||
return if (more(s).isEmpty()) shown else shown + MORE
|
||||
}
|
||||
fun bar(s: FrontEndState): List<String> = listed(s).filter { place(s, it) == TabPlace.BAR } + MORE
|
||||
|
||||
fun setHidden(context: Context, key: String, hide: Boolean) {
|
||||
hidden = if (hide && hideable(key)) hidden + key else hidden - key
|
||||
|
||||
@@ -11,7 +11,7 @@ internal fun PenSettingsGroup(
|
||||
host: MenuHost, pen: SessionPrefs.Pen, track: (String) -> Modifier = { Modifier },
|
||||
onPick: (key: String, value: String) -> Unit,
|
||||
) {
|
||||
SettingsGroup(stringResource(R.string.mode_pen)) {
|
||||
SettingsGroup(stringResource(R.string.mode_pen), key = "controller-pen") {
|
||||
ChoiceRow(host, "pen", stringResource(R.string.mode_pen), null,
|
||||
listOf(SessionPrefs.PEN_MOUSE to stringResource(R.string.mode_pen_mouse),
|
||||
SessionPrefs.PEN_TOUCH to stringResource(R.string.mode_pen_touch)),
|
||||
|
||||
@@ -218,7 +218,7 @@ fun PerformancePage(
|
||||
|
||||
@Composable
|
||||
internal fun GpuClockGroup(host: MenuHost, on: Boolean, chipModifier: Modifier = Modifier, onChange: (Boolean) -> Unit) {
|
||||
SettingsGroup(stringResource(R.string.perf_gpu)) {
|
||||
SettingsGroup(stringResource(R.string.perf_gpu), key = "performance-gpu") {
|
||||
ToggleRow(
|
||||
host, "gpuclock", stringResource(R.string.perf_gpuclock),
|
||||
null,
|
||||
|
||||
@@ -6,17 +6,18 @@ import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.setValue
|
||||
import com.droiddeck.launcher.session.SessionPrefs
|
||||
|
||||
/** HUD holds the Performance page and GAMES the Game page; the names stay because saved page orders use them. */
|
||||
internal enum class SessionDrawerPage(val firstControl: String) {
|
||||
CONTROLLER("input-profile"),
|
||||
GLASSES("glasses-game"),
|
||||
DISPLAY("fg"),
|
||||
HUD("hud"),
|
||||
EFFECTS("look"),
|
||||
GAMES("anisotropy"),
|
||||
AGENT("agent-input"),
|
||||
SESSION("suspend"),
|
||||
CONTROLLER("section-controller-input"),
|
||||
HUD("section-performance-pacing"),
|
||||
DISPLAY("section-display"),
|
||||
EFFECTS("section-effects-look"),
|
||||
GAMES("section-game-profile"),
|
||||
VR("section-vr-steamvr"),
|
||||
SESSION("pause"),
|
||||
MORE("more-edit"),
|
||||
VR("steamvr"),
|
||||
ACHIEVEMENTS("achievements"),
|
||||
AGENT("agent-input"),
|
||||
}
|
||||
|
||||
internal object DrawerPages {
|
||||
@@ -71,16 +72,16 @@ internal object DrawerPages {
|
||||
}
|
||||
|
||||
internal fun offeredDrawerPages(
|
||||
hasGlasses: Boolean = false, hasAgent: Boolean = com.droiddeck.launcher.agent.AgentTab.shown,
|
||||
hasAchievements: Boolean = false, hasAgent: Boolean = com.droiddeck.launcher.agent.AgentTab.shown,
|
||||
): List<SessionDrawerPage> =
|
||||
DrawerPages.order.filter {
|
||||
(hasGlasses || it != SessionDrawerPage.GLASSES) &&
|
||||
(hasAchievements || it != SessionDrawerPage.ACHIEVEMENTS) &&
|
||||
(hasAgent || it != SessionDrawerPage.AGENT)
|
||||
}
|
||||
|
||||
internal fun sessionDrawerPages(
|
||||
hasGlasses: Boolean = false, hasAgent: Boolean = com.droiddeck.launcher.agent.AgentTab.shown,
|
||||
): List<SessionDrawerPage> = offeredDrawerPages(hasGlasses, hasAgent).filter { it !in DrawerPages.hidden }
|
||||
hasAchievements: Boolean = false, hasAgent: Boolean = com.droiddeck.launcher.agent.AgentTab.shown,
|
||||
): List<SessionDrawerPage> = offeredDrawerPages(hasAchievements, hasAgent).filter { it !in DrawerPages.hidden }
|
||||
|
||||
/** The pages shown as tabs: everything up to and including the More tab. */
|
||||
internal fun List<SessionDrawerPage>.strip(): List<SessionDrawerPage> {
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -443,7 +443,11 @@ fun ValueChip(text: String, open: Boolean, enabled: Boolean = true, modifier: Mo
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun SettingsGroup(title: String, compact: Boolean = false, detail: String? = null, content: @Composable ColumnScope.() -> Unit) {
|
||||
fun SettingsGroup(title: String, compact: Boolean = false, detail: String? = null, key: String? = null, tag: String? = null, content: @Composable ColumnScope.() -> Unit) {
|
||||
LocalDrawerSections.current?.let { sections ->
|
||||
DrawerSection(sections, key ?: title, title, detail, tag, content)
|
||||
return
|
||||
}
|
||||
val tight = compact || LocalCompactSettings.current
|
||||
val colors = MaterialTheme.colorScheme
|
||||
val pal = LocalPalette.current
|
||||
|
||||
@@ -56,6 +56,7 @@ import androidx.compose.ui.draw.alpha
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.focus.FocusRequester
|
||||
import androidx.compose.ui.focus.focusRequester
|
||||
import androidx.compose.ui.focus.onFocusChanged
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
@@ -358,6 +359,67 @@ internal fun SessionAchievementsPanel(label: String, state: AchievementsState, t
|
||||
}
|
||||
}
|
||||
|
||||
/** The Achievements page of the session menu: the same list as the full panel, inside the menu's own scroll. */
|
||||
@Composable
|
||||
internal fun DrawerAchievementsPage(game: StoreAchievements.Game, title: String?, track: (String) -> Modifier) {
|
||||
val colors = MaterialTheme.colorScheme
|
||||
val pal = LocalPalette.current
|
||||
val label = StoreAchievements.forSource(game.source)?.label.orEmpty()
|
||||
val state = rememberAchievements(game) ?: AchievementsState.READING
|
||||
val kinds = remember(state.list) {
|
||||
val list = state.list.orEmpty()
|
||||
val split = groups(list)
|
||||
if (split.size < 2) emptyList() else listOf(R.string.stores_tab_all to list) + split
|
||||
}
|
||||
var pick by remember { mutableIntStateOf(0) }
|
||||
if (pick >= kinds.size) pick = 0
|
||||
var noteHadFocus by remember { mutableStateOf(false) }
|
||||
val firstRow = remember { FocusRequester() }
|
||||
val loaded = !state.list.isNullOrEmpty()
|
||||
LaunchedEffect(loaded) {
|
||||
if (loaded && noteHadFocus) {
|
||||
noteHadFocus = false
|
||||
withFrameNanos { }
|
||||
runCatching { firstRow.requestFocus() }
|
||||
}
|
||||
}
|
||||
Column(Modifier.fillMaxWidth().padding(top = 8.dp, start = 4.dp, end = 4.dp)) {
|
||||
Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.fillMaxWidth()) {
|
||||
Text(title.orEmpty(), fontSize = 13.sp, color = colors.onSurfaceVariant, maxLines = 1, overflow = TextOverflow.Ellipsis, modifier = Modifier.weight(1f))
|
||||
state.list?.takeIf { it.isNotEmpty() }?.let { list ->
|
||||
if (state.all) Trophy(18.dp, Modifier.padding(end = 6.dp))
|
||||
Text(stringResource(R.string.achievements_count_short, state.done, list.size), fontSize = 15.sp, fontWeight = FontWeight.SemiBold, color = pal.signal)
|
||||
}
|
||||
}
|
||||
val list = state.list
|
||||
if (list.isNullOrEmpty()) {
|
||||
Text(achievementsNote(state, label).orEmpty(), fontSize = 13.sp, color = colors.onSurfaceVariant,
|
||||
modifier = Modifier.padding(top = 12.dp).then(track("achievements"))
|
||||
.onFocusChanged { if (it.isFocused) noteHadFocus = true }.focusable())
|
||||
return@Column
|
||||
}
|
||||
LinearProgressIndicator(
|
||||
progress = { state.done / list.size.toFloat() }, color = pal.signal, trackColor = pal.line,
|
||||
modifier = Modifier.padding(top = 8.dp).fillMaxWidth().height(4.dp).clip(RoundedCornerShape(2.dp)),
|
||||
)
|
||||
if (kinds.isNotEmpty()) TabStrip(
|
||||
kinds.map { (name, group) -> if (name == R.string.stores_tab_all) stringResource(name) + " · " + group.size else stringResource(name, group.size) },
|
||||
pick, { pick = it }, Modifier.padding(top = 10.dp), bumpers = false, compact = true,
|
||||
)
|
||||
val shown = kinds.getOrNull(pick)?.second ?: list
|
||||
val sections = if (pick == 0) groups(shown).filter { it.second.isNotEmpty() } else listOf(null to shown)
|
||||
val first = sections.firstOrNull()?.second?.firstOrNull()?.id
|
||||
Column(Modifier.padding(top = 6.dp), verticalArrangement = Arrangement.spacedBy(6.dp)) {
|
||||
for ((group, items) in sections) {
|
||||
if (group != null) AchievementGroupLabel(stringResource(group, items.size))
|
||||
for (a in items) androidx.compose.runtime.key(a.id) {
|
||||
AchievementRow(a, compact = true, if (a.id == first) track("achievements").focusRequester(firstRow) else Modifier)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
internal fun DrawerAchievementsRow(progress: Pair<Int, Int>?, modifier: Modifier = Modifier, onClick: () -> Unit) {
|
||||
val colors = MaterialTheme.colorScheme
|
||||
|
||||
@@ -707,7 +707,22 @@
|
||||
<string name="drawer_next_page">Next page</string>
|
||||
<string name="drawer_manage_pages">Arrange pages</string>
|
||||
<string name="drawer_page_more">More</string>
|
||||
<string name="drawer_more_back">Back to %1$s</string>
|
||||
<string name="drawer_page_performance">Performance</string>
|
||||
<string name="drawer_page_game">Game</string>
|
||||
<string name="drawer_page_vr">VR & glasses</string>
|
||||
<string name="drawer_section_pacing">Frame pacing</string>
|
||||
<string name="drawer_section_mouse">Mouse</string>
|
||||
<string name="drawer_section_keyboard_layout">Keyboard layout</string>
|
||||
<string name="drawer_section_input">Input profile</string>
|
||||
<string name="drawer_section_compat">Compatibility</string>
|
||||
<string name="drawer_section_tuning">Fine tuning</string>
|
||||
<string name="drawer_tag_controller">controller connected</string>
|
||||
<string name="drawer_tag_no_controller">no controller</string>
|
||||
<string name="drawer_tag_running">running</string>
|
||||
<string name="drawer_tag_custom">custom look</string>
|
||||
<string name="drawer_tag_attached">attached</string>
|
||||
<string name="drawer_tag_downloading">downloading</string>
|
||||
<string name="drawer_pause_game">Pause game</string> <string name="drawer_more_back">Back to %1$s</string>
|
||||
<string name="drawer_more_empty">Nothing is kept here. Arrange pages and move one below the More row.</string>
|
||||
<string name="drawer_pages_reset">Reset</string>
|
||||
<string name="drawer_pages_done">Done</string>
|
||||
|
||||
@@ -13,7 +13,7 @@ class GpuStatsBindsTest {
|
||||
@Test fun feedsWithNoValueYetAreStillBound() {
|
||||
val dir = tmp.newFolder("kgsl-3d0")
|
||||
GpuStatsComponent.createMissing(listOf(File(dir, "perf_now"), File(dir, "cur_freq")))
|
||||
val binds = GpuStatsComponent(dir, tmp.root, kgsl = true).binds()
|
||||
val binds = GpuStatsComponent(dir, tmp.root).binds()
|
||||
assertTrue(binds.contains(File(dir, "perf_now").path + ":" + GpuStatsComponent.MSM_LOAD))
|
||||
assertTrue(binds.contains(File(dir, "cur_freq").path + ":" + GpuStatsComponent.MSM_CLOCK))
|
||||
}
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
package com.droiddeck.launcher.session
|
||||
|
||||
import com.droiddeck.launcher.hud.HudMetrics
|
||||
import java.io.File
|
||||
import org.junit.After
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.rules.TemporaryFolder
|
||||
|
||||
class GpuStatsComponentWithoutKgslTest {
|
||||
@get:Rule val tmp = TemporaryFolder()
|
||||
private val parts = ArrayList<GpuStatsComponent>()
|
||||
|
||||
private fun component(nodes: List<String>, metrics: HudMetrics? = null) =
|
||||
GpuStatsComponent(tmp.newFolder("kgsl-3d0"), tmp.root, metrics, kgsl = false, loadNodes = { nodes }).also { parts += it }
|
||||
|
||||
@After fun reset() {
|
||||
parts.forEach { it.stop() }
|
||||
KgslBusy.status = "not tried"
|
||||
KgslClock.status = "not tried"
|
||||
}
|
||||
|
||||
@Test fun noReadableLoadNodeWithoutKgslTurnsTheTimingFeedOn() {
|
||||
assertTrue(GpuStatsComponent.noLoadNode(false) { emptyList() })
|
||||
assertFalse(GpuStatsComponent.noLoadNode(false) { listOf(MALI_NODE) })
|
||||
}
|
||||
|
||||
@Test fun kgslDevicesIgnoreOtherGpusNodes() {
|
||||
val decided = GpuStatsComponent.noLoadNode(true) { throw AssertionError("kgsl devices read other GPUs' nodes") }
|
||||
assertEquals(GpuStatsComponent.loadBlocked(), decided)
|
||||
}
|
||||
|
||||
@Test fun withoutAnyLoadNodeTheHudLoadComesFromVulkanTiming() {
|
||||
val gpu = component(emptyList())
|
||||
assertTrue(gpu.prepare())
|
||||
assertTrue(GpuStatsComponent.sources, GpuStatsComponent.sources.startsWith("gpu_busy_percentage Vulkan timing"))
|
||||
assertTrue(File(gpu.dir, "perf_now").isFile)
|
||||
assertEquals(emptyList<String>(), gpu.binds())
|
||||
assertEquals("", GpuStatsComponent.readerStatus())
|
||||
}
|
||||
|
||||
@Test fun aReadableLoadNodeFeedsTheHudInsteadOfTheLayer() {
|
||||
val gpu = component(listOf(MALI_NODE), HudMetrics(null))
|
||||
assertTrue(gpu.prepare())
|
||||
assertTrue(GpuStatsComponent.sources, GpuStatsComponent.sources.startsWith("gpu_busy_percentage $MALI_NODE"))
|
||||
assertTrue(File(gpu.dir, "perf_now").isFile)
|
||||
assertFalse(File(GpuStatsComponent.guestLoadDir(tmp.root), "on").exists())
|
||||
assertEquals("", GpuStatsComponent.readerStatus())
|
||||
}
|
||||
|
||||
private companion object {
|
||||
const val MALI_NODE = "/sys/class/misc/mali0/device/utilisation"
|
||||
}
|
||||
}
|
||||
@@ -30,4 +30,16 @@ class OutputPacingTest {
|
||||
@Test fun mirroringKeepsTheGlassesRate() {
|
||||
assertEquals(60, SessionPrefs.compositorFpsLimit(60))
|
||||
}
|
||||
|
||||
@Test fun gameModeOverrideCapsAPanelThatRunsFaster() {
|
||||
assertEquals(60, SessionPrefs.hostFrameCap(60.000004f, 120.00001f))
|
||||
assertEquals(0, SessionPrefs.hostFrameCap(120.00001f, 120.00001f))
|
||||
assertEquals(0, SessionPrefs.hostFrameCap(0f, 120f))
|
||||
}
|
||||
|
||||
@Test fun hostCapPacesSteamSessionsAndYieldsToLowerLimits() {
|
||||
assertEquals(60, SessionPrefs.compositorFpsLimit(0, 0, hostCap = 60))
|
||||
assertEquals(45, SessionPrefs.compositorFpsLimit(0, 45, hostCap = 60))
|
||||
assertEquals(SessionPrefs.PIP_FPS, SessionPrefs.compositorFpsLimit(0, 0, pip = true, hostCap = 60))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import androidx.compose.ui.test.SemanticsNodeInteractionsProvider
|
||||
import androidx.compose.ui.test.onNodeWithTag
|
||||
import androidx.compose.ui.test.performClick
|
||||
import androidx.compose.ui.test.performScrollTo
|
||||
|
||||
/** Session menu groups start folded; a test opens the one whose rows it checks. */
|
||||
internal fun SemanticsNodeInteractionsProvider.openSection(key: String) {
|
||||
if (DrawerSectionState.isOpen(key)) return
|
||||
onNodeWithTag("drawer-section-$key").performScrollTo().performClick()
|
||||
}
|
||||
@@ -227,6 +227,81 @@ class InputSurfaceTouchTest {
|
||||
touch(MotionEvent.ACTION_UP, 1 to (750f to 285f))
|
||||
}
|
||||
|
||||
@Test fun theMiddleOfACrossedDpadPressesTheNearestArmInsteadOfFallingThrough() {
|
||||
val up = InputSurfaceElement(InputControl.UP, .45f, .1f, .1f, .15f)
|
||||
val down = InputSurfaceElement(InputControl.DOWN, .45f, .45f, .1f, .15f)
|
||||
show(up, down, InputSurfaceElement(InputControl.LEFT, .3f, .25f, .15f, .2f),
|
||||
InputSurfaceElement(InputControl.RIGHT, .55f, .25f, .15f, .2f), a)
|
||||
val missed = mutableListOf<Int>()
|
||||
view.onTouchMiss = { missed += it.actionMasked }
|
||||
touch(MotionEvent.ACTION_DOWN, 1 to (500f to 170f))
|
||||
assertEquals(-1, state().hatY())
|
||||
touch(MotionEvent.ACTION_MOVE, 1 to (540f to 215f))
|
||||
assertEquals(1, state().hatX())
|
||||
assertEquals(0, state().hatY())
|
||||
touch(MotionEvent.ACTION_UP, 1 to (540f to 215f))
|
||||
assertEquals(0, state().hatX())
|
||||
assertTrue(missed.isEmpty())
|
||||
assertFalse(view.takesTouchAt(250f, 210f))
|
||||
assertFalse(view.takesTouchAt(800f, 500f))
|
||||
assertFalse(view.takesTouchAt(350f, 100f))
|
||||
show(up, down)
|
||||
assertFalse(view.takesTouchAt(500f, 210f))
|
||||
view.onTouchMiss = null
|
||||
}
|
||||
|
||||
@Test fun aHandPlacedDpadWithOffArmsStillTakesItsMiddle() {
|
||||
show(InputSurfaceElement(InputControl.UP, .42f, .1f, .1f, .15f),
|
||||
InputSurfaceElement(InputControl.DOWN, .42f, .45f, .1f, .15f),
|
||||
InputSurfaceElement(InputControl.LEFT, .3f, .27f, .15f, .15f),
|
||||
InputSurfaceElement(InputControl.RIGHT, .5f, .25f, .15f, .2f))
|
||||
touch(MotionEvent.ACTION_DOWN, 1 to (475f to 225f))
|
||||
assertTrue(state().hatX() != 0 || state().hatY() != 0)
|
||||
touch(MotionEvent.ACTION_UP, 1 to (475f to 225f))
|
||||
assertFalse(view.takesTouchAt(750f, 225f))
|
||||
}
|
||||
|
||||
@Test fun aTallGapPicksTheNearestArmAndSplitArmsAreNoCross() {
|
||||
show(InputSurfaceElement(InputControl.UP, .45f, .1f, .1f, .15f),
|
||||
InputSurfaceElement(InputControl.DOWN, .45f, .65f, .1f, .15f),
|
||||
InputSurfaceElement(InputControl.LEFT, .3f, .35f, .15f, .2f),
|
||||
InputSurfaceElement(InputControl.RIGHT, .55f, .35f, .15f, .2f))
|
||||
touch(MotionEvent.ACTION_DOWN, 1 to (530f to 290f))
|
||||
assertEquals(1, state().hatX())
|
||||
assertEquals(0, state().hatY())
|
||||
touch(MotionEvent.ACTION_UP, 1 to (530f to 290f))
|
||||
touch(MotionEvent.ACTION_DOWN, 1 to (530f to 180f))
|
||||
assertEquals(-1, state().hatY())
|
||||
assertEquals(0, state().hatX())
|
||||
touch(MotionEvent.ACTION_UP, 1 to (530f to 180f))
|
||||
show(InputSurfaceElement(InputControl.UP, .2f, .1f, .1f, .15f),
|
||||
InputSurfaceElement(InputControl.DOWN, .7f, .6f, .1f, .15f),
|
||||
InputSurfaceElement(InputControl.LEFT, .1f, .35f, .15f, .2f),
|
||||
InputSurfaceElement(InputControl.RIGHT, .8f, .35f, .15f, .2f))
|
||||
assertFalse(view.takesTouchAt(500f, 300f))
|
||||
}
|
||||
|
||||
@Test fun aSecondUpButtonDoesNotHideTheCross() {
|
||||
show(InputSurfaceElement(InputControl.UP, .1f, .7f, .1f, .15f, "extra-up"),
|
||||
InputSurfaceElement(InputControl.UP, .45f, .1f, .1f, .15f),
|
||||
InputSurfaceElement(InputControl.DOWN, .45f, .45f, .1f, .15f),
|
||||
InputSurfaceElement(InputControl.LEFT, .3f, .25f, .15f, .2f),
|
||||
InputSurfaceElement(InputControl.RIGHT, .55f, .25f, .15f, .2f))
|
||||
touch(MotionEvent.ACTION_DOWN, 1 to (500f to 170f))
|
||||
assertEquals(-1, state().hatY())
|
||||
touch(MotionEvent.ACTION_UP, 1 to (500f to 170f))
|
||||
assertEquals(0, state().hatY())
|
||||
show(InputSurfaceElement(InputControl.UP, .45f, 0f, .1f, .05f, "extra-up"),
|
||||
InputSurfaceElement(InputControl.UP, .45f, .1f, .1f, .15f),
|
||||
InputSurfaceElement(InputControl.DOWN, .45f, .45f, .1f, .15f),
|
||||
InputSurfaceElement(InputControl.LEFT, .3f, .25f, .15f, .2f),
|
||||
InputSurfaceElement(InputControl.RIGHT, .55f, .25f, .15f, .2f))
|
||||
touch(MotionEvent.ACTION_DOWN, 1 to (490f to 170f))
|
||||
assertEquals(-1, state().hatY())
|
||||
assertEquals(0, state().hatX())
|
||||
touch(MotionEvent.ACTION_UP, 1 to (490f to 170f))
|
||||
}
|
||||
|
||||
@Test fun adaptiveSticksCaptureAroundThemAndTheLeftOneToTheEdge() {
|
||||
val left = InputSurfaceElement(InputControl.LS, .3f, .3f, .2f, .4f, hideWhenIdle = true)
|
||||
val right = InputSurfaceElement(InputControl.RS, .6f, .3f, .2f, .4f, hideWhenIdle = true)
|
||||
|
||||
@@ -77,6 +77,17 @@ class NavTabsTest {
|
||||
assertFalse("desktop" in navigationKeys(s))
|
||||
}
|
||||
|
||||
@Test fun moreStaysOnTheBarWhenNoTabIsShelvedSoTabsCanStillBeEdited() {
|
||||
NavTabs.more(state()).forEach { place(it, TabPlace.HIDDEN) }
|
||||
assertTrue(NavTabs.more(state()).isEmpty())
|
||||
assertEquals(NavTabs.MORE, navigationKeys(state()).last())
|
||||
NavTabs.reset(ctx)
|
||||
NavTabs.more(state()).forEach { place(it, TabPlace.BAR) }
|
||||
assertTrue(NavTabs.more(state()).isEmpty())
|
||||
assertEquals(NavTabs.MORE, navigationKeys(state()).last())
|
||||
assertEquals(1, navigationKeys(state()).count { it == NavTabs.MORE })
|
||||
}
|
||||
|
||||
@Test fun appsAndTheDevHarnessCanBeShownWithoutHomeScreenOrDeveloperTools() {
|
||||
place("android-apps", TabPlace.MORE)
|
||||
assertTrue("android-apps" in NavTabs.more(state()))
|
||||
|
||||
@@ -31,7 +31,9 @@ class PenSettingsGroupTest {
|
||||
|
||||
@Test fun theDrawerHasNoPenGroupUntilAPenIsKnown() {
|
||||
compose.setContent { DroidDeckTheme { SessionDrawer(true, SessionDrawerPage.CONTROLLER, false, {}, actions(pen = null)) } }
|
||||
compose.openSection("controller-touch")
|
||||
compose.onNodeWithTag("setting-touch").assertExists()
|
||||
compose.onNodeWithTag("drawer-section-controller-pen").assertDoesNotExist()
|
||||
compose.onNodeWithTag("setting-pen").assertDoesNotExist()
|
||||
compose.onNodeWithTag("setting-pen-button").assertDoesNotExist()
|
||||
}
|
||||
@@ -43,6 +45,7 @@ class PenSettingsGroupTest {
|
||||
SessionDrawer(true, SessionDrawerPage.CONTROLLER, false, {}, actions(SessionPrefs.Pen()) { k, v -> picks += k to v })
|
||||
}
|
||||
}
|
||||
compose.openSection("controller-pen")
|
||||
compose.onNodeWithTag("setting-pen-button").performScrollTo().performClick()
|
||||
compose.onNodeWithText(context.getString(R.string.gesture_middle_click)).performScrollTo().performClick()
|
||||
compose.onNodeWithTag("setting-pen").performScrollTo().performClick()
|
||||
|
||||
@@ -4,60 +4,51 @@ import org.junit.Assert.*
|
||||
import org.junit.Test
|
||||
|
||||
class SessionDrawerPageTest {
|
||||
@Test fun navigationStartsWithControllerAndGoesStraightToDisplay() {
|
||||
@Test fun navigationRunsControllerPerformanceDisplayEffectsGameVrSession() {
|
||||
val pages = sessionDrawerPages(hasAgent = false)
|
||||
assertEquals(SessionDrawerPage.CONTROLLER, pages.first())
|
||||
assertEquals(SessionDrawerPage.DISPLAY, pages.step(SessionDrawerPage.CONTROLLER, 1))
|
||||
assertEquals(SessionDrawerPage.VR, pages.step(SessionDrawerPage.CONTROLLER, -1))
|
||||
assertEquals(SessionDrawerPage.HUD, pages.step(SessionDrawerPage.DISPLAY, 1))
|
||||
assertEquals(SessionDrawerPage.EFFECTS, pages.step(SessionDrawerPage.HUD, 1))
|
||||
assertEquals(SessionDrawerPage.GAMES, pages.step(SessionDrawerPage.EFFECTS, 1))
|
||||
assertEquals(SessionDrawerPage.SESSION, pages.step(SessionDrawerPage.GAMES, 1))
|
||||
assertEquals(
|
||||
listOf(SessionDrawerPage.CONTROLLER, SessionDrawerPage.HUD, SessionDrawerPage.DISPLAY, SessionDrawerPage.EFFECTS,
|
||||
SessionDrawerPage.GAMES, SessionDrawerPage.VR, SessionDrawerPage.SESSION, SessionDrawerPage.MORE),
|
||||
pages.strip(),
|
||||
)
|
||||
assertEquals(SessionDrawerPage.MORE, pages.step(SessionDrawerPage.CONTROLLER, -1))
|
||||
}
|
||||
|
||||
@Test fun moreKeepsSteamVrByDefaultAndStandsInForThePagesInsideIt() {
|
||||
val pages = sessionDrawerPages(hasAgent = false)
|
||||
assertEquals(listOf(SessionDrawerPage.VR), pages.inMore())
|
||||
assertEquals(SessionDrawerPage.MORE, pages.strip().last())
|
||||
assertFalse(SessionDrawerPage.VR in pages.strip())
|
||||
assertEquals(SessionDrawerPage.MORE, pages.tabFor(SessionDrawerPage.VR))
|
||||
@Test fun achievementsAndTheAgentStartInsideMore() {
|
||||
val pages = sessionDrawerPages(hasAchievements = true, hasAgent = true)
|
||||
assertEquals(listOf(SessionDrawerPage.ACHIEVEMENTS, SessionDrawerPage.AGENT), pages.inMore())
|
||||
assertEquals(SessionDrawerPage.MORE, pages.tabFor(SessionDrawerPage.ACHIEVEMENTS))
|
||||
assertEquals(SessionDrawerPage.GAMES, pages.tabFor(SessionDrawerPage.GAMES))
|
||||
val strip = pages.strip()
|
||||
assertEquals(SessionDrawerPage.MORE, strip.step(SessionDrawerPage.SESSION, 1))
|
||||
assertEquals(SessionDrawerPage.CONTROLLER, strip.step(SessionDrawerPage.MORE, 1))
|
||||
assertEquals(SessionDrawerPage.SESSION, strip.step(pages.tabFor(SessionDrawerPage.VR), -1))
|
||||
assertEquals(SessionDrawerPage.CONTROLLER, strip.step(pages.tabFor(SessionDrawerPage.AGENT), 1))
|
||||
}
|
||||
|
||||
@Test fun achievementsAreOfferedOnlyForAGameThatHasThem() {
|
||||
assertFalse(SessionDrawerPage.ACHIEVEMENTS in sessionDrawerPages(hasAchievements = false, hasAgent = false))
|
||||
assertFalse(SessionDrawerPage.AGENT in sessionDrawerPages(hasAgent = false))
|
||||
assertTrue(sessionDrawerPages(hasAgent = false).inMore().isEmpty())
|
||||
}
|
||||
|
||||
@Test fun anOlderSavedOrderKeepsItsPagesAndGetsAMoreTabAfterSession() {
|
||||
val saved = listOf("CONTROLLER", "DISPLAY", "HUD", "EFFECTS", "VR", "GAMES", "AGENT", "SESSION")
|
||||
val saved = listOf("CONTROLLER", "GLASSES", "DISPLAY", "HUD", "EFFECTS", "VR", "GAMES", "AGENT", "SESSION")
|
||||
val out = DrawerPages.arrange(saved)
|
||||
assertEquals(SessionDrawerPage.entries.toSet(), out.toSet())
|
||||
assertEquals(SessionDrawerPage.MORE, out[out.indexOf(SessionDrawerPage.SESSION) + 1])
|
||||
assertTrue(out.indexOf(SessionDrawerPage.VR) < out.indexOf(SessionDrawerPage.EFFECTS) + 2)
|
||||
assertTrue(out.inMore().isEmpty())
|
||||
assertEquals(listOf(SessionDrawerPage.ACHIEVEMENTS), out.inMore())
|
||||
assertTrue(SessionDrawerPage.AGENT in out.strip())
|
||||
}
|
||||
|
||||
@Test fun sessionCanBeKeptInsideMore() {
|
||||
val saved = listOf("CONTROLLER", "DISPLAY", "HUD", "EFFECTS", "GAMES", "AGENT", "MORE", "SESSION", "VR")
|
||||
val out = DrawerPages.arrange(saved)
|
||||
assertEquals(listOf(SessionDrawerPage.SESSION, SessionDrawerPage.VR), out.inMore())
|
||||
assertEquals(listOf(SessionDrawerPage.ACHIEVEMENTS, SessionDrawerPage.SESSION, SessionDrawerPage.VR), out.inMore())
|
||||
assertFalse(SessionDrawerPage.SESSION in out.strip())
|
||||
}
|
||||
|
||||
@Test fun moreAndSessionCannotBeHidden() {
|
||||
assertFalse(DrawerPages.hideable(SessionDrawerPage.MORE))
|
||||
}
|
||||
|
||||
@Test fun glassesAddTheirPageAfterController() {
|
||||
val pages = sessionDrawerPages(hasGlasses = true, hasAgent = false)
|
||||
assertEquals(SessionDrawerPage.GLASSES, pages.step(SessionDrawerPage.CONTROLLER, 1))
|
||||
assertEquals(sessionDrawerPages(hasAgent = false), pages.filter { it != SessionDrawerPage.GLASSES })
|
||||
}
|
||||
|
||||
@Test fun theAgentPageComesBeforeSessionOnlyWhenTheTabIsShown() {
|
||||
val with = sessionDrawerPages(hasAgent = true)
|
||||
assertEquals(SessionDrawerPage.AGENT, with.step(SessionDrawerPage.GAMES, 1))
|
||||
assertEquals(SessionDrawerPage.SESSION, with.step(SessionDrawerPage.AGENT, 1))
|
||||
assertFalse(SessionDrawerPage.AGENT in sessionDrawerPages(hasAgent = false))
|
||||
assertFalse(DrawerPages.hideable(SessionDrawerPage.SESSION))
|
||||
assertTrue(DrawerPages.hideable(SessionDrawerPage.HUD))
|
||||
}
|
||||
|
||||
@Test fun arrangeKeepsSavedOrderAndSlotsNewPagesAfterTheirNeighbour() {
|
||||
@@ -67,9 +58,4 @@ class SessionDrawerPageTest {
|
||||
assertEquals(listOf(SessionDrawerPage.SESSION, SessionDrawerPage.HUD), out.filter { it in setOf(SessionDrawerPage.SESSION, SessionDrawerPage.HUD) })
|
||||
assertTrue(out.indexOf(SessionDrawerPage.HUD) < out.indexOf(SessionDrawerPage.CONTROLLER))
|
||||
}
|
||||
|
||||
@Test fun sessionPageCannotBeHidden() {
|
||||
assertFalse(DrawerPages.hideable(SessionDrawerPage.SESSION))
|
||||
assertTrue(DrawerPages.hideable(SessionDrawerPage.HUD))
|
||||
}
|
||||
}
|
||||
@@ -130,6 +130,8 @@ class SessionSecondScreenTest {
|
||||
actions(true, listOf(SecondScreenDisplay(1, "Bottom screen"), SecondScreenDisplay(2, "Monitor")), gameSwap = true))
|
||||
}
|
||||
}
|
||||
compose.onNodeWithText(context.getString(R.string.swap_game_screen)).assertDoesNotExist()
|
||||
compose.openSection("display-second")
|
||||
compose.onNodeWithText(context.getString(R.string.swap_game_screen)).performScrollTo().assertIsDisplayed()
|
||||
compose.onNodeWithText("Bottom screen").performScrollTo().assertIsDisplayed()
|
||||
}
|
||||
@@ -265,7 +267,7 @@ class SessionSecondScreenTest {
|
||||
state<Boolean>("drawerOpenState").value = true
|
||||
state<Boolean>("drawerControllerActive").value = true
|
||||
state<List<SecondScreenDisplay>>("secondScreenDisplays").value = listOf(SecondScreenDisplay(1, "Bottom screen"))
|
||||
for ((button, page) in listOf(KeyEvent.KEYCODE_BUTTON_R1 to SessionDrawerPage.DISPLAY,
|
||||
for ((button, page) in listOf(KeyEvent.KEYCODE_BUTTON_R1 to SessionDrawerPage.HUD,
|
||||
KeyEvent.KEYCODE_BUTTON_L1 to SessionDrawerPage.CONTROLLER)) {
|
||||
assertTrue(activity.dispatchKeyEvent(KeyEvent(0L, 0L, KeyEvent.ACTION_DOWN, button, 0, 0,
|
||||
device.id, 0, 0, InputDevice.SOURCE_GAMEPAD)))
|
||||
@@ -309,6 +311,7 @@ class SessionSecondScreenTest {
|
||||
actions(true, emptyList(), micAvailable = true, micEnabled = true, onMic = changes::add))
|
||||
}
|
||||
}
|
||||
compose.openSection("session-behavior")
|
||||
compose.onNodeWithTag("setting-microphone").assertIsEnabled()
|
||||
.assert(SemanticsMatcher.expectValue(StateDescription, context.getString(R.string.widgets_on))).performClick()
|
||||
assertEquals(listOf(false), changes)
|
||||
@@ -322,6 +325,7 @@ class SessionSecondScreenTest {
|
||||
actions(true, emptyList(), micAvailable = true, onMic = changes::add))
|
||||
}
|
||||
}
|
||||
compose.openSection("session-behavior")
|
||||
compose.onNodeWithTag("setting-microphone").assertIsEnabled()
|
||||
.assert(SemanticsMatcher.expectValue(StateDescription, context.getString(R.string.widgets_off))).performClick()
|
||||
assertEquals(listOf(true), changes)
|
||||
@@ -333,6 +337,7 @@ class SessionSecondScreenTest {
|
||||
SessionDrawer(true, SessionDrawerPage.SESSION, false, {}, actions(false, emptyList()))
|
||||
}
|
||||
}
|
||||
compose.openSection("session-behavior")
|
||||
compose.onNodeWithTag("setting-microphone").assertDoesNotExist()
|
||||
compose.onNodeWithText(context.getString(R.string.mode_mic)).assertDoesNotExist()
|
||||
}
|
||||
@@ -354,6 +359,7 @@ class SessionSecondScreenTest {
|
||||
onInputSelection = { panel.refreshControls() }, onClose = { open.value = false }))
|
||||
}
|
||||
}
|
||||
compose.openSection("controller-input")
|
||||
compose.onNodeWithTag("setting-input-profile").performScrollTo().performClick()
|
||||
compose.onNodeWithText("Desktop").performScrollTo().performClick()
|
||||
compose.onNodeWithTag("input-profile-expand").performScrollTo().performClick()
|
||||
|
||||
@@ -86,7 +86,8 @@ RTD=$APP/.wayland-rt
|
||||
export VK_ICD_FILENAMES=$PACK/adapter/icd.json ADRENOTOOLS_DRIVER_PATH=$DRVDIR/ ADRENOTOOLS_HOOKS_PATH=$PACK/lib
|
||||
export ADRENOTOOLS_DRIVER_NAME=$(drvlib "$DRVDIR")
|
||||
export VK_ADD_IMPLICIT_LAYER_PATH=$PACK/layer ENABLE_GAMESCOPE_WSI=1 GAMESCOPE_WAYLAND_DISPLAY=${GAMESCOPE_WAYLAND_DISPLAY:-gamescope-0}
|
||||
export XDG_RUNTIME_DIR=$RTD DROIDDECK_WSI_BYPASS_CHECK_MS=100 GAMESCOPE_WSI_FORCE_BYPASS=1
|
||||
export XDG_RUNTIME_DIR=$RTD DROIDDECK_WSI_BYPASS_CHECK_MS=100 GAMESCOPE_WSI_FORCE_BYPASS=0
|
||||
echo "WSI forced XWayland bypass disabled (GAMESCOPE_WSI_FORCE_BYPASS=$GAMESCOPE_WSI_FORCE_BYPASS)"
|
||||
[ -e "$RTD/droiddeck-gamescope-limiter" ] && export GAMESCOPE_LIMITER_FILE=$RTD/droiddeck-gamescope-limiter
|
||||
|
||||
# Wine: DXVK/VKD3D over the builtins, X11 inside gamescope (winewayland would pick DroidDeck's compositor),
|
||||
|
||||
@@ -494,5 +494,15 @@ gamescope returned the buffer to the client on that release, and a client whose
|
||||
fences attached to a dma-buf then drew into it while the display was still scanning it out, which showed as black
|
||||
tiles in compressed buffers. A forwarded client buffer now stays held until `poll(POLLOUT)` on its dma-buf reports
|
||||
that the display has finished with it, on a waiter thread so nothing else blocks. A release that arrives after the
|
||||
buffer was shown again is dropped, so the later release decides. Composite output images keep the 0146 path, and a
|
||||
buffer was shown again is dropped, so the later release decides. A pending wait holds its own reference on the
|
||||
buffer, since that later release can drop the host's reference before the wait ends. Composite output images keep the 0146 path, and a
|
||||
host that waits for the fence itself releases buffers that are already idle, so nothing changes there.
|
||||
|
||||
## 0148 Wayland backend: composite every frame when the host releases buffers before scanout
|
||||
|
||||
With 0147 a forwarded client buffer stays held until the display has finished scanning it out, about one refresh after
|
||||
the host releases it. Steam's web helper cycles three buffers of its own, so forwarding them held the Steam UI at 80 fps
|
||||
on a 120 Hz screen (frames alternately one and two refreshes apart). The first time a forwarded buffer comes back while
|
||||
it is still being scanned out, the backend now composites every frame into its own output images. Those are reused at
|
||||
latch under 0146, and the client's buffers return as soon as the composite has read them: the Steam UI then runs at
|
||||
the full 120 fps. Hosts that release a buffer only after scanout never take this path and keep forwarding.
|
||||
@@ -1,5 +1,5 @@
|
||||
diff --git a/src/Backends/WaylandBackend.cpp b/src/Backends/WaylandBackend.cpp
|
||||
index 12f0f50..a0fedd4 100644
|
||||
index 12f0f50..d9db2e6 100644
|
||||
--- a/src/Backends/WaylandBackend.cpp
|
||||
+++ b/src/Backends/WaylandBackend.cpp
|
||||
@@ -3,24 +3,28 @@
|
||||
@@ -31,7 +31,7 @@ index 12f0f50..a0fedd4 100644
|
||||
#include <libdecor.h>
|
||||
|
||||
#include "wlr_begin.hpp"
|
||||
@@ -485,44 +489,82 @@ namespace gamescope
|
||||
@@ -485,44 +489,86 @@ namespace gamescope
|
||||
|
||||
// One backing plane plus every layer steamcompmgr can hand us.
|
||||
CWaylandPlane m_Planes[k_nMaxLayers + 1];
|
||||
@@ -78,8 +78,12 @@ index 12f0f50..a0fedd4 100644
|
||||
+ , m_nFd{ nFd }
|
||||
+ , m_ulAcquireSerial{ ulAcquireSerial }
|
||||
+ {
|
||||
+ // A later acquire and release can drop the compositor's reference before this wait ends.
|
||||
+ m_pFb->IncRef();
|
||||
+ }
|
||||
+
|
||||
+ ~CWaylandScanoutRelease() { m_pFb->DecRef(); }
|
||||
+
|
||||
+ int GetFD() override { return m_nFd; }
|
||||
+ void OnPollOut() override { Finish(); }
|
||||
+ void OnPollHangUp() override { Finish(); }
|
||||
@@ -115,7 +119,7 @@ index 12f0f50..a0fedd4 100644
|
||||
~CWaylandInputThread();
|
||||
|
||||
bool Init( CWaylandBackend *pBackend );
|
||||
@@ -969,73 +1011,108 @@ namespace gamescope
|
||||
@@ -969,73 +1015,108 @@ namespace gamescope
|
||||
.action = WAYLAND_NULL(),
|
||||
};
|
||||
const zwp_primary_selection_source_v1_listener CWaylandBackend::s_PrimarySelectionSourceListener =
|
||||
@@ -235,7 +239,7 @@ index 12f0f50..a0fedd4 100644
|
||||
, m_pBackend( pBackend )
|
||||
, m_Planes{ this, this, this, this, this, this, this, this, this }
|
||||
{
|
||||
@@ -2349,25 +2426,26 @@ namespace gamescope
|
||||
@@ -2349,25 +2430,26 @@ namespace gamescope
|
||||
pDmaBuf->format,
|
||||
0u );
|
||||
|
||||
|
||||
@@ -0,0 +1,116 @@
|
||||
diff --git a/src/Backends/WaylandBackend.cpp b/src/Backends/WaylandBackend.cpp
|
||||
index d9db2e6..5c4cd86 100644
|
||||
--- a/src/Backends/WaylandBackend.cpp
|
||||
+++ b/src/Backends/WaylandBackend.cpp
|
||||
@@ -804,24 +804,31 @@ namespace gamescope
|
||||
{
|
||||
auto iter = m_pOutputs.find( pOutput );
|
||||
if ( iter == m_pOutputs.end() )
|
||||
return nullptr;
|
||||
|
||||
return &iter->second;
|
||||
}
|
||||
|
||||
wl_region *GetEmptyRegion() const { return m_pEmptyRegion; }
|
||||
wl_region *GetFullRegion() const { return m_pFullRegion; }
|
||||
CWaylandFb *GetBlackFb() const { return m_BlackFb.get(); }
|
||||
|
||||
+ bool HostReleasesBeforeScanout() const { return m_bHostReleasesBeforeScanout; }
|
||||
+ void OnHostReleasedBeforeScanout()
|
||||
+ {
|
||||
+ if ( !m_bHostReleasesBeforeScanout.exchange( true ) )
|
||||
+ xdg_log.infof( "Host releases buffers before scanout ends: compositing every frame into our own images" );
|
||||
+ }
|
||||
+
|
||||
void OnConnectorDestroyed( CWaylandConnector *pConnector )
|
||||
{
|
||||
m_pFocusConnector.compare_exchange_strong( pConnector, nullptr );
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
void Wayland_Registry_Global( wl_registry *pRegistry, uint32_t uName, const char *pInterface, uint32_t uVersion );
|
||||
static const wl_registry_listener s_RegistryListener;
|
||||
|
||||
void Wayland_Modifier( zwp_linux_dmabuf_v1 *pDmabuf, uint32_t uFormat, uint32_t uModifierHi, uint32_t uModifierLo );
|
||||
|
||||
@@ -871,24 +878,25 @@ namespace gamescope
|
||||
|
||||
wl_display *m_pDisplay = nullptr;
|
||||
wl_shm *m_pShm = nullptr;
|
||||
wl_compositor *m_pCompositor = nullptr;
|
||||
wp_single_pixel_buffer_manager_v1 *m_pSinglePixelBufferManager = nullptr;
|
||||
wl_subcompositor *m_pSubcompositor = nullptr;
|
||||
zwp_linux_dmabuf_v1 *m_pLinuxDmabuf = nullptr;
|
||||
xdg_wm_base *m_pXdgWmBase = nullptr;
|
||||
wp_viewporter *m_pViewporter = nullptr;
|
||||
wl_region *m_pEmptyRegion = nullptr;
|
||||
wl_region *m_pFullRegion = nullptr;
|
||||
Rc<CWaylandFb> m_BlackFb;
|
||||
+ std::atomic<bool> m_bHostReleasesBeforeScanout = { false };
|
||||
OwningRc<CWaylandFb> m_pOwnedBlackFb;
|
||||
OwningRc<CVulkanTexture> m_pBlackTexture;
|
||||
wp_presentation *m_pPresentation = nullptr;
|
||||
droiddeck_refresh_v1 *m_pHostRefresh = nullptr;
|
||||
std::array<uint32_t, 16> m_HostRefreshRates{};
|
||||
std::atomic<uint32_t> m_uHostRefreshRateCount = { 0 };
|
||||
std::vector<uint32_t> m_PendingHostRefreshRates;
|
||||
int m_nSentHostRefresh = 0;
|
||||
int m_nSentHostFrameRate = 0;
|
||||
frog_color_management_factory_v1 *m_pFrogColorMgmtFactory = nullptr;
|
||||
wp_color_manager_v1 *m_pWPColorManager = nullptr;
|
||||
wp_image_description_v1 *m_pWPImageDescriptions[ GamescopeAppTextureColorspace_Count ]{};
|
||||
@@ -1083,24 +1091,25 @@ namespace gamescope
|
||||
xdg_log.errorf( "Compositor released us but we were not acquired. Oh no." );
|
||||
}
|
||||
|
||||
void CWaylandFb::Wayland_Buffer_Release( wl_buffer *pBuffer )
|
||||
{
|
||||
assert( m_pHostBuffer );
|
||||
assert( m_pHostBuffer == pBuffer );
|
||||
|
||||
xdg_log.debugf( "buffer_release: %p", pBuffer );
|
||||
|
||||
if ( ShowsClientBuffer() && gamescope::DmabufScanoutPending( m_nDmabufFd ) )
|
||||
{
|
||||
+ m_pBackend->OnHostReleasedBeforeScanout();
|
||||
int nFd = fcntl( m_nDmabufFd, F_DUPFD_CLOEXEC, 0 );
|
||||
if ( nFd >= 0 )
|
||||
{
|
||||
uint64_t ulSerial;
|
||||
{
|
||||
std::scoped_lock lock( m_AcquireMutex );
|
||||
ulSerial = m_ulAcquireSerial;
|
||||
}
|
||||
auto *pWait = new CWaylandScanoutRelease( this, nFd, ulSerial );
|
||||
if ( CWaylandScanoutRelease::Waiter().AddWaitable( pWait, EPOLLOUT | EPOLLHUP | EPOLLONESHOT ) )
|
||||
return;
|
||||
delete pWait;
|
||||
@@ -1194,24 +1203,27 @@ namespace gamescope
|
||||
plane.Present( nullptr );
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: Dedupe some of this composite check code between us and drm.cpp
|
||||
bool bLayer0ScreenSize = close_enough(pFrameInfo->layers.get( 0 ).scale.x, 1.0f) && close_enough(pFrameInfo->layers.get( 0 ).scale.y, 1.0f);
|
||||
|
||||
GamescopeUpscaleFilter eLayer0Filter = pFrameInfo->layers.get( 0 ).filter;
|
||||
bool bNeedsCompositeFromFilter = ( eLayer0Filter == GamescopeUpscaleFilter::NEAREST ||
|
||||
eLayer0Filter == GamescopeUpscaleFilter::PIXEL ) && !bLayer0ScreenSize;
|
||||
|
||||
bNeedsFullComposite |= cv_composite_force;
|
||||
+ // A forwarded buffer would stay out of its client's hands until scanout ends, which caps a
|
||||
+ // three-image client at two thirds of the refresh rate. Our own output images are reused at latch.
|
||||
+ bNeedsFullComposite |= m_pBackend->HostReleasesBeforeScanout();
|
||||
bNeedsFullComposite |= cv_wayland_overlay_planes >= 0 && pFrameInfo->layers.count() > 1 + cv_wayland_overlay_planes;
|
||||
bNeedsFullComposite |= pFrameInfo->useFSRLayer0;
|
||||
bNeedsFullComposite |= pFrameInfo->useNISLayer0;
|
||||
bNeedsFullComposite |= pFrameInfo->useSGSRLayer0;
|
||||
bNeedsFullComposite |= pFrameInfo->blurLayer0;
|
||||
bNeedsFullComposite |= bNeedsCompositeFromFilter;
|
||||
bNeedsFullComposite |= g_bColorSliderInUse;
|
||||
bNeedsFullComposite |= pFrameInfo->bFadingOut;
|
||||
bNeedsFullComposite |= !g_reshade_effect.empty();
|
||||
|
||||
if ( g_bOutputHDREnabled )
|
||||
bNeedsFullComposite |= g_bHDRItmEnable;
|
||||
@@ -1,3 +1,3 @@
|
||||
GAMESCOPE_REPO=Droid-Deck/DroidDeck-Components
|
||||
GAMESCOPE_TAG=gamescope-3.16.29-cb9c4861
|
||||
GAMESCOPE_SHA256=89a3d70124a13bb5de0b4c67ff75d748a5d7ba6f29590194621754e3550b1f31
|
||||
GAMESCOPE_TAG=gamescope-3.16.29-17928792
|
||||
GAMESCOPE_SHA256=b25680d5f81c8ba1f3e0f6f49894686a148baa296647c3bf3dafa3a04697b7c8
|
||||
@@ -136,10 +136,21 @@ int main( int argc, char **argv ) {
|
||||
assert( fb.refs == 2 );
|
||||
d.scanning();
|
||||
fb.Wayland_Buffer_Release( fb.m_pHostBuffer );
|
||||
assert( fb.refs == 2 && fb.m_bCompositorAcquired );
|
||||
assert( fb.refs == 3 && fb.m_bCompositorAcquired );
|
||||
d.done();
|
||||
fire();
|
||||
assert( fb.refs == 1 && !fb.m_bCompositorAcquired && xdg_log.oh_no == 0 );
|
||||
} else if ( which == "stale-wait-keeps-buffer" ) {
|
||||
fb.client = true;
|
||||
fb.OnCompositorAcquire();
|
||||
d.scanning();
|
||||
fb.Wayland_Buffer_Release( fb.m_pHostBuffer );
|
||||
fb.OnCompositorAcquire();
|
||||
d.done();
|
||||
fb.Wayland_Buffer_Release( fb.m_pHostBuffer );
|
||||
assert( fb.refs == 2 && !fb.m_bCompositorAcquired );
|
||||
fire();
|
||||
assert( fb.refs == 1 && xdg_log.oh_no == 0 );
|
||||
} else if ( which == "client-idle" ) {
|
||||
fb.client = true;
|
||||
fb.OnCompositorAcquire();
|
||||
@@ -214,6 +225,9 @@ class ForwardedBufferScanoutTest(unittest.TestCase):
|
||||
def test_buffer_shown_again_waits_for_its_next_release(self):
|
||||
self.scenario("shown-again")
|
||||
|
||||
def test_pending_wait_keeps_the_buffer_after_a_later_release(self):
|
||||
self.scenario("stale-wait-keeps-buffer")
|
||||
|
||||
def test_buffer_without_dmabuf_is_released_at_once(self):
|
||||
self.scenario("no-dmabuf")
|
||||
|
||||
|
||||
@@ -15,6 +15,8 @@ SRC = TESTS.parents[1] / "app/src/main/cpp/waylandcomp/src"
|
||||
LAYER_HARNESS = r'''
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include <vulkan/vulkan.h>
|
||||
#include "vk_external_image_sync.h"
|
||||
#include "vk_linear_dmabuf.h"
|
||||
@@ -42,6 +44,11 @@ static const uint32_t g_qfam = 2;
|
||||
%(width)s
|
||||
%(height)s
|
||||
static int black_fill_below(const struct draw_list *dl, int n) { (void)dl; (void)n; return 0; }
|
||||
#define LAYER_CANDIDATE_DIAGNOSTICS 32u
|
||||
static unsigned g_layer_candidate_diag_count;
|
||||
static int g_layer_candidate_diag_limit;
|
||||
static void droiddeck_log(const char *tag, const char *fmt, ...) { (void)tag; (void)fmt; }
|
||||
%(candidate_skip)s
|
||||
%(candidate)s
|
||||
|
||||
static int candidate(struct vkp_image *img) {
|
||||
@@ -135,6 +142,7 @@ class VkLinearDmabufTest(unittest.TestCase):
|
||||
"is_dmabuf": function(vk, "vkp_image_is_dmabuf"),
|
||||
"width": function(vk, "vkp_image_width"),
|
||||
"height": function(vk, "vkp_image_height"),
|
||||
"candidate_skip": function(comp, "note_layer_candidate_skip"),
|
||||
"candidate": function(comp, "layer_candidate"),
|
||||
}
|
||||
with tempfile.TemporaryDirectory(prefix="droiddeck-vk-linear-layer-") as tmp:
|
||||
|
||||
@@ -0,0 +1,146 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
import re
|
||||
import shutil
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
from test_vk_pending_completion import function
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
SRC = ROOT / 'app/src/main/cpp/waylandcomp/src'
|
||||
|
||||
HARNESS = r'''
|
||||
#define _GNU_SOURCE
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <poll.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include <wayland-util.h>
|
||||
struct wl_listener { struct wl_list link; void (*notify)(struct wl_listener *, void *); };
|
||||
struct wl_event_source;
|
||||
struct wl_client;
|
||||
struct wl_resource;
|
||||
struct surface { int unused; };
|
||||
struct vkp_draw { int unused; };
|
||||
struct dmabuf_buffer { int fd; void *slot; };
|
||||
typedef struct AHardwareBuffer { int unused; } AHardwareBuffer;
|
||||
DEFINES
|
||||
STRUCT
|
||||
static unsigned g_stat_zero_copy;
|
||||
static int g_export_failed_logged;
|
||||
static struct surface *g_announced;
|
||||
static volatile int64_t g_last_zero_copy_ns;
|
||||
static int export_ok, exports, presents, presented_acquire, logs, polls;
|
||||
static int fake_ioctl(int fd, unsigned long req, void *arg) {
|
||||
struct droiddeck_dma_buf_sync_file *f = arg;
|
||||
(void)fd;
|
||||
assert(req == DROIDDECK_DMA_BUF_IOCTL_EXPORT_SYNC_FILE && f->flags == DROIDDECK_DMA_BUF_SYNC_READ);
|
||||
++exports;
|
||||
if (!export_ok) { errno = ENOTTY; return -1; }
|
||||
f->fd = dup(0);
|
||||
return 0;
|
||||
}
|
||||
#define ioctl fake_ioctl
|
||||
static int fake_poll(struct pollfd *p, nfds_t n, int timeout) {
|
||||
assert(n == 1 && p->events == POLLIN && timeout == 100);
|
||||
++polls; p->revents = POLLIN; return 1;
|
||||
}
|
||||
#define poll fake_poll
|
||||
static int64_t now_ns(void) { return 1; }
|
||||
static void **droiddeck_dmabuf_ahb_slot(struct dmabuf_buffer *b) { return &b->slot; }
|
||||
static int droiddeck_dmabuf_fd(struct dmabuf_buffer *b) { return b->fd; }
|
||||
static const void *droiddeck_surface_color(struct surface *s) { (void)s; return NULL; }
|
||||
static void droiddeck_surface_describe(struct surface *s, char *out, size_t n) { (void)s; snprintf(out, n, "game"); }
|
||||
static void droiddeck_log(const char *tag, const char *fmt, ...) { (void)tag; (void)fmt; ++logs; }
|
||||
static int sc_layer_present_ahb(AHardwareBuffer *a, int w, int h, int acquire, void *token, int sw, int sh,
|
||||
const struct vkp_draw *d, const void *color, uint32_t format) {
|
||||
(void)a; (void)w; (void)h; (void)token; (void)sw; (void)sh; (void)d; (void)color; (void)format;
|
||||
++presents; presented_acquire = acquire;
|
||||
if (acquire >= 0) close(acquire);
|
||||
return 0;
|
||||
}
|
||||
FUNCTIONS
|
||||
static void run(int fd, int can_export, int copyable) {
|
||||
struct dmabuf_buffer b = {.fd = fd};
|
||||
struct vkp_draw d;
|
||||
const struct vkp_draw *draw = copyable ? &d : NULL;
|
||||
struct ahb_buf ab;
|
||||
struct surface s;
|
||||
memset(&ab, 0, sizeof(ab));
|
||||
ab.id = 7; ab.w = 64; ab.h = 64; ab.fence_fd = -1;
|
||||
b.slot = &ab;
|
||||
export_ok = can_export;
|
||||
int r = ahb_swapchain_present(&b, &s, 64, 64, draw);
|
||||
if (fd >= 0 && can_export) {
|
||||
assert(r == 0 && presents == 1 && presented_acquire >= 0 && ab.on_layer && g_stat_zero_copy == 1 && polls == 0);
|
||||
} else if (copyable) {
|
||||
assert(r == -1 && presents == 0 && !ab.on_layer && g_stat_zero_copy == 0 && polls == (fd >= 0));
|
||||
r = ahb_swapchain_present(&b, &s, 64, 64, draw);
|
||||
assert(r == -1 && presents == 0 && logs == 1);
|
||||
} else {
|
||||
assert(r == 0 && presents == 1 && presented_acquire == -1 && ab.on_layer && polls == (fd >= 0));
|
||||
}
|
||||
}
|
||||
int main(int argc, char **argv) {
|
||||
assert(argc == 4);
|
||||
run(atoi(argv[1]), atoi(argv[2]), atoi(argv[3]));
|
||||
return 0;
|
||||
}
|
||||
'''
|
||||
|
||||
|
||||
class ZeroCopyAcquireFenceTest(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
cc = shutil.which(os.environ.get('CC', 'cc'))
|
||||
if not cc:
|
||||
raise AssertionError('C compiler required')
|
||||
ahb = (SRC / 'ahb_swapchain.c').read_text()
|
||||
defines = '\n'.join(re.findall(r'^(?:struct droiddeck_dma_buf_sync_file \{.*?\};|#define DROIDDECK_DMA_BUF_\w+ .*)$',
|
||||
ahb, re.M))
|
||||
struct = re.search(r'struct ahb_buf \{.*?\n\};', ahb, re.S).group()
|
||||
source = HARNESS.replace('DEFINES', defines).replace('STRUCT', struct)
|
||||
source = source.replace('FUNCTIONS', function(ahb, 'ahb_swapchain_present'))
|
||||
cls.tmp = tempfile.TemporaryDirectory(prefix='droiddeck-acquire-fence-')
|
||||
cls.addClassCleanup(cls.tmp.cleanup)
|
||||
probe = Path(cls.tmp.name) / 'probe.c'
|
||||
probe.write_text(source)
|
||||
cls.binary = probe.with_suffix('')
|
||||
built = subprocess.run([cc, '-std=c11', '-Wall', '-Wextra', '-Werror', '-Wno-unused-function', '-UNDEBUG',
|
||||
'-include', 'stdio.h', '-I', str(SRC.parent / 'prebuilt/include'), str(probe),
|
||||
'-o', str(cls.binary)],
|
||||
capture_output=True, text=True)
|
||||
if built.returncode:
|
||||
raise AssertionError(built.stdout + built.stderr)
|
||||
|
||||
def scenario(self, fd, can_export, copyable=1):
|
||||
result = subprocess.run([str(self.binary), str(fd), str(can_export), str(copyable)], capture_output=True, text=True,
|
||||
timeout=10)
|
||||
self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
|
||||
|
||||
def test_exported_fence_goes_to_the_display(self):
|
||||
self.scenario(5, 1)
|
||||
|
||||
def test_kernel_without_fence_export_falls_back_to_copy(self):
|
||||
self.scenario(5, 0)
|
||||
|
||||
def test_buffer_without_dmabuf_fd_falls_back_to_copy(self):
|
||||
self.scenario(-1, 1)
|
||||
|
||||
def test_uncopyable_buffer_waits_on_the_cpu_and_stays_on_the_layer(self):
|
||||
self.scenario(5, 0, 0)
|
||||
|
||||
def test_uncopyable_buffer_without_dmabuf_fd_stays_on_the_layer(self):
|
||||
self.scenario(-1, 1, 0)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user