mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-21 05:46:03 +00:00
* feat(display): zero-copy presentation toggle and compositor display buffers Adds a Zero-copy presentation switch under Steam Settings, Display, Session Display (on by default), and a display-buffer allocator in the compositor: a Vulkan driver that states displayBuffers asks it for the memory of the images it exports, so frames presented through the nested compositor are gralloc buffers that go on the display layer without a copy. Compressed buffers are offered only where the device's allocator matches the layout the drivers render to; everything else stays on the copy path. The private buffer protocol is renamed to droiddeck-ahb-v1. * fix(display): zero-copy frames keep the full refresh rate Two buffers set on the game layer inside one refresh replaced each other, and a frame that slipped into the next refresh made the compositor hold and drop the on-time frame behind it. The layer now queues buffers, and a refresh takes a second frame when the one before it took none. The pacing tool no longer counts its dump time in the frame rate. * Keep cropped scenes on the display layer and pace layer frames evenly Accept any in-bounds source crop for the display layer and map the draw geometry the same way the copy path does. Time layer frames against the display's frame timeline, and when the game's rate is a steady whole fraction of the refresh rate show each frame a fixed number of refreshes after the last so uneven arrivals no longer reach the screen. * List zero-copy in the settings map * Hold display buffers until the display releases them A buffer the game or gamescope rendered straight into went back to its client as soon as the next one was latched, with the display's release fence attached to the dma-buf. The KGSL driver does not wait on that fence, so the client could draw into a buffer the panel was still reading. Display buffers now wait for the release fence before the release event, and gamescope composites only into output images the host has released. * Keep the game picture copy-free when an overlay has no display layer When the display cannot give a second layer of its own to an overlay, the compositor tells gamescope how many planes it can show directly. gamescope then composes its overlays into the game picture, which still reaches the display without a copy. * feat(session): the panel refresh rate follows the session's frame rate The session learns the panel's refresh rates and reports the refresh rate and frame rate it wants. The panel moves to the highest rate the frame rate divides evenly, frame generation counts at its output rate, and a panel whose rate the system holds offers only that rate. * feat(session): the panel follows a frame rate the game holds on its own The compositor reports the game's frame rate once a second. A rate that holds for three seconds and divides a panel rate becomes the content rate when neither the app's limit nor the session's limiter is setting the pace, so a game capped in its own settings gets a panel rate its frames divide into. A rate that was dropped has to hold twice as long before it is used again. * Show generated frames on the game's display layer With frame generation on, the game's own frames stay on their display layer untouched and each generated frame is placed on the same layer between them, timed across the game's frame interval. The compositor pass is kept when effects, HDR routing or a cursor need it, or when the panel cannot show the multiplied rate. * Keep scaling, generated frames and HDR on the display layer A scaler or frame generation with zero-copy on now draws once into the display layer instead of falling back to the copied surface. HDR output goes to the layer when the panel supports it; on a panel without HDR the picture is tone-mapped on the same path, and the toggle is labelled to match what the panel can do. * Spread a frame limit the refresh rate does not divide evenly across refreshes * Cover the spare-tick and panel-rate paths in the compositor source tests * Pin the gamescope build with the display-plane, release, refresh and limiter patches * Give the layer and terminal-caller harnesses the black fill state they compile against * feat(display): switch HDR during a session without restarting the app The compositor now offers HDR whenever the device can present it, and the HDR setting only decides whether the session uses it. Both HDR switches set gamescope's hdr_enabled, the compositor's HDR output and zero-copy for the running session. gamescope patch 0139 lets hdr_enabled change after start. The 'Restart the app to apply.' hint is removed from every locale. * Remake the output images in the new format when HDR is switched during a session * Pin the gamescope build that switches HDR during a session * Apply a saved HDR opt-out at session start and keep HDR retries with their session * Serialise the HDR output switch with the gate opening * feat(display): keep the client's HDR setting and the session's in step The session publishes its HDR state with the other device controls and the client helper applies it to the client's own display setting. A change made in the client is reported back and goes through the same switch the drawer and Session Display use, so all three always show one value. * fix(desktop): keep the display-buffer socket when the runtime directory is cleared The desktop launcher removed everything in the runtime directory except the compositor's Wayland socket, which took the display-buffer socket with it, so no desktop program could ask for display buffers and every frame was copied. * fix(display): the client's HDR setting follows the session in every client mode The bridge only ran when a variable nothing sets was present, so the client's HDR setting and the session's never met. It now runs whenever the session publishes an HDR state, and a client that has no such setting is asked again only every ten seconds. * fix(display): harden display-buffer hand-off, layer fallbacks and HDR sync - Stop closing a buffer handle's descriptor the allocator still owns, and free an allocation whose reply could not be sent. - Rebuild the advertised buffer formats when zero-copy is switched during a session. - Fall back to the copy path when a layer buffer cannot be allocated, and hide the game layer when it is skipped for a frame. - Keep a release fence that has not signalled instead of rendering into a buffer the display still reads. - Ignore a refresh-target reset from a client that does not own the target. - Restart the content-rate measurement after a pause, clear it when the game stops, and lengthen engagement only for a rate that was released before. - Compare colour conversions by their values, and read padded cursor buffers at their row width. - Use the running session's mode for the HDR and zero-copy settings, probe the display before screen effects are pushed, retry a held panel mode, and ignore callbacks after the activity is destroyed. - Write a newer HDR value while an earlier write is settling, and reapply the value after the bridge is reinstalled.
186 lines
8.6 KiB
Python
186 lines
8.6 KiB
Python
import json
|
|
from pathlib import Path
|
|
import runpy
|
|
import subprocess
|
|
import tempfile
|
|
import unittest
|
|
|
|
ROOT = Path(__file__).resolve().parents[2]
|
|
BIN = ROOT / "tools/linuxfs/overlay/usr/local/bin"
|
|
APP = ROOT / "app/src/main/java/com/droiddeck/launcher"
|
|
LIVE = runpy.run_path(str(BIN / "droiddeck-steam-compat"))
|
|
|
|
HARNESS = r"""
|
|
const assert = require('assert');
|
|
globalThis.window = globalThis;
|
|
globalThis.btoa = text => Buffer.from(text, 'binary').toString('base64');
|
|
let now = 0, tick = null;
|
|
Object.defineProperty(globalThis, 'performance', { value: { now: () => now }, configurable: true });
|
|
globalThis.setInterval = callback => { tick = callback; return 1; };
|
|
const varints = bytes => { const out = []; let value = 0, shift = 0;
|
|
for (const b of bytes) { value += (b & 127) * 2 ** shift; shift += 7; if (b < 128) { out.push(value); value = 0; shift = 0; } }
|
|
return out; };
|
|
const writes = [], told = [];
|
|
let apply = true;
|
|
globalThis.settingsStore = { clientSettings: { gamescope_hdr_enabled: false } };
|
|
globalThis.SteamClient = { Settings: { SetSetting(encoded) {
|
|
const [key, value] = varints([...Buffer.from(encoded, 'base64')]);
|
|
assert.strictEqual(key, 21015 * 8);
|
|
writes.push(value);
|
|
if (apply) settingsStore.clientSettings.gamescope_hdr_enabled = value === 1;
|
|
} } };
|
|
window.droiddeckHdrChanged = value => told.push(value);
|
|
const script = require('fs').readFileSync(process.argv[2], 'utf8');
|
|
assert.strictEqual(eval(script), 'installed');
|
|
assert.strictEqual(eval(script), 'present');
|
|
const bridge = window.__droiddeckHdr;
|
|
tick();
|
|
assert.deepStrictEqual(told, [], 'an unchanged client setting is not reported');
|
|
assert.strictEqual(bridge.set(true), true);
|
|
assert.deepStrictEqual(writes, [1]);
|
|
tick();
|
|
assert.deepStrictEqual(told, [], 'a value the app set is not reported back to it');
|
|
assert.strictEqual(bridge.set(true), true);
|
|
assert.deepStrictEqual(writes, [1], 'an equal value is not written again');
|
|
settingsStore.clientSettings.gamescope_hdr_enabled = false;
|
|
tick();
|
|
assert.deepStrictEqual(told, ['0'], 'a change made in the client reaches the app');
|
|
tick();
|
|
assert.deepStrictEqual(told, ['0']);
|
|
settingsStore.clientSettings.gamescope_hdr_enabled = true;
|
|
tick();
|
|
assert.deepStrictEqual(told, ['0', '1']);
|
|
apply = false;
|
|
bridge.set(false);
|
|
assert.deepStrictEqual(writes, [1, 0]);
|
|
now += 500; tick();
|
|
assert.deepStrictEqual(told, ['0', '1'], 'the old value is not reported while a write is settling');
|
|
now += 3000; tick();
|
|
assert.deepStrictEqual(told, ['0', '1', '1'], 'a write the client did not take is reported as its real value');
|
|
assert.strictEqual(bridge.set('yes'), true);
|
|
assert.deepStrictEqual(writes, [1, 0]);
|
|
bridge.set(false);
|
|
bridge.set(true);
|
|
assert.deepStrictEqual(writes, [1, 0, 0, 1], 'a newer opposite value is written while the earlier write is settling');
|
|
settingsStore.clientSettings.gamescope_hdr_enabled = false;
|
|
now += 500; tick();
|
|
settingsStore.clientSettings.gamescope_hdr_enabled = true;
|
|
now += 500; tick();
|
|
assert.deepStrictEqual(told, ['0', '1', '1'], 'the earlier write landing late is not reported to the app');
|
|
delete globalThis.__droiddeckHdr;
|
|
delete settingsStore.clientSettings.gamescope_hdr_enabled;
|
|
assert.strictEqual(eval(script), 'unavailable');
|
|
"""
|
|
|
|
|
|
class HdrSteamSyncTest(unittest.TestCase):
|
|
def test_bridge_keeps_the_client_setting_and_the_app_equal(self):
|
|
with tempfile.TemporaryDirectory() as directory:
|
|
script = Path(directory) / "bridge.js"
|
|
script.write_text(LIVE["HDR_JS"])
|
|
test = Path(directory) / "test.js"
|
|
test.write_text(HARNESS)
|
|
result = subprocess.run(["node", str(test), str(script)], capture_output=True, text=True, timeout=20)
|
|
self.assertEqual(result.returncode, 0, result.stderr)
|
|
|
|
def test_requests_accept_only_on_and_off(self):
|
|
with tempfile.TemporaryDirectory() as directory:
|
|
path = Path(directory) / "hdr.request"
|
|
for value in ["2", "true", "", None, 1]:
|
|
LIVE["hdr_request"](value, directory)
|
|
self.assertFalse(path.exists())
|
|
LIVE["hdr_request"]("1", directory)
|
|
self.assertEqual(path.read_text(), "1\n")
|
|
LIVE["hdr_request"]("0", directory)
|
|
self.assertEqual(path.read_text(), "0\n")
|
|
|
|
def helper(self, directory):
|
|
helper = LIVE["Helper"]("/steam", 0)
|
|
calls = []
|
|
|
|
class Page:
|
|
answer = True
|
|
|
|
def call(self, method, params=None):
|
|
calls.append((method, params))
|
|
|
|
def evaluate(self, expression):
|
|
calls.append(expression)
|
|
return "installed" if expression == LIVE["HDR_JS"] else self.answer
|
|
|
|
helper.page = Page()
|
|
return helper, calls
|
|
|
|
def test_the_app_state_is_applied_once_per_change(self):
|
|
with tempfile.TemporaryDirectory() as directory:
|
|
globals_ = LIVE["Helper"].sync_hdr.__globals__
|
|
previous = globals_["CONTROLS_DIR"]
|
|
try:
|
|
globals_["CONTROLS_DIR"] = directory
|
|
helper, calls = self.helper(directory)
|
|
path = Path(directory) / "state.json"
|
|
helper.sync_hdr()
|
|
path.write_text(json.dumps({"brightness": 0.5}))
|
|
helper.sync_hdr()
|
|
self.assertEqual(calls, [], "a session that cannot show HDR leaves the client setting alone")
|
|
path.write_text(json.dumps({"brightness": 0.5, "hdr": True}))
|
|
helper.sync_hdr()
|
|
helper.sync_hdr()
|
|
self.assertEqual(calls[0], ("Runtime.addBinding", {"name": LIVE["HDR_BINDING"]}))
|
|
self.assertEqual(calls[1], LIVE["HDR_JS"])
|
|
self.assertEqual(calls[2:], ["window.__droiddeckHdr ? window.__droiddeckHdr.set(true) : false"])
|
|
path.write_text(json.dumps({"brightness": 0.7, "hdr": True}))
|
|
helper.sync_hdr()
|
|
self.assertEqual(len(calls), 3)
|
|
path.write_text(json.dumps({"hdr": False}))
|
|
helper.sync_hdr()
|
|
self.assertEqual(calls[3], "window.__droiddeckHdr ? window.__droiddeckHdr.set(false) : false")
|
|
helper.page.answer = False
|
|
path.write_text(json.dumps({"hdr": True}))
|
|
helper.sync_hdr()
|
|
self.assertFalse(helper.hdr_installed)
|
|
self.assertIsNone(helper.hdr_state)
|
|
helper.page.answer = True
|
|
path.write_text(json.dumps({"hdr": False}))
|
|
helper.sync_hdr()
|
|
self.assertEqual(calls[-1], "window.__droiddeckHdr ? window.__droiddeckHdr.set(false) : false")
|
|
finally:
|
|
globals_["CONTROLS_DIR"] = previous
|
|
|
|
def test_a_client_without_the_setting_is_left_alone(self):
|
|
with tempfile.TemporaryDirectory() as directory:
|
|
globals_ = LIVE["Helper"].sync_hdr.__globals__
|
|
previous = globals_["CONTROLS_DIR"]
|
|
try:
|
|
globals_["CONTROLS_DIR"] = directory
|
|
helper, calls = self.helper(directory)
|
|
helper.page.evaluate = lambda expression: calls.append(expression) or "unavailable"
|
|
(Path(directory) / "state.json").write_text(json.dumps({"hdr": True}))
|
|
helper.sync_hdr()
|
|
self.assertEqual(calls, [("Runtime.addBinding", {"name": LIVE["HDR_BINDING"]}), LIVE["HDR_JS"]])
|
|
self.assertFalse(helper.hdr_installed)
|
|
self.assertIsNone(helper.hdr_state)
|
|
helper.sync_hdr()
|
|
self.assertEqual(len(calls), 2, "a client without the setting is not asked again straight away")
|
|
finally:
|
|
globals_["CONTROLS_DIR"] = previous
|
|
|
|
def test_the_app_publishes_and_takes_the_shared_value(self):
|
|
controls = (APP / "runtime/DeviceControlsComponent.kt").read_text()
|
|
self.assertIn('if (SessionState.hdrCapable) controls.put("hdr", SessionState.hdr)', controls)
|
|
self.assertIn('"hdr.request" -> if (text == "0" || text == "1")', controls)
|
|
self.assertIn('SessionHdr.set(context, SessionPrefs.prefMode(SessionState.mode), text == "1")', controls)
|
|
self.assertIn('"hdr.request")', controls[controls.index("REQUESTS = setOf"):])
|
|
session = (APP / "SessionActivity.kt").read_text()
|
|
self.assertIn("if (key == SessionPrefs.hdrKey(hdrPrefMode()))", session)
|
|
self.assertIn("registerOnSharedPreferenceChangeListener(hdrPrefListener)", session)
|
|
self.assertIn("unregisterOnSharedPreferenceChangeListener(hdrPrefListener)", session)
|
|
|
|
def test_frame_limit_writes_share_the_setting_writer(self):
|
|
self.assertIn("(21002, value)", LIVE["FRAME_LIMIT_JS"])
|
|
self.assertNotIn("__SET_SETTING__", LIVE["FRAME_LIMIT_JS"] + LIVE["HDR_JS"])
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|