diff options
| author | Lena <lena@omega> | 2026-08-01 00:00:00 +0000 |
|---|---|---|
| committer | Lena <lena@omega> | 2026-08-01 00:00:00 +0000 |
| commit | 852a8a00273c9128efeed0217a8e5d3fcd8bf780 (patch) | |
| tree | c72f959731fa3c7c809cf1a0222363b6c9c9b03b /app/src/main/java/invalid/lena/scrcpy/TouchGeometry.java | |
| parent | f379b93d52bf0dbd3816ec3f64d165314771d2a6 (diff) | |
| download | scrcpy-android-852a8a00273c9128efeed0217a8e5d3fcd8bf780.tar.gz | |
app: harden mirroring lifecycle and state
Diffstat (limited to 'app/src/main/java/invalid/lena/scrcpy/TouchGeometry.java')
| -rw-r--r-- | app/src/main/java/invalid/lena/scrcpy/TouchGeometry.java | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/app/src/main/java/invalid/lena/scrcpy/TouchGeometry.java b/app/src/main/java/invalid/lena/scrcpy/TouchGeometry.java new file mode 100644 index 0000000..5ee80d4 --- /dev/null +++ b/app/src/main/java/invalid/lena/scrcpy/TouchGeometry.java @@ -0,0 +1,46 @@ +package invalid.lena.scrcpy; + +// Publishes a target size and its matching on-screen viewport as one +// immutable value. A target resize invalidates the old viewport until the UI +// lays out the new generation. +final class TouchGeometry { + + static final class Snapshot { + final int targetW, targetH; + final int x, y, w, h; + + Snapshot(int targetW, int targetH, int x, int y, int w, int h) { + this.targetW = targetW; + this.targetH = targetH; + this.x = x; + this.y = y; + this.w = w; + this.h = h; + } + } + + private volatile Snapshot snapshot; + private long version; + private int targetW; + private int targetH; + + synchronized void setTargetSize(long nextVersion, int w, int h) { + if (nextVersion <= version) throw new IllegalArgumentException("stale target version"); + if (w <= 0 || h <= 0) throw new IllegalArgumentException("invalid target size"); + version = nextVersion; + targetW = w; + targetH = h; + snapshot = null; + } + + synchronized void setViewport(long expectedVersion, int x, int y, int w, int h) { + if (expectedVersion != version) return; + snapshot = version > 0 && targetW > 0 && targetH > 0 && w > 0 && h > 0 + ? new Snapshot(targetW, targetH, x, y, w, h) + : null; + } + + Snapshot snapshot() { + return snapshot; + } +} |