Commit 40ee4d54 authored by spang's avatar spang Committed by Commit bot

ozone: evdev: Move touch ui::Event transformation to EventFactoryEvdev

This is part of a series moving IO on evdev devices to a fast thread,
since UI thread is too slow for the cursor.

DeviceDataManager is a UI thread object, so move final transformation
of touches into EventFactoryEvdev prior to dispatch into UI. This
will avoid sharing state across threads.

BUG=449710
TEST=boot link_freon & move cursor

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

Cr-Commit-Position: refs/heads/master@{#313204}
parent 0c80fb96
...@@ -68,6 +68,8 @@ component("events_ozone_evdev") { ...@@ -68,6 +68,8 @@ component("events_ozone_evdev") {
"evdev/event_converter_evdev_impl.h", "evdev/event_converter_evdev_impl.h",
"evdev/event_device_info.cc", "evdev/event_device_info.cc",
"evdev/event_device_info.h", "evdev/event_device_info.h",
"evdev/event_dispatch_callback.cc",
"evdev/event_dispatch_callback.h",
"evdev/event_factory_evdev.cc", "evdev/event_factory_evdev.cc",
"evdev/event_factory_evdev.h", "evdev/event_factory_evdev.h",
"evdev/event_modifiers_evdev.cc", "evdev/event_modifiers_evdev.cc",
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/events/ozone/evdev/event_dispatch_callback.h"
namespace ui {
TouchEventParams::TouchEventParams(int device_id,
int touch_id,
EventType type,
const gfx::PointF& location,
const gfx::Vector2dF& radii,
float pressure,
const base::TimeDelta& timestamp)
: device_id(device_id),
touch_id(touch_id),
type(type),
location(location),
radii(radii),
pressure(pressure),
timestamp(timestamp) {
}
TouchEventParams::TouchEventParams(const TouchEventParams& other) = default;
TouchEventParams::~TouchEventParams() {
}
} // namspace ui
...@@ -6,6 +6,20 @@ ...@@ -6,6 +6,20 @@
#define UI_EVENTS_OZONE_EVDEV_EVENT_DISPATCH_CALLBACK_H_ #define UI_EVENTS_OZONE_EVDEV_EVENT_DISPATCH_CALLBACK_H_
#include "base/callback.h" #include "base/callback.h"
#include "base/time/time.h"
#include "ui/events/event_constants.h"
#include "ui/events/ozone/evdev/events_ozone_evdev_export.h"
#include "ui/gfx/geometry/point_f.h"
#include "ui/gfx/geometry/vector2d_f.h"
namespace base {
class TimeDelta;
}
namespace gfx {
class PointF;
class Vector2dF;
}
namespace ui { namespace ui {
...@@ -13,6 +27,29 @@ class Event; ...@@ -13,6 +27,29 @@ class Event;
typedef base::Callback<void(scoped_ptr<Event>)> EventDispatchCallback; typedef base::Callback<void(scoped_ptr<Event>)> EventDispatchCallback;
struct EVENTS_OZONE_EVDEV_EXPORT TouchEventParams {
TouchEventParams(int device_id,
int touch_id,
EventType type,
const gfx::PointF& location,
const gfx::Vector2dF& radii,
float pressure,
const base::TimeDelta& timestamp);
TouchEventParams(const TouchEventParams& other);
~TouchEventParams();
int device_id;
int touch_id;
EventType type;
gfx::PointF location;
gfx::Vector2dF radii;
float pressure;
base::TimeDelta timestamp;
};
typedef base::Callback<void(const TouchEventParams& params)>
TouchEventDispatchCallback;
} // namspace ui } // namspace ui
#endif // UI_EVENTS_OZONE_EVDEV_EVENT_DISPATCH_CALLBACK_H_ #endif // UI_EVENTS_OZONE_EVDEV_EVENT_DISPATCH_CALLBACK_H_
...@@ -7,11 +7,13 @@ ...@@ -7,11 +7,13 @@
#include <fcntl.h> #include <fcntl.h>
#include <linux/input.h> #include <linux/input.h>
#include "base/bind.h"
#include "base/debug/trace_event.h" #include "base/debug/trace_event.h"
#include "base/stl_util.h" #include "base/stl_util.h"
#include "base/task_runner.h" #include "base/task_runner.h"
#include "base/thread_task_runner_handle.h" #include "base/thread_task_runner_handle.h"
#include "base/threading/worker_pool.h" #include "base/threading/worker_pool.h"
#include "base/time/time.h"
#include "ui/events/devices/device_data_manager.h" #include "ui/events/devices/device_data_manager.h"
#include "ui/events/devices/device_util_linux.h" #include "ui/events/devices/device_util_linux.h"
#include "ui/events/devices/input_device.h" #include "ui/events/devices/input_device.h"
...@@ -49,6 +51,7 @@ struct OpenInputDeviceParams { ...@@ -49,6 +51,7 @@ struct OpenInputDeviceParams {
// Callback for dispatching events. Call on UI thread only. // Callback for dispatching events. Call on UI thread only.
EventDispatchCallback dispatch_callback; EventDispatchCallback dispatch_callback;
TouchEventDispatchCallback touch_callback;
// State shared between devices. Must not be dereferenced on worker thread. // State shared between devices. Must not be dereferenced on worker thread.
EventModifiersEvdev* modifiers; EventModifiersEvdev* modifiers;
...@@ -94,7 +97,7 @@ scoped_ptr<EventConverterEvdev> CreateConverter( ...@@ -94,7 +97,7 @@ scoped_ptr<EventConverterEvdev> CreateConverter(
// Touchscreen: use TouchEventConverterEvdev. // Touchscreen: use TouchEventConverterEvdev.
if (devinfo.HasMTAbsXY()) { if (devinfo.HasMTAbsXY()) {
scoped_ptr<TouchEventConverterEvdev> converter(new TouchEventConverterEvdev( scoped_ptr<TouchEventConverterEvdev> converter(new TouchEventConverterEvdev(
fd, params.path, params.id, type, params.dispatch_callback)); fd, params.path, params.id, type, params.touch_callback));
converter->Initialize(devinfo); converter->Initialize(devinfo);
return converter.Pass(); return converter.Pass();
} }
...@@ -197,6 +200,28 @@ scoped_ptr<SystemInputInjector> EventFactoryEvdev::CreateSystemInputInjector() { ...@@ -197,6 +200,28 @@ scoped_ptr<SystemInputInjector> EventFactoryEvdev::CreateSystemInputInjector() {
&modifiers_, cursor_, &keyboard_, dispatch_callback_)); &modifiers_, cursor_, &keyboard_, dispatch_callback_));
} }
void EventFactoryEvdev::PostTouchEvent(const TouchEventParams& params) {
float x = params.location.x();
float y = params.location.y();
double radius_x = params.radii.x();
double radius_y = params.radii.y();
// Transform the event to align touches to the image based on display mode.
DeviceDataManager::GetInstance()->ApplyTouchTransformer(params.device_id, &x,
&y);
DeviceDataManager::GetInstance()->ApplyTouchRadiusScale(params.device_id,
&radius_x);
DeviceDataManager::GetInstance()->ApplyTouchRadiusScale(params.device_id,
&radius_y);
scoped_ptr<TouchEvent> touch_event(new TouchEvent(
params.type, gfx::PointF(x, y),
/* flags */ 0, params.touch_id, params.timestamp, radius_x, radius_y,
/* angle */ 0., params.pressure));
touch_event->set_source_device_id(params.device_id);
PostUiEvent(touch_event.Pass());
}
void EventFactoryEvdev::PostUiEvent(scoped_ptr<Event> event) { void EventFactoryEvdev::PostUiEvent(scoped_ptr<Event> event) {
base::ThreadTaskRunnerHandle::Get()->PostTask( base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, FROM_HERE,
...@@ -245,6 +270,10 @@ void EventFactoryEvdev::OnDeviceEvent(const DeviceEvent& event) { ...@@ -245,6 +270,10 @@ void EventFactoryEvdev::OnDeviceEvent(const DeviceEvent& event) {
params->button_map = &button_map_; params->button_map = &button_map_;
params->keyboard = &keyboard_; params->keyboard = &keyboard_;
params->cursor = cursor_; params->cursor = cursor_;
params->touch_callback = base::Bind(&EventFactoryEvdev::PostTouchEvent,
weak_ptr_factory_.GetWeakPtr());
#if defined(USE_EVDEV_GESTURES) #if defined(USE_EVDEV_GESTURES)
params->gesture_property_provider = gesture_property_provider_.get(); params->gesture_property_provider = gesture_property_provider_.get();
#endif #endif
......
...@@ -78,6 +78,9 @@ class EVENTS_OZONE_EVDEV_EXPORT EventFactoryEvdev : public DeviceEventObserver, ...@@ -78,6 +78,9 @@ class EVENTS_OZONE_EVDEV_EXPORT EventFactoryEvdev : public DeviceEventObserver,
InputController* input_controller() { return &input_controller_; } InputController* input_controller() { return &input_controller_; }
// Post a touch event to UI.
void PostTouchEvent(const TouchEventParams& params);
protected: protected:
// DeviceEventObserver overrides: // DeviceEventObserver overrides:
// //
......
...@@ -74,9 +74,9 @@ TouchEventConverterEvdev::TouchEventConverterEvdev( ...@@ -74,9 +74,9 @@ TouchEventConverterEvdev::TouchEventConverterEvdev(
base::FilePath path, base::FilePath path,
int id, int id,
InputDeviceType type, InputDeviceType type,
const EventDispatchCallback& callback) const TouchEventDispatchCallback& touch_callback)
: EventConverterEvdev(fd, path, id, type), : EventConverterEvdev(fd, path, id, type),
callback_(callback), touch_callback_(touch_callback),
syn_dropped_(false), syn_dropped_(false),
is_type_a_(false), is_type_a_(false),
current_slot_(0) { current_slot_(0) {
...@@ -270,35 +270,12 @@ void TouchEventConverterEvdev::ProcessSyn(const input_event& input) { ...@@ -270,35 +270,12 @@ void TouchEventConverterEvdev::ProcessSyn(const input_event& input) {
} }
void TouchEventConverterEvdev::ReportEvent(int touch_id, void TouchEventConverterEvdev::ReportEvent(int touch_id,
const InProgressEvents& event, const base::TimeDelta& delta) { const InProgressEvents& event,
float x = event.x_; const base::TimeDelta& timestamp) {
float y = event.y_; touch_callback_.Run(TouchEventParams(
id_, touch_id, event.type_, gfx::PointF(event.x_, event.y_),
double radius_x = event.radius_x_; gfx::Vector2dF(event.radius_x_, event.radius_y_), event.pressure_,
double radius_y = event.radius_y_; timestamp));
// Transform the event according (this is used to align touches
// to the image based on display mode).
DeviceDataManager::GetInstance()->ApplyTouchTransformer(
id_, &x, &y);
DeviceDataManager::GetInstance()->ApplyTouchRadiusScale(
id_, &radius_x);
DeviceDataManager::GetInstance()->ApplyTouchRadiusScale(
id_, &radius_y);
gfx::PointF location(x, y);
scoped_ptr<TouchEvent> touch_event(
new TouchEvent(event.type_, location,
/* flags */ 0,
/* touch_id */ touch_id,
delta,
/* radius_x */ radius_x,
/* radius_y */ radius_y,
/* angle */ 0.,
event.pressure_));
touch_event->set_source_device_id(id_);
callback_.Run(touch_event.Pass());
} }
void TouchEventConverterEvdev::ReportEvents(base::TimeDelta delta) { void TouchEventConverterEvdev::ReportEvents(base::TimeDelta delta) {
......
...@@ -29,7 +29,7 @@ class EVENTS_OZONE_EVDEV_EXPORT TouchEventConverterEvdev ...@@ -29,7 +29,7 @@ class EVENTS_OZONE_EVDEV_EXPORT TouchEventConverterEvdev
base::FilePath path, base::FilePath path,
int id, int id,
InputDeviceType type, InputDeviceType type,
const EventDispatchCallback& dispatch); const TouchEventDispatchCallback& touch_callback);
~TouchEventConverterEvdev() override; ~TouchEventConverterEvdev() override;
// EventConverterEvdev: // EventConverterEvdev:
...@@ -70,7 +70,7 @@ class EVENTS_OZONE_EVDEV_EXPORT TouchEventConverterEvdev ...@@ -70,7 +70,7 @@ class EVENTS_OZONE_EVDEV_EXPORT TouchEventConverterEvdev
void ReportEvents(base::TimeDelta delta); void ReportEvents(base::TimeDelta delta);
// Callback for dispatching events. // Callback for dispatching events.
EventDispatchCallback callback_; TouchEventDispatchCallback touch_callback_;
// Set if we have seen a SYN_DROPPED and not yet re-synced with the device. // Set if we have seen a SYN_DROPPED and not yet re-synced with the device.
bool syn_dropped_; bool syn_dropped_;
......
...@@ -81,6 +81,8 @@ ...@@ -81,6 +81,8 @@
'evdev/event_converter_evdev_impl.h', 'evdev/event_converter_evdev_impl.h',
'evdev/event_device_info.cc', 'evdev/event_device_info.cc',
'evdev/event_device_info.h', 'evdev/event_device_info.h',
'evdev/event_dispatch_callback.cc',
'evdev/event_dispatch_callback.h',
'evdev/event_factory_evdev.cc', 'evdev/event_factory_evdev.cc',
'evdev/event_factory_evdev.h', 'evdev/event_factory_evdev.h',
'evdev/event_modifiers_evdev.cc', 'evdev/event_modifiers_evdev.cc',
......
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