mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-24 15:26:04 +00:00
feat: launch Quest SteamVR and harden XR lifecycle
This commit is contained in:
1 parent
e1d096127c
commit
7277386cd3
8 files changed
+152
-52
No files matched your search
@@ -3,51 +3,62 @@ package com.droiddeck.launcher
|
||||
import android.app.NativeActivity
|
||||
import android.os.Bundle
|
||||
import android.view.Surface
|
||||
import android.util.Log
|
||||
import com.droiddeck.launcher.gpu.SteamVr
|
||||
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
|
||||
private var steamVrStarted = false
|
||||
@Volatile private var closing = false
|
||||
@Volatile private var steamVrStatus = SteamVr.Status.UNAVAILABLE
|
||||
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)
|
||||
SessionService.resume(this)
|
||||
}
|
||||
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()
|
||||
}
|
||||
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)
|
||||
}
|
||||
check(complete.await(3, TimeUnit.SECONDS)) { "XR surface UI handshake timed out" }
|
||||
failure?.let { throw it }
|
||||
CompositorHost.attachXr(surface)
|
||||
SessionService.setActivityVisible(this, surface != null)
|
||||
WaylandCompositor.nativeVsync(System.nanoTime())
|
||||
check(WaylandCompositor.nativeWaitSurface(3000)) { "XR surface GPU handshake timed out" }
|
||||
if (surface != null && intent.getBooleanExtra("start_steamvr", false) && !steamVrStarted) {
|
||||
steamVrStarted = true
|
||||
Thread({
|
||||
if (!SteamVr.run(this, "start")) Log.e("DroidDeckXR", "SteamVR start failed")
|
||||
while (!closing) {
|
||||
steamVrStatus = SteamVr.status(this)
|
||||
Thread.sleep(1000)
|
||||
}
|
||||
SteamVr.run(this, "stop")
|
||||
}, "quest-steamvr-start").start()
|
||||
}
|
||||
}
|
||||
|
||||
fun onXrFrame(frameTimeNanos: Long): Long {
|
||||
WaylandCompositor.nativeVsync(frameTimeNanos)
|
||||
return (WaylandCompositor.nativePresentedFrames() - presentedBaseline).coerceAtLeast(0)
|
||||
}
|
||||
|
||||
fun onXrStatus(): Int = steamVrStatus.ordinal
|
||||
|
||||
override fun onDestroy() {
|
||||
closing = true
|
||||
if (steamVrStarted) Thread({ SteamVr.run(this, "stop") }, "quest-steamvr-stop").start()
|
||||
super.onDestroy()
|
||||
}
|
||||
}
|
||||
@@ -2325,6 +2325,11 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
||||
}
|
||||
|
||||
private fun steamVrAction(action: String) {
|
||||
if (action == "start" && com.droiddeck.launcher.session.QuestExperimental.isSupported()) {
|
||||
startActivity(android.content.Intent(this, QuestXrActivity::class.java)
|
||||
.putExtra("guest_surface", true).putExtra("start_steamvr", true))
|
||||
return
|
||||
}
|
||||
if (action == "start") {
|
||||
switchPictureForSteamVr()
|
||||
steamVrSeenRunning = false
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.droiddeck.launcher.session.SessionState
|
||||
object CompositorHost {
|
||||
@Volatile
|
||||
private var started = false
|
||||
@Volatile
|
||||
private var vsyncRunning = false
|
||||
|
||||
private val vsync = object : Choreographer.FrameCallback {
|
||||
|
||||
Reference in new issue
Block a user