Use sequence numbers to synchronize enabling Pointer Capture (1/2)
InputReader only processes configuration change from its main thread.
This means that if there is more than one Pointer Capture change
request when the thread is busy or sleeping, it will only process the
latest one. To ensure requests to enable Pointer Capture are synchronized
with Dispatcher, we must use sequence numbers.
Requests to enable Pointer Capture have a sequence number. Requests to
disable Pointer Capture do not have a value.
Bug: 195312888
Test: atest inputflinger_tests
Test: manual with GeforceNow app, see bug.
Change-Id: I6ae9c5498dc2f783b4c7211fa3665d42e29d2919
diff --git a/include/input/Input.h b/include/input/Input.h
index 2e42409..d2d9fd4 100644
--- a/include/input/Input.h
+++ b/include/input/Input.h
@@ -1025,6 +1025,25 @@
std::queue<std::unique_ptr<TouchModeEvent>> mTouchModeEventPool;
};
+/*
+ * Describes a unique request to enable or disable Pointer Capture.
+ */
+struct PointerCaptureRequest {
+public:
+ inline PointerCaptureRequest() : enable(false), seq(0) {}
+ inline PointerCaptureRequest(bool enable, uint32_t seq) : enable(enable), seq(seq) {}
+ inline bool operator==(const PointerCaptureRequest& other) const {
+ return enable == other.enable && seq == other.seq;
+ }
+ explicit inline operator bool() const { return enable; }
+
+ // True iff this is a request to enable Pointer Capture.
+ bool enable;
+
+ // The sequence number for the request.
+ uint32_t seq;
+};
+
} // namespace android
#endif // _LIBINPUT_INPUT_H