Commit 6b00b5ad authored by robert.bradford's avatar robert.bradford Committed by Commit bot

ozone: Map TouchEvent::touch_id_ into expected range

Touch events from evdev have a slot identifier to represent which
fingers are touched. Prior to this change this slot identifier was used
as the TouchEvent::touch_id_. However this breaks with multiple
touchscreens as the range for the slots will be the same.

This CL resolves that by using a SequentialIDGenerator to map a unique
device and slot id to an unused touch id in the sequence.

The touch id is released when the touch is released or cancelled.

BUG=472308
TEST=Manual testing on link_freon with uncommitted VLOG messages.

Review URL: https://codereview.chromium.org/1048333005

Cr-Commit-Position: refs/heads/master@{#325255}
parent 55d1762e
......@@ -88,14 +88,14 @@ ScrollEventParams::~ScrollEventParams() {
}
TouchEventParams::TouchEventParams(int device_id,
int touch_id,
int slot,
EventType type,
const gfx::PointF& location,
const gfx::Vector2dF& radii,
float pressure,
const base::TimeDelta& timestamp)
: device_id(device_id),
touch_id(touch_id),
slot(slot),
type(type),
location(location),
radii(radii),
......
......@@ -99,7 +99,7 @@ struct EVENTS_OZONE_EVDEV_EXPORT ScrollEventParams {
struct EVENTS_OZONE_EVDEV_EXPORT TouchEventParams {
TouchEventParams(int device_id,
int touch_id,
int slot,
EventType type,
const gfx::PointF& location,
const gfx::Vector2dF& radii,
......@@ -109,7 +109,7 @@ struct EVENTS_OZONE_EVDEV_EXPORT TouchEventParams {
~TouchEventParams();
int device_id;
int touch_id;
int slot;
EventType type;
gfx::PointF location;
gfx::Vector2dF radii;
......
......@@ -20,6 +20,7 @@
#include "ui/events/ozone/evdev/input_device_factory_evdev.h"
#include "ui/events/ozone/evdev/input_device_factory_evdev_proxy.h"
#include "ui/events/ozone/evdev/input_injector_evdev.h"
#include "ui/events/ozone/evdev/touch_evdev_types.h"
namespace ui {
......@@ -121,6 +122,7 @@ EventFactoryEvdev::EventFactoryEvdev(CursorDelegateEvdev* cursor,
cursor_(cursor),
input_controller_(&keyboard_, &button_map_),
initialized_(false),
touch_id_generator_(0),
weak_ptr_factory_(this) {
DCHECK(device_manager_);
}
......@@ -231,12 +233,19 @@ void EventFactoryEvdev::DispatchTouchEvent(const TouchEventParams& params) {
DeviceDataManager::GetInstance()->ApplyTouchRadiusScale(params.device_id,
&radius_y);
// params.slot is guaranteed to be < kNumTouchEvdevSlots.
int touch_id = touch_id_generator_.GetGeneratedID(
params.device_id * kNumTouchEvdevSlots + params.slot);
TouchEvent touch_event(params.type, gfx::PointF(x, y),
modifiers_.GetModifierFlags(), params.touch_id,
modifiers_.GetModifierFlags(), touch_id,
params.timestamp, radius_x, radius_y,
/* angle */ 0.f, params.pressure);
touch_event.set_source_device_id(params.device_id);
DispatchUiEvent(&touch_event);
if (params.type == ET_TOUCH_RELEASED || params.type == ET_TOUCH_CANCELLED) {
touch_id_generator_.ReleaseGeneratedID(touch_event.touch_id());
}
}
void EventFactoryEvdev::DispatchUiEvent(Event* event) {
......
......@@ -20,6 +20,7 @@
#include "ui/events/ozone/evdev/mouse_button_map_evdev.h"
#include "ui/events/platform/platform_event_source.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/gfx/sequential_id_generator.h"
#include "ui/ozone/public/system_input_injector.h"
namespace gfx {
......@@ -128,6 +129,9 @@ class EVENTS_OZONE_EVDEV_EXPORT EventFactoryEvdev : public DeviceEventObserver,
// Thread for device I/O.
EventThreadEvdev thread_;
// Touch event id generator.
SequentialIDGenerator touch_id_generator_;
// Support weak pointers for attach & detach callbacks.
base::WeakPtrFactory<EventFactoryEvdev> weak_ptr_factory_;
......
......@@ -256,7 +256,7 @@ TEST_F(TouchEventConverterEvdevTest, TouchMove) {
event.timestamp);
EXPECT_EQ(295, event.location.x());
EXPECT_EQ(421, event.location.y());
EXPECT_EQ(0, event.touch_id);
EXPECT_EQ(0, event.slot);
EXPECT_FLOAT_EQ(58.f, event.radii.x());
EXPECT_FLOAT_EQ(0.13333334f, event.pressure);
......@@ -271,7 +271,7 @@ TEST_F(TouchEventConverterEvdevTest, TouchMove) {
event.timestamp);
EXPECT_EQ(312, event.location.x());
EXPECT_EQ(432, event.location.y());
EXPECT_EQ(0, event.touch_id);
EXPECT_EQ(0, event.slot);
EXPECT_FLOAT_EQ(50.f, event.radii.x());
EXPECT_FLOAT_EQ(0.16862745f, event.pressure);
......@@ -286,7 +286,7 @@ TEST_F(TouchEventConverterEvdevTest, TouchMove) {
event.timestamp);
EXPECT_EQ(312, event.location.x());
EXPECT_EQ(432, event.location.y());
EXPECT_EQ(0, event.touch_id);
EXPECT_EQ(0, event.slot);
EXPECT_FLOAT_EQ(50.f, event.radii.x());
EXPECT_FLOAT_EQ(0.16862745f, event.pressure);
}
......@@ -336,7 +336,7 @@ TEST_F(TouchEventConverterEvdevTest, TwoFingerGesture) {
EXPECT_EQ(base::TimeDelta::FromMicroseconds(0), ev0.timestamp);
EXPECT_EQ(40, ev0.location.x());
EXPECT_EQ(51, ev0.location.y());
EXPECT_EQ(0, ev0.touch_id);
EXPECT_EQ(0, ev0.slot);
EXPECT_FLOAT_EQ(0.17647059f, ev0.pressure);
// Press
......@@ -344,7 +344,7 @@ TEST_F(TouchEventConverterEvdevTest, TwoFingerGesture) {
EXPECT_EQ(base::TimeDelta::FromMicroseconds(0), ev1.timestamp);
EXPECT_EQ(101, ev1.location.x());
EXPECT_EQ(102, ev1.location.y());
EXPECT_EQ(1, ev1.touch_id);
EXPECT_EQ(1, ev1.slot);
EXPECT_FLOAT_EQ(0.17647059f, ev1.pressure);
// Stationary 0, Moves 1.
......@@ -360,7 +360,7 @@ TEST_F(TouchEventConverterEvdevTest, TwoFingerGesture) {
EXPECT_EQ(base::TimeDelta::FromMicroseconds(0), ev1.timestamp);
EXPECT_EQ(40, ev1.location.x());
EXPECT_EQ(102, ev1.location.y());
EXPECT_EQ(1, ev1.touch_id);
EXPECT_EQ(1, ev1.slot);
EXPECT_FLOAT_EQ(0.17647059f, ev1.pressure);
// Move 0, stationary 1.
......@@ -377,7 +377,7 @@ TEST_F(TouchEventConverterEvdevTest, TwoFingerGesture) {
EXPECT_EQ(base::TimeDelta::FromMicroseconds(0), ev0.timestamp);
EXPECT_EQ(39, ev0.location.x());
EXPECT_EQ(51, ev0.location.y());
EXPECT_EQ(0, ev0.touch_id);
EXPECT_EQ(0, ev0.slot);
EXPECT_FLOAT_EQ(0.17647059f, ev0.pressure);
// Release 0, move 1.
......@@ -395,14 +395,14 @@ TEST_F(TouchEventConverterEvdevTest, TwoFingerGesture) {
EXPECT_EQ(base::TimeDelta::FromMicroseconds(0), ev0.timestamp);
EXPECT_EQ(39, ev0.location.x());
EXPECT_EQ(51, ev0.location.y());
EXPECT_EQ(0, ev0.touch_id);
EXPECT_EQ(0, ev0.slot);
EXPECT_FLOAT_EQ(0.17647059f, ev0.pressure);
EXPECT_EQ(ui::ET_TOUCH_MOVED, ev1.type);
EXPECT_EQ(base::TimeDelta::FromMicroseconds(0), ev1.timestamp);
EXPECT_EQ(38, ev1.location.x());
EXPECT_EQ(102, ev1.location.y());
EXPECT_EQ(1, ev1.touch_id);
EXPECT_EQ(1, ev1.slot);
EXPECT_FLOAT_EQ(0.17647059f, ev1.pressure);
// Release 1.
......@@ -418,7 +418,7 @@ TEST_F(TouchEventConverterEvdevTest, TwoFingerGesture) {
EXPECT_EQ(base::TimeDelta::FromMicroseconds(0), ev1.timestamp);
EXPECT_EQ(38, ev1.location.x());
EXPECT_EQ(102, ev1.location.y());
EXPECT_EQ(1, ev1.touch_id);
EXPECT_EQ(1, ev1.slot);
EXPECT_FLOAT_EQ(0.17647059f, ev1.pressure);
}
......@@ -488,7 +488,7 @@ TEST_F(TouchEventConverterEvdevTest, ShouldResumeExistingContactsOnStart) {
ui::TouchEventParams ev = dispatched_event(0);
EXPECT_EQ(ET_TOUCH_PRESSED, ev.type);
EXPECT_EQ(0, ev.touch_id);
EXPECT_EQ(0, ev.slot);
EXPECT_FLOAT_EQ(50.f, ev.radii.x());
EXPECT_FLOAT_EQ(0.f, ev.radii.y());
EXPECT_FLOAT_EQ(0.50196081f, ev.pressure);
......@@ -530,12 +530,12 @@ TEST_F(TouchEventConverterEvdevTest,
ui::TouchEventParams ev0 = dispatched_event(0);
ui::TouchEventParams ev1 = dispatched_event(1);
EXPECT_EQ(0, ev0.touch_id);
EXPECT_EQ(0, ev0.slot);
EXPECT_EQ(999, ev0.location.x());
EXPECT_EQ(888, ev0.location.y());
EXPECT_FLOAT_EQ(0.21568628f, ev0.pressure);
EXPECT_EQ(1, ev1.touch_id);
EXPECT_EQ(1, ev1.slot);
EXPECT_EQ(777, ev1.location.x());
EXPECT_EQ(666, ev1.location.y());
EXPECT_FLOAT_EQ(0.17254902f, ev1.pressure);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment