Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ui/events/device_data_manager.h" | |
| 6 | |
| 7 #include "base/at_exit.h" | |
| 8 #include "base/bind.h" | |
| 9 #include "base/logging.h" | |
| 10 #include "ui/gfx/display.h" | |
| 11 #include "ui/gfx/geometry/point3_f.h" | |
| 12 | |
| 13 namespace ui { | |
| 14 | |
| 15 // static | |
| 16 DeviceDataManager* DeviceDataManager::instance_ = NULL; | |
| 17 | |
| 18 DeviceDataManager::DeviceDataManager() { | |
| 19 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
| |
| 20 base::Unretained(this))); | |
| 21 for (int i = 0; i < kMaxDeviceNum; ++i) | |
| 22 touch_device_to_display_map_[i] = gfx::Display::kInvalidDisplayID; | |
| 23 } | |
| 24 | |
| 25 DeviceDataManager::~DeviceDataManager() { | |
| 26 CHECK_EQ(this, instance_); | |
| 27 instance_ = NULL; | |
| 28 } | |
| 29 | |
| 30 #if !defined(USE_X11) | |
| 31 //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
| |
| 32 void DeviceDataManager::Initialize() { | |
| 33 CHECK(!instance_) << "Cannot initialize DeviceDataManager multiple times."; | |
| 34 instance_ = new DeviceDataManager(); | |
| 35 } | |
| 36 #endif | |
| 37 | |
| 38 // static | |
| 39 DeviceDataManager* DeviceDataManager::GetInstance() { | |
| 40 CHECK(instance_) << "DeviceDataManager was not initialized."; | |
| 41 return instance_; | |
| 42 } | |
| 43 | |
| 44 void DeviceDataManager::OnExit() { | |
| 45 delete this; | |
| 46 } | |
| 47 | |
| 48 void DeviceDataManager::ClearTouchTransformerRecord() { | |
| 49 for (int i = 0; i < kMaxDeviceNum; i++) { | |
| 50 touch_device_transformer_map_[i] = gfx::Transform(); | |
| 51 touch_device_to_display_map_[i] = gfx::Display::kInvalidDisplayID; | |
| 52 } | |
| 53 } | |
| 54 | |
| 55 bool DeviceDataManager::IsTouchDeviceIdValid(int touch_device_id) const { | |
| 56 return (touch_device_id > 0 && touch_device_id < kMaxDeviceNum); | |
| 57 } | |
| 58 | |
| 59 void DeviceDataManager::UpdateTouchInfoForDisplay( | |
| 60 int64_t display_id, | |
| 61 int touch_device_id, | |
| 62 const gfx::Transform& touch_transformer) { | |
| 63 if (IsTouchDeviceIdValid(touch_device_id)) { | |
| 64 touch_device_to_display_map_[touch_device_id] = display_id; | |
| 65 touch_device_transformer_map_[touch_device_id] = touch_transformer; | |
| 66 } | |
| 67 } | |
| 68 | |
| 69 void DeviceDataManager::ApplyTouchTransformer(int touch_device_id, | |
| 70 float* x, | |
| 71 float* y) { | |
| 72 if (IsTouchDeviceIdValid(touch_device_id)) { | |
| 73 gfx::Point3F point(*x, *y, 0.0); | |
| 74 const gfx::Transform& trans = | |
| 75 touch_device_transformer_map_[touch_device_id]; | |
| 76 trans.TransformPoint(&point); | |
| 77 *x = point.x(); | |
| 78 *y = point.y(); | |
| 79 } | |
| 80 } | |
| 81 | |
| 82 int64_t DeviceDataManager::GetDisplayForTouchDevice(int touch_device_id) const { | |
| 83 if (IsTouchDeviceIdValid(touch_device_id)) | |
| 84 return touch_device_to_display_map_[touch_device_id]; | |
| 85 return gfx::Display::kInvalidDisplayID; | |
| 86 } | |
| 87 | |
| 88 } // namespace ui | |
| OLD | NEW |