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 "ash/touch/touch_transformer_controller.h" | 5 #include "ash/touch/touch_transformer_controller.h" |
6 | 6 |
7 #include "ash/display/display_manager.h" | 7 #include "ash/display/display_manager.h" |
8 #include "ash/display/window_tree_host_manager.h" | 8 #include "ash/display/window_tree_host_manager.h" |
9 #include "ash/host/ash_window_tree_host.h" | 9 #include "ash/host/ash_window_tree_host.h" |
10 #include "ash/root_window_controller.h" | 10 #include "ash/root_window_controller.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 | 38 |
39 // This is to compute the scale ratio for the TouchEvent's radius. The | 39 // This is to compute the scale ratio for the TouchEvent's radius. The |
40 // configured resolution of the display is not always the same as the touch | 40 // configured resolution of the display is not always the same as the touch |
41 // screen's reporting resolution, e.g. the display could be set as | 41 // screen's reporting resolution, e.g. the display could be set as |
42 // 1920x1080 while the touchscreen is reporting touch position range at | 42 // 1920x1080 while the touchscreen is reporting touch position range at |
43 // 32767x32767. Touch radius is reported in the units the same as touch position | 43 // 32767x32767. Touch radius is reported in the units the same as touch position |
44 // so we need to scale the touch radius to be compatible with the display's | 44 // so we need to scale the touch radius to be compatible with the display's |
45 // resolution. We compute the scale as | 45 // resolution. We compute the scale as |
46 // sqrt of (display_area / touchscreen_area) | 46 // sqrt of (display_area / touchscreen_area) |
47 double TouchTransformerController::GetTouchResolutionScale( | 47 double TouchTransformerController::GetTouchResolutionScale( |
48 const DisplayInfo& touch_display, | 48 const display::ManagedDisplayInfo& touch_display, |
49 const ui::TouchscreenDevice& touch_device) const { | 49 const ui::TouchscreenDevice& touch_device) const { |
50 if (touch_device.id == ui::InputDevice::kInvalidId || | 50 if (touch_device.id == ui::InputDevice::kInvalidId || |
51 touch_device.size.IsEmpty() || | 51 touch_device.size.IsEmpty() || |
52 touch_display.bounds_in_native().size().IsEmpty()) | 52 touch_display.bounds_in_native().size().IsEmpty()) |
53 return 1.0; | 53 return 1.0; |
54 | 54 |
55 double display_area = touch_display.bounds_in_native().size().GetArea(); | 55 double display_area = touch_display.bounds_in_native().size().GetArea(); |
56 double touch_area = touch_device.size.GetArea(); | 56 double touch_area = touch_device.size.GetArea(); |
57 double ratio = std::sqrt(display_area / touch_area); | 57 double ratio = std::sqrt(display_area / touch_area); |
58 | 58 |
59 VLOG(2) << "Display size: " | 59 VLOG(2) << "Display size: " |
60 << touch_display.bounds_in_native().size().ToString() | 60 << touch_display.bounds_in_native().size().ToString() |
61 << ", Touchscreen size: " << touch_device.size.ToString() | 61 << ", Touchscreen size: " << touch_device.size.ToString() |
62 << ", Touch radius scale ratio: " << ratio; | 62 << ", Touch radius scale ratio: " << ratio; |
63 return ratio; | 63 return ratio; |
64 } | 64 } |
65 | 65 |
66 gfx::Transform TouchTransformerController::GetTouchTransform( | 66 gfx::Transform TouchTransformerController::GetTouchTransform( |
67 const DisplayInfo& display, | 67 const display::ManagedDisplayInfo& display, |
68 const DisplayInfo& touch_display, | 68 const display::ManagedDisplayInfo& touch_display, |
69 const ui::TouchscreenDevice& touchscreen, | 69 const ui::TouchscreenDevice& touchscreen, |
70 const gfx::Size& framebuffer_size) const { | 70 const gfx::Size& framebuffer_size) const { |
71 auto current_size = gfx::SizeF(display.bounds_in_native().size()); | 71 auto current_size = gfx::SizeF(display.bounds_in_native().size()); |
72 auto touch_native_size = gfx::SizeF(touch_display.GetNativeModeSize()); | 72 auto touch_native_size = gfx::SizeF(touch_display.GetNativeModeSize()); |
73 #if defined(USE_OZONE) | 73 #if defined(USE_OZONE) |
74 auto touch_area = gfx::SizeF(touchscreen.size); | 74 auto touch_area = gfx::SizeF(touchscreen.size); |
75 #elif defined(USE_X11) | 75 #elif defined(USE_X11) |
76 // On X11 touches are reported in the framebuffer coordinate space. | 76 // On X11 touches are reported in the framebuffer coordinate space. |
77 auto touch_area = gfx::SizeF(framebuffer_size); | 77 auto touch_area = gfx::SizeF(framebuffer_size); |
78 #endif | 78 #endif |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 | 118 |
119 TouchTransformerController::TouchTransformerController() { | 119 TouchTransformerController::TouchTransformerController() { |
120 Shell::GetInstance()->window_tree_host_manager()->AddObserver(this); | 120 Shell::GetInstance()->window_tree_host_manager()->AddObserver(this); |
121 } | 121 } |
122 | 122 |
123 TouchTransformerController::~TouchTransformerController() { | 123 TouchTransformerController::~TouchTransformerController() { |
124 Shell::GetInstance()->window_tree_host_manager()->RemoveObserver(this); | 124 Shell::GetInstance()->window_tree_host_manager()->RemoveObserver(this); |
125 } | 125 } |
126 | 126 |
127 void TouchTransformerController::UpdateTouchRadius( | 127 void TouchTransformerController::UpdateTouchRadius( |
128 const DisplayInfo& display) const { | 128 const display::ManagedDisplayInfo& display) const { |
129 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance(); | 129 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance(); |
130 for (const auto& device_id : display.input_devices()) { | 130 for (const auto& device_id : display.input_devices()) { |
131 device_manager->UpdateTouchRadiusScale( | 131 device_manager->UpdateTouchRadiusScale( |
132 device_id, | 132 device_id, |
133 GetTouchResolutionScale(display, FindTouchscreenById(device_id))); | 133 GetTouchResolutionScale(display, FindTouchscreenById(device_id))); |
134 } | 134 } |
135 } | 135 } |
136 | 136 |
137 void TouchTransformerController::UpdateTouchTransform( | 137 void TouchTransformerController::UpdateTouchTransform( |
138 int64_t target_display_id, | 138 int64_t target_display_id, |
139 const DisplayInfo& touch_display, | 139 const display::ManagedDisplayInfo& touch_display, |
140 const DisplayInfo& target_display) const { | 140 const display::ManagedDisplayInfo& target_display) const { |
141 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance(); | 141 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance(); |
142 gfx::Size fb_size = | 142 gfx::Size fb_size = |
143 Shell::GetInstance()->display_configurator()->framebuffer_size(); | 143 Shell::GetInstance()->display_configurator()->framebuffer_size(); |
144 for (const auto& device_id : touch_display.input_devices()) { | 144 for (const auto& device_id : touch_display.input_devices()) { |
145 device_manager->UpdateTouchInfoForDisplay( | 145 device_manager->UpdateTouchInfoForDisplay( |
146 target_display_id, device_id, | 146 target_display_id, device_id, |
147 GetTouchTransform(target_display, touch_display, | 147 GetTouchTransform(target_display, touch_display, |
148 FindTouchscreenById(device_id), fb_size)); | 148 FindTouchscreenById(device_id), fb_size)); |
149 } | 149 } |
150 } | 150 } |
151 | 151 |
152 void TouchTransformerController::UpdateTouchTransformer() const { | 152 void TouchTransformerController::UpdateTouchTransformer() const { |
153 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance(); | 153 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance(); |
154 device_manager->ClearTouchDeviceAssociations(); | 154 device_manager->ClearTouchDeviceAssociations(); |
155 | 155 |
156 // Display IDs and DisplayInfo for mirror or extended mode. | 156 // Display IDs and display::ManagedDisplayInfo for mirror or extended mode. |
157 int64_t display1_id = display::Display::kInvalidDisplayID; | 157 int64_t display1_id = display::Display::kInvalidDisplayID; |
158 int64_t display2_id = display::Display::kInvalidDisplayID; | 158 int64_t display2_id = display::Display::kInvalidDisplayID; |
159 DisplayInfo display1; | 159 display::ManagedDisplayInfo display1; |
160 DisplayInfo display2; | 160 display::ManagedDisplayInfo display2; |
161 // Display ID and DisplayInfo for single display mode. | 161 // Display ID and display::ManagedDisplayInfo for single display mode. |
162 int64_t single_display_id = display::Display::kInvalidDisplayID; | 162 int64_t single_display_id = display::Display::kInvalidDisplayID; |
163 DisplayInfo single_display; | 163 display::ManagedDisplayInfo single_display; |
164 | 164 |
165 WindowTreeHostManager* window_tree_host_manager = | 165 WindowTreeHostManager* window_tree_host_manager = |
166 Shell::GetInstance()->window_tree_host_manager(); | 166 Shell::GetInstance()->window_tree_host_manager(); |
167 DisplayManager* display_manager = GetDisplayManager(); | 167 DisplayManager* display_manager = GetDisplayManager(); |
168 if (display_manager->num_connected_displays() == 0) { | 168 if (display_manager->num_connected_displays() == 0) { |
169 return; | 169 return; |
170 } else if (display_manager->num_connected_displays() == 1 || | 170 } else if (display_manager->num_connected_displays() == 1 || |
171 display_manager->IsInUnifiedMode()) { | 171 display_manager->IsInUnifiedMode()) { |
172 single_display_id = display_manager->first_display_id(); | 172 single_display_id = display_manager->first_display_id(); |
173 DCHECK(single_display_id != display::Display::kInvalidDisplayID); | 173 DCHECK(single_display_id != display::Display::kInvalidDisplayID); |
(...skipping 11 matching lines...) Expand all Loading... |
185 UpdateTouchRadius(display2); | 185 UpdateTouchRadius(display2); |
186 } | 186 } |
187 | 187 |
188 if (display_manager->IsInMirrorMode()) { | 188 if (display_manager->IsInMirrorMode()) { |
189 int64_t primary_display_id = | 189 int64_t primary_display_id = |
190 window_tree_host_manager->GetPrimaryDisplayId(); | 190 window_tree_host_manager->GetPrimaryDisplayId(); |
191 if (GetDisplayManager()->SoftwareMirroringEnabled()) { | 191 if (GetDisplayManager()->SoftwareMirroringEnabled()) { |
192 // In extended but software mirroring mode, there is a WindowTreeHost for | 192 // In extended but software mirroring mode, there is a WindowTreeHost for |
193 // each display, but all touches are forwarded to the primary root | 193 // each display, but all touches are forwarded to the primary root |
194 // window's WindowTreeHost. | 194 // window's WindowTreeHost. |
195 DisplayInfo target_display = | 195 display::ManagedDisplayInfo target_display = |
196 primary_display_id == display1_id ? display1 : display2; | 196 primary_display_id == display1_id ? display1 : display2; |
197 UpdateTouchTransform(target_display.id(), display1, target_display); | 197 UpdateTouchTransform(target_display.id(), display1, target_display); |
198 UpdateTouchTransform(target_display.id(), display2, target_display); | 198 UpdateTouchTransform(target_display.id(), display2, target_display); |
199 } else { | 199 } else { |
200 // In mirror mode, there is just one WindowTreeHost and two displays. Make | 200 // In mirror mode, there is just one WindowTreeHost and two displays. Make |
201 // the WindowTreeHost accept touch events from both displays. | 201 // the WindowTreeHost accept touch events from both displays. |
202 UpdateTouchTransform(primary_display_id, display1, display1); | 202 UpdateTouchTransform(primary_display_id, display1, display1); |
203 UpdateTouchTransform(primary_display_id, display2, display2); | 203 UpdateTouchTransform(primary_display_id, display2, display2); |
204 } | 204 } |
205 return; | 205 return; |
(...skipping 13 matching lines...) Expand all Loading... |
219 | 219 |
220 void TouchTransformerController::OnDisplaysInitialized() { | 220 void TouchTransformerController::OnDisplaysInitialized() { |
221 UpdateTouchTransformer(); | 221 UpdateTouchTransformer(); |
222 } | 222 } |
223 | 223 |
224 void TouchTransformerController::OnDisplayConfigurationChanged() { | 224 void TouchTransformerController::OnDisplayConfigurationChanged() { |
225 UpdateTouchTransformer(); | 225 UpdateTouchTransformer(); |
226 } | 226 } |
227 | 227 |
228 } // namespace ash | 228 } // namespace ash |
OLD | NEW |