Files
DroidDeck/tools/tests/test_hdr_live_switch.py
T
MaxsTechReview 210c127446 feat(addons): add a CurseForge source to the addon browser (#3028)
* feat(addons): add a CurseForge source to the addon browser

Search and install CurseForge addons from the Download addons window by
driving the installed CurseForge app in the background: it starts minimized
on the session's X display with its inspector bound to 127.0.0.1, and the
window's own renderer services handle game detection, search, install and
shutdown. Sign-in stays inside the CurseForge app.

The Install buttons in the addon list now size to their label, so the label
is centered and the button matches the other compact buttons.

* fix(curseforge): secret inspector URL, hold mode and serialised starts

- Start CurseForge with its Node inspector on 127.0.0.1:0 and publish only
  the UUID websocket URL, kept in the 0700 state directory, so no fixed
  unauthenticated debug port is exposed.
- The agent evaluates through that URL instead of a fixed port.
- Add a hold mode that runs as a session program and stops the app on
  exit, and a lock so hold and start never launch twice.

* feat(addons): run CurseForge in a hidden session when none is running

- Opening the CurseForge source with no session starts one headlessly
  (offscreen compositor output, shared start path with SessionActivity via
  CompositorHost) running the CurseForge hold helper; leaving the dialog
  stops the app and that session. A session the user already had is
  reused and left running.
- Drop the "start a session" notice from every locale.
- Addon browser link: cleanup shares the link's lock off the UI thread,
  stops the app at once on close, refuses work after close and stops a
  launch that finishes after close.
- CurseForgeApp.start stops the app before every failed return.
- instanceFor returns no instance when the populated list has no match.

* Harden headless CurseForge session and helper lifecycle

Scope the hidden session to its id, roll back partial starts, release the
offscreen reader once the session ends, re-acquire the inspector when its
endpoint goes away, bound DevTools calls by one deadline, key the installed
snapshot by target, track the helper launch by pid start time and directory,
fail on lock errors, and update the HDR gate test to its new location.

* Map DevTools send failures and recheck the hidden session id

* fix(addons): bind the hidden session to the id it claims at launch

* Keep the CurseForge helper quiet when no launch is recorded
2026-11-22 17:02:35 -05:00

92 lines
4.9 KiB
Python

from pathlib import Path
import re
import unittest
ROOT = Path(__file__).resolve().parents[2]
PATCH = ROOT / "tools/gamescope/patches/0139-hdr-switch-live.patch"
APP = ROOT / "app/src/main/java/com/droiddeck/launcher"
RES = ROOT / "app/src/main/res"
def lines(prefix):
return [line[1:] for line in PATCH.read_text().splitlines()
if line.startswith(prefix) and not line.startswith(prefix * 3)]
class HdrLiveSwitchTest(unittest.TestCase):
def test_display_capability_does_not_depend_on_the_setting(self):
added = [line for line in lines("+") if "bExposeHDRSupport =" in line]
self.assertEqual(len(added), 1)
self.assertNotIn("cv_hdr_enabled", added[0])
self.assertIn("m_uMaxTargetLuminance > m_pConnector->m_uReferenceLuminance", added[0])
def test_sdr_keeps_the_8_bit_output(self):
added = [line for line in lines("+") if "*pPrimaryPlaneFormat" in line]
self.assertEqual(len(added), 1)
self.assertRegex(added[0], r"cv_hdr_enabled && u10BitFormat != DRM_FORMAT_INVALID \) \? u10BitFormat : u8BitFormat")
def test_remade_output_images_pick_the_format_again(self):
text = PATCH.read_text()
hunk = text[text.index("src/rendervulkan.cpp"):]
added = [line[1:] for line in hunk.splitlines() if line.startswith("+") and not line.startswith("+++")]
self.assertEqual([line.strip() for line in added],
["GetBackend()->GetPreferredOutputFormat( &pOutput->uOutputFormat, &pOutput->uOutputFormatOverlay );"])
self.assertIn("if ( vulkan_defer_output_images() )", hunk[:hunk.index(added[0])])
def test_capable_display_does_not_force_dxvk_hdr_off(self):
added = "\n".join(lines("+"))
self.assertIn('unsetenv( "DXVK_HDR" )', added)
off = added.index('setenv( "DXVK_HDR", "0", true )')
self.assertIn("!GetCurrentConnector()->GetHDRInfo().bExposeHDRSupport", added[:off])
def test_the_gate_follows_the_display_not_the_setting(self):
text = (APP / "SessionActivity.kt").read_text()
start = text.index("val attached = CompositorHost.isStarted")
block = text[start:text.index("CompositorHost.start(", start)]
request = block[block.index("nativeSetHdrRequest("):block.index("Log.i", block.index("nativeSetHdrRequest("))]
self.assertNotIn("SessionPrefs.hdr", block)
self.assertIn("capable, false", request)
self.assertIn("if (!SessionState.running) CompositorHost.applyHdr(this, mode)", block)
host = (APP / "wayland/CompositorHost.kt").read_text()
gate = host[host.index("fun applyHdr("):]
gate = gate[:gate.index("\n }")]
self.assertIn("SessionState.hdrCapable && SessionPrefs.hdr(context, mode)", gate)
def test_both_switches_apply_to_the_running_session(self):
helper = (APP / "session/SessionHdr.kt").read_text()
self.assertIn('setGamescopeConvar(app, "hdr_enabled", if (on) 1 else 0)', helper)
self.assertIn("nativeSetHdrOutput(on)", helper)
self.assertIn("nativeSetZeroCopy(on || SessionPrefs.zeroCopy(context, mode))", helper)
self.assertIn("SessionPrefs.prefMode(SessionState.mode) != mode", helper)
for name in ("SessionActivity.kt", "FrontEndActivity.kt"):
text = (APP / name).read_text()
self.assertEqual(len(re.findall(r"onHdr = \{ on -> com\.droiddeck\.launcher\.session\.SessionHdr\.set\(", text)), 1, name)
self.assertNotIn("SessionPrefs.setHdr(", text, name)
def test_a_saved_opt_out_applies_before_the_gate_opens(self):
native = (ROOT / "app/src/main/cpp/waylandcomp/src/wl_color_mgmt.c").read_text()
switch = native[native.index("void droiddeck_color_set_output(int on)"):]
switch = switch[:switch.index("if (gate != 1)")]
self.assertLess(switch.index("pthread_mutex_lock(&g_output_mu)"), switch.index("atomic_store(&g_output_wanted, on)"))
self.assertLess(switch.index("atomic_exchange(&g_output_on, on)"), switch.index("pthread_mutex_unlock(&g_output_mu)"))
opened = native[native.index("atomic_store(&g_gate, 1);") - 40:]
opened = opened[:opened.index("pthread_mutex_unlock(&g_output_mu)")]
self.assertIn("pthread_mutex_lock(&g_output_mu)", opened)
self.assertIn("if (mode == 3 || !atomic_load(&g_output_wanted)) atomic_store(&g_output_on, 0);", opened)
text = (APP / "SessionActivity.kt").read_text()
self.assertNotIn("if (attached) WaylandCompositor.nativeSetHdrOutput", text)
def test_retries_stay_with_the_session_that_asked(self):
helper = (APP / "session/SessionHdr.kt").read_text()
self.assertIn("val session = SessionState.sessionId", helper)
self.assertIn("SessionState.sessionId == session", helper)
def test_no_restart_hint_is_left(self):
for path in list(RES.glob("values*/strings.xml")) + list(APP.rglob("*.kt")):
self.assertNotIn("mode_hdr_restart", path.read_text(), str(path))
if __name__ == "__main__":
unittest.main()