feat: bridge Quest projection surface and tracking

This commit is contained in:
XxJSONDeruloxX committed 2026-10-14 17:20:13 -04:00
1 parent 07f5e5f83d
commit f0934018df
19 files changed
+569 -35

No files matched your search

+2
View File
@@ -150,6 +150,7 @@ android {
}
buildFeatures {
prefab true
compose true
buildConfig true
}
@@ -225,6 +226,7 @@ if (!skipRust) android.sourceSets.main.jniLibs.srcDir(rustJniLibsDir)
tasks.named('preBuild').configure { dependsOn(buildRustStores) }
dependencies {
implementation 'org.khronos.openxr:openxr_loader_for_android:1.1.49'
implementation 'com.github.luben:zstd-jni:1.5.2-3@aar'
implementation 'org.apache.commons:commons-compress:1.27.1'
implementation 'org.tukaani:xz:1.10'
+14
View File
@@ -22,6 +22,9 @@
<uses-feature android:name="android.hardware.vulkan.version" android:version="0x401000" android:required="true" />
<uses-feature android:name="android.hardware.gamepad" android:required="false" />
<uses-feature android:name="android.hardware.vr.headtracking" android:version="1" android:required="false" />
<uses-feature android:name="oculus.software.handtracking" android:required="false" />
<uses-permission android:name="com.oculus.permission.HAND_TRACKING" />
<application
android:name=".App"
@@ -37,6 +40,17 @@
android:isGame="true">
<meta-data android:name="android.game_mode_config" android:resource="@xml/game_mode_config" />
<activity android:name=".QuestXrActivity" android:exported="true" android:launchMode="singleTask"
android:resizeableActivity="false" android:screenOrientation="landscape"
android:configChanges="orientation|screenSize|screenLayout|keyboardHidden|keyboard|navigation|uiMode"
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen">
<meta-data android:name="android.app.lib_name" android:value="droiddeckxr" />
<intent-filter>
<action android:name="com.droiddeck.launcher.XR" />
<category android:name="com.oculus.intent.category.VR" />
<category android:name="org.khronos.openxr.intent.category.IMMERSIVE_HMD" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
+1
View File
@@ -30,6 +30,7 @@ string(SUBSTRING "${WINFG_CHAIN_HASH_FULL}" 0 12 WINFG_CHAIN_HASH)
message(STATUS "win-fg chain: ${WINFG_UPSTREAM} (src ${WINFG_CHAIN_HASH})")
add_subdirectory(waylandcomp)
add_subdirectory(../../../../questxr/src/main/cpp questxr)
add_library(sdnative SHARED sdnative/sdnative.c)
target_link_libraries(sdnative log)
+35 -1
View File
@@ -121,6 +121,11 @@ static pthread_mutex_t g_req_lock = PTHREAD_MUTEX_INITIALIZER;
static ANativeWindow *g_req_window;
static int g_req_pending;
static int g_req_detached;
static uint64_t g_req_generation, g_req_applied;
static pthread_cond_t g_req_condition = PTHREAD_COND_INITIALIZER;
static uint64_t g_presented_frames;
uint64_t vkp_presented_frames(void) { return __atomic_load_n(&g_presented_frames, __ATOMIC_ACQUIRE); }
static volatile int g_mode = VKP_MODE_STRETCH, g_align = VKP_ALIGN_CENTER;
@@ -198,26 +203,53 @@ void vk_present_set_window(ANativeWindow *window) {
if (g_req_pending && g_req_window && g_req_window != window) superseded = g_req_window;
g_req_window = window;
g_req_pending = 1;
g_req_generation++;
if (!window) g_req_detached = 1;
pthread_mutex_unlock(&g_req_lock);
if (superseded) ANativeWindow_release(superseded);
}
static void window_request_applied(uint64_t generation) {
pthread_mutex_lock(&g_req_lock);
g_req_applied = generation;
pthread_cond_broadcast(&g_req_condition);
pthread_mutex_unlock(&g_req_lock);
}
int vkp_wait_window_request(int timeout_ms) {
if (timeout_ms <= 0 || timeout_ms > 10000) return 0;
struct timespec deadline;
clock_gettime(CLOCK_REALTIME, &deadline);
deadline.tv_sec += timeout_ms / 1000;
deadline.tv_nsec += (timeout_ms % 1000) * 1000000L;
if (deadline.tv_nsec >= 1000000000L) { deadline.tv_sec++; deadline.tv_nsec -= 1000000000L; }
pthread_mutex_lock(&g_req_lock);
const uint64_t generation = g_req_generation;
int error = 0;
while (g_req_applied < generation && error == 0)
error = pthread_cond_timedwait(&g_req_condition, &g_req_lock, &deadline);
int applied = g_req_applied >= generation;
pthread_mutex_unlock(&g_req_lock);
return applied;
}
int vkp_apply_window_request(void) {
ANativeWindow *w;
pthread_mutex_lock(&g_req_lock);
if (!g_req_pending) { pthread_mutex_unlock(&g_req_lock); return 0; }
w = g_req_window;
const int detached = g_req_detached;
const uint64_t generation = g_req_generation;
g_req_window = NULL;
g_req_pending = 0;
g_req_detached = 0;
pthread_mutex_unlock(&g_req_lock);
if (w == g_window) {
if (w) ANativeWindow_release(w);
if (!w || !detached) return 0;
if (!w || !detached) { window_request_applied(generation); return 0; }
sc_layer_window_gone();
destroy_swapchain();
window_request_applied(generation);
droiddeck_log("gpu", "screen surface rebound: rebuilding the swapchain at its new size");
return 1;
}
@@ -228,6 +260,7 @@ int vkp_apply_window_request(void) {
g_window = w;
g_swap_retry_at_ns = 0;
g_swap_fail_logged = 0;
window_request_applied(generation);
droiddeck_log("gpu", w ? "screen surface attached" : "screen surface gone: presenting paused");
return 1;
}
@@ -1638,6 +1671,7 @@ static int render_impl(int scene_w, int scene_h, const struct vkp_draw *draws, i
}
g_base_black = (g_plain_frame && n == 0 && !hf) ? 1 : 0;
if (fr == VK_SUCCESS) __atomic_add_fetch(&g_presented_frames, 1u, __ATOMIC_RELEASE);
if (drawn && !g_first_frame_done) {
g_first_frame_done = 1;
@@ -48,6 +48,8 @@ const char *vkp_gpu_name(void);
int vkp_ready(void);
int vkp_has_window(void);
int vkp_wait_window_request(int timeout_ms);
uint64_t vkp_presented_frames(void);
int vkp_device_lost(void);
int vkp_render(int scene_w, int scene_h, const struct vkp_draw *draws, int n);
@@ -582,6 +582,17 @@ static char *dup_bytes(JNIEnv *env, jbyteArray arr, int *len) {
return buf;
}
JNIEXPORT jboolean JNICALL
Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeWaitSurface(
JNIEnv *env, jclass clazz, jint timeout_ms) {
return vkp_wait_window_request(timeout_ms) ? JNI_TRUE : JNI_FALSE;
}
JNIEXPORT jlong JNICALL
Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativePresentedFrames(JNIEnv *env, jclass clazz) {
return (jlong)vkp_presented_frames();
}
JNIEXPORT void JNICALL
Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeSetClipboardText(JNIEnv *env, jclass clazz, jbyteArray utf8) {
int len;
@@ -0,0 +1,53 @@
package com.droiddeck.launcher
import android.app.NativeActivity
import android.os.Bundle
import android.view.Surface
import com.droiddeck.launcher.session.SessionService
import com.droiddeck.launcher.wayland.CompositorHost
import com.droiddeck.launcher.wayland.WaylandCompositor
import java.util.concurrent.CountDownLatch
import java.util.concurrent.TimeUnit
class QuestXrActivity : NativeActivity() {
private var presentedBaseline = 0L
override fun onCreate(savedInstanceState: Bundle?) {
if (intent.getBooleanExtra("guest_surface", false)) {
require(CompositorHost.isStarted) { "Start a DroidDeck session before attaching XR" }
intent.putExtra("surface_test", true)
}
super.onCreate(savedInstanceState)
}
fun onXrSurface(surface: Surface?, width: Int, height: Int) {
val complete = CountDownLatch(1)
var failure: Throwable? = null
runOnUiThread {
try {
if (surface != null) {
presentedBaseline = WaylandCompositor.nativePresentedFrames()
WaylandCompositor.nativeSetCardboard(false, 1, 0.064f, 3f, 4f, 0f, 0f, 90f, 0f, 0f)
WaylandCompositor.nativeSetFrameGenArmed(false, 0, 0)
WaylandCompositor.nativeSetZeroCopy(false)
WaylandCompositor.nativeSetOutputSize(width, height)
WaylandCompositor.nativeSetFpsLimit(0)
}
CompositorHost.attachXr(surface)
SessionService.setActivityVisible(this, surface != null)
WaylandCompositor.nativeVsync(System.nanoTime())
} catch (error: Throwable) {
failure = error
} finally {
complete.countDown()
}
}
check(complete.await(3, TimeUnit.SECONDS)) { "XR surface UI handshake timed out" }
failure?.let { throw it }
check(WaylandCompositor.nativeWaitSurface(3000)) { "XR surface GPU handshake timed out" }
}
fun onXrFrame(frameTimeNanos: Long): Long {
WaylandCompositor.nativeVsync(frameTimeNanos)
return (WaylandCompositor.nativePresentedFrames() - presentedBaseline).coerceAtLeast(0)
}
}
@@ -71,6 +71,14 @@ object CompositorHost {
private var attached: Surface? = null
@Synchronized
fun attachXr(surface: Surface?) {
check(started) { "DroidDeck compositor is not running" }
pauseVsync()
attached = surface
WaylandCompositor.nativeSetSurface(surface)
}
@Synchronized
fun detach(surface: Surface?) {
if (!started) return
@@ -148,6 +148,8 @@ public final class WaylandCompositor {
String nativeLibDir);
public static native void nativeSetSurface(Surface surface);
public static native boolean nativeWaitSurface(int timeoutMs);
public static native long nativePresentedFrames();
public static native void nativeSendPointer(int action, int x, int y);