mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-21 13:55:58 +00:00
Feat:Add per-game frame generation profiles (#2473)
This commit is contained in:
1 parent
b1b6ab7931
commit
b52ce7e4c5
46 files changed
+598
-43
No files matched your search
@@ -28,12 +28,38 @@ object FrameGen {
|
||||
|
||||
fun engine(context: Context): String = mode(context).engine
|
||||
|
||||
fun mode(context: Context): Mode {
|
||||
fun mode(context: Context): Mode = mode(context, null)
|
||||
|
||||
fun mode(context: Context, appId: String?): Mode {
|
||||
val prefs = context.getSharedPreferences(PREFS, Context.MODE_PRIVATE)
|
||||
val engine = prefs.getString("engine", ENGINE_OFF).let { if (it == LEGACY_ENGINE_WINFG) ENGINE_DDFG else it ?: ENGINE_OFF }
|
||||
val target = prefs.getInt("target", 0)
|
||||
val gamePrefix = appId?.takeIf { it.isNotBlank() }?.let { "game.$it." }
|
||||
?.takeIf { prefs.contains(it + "engine") } ?: ""
|
||||
val engine = prefs.getString(gamePrefix + "engine", ENGINE_OFF)
|
||||
.let { if (it == LEGACY_ENGINE_WINFG) ENGINE_DDFG else it ?: ENGINE_OFF }
|
||||
val target = prefs.getInt(gamePrefix + "target", 0)
|
||||
if (engine == ENGINE_LSFG && target in ADAPTIVE_TARGETS) return Mode(engine, target = target)
|
||||
return Mode(engine, prefs.getInt("multiplier", 2).coerceIn(2, 4))
|
||||
return Mode(engine, prefs.getInt(gamePrefix + "multiplier", 2).coerceIn(2, 4))
|
||||
}
|
||||
|
||||
fun hasGameOverride(context: Context, appId: String): Boolean =
|
||||
context.getSharedPreferences(PREFS, Context.MODE_PRIVATE).contains("game.$appId.engine")
|
||||
|
||||
fun setForGame(context: Context, appId: String, mode: Mode) {
|
||||
val prefix = "game.$appId."
|
||||
context.getSharedPreferences(PREFS, Context.MODE_PRIVATE).edit()
|
||||
.putString(prefix + "engine", mode.engine)
|
||||
.putInt(prefix + "multiplier", mode.multiplier)
|
||||
.putInt(prefix + "target", mode.target)
|
||||
.apply()
|
||||
}
|
||||
|
||||
fun clearGame(context: Context, appId: String) {
|
||||
val prefix = "game.$appId."
|
||||
context.getSharedPreferences(PREFS, Context.MODE_PRIVATE).edit()
|
||||
.remove(prefix + "engine")
|
||||
.remove(prefix + "multiplier")
|
||||
.remove(prefix + "target")
|
||||
.apply()
|
||||
}
|
||||
|
||||
fun set(context: Context, mode: Mode) {
|
||||
@@ -41,6 +67,11 @@ object FrameGen {
|
||||
.putString("engine", mode.engine).putInt("multiplier", mode.multiplier).putInt("target", mode.target).apply()
|
||||
}
|
||||
|
||||
fun clearGlobal(context: Context) {
|
||||
context.getSharedPreferences(PREFS, Context.MODE_PRIVATE).edit()
|
||||
.remove("engine").remove("multiplier").remove("target").apply()
|
||||
}
|
||||
|
||||
fun label(context: Context): String = label(context, mode(context))
|
||||
|
||||
fun label(context: Context, mode: Mode): String = when {
|
||||
@@ -50,14 +81,32 @@ object FrameGen {
|
||||
else -> context.getString(R.string.frame_gen_off)
|
||||
}
|
||||
|
||||
fun apply(context: Context, refreshHz: Float): String? = apply(context, mode(context), refreshHz)
|
||||
data class PreparedApply internal constructor(
|
||||
val mode: Mode,
|
||||
internal val lsfgStatus: Int? = null,
|
||||
internal val lsfgCachePath: String? = null,
|
||||
)
|
||||
|
||||
fun apply(context: Context, mode: Mode, refreshHz: Float): String? {
|
||||
fun prepareApply(context: Context, mode: Mode): PreparedApply {
|
||||
if (mode.engine != ENGINE_LSFG) return PreparedApply(mode)
|
||||
val status = Lossless.sync(context)
|
||||
val cachePath = Lossless.cacheFile(context)?.absolutePath
|
||||
return PreparedApply(mode, status, cachePath)
|
||||
}
|
||||
|
||||
fun apply(context: Context, refreshHz: Float): String? =
|
||||
apply(context, mode(context), refreshHz)
|
||||
|
||||
fun apply(context: Context, mode: Mode, refreshHz: Float): String? =
|
||||
applyPrepared(context, prepareApply(context, mode), refreshHz)
|
||||
|
||||
fun applyPrepared(context: Context, prepared: PreparedApply, refreshHz: Float): String? {
|
||||
val mode = prepared.mode
|
||||
when (mode.engine) {
|
||||
ENGINE_LSFG -> {
|
||||
val status = Lossless.sync(context)
|
||||
val cache = Lossless.cacheFile(context)
|
||||
if (status != LsfgNative.STATUS_OK || cache == null) {
|
||||
val status = prepared.lsfgStatus ?: LsfgNative.STATUS_NOT_INSTALLED
|
||||
val cachePath = prepared.lsfgCachePath
|
||||
if (status != LsfgNative.STATUS_OK || cachePath == null) {
|
||||
WaylandCompositor.nativeSetFrameGenArmed(false, 0, 0)
|
||||
val problem = context.getString(
|
||||
if (status == LsfgNative.STATUS_NOT_INSTALLED) R.string.lsfg_problem_missing else R.string.lsfg_problem_failed,
|
||||
@@ -66,7 +115,7 @@ object FrameGen {
|
||||
return problem
|
||||
}
|
||||
WaylandCompositor.nativeSetFrameGenEngine(WaylandCompositor.FG_ENGINE_LSFG)
|
||||
WaylandCompositor.nativeSetLsfgCachePath(cache.absolutePath)
|
||||
WaylandCompositor.nativeSetLsfgCachePath(cachePath)
|
||||
WaylandCompositor.nativeSetFrameGenTuning(FLOW_SCALE_LSFG, refreshHz)
|
||||
WaylandCompositor.nativeSetFrameGenArmed(true, mode.multiplier, mode.target)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user