mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-05 12:35:42 +00:00
Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
332bd81524 | ||
|
|
c986594aa9 | ||
|
|
72c8b8426d |
No files matched your search
@@ -2844,9 +2844,10 @@ static void render_scene(void) {
|
||||
else if (rendered && how == 2) droiddeck_color_frame_shown(hs.color, DROIDDECK_HDR_TONEMAPPED, 0);
|
||||
else if (rendered) hdr_copy = "the HDR composition pass is unavailable on this driver";
|
||||
}
|
||||
if (hdr_route == 0 && vkp_quest_layer_presentation() && !framegen && !cardboard && !cursor_on &&
|
||||
if (hdr_route == 0 && vkp_quest_layer_presentation() && !cardboard && !cursor_on &&
|
||||
!ahb_only) {
|
||||
settle_unwaited();
|
||||
g_framegen_layer = framegen;
|
||||
rendered = vkp_render(w, h, dl.d, dl.n) == 0;
|
||||
} else if (hdr_route == 0 || hdr_route == 3) {
|
||||
const int pass_on = fx_on || framegen;
|
||||
|
||||
@@ -3013,15 +3013,24 @@ static int render_impl(int scene_w, int scene_h, const struct vkp_draw *draws, i
|
||||
}
|
||||
|
||||
int vkp_render(int scene_w, int scene_h, const struct vkp_draw *draws, int n) {
|
||||
if (vkp_quest_layer_presentation() && !vkp_framegen_active() && !vkp_cardboard_active()) {
|
||||
if (vkp_quest_layer_presentation() && !vkp_cardboard_active()) {
|
||||
vkp_apply_window_request();
|
||||
sc_layer_hide_overlay();
|
||||
if (n > 0) {
|
||||
if (sc_layer_present_pass(draws, n, scene_w, scene_h) != 0) {
|
||||
const int fg = vkp_framegen_active();
|
||||
const int generated = fg
|
||||
? sc_layer_present_generated(draws, n, NULL, scene_w, scene_h, 1, NULL) : 0;
|
||||
const int r = fg ? (generated >= 0 ? 0 : -1)
|
||||
: sc_layer_present_pass(draws, n, scene_w, scene_h);
|
||||
if (r != 0) {
|
||||
static int said;
|
||||
if (!said) { said = 1; droiddeck_log("error", "Quest scene layer unavailable; retaining the previous frame rather than using the corrupt Android swapchain"); }
|
||||
return -1;
|
||||
}
|
||||
if (fg && generated > 0) {
|
||||
static int said;
|
||||
if (!said) { said = 1; droiddeck_log("framegen", "generated frames go on the Quest display layer"); }
|
||||
}
|
||||
} else {
|
||||
sc_layer_hide();
|
||||
}
|
||||
|
||||
@@ -190,7 +190,6 @@ object BwrapSpawner {
|
||||
val env = LinkedHashMap<String, String>()
|
||||
request.optJSONObject("env")?.let { e -> e.keys().forEach { k -> env[k] = e.getString(k) } }
|
||||
withoutRootfsSettings(env, rootfs)
|
||||
sdlAudioOnPulse(env)
|
||||
val envTool = request.optString("envTool").takeIf { it.startsWith("/") }
|
||||
if (envTool == null && binds.any { it.guest == "/dev" }) {
|
||||
val glIcd = coveringBind(GL_ICD_DIR) != null && File(hostPath(binds, root.path, GL_ICD_DIR)).isDirectory
|
||||
@@ -221,17 +220,6 @@ object BwrapSpawner {
|
||||
}
|
||||
}
|
||||
|
||||
private val SDL_AUDIO_DRIVER_KEYS = listOf("SDL_AUDIODRIVER", "SDL_AUDIO_DRIVER")
|
||||
|
||||
internal fun sdlAudioOnPulse(env: MutableMap<String, String>) {
|
||||
if (env["PULSE_SERVER"].isNullOrEmpty()) return
|
||||
for (key in SDL_AUDIO_DRIVER_KEYS) {
|
||||
val drivers = env[key]?.split(',')?.map { it.trim() } ?: continue
|
||||
if (drivers.none { it.equals("pipewire", true) } || drivers.any { it.equals("pulseaudio", true) }) continue
|
||||
env[key] = drivers.map { if (it.equals("pipewire", true)) "pulseaudio" else it }.joinToString(",")
|
||||
}
|
||||
}
|
||||
|
||||
private const val GPU_DIR = "/run/droiddeck-gpu"
|
||||
private const val GL_ICD_DIR = "/usr/lib/aarch64-linux-gnu/GL/vulkan/icd.d"
|
||||
|
||||
|
||||
@@ -77,31 +77,6 @@ class BwrapSpawnerTest {
|
||||
assertEquals("x11", x11["SDL_VIDEODRIVER"])
|
||||
}
|
||||
|
||||
@Test fun sdlPinnedToPipewireUsesTheSessionsPulseServer() {
|
||||
val pulse = "unix:/run/flatpak/pulse/native"
|
||||
val pinned = mutableMapOf("SDL_AUDIODRIVER" to "pipewire", "PULSE_SERVER" to pulse)
|
||||
BwrapSpawner.sdlAudioOnPulse(pinned)
|
||||
assertEquals("pulseaudio", pinned["SDL_AUDIODRIVER"])
|
||||
val sdl3 = mutableMapOf("SDL_AUDIO_DRIVER" to "PipeWire, alsa", "PULSE_SERVER" to pulse)
|
||||
BwrapSpawner.sdlAudioOnPulse(sdl3)
|
||||
assertEquals("pulseaudio,alsa", sdl3["SDL_AUDIO_DRIVER"])
|
||||
}
|
||||
|
||||
@Test fun otherSdlAudioChoicesAreKept() {
|
||||
val noPulse = mutableMapOf("SDL_AUDIODRIVER" to "pipewire")
|
||||
BwrapSpawner.sdlAudioOnPulse(noPulse)
|
||||
assertEquals(mapOf("SDL_AUDIODRIVER" to "pipewire"), noPulse)
|
||||
val pulse = "unix:/run/flatpak/pulse/native"
|
||||
for (choice in listOf("pipewire,pulseaudio", "alsa", "dummy")) {
|
||||
val env = mutableMapOf("SDL_AUDIODRIVER" to choice, "PULSE_SERVER" to pulse)
|
||||
BwrapSpawner.sdlAudioOnPulse(env)
|
||||
assertEquals(choice, env["SDL_AUDIODRIVER"])
|
||||
}
|
||||
val unset = mutableMapOf("PULSE_SERVER" to pulse)
|
||||
BwrapSpawner.sdlAudioOnPulse(unset)
|
||||
assertEquals(mapOf("PULSE_SERVER" to pulse), unset)
|
||||
}
|
||||
|
||||
@Test fun sourcesNamedByTheirKernelPathReachTheSessionsMounts() {
|
||||
val files = "/data/user/0/com.droiddeck.launcher/files"
|
||||
val kernel = "/data/data/com.droiddeck.launcher/files"
|
||||
|
||||
@@ -59,10 +59,6 @@ The spawner also adds what the rootfs gives its own programs:
|
||||
Chromium and Electron apps use zypak's mimic strategy (`ZYPAK_ZYGOTE_STRATEGY_SPAWN=0`). The
|
||||
Flatpak portal's Spawn refuses a caller whose `/proc/<pid>/root` holds no `.flatpak-info`,
|
||||
and a proot sandbox's root is the host's.
|
||||
- **Audio.** The session's sound server is PulseAudio, and Flatpak binds its socket in for apps that ask
|
||||
for it. An app that pins SDL to PipeWire (`SDL_AUDIODRIVER=pipewire`, as Chiaki-ng's does) gets
|
||||
`pulseaudio` in its place when that socket is there. Otherwise SDL finds no PipeWire server and the
|
||||
app quits at start.
|
||||
- **CPU.** `/proc/cpuinfo` without the cores' part numbers. Snapdragon's ARMv9 cores imply SVE2
|
||||
to LLVM, Qualcomm leaves SVE off, and llvmpipe's first shader died with SIGILL.
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <dlfcn.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <link.h>
|
||||
#include <linux/input.h>
|
||||
#include <pthread.h>
|
||||
#include <stdatomic.h>
|
||||
@@ -15,6 +16,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/sysmacros.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
@@ -34,7 +36,8 @@
|
||||
"NAME=\"Xbox 360 Controller (%d)\"\n" \
|
||||
"PHYS=\"usb-fakeinput/input%d\"\n"
|
||||
|
||||
#define RING_SDL_ID 0x045e028eu
|
||||
#define STEAM_VIRTUAL_VENDOR 0x28de
|
||||
#define STEAM_VIRTUAL_PRODUCT 0x11ff
|
||||
|
||||
#define PARENT_NAME "droiddeck-input"
|
||||
#define PARENT_SYSPATH_FORMAT "/sys/devices/droiddeck%d/" PARENT_NAME "%d"
|
||||
@@ -141,66 +144,8 @@ static int any_virtual_pad(void) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static char *sdl_id_list_text(const char *list) {
|
||||
char *text = NULL;
|
||||
char *grown;
|
||||
size_t length = 0;
|
||||
size_t got;
|
||||
FILE *file;
|
||||
|
||||
if (list[0] != '@') return strdup(list);
|
||||
file = fopen(list + 1, "re");
|
||||
if (file == NULL) return NULL;
|
||||
do {
|
||||
grown = realloc(text, length + 4097);
|
||||
if (grown == NULL) {
|
||||
free(text);
|
||||
fclose(file);
|
||||
return NULL;
|
||||
}
|
||||
text = grown;
|
||||
got = fread(text + length, 1, 4096, file);
|
||||
length += got;
|
||||
} while (got > 0);
|
||||
fclose(file);
|
||||
text[length] = '\0';
|
||||
return text;
|
||||
}
|
||||
|
||||
static int sdl_id_list_entries(const char *list, int *has_ring) {
|
||||
char *text = sdl_id_list_text(list);
|
||||
char *spot = text;
|
||||
uint32_t entry;
|
||||
int entries = 0;
|
||||
|
||||
*has_ring = 0;
|
||||
if (text == NULL) return 0;
|
||||
while ((spot = strstr(spot, "0x")) != NULL) {
|
||||
entry = (uint32_t)(uint16_t)strtol(spot, &spot, 0) << 16;
|
||||
spot = strstr(spot, "0x");
|
||||
if (spot == NULL) break;
|
||||
entry |= (uint16_t)strtol(spot, &spot, 0);
|
||||
entries++;
|
||||
if (entry == RING_SDL_ID) *has_ring = 1;
|
||||
}
|
||||
free(text);
|
||||
return entries;
|
||||
}
|
||||
|
||||
static int sdl_bus_skips_ring_pad(void) {
|
||||
const char *steam_virtual = getenv("FAKE_EVDEV_STEAM_VIRTUAL");
|
||||
const char *except = getenv("SDL_GAMECONTROLLER_IGNORE_DEVICES_EXCEPT");
|
||||
const char *ignore = getenv("SDL_GAMECONTROLLER_IGNORE_DEVICES");
|
||||
int has_ring;
|
||||
|
||||
if (steam_virtual != NULL && atoi(steam_virtual) != 0) return 1;
|
||||
if (except != NULL && sdl_id_list_entries(except, &has_ring) > 0) return !has_ring;
|
||||
return ignore != NULL && sdl_id_list_entries(ignore, &has_ring) > 0 && has_ring;
|
||||
}
|
||||
|
||||
static const char *ring_uevent_format(void) {
|
||||
if (uinput_enabled() && any_virtual_pad()) return PAD_PHYSICAL_UEVENT_FORMAT;
|
||||
return sdl_bus_skips_ring_pad() ? PAD_UEVENT_FORMAT : PAD_PHYSICAL_UEVENT_FORMAT;
|
||||
return uinput_enabled() && any_virtual_pad() ? PAD_PHYSICAL_UEVENT_FORMAT : PAD_UEVENT_FORMAT;
|
||||
}
|
||||
|
||||
static void refresh_locked(int node) {
|
||||
@@ -514,6 +459,60 @@ static int caller_in_library(void *caller, const char *library) {
|
||||
|
||||
static int caller_is_winebus(void *caller) { return caller_in_library(caller, "winebus.so"); }
|
||||
|
||||
static int note_winebus(struct dl_phdr_info *info, size_t size, void *data) {
|
||||
(void)size;
|
||||
if (info->dlpi_name == NULL || strstr(info->dlpi_name, "winebus.so") == NULL) return 0;
|
||||
*(int *)data = 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int winebus_reads_udev(void) {
|
||||
const char *x360 = getenv("FAKE_EVDEV_STEAM_PAD_AS_X360");
|
||||
int loaded = 0;
|
||||
|
||||
if (x360 != NULL && atoi(x360) != 0) return 0;
|
||||
dl_iterate_phdr(note_winebus, &loaded);
|
||||
return loaded;
|
||||
}
|
||||
|
||||
static int ring_pad_fd(int fd) {
|
||||
const char *spec = getenv("FAKE_EVDEV_MEMFD_PATHS");
|
||||
const char *entry;
|
||||
struct stat opened;
|
||||
struct stat ring;
|
||||
char path[PATH_MAX];
|
||||
|
||||
if (spec == NULL || fstat(fd, &opened) != 0) return 0;
|
||||
for (entry = spec; *entry != '\0';) {
|
||||
char *end;
|
||||
long slot = strtol(entry, &end, 10);
|
||||
const char *next = strchr(entry, ';');
|
||||
size_t length;
|
||||
|
||||
if (end != entry && *end == '=' && slot >= 0 && slot < RING_MAX) {
|
||||
length = next != NULL ? (size_t)(next - end - 1) : strlen(end + 1);
|
||||
if (length < sizeof(path)) {
|
||||
memcpy(path, end + 1, length);
|
||||
path[length] = '\0';
|
||||
if (stat(path, &ring) == 0 && ring.st_dev == opened.st_dev && ring.st_ino == opened.st_ino) return 1;
|
||||
}
|
||||
}
|
||||
if (next == NULL) break;
|
||||
entry = next + 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
__attribute__((visibility("hidden"))) void dd_ring_pad_sdl_id(int fd, unsigned long request, void *arg,
|
||||
void *caller, int rc) {
|
||||
struct input_id *id = arg;
|
||||
|
||||
if (rc != 0 || request != EVIOCGID || id == NULL) return;
|
||||
if (!caller_in_library(caller, "libSDL") || !winebus_reads_udev() || !ring_pad_fd(fd)) return;
|
||||
id->vendor = STEAM_VIRTUAL_VENDOR;
|
||||
id->product = STEAM_VIRTUAL_PRODUCT;
|
||||
}
|
||||
|
||||
typedef int (*sdl_rumble_fn)(void *, uint16_t, uint16_t, uint32_t);
|
||||
static _Atomic(sdl_rumble_fn) real_sdl_rumble;
|
||||
static __thread int winebus_sdl_call;
|
||||
|
||||
@@ -424,6 +424,8 @@ int dd_venc_ioctl(int fd, unsigned long request, void *arg, int *rc) __attribute
|
||||
int dd_vdec_ioctl(int fd, unsigned long request, void *arg, int *rc) __attribute__((visibility("hidden")));
|
||||
int dd_winebus_rumble_ioctl(int (*real)(int, unsigned long, void *), int fd, unsigned long request,
|
||||
void *arg, void *caller, int *rc) __attribute__((visibility("hidden")));
|
||||
void dd_ring_pad_sdl_id(int fd, unsigned long request, void *arg, void *caller, int rc)
|
||||
__attribute__((visibility("hidden")));
|
||||
int dd_writewatch_ioctl(int (*real)(int, unsigned long, void *), int fd, unsigned long request, void *arg,
|
||||
int *rc) __attribute__((visibility("hidden")));
|
||||
|
||||
@@ -444,6 +446,7 @@ int ioctl(int fd, unsigned long request, ...) {
|
||||
if (dd_winebus_rumble_ioctl(real, fd, request, arg, __builtin_return_address(0), &rc)) return rc;
|
||||
if (dd_writewatch_ioctl(real, fd, request, arg, &rc)) return rc;
|
||||
if (!dd_kgsl_poll(real, fd, request, arg, &rc)) rc = quest_kgsl_ioctl(real, fd, request, arg);
|
||||
dd_ring_pad_sdl_id(fd, request, arg, __builtin_return_address(0), rc);
|
||||
dd_kgsl_track(real, fd, request, arg, &rc);
|
||||
dd_kgsl_chip_id_fixup(request, arg, rc);
|
||||
if (arg == NULL || !is_link_query(request)) return rc;
|
||||
|
||||
+101
-11
@@ -3,8 +3,12 @@
|
||||
#include <stdio.h>
|
||||
|
||||
struct vkp_draw { int unused; };
|
||||
static int quest, framegen, cardboard, pass_result, base_result, pass_shown;
|
||||
static int first_frames, pass_calls, base_calls, fallback_calls;
|
||||
struct vkp_hdr_frame;
|
||||
struct droiddeck_color;
|
||||
static int quest, framegen, cardboard, pass_result, gen_result, base_result, pass_shown, gen_shown;
|
||||
static int first_frames, pass_calls, gen_calls, base_calls, fallback_calls;
|
||||
static int settled, g_framegen_layer;
|
||||
static void settle_unwaited(void) { settled++; }
|
||||
static int vkp_quest_layer_presentation(void) { return quest; }
|
||||
static int vkp_framegen_active(void) { return framegen; }
|
||||
static int vkp_cardboard_active(void) { return cardboard; }
|
||||
@@ -19,26 +23,46 @@ static int sc_layer_present_pass(const struct vkp_draw *draws, int n, int w, int
|
||||
if (pass_result == 0 && pass_shown) vkp_signal_first_frame();
|
||||
return pass_result;
|
||||
}
|
||||
static int sc_layer_present_generated(const struct vkp_draw *draws, int n_draws,
|
||||
const struct vkp_hdr_frame *hf, int w, int h,
|
||||
int composed, const struct droiddeck_color *color) {
|
||||
(void)w; (void)h;
|
||||
assert(composed == 1 && hf == NULL && color == NULL);
|
||||
gen_calls++;
|
||||
if (gen_result >= 0 && gen_shown) vkp_signal_first_frame();
|
||||
return gen_result;
|
||||
}
|
||||
static int render_impl(int w, int h, const struct vkp_draw *draws, int n,
|
||||
const void *hdr, int *how) { fallback_calls++; return 17; }
|
||||
|
||||
#include "vkp_render_under_test.inc"
|
||||
|
||||
static int compositor_route(int hdr_route, int cursor_on, int ahb_only,
|
||||
const struct vkp_draw *draws) {
|
||||
const int w = 1280, h = 720;
|
||||
const struct { const struct vkp_draw *d; int n; } dl = {draws, 1};
|
||||
int rendered = -2;
|
||||
#include "quest_route_under_test.inc"
|
||||
return rendered;
|
||||
}
|
||||
|
||||
static void reset(void) {
|
||||
quest = 1;
|
||||
framegen = cardboard = pass_result = base_result = pass_shown = 0;
|
||||
first_frames = pass_calls = base_calls = fallback_calls = 0;
|
||||
settled = 0;
|
||||
g_framegen_layer = -1;
|
||||
framegen = cardboard = pass_result = gen_result = base_result = pass_shown = gen_shown = 0;
|
||||
first_frames = pass_calls = gen_calls = base_calls = fallback_calls = 0;
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
const struct vkp_draw draw = {0};
|
||||
reset();
|
||||
for (int i = 0; i < 3; i++) assert(vkp_render(1280, 720, NULL, 0) == 0);
|
||||
assert(base_calls == 3 && pass_calls == 0 && first_frames == 0);
|
||||
assert(base_calls == 3 && pass_calls == 0 && gen_calls == 0 && first_frames == 0);
|
||||
|
||||
reset();
|
||||
assert(vkp_render(1280, 720, &draw, 1) == 0);
|
||||
assert(pass_calls == 1 && base_calls == 1 && first_frames == 0);
|
||||
assert(pass_calls == 1 && gen_calls == 0 && base_calls == 1 && first_frames == 0);
|
||||
|
||||
reset(); pass_shown = 1;
|
||||
assert(vkp_render(1280, 720, &draw, 1) == 0);
|
||||
@@ -53,15 +77,81 @@ int main(void) {
|
||||
assert(vkp_render(1280, 720, NULL, 0) == -1);
|
||||
assert(first_frames == 0);
|
||||
|
||||
for (int mode = 0; mode < 3; mode++) {
|
||||
for (int mode = 0; mode < 4; mode++) {
|
||||
reset();
|
||||
if (mode == 0) quest = 0;
|
||||
if (mode == 1) framegen = 1;
|
||||
if (mode == 2) cardboard = 1;
|
||||
if (mode == 1) cardboard = 1;
|
||||
if (mode == 2) { quest = 0; framegen = 1; }
|
||||
if (mode == 3) { framegen = 1; cardboard = 1; }
|
||||
assert(vkp_render(1280, 720, &draw, 1) == 17);
|
||||
assert(fallback_calls == 1 && pass_calls == 0 && base_calls == 0);
|
||||
assert(fallback_calls == 1 && pass_calls == 0 && gen_calls == 0 && base_calls == 0);
|
||||
assert(first_frames == 0);
|
||||
}
|
||||
puts("PASS: Quest first-frame notification waits for client content");
|
||||
|
||||
reset(); framegen = 1;
|
||||
assert(vkp_render(1280, 720, &draw, 1) == 0);
|
||||
assert(gen_calls == 1 && pass_calls == 0 && fallback_calls == 0 && base_calls == 1);
|
||||
|
||||
reset(); framegen = 1; gen_result = -1;
|
||||
assert(vkp_render(1280, 720, &draw, 1) == -1);
|
||||
assert(gen_calls == 1 && fallback_calls == 0 && base_calls == 0 && first_frames == 0);
|
||||
|
||||
reset(); framegen = 1; gen_shown = 1;
|
||||
assert(vkp_render(1280, 720, &draw, 1) == 0);
|
||||
assert(first_frames == 1);
|
||||
assert(vkp_render(1280, 720, NULL, 0) == 0);
|
||||
assert(first_frames == 1);
|
||||
|
||||
reset(); framegen = 1;
|
||||
assert(vkp_render(1280, 720, &draw, 1) == 0);
|
||||
framegen = 0;
|
||||
assert(vkp_render(1280, 720, &draw, 1) == 0);
|
||||
assert(gen_calls == 1 && pass_calls == 1 && fallback_calls == 0 && first_frames == 0);
|
||||
for (int count = 1; count <= 2; count++) {
|
||||
for (int shown = 0; shown <= 1; shown++) {
|
||||
reset(); framegen = 1; gen_result = count; gen_shown = shown;
|
||||
assert(vkp_render(1280, 720, &draw, 1) == 0);
|
||||
assert(gen_calls == 1 && pass_calls == 0 && fallback_calls == 0);
|
||||
assert(base_calls == 1 && first_frames == shown);
|
||||
assert(vkp_render(1280, 720, NULL, 0) == 0);
|
||||
assert(gen_calls == 1 && base_calls == 2 && first_frames == shown);
|
||||
}
|
||||
reset(); framegen = 1; gen_result = count; gen_shown = 1; base_result = -1;
|
||||
assert(vkp_render(1280, 720, &draw, 1) == -1);
|
||||
assert(gen_calls == 1 && base_calls == 1 && first_frames == 1);
|
||||
assert(pass_calls == 0 && fallback_calls == 0);
|
||||
}
|
||||
|
||||
for (int route = 0; route <= 3; route++) {
|
||||
for (int flags = 0; flags < 32; flags++) {
|
||||
reset();
|
||||
quest = flags & 1;
|
||||
framegen = (flags >> 1) & 1;
|
||||
cardboard = (flags >> 2) & 1;
|
||||
const int cursor = (flags >> 3) & 1;
|
||||
const int ahb = (flags >> 4) & 1;
|
||||
const int selected = route == 0 && quest && !cardboard && !cursor && !ahb;
|
||||
gen_result = 2; gen_shown = pass_shown = 1;
|
||||
assert(compositor_route(route, cursor, ahb, &draw) == (selected ? 1 : -2));
|
||||
assert(settled == selected && base_calls == selected);
|
||||
assert(gen_calls == (selected && framegen));
|
||||
assert(pass_calls == (selected && !framegen));
|
||||
assert(first_frames == selected && fallback_calls == 0);
|
||||
assert(g_framegen_layer == (selected ? framegen : -1));
|
||||
assert(quest == (flags & 1));
|
||||
assert(framegen == ((flags >> 1) & 1));
|
||||
assert(cardboard == ((flags >> 2) & 1));
|
||||
}
|
||||
}
|
||||
reset(); framegen = 1; gen_result = 2;
|
||||
assert(compositor_route(0, 0, 0, &draw) == 1);
|
||||
assert(g_framegen_layer == 1);
|
||||
framegen = 0;
|
||||
assert(compositor_route(0, 0, 0, &draw) == 1);
|
||||
assert(g_framegen_layer == 0 && gen_calls == 1 && pass_calls == 1 && base_calls == 2);
|
||||
reset(); framegen = 1; gen_result = -1;
|
||||
assert(compositor_route(0, 0, 0, &draw) == 0);
|
||||
assert(settled == 1 && gen_calls == 1 && base_calls == 0 && fallback_calls == 0);
|
||||
puts("PASS: Quest first-frame notification and display-layer frame generation");
|
||||
return 0;
|
||||
}
|
||||
@@ -707,36 +707,15 @@ class InputUdevPreloadTest(unittest.TestCase):
|
||||
def identity(self, pads=None, **extra):
|
||||
return self.run_program("identity", pads=pads, extra=extra)
|
||||
|
||||
@classmethod
|
||||
def id_list(cls, name, text):
|
||||
path = cls.dir / name
|
||||
path.write_text(text)
|
||||
return "@" + str(path)
|
||||
|
||||
def test_a_pad_wine_also_reads_through_sdl_is_described_as_the_pad_sdl_sees(self):
|
||||
xbox = ["pad PRODUCT=3/45e/28e/110", "parent PRODUCT=3/45e/28e/110"]
|
||||
for extra in ({}, {"FAKE_EVDEV_UINPUT": "1"}, {"SDL_GAMECONTROLLER_IGNORE_DEVICES": "0x28de/0x1142"},
|
||||
{"SDL_GAMECONTROLLER_IGNORE_DEVICES_EXCEPT": "0x045e/0x028e"}, {"FAKE_EVDEV_STEAM_VIRTUAL": "0"},
|
||||
{"SDL_GAMECONTROLLER_IGNORE_DEVICES": self.id_list("ignore-other.txt", "0x28de/0x1142\n")},
|
||||
{"SDL_GAMECONTROLLER_IGNORE_DEVICES": "@" + str(self.dir / "missing.txt")},
|
||||
{"SDL_GAMECONTROLLER_IGNORE_DEVICES_EXCEPT": self.id_list("except-ring.txt", "0x045E/0x028E\n")},
|
||||
{"SDL_GAMECONTROLLER_IGNORE_DEVICES_EXCEPT": "0x45e/0x28e"},
|
||||
{"SDL_GAMECONTROLLER_IGNORE_DEVICES_EXCEPT": ""},
|
||||
{"SDL_GAMECONTROLLER_IGNORE_DEVICES_EXCEPT": "", "SDL_GAMECONTROLLER_IGNORE_DEVICES": "0x28de/0x1142"},
|
||||
{"SDL_GAMECONTROLLER_IGNORE_DEVICES": "0x045e/0x028f"}):
|
||||
with self.subTest(**extra):
|
||||
self.assertEqual(self.identity(**extra), xbox)
|
||||
|
||||
def test_a_pad_sdl_skips_keeps_the_steam_input_identity(self):
|
||||
def test_a_ring_pad_keeps_the_steam_input_identity_whatever_sdl_is_told(self):
|
||||
steam = ["pad PRODUCT=6/28de/11ff/110", "parent PRODUCT=6/28de/11ff/110"]
|
||||
for extra in ({"FAKE_EVDEV_STEAM_VIRTUAL": "1"}, {"SDL_GAMECONTROLLER_IGNORE_DEVICES": "0x28de/0x1142,0x045E/0x028E"},
|
||||
for extra in ({}, {"FAKE_EVDEV_UINPUT": "1"}, {"FAKE_EVDEV_STEAM_VIRTUAL": "0"}, {"FAKE_EVDEV_STEAM_VIRTUAL": "1"},
|
||||
{"SDL_GAMECONTROLLER_IGNORE_DEVICES": "0x28de/0x1142"},
|
||||
{"SDL_GAMECONTROLLER_IGNORE_DEVICES": "0x28de/0x1142,0x045E/0x028E"},
|
||||
{"SDL_GAMECONTROLLER_IGNORE_DEVICES_EXCEPT": "0x045e/0x028e"},
|
||||
{"SDL_GAMECONTROLLER_IGNORE_DEVICES_EXCEPT": "0x28de/0x11ff"},
|
||||
{"FAKE_EVDEV_UINPUT": "1", "SDL_GAMECONTROLLER_IGNORE_DEVICES": "0x045e/0x028e"},
|
||||
{"SDL_GAMECONTROLLER_IGNORE_DEVICES": self.id_list("ignore-ring.txt", "0x28de/0x1142\n0x045e/0x028e\n")},
|
||||
{"SDL_GAMECONTROLLER_IGNORE_DEVICES_EXCEPT": self.id_list("except-other.txt", "0x28de/0x11ff\n")},
|
||||
{"SDL_GAMECONTROLLER_IGNORE_DEVICES": self.id_list("ignore-long.txt", "0x28de/0x1142\n" * 400 + "0x045e/0x028e\n")},
|
||||
{"SDL_GAMECONTROLLER_IGNORE_DEVICES": "0x45e/0x28e"},
|
||||
{"SDL_GAMECONTROLLER_IGNORE_DEVICES_EXCEPT": "", "SDL_GAMECONTROLLER_IGNORE_DEVICES": "0x045e/0x028e"}):
|
||||
{"SDL_GAMECONTROLLER_IGNORE_DEVICES_EXCEPT": ""},
|
||||
{"FAKE_EVDEV_UINPUT": "1", "SDL_GAMECONTROLLER_IGNORE_DEVICES": "0x045e/0x028e"}):
|
||||
with self.subTest(**extra):
|
||||
self.assertEqual(self.identity(**extra), steam)
|
||||
|
||||
|
||||
@@ -16,6 +16,11 @@ class QuestBackdropTest(unittest.TestCase):
|
||||
with tempfile.TemporaryDirectory() as folder:
|
||||
work = Path(folder)
|
||||
(work / 'vkp_render_under_test.inc').write_text(source[start:end])
|
||||
compositor = (ROOT / 'app/src/main/cpp/waylandcomp/src/compositor.c').read_text()
|
||||
route_start = compositor.index(' if (hdr_route == 0 && vkp_quest_layer_presentation()')
|
||||
route_end = compositor.index(' } else if (hdr_route == 0 || hdr_route == 3)', route_start)
|
||||
(work / 'quest_route_under_test.inc').write_text(
|
||||
compositor[route_start:route_end] + ' }\n')
|
||||
binary = work / 'test-first-frame'
|
||||
subprocess.run(['cc', '-std=c11', '-Wall', '-Wextra',
|
||||
'-Wno-unused-parameter', '-Wno-unused-function', f'-I{work}',
|
||||
@@ -55,6 +60,20 @@ void AHardwareBuffer_describe(const AHardwareBuffer *, AHardwareBuffer_Desc *);
|
||||
int AHardwareBuffer_lock(AHardwareBuffer *, uint64_t, int32_t, const ARect *, void **);
|
||||
int AHardwareBuffer_unlock(AHardwareBuffer *, int32_t *);
|
||||
void AHardwareBuffer_release(AHardwareBuffer *);
|
||||
''')
|
||||
vulkan = work / 'vulkan'
|
||||
vulkan.mkdir()
|
||||
(vulkan / 'vulkan.h').write_text('''#pragma once
|
||||
#include <stdint.h>
|
||||
typedef void *VkInstance;
|
||||
typedef void *VkPhysicalDevice;
|
||||
typedef void *VkDevice;
|
||||
typedef void *VkQueue;
|
||||
typedef void *VkCommandBuffer;
|
||||
typedef void *VkImage;
|
||||
typedef void *VkImageView;
|
||||
typedef int VkFormat;
|
||||
typedef void (*PFN_vkGetInstanceProcAddr)(void);
|
||||
''')
|
||||
binary = work / 'test-presentation'
|
||||
subprocess.run(['cc', '-std=c11', '-O1', '-g', '-Wall', '-Wextra',
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
from pathlib import Path
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
PRELOAD = Path(__file__).resolve().parents[1] / "linuxfs/preload"
|
||||
|
||||
SHIM = r"""
|
||||
#include <linux/input.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
|
||||
int ioctl(int fd, unsigned long request, ...) {
|
||||
va_list ap;
|
||||
va_start(ap, request);
|
||||
struct input_id *id = va_arg(ap, struct input_id *);
|
||||
va_end(ap);
|
||||
(void)fd;
|
||||
if (request != EVIOCGID) return -1;
|
||||
memset(id, 0, sizeof(*id));
|
||||
id->bustype = 3;
|
||||
id->vendor = 0x045e;
|
||||
id->product = 0x028e;
|
||||
return 0;
|
||||
}
|
||||
"""
|
||||
|
||||
QUERY = r"""
|
||||
#include <fcntl.h>
|
||||
#include <linux/input.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
void query(const char *path) {
|
||||
struct input_id id;
|
||||
int fd = open(path, O_RDONLY | O_CLOEXEC);
|
||||
int rc = ioctl(fd, EVIOCGID, &id);
|
||||
printf("%d %04x:%04x\n", rc, id.vendor, id.product);
|
||||
close(fd);
|
||||
}
|
||||
"""
|
||||
|
||||
PROGRAM = r"""
|
||||
#include <dlfcn.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
void query(const char *path);
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
(void)argc;
|
||||
if (strcmp(argv[1], "-") != 0) dlopen(argv[1], RTLD_NOW);
|
||||
if (strcmp(argv[2], "program") == 0) {
|
||||
query(argv[3]);
|
||||
} else {
|
||||
void *sdl = dlopen(argv[2], RTLD_NOW | RTLD_LOCAL);
|
||||
void (*sdl_query)(const char *) = (void (*)(const char *))dlsym(sdl, "query");
|
||||
sdl_query(argv[3]);
|
||||
}
|
||||
fflush(stdout);
|
||||
return 0;
|
||||
}
|
||||
"""
|
||||
|
||||
|
||||
@unittest.skipUnless(sys.platform == "linux" and shutil.which("cc"), "needs Linux and cc")
|
||||
class RingPadSdlIdentityTest(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
cls.dir = Path(tempfile.mkdtemp())
|
||||
build = cls.dir / "build"
|
||||
build.mkdir()
|
||||
for name, text in (("shim.c", SHIM), ("query.c", QUERY), ("program.c", PROGRAM), ("empty.c", "int bus;\n")):
|
||||
(build / name).write_text(text)
|
||||
cls.lib = cls.dir / "libddsession.so"
|
||||
subprocess.run(["cc", "-shared", "-fPIC", "-O2", "-Wall", "-pthread", "-o", str(cls.lib),
|
||||
*map(str, sorted(PRELOAD.glob("*.c"))), "-ldl"], check=True)
|
||||
cls.shim = cls.dir / "libshim.so"
|
||||
subprocess.run(["cc", "-shared", "-fPIC", "-O2", "-o", str(cls.shim), str(build / "shim.c")], check=True)
|
||||
cls.winebus = cls.dir / "winebus.so"
|
||||
subprocess.run(["cc", "-shared", "-fPIC", "-O2", "-o", str(cls.winebus), str(build / "empty.c")], check=True)
|
||||
cls.sdl_library = cls.dir / "libSDL2-2.0.so.0"
|
||||
subprocess.run(["cc", "-shared", "-fPIC", "-O2", "-o", str(cls.sdl_library), str(build / "query.c")], check=True)
|
||||
cls.program = cls.dir / "program"
|
||||
subprocess.run(["cc", "-O2", "-o", str(cls.program), str(build / "program.c"), str(build / "query.c"), "-ldl"],
|
||||
check=True)
|
||||
cls.ring = cls.dir / "ring0"
|
||||
cls.ring.write_text("")
|
||||
cls.virtual = cls.dir / "ring16"
|
||||
cls.virtual.write_text("")
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
shutil.rmtree(cls.dir, True)
|
||||
|
||||
def query(self, winebus=True, caller="sdl", path=None, **extra):
|
||||
env = dict(os.environ, LD_PRELOAD="%s:%s" % (self.lib, self.shim),
|
||||
FAKE_EVDEV_MEMFD_PATHS="0=%s;16=%s" % (self.ring, self.virtual))
|
||||
env.pop("FAKE_EVDEV_STEAM_PAD_AS_X360", None)
|
||||
env.update(extra)
|
||||
result = subprocess.run([str(self.program), str(self.winebus) if winebus else "-",
|
||||
str(self.sdl_library) if caller == "sdl" else "program", str(path or self.ring)],
|
||||
env=env, capture_output=True, text=True, timeout=10, check=True)
|
||||
return result.stdout.strip()
|
||||
|
||||
def test_sdl_in_a_winebus_process_sees_a_ring_pad_as_the_steam_input_pad(self):
|
||||
self.assertEqual(self.query(), "0 28de:11ff")
|
||||
|
||||
def test_sdl_outside_winebus_keeps_the_pad_identity(self):
|
||||
self.assertEqual(self.query(winebus=False), "0 045e:028e")
|
||||
|
||||
def test_other_callers_and_devices_keep_their_identity(self):
|
||||
self.assertEqual(self.query(caller="program"), "0 045e:028e")
|
||||
self.assertEqual(self.query(path=self.virtual), "0 045e:028e")
|
||||
|
||||
def test_a_winebus_without_a_udev_bus_keeps_the_pad_for_sdl(self):
|
||||
self.assertEqual(self.query(FAKE_EVDEV_STEAM_PAD_AS_X360="1"), "0 045e:028e")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user