CHROMIUM: Input: synaptics - fix 1->3 contact transition reporting
authorDaniel Kurtz <djkurtz@chromium.org>
Fri, 18 Nov 2011 11:26:53 +0000 (19:26 +0800)
committerGrant Grundler <grundler@google.com>
Thu, 24 May 2012 22:12:02 +0000 (15:12 -0700)
Investigating the following gesture highlighted two slight implementation
errors with choosing which slots to report in which slot when multiple
contacts are present:

Action                 SGM  AGM (MTB slot:Contact)
1. Touch contact 0    (0:0)
2. Touch contact 1    (0:0, 1:1)
3. Lift  contact 0    (1:1)
4. Touch contacts 2,3 (0:2, 1:3)

In step 4, slot 1 was not being cleared first, which means the same
tracking ID was being used for reporting both the old contact 1 and the
new contact 3.  This could result in "drumroll", where the old contact 1
would appear to suddenly jump to new finger 3 position.

Similarly, if contacts 2 & 3 are not detected at the same sample, step 4
is split into two:

Action                SGM  AGM  (MTB slot:contact)
1. Touch contact 0   (0:0)
2. Touch contact 1   (0:0, 1:1)
3. Lift  contact 0   (1:1)
4. Touch contact 2   (0:2, 1:1)
5. Touch contact 3   (0:2, 1:3)

In this case, there was also a bug.  In step 4, when contact 1 moves from
SGM to AGM and contact 2 is first reported in SGM, slot 0 was actually
empty.  So slot 0 can be used to report the new SGM (contact 0),
immediately.  Since it was empty, contact 2 in slot 0 will get a new
tracking ID.

Signed-off-by: Daniel Kurtz <djkurtz@chromium.org>
BUG=chromium-os:23197
TEST=Reproduce actions listed above.
  Inspect resulting event stream using evtest.
  Case (a) Contacts 2 and 3 should have different Tracking IDs than 0 and 1
  Case (b) Contact 2 should be reported in slot 0 in the first report
           after it is detected.

Change-Id: I3a58ae06c29b8d7570720297f3b2bd9383be87ca
Reviewed-on: https://gerrit.chromium.org/gerrit/11902
Reviewed-by: Andrew de los Reyes <adlr@chromium.org>
Commit-Ready: Daniel Kurtz <djkurtz@chromium.org>
Reviewed-by: Daniel Kurtz <djkurtz@chromium.org>
Tested-by: Daniel Kurtz <djkurtz@chromium.org>
drivers/input/mouse/synaptics.c

index ee1daab..3c24949 100644 (file)
@@ -652,11 +652,13 @@ static void synaptics_report_mt_data(struct psmouse *psmouse,
        default:
                /*
                 * If the finger slot contained in SGM is valid, and either
-                * hasn't changed, or is new, then report SGM in MTB slot 0.
+                * hasn't changed, or is new, or the old SGM has now moved to
+                * AGM, then report SGM in MTB slot 0.
                 * Otherwise, empty MTB slot 0.
                 */
                if (mt_state->sgm != -1 &&
-                   (mt_state->sgm == old->sgm || old->sgm == -1))
+                   (mt_state->sgm == old->sgm ||
+                    old->sgm == -1 || mt_state->agm == old->sgm))
                        synaptics_report_slot(dev, 0, sgm);
                else
                        synaptics_report_slot(dev, 0, NULL);
@@ -665,9 +667,31 @@ static void synaptics_report_mt_data(struct psmouse *psmouse,
                 * If the finger slot contained in AGM is valid, and either
                 * hasn't changed, or is new, then report AGM in MTB slot 1.
                 * Otherwise, empty MTB slot 1.
+                *
+                * However, in the case where the AGM is new, make sure that
+                * that it is either the same as the old SGM, or there was no
+                * SGM.
+                *
+                * Otherwise, if the SGM was just 1, and the new AGM is 2, then
+                * the new AGM will keep the old SGM's tracking ID, which can
+                * cause apparent drumroll.  This happens if in the following
+                * valid finger sequence:
+                *
+                *  Action                 SGM  AGM (MTB slot:Contact)
+                *  1. Touch contact 0    (0:0)
+                *  2. Touch contact 1    (0:0, 1:1)
+                *  3. Lift  contact 0    (1:1)
+                *  4. Touch contacts 2,3 (0:2, 1:3)
+                *
+                * In step 4, contact 3, in AGM must not be given the same
+                * tracking ID as contact 1 had in step 3.  To avoid this,
+                * the first agm with contact 3 is dropped and slot 1 is
+                * invalidated (tracking ID = -1).
                 */
                if (mt_state->agm != -1 &&
-                   (mt_state->agm == old->agm || old->agm == -1))
+                   (mt_state->agm == old->agm ||
+                    (old->agm == -1 &&
+                     (old->sgm == -1 || mt_state->agm == old->sgm))))
                        synaptics_report_slot(dev, 1, agm);
                else
                        synaptics_report_slot(dev, 1, NULL);