Commit f77fda10 authored by kylechar's avatar kylechar Committed by Commit bot

Add full touch support to mus.

Everything necessary to use the existing display to touch input-device
association/transform code is accessible from mus now.
ScreenManagerOzone creates a TouchTransformController and tells it to
compute new transforms when the display configuration changes. That's
it.

Delete existing touch code that was added to the WS to associate a
single display and touch input-device.

BUG=679747

Review-Url: https://codereview.chromium.org/2627623003
Cr-Commit-Position: refs/heads/master@{#443162}
parent fd39adcc
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "services/service_manager/public/cpp/interface_registry.h" #include "services/service_manager/public/cpp/interface_registry.h"
#include "third_party/skia/include/core/SkColor.h" #include "third_party/skia/include/core/SkColor.h"
#include "ui/display/manager/chromeos/display_change_observer.h" #include "ui/display/manager/chromeos/display_change_observer.h"
#include "ui/display/manager/chromeos/touch_transform_controller.h"
#include "ui/display/manager/display_layout_store.h" #include "ui/display/manager/display_layout_store.h"
#include "ui/display/manager/display_manager_utilities.h" #include "ui/display/manager/display_manager_utilities.h"
#include "ui/display/screen.h" #include "ui/display/screen.h"
...@@ -63,6 +64,8 @@ ScreenManagerOzone::~ScreenManagerOzone() { ...@@ -63,6 +64,8 @@ ScreenManagerOzone::~ScreenManagerOzone() {
// We are shutting down and don't want to make anymore display changes. // We are shutting down and don't want to make anymore display changes.
fake_display_controller_ = nullptr; fake_display_controller_ = nullptr;
touch_transform_controller_.reset();
if (display_manager_) if (display_manager_)
display_manager_->RemoveObserver(this); display_manager_->RemoveObserver(this);
...@@ -180,6 +183,9 @@ void ScreenManagerOzone::Init(ScreenManagerDelegate* delegate) { ...@@ -180,6 +183,9 @@ void ScreenManagerOzone::Init(ScreenManagerDelegate* delegate) {
// Perform initial configuration. // Perform initial configuration.
display_configurator_.Init(std::move(native_display_delegate_), false); display_configurator_.Init(std::move(native_display_delegate_), false);
display_configurator_.ForceInitialConfigure(kChromeOsBootColor); display_configurator_.ForceInitialConfigure(kChromeOsBootColor);
touch_transform_controller_ = base::MakeUnique<TouchTransformController>(
&display_configurator_, display_manager_.get());
} }
void ScreenManagerOzone::RequestCloseDisplay(int64_t display_id) { void ScreenManagerOzone::RequestCloseDisplay(int64_t display_id) {
...@@ -356,6 +362,8 @@ void ScreenManagerOzone::PostDisplayConfigurationChange( ...@@ -356,6 +362,8 @@ void ScreenManagerOzone::PostDisplayConfigurationChange(
} }
} }
touch_transform_controller_->UpdateTouchTransforms();
DVLOG(1) << "PostDisplayConfigurationChange"; DVLOG(1) << "PostDisplayConfigurationChange";
} }
......
...@@ -28,6 +28,7 @@ namespace display { ...@@ -28,6 +28,7 @@ namespace display {
class DisplayChangeObserver; class DisplayChangeObserver;
class FakeDisplayController; class FakeDisplayController;
class ScreenBase; class ScreenBase;
class TouchTransformController;
// ScreenManagerOzone provides the necessary functionality to configure all // ScreenManagerOzone provides the necessary functionality to configure all
// attached physical displays on the ozone platform. // attached physical displays on the ozone platform.
...@@ -96,6 +97,7 @@ class ScreenManagerOzone ...@@ -96,6 +97,7 @@ class ScreenManagerOzone
DisplayConfigurator display_configurator_; DisplayConfigurator display_configurator_;
std::unique_ptr<DisplayManager> display_manager_; std::unique_ptr<DisplayManager> display_manager_;
std::unique_ptr<DisplayChangeObserver> display_change_observer_; std::unique_ptr<DisplayChangeObserver> display_change_observer_;
std::unique_ptr<TouchTransformController> touch_transform_controller_;
ScreenBase* screen_ = nullptr; ScreenBase* screen_ = nullptr;
ScreenManagerDelegate* delegate_ = nullptr; ScreenManagerDelegate* delegate_ = nullptr;
......
...@@ -191,12 +191,6 @@ void Service::OnStart() { ...@@ -191,12 +191,6 @@ void Service::OnStart() {
// Gpu must be running before the ScreenManager can be initialized. // Gpu must be running before the ScreenManager can be initialized.
window_server_.reset(new ws::WindowServer(this)); window_server_.reset(new ws::WindowServer(this));
// DeviceDataManager must be initialized before TouchController. On non-Linux
// platforms there is no DeviceDataManager so don't create touch controller.
if (ui::DeviceDataManager::HasInstance())
touch_controller_.reset(
new ws::TouchController(window_server_->display_manager()));
ime_server_.Init(context()->connector(), test_config_); ime_server_.Init(context()->connector(), test_config_);
discardable_shared_memory_manager_ = discardable_shared_memory_manager_ =
...@@ -263,11 +257,6 @@ bool Service::IsTestConfig() const { ...@@ -263,11 +257,6 @@ bool Service::IsTestConfig() const {
return test_config_; return test_config_;
} }
void Service::UpdateTouchTransforms() {
if (touch_controller_)
touch_controller_->UpdateTouchTransforms();
}
void Service::Create(const service_manager::Identity& remote_identity, void Service::Create(const service_manager::Identity& remote_identity,
mojom::AccessibilityManagerRequest request) { mojom::AccessibilityManagerRequest request) {
UserState* user_state = GetUserState(remote_identity); UserState* user_state = GetUserState(remote_identity);
......
...@@ -33,7 +33,6 @@ ...@@ -33,7 +33,6 @@
#include "services/ui/public/interfaces/window_tree.mojom.h" #include "services/ui/public/interfaces/window_tree.mojom.h"
#include "services/ui/public/interfaces/window_tree_host.mojom.h" #include "services/ui/public/interfaces/window_tree_host.mojom.h"
#include "services/ui/ws/platform_display_init_params.h" #include "services/ui/ws/platform_display_init_params.h"
#include "services/ui/ws/touch_controller.h"
#include "services/ui/ws/user_id.h" #include "services/ui/ws/user_id.h"
#include "services/ui/ws/window_server_delegate.h" #include "services/ui/ws/window_server_delegate.h"
...@@ -111,7 +110,6 @@ class Service ...@@ -111,7 +110,6 @@ class Service
void OnFirstDisplayReady() override; void OnFirstDisplayReady() override;
void OnNoMoreDisplays() override; void OnNoMoreDisplays() override;
bool IsTestConfig() const override; bool IsTestConfig() const override;
void UpdateTouchTransforms() override;
// service_manager::InterfaceFactory<mojom::AccessibilityManager> // service_manager::InterfaceFactory<mojom::AccessibilityManager>
// implementation. // implementation.
...@@ -191,7 +189,6 @@ class Service ...@@ -191,7 +189,6 @@ class Service
// interfaces and must outlive service_manager::InterfaceRegistry. // interfaces and must outlive service_manager::InterfaceRegistry.
std::unique_ptr<display::ScreenManager> screen_manager_; std::unique_ptr<display::ScreenManager> screen_manager_;
std::unique_ptr<ws::TouchController> touch_controller_;
IMERegistrarImpl ime_registrar_; IMERegistrarImpl ime_registrar_;
IMEServerImpl ime_server_; IMEServerImpl ime_server_;
......
...@@ -64,8 +64,6 @@ static_library("lib") { ...@@ -64,8 +64,6 @@ static_library("lib") {
"server_window_drawn_tracker_observer.h", "server_window_drawn_tracker_observer.h",
"server_window_observer.h", "server_window_observer.h",
"server_window_tracker.h", "server_window_tracker.h",
"touch_controller.cc",
"touch_controller.h",
"user_activity_monitor.cc", "user_activity_monitor.cc",
"user_activity_monitor.h", "user_activity_monitor.h",
"user_display_manager.cc", "user_display_manager.cc",
......
...@@ -180,8 +180,6 @@ void DisplayManager::OnDisplayAdded(int64_t id, ...@@ -180,8 +180,6 @@ void DisplayManager::OnDisplayAdded(int64_t id,
ws::Display* display = new ws::Display(window_server_); ws::Display* display = new ws::Display(window_server_);
display->Init(params, nullptr); display->Init(params, nullptr);
window_server_->delegate()->UpdateTouchTransforms();
} }
void DisplayManager::OnDisplayRemoved(int64_t id) { void DisplayManager::OnDisplayRemoved(int64_t id) {
......
...@@ -554,7 +554,6 @@ class TestWindowServerDelegate : public WindowServerDelegate { ...@@ -554,7 +554,6 @@ class TestWindowServerDelegate : public WindowServerDelegate {
mojom::WindowTreeRequest* tree_request, mojom::WindowTreeRequest* tree_request,
mojom::WindowTreeClientPtr* client) override; mojom::WindowTreeClientPtr* client) override;
bool IsTestConfig() const override; bool IsTestConfig() const override;
void UpdateTouchTransforms() override {}
private: private:
WindowServer* window_server_ = nullptr; WindowServer* window_server_ = nullptr;
......
// Copyright 2016 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 "services/ui/ws/touch_controller.h"
#include <set>
#include <vector>
#include "base/logging.h"
#include "services/ui/ws/display.h"
#include "services/ui/ws/display_manager.h"
#include "ui/events/devices/device_data_manager.h"
#include "ui/events/devices/touchscreen_device.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/transform.h"
namespace ui {
namespace ws {
namespace {
// Computes the scale ratio for the TouchEvent's radius.
double ComputeTouchResolutionScale(const Display* touch_display,
const ui::TouchscreenDevice& touch_device) {
gfx::Size touch_display_size = touch_display->GetSize();
if (touch_device.size.IsEmpty() || touch_display_size.IsEmpty())
return 1.0;
double display_area = touch_display_size.GetArea();
double touch_area = touch_device.size.GetArea();
double ratio = std::sqrt(display_area / touch_area);
return ratio;
}
// Computes a touch transform that maps from window bounds to touchscreen size.
// Assumes scale factor of 1.0.
gfx::Transform ComputeTouchTransform(
const Display* touch_display,
const ui::TouchscreenDevice& touch_device) {
gfx::Size touch_display_size = touch_display->GetSize();
gfx::SizeF current_size(touch_display_size);
gfx::SizeF touch_area(touch_device.size);
gfx::Transform transform;
if (current_size.IsEmpty() || touch_area.IsEmpty())
return transform;
// Take care of scaling between touchscreen area and display resolution.
transform.Scale(current_size.width() / touch_area.width(),
current_size.height() / touch_area.height());
return transform;
}
} // namespace
TouchController::TouchController(DisplayManager* display_manager)
: display_manager_(display_manager) {
DCHECK(display_manager_);
ui::DeviceDataManager::GetInstance()->AddObserver(this);
}
TouchController::~TouchController() {
ui::DeviceDataManager::GetInstance()->RemoveObserver(this);
}
void TouchController::UpdateTouchTransforms() const {
ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance();
device_manager->ClearTouchDeviceAssociations();
const std::set<Display*>& touch_displays = display_manager_->displays();
const std::vector<ui::TouchscreenDevice>& touch_devices =
device_manager->GetTouchscreenDevices();
// Mash can only handle a single display so this doesn't implement support for
// matching touchscreens with multiple displays.
// TODO(kylechar): Implement support for multiple displays when needed.
if (touch_displays.size() == 1 && touch_devices.size() == 1) {
const Display* touch_display = *touch_displays.begin();
const ui::TouchscreenDevice& touch_device = touch_devices[0];
int64_t touch_display_id = touch_display->GetId();
int touch_device_id = touch_device.id;
if (touch_device_id != ui::InputDevice::kInvalidId) {
device_manager->UpdateTouchRadiusScale(
touch_device_id,
ComputeTouchResolutionScale(touch_display, touch_device));
device_manager->UpdateTouchInfoForDisplay(
touch_display_id, touch_device_id,
ComputeTouchTransform(touch_display, touch_device));
}
}
}
void TouchController::OnTouchscreenDeviceConfigurationChanged() {
UpdateTouchTransforms();
}
} // namespace ws
} // namespace ui
// Copyright 2016 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 SERVICES_UI_WS_TOUCH_CONTROLLER_H_
#define SERVICES_UI_WS_TOUCH_CONTROLLER_H_
#include "base/macros.h"
#include "ui/events/devices/input_device_event_observer.h"
namespace ui {
namespace ws {
class DisplayManager;
// Tracks changes to displays and touchscreen devices. Updates the mapping
// between display devices and touchscreen devices when changes occur.
class TouchController : public ui::InputDeviceEventObserver {
public:
explicit TouchController(DisplayManager* display_manager);
~TouchController() override;
void UpdateTouchTransforms() const;
// ui::InputDeviceEventObserver:
void OnTouchscreenDeviceConfigurationChanged() override;
private:
DisplayManager* display_manager_;
DISALLOW_COPY_AND_ASSIGN(TouchController);
};
} // namespace ws
} // namespace ui
#endif // SERVICES_UI_WS_TOUCH_CONTROLLER_H_
...@@ -44,10 +44,6 @@ class WindowServerDelegate { ...@@ -44,10 +44,6 @@ class WindowServerDelegate {
virtual bool IsTestConfig() const = 0; virtual bool IsTestConfig() const = 0;
// Called when touchscreen coordinate transforms should be updated. For
// example when displays or touch input devices are added/removed.
virtual void UpdateTouchTransforms() = 0;
// Creates a WindowTreeBinding. Default implementation returns null, which // Creates a WindowTreeBinding. Default implementation returns null, which
// creates DefaultBinding. // creates DefaultBinding.
virtual std::unique_ptr<WindowTreeBinding> CreateWindowTreeBinding( virtual std::unique_ptr<WindowTreeBinding> CreateWindowTreeBinding(
......
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