Commit 5957ed65 authored by spang's avatar spang Committed by Commit bot

ozone: evdev: Factor device I/O out of EventFactoryOzone

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

This splits EventFactoryOzone into two parts: EventFactoryOzone and
InputDeviceFactoryOzone. The new InputDeviceFactoryOzone class is now the
device I/O-centric part, and is intended to exist on a low-latency thread.

Hotplug events still originate on the UI thread, but this is not a
problem because hotplug is not latency critical. We're sharing udev
with the display code, so its easiest leave that code alone for now.

This doesn't add a new thread yet. Everything still runs on the UI thread.

BUG=449710
TEST=boot link_freon & move mouse

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

Cr-Commit-Position: refs/heads/master@{#313629}
parent b138032e
......@@ -77,6 +77,8 @@ component("events_ozone_evdev") {
"evdev/events_ozone_evdev_export.h",
"evdev/input_controller_evdev.cc",
"evdev/input_controller_evdev.h",
"evdev/input_device_factory_evdev.cc",
"evdev/input_device_factory_evdev.h",
"evdev/input_injector_evdev.cc",
"evdev/input_injector_evdev.h",
"evdev/keyboard_evdev.cc",
......
......@@ -5,9 +5,6 @@
#ifndef UI_EVENTS_OZONE_EVDEV_EVENT_FACTORY_EVDEV_H_
#define UI_EVENTS_OZONE_EVDEV_EVENT_FACTORY_EVDEV_H_
#include <set>
#include <vector>
#include "base/callback.h"
#include "base/compiler_specific.h"
#include "base/files/file_path.h"
......@@ -15,8 +12,6 @@
#include "base/task_runner.h"
#include "ui/events/ozone/device/device_event_observer.h"
#include "ui/events/ozone/evdev/device_event_dispatcher_evdev.h"
#include "ui/events/ozone/evdev/event_converter_evdev.h"
#include "ui/events/ozone/evdev/event_device_info.h"
#include "ui/events/ozone/evdev/event_modifiers_evdev.h"
#include "ui/events/ozone/evdev/events_ozone_evdev_export.h"
#include "ui/events/ozone/evdev/input_controller_evdev.h"
......@@ -34,6 +29,7 @@ namespace ui {
class CursorDelegateEvdev;
class DeviceManager;
class InputDeviceFactoryEvdev;
class SystemInputInjector;
enum class DomCode;
......@@ -41,10 +37,6 @@ enum class DomCode;
#error Missing dependency on ui/events/ozone:events_ozone_evdev
#endif
#if defined(USE_EVDEV_GESTURES)
class GesturePropertyProvider;
#endif
// Ozone events implementation for the Linux input subsystem ("evdev").
class EVENTS_OZONE_EVDEV_EXPORT EventFactoryEvdev
: public DeviceEventObserver,
......@@ -59,27 +51,9 @@ class EVENTS_OZONE_EVDEV_EXPORT EventFactoryEvdev
// Initialize. Must be called with a valid message loop.
void Init();
// Get a list of device ids that matches a device type. Return true if the
// list is not empty. |device_ids| can be NULL.
bool GetDeviceIdsByType(const EventDeviceType type,
std::vector<int>* device_ids);
void WarpCursorTo(gfx::AcceleratedWidget widget,
const gfx::PointF& location);
// Disables the internal touchpad.
void DisableInternalTouchpad();
// Enables the internal touchpad.
void EnableInternalTouchpad();
// Disables all keys on the internal keyboard except |excepted_keys|.
void DisableInternalKeyboardExceptKeys(
scoped_ptr<std::set<DomCode>> excepted_keys);
// Enables all keys on the internal keyboard.
void EnableInternalKeyboard();
scoped_ptr<SystemInputInjector> CreateSystemInputInjector();
InputController* input_controller() { return &input_controller_; }
......@@ -108,30 +82,16 @@ class EVENTS_OZONE_EVDEV_EXPORT EventFactoryEvdev
// Dispatch event via PlatformEventSource.
void DispatchUiEventTask(scoped_ptr<Event> event);
// Open device at path & starting processing events (on UI thread).
void AttachInputDevice(scoped_ptr<EventConverterEvdev> converter);
// Close device at path (on UI thread).
void DetachInputDevice(const base::FilePath& file_path);
// Update observers on device changes.
void NotifyDeviceChange(const EventConverterEvdev& converter);
void NotifyKeyboardsUpdated();
void NotifyTouchscreensUpdated();
int NextDeviceId();
// Owned per-device event converters (by path).
std::map<base::FilePath, EventConverterEvdev*> converters_;
// Used to uniquely identify input devices.
int last_device_id_;
// Interface for scanning & monitoring input devices.
DeviceManager* device_manager_; // Not owned.
// Task runner for event dispatch.
scoped_refptr<base::TaskRunner> ui_task_runner_;
// Factory for per-device objects.
scoped_ptr<InputDeviceFactoryEvdev> input_device_factory_;
// Dispatch callback for events.
EventDispatchCallback dispatch_callback_;
......
......@@ -11,7 +11,8 @@
#include "base/bind.h"
#include "base/strings/stringprintf.h"
#include "base/thread_task_runner_handle.h"
#include "ui/events/ozone/evdev/event_factory_evdev.h"
#include "ui/events/ozone/evdev/input_device_factory_evdev.h"
#include "ui/events/ozone/evdev/keyboard_evdev.h"
#include "ui/events/ozone/evdev/mouse_button_map_evdev.h"
#if defined(USE_EVDEV_GESTURES)
......@@ -84,7 +85,7 @@ std::string DumpGesturePropertyValue(GesturesProp* property) {
}
// Dump touch device property values to a string.
void DumpTouchDeviceStatus(EventFactoryEvdev* event_factory,
void DumpTouchDeviceStatus(InputDeviceFactoryEvdev* event_factory,
GesturePropertyProvider* provider,
std::string* status) {
// We use DT_ALL since we want gesture property values for all devices that
......@@ -117,7 +118,6 @@ void DumpTouchDeviceStatus(EventFactoryEvdev* event_factory,
} // namespace
InputControllerEvdev::InputControllerEvdev(
EventFactoryEvdev* event_factory,
KeyboardEvdev* keyboard,
MouseButtonMapEvdev* button_map
#if defined(USE_EVDEV_GESTURES)
......@@ -125,7 +125,7 @@ InputControllerEvdev::InputControllerEvdev(
GesturePropertyProvider* gesture_property_provider
#endif
)
: event_factory_(event_factory),
: input_device_factory_(nullptr),
keyboard_(keyboard),
button_map_(button_map)
#if defined(USE_EVDEV_GESTURES)
......@@ -138,12 +138,21 @@ InputControllerEvdev::InputControllerEvdev(
InputControllerEvdev::~InputControllerEvdev() {
}
void InputControllerEvdev::SetInputDeviceFactory(
InputDeviceFactoryEvdev* input_device_factory) {
input_device_factory_ = input_device_factory;
}
bool InputControllerEvdev::HasMouse() {
return event_factory_->GetDeviceIdsByType(DT_MOUSE, NULL);
if (!input_device_factory_)
return false;
return input_device_factory_->GetDeviceIdsByType(DT_MOUSE, NULL);
}
bool InputControllerEvdev::HasTouchpad() {
return event_factory_->GetDeviceIdsByType(DT_TOUCHPAD, NULL);
if (!input_device_factory_)
return false;
return input_device_factory_->GetDeviceIdsByType(DT_TOUCHPAD, NULL);
}
bool InputControllerEvdev::IsCapsLockEnabled() {
......@@ -177,28 +186,36 @@ void InputControllerEvdev::GetAutoRepeatRate(base::TimeDelta* delay,
}
void InputControllerEvdev::DisableInternalTouchpad() {
event_factory_->DisableInternalTouchpad();
if (input_device_factory_)
input_device_factory_->DisableInternalTouchpad();
}
void InputControllerEvdev::EnableInternalTouchpad() {
event_factory_->EnableInternalTouchpad();
if (input_device_factory_)
input_device_factory_->EnableInternalTouchpad();
}
void InputControllerEvdev::DisableInternalKeyboardExceptKeys(
scoped_ptr<std::set<DomCode>> excepted_keys) {
event_factory_->DisableInternalKeyboardExceptKeys(excepted_keys.Pass());
if (input_device_factory_) {
input_device_factory_->DisableInternalKeyboardExceptKeys(
excepted_keys.Pass());
}
}
void InputControllerEvdev::EnableInternalKeyboard() {
event_factory_->EnableInternalKeyboard();
if (input_device_factory_)
input_device_factory_->EnableInternalKeyboard();
}
void InputControllerEvdev::SetIntPropertyForOneType(const EventDeviceType type,
const std::string& name,
int value) {
if (!input_device_factory_)
return;
#if defined(USE_EVDEV_GESTURES)
std::vector<int> ids;
event_factory_->GetDeviceIdsByType(type, &ids);
input_device_factory_->GetDeviceIdsByType(type, &ids);
for (size_t i = 0; i < ids.size(); ++i) {
SetGestureIntProperty(gesture_property_provider_, ids[i], name, value);
}
......@@ -211,9 +228,11 @@ void InputControllerEvdev::SetIntPropertyForOneType(const EventDeviceType type,
void InputControllerEvdev::SetBoolPropertyForOneType(const EventDeviceType type,
const std::string& name,
bool value) {
if (!input_device_factory_)
return;
#if defined(USE_EVDEV_GESTURES)
std::vector<int> ids;
event_factory_->GetDeviceIdsByType(type, &ids);
input_device_factory_->GetDeviceIdsByType(type, &ids);
for (size_t i = 0; i < ids.size(); ++i) {
SetGestureBoolProperty(gesture_property_provider_, ids[i], name, value);
}
......@@ -262,7 +281,7 @@ void InputControllerEvdev::GetTouchDeviceStatus(
#if defined(USE_EVDEV_GESTURES)
std::string* status_ptr = status.get();
base::ThreadTaskRunnerHandle::Get()->PostTaskAndReply(
FROM_HERE, base::Bind(&DumpTouchDeviceStatus, event_factory_,
FROM_HERE, base::Bind(&DumpTouchDeviceStatus, input_device_factory_,
gesture_property_provider_, status_ptr),
base::Bind(reply, base::Passed(&status)));
#else
......
......@@ -14,7 +14,7 @@
namespace ui {
class EventFactoryEvdev;
class InputDeviceFactoryEvdev;
class KeyboardEvdev;
class MouseButtonMapEvdev;
......@@ -25,8 +25,7 @@ class GesturePropertyProvider;
// Ozone InputController implementation for the Linux input subsystem ("evdev").
class EVENTS_OZONE_EVDEV_EXPORT InputControllerEvdev : public InputController {
public:
InputControllerEvdev(EventFactoryEvdev* event_factory,
KeyboardEvdev* keyboard,
InputControllerEvdev(KeyboardEvdev* keyboard,
MouseButtonMapEvdev* button_map
#if defined(USE_EVDEV_GESTURES)
,
......@@ -35,6 +34,10 @@ class EVENTS_OZONE_EVDEV_EXPORT InputControllerEvdev : public InputController {
);
~InputControllerEvdev() override;
// Initialize device factory. This would be in the constructor if it was
// built early enough for that to be possible.
void SetInputDeviceFactory(InputDeviceFactoryEvdev* input_device_factory);
// InputController:
bool HasMouse() override;
bool HasTouchpad() override;
......@@ -71,8 +74,8 @@ class EVENTS_OZONE_EVDEV_EXPORT InputControllerEvdev : public InputController {
const std::string& name,
bool value);
// Event factory object which manages device event converters.
EventFactoryEvdev* event_factory_;
// Factory for devices. Needed to update device config.
InputDeviceFactoryEvdev* input_device_factory_;
// Keyboard state.
KeyboardEvdev* keyboard_;
......
This diff is collapsed.
// 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.
#ifndef UI_EVENTS_OZONE_EVDEV_INPUT_DEVICE_FACTORY_EVDEV_H_
#define UI_EVENTS_OZONE_EVDEV_INPUT_DEVICE_FACTORY_EVDEV_H_
#include <map>
#include <set>
#include <vector>
#include "base/callback.h"
#include "base/compiler_specific.h"
#include "base/files/file_path.h"
#include "base/memory/ref_counted.h"
#include "base/task_runner.h"
#include "ui/events/ozone/evdev/event_converter_evdev.h"
#include "ui/events/ozone/evdev/event_device_info.h"
#include "ui/events/ozone/evdev/events_ozone_evdev_export.h"
namespace ui {
class CursorDelegateEvdev;
class DeviceEventDispatcherEvdev;
#if !defined(USE_EVDEV)
#error Missing dependency on ui/events/ozone:events_ozone_evdev
#endif
#if defined(USE_EVDEV_GESTURES)
class GesturePropertyProvider;
#endif
// Manager for event device objects. All device I/O starts here.
class EVENTS_OZONE_EVDEV_EXPORT InputDeviceFactoryEvdev {
public:
InputDeviceFactoryEvdev(
DeviceEventDispatcherEvdev* dispatcher,
scoped_refptr<base::SingleThreadTaskRunner> dispatch_runner,
#if defined(USE_EVDEV_GESTURES)
GesturePropertyProvider* gesture_property_provider_,
#endif
CursorDelegateEvdev* cursor);
~InputDeviceFactoryEvdev();
// Open & start reading a newly plugged-in input device.
void AddInputDevice(int id, const base::FilePath& path);
// Stop reading & close an unplugged input device.
void RemoveInputDevice(const base::FilePath& path);
// Get a list of device ids that matches a device type. Return true if the
// list is not empty. |device_ids| can be NULL.
bool GetDeviceIdsByType(const EventDeviceType type,
std::vector<int>* device_ids);
// Disables the internal touchpad.
void DisableInternalTouchpad();
// Enables the internal touchpad.
void EnableInternalTouchpad();
// Disables all keys on the internal keyboard except |excepted_keys|.
void DisableInternalKeyboardExceptKeys(
scoped_ptr<std::set<DomCode>> excepted_keys);
// Enables all keys on the internal keyboard.
void EnableInternalKeyboard();
private:
// Open device at path & starting processing events (on UI thread).
void AttachInputDevice(scoped_ptr<EventConverterEvdev> converter);
// Close device at path (on UI thread).
void DetachInputDevice(const base::FilePath& file_path);
// Update observers on device changes.
void NotifyDeviceChange(const EventConverterEvdev& converter);
void NotifyKeyboardsUpdated();
void NotifyTouchscreensUpdated();
// Owned per-device event converters (by path).
std::map<base::FilePath, EventConverterEvdev*> converters_;
// Task runner for event dispatch.
scoped_refptr<base::TaskRunner> ui_task_runner_;
// Cursor movement.
CursorDelegateEvdev* cursor_;
#if defined(USE_EVDEV_GESTURES)
// Gesture library property provider (used by touchpads/mice).
GesturePropertyProvider* gesture_property_provider_;
#endif
// Dispatcher for events.
DeviceEventDispatcherEvdev* dispatcher_;
// Support weak pointers for attach & detach callbacks.
base::WeakPtrFactory<InputDeviceFactoryEvdev> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(InputDeviceFactoryEvdev);
};
} // namespace ui
#endif // UI_EVENTS_OZONE_EVDEV_INPUT_DEVICE_FACTORY_EVDEV_H_
......@@ -90,6 +90,8 @@
'evdev/events_ozone_evdev_export.h',
'evdev/input_controller_evdev.cc',
'evdev/input_controller_evdev.h',
'evdev/input_device_factory_evdev.cc',
'evdev/input_device_factory_evdev.h',
'evdev/input_injector_evdev.cc',
'evdev/input_injector_evdev.h',
'evdev/keyboard_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