Skip to content

Commit

Permalink
ozone: evdev: Add a device factory proxy that forwards to device thread
Browse files Browse the repository at this point in the history
This is part of a series moving IO on evdev devices to a fast thread,
since UI thread is too slow for the cursor.

Make a new class InputDeviceFactoryProxyEvdev that wraps
InputDeviceFactoryEvdev and can be safely passed to another thread. When
the other thread calls to manipulate devices, we'll post to
InputDeviceFactoryEvdev on the device thread with the command.

BUG=449710
TEST=boot link_freon & move mouse

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

Cr-Commit-Position: refs/heads/master@{#313938}
  • Loading branch information
mspang authored and Commit bot committed Jan 30, 2015
1 parent af25550 commit da763e4
Show file tree
Hide file tree
Showing 10 changed files with 214 additions and 9 deletions.
4 changes: 3 additions & 1 deletion ui/events/ozone/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ component("events_ozone_evdev") {
"evdev/input_controller_evdev.cc",
"evdev/input_controller_evdev.h",
"evdev/input_device_factory_evdev.cc",
"evdev/input_device_factory_evdev.h",
"evdev/input_device_factory_evdev.cc",
"evdev/input_device_factory_evdev_proxy.h",
"evdev/input_device_factory_evdev_proxy.h",
"evdev/input_injector_evdev.cc",
"evdev/input_injector_evdev.h",
"evdev/keyboard_evdev.cc",
Expand Down
10 changes: 7 additions & 3 deletions ui/events/ozone/evdev/event_factory_evdev.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "ui/events/ozone/evdev/cursor_delegate_evdev.h"
#include "ui/events/ozone/evdev/input_controller_evdev.h"
#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"

namespace ui {
Expand Down Expand Up @@ -133,9 +134,12 @@ void EventFactoryEvdev::Init() {
weak_ptr_factory_.GetWeakPtr()));
input_device_factory_.reset(
new InputDeviceFactoryEvdev(dispatcher.Pass(), cursor_));
input_device_factory_proxy_.reset(
new InputDeviceFactoryEvdevProxy(base::ThreadTaskRunnerHandle::Get(),
input_device_factory_->GetWeakPtr()));

// TODO(spang): This settings interface is really broken. crbug.com/450899
input_controller_.SetInputDeviceFactory(input_device_factory_.get());
input_controller_.SetInputDeviceFactory(input_device_factory_proxy_.get());

// Scan & monitor devices.
device_manager_->AddObserver(this);
Expand Down Expand Up @@ -279,12 +283,12 @@ void EventFactoryEvdev::OnDeviceEvent(const DeviceEvent& event) {
case DeviceEvent::ADD:
case DeviceEvent::CHANGE: {
TRACE_EVENT1("ozone", "OnDeviceAdded", "path", event.path().value());
input_device_factory_->AddInputDevice(NextDeviceId(), event.path());
input_device_factory_proxy_->AddInputDevice(NextDeviceId(), event.path());
break;
}
case DeviceEvent::REMOVE: {
TRACE_EVENT1("ozone", "OnDeviceRemoved", "path", event.path().value());
input_device_factory_->RemoveInputDevice(event.path());
input_device_factory_proxy_->RemoveInputDevice(event.path());
break;
}
}
Expand Down
4 changes: 4 additions & 0 deletions ui/events/ozone/evdev/event_factory_evdev.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ namespace ui {
class CursorDelegateEvdev;
class DeviceManager;
class InputDeviceFactoryEvdev;
class InputDeviceFactoryEvdevProxy;
class SystemInputInjector;
enum class DomCode;

Expand Down Expand Up @@ -96,6 +97,9 @@ class EVENTS_OZONE_EVDEV_EXPORT EventFactoryEvdev : public DeviceEventObserver,
// Factory for per-device objects.
scoped_ptr<InputDeviceFactoryEvdev> input_device_factory_;

// Proxy for input device factory (manages device I/O objects).
scoped_ptr<InputDeviceFactoryEvdevProxy> input_device_factory_proxy_;

// Modifier key state (shift, ctrl, etc).
EventModifiersEvdev modifiers_;

Expand Down
4 changes: 2 additions & 2 deletions ui/events/ozone/evdev/input_controller_evdev.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <algorithm>
#include <linux/input.h>

#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/keyboard_evdev.h"
#include "ui/events/ozone/evdev/mouse_button_map_evdev.h"

Expand All @@ -26,7 +26,7 @@ InputControllerEvdev::~InputControllerEvdev() {
}

void InputControllerEvdev::SetInputDeviceFactory(
InputDeviceFactoryEvdev* input_device_factory) {
InputDeviceFactoryEvdevProxy* input_device_factory) {
input_device_factory_ = input_device_factory;
}

Expand Down
7 changes: 4 additions & 3 deletions ui/events/ozone/evdev/input_controller_evdev.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace ui {

class InputDeviceFactoryEvdev;
class InputDeviceFactoryEvdevProxy;
class KeyboardEvdev;
class MouseButtonMapEvdev;

Expand All @@ -26,7 +26,8 @@ class EVENTS_OZONE_EVDEV_EXPORT InputControllerEvdev : public InputController {

// 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);
void SetInputDeviceFactory(
InputDeviceFactoryEvdevProxy* input_device_factory);

void set_has_mouse(bool has_mouse);
void set_has_touchpad(bool has_touchpad);
Expand Down Expand Up @@ -60,7 +61,7 @@ class EVENTS_OZONE_EVDEV_EXPORT InputControllerEvdev : public InputController {

private:
// Factory for devices. Needed to update device config.
InputDeviceFactoryEvdev* input_device_factory_;
InputDeviceFactoryEvdevProxy* input_device_factory_;

// Keyboard state.
KeyboardEvdev* keyboard_;
Expand Down
4 changes: 4 additions & 0 deletions ui/events/ozone/evdev/input_device_factory_evdev.cc
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,10 @@ void InputDeviceFactoryEvdev::GetTouchDeviceStatus(
reply.Run(status.Pass());
}

base::WeakPtr<InputDeviceFactoryEvdev> InputDeviceFactoryEvdev::GetWeakPtr() {
return weak_ptr_factory_.GetWeakPtr();
}

void InputDeviceFactoryEvdev::NotifyDeviceChange(
const EventConverterEvdev& converter) {
if (converter.HasTouchscreen())
Expand Down
3 changes: 3 additions & 0 deletions ui/events/ozone/evdev/input_device_factory_evdev.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ namespace ui {

class CursorDelegateEvdev;
class DeviceEventDispatcherEvdev;
class InputDeviceFactoryEvdevProxy;

#if !defined(USE_EVDEV)
#error Missing dependency on ui/events/ozone:events_ozone_evdev
Expand Down Expand Up @@ -69,6 +70,8 @@ class EVENTS_OZONE_EVDEV_EXPORT InputDeviceFactoryEvdev {
void SetTapToClickPaused(bool state);
void GetTouchDeviceStatus(const GetTouchDeviceStatusReply& reply);

base::WeakPtr<InputDeviceFactoryEvdev> GetWeakPtr();

private:
// Open device at path & starting processing events (on UI thread).
void AttachInputDevice(scoped_ptr<EventConverterEvdev> converter);
Expand Down
126 changes: 126 additions & 0 deletions ui/events/ozone/evdev/input_device_factory_evdev_proxy.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
// Copyright 2015 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/input_device_factory_evdev_proxy.h"

#include "base/bind.h"
#include "base/thread_task_runner_handle.h"
#include "ui/events/ozone/evdev/input_device_factory_evdev.h"

namespace ui {

namespace {

void ForwardGetTouchDeviceStatusReply(
scoped_refptr<base::SingleThreadTaskRunner> reply_runner,
const GetTouchDeviceStatusReply& reply,
scoped_ptr<std::string> status) {
// Thread hop back to UI for reply.
reply_runner->PostTask(FROM_HERE, base::Bind(reply, base::Passed(&status)));
}

} // namespace

InputDeviceFactoryEvdevProxy::InputDeviceFactoryEvdevProxy(
scoped_refptr<base::SingleThreadTaskRunner> task_runner,
base::WeakPtr<InputDeviceFactoryEvdev> input_device_factory)
: task_runner_(task_runner), input_device_factory_(input_device_factory) {
}

InputDeviceFactoryEvdevProxy::~InputDeviceFactoryEvdevProxy() {
}

void InputDeviceFactoryEvdevProxy::AddInputDevice(int id,
const base::FilePath& path) {
task_runner_->PostTask(FROM_HERE,
base::Bind(&InputDeviceFactoryEvdev::AddInputDevice,
input_device_factory_, id, path));
}

void InputDeviceFactoryEvdevProxy::RemoveInputDevice(
const base::FilePath& path) {
task_runner_->PostTask(FROM_HERE,
base::Bind(&InputDeviceFactoryEvdev::RemoveInputDevice,
input_device_factory_, path));
}

void InputDeviceFactoryEvdevProxy::DisableInternalTouchpad() {
task_runner_->PostTask(
FROM_HERE, base::Bind(&InputDeviceFactoryEvdev::DisableInternalTouchpad,
input_device_factory_));
}

void InputDeviceFactoryEvdevProxy::EnableInternalTouchpad() {
task_runner_->PostTask(
FROM_HERE, base::Bind(&InputDeviceFactoryEvdev::EnableInternalTouchpad,
input_device_factory_));
}

void InputDeviceFactoryEvdevProxy::DisableInternalKeyboardExceptKeys(
scoped_ptr<std::set<DomCode>> excepted_keys) {
task_runner_->PostTask(
FROM_HERE,
base::Bind(&InputDeviceFactoryEvdev::DisableInternalKeyboardExceptKeys,
input_device_factory_, base::Passed(&excepted_keys)));
}

void InputDeviceFactoryEvdevProxy::EnableInternalKeyboard() {
task_runner_->PostTask(
FROM_HERE, base::Bind(&InputDeviceFactoryEvdev::EnableInternalKeyboard,
input_device_factory_));
}

void InputDeviceFactoryEvdevProxy::SetTouchpadSensitivity(int value) {
task_runner_->PostTask(
FROM_HERE, base::Bind(&InputDeviceFactoryEvdev::SetTouchpadSensitivity,
input_device_factory_, value));
}

void InputDeviceFactoryEvdevProxy::SetTapToClick(bool enabled) {
task_runner_->PostTask(FROM_HERE,
base::Bind(&InputDeviceFactoryEvdev::SetTapToClick,
input_device_factory_, enabled));
}

void InputDeviceFactoryEvdevProxy::SetThreeFingerClick(bool enabled) {
task_runner_->PostTask(
FROM_HERE, base::Bind(&InputDeviceFactoryEvdev::SetThreeFingerClick,
input_device_factory_, enabled));
}

void InputDeviceFactoryEvdevProxy::SetTapDragging(bool enabled) {
task_runner_->PostTask(FROM_HERE,
base::Bind(&InputDeviceFactoryEvdev::SetTapDragging,
input_device_factory_, enabled));
}

void InputDeviceFactoryEvdevProxy::SetNaturalScroll(bool enabled) {
task_runner_->PostTask(FROM_HERE,
base::Bind(&InputDeviceFactoryEvdev::SetNaturalScroll,
input_device_factory_, enabled));
}

void InputDeviceFactoryEvdevProxy::SetMouseSensitivity(int value) {
task_runner_->PostTask(
FROM_HERE, base::Bind(&InputDeviceFactoryEvdev::SetMouseSensitivity,
input_device_factory_, value));
}

void InputDeviceFactoryEvdevProxy::SetTapToClickPaused(bool state) {
task_runner_->PostTask(
FROM_HERE, base::Bind(&InputDeviceFactoryEvdev::SetTapToClickPaused,
input_device_factory_, state));
}

void InputDeviceFactoryEvdevProxy::GetTouchDeviceStatus(
const GetTouchDeviceStatusReply& reply) {
task_runner_->PostTask(
FROM_HERE,
base::Bind(&InputDeviceFactoryEvdev::GetTouchDeviceStatus,
input_device_factory_,
base::Bind(&ForwardGetTouchDeviceStatusReply,
base::ThreadTaskRunnerHandle::Get(), reply)));
}

} // namespace ui
59 changes: 59 additions & 0 deletions ui/events/ozone/evdev/input_device_factory_evdev_proxy.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// 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_PROXY_EVDEV_H_
#define UI_EVENTS_OZONE_EVDEV_INPUT_DEVICE_FACTORY_PROXY_EVDEV_H_

#include <set>

#include "base/compiler_specific.h"
#include "base/files/file_path.h"
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "base/single_thread_task_runner.h"
#include "ui/events/ozone/evdev/events_ozone_evdev_export.h"

namespace ui {

enum class DomCode;
class InputDeviceFactoryEvdev;

typedef base::Callback<void(scoped_ptr<std::string>)> GetTouchDeviceStatusReply;

// Thread safe proxy for InputDeviceFactoryEvdev.
class EVENTS_OZONE_EVDEV_EXPORT InputDeviceFactoryEvdevProxy {
public:
InputDeviceFactoryEvdevProxy(
scoped_refptr<base::SingleThreadTaskRunner> task_runner,
base::WeakPtr<InputDeviceFactoryEvdev> input_device_factory);
~InputDeviceFactoryEvdevProxy();

// See InputDeviceFactoryEvdev for docs. These calls simply forward to
// that object on another thread.
void AddInputDevice(int id, const base::FilePath& path);
void RemoveInputDevice(const base::FilePath& path);
void DisableInternalTouchpad();
void EnableInternalTouchpad();
void DisableInternalKeyboardExceptKeys(
scoped_ptr<std::set<DomCode>> excepted_keys);
void EnableInternalKeyboard();
void SetTouchpadSensitivity(int value);
void SetTapToClick(bool enabled);
void SetThreeFingerClick(bool enabled);
void SetTapDragging(bool enabled);
void SetNaturalScroll(bool enabled);
void SetMouseSensitivity(int value);
void SetTapToClickPaused(bool state);
void GetTouchDeviceStatus(const GetTouchDeviceStatusReply& reply);

private:
scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
base::WeakPtr<InputDeviceFactoryEvdev> input_device_factory_;

DISALLOW_COPY_AND_ASSIGN(InputDeviceFactoryEvdevProxy);
};

} // namespace ui

#endif // UI_EVENTS_OZONE_EVDEV_INPUT_DEVICE_FACTORY_PROXY_EVDEV_H_
2 changes: 2 additions & 0 deletions ui/events/ozone/events_ozone.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@
'evdev/input_controller_evdev.h',
'evdev/input_device_factory_evdev.cc',
'evdev/input_device_factory_evdev.h',
'evdev/input_device_factory_evdev_proxy.cc',
'evdev/input_device_factory_evdev_proxy.h',
'evdev/input_injector_evdev.cc',
'evdev/input_injector_evdev.h',
'evdev/keyboard_evdev.cc',
Expand Down

0 comments on commit da763e4

Please sign in to comment.