Chromium Code Reviews| Index: ui/events/device_data_manager.cc |
| diff --git a/ui/events/device_data_manager.cc b/ui/events/device_data_manager.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..181944cebd199e0291fc945156b79de4b18bbdfc |
| --- /dev/null |
| +++ b/ui/events/device_data_manager.cc |
| @@ -0,0 +1,88 @@ |
| +// 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/device_data_manager.h" |
| + |
| +#include "base/at_exit.h" |
| +#include "base/bind.h" |
| +#include "base/logging.h" |
| +#include "ui/gfx/display.h" |
| +#include "ui/gfx/geometry/point3_f.h" |
| + |
| +namespace ui { |
| + |
| +// static |
| +DeviceDataManager* DeviceDataManager::instance_ = NULL; |
| + |
| +DeviceDataManager::DeviceDataManager() { |
| + base::AtExitManager::RegisterTask(base::Bind(&DeviceDataManager::OnExit, |
|
sadrul
2014/05/30 09:44:31
base::DeletePointer<>?
dnicoara
2014/06/10 20:25:03
Nice! Thanks.
Done
|
| + base::Unretained(this))); |
| + for (int i = 0; i < kMaxDeviceNum; ++i) |
| + touch_device_to_display_map_[i] = gfx::Display::kInvalidDisplayID; |
| +} |
| + |
| +DeviceDataManager::~DeviceDataManager() { |
| + CHECK_EQ(this, instance_); |
| + instance_ = NULL; |
| +} |
| + |
| +#if !defined(USE_X11) |
| +//static |
|
sadrul
2014/05/30 09:44:31
I am not a fan of the ifdef here. I think there ar
dnicoara
2014/06/10 20:25:03
I went with the first option since it seemed more
|
| +void DeviceDataManager::Initialize() { |
| + CHECK(!instance_) << "Cannot initialize DeviceDataManager multiple times."; |
| + instance_ = new DeviceDataManager(); |
| +} |
| +#endif |
| + |
| +// static |
| +DeviceDataManager* DeviceDataManager::GetInstance() { |
| + CHECK(instance_) << "DeviceDataManager was not initialized."; |
| + return instance_; |
| +} |
| + |
| +void DeviceDataManager::OnExit() { |
| + delete this; |
| +} |
| + |
| +void DeviceDataManager::ClearTouchTransformerRecord() { |
| + for (int i = 0; i < kMaxDeviceNum; i++) { |
| + touch_device_transformer_map_[i] = gfx::Transform(); |
| + touch_device_to_display_map_[i] = gfx::Display::kInvalidDisplayID; |
| + } |
| +} |
| + |
| +bool DeviceDataManager::IsTouchDeviceIdValid(int touch_device_id) const { |
| + return (touch_device_id > 0 && touch_device_id < kMaxDeviceNum); |
| +} |
| + |
| +void DeviceDataManager::UpdateTouchInfoForDisplay( |
| + int64_t display_id, |
| + int touch_device_id, |
| + const gfx::Transform& touch_transformer) { |
| + if (IsTouchDeviceIdValid(touch_device_id)) { |
| + touch_device_to_display_map_[touch_device_id] = display_id; |
| + touch_device_transformer_map_[touch_device_id] = touch_transformer; |
| + } |
| +} |
| + |
| +void DeviceDataManager::ApplyTouchTransformer(int touch_device_id, |
| + float* x, |
| + float* y) { |
| + if (IsTouchDeviceIdValid(touch_device_id)) { |
| + gfx::Point3F point(*x, *y, 0.0); |
| + const gfx::Transform& trans = |
| + touch_device_transformer_map_[touch_device_id]; |
| + trans.TransformPoint(&point); |
| + *x = point.x(); |
| + *y = point.y(); |
| + } |
| +} |
| + |
| +int64_t DeviceDataManager::GetDisplayForTouchDevice(int touch_device_id) const { |
| + if (IsTouchDeviceIdValid(touch_device_id)) |
| + return touch_device_to_display_map_[touch_device_id]; |
| + return gfx::Display::kInvalidDisplayID; |
| +} |
| + |
| +} // namespace ui |