Effects page in the session menu: scaling modes, screen effects and texture filtering (#198)

This commit is contained in:
The412Banner authored and GitHub committed 2026-10-04 08:17:00 -04:00
1 parent 33f7213599
commit 423cf11919
16 files changed
+664 -51

No files matched your search

@@ -3,6 +3,7 @@ package com.droiddeck.launcher.session
import android.content.Context
import android.util.AtomicFile
import com.droiddeck.launcher.core.GameEnvironment
import com.droiddeck.launcher.core.TextureFiltering
import com.droiddeck.launcher.runtime.LinuxRuntime
import org.json.JSONObject
import java.io.File
@@ -10,6 +11,8 @@ import java.io.File
object GameEnvironmentStore {
private const val SETTINGS = "game-environment.json"
private const val GUEST_FILE = "root/.config/droiddeck/game-environment.json"
/** The published file's extra DXVK options (bannerlator-game-env reads it; the app's own file has none). */
const val DXVK_CONFIG = "dxvkConfig"
@Synchronized
fun read(context: Context): GameEnvironment.Config {
@@ -57,7 +60,15 @@ object GameEnvironmentStore {
@Synchronized
fun publish(context: Context, config: GameEnvironment.Config = read(context)) {
val resolved = config.copy(shared = GameEnvironment.defaults(SessionPrefs.fexPreset(context)) + config.shared)
write(File(LinuxRuntime.rootDir(context), GUEST_FILE), encode(resolved).toString())
val json = encode(resolved)
// The Display page's texture filtering, as DXVK options the launcher appends to
// DXVK_CONFIG after the profiles - a user's own DXVK_CONFIG entry keeps its options.
val dxvk = TextureFiltering.dxvkOptions(
SessionPrefs.textureAnisotropy(context), SessionPrefs.textureLodBias(context),
TextureFiltering.autoLodBias(SessionState.upscaleRatio),
)
if (dxvk.isNotEmpty()) json.put(DXVK_CONFIG, dxvk)
write(File(LinuxRuntime.rootDir(context), GUEST_FILE), json.toString())
}
private fun write(file: File, text: String) {
@@ -1,6 +1,9 @@
package com.droiddeck.launcher.session
import android.content.Context
import com.droiddeck.launcher.core.TextureFiltering
import com.droiddeck.launcher.gpu.ScreenEffects
import org.json.JSONObject
/** The in-session switches: the HUD and how the on-screen controls decide to appear. */
object SessionPrefs {
@@ -610,9 +613,15 @@ object SessionPrefs {
val fpsLimitChoices = listOf(0 to "Off", 30 to "30", 40 to "40", 45 to "45", 60 to "60", 90 to "90", 120 to "120")
/**
* How the compositor resizes the session onto the panel (WaylandCompositor.nativeSetUpscaler's
* modes): Off and Linear both filter bilinearly, Nearest keeps pixels square for 2D and old
* titles, the rest sharpen where the picture is enlarged; FSR (fit) rounds the picture to
* FSR's preferred size first. Sharpen only works at any size.
*/
val upscalerChoices = listOf(
0 to "Off", 4 to "AMD FSR 1", 3 to "Snapdragon GSR", 8 to "Snapdragon GSR (quality)",
7 to "NVIDIA NIS", 6 to "Sharpen only",
0 to "Off", 1 to "Linear", 2 to "Nearest", 4 to "AMD FSR 1", 5 to "AMD FSR 1 (fit)", 3 to "Snapdragon GSR",
8 to "Snapdragon GSR (quality)", 7 to "NVIDIA NIS", 6 to "Sharpen only",
)
fun upscaler(context: Context): Int =
@@ -622,14 +631,58 @@ object SessionPrefs {
prefs(context).edit().putInt("upscaler", mode).apply()
}
val upscaleSharpnessChoices = listOf(0 to "0%", 25 to "25%", 50 to "50%", 75 to "75%", 100 to "100%")
fun upscaleSharpness(context: Context): Int = prefs(context).getInt("upscaleSharpness", 75).coerceIn(0, 100)
fun setUpscaleSharpness(context: Context, pct: Int) {
prefs(context).edit().putInt("upscaleSharpness", pct.coerceIn(0, 100)).apply()
}
// ── Screen effects and texture filtering (the Display page) ─────────────────────────────
/** The compositor's post chain as last set; off until the user picks a Look or moves a row. */
fun screenEffects(context: Context): ScreenEffects {
val text = prefs(context).getString("screenEffects", null) ?: return ScreenEffects.OFF
return runCatching { ScreenEffects.decode(JSONObject(text)) }.getOrDefault(ScreenEffects.OFF)
}
fun setScreenEffects(context: Context, effects: ScreenEffects) {
prefs(context).edit().putString("screenEffects", effects.encode().toString()).apply()
}
val textureAnisotropyChoices = TextureFiltering.ANISOTROPY.map { it to if (it == 0) "Off" else "${it}x" }
val textureLodBiasChoices = TextureFiltering.LOD_BIAS.map {
it to when (it) {
TextureFiltering.LOD_BIAS_OFF -> "Off"
TextureFiltering.LOD_BIAS_AUTO -> "Auto (match scaling)"
else -> it
}
}
/** Anisotropic filtering forced on DirectX 9-11 games (core/TextureFiltering); 0 = the game's own. */
fun textureAnisotropy(context: Context): Int =
prefs(context).getInt("textureAnisotropy", 0).takeIf { it in TextureFiltering.ANISOTROPY } ?: 0
fun setTextureAnisotropy(context: Context, value: Int) {
prefs(context).edit().putInt("textureAnisotropy", value).apply()
publishGameEnvironment(context)
}
/** Texture sharpness: the mip LOD bias choice (TextureFiltering.LOD_BIAS), "0" = the game's own. */
fun textureLodBias(context: Context): String =
prefs(context).getString("textureLodBias", null)?.takeIf { it in TextureFiltering.LOD_BIAS } ?: TextureFiltering.LOD_BIAS_OFF
fun setTextureLodBias(context: Context, choice: String) {
prefs(context).edit().putString("textureLodBias", choice).apply()
publishGameEnvironment(context)
}
/** Hands the change to the next game launch (GameEnvironmentStore); the running game keeps its own. */
private fun publishGameEnvironment(context: Context) {
runCatching { GameEnvironmentStore.publish(context) }
.onFailure { android.util.Log.e("GameEnvironment", "Could not update game environment", it) }
}
/**
* The mode whose per-mode settings apply: a program run under gamescope (MODE_RUN) is a
* fullscreen session like Steam's, so it takes Steam's display, driver and HDR choices.
@@ -96,6 +96,14 @@ object SessionState {
@Volatile
var refreshHz: Float = 60f
/**
* How far the compositor enlarges the session onto the panel (panel over outputSize, long
* side to long side); set with outputSize. 0 before a session has been sized. Texture
* sharpness "Auto" (core/TextureFiltering) is derived from it when a game launches.
*/
@Volatile
var upscaleRatio: Float = 0f
/** The session's frame cap (SessionPrefs.fpsLimit), fixed when it starts; 0 = none. */
@Volatile
var fpsLimit: Int = 0