OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/events/device_data_manager.h" | 5 #include "ui/events/device_data_manager.h" |
6 | 6 |
7 #include "base/at_exit.h" | 7 #include "base/at_exit.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "ui/gfx/display.h" | 10 #include "ui/gfx/display.h" |
11 #include "ui/gfx/geometry/point3_f.h" | 11 #include "ui/gfx/geometry/point3_f.h" |
12 | 12 |
13 namespace ui { | 13 namespace ui { |
14 | 14 |
15 // static | 15 // static |
16 DeviceDataManager* DeviceDataManager::instance_ = NULL; | 16 DeviceDataManager* DeviceDataManager::instance_ = NULL; |
17 | 17 |
18 DeviceDataManager::DeviceDataManager() { | 18 DeviceDataManager::DeviceDataManager() { |
19 CHECK(!instance_) << "Can not create multiple instances of DeviceDataManager"; | 19 CHECK(!instance_) << "Can not create multiple instances of DeviceDataManager"; |
20 instance_ = this; | 20 instance_ = this; |
21 | 21 |
22 base::AtExitManager::RegisterTask( | 22 base::AtExitManager::RegisterTask( |
23 base::Bind(&base::DeletePointer<DeviceDataManager>, this)); | 23 base::Bind(&base::DeletePointer<DeviceDataManager>, this)); |
24 | 24 |
25 for (int i = 0; i < kMaxDeviceNum; ++i) | 25 for (int i = 0; i < kMaxDeviceNum; ++i) { |
26 touch_device_to_display_map_[i] = gfx::Display::kInvalidDisplayID; | 26 touch_device_to_display_map_[i] = gfx::Display::kInvalidDisplayID; |
| 27 touch_radius_scale_map_[i] = 1.0; |
| 28 } |
27 } | 29 } |
28 | 30 |
29 DeviceDataManager::~DeviceDataManager() { | 31 DeviceDataManager::~DeviceDataManager() { |
30 CHECK_EQ(this, instance_); | 32 CHECK_EQ(this, instance_); |
31 instance_ = NULL; | 33 instance_ = NULL; |
32 } | 34 } |
33 | 35 |
34 // static | 36 // static |
35 DeviceDataManager* DeviceDataManager::instance() { return instance_; } | 37 DeviceDataManager* DeviceDataManager::instance() { return instance_; } |
36 | 38 |
(...skipping 13 matching lines...) Expand all Loading... |
50 | 52 |
51 // static | 53 // static |
52 bool DeviceDataManager::HasInstance() { | 54 bool DeviceDataManager::HasInstance() { |
53 return instance_ != NULL; | 55 return instance_ != NULL; |
54 } | 56 } |
55 | 57 |
56 void DeviceDataManager::ClearTouchTransformerRecord() { | 58 void DeviceDataManager::ClearTouchTransformerRecord() { |
57 for (int i = 0; i < kMaxDeviceNum; i++) { | 59 for (int i = 0; i < kMaxDeviceNum; i++) { |
58 touch_device_transformer_map_[i] = gfx::Transform(); | 60 touch_device_transformer_map_[i] = gfx::Transform(); |
59 touch_device_to_display_map_[i] = gfx::Display::kInvalidDisplayID; | 61 touch_device_to_display_map_[i] = gfx::Display::kInvalidDisplayID; |
| 62 touch_radius_scale_map_[i] = 1.0; |
60 } | 63 } |
61 } | 64 } |
62 | 65 |
63 bool DeviceDataManager::IsTouchDeviceIdValid(int touch_device_id) const { | 66 bool DeviceDataManager::IsTouchDeviceIdValid(int touch_device_id) const { |
64 return (touch_device_id > 0 && touch_device_id < kMaxDeviceNum); | 67 return (touch_device_id > 0 && touch_device_id < kMaxDeviceNum); |
65 } | 68 } |
66 | 69 |
67 void DeviceDataManager::UpdateTouchInfoForDisplay( | 70 void DeviceDataManager::UpdateTouchInfoForDisplay( |
68 int64_t display_id, | 71 int64_t display_id, |
69 int touch_device_id, | 72 int touch_device_id, |
70 const gfx::Transform& touch_transformer) { | 73 const gfx::Transform& touch_transformer) { |
71 if (IsTouchDeviceIdValid(touch_device_id)) { | 74 if (IsTouchDeviceIdValid(touch_device_id)) { |
72 touch_device_to_display_map_[touch_device_id] = display_id; | 75 touch_device_to_display_map_[touch_device_id] = display_id; |
73 touch_device_transformer_map_[touch_device_id] = touch_transformer; | 76 touch_device_transformer_map_[touch_device_id] = touch_transformer; |
74 } | 77 } |
75 } | 78 } |
76 | 79 |
| 80 void DeviceDataManager::UpdateTouchRadiusScale(int touch_device_id, |
| 81 double scale) { |
| 82 if (IsTouchDeviceIdValid(touch_device_id)) |
| 83 touch_radius_scale_map_[touch_device_id] = scale; |
| 84 } |
| 85 |
| 86 void DeviceDataManager::ApplyTouchRadiusScale(int touch_device_id, |
| 87 double* radius) { |
| 88 if (IsTouchDeviceIdValid(touch_device_id)) |
| 89 *radius = (*radius) * touch_radius_scale_map_[touch_device_id]; |
| 90 } |
| 91 |
77 void DeviceDataManager::ApplyTouchTransformer(int touch_device_id, | 92 void DeviceDataManager::ApplyTouchTransformer(int touch_device_id, |
78 float* x, | 93 float* x, |
79 float* y) { | 94 float* y) { |
80 if (IsTouchDeviceIdValid(touch_device_id)) { | 95 if (IsTouchDeviceIdValid(touch_device_id)) { |
81 gfx::Point3F point(*x, *y, 0.0); | 96 gfx::Point3F point(*x, *y, 0.0); |
82 const gfx::Transform& trans = | 97 const gfx::Transform& trans = |
83 touch_device_transformer_map_[touch_device_id]; | 98 touch_device_transformer_map_[touch_device_id]; |
84 trans.TransformPoint(&point); | 99 trans.TransformPoint(&point); |
85 *x = point.x(); | 100 *x = point.x(); |
86 *y = point.y(); | 101 *y = point.y(); |
87 } | 102 } |
88 } | 103 } |
89 | 104 |
90 int64_t DeviceDataManager::GetDisplayForTouchDevice(int touch_device_id) const { | 105 int64_t DeviceDataManager::GetDisplayForTouchDevice(int touch_device_id) const { |
91 if (IsTouchDeviceIdValid(touch_device_id)) | 106 if (IsTouchDeviceIdValid(touch_device_id)) |
92 return touch_device_to_display_map_[touch_device_id]; | 107 return touch_device_to_display_map_[touch_device_id]; |
93 return gfx::Display::kInvalidDisplayID; | 108 return gfx::Display::kInvalidDisplayID; |
94 } | 109 } |
95 | 110 |
96 } // namespace ui | 111 } // namespace ui |
OLD | NEW |