mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-06 04:55:44 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bfbf1f3d07 |
No files matched your search
@@ -369,6 +369,7 @@ int vkp_has_window(void) {
|
||||
|
||||
int vkp_device_lost(void) { return g_dev_state == -2; }
|
||||
int vkp_completion_unknown(void) { return g_dev_state == -3; }
|
||||
int vkp_device_unusable(void) { return __atomic_load_n(&g_dev_state, __ATOMIC_RELAXED) < 0; }
|
||||
|
||||
void vk_present_set_scale_mode(int mode, int alignment) {
|
||||
if (mode < VKP_MODE_OFF || mode > VKP_MODE_INTEGER) mode = VKP_MODE_FIT;
|
||||
|
||||
@@ -73,6 +73,7 @@ int vkp_device_lost(void);
|
||||
* buffer references and withhold DMA-BUF releases until the app process exits.
|
||||
* This terminal state is distinct from genuine device loss. */
|
||||
int vkp_completion_unknown(void);
|
||||
int vkp_device_unusable(void);
|
||||
|
||||
int vkp_render(int scene_w, int scene_h, const struct vkp_draw *draws, int n);
|
||||
int vkp_render_plain(int scene_w, int scene_h);
|
||||
|
||||
@@ -269,6 +269,13 @@ Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeCompositorFault(JNIE
|
||||
return (*env)->NewStringUTF(env, f ? f : "");
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeDisplayDeviceUnusable(JNIEnv *env, jclass clazz) {
|
||||
(void)env; (void)clazz;
|
||||
extern int vkp_device_unusable(void);
|
||||
return vkp_device_unusable() ? JNI_TRUE : JNI_FALSE;
|
||||
}
|
||||
|
||||
/* The display driver as the driver itself reports it ("" before the compositor's device exists). */
|
||||
JNIEXPORT jstring JNICALL
|
||||
Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeDisplayDriver(JNIEnv *env, jclass clazz) {
|
||||
|
||||
@@ -2868,6 +2868,10 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
override fun surfaceCreated(holder: SurfaceHolder) {
|
||||
if (holder !== outputHolder()) return
|
||||
if (installingRuntime || SessionState.stopRequested || ended) return
|
||||
if (CompositorHost.unusableForNewSession(SessionState.running)) {
|
||||
restartForUnusableDisplay()
|
||||
return
|
||||
}
|
||||
if (!SessionState.running) {
|
||||
SessionEvents.transition(SessionPhase.STARTING_COMPOSITOR, "compositor.starting")
|
||||
}
|
||||
@@ -3475,6 +3479,25 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
startActivity(again)
|
||||
}
|
||||
|
||||
private fun restartForUnusableDisplay() {
|
||||
val fault = WaylandCompositor.compositorFault()
|
||||
val downloading = com.droiddeck.launcher.stores.StoresState.latestDownloads.any { it.isActive }
|
||||
Log.w(TAG, "the compositor's GPU device from an earlier session is unusable ($fault); " +
|
||||
if (downloading) "a store download is running, so DroidDeck is not restarted" else "restarting DroidDeck for this session")
|
||||
SessionEvents.record("compositor.unusable", mapOf("fault" to fault, "restart" to !downloading))
|
||||
if (downloading) {
|
||||
SessionEvents.fail("DISPLAY_DEVICE_UNUSABLE", fault)
|
||||
loading.showEnded(getString(R.string.session_end_present_fault, fault))
|
||||
focusEndedScreen()
|
||||
return
|
||||
}
|
||||
val again = Intent(intent).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK)
|
||||
closeAtOnce = true
|
||||
finish()
|
||||
startActivity(again)
|
||||
Runtime.getRuntime().exit(0)
|
||||
}
|
||||
|
||||
private fun retrySession() {
|
||||
val again = Intent(intent)
|
||||
closeAtOnce = true
|
||||
|
||||
@@ -188,4 +188,9 @@ object CompositorHost {
|
||||
}
|
||||
|
||||
val isStarted: Boolean get() = started
|
||||
|
||||
fun unusableForNewSession(
|
||||
sessionRunning: Boolean,
|
||||
deviceUnusable: () -> Boolean = WaylandCompositor::displayDeviceUnusable,
|
||||
): Boolean = started && !sessionRunning && deviceUnusable()
|
||||
}
|
||||
@@ -264,6 +264,16 @@ public final class WaylandCompositor {
|
||||
|
||||
private static native String nativeDisplayDriver();
|
||||
|
||||
private static native boolean nativeDisplayDeviceUnusable();
|
||||
|
||||
public static boolean displayDeviceUnusable() {
|
||||
try {
|
||||
return nativeDisplayDeviceUnusable();
|
||||
} catch (Throwable t) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/** Why the compositor cannot present, or "" while it can (or before the library is loaded). */
|
||||
public static String compositorFault() {
|
||||
try {
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.droiddeck.launcher.wayland
|
||||
|
||||
import org.junit.After
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
import org.robolectric.util.ReflectionHelpers
|
||||
|
||||
class CompositorHostTest {
|
||||
private fun started(on: Boolean) = ReflectionHelpers.setStaticField(CompositorHost::class.java, "started", on)
|
||||
|
||||
@After fun reset() = started(false)
|
||||
|
||||
@Test fun aNewSessionDoesNotAttachToACompositorWhoseDeviceIsUnusable() {
|
||||
started(true)
|
||||
assertTrue(CompositorHost.unusableForNewSession(sessionRunning = false) { true })
|
||||
}
|
||||
|
||||
@Test fun aNewSessionStillAttachesToAHealthyCompositor() {
|
||||
started(true)
|
||||
assertFalse(CompositorHost.unusableForNewSession(sessionRunning = false) { false })
|
||||
}
|
||||
|
||||
@Test fun aRunningSessionIsNeverRestartedWhenItsSurfaceComesBack() {
|
||||
started(true)
|
||||
assertFalse(CompositorHost.unusableForNewSession(sessionRunning = true) { true })
|
||||
}
|
||||
|
||||
@Test fun aFreshProcessStartsItsCompositorWithoutAskingTheDevice() {
|
||||
var asked = 0
|
||||
assertFalse(CompositorHost.unusableForNewSession(sessionRunning = false) { asked++; true })
|
||||
assertEquals(0, asked)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user