Commit 6a0ddb22 authored by dnicoara's avatar dnicoara Committed by Commit bot

[Ozone-Evdev] Propagate touchscreen device information to DeviceDataManager

Propagate touchscreen information so that Ash can map touchscreens to displays.

BUG=none
NOTRY=true

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

Cr-Commit-Position: refs/heads/master@{#297823}
parent 0bfdfae4
...@@ -10,8 +10,10 @@ ...@@ -10,8 +10,10 @@
namespace ui { namespace ui {
EventConverterEvdev::EventConverterEvdev(int fd, const base::FilePath& path) EventConverterEvdev::EventConverterEvdev(int fd,
: fd_(fd), path_(path) { const base::FilePath& path,
int id)
: fd_(fd), path_(path), id_(id) {
} }
EventConverterEvdev::~EventConverterEvdev() { EventConverterEvdev::~EventConverterEvdev() {
...@@ -31,4 +33,13 @@ void EventConverterEvdev::OnFileCanWriteWithoutBlocking(int fd) { ...@@ -31,4 +33,13 @@ void EventConverterEvdev::OnFileCanWriteWithoutBlocking(int fd) {
NOTREACHED(); NOTREACHED();
} }
bool EventConverterEvdev::HasTouchscreen() const {
return false;
}
gfx::Size EventConverterEvdev::GetTouchscreenSize() const {
NOTREACHED();
return gfx::Size();
}
} // namespace ui } // namespace ui
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/message_loop/message_loop.h" #include "base/message_loop/message_loop.h"
#include "ui/events/ozone/evdev/events_ozone_evdev_export.h" #include "ui/events/ozone/evdev/events_ozone_evdev_export.h"
#include "ui/gfx/geometry/size.h"
namespace ui { namespace ui {
...@@ -19,15 +20,24 @@ typedef base::Callback<void(Event*)> EventDispatchCallback; ...@@ -19,15 +20,24 @@ typedef base::Callback<void(Event*)> EventDispatchCallback;
class EVENTS_OZONE_EVDEV_EXPORT EventConverterEvdev class EVENTS_OZONE_EVDEV_EXPORT EventConverterEvdev
: public base::MessagePumpLibevent::Watcher { : public base::MessagePumpLibevent::Watcher {
public: public:
EventConverterEvdev(int fd, const base::FilePath& path); EventConverterEvdev(int fd, const base::FilePath& path, int id);
virtual ~EventConverterEvdev(); virtual ~EventConverterEvdev();
int id() const { return id_; }
// Start reading events. // Start reading events.
void Start(); void Start();
// Stop reading events. // Stop reading events.
void Stop(); void Stop();
// Returns true of the converter is used for a touchscreen device.
virtual bool HasTouchscreen() const;
// Returns the size of the touchscreen device if the converter is used for a
// touchscreen device.
virtual gfx::Size GetTouchscreenSize() const;
protected: protected:
// base::MessagePumpLibevent::Watcher: // base::MessagePumpLibevent::Watcher:
virtual void OnFileCanWriteWithoutBlocking(int fd) OVERRIDE; virtual void OnFileCanWriteWithoutBlocking(int fd) OVERRIDE;
...@@ -38,6 +48,9 @@ class EVENTS_OZONE_EVDEV_EXPORT EventConverterEvdev ...@@ -38,6 +48,9 @@ class EVENTS_OZONE_EVDEV_EXPORT EventConverterEvdev
// Path to input device. // Path to input device.
base::FilePath path_; base::FilePath path_;
// Uniquely identifies an event converter.
int id_;
// Controller for watching the input fd. // Controller for watching the input fd.
base::MessagePumpLibevent::FileDescriptorWatcher controller_; base::MessagePumpLibevent::FileDescriptorWatcher controller_;
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#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 "ui/events/device_data_manager.h"
#include "ui/events/ozone/device/device_event.h" #include "ui/events/ozone/device/device_event.h"
#include "ui/events/ozone/device/device_manager.h" #include "ui/events/ozone/device/device_manager.h"
#include "ui/events/ozone/evdev/cursor_delegate_evdev.h" #include "ui/events/ozone/evdev/cursor_delegate_evdev.h"
...@@ -47,6 +48,7 @@ bool UseGesturesLibraryForDevice(const EventDeviceInfo& devinfo) { ...@@ -47,6 +48,7 @@ bool UseGesturesLibraryForDevice(const EventDeviceInfo& devinfo) {
scoped_ptr<EventConverterEvdev> CreateConverter( scoped_ptr<EventConverterEvdev> CreateConverter(
int fd, int fd,
const base::FilePath& path, const base::FilePath& path,
int id,
const EventDeviceInfo& devinfo, const EventDeviceInfo& devinfo,
const EventDispatchCallback& dispatch, const EventDispatchCallback& dispatch,
EventModifiersEvdev* modifiers, EventModifiersEvdev* modifiers,
...@@ -61,6 +63,7 @@ scoped_ptr<EventConverterEvdev> CreateConverter( ...@@ -61,6 +63,7 @@ scoped_ptr<EventConverterEvdev> CreateConverter(
make_scoped_ptr(new EventReaderLibevdevCros( make_scoped_ptr(new EventReaderLibevdevCros(
fd, fd,
path, path,
id,
gesture_interp.PassAs<EventReaderLibevdevCros::Delegate>())); gesture_interp.PassAs<EventReaderLibevdevCros::Delegate>()));
return libevdev_reader.PassAs<EventConverterEvdev>(); return libevdev_reader.PassAs<EventConverterEvdev>();
} }
...@@ -70,11 +73,11 @@ scoped_ptr<EventConverterEvdev> CreateConverter( ...@@ -70,11 +73,11 @@ scoped_ptr<EventConverterEvdev> CreateConverter(
scoped_ptr<EventConverterEvdev> converter; scoped_ptr<EventConverterEvdev> converter;
if (devinfo.HasAbsXY()) if (devinfo.HasAbsXY())
return make_scoped_ptr<EventConverterEvdev>( return make_scoped_ptr<EventConverterEvdev>(
new TouchEventConverterEvdev(fd, path, devinfo, dispatch)); new TouchEventConverterEvdev(fd, path, id, devinfo, dispatch));
// Everything else: use KeyEventConverterEvdev. // Everything else: use KeyEventConverterEvdev.
return make_scoped_ptr<EventConverterEvdev>( return make_scoped_ptr<EventConverterEvdev>(
new KeyEventConverterEvdev(fd, path, modifiers, dispatch)); new KeyEventConverterEvdev(fd, path, id, modifiers, dispatch));
} }
// Open an input device. Opening may put the calling thread to sleep, and // Open an input device. Opening may put the calling thread to sleep, and
...@@ -87,6 +90,7 @@ void OpenInputDevice( ...@@ -87,6 +90,7 @@ void OpenInputDevice(
const base::FilePath& path, const base::FilePath& path,
EventModifiersEvdev* modifiers, EventModifiersEvdev* modifiers,
CursorDelegateEvdev* cursor, CursorDelegateEvdev* cursor,
int device_id,
scoped_refptr<base::TaskRunner> reply_runner, scoped_refptr<base::TaskRunner> reply_runner,
const EventDispatchCallback& dispatch, const EventDispatchCallback& dispatch,
base::Callback<void(scoped_ptr<EventConverterEvdev>)> reply_callback) { base::Callback<void(scoped_ptr<EventConverterEvdev>)> reply_callback) {
...@@ -112,8 +116,8 @@ void OpenInputDevice( ...@@ -112,8 +116,8 @@ void OpenInputDevice(
return; return;
} }
scoped_ptr<EventConverterEvdev> converter = scoped_ptr<EventConverterEvdev> converter = CreateConverter(
CreateConverter(fd, path, devinfo, dispatch, modifiers, cursor); fd, path, device_id, devinfo, dispatch, modifiers, cursor);
// Reply with the constructed converter. // Reply with the constructed converter.
reply_runner->PostTask(FROM_HERE, reply_runner->PostTask(FROM_HERE,
...@@ -131,10 +135,10 @@ void CloseInputDevice(const base::FilePath& path, ...@@ -131,10 +135,10 @@ void CloseInputDevice(const base::FilePath& path,
} // namespace } // namespace
EventFactoryEvdev::EventFactoryEvdev( EventFactoryEvdev::EventFactoryEvdev(CursorDelegateEvdev* cursor,
CursorDelegateEvdev* cursor, DeviceManager* device_manager)
DeviceManager* device_manager) : last_device_id_(0),
: device_manager_(device_manager), device_manager_(device_manager),
cursor_(cursor), cursor_(cursor),
dispatch_callback_( dispatch_callback_(
base::Bind(base::IgnoreResult(&EventFactoryEvdev::DispatchUiEvent), base::Bind(base::IgnoreResult(&EventFactoryEvdev::DispatchUiEvent),
...@@ -163,6 +167,8 @@ void EventFactoryEvdev::AttachInputDevice( ...@@ -163,6 +167,8 @@ void EventFactoryEvdev::AttachInputDevice(
// Add initialized device to map. // Add initialized device to map.
converters_[path] = converter.release(); converters_[path] = converter.release();
converters_[path]->Start(); converters_[path]->Start();
NotifyHotplugEventObserver(*converters_[path]);
} }
void EventFactoryEvdev::OnDeviceEvent(const DeviceEvent& event) { void EventFactoryEvdev::OnDeviceEvent(const DeviceEvent& event) {
...@@ -181,6 +187,7 @@ void EventFactoryEvdev::OnDeviceEvent(const DeviceEvent& event) { ...@@ -181,6 +187,7 @@ void EventFactoryEvdev::OnDeviceEvent(const DeviceEvent& event) {
event.path(), event.path(),
&modifiers_, &modifiers_,
cursor_, cursor_,
NextDeviceId(),
ui_task_runner_, ui_task_runner_,
dispatch_callback_, dispatch_callback_,
base::Bind(&EventFactoryEvdev::AttachInputDevice, base::Bind(&EventFactoryEvdev::AttachInputDevice,
...@@ -219,6 +226,8 @@ void EventFactoryEvdev::DetachInputDevice(const base::FilePath& path) { ...@@ -219,6 +226,8 @@ void EventFactoryEvdev::DetachInputDevice(const base::FilePath& path) {
// on UI since the polling happens on UI. // on UI since the polling happens on UI.
converter->Stop(); converter->Stop();
NotifyHotplugEventObserver(*converter);
// Dispatch task to close from the worker pool, since close may block. // Dispatch task to close from the worker pool, since close may block.
base::WorkerPool::PostTask( base::WorkerPool::PostTask(
FROM_HERE, FROM_HERE,
...@@ -240,4 +249,28 @@ void EventFactoryEvdev::WarpCursorTo(gfx::AcceleratedWidget widget, ...@@ -240,4 +249,28 @@ void EventFactoryEvdev::WarpCursorTo(gfx::AcceleratedWidget widget,
} }
} }
void EventFactoryEvdev::NotifyHotplugEventObserver(
const EventConverterEvdev& converter) {
// For now the only information propagated is related to touchscreens. Ignore
// events for everything but touchscreens.
if (!converter.HasTouchscreen())
return;
DeviceHotplugEventObserver* observer = DeviceDataManager::GetInstance();
std::vector<TouchscreenDevice> touchscreens;
for (auto it = converters_.begin(); it != converters_.end(); ++it) {
if (it->second->HasTouchscreen()) {
touchscreens.push_back(TouchscreenDevice(it->second->id(),
it->second->GetTouchscreenSize(),
false /* is_internal */));
}
}
observer->OnTouchscreenDevicesUpdated(touchscreens);
}
int EventFactoryEvdev::NextDeviceId() {
return ++last_device_id_;
}
} // namespace ui } // namespace ui
...@@ -47,6 +47,10 @@ class EVENTS_OZONE_EVDEV_EXPORT EventFactoryEvdev : public DeviceEventObserver, ...@@ -47,6 +47,10 @@ class EVENTS_OZONE_EVDEV_EXPORT EventFactoryEvdev : public DeviceEventObserver,
// Close device at path (on UI thread). // Close device at path (on UI thread).
void DetachInputDevice(const base::FilePath& file_path); void DetachInputDevice(const base::FilePath& file_path);
void NotifyHotplugEventObserver(const EventConverterEvdev& converter);
int NextDeviceId();
// DeviceEventObserver overrides: // DeviceEventObserver overrides:
// //
// Callback for device add (on UI thread). // Callback for device add (on UI thread).
...@@ -58,6 +62,9 @@ class EVENTS_OZONE_EVDEV_EXPORT EventFactoryEvdev : public DeviceEventObserver, ...@@ -58,6 +62,9 @@ class EVENTS_OZONE_EVDEV_EXPORT EventFactoryEvdev : public DeviceEventObserver,
// Owned per-device event converters (by path). // Owned per-device event converters (by path).
std::map<base::FilePath, EventConverterEvdev*> converters_; std::map<base::FilePath, EventConverterEvdev*> converters_;
// Used to uniquely identify input devices.
int last_device_id_;
// Interface for scanning & monitoring input devices. // Interface for scanning & monitoring input devices.
DeviceManager* device_manager_; // Not owned. DeviceManager* device_manager_; // Not owned.
......
...@@ -192,9 +192,10 @@ bool IsLockButton(unsigned int code) { return code == KEY_CAPSLOCK; } ...@@ -192,9 +192,10 @@ bool IsLockButton(unsigned int code) { return code == KEY_CAPSLOCK; }
KeyEventConverterEvdev::KeyEventConverterEvdev( KeyEventConverterEvdev::KeyEventConverterEvdev(
int fd, int fd,
base::FilePath path, base::FilePath path,
int id,
EventModifiersEvdev* modifiers, EventModifiersEvdev* modifiers,
const EventDispatchCallback& callback) const EventDispatchCallback& callback)
: EventConverterEvdev(fd, path), : EventConverterEvdev(fd, path, id),
callback_(callback), callback_(callback),
modifiers_(modifiers) { modifiers_(modifiers) {
// TODO(spang): Initialize modifiers using EVIOCGKEY. // TODO(spang): Initialize modifiers using EVIOCGKEY.
......
...@@ -21,6 +21,7 @@ class EVENTS_OZONE_EVDEV_EXPORT KeyEventConverterEvdev ...@@ -21,6 +21,7 @@ class EVENTS_OZONE_EVDEV_EXPORT KeyEventConverterEvdev
public: public:
KeyEventConverterEvdev(int fd, KeyEventConverterEvdev(int fd,
base::FilePath path, base::FilePath path,
int id,
EventModifiersEvdev* modifiers, EventModifiersEvdev* modifiers,
const EventDispatchCallback& dispatch); const EventDispatchCallback& dispatch);
virtual ~KeyEventConverterEvdev(); virtual ~KeyEventConverterEvdev();
......
...@@ -23,6 +23,7 @@ class MockKeyEventConverterEvdev : public KeyEventConverterEvdev { ...@@ -23,6 +23,7 @@ class MockKeyEventConverterEvdev : public KeyEventConverterEvdev {
: KeyEventConverterEvdev( : KeyEventConverterEvdev(
fd, fd,
base::FilePath(kTestDevicePath), base::FilePath(kTestDevicePath),
1,
modifiers, modifiers,
base::Bind(&MockKeyEventConverterEvdev::DispatchEventForTest, base::Bind(&MockKeyEventConverterEvdev::DispatchEventForTest,
base::Unretained(this))) { base::Unretained(this))) {
......
...@@ -27,8 +27,9 @@ std::string FormatLog(const char* fmt, va_list args) { ...@@ -27,8 +27,9 @@ std::string FormatLog(const char* fmt, va_list args) {
EventReaderLibevdevCros::EventReaderLibevdevCros(int fd, EventReaderLibevdevCros::EventReaderLibevdevCros(int fd,
const base::FilePath& path, const base::FilePath& path,
int id,
scoped_ptr<Delegate> delegate) scoped_ptr<Delegate> delegate)
: EventConverterEvdev(fd, path), delegate_(delegate.Pass()) { : EventConverterEvdev(fd, path, id), delegate_(delegate.Pass()) {
memset(&evdev_, 0, sizeof(evdev_)); memset(&evdev_, 0, sizeof(evdev_));
evdev_.log = OnLogMessage; evdev_.log = OnLogMessage;
evdev_.log_udata = this; evdev_.log_udata = this;
......
...@@ -37,6 +37,7 @@ class EventReaderLibevdevCros : public EventConverterEvdev { ...@@ -37,6 +37,7 @@ class EventReaderLibevdevCros : public EventConverterEvdev {
EventReaderLibevdevCros(int fd, EventReaderLibevdevCros(int fd,
const base::FilePath& path, const base::FilePath& path,
int id,
scoped_ptr<Delegate> delegate); scoped_ptr<Delegate> delegate);
~EventReaderLibevdevCros(); ~EventReaderLibevdevCros();
......
...@@ -75,9 +75,10 @@ namespace ui { ...@@ -75,9 +75,10 @@ namespace ui {
TouchEventConverterEvdev::TouchEventConverterEvdev( TouchEventConverterEvdev::TouchEventConverterEvdev(
int fd, int fd,
base::FilePath path, base::FilePath path,
int id,
const EventDeviceInfo& info, const EventDeviceInfo& info,
const EventDispatchCallback& callback) const EventDispatchCallback& callback)
: EventConverterEvdev(fd, path), : EventConverterEvdev(fd, path, id),
callback_(callback), callback_(callback),
syn_dropped_(false), syn_dropped_(false),
is_type_a_(false), is_type_a_(false),
...@@ -91,22 +92,19 @@ TouchEventConverterEvdev::~TouchEventConverterEvdev() { ...@@ -91,22 +92,19 @@ TouchEventConverterEvdev::~TouchEventConverterEvdev() {
} }
void TouchEventConverterEvdev::Init(const EventDeviceInfo& info) { void TouchEventConverterEvdev::Init(const EventDeviceInfo& info) {
gfx::Screen *screen = gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_NATIVE); gfx::Screen* screen = gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_NATIVE);
if (!screen) if (!screen)
return; // No scaling. return; // No scaling.
gfx::Display display = screen->GetPrimaryDisplay(); gfx::Display display = screen->GetPrimaryDisplay();
gfx::Size size = display.GetSizeInPixel(); gfx::Size size = display.GetSizeInPixel();
pressure_min_ = info.GetAbsMinimum(ABS_MT_PRESSURE), pressure_min_ = info.GetAbsMinimum(ABS_MT_PRESSURE);
pressure_max_ = info.GetAbsMaximum(ABS_MT_PRESSURE), pressure_max_ = info.GetAbsMaximum(ABS_MT_PRESSURE);
x_min_tuxels_ = info.GetAbsMinimum(ABS_MT_POSITION_X), x_min_tuxels_ = info.GetAbsMinimum(ABS_MT_POSITION_X);
x_num_tuxels_ = info.GetAbsMaximum(ABS_MT_POSITION_X) - x_min_tuxels_ + 1, x_num_tuxels_ = info.GetAbsMaximum(ABS_MT_POSITION_X) - x_min_tuxels_ + 1;
y_min_tuxels_ = info.GetAbsMinimum(ABS_MT_POSITION_Y), y_min_tuxels_ = info.GetAbsMinimum(ABS_MT_POSITION_Y);
y_num_tuxels_ = info.GetAbsMaximum(ABS_MT_POSITION_Y) - y_min_tuxels_ + 1, y_num_tuxels_ = info.GetAbsMaximum(ABS_MT_POSITION_Y) - y_min_tuxels_ + 1;
x_min_pixels_ = x_min_tuxels_, native_size_ = gfx::Size(x_num_tuxels_, y_num_tuxels_);
x_num_pixels_ = x_num_tuxels_,
y_min_pixels_ = y_min_tuxels_,
y_num_pixels_ = y_num_tuxels_,
// Map coordinates onto screen. // Map coordinates onto screen.
x_min_pixels_ = 0; x_min_pixels_ = 0;
...@@ -142,6 +140,14 @@ bool TouchEventConverterEvdev::Reinitialize() { ...@@ -142,6 +140,14 @@ bool TouchEventConverterEvdev::Reinitialize() {
return false; return false;
} }
bool TouchEventConverterEvdev::HasTouchscreen() const {
return true;
}
gfx::Size TouchEventConverterEvdev::GetTouchscreenSize() const {
return native_size_;
}
void TouchEventConverterEvdev::OnFileCanReadWithoutBlocking(int fd) { void TouchEventConverterEvdev::OnFileCanReadWithoutBlocking(int fd) {
input_event inputs[MAX_FINGERS * 6 + 1]; input_event inputs[MAX_FINGERS * 6 + 1];
ssize_t read_size = read(fd, inputs, sizeof(inputs)); ssize_t read_size = read(fd, inputs, sizeof(inputs));
......
...@@ -27,10 +27,15 @@ class EVENTS_OZONE_EVDEV_EXPORT TouchEventConverterEvdev ...@@ -27,10 +27,15 @@ class EVENTS_OZONE_EVDEV_EXPORT TouchEventConverterEvdev
}; };
TouchEventConverterEvdev(int fd, TouchEventConverterEvdev(int fd,
base::FilePath path, base::FilePath path,
int id,
const EventDeviceInfo& info, const EventDeviceInfo& info,
const EventDispatchCallback& dispatch); const EventDispatchCallback& dispatch);
virtual ~TouchEventConverterEvdev(); virtual ~TouchEventConverterEvdev();
// EventConverterEvdev:
virtual bool HasTouchscreen() const OVERRIDE;
virtual gfx::Size GetTouchscreenSize() const OVERRIDE;
private: private:
friend class MockTouchEventConverterEvdev; friend class MockTouchEventConverterEvdev;
...@@ -77,6 +82,9 @@ class EVENTS_OZONE_EVDEV_EXPORT TouchEventConverterEvdev ...@@ -77,6 +82,9 @@ class EVENTS_OZONE_EVDEV_EXPORT TouchEventConverterEvdev
float y_min_pixels_; float y_min_pixels_;
float y_num_pixels_; float y_num_pixels_;
// Size of the touchscreen as reported by the driver.
gfx::Size native_size_;
// Touch point currently being updated from the /dev/input/event* stream. // Touch point currently being updated from the /dev/input/event* stream.
int current_slot_; int current_slot_;
......
...@@ -75,6 +75,7 @@ MockTouchEventConverterEvdev::MockTouchEventConverterEvdev(int fd, ...@@ -75,6 +75,7 @@ MockTouchEventConverterEvdev::MockTouchEventConverterEvdev(int fd,
: TouchEventConverterEvdev( : TouchEventConverterEvdev(
fd, fd,
path, path,
1,
EventDeviceInfo(), EventDeviceInfo(),
base::Bind(&MockTouchEventConverterEvdev::DispatchCallback, base::Bind(&MockTouchEventConverterEvdev::DispatchCallback,
base::Unretained(this))) { base::Unretained(this))) {
......
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