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_controller.h" | 7 #include "ash/display/display_controller.h" |
8 #include "ash/display/display_manager.h" | 8 #include "ash/display/display_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" |
11 #include "ash/shell.h" | 11 #include "ash/shell.h" |
12 #include "ui/aura/window_tree_host.h" | 12 #include "ui/aura/window_tree_host.h" |
13 #include "ui/display/chromeos/display_configurator.h" | 13 #include "ui/display/chromeos/display_configurator.h" |
14 #include "ui/display/types/chromeos/display_snapshot.h" | 14 #include "ui/display/types/chromeos/display_snapshot.h" |
15 #include "ui/events/device_data_manager.h" | 15 #include "ui/events/device_data_manager.h" |
| 16 #include "ui/events/x/device_data_manager_x11.h" |
16 | 17 |
17 namespace ash { | 18 namespace ash { |
18 | 19 |
19 namespace { | 20 namespace { |
20 | 21 |
21 DisplayManager* GetDisplayManager() { | 22 DisplayManager* GetDisplayManager() { |
22 return Shell::GetInstance()->display_manager(); | 23 return Shell::GetInstance()->display_manager(); |
23 } | 24 } |
24 | 25 |
25 } // namespace | 26 } // namespace |
26 | 27 |
| 28 |
| 29 // This is to compute the scale ratio for the TouchEvent's radius. The |
| 30 // configured resolution of the display is not always the same as the touch |
| 31 // screen's reporting resolution, e.g. the display could be set as |
| 32 // 1920x1080 while the touchscreen is reporting touch position range at |
| 33 // 32767x32767. Touch radius is reported in the units the same as touch position |
| 34 // so we need to scale the touch radius to be compatible with the display's |
| 35 // resolution. We compute the scale as |
| 36 // sqrt of (display_area / touchscreen_area) |
| 37 double TouchTransformerController::GetTouchResolutionScale( |
| 38 const DisplayInfo& touch_display) const { |
| 39 if (touch_display.touch_device_id() == 0) |
| 40 return 1.0; |
| 41 |
| 42 double min_x, max_x; |
| 43 double min_y, max_y; |
| 44 if (!ui::DeviceDataManagerX11::GetInstance()->GetDataRange( |
| 45 touch_display.touch_device_id(), |
| 46 ui::DeviceDataManagerX11::DT_TOUCH_POSITION_X, |
| 47 &min_x, &max_x) || |
| 48 !ui::DeviceDataManagerX11::GetInstance()->GetDataRange( |
| 49 touch_display.touch_device_id(), |
| 50 ui::DeviceDataManagerX11::DT_TOUCH_POSITION_Y, |
| 51 &min_y, &max_y)) { |
| 52 return 1.0; |
| 53 } |
| 54 |
| 55 double width = touch_display.bounds_in_native().width(); |
| 56 double height = touch_display.bounds_in_native().height(); |
| 57 |
| 58 if (max_x == 0.0 || max_y == 0.0 || width == 0.0 || height == 0.0) |
| 59 return 1.0; |
| 60 |
| 61 // [0, max_x] -> touchscreen width = max_x + 1 |
| 62 // [0, max_y] -> touchscreen height = max_y + 1 |
| 63 max_x += 1.0; |
| 64 max_y += 1.0; |
| 65 |
| 66 double ratio = std::sqrt((width * height) / (max_x * max_y)); |
| 67 |
| 68 VLOG(2) << "Screen width/height: " << width << "/" << height |
| 69 << ", Touchscreen width/height: " << max_x << "/" << max_y |
| 70 << ", Touch radius scale ratio: " << ratio; |
| 71 return ratio; |
| 72 } |
| 73 |
27 // This function computes the extended mode TouchTransformer for | 74 // This function computes the extended mode TouchTransformer for |
28 // |touch_display|. The TouchTransformer maps the touch event position | 75 // |touch_display|. The TouchTransformer maps the touch event position |
29 // from framebuffer size to the display size. | 76 // from framebuffer size to the display size. |
30 gfx::Transform | 77 gfx::Transform |
31 TouchTransformerController::GetExtendedModeTouchTransformer( | 78 TouchTransformerController::GetExtendedModeTouchTransformer( |
32 const DisplayInfo& touch_display, const gfx::Size& fb_size) const { | 79 const DisplayInfo& touch_display, const gfx::Size& fb_size) const { |
33 gfx::Transform ctm; | 80 gfx::Transform ctm; |
34 if (touch_display.touch_device_id() == 0 || | 81 if (touch_display.touch_device_id() == 0 || |
35 fb_size.width() == 0.0 || | 82 fb_size.width() == 0.0 || |
36 fb_size.height() == 0.0) | 83 fb_size.height() == 0.0) |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 } else if (display_state == ui::MULTIPLE_DISPLAY_STATE_DUAL_MIRROR || | 198 } else if (display_state == ui::MULTIPLE_DISPLAY_STATE_DUAL_MIRROR || |
152 display_state == ui::MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED) { | 199 display_state == ui::MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED) { |
153 // TODO(miletus) : Handle DUAL_EXTENDED with software mirroring. | 200 // TODO(miletus) : Handle DUAL_EXTENDED with software mirroring. |
154 DisplayIdPair id_pair = GetDisplayManager()->GetCurrentDisplayIdPair(); | 201 DisplayIdPair id_pair = GetDisplayManager()->GetCurrentDisplayIdPair(); |
155 display1_id = id_pair.first; | 202 display1_id = id_pair.first; |
156 display2_id = id_pair.second; | 203 display2_id = id_pair.second; |
157 DCHECK(display1_id != gfx::Display::kInvalidDisplayID && | 204 DCHECK(display1_id != gfx::Display::kInvalidDisplayID && |
158 display2_id != gfx::Display::kInvalidDisplayID); | 205 display2_id != gfx::Display::kInvalidDisplayID); |
159 display1 = GetDisplayManager()->GetDisplayInfo(display1_id); | 206 display1 = GetDisplayManager()->GetDisplayInfo(display1_id); |
160 display2 = GetDisplayManager()->GetDisplayInfo(display2_id); | 207 display2 = GetDisplayManager()->GetDisplayInfo(display2_id); |
| 208 device_manager->UpdateTouchRadiusScale(display1.touch_device_id(), |
| 209 GetTouchResolutionScale(display1)); |
| 210 device_manager->UpdateTouchRadiusScale(display2.touch_device_id(), |
| 211 GetTouchResolutionScale(display2)); |
161 } else { | 212 } else { |
162 single_display_id = GetDisplayManager()->first_display_id(); | 213 single_display_id = GetDisplayManager()->first_display_id(); |
163 DCHECK(single_display_id != gfx::Display::kInvalidDisplayID); | 214 DCHECK(single_display_id != gfx::Display::kInvalidDisplayID); |
164 single_display = GetDisplayManager()->GetDisplayInfo(single_display_id); | 215 single_display = GetDisplayManager()->GetDisplayInfo(single_display_id); |
| 216 device_manager->UpdateTouchRadiusScale( |
| 217 single_display.touch_device_id(), |
| 218 GetTouchResolutionScale(single_display)); |
165 } | 219 } |
166 | 220 |
167 if (display_state == ui::MULTIPLE_DISPLAY_STATE_DUAL_MIRROR) { | 221 if (display_state == ui::MULTIPLE_DISPLAY_STATE_DUAL_MIRROR) { |
168 // In mirror mode, both displays share the same root window so | 222 // In mirror mode, both displays share the same root window so |
169 // both display ids are associated with the root window. | 223 // both display ids are associated with the root window. |
170 aura::Window* root = display_controller->GetPrimaryRootWindow(); | 224 aura::Window* root = display_controller->GetPrimaryRootWindow(); |
171 RootWindowController::ForWindow(root)->ash_host()->UpdateDisplayID( | 225 RootWindowController::ForWindow(root)->ash_host()->UpdateDisplayID( |
172 display1_id, display2_id); | 226 display1_id, display2_id); |
173 device_manager->UpdateTouchInfoForDisplay( | 227 device_manager->UpdateTouchInfoForDisplay( |
174 display1_id, | 228 display1_id, |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 | 274 |
221 void TouchTransformerController::OnDisplaysInitialized() { | 275 void TouchTransformerController::OnDisplaysInitialized() { |
222 UpdateTouchTransformer(); | 276 UpdateTouchTransformer(); |
223 } | 277 } |
224 | 278 |
225 void TouchTransformerController::OnDisplayConfigurationChanged() { | 279 void TouchTransformerController::OnDisplayConfigurationChanged() { |
226 UpdateTouchTransformer(); | 280 UpdateTouchTransformer(); |
227 } | 281 } |
228 | 282 |
229 } // namespace ash | 283 } // namespace ash |
OLD | NEW |