Handle different scale and offset for pointers in InputTarget.
This change allows an InputTarget to have multiple pointers in different
scale and offsets. This was done by using an array to store each
pointerId to PointerInfo. PointerInfo contains the information that's
unique to each pointer, scale and offset.
Once the dispatcher is ready to queue the event, the dispatcher will
request the InputTarget to gather all it's pointer information and
normalize them to a single offset and scale. It will generate a new
DispatcherEntry with a new MotionEvent that has all the coordinates in a
single offset and scale. It will also set that offset and scale in the
MotionEvent so it can be handled properly when sent to the client.
This is the 3rd attempt since it was breaking tests
Change-Id: Ic75c7df06cf4a881da6ac0c57013e29a84533d1e
Test: InputDispatcherMultiWindowSameTokenTests
Test: manually with magnification
Test: NexusLauncherOutOfProcTests:TaplTestsLauncher3
Test: NexusLauncherOutOfProcTests:TaplTestsQuickstep
Fixes: 140756730
Fixes: 147371357
diff --git a/services/inputflinger/dispatcher/InputTarget.h b/services/inputflinger/dispatcher/InputTarget.h
index 1ba5eff..499a75f 100644
--- a/services/inputflinger/dispatcher/InputTarget.h
+++ b/services/inputflinger/dispatcher/InputTarget.h
@@ -24,6 +24,22 @@
namespace android::inputdispatcher {
/*
+ * Information about each pointer for an InputTarget. This includes offset and scale so
+ * all pointers can be normalized to a single offset and scale.
+ *
+ * These values are ignored for KeyEvents
+ */
+struct PointerInfo {
+ // The x and y offset to add to a MotionEvent as it is delivered.
+ float xOffset = 0.0f;
+ float yOffset = 0.0f;
+
+ // Scaling factor to apply to MotionEvent as it is delivered.
+ float windowXScale = 1.0f;
+ float windowYScale = 1.0f;
+};
+
+/*
* An input target specifies how an input event is to be dispatched to a particular window
* including the window's input channel, control flags, a timeout, and an X / Y offset to
* be added to input event coordinates to compensate for the absolute position of the
@@ -95,20 +111,37 @@
// Flags for the input target.
int32_t flags = 0;
- // The x and y offset to add to a MotionEvent as it is delivered.
- // (ignored for KeyEvents)
- float xOffset = 0.0f;
- float yOffset = 0.0f;
-
// Scaling factor to apply to MotionEvent as it is delivered.
// (ignored for KeyEvents)
float globalScaleFactor = 1.0f;
- float windowXScale = 1.0f;
- float windowYScale = 1.0f;
// The subset of pointer ids to include in motion events dispatched to this input target
// if FLAG_SPLIT is set.
BitSet32 pointerIds;
+ // The data is stored by the pointerId. Use the bit position of pointerIds to look up
+ // PointerInfo per pointerId.
+ PointerInfo pointerInfos[MAX_POINTERS];
+
+ void addPointers(BitSet32 pointerIds, float xOffset, float yOffset, float windowXScale,
+ float windowYScale);
+ void setDefaultPointerInfo(float xOffset, float yOffset, float windowXScale,
+ float windowYScale);
+
+ /**
+ * Returns whether the default pointer information should be used. This will be true when the
+ * InputTarget doesn't have any bits set in the pointerIds bitset. This can happen for monitors
+ * and non splittable windows since we want all pointers for the EventEntry to go to this
+ * target.
+ */
+ bool useDefaultPointerInfo() const;
+
+ /**
+ * Returns the default PointerInfo object. This should be used when useDefaultPointerInfo is
+ * true.
+ */
+ const PointerInfo& getDefaultPointerInfo() const;
+
+ std::string getPointerInfoString() const;
};
std::string dispatchModeToString(int32_t dispatchMode);