mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-22 06:15:58 +00:00
fix: read Steam shader settings off the main thread
This commit is contained in:
1 parent
0790cb4390
commit
2bd279a0f3
2 files changed
+88
-3
No files matched your search
@@ -120,7 +120,7 @@ class FrontEndActivity : ComponentActivity() {
|
||||
private var glThread by mutableStateOf(true)
|
||||
private var noGlError by mutableStateOf(true)
|
||||
private var returnAfterGame by mutableStateOf(true)
|
||||
private var shaderPrecache by mutableStateOf(true)
|
||||
private var shaderPrecache by mutableStateOf<Boolean?>(null)
|
||||
private var steamRepairQueued by mutableStateOf(false)
|
||||
private var mangoapp by mutableStateOf(true)
|
||||
private var steamController by mutableStateOf(SessionPrefs.CONTROLLER_DECK)
|
||||
@@ -1733,7 +1733,7 @@ class FrontEndActivity : ComponentActivity() {
|
||||
onSteamClientArch = { id ->
|
||||
SessionPrefs.setSteamClientArch(this, id)
|
||||
steamClientArch = id
|
||||
shaderPrecache = SessionPrefs.shaderPrecache(this)
|
||||
loadShaderPrecache(mode)
|
||||
refresh()
|
||||
},
|
||||
onMangoapp = { on -> SessionPrefs.setMangoapp(this, on); mangoapp = on },
|
||||
@@ -1895,6 +1895,19 @@ class FrontEndActivity : ComponentActivity() {
|
||||
private var pipAutoEnter by mutableStateOf(false)
|
||||
private var unfoldedControls by mutableStateOf(false)
|
||||
private var unfoldedControlsWithController by mutableStateOf(false)
|
||||
private var shaderPrecacheGeneration = 0
|
||||
|
||||
private fun loadShaderPrecache(mode: String) {
|
||||
val generation = ++shaderPrecacheGeneration
|
||||
shaderPrecache = null
|
||||
if (mode != SessionService.MODE_STEAM) return
|
||||
Thread({
|
||||
val precache = SessionPrefs.shaderPrecache(this)
|
||||
ui.post {
|
||||
if (!isDestroyed && generation == shaderPrecacheGeneration) shaderPrecache = precache
|
||||
}
|
||||
}, "shader-precache").start()
|
||||
}
|
||||
|
||||
private fun loadModeSettings(mode: String) {
|
||||
pipAutoEnter = SessionPrefs.pipAutoEnter(this)
|
||||
@@ -1910,7 +1923,7 @@ class FrontEndActivity : ComponentActivity() {
|
||||
steamRepairQueued = SteamRepair.queued(this)
|
||||
mangoapp = SessionPrefs.mangoapp(this)
|
||||
returnAfterGame = SessionPrefs.returnAfterGame(this)
|
||||
shaderPrecache = SessionPrefs.shaderPrecache(this)
|
||||
loadShaderPrecache(mode)
|
||||
steamController = SessionPrefs.steamController(this)
|
||||
runSteamAtStartup = SessionPrefs.runSteamAtStartup(this)
|
||||
loadBootMovie()
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
package com.droiddeck.launcher.frontend
|
||||
|
||||
import android.os.Looper
|
||||
import com.droiddeck.launcher.FrontEndActivity
|
||||
import com.droiddeck.launcher.runtime.LinuxRuntime
|
||||
import com.droiddeck.launcher.session.SessionPrefs
|
||||
import com.droiddeck.launcher.session.SessionService
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.Robolectric
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.Shadows.shadowOf
|
||||
import org.robolectric.annotation.Config
|
||||
import org.robolectric.annotation.LooperMode
|
||||
import java.io.File
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [28])
|
||||
@LooperMode(LooperMode.Mode.PAUSED)
|
||||
class ModeSettingsLoadingTest {
|
||||
@Test fun steamPublishesItsShaderChoiceThroughTheMainQueue() {
|
||||
val activity = Robolectric.buildActivity(FrontEndActivity::class.java).get()
|
||||
SessionPrefs.setShaderPrecache(activity, false)
|
||||
load(activity, SessionService.MODE_STEAM)
|
||||
awaitRead()
|
||||
assertNull(value(activity))
|
||||
shadowOf(Looper.getMainLooper()).idle()
|
||||
assertEquals(false, value(activity))
|
||||
}
|
||||
|
||||
@Test fun desktopDoesNotConsumeSteamsAppliedShaderChoice() {
|
||||
val activity = Robolectric.buildActivity(FrontEndActivity::class.java).get()
|
||||
SessionPrefs.setShaderPrecache(activity, false)
|
||||
val applied = File(LinuxRuntime.rootDir(activity), "root/.bl-shader-precache-applied")
|
||||
applied.parentFile!!.mkdirs()
|
||||
applied.writeText("0")
|
||||
load(activity, SessionService.MODE_DESKTOP)
|
||||
awaitRead()
|
||||
shadowOf(Looper.getMainLooper()).idle()
|
||||
assertTrue(applied.isFile)
|
||||
assertNull(value(activity))
|
||||
}
|
||||
|
||||
@Test fun switchingToDesktopDiscardsAQueuedSteamResult() {
|
||||
val activity = Robolectric.buildActivity(FrontEndActivity::class.java).get()
|
||||
load(activity, SessionService.MODE_STEAM)
|
||||
awaitRead()
|
||||
load(activity, SessionService.MODE_DESKTOP)
|
||||
shadowOf(Looper.getMainLooper()).idle()
|
||||
assertNull(value(activity))
|
||||
}
|
||||
|
||||
private fun load(activity: FrontEndActivity, mode: String) {
|
||||
FrontEndActivity::class.java.getDeclaredMethod("loadShaderPrecache", String::class.java)
|
||||
.apply { isAccessible = true }.invoke(activity, mode)
|
||||
}
|
||||
|
||||
private fun value(activity: FrontEndActivity): Boolean? =
|
||||
FrontEndActivity::class.java.getDeclaredMethod("getShaderPrecache")
|
||||
.apply { isAccessible = true }.invoke(activity) as Boolean?
|
||||
|
||||
private fun awaitRead() {
|
||||
Thread.getAllStackTraces().keys.filter { it.name == "shader-precache" }.forEach {
|
||||
it.join(5_000)
|
||||
assertFalse("Shader settings read did not finish", it.isAlive)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user