Skip to content

A rootless Android app that boots Alpine Linux: run containers (Podman/Docker/LXC) and GUI desktop apps.

refactor(x11): remove unused code and correct outdated comments

ExTvbf5835ec9662
diff --git a/app/src/main/java/com/excp/podroid/ui/screens/x11/X11SettingsSheet.kt b/app/src/main/java/com/excp/podroid/ui/screens/x11/X11SettingsSheet.kt
index 336d34a..cf325f5 100644
--- a/app/src/main/java/com/excp/podroid/ui/screens/x11/X11SettingsSheet.kt
+++ b/app/src/main/java/com/excp/podroid/ui/screens/x11/X11SettingsSheet.kt
@@ -3,8 +3,8 @@
* Copyright (C) 2024-2026 Podroid contributors
*
* Bottom sheet for X11 viewer settings: resolution mode/preset/custom
- * and rotation lock. TOUCH (Phase 4) and DISPLAY (Phase 5) sections
- * will be appended to the Column below the rotation section.
+ * (plus render scale in MATCH mode), rotation lock, touch mode, and
+ * display (DPI) sections, in that order down the Column.
*/
package com.excp.podroid.ui.screens.x11
diff --git a/app/src/main/java/com/excp/podroid/ui/screens/x11/X11ViewModel.kt b/app/src/main/java/com/excp/podroid/ui/screens/x11/X11ViewModel.kt
index df486d3..6d4b788 100644
--- a/app/src/main/java/com/excp/podroid/ui/screens/x11/X11ViewModel.kt
+++ b/app/src/main/java/com/excp/podroid/ui/screens/x11/X11ViewModel.kt
@@ -10,8 +10,6 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.excp.podroid.BuildConfig
import com.excp.podroid.data.repository.SettingsRepository
-import com.excp.podroid.engine.VmEngine
-import com.excp.podroid.engine.VmState
import com.excp.podroid.x11.AudioStreamer
import com.excp.podroid.x11.DamageTracker
import com.excp.podroid.x11.EncodingPolicy
@@ -58,13 +56,10 @@ sealed interface X11ConnectionState {
@OptIn(ExperimentalCoroutinesApi::class)
@HiltViewModel
class X11ViewModel @Inject constructor(
- val engine: VmEngine,
private val settings: SettingsRepository,
@ApplicationContext private val context: Context,
) : ViewModel() {
- val vmState: StateFlow<VmState> = engine.state
-
private val _connection = MutableStateFlow<X11ConnectionState>(X11ConnectionState.Disconnected)
val connection: StateFlow<X11ConnectionState> = _connection.asStateFlow()
@@ -79,7 +74,7 @@ class X11ViewModel @Inject constructor(
@Volatile private var fbH = X11Constants.FB_HEIGHT
@Volatile var framebuffer: IntArray = IntArray(fbW * fbH); private set
// Dedicated lock object so synchronized() is never on the reassigned framebuffer field.
- val fbLock = Any()
+ private val fbLock = Any()
@Volatile private var scratch: IntArray = IntArray(fbW * fbH)
private val zrle = ZrleDecoder()
@Volatile private var screenId = 0
@@ -92,11 +87,6 @@ class X11ViewModel @Inject constructor(
// StateFlow (which conflates and can silently drop damage between ticks).
@Volatile var onFrame: (() -> Unit)? = null
- /** Takes fbLock and drains pending damage. Prefer [withFrame] when the pixel
- * data is needed too, so the drain and the pixel copy share one critical
- * section instead of two separate locks. */
- fun drainDamage(): List<VncRect> = synchronized(fbLock) { damageTracker.drain() }
-
/** Atomically hands the current framebuffer, its dimensions, and the drained
* pending damage to [block] under fbLock. */
fun <T> withFrame(block: (fb: IntArray, fbW: Int, fbH: Int, damage: List<VncRect>) -> T): T =
@@ -118,8 +108,9 @@ class X11ViewModel @Inject constructor(
// x11-debug.conf and the Raw fallback, debug builds only); read cross-thread
// by the renderer.
@Volatile private var debugEncodingName = "raw"
- // Effective present mode for the current session (used by Task F3);
- // parsed here so the control file's format is settled before that lands.
+ // Effective present mode for the current session: whether the renderer
+ // should try a hardware canvas, read from x11-debug.conf's present= key
+ // (debug builds only; release always stays sw).
@Volatile var debugPresentHw: Boolean = false; private set
/** Debug-only: atomically snapshots and resets (bytesRead, updates, copyNanos, rxNanos). */
@@ -184,9 +175,9 @@ class X11ViewModel @Inject constructor(
zrle.reset()
// Debug-only (BuildConfig.DEBUG): x11-debug.conf lets a developer
- // request ZRLE (and, for Task F3, the present mode) without a
- // rebuild. Release builds never read this file and never want ZRLE,
- // so they always advertise VncClient.DEFAULT_ENCODINGS.
+ // request ZRLE (and the present mode) without a rebuild. Release
+ // builds never read this file and never want ZRLE, so they always
+ // advertise VncClient.DEFAULT_ENCODINGS.
val wantZrle = if (BuildConfig.DEBUG) {
val cfg = X11DebugConfig.read(context)
debugPresentHw = cfg.presentHw
@@ -442,11 +433,11 @@ class X11ViewModel @Inject constructor(
/**
* Debug-only (BuildConfig.DEBUG) reader for `filesDir/x11-debug.conf`: lets a
- * developer flip the advertised SetEncodings list, and (Task F3) the present
- * mode, without a rebuild. Read once per connect(), only when
- * BuildConfig.DEBUG; release builds never call [read]. Format is `key=value`
- * lines; a missing/unreadable file or an unrecognized value falls back to the
- * default for that key.
+ * developer flip the advertised SetEncodings list and the present mode
+ * without a rebuild. Read once per connect(), only when BuildConfig.DEBUG;
+ * release builds never call [read]. Format is `key=value` lines; a
+ * missing/unreadable file or an unrecognized value falls back to the default
+ * for that key.
*/
private object X11DebugConfig {
class Config(val wantZrle: Boolean, val encodingName: String, val presentHw: Boolean)
diff --git a/app/src/main/java/com/excp/podroid/x11/VncClient.kt b/app/src/main/java/com/excp/podroid/x11/VncClient.kt
index 8eaa339..20fb64c 100644
--- a/app/src/main/java/com/excp/podroid/x11/VncClient.kt
+++ b/app/src/main/java/com/excp/podroid/x11/VncClient.kt
@@ -3,7 +3,8 @@
* Copyright (C) 2024-2026 Podroid contributors
*
* Minimal RFB 3.8 client. Supports SecurityType None, Raw + CopyRect +
- * ExtendedDesktopSize + ZRLE encodings. Designed for loopback (SLIRP).
+ * ExtendedDesktopSize + ZRLE encodings. Used over a loopback connection on
+ * both backends (the VNC port is an implicit loopback forward).
*/
package com.excp.podroid.x11
@@ -38,8 +39,9 @@ object VncClient {
/**
* Performs the RFB 3.8 handshake. Reads the server greeting from `inp`,
* writes our responses to `out`, and returns the framebuffer dimensions
- * (the only ServerInit fields we need for v1 — pixel format is fixed
- * 32-bit BGRA via SetPixelFormat sent later by the caller).
+ * (the only ServerInit fields we need for v1: pixel format is fixed to
+ * 32bpp little-endian, depth 24, R shift 16 / G shift 8 / B shift 0 via
+ * SetPixelFormat sent later by the caller).
*
* Throws RfbProtocolException on protocol mismatch.
*/
@@ -119,20 +121,19 @@ object VncClient {
private const val ENC_EXTENDED_DESKTOP_SIZE = -308
// Default SetEncodings list: CopyRect, Raw, ExtendedDesktopSize(-308). ZRLE
- // is deliberately not in the default: the historical desync cause is fixed
- // (ZrleDecoder now feeds the inflater on demand and bounds-checks palette
- // indices/run lengths instead of dropping >4KB blocks), but re-enabling it
- // changes what the server streams, so it stays gated until validated
- // on-device against real Firefox/xfce tiles. Exposed for the debug-only
- // encoding switch (x11-debug.conf, read only when BuildConfig.DEBUG).
+ // is opt-in only, via the debug-only x11-debug.conf switch (read only when
+ // BuildConfig.DEBUG); a ZRLE session that hits a protocol error falls back
+ // to this Raw list for the rest of the ViewModel's lifetime (see
+ // EncodingPolicy). The release default stays Raw.
val DEFAULT_ENCODINGS: IntArray = intArrayOf(ENC_COPY_RECT, ENC_RAW, ENC_EXTENDED_DESKTOP_SIZE)
val ZRLE_ENCODINGS: IntArray = intArrayOf(ENC_ZRLE, ENC_COPY_RECT, ENC_RAW, ENC_EXTENDED_DESKTOP_SIZE)
/**
- * Sends SetPixelFormat to lock the server to 32-bit BGRA, then SetEncodings
- * to advertise [encodings] (default: Raw + CopyRect + ExtendedDesktopSize,
- * byte-identical to the previously hardcoded list). Call once after
- * handshake before requesting any framebuffer update.
+ * Sends SetPixelFormat to lock the server to 32bpp little-endian, depth 24,
+ * R shift 16 / G shift 8 / B shift 0, then SetEncodings to advertise
+ * [encodings] (default: Raw + CopyRect + ExtendedDesktopSize, byte-identical
+ * to the previously hardcoded list). Call once after handshake before
+ * requesting any framebuffer update.
*/
fun negotiatePixelFormat(out: OutputStream, encodings: IntArray = DEFAULT_ENCODINGS) {
// SetPixelFormat (msg=0): pad[3] + 16-byte PixelFormat
diff --git a/app/src/main/java/com/excp/podroid/x11/X11SurfaceRenderer.kt b/app/src/main/java/com/excp/podroid/x11/X11SurfaceRenderer.kt
index 40123ce..689daaf 100644
--- a/app/src/main/java/com/excp/podroid/x11/X11SurfaceRenderer.kt
+++ b/app/src/main/java/com/excp/podroid/x11/X11SurfaceRenderer.kt
@@ -57,9 +57,9 @@ class X11SurfaceRenderer(
// X11ViewModel.debugSnapshotAndReset: only called when BuildConfig.DEBUG,
// once per second, to assemble the combined X11Stats log line below.
private val debugRfbStats: () -> RfbDebugSnapshot,
- // X11ViewModel.debugPresentHw: the F2 debug control file's present=hw|sw
- // setting for this session. Always false (sw) in release builds, which
- // never read that file. Consulted once per Surface, at its first present.
+ // X11ViewModel.debugPresentHw: x11-debug.conf's present=hw|sw setting for
+ // this session. Always false (sw) in release builds, which never read
+ // that file. Consulted once per Surface, at its first present.
private val presentHw: () -> Boolean,
) {
private val thread = HandlerThread("X11Render").apply { start() }
diff --git a/app/src/main/java/com/excp/podroid/x11/ZrleDecoder.kt b/app/src/main/java/com/excp/podroid/x11/ZrleDecoder.kt
index 643c28a..d795748 100644
--- a/app/src/main/java/com/excp/podroid/x11/ZrleDecoder.kt
+++ b/app/src/main/java/com/excp/podroid/x11/ZrleDecoder.kt
@@ -225,7 +225,9 @@ class ZrleDecoder {
/**
* Thin wrapper around [Inflater] that provides byte-level and CPIXEL reads.
- * The inflater's input was already loaded by [decode]; this just drains output.
+ * Compressed input is fed to the inflater on demand via [feedChunk], bounded
+ * by the enclosing rect's compressed length ([remaining]); this class only
+ * drains inflated output.
*/
private inner class ZInput(private val inf: Inflater) {
private val buf = ByteArray(256)