aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/invalid/lena/scrcpy/TouchGeometry.java
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/invalid/lena/scrcpy/TouchGeometry.java')
-rw-r--r--app/src/main/java/invalid/lena/scrcpy/TouchGeometry.java46
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;
+ }
+}