| 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/display/manager/chromeos/touch_transform_controller.h" | 5 #include "ui/display/manager/chromeos/touch_transform_controller.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "third_party/skia/include/core/SkMatrix44.h" | 10 #include "third_party/skia/include/core/SkMatrix44.h" |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 (1 - touch_calib_ar / current_ar) * 0.5 * current_size.width(), 0); | 145 (1 - touch_calib_ar / current_ar) * 0.5 * current_size.width(), 0); |
| 146 ctm.Scale(touch_calib_ar / current_ar, 1); | 146 ctm.Scale(touch_calib_ar / current_ar, 1); |
| 147 } | 147 } |
| 148 } | 148 } |
| 149 // Take care of scaling between touchscreen area and display resolution. | 149 // Take care of scaling between touchscreen area and display resolution. |
| 150 ctm.Scale(current_size.width() / touch_area.width(), | 150 ctm.Scale(current_size.width() / touch_area.width(), |
| 151 current_size.height() / touch_area.height()); | 151 current_size.height() / touch_area.height()); |
| 152 return ctm; | 152 return ctm; |
| 153 } | 153 } |
| 154 | 154 |
| 155 DisplayIdList GetCurrentDisplayIdList(const DisplayManager* display_manager) { |
| 156 DCHECK(display_manager->num_connected_displays()); |
| 157 if (display_manager->num_connected_displays() == 1) |
| 158 return DisplayIdList{display_manager->first_display_id()}; |
| 159 return display_manager->GetCurrentDisplayIdList(); |
| 160 } |
| 161 |
| 155 } // namespace | 162 } // namespace |
| 156 | 163 |
| 157 // This is to compute the scale ratio for the TouchEvent's radius. The | 164 // This is to compute the scale ratio for the TouchEvent's radius. The |
| 158 // configured resolution of the display is not always the same as the touch | 165 // configured resolution of the display is not always the same as the touch |
| 159 // screen's reporting resolution, e.g. the display could be set as | 166 // screen's reporting resolution, e.g. the display could be set as |
| 160 // 1920x1080 while the touchscreen is reporting touch position range at | 167 // 1920x1080 while the touchscreen is reporting touch position range at |
| 161 // 32767x32767. Touch radius is reported in the units the same as touch position | 168 // 32767x32767. Touch radius is reported in the units the same as touch position |
| 162 // so we need to scale the touch radius to be compatible with the display's | 169 // so we need to scale the touch radius to be compatible with the display's |
| 163 // resolution. We compute the scale as | 170 // resolution. We compute the scale as |
| 164 // sqrt of (display_area / touchscreen_area) | 171 // sqrt of (display_area / touchscreen_area) |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 for (const auto& device_id : touch_display.input_devices()) { | 308 for (const auto& device_id : touch_display.input_devices()) { |
| 302 device_manager->UpdateTouchInfoForDisplay( | 309 device_manager->UpdateTouchInfoForDisplay( |
| 303 target_display_id, device_id, | 310 target_display_id, device_id, |
| 304 GetTouchTransform(target_display, touch_display, | 311 GetTouchTransform(target_display, touch_display, |
| 305 FindTouchscreenById(device_id), fb_size)); | 312 FindTouchscreenById(device_id), fb_size)); |
| 306 } | 313 } |
| 307 } | 314 } |
| 308 | 315 |
| 309 void TouchTransformController::UpdateTouchTransforms() const { | 316 void TouchTransformController::UpdateTouchTransforms() const { |
| 310 ui::DeviceDataManager::GetInstance()->ClearTouchDeviceAssociations(); | 317 ui::DeviceDataManager::GetInstance()->ClearTouchDeviceAssociations(); |
| 318 if (display_manager_->num_connected_displays() == 0) |
| 319 return; |
| 311 | 320 |
| 312 // Display IDs and ManagedDisplayInfo for mirror or extended mode. | 321 DisplayIdList display_id_list = GetCurrentDisplayIdList(display_manager_); |
| 313 int64_t display1_id = kInvalidDisplayId; | 322 DCHECK(display_id_list.size()); |
| 314 int64_t display2_id = kInvalidDisplayId; | |
| 315 ManagedDisplayInfo display1; | |
| 316 ManagedDisplayInfo display2; | |
| 317 // Display ID and ManagedDisplayInfo for single display mode. | |
| 318 int64_t single_display_id = kInvalidDisplayId; | |
| 319 ManagedDisplayInfo single_display; | |
| 320 | 323 |
| 321 if (display_manager_->num_connected_displays() == 0) { | 324 DisplayInfoList display_info_list; |
| 322 return; | 325 |
| 323 } else if (display_manager_->num_connected_displays() == 1 || | 326 for (int64_t display_id : display_id_list) { |
| 324 display_manager_->IsInUnifiedMode()) { | 327 DCHECK(display_id != kInvalidDisplayId); |
| 325 single_display_id = display_manager_->first_display_id(); | 328 display_info_list.push_back(display_manager_->GetDisplayInfo(display_id)); |
| 326 DCHECK(single_display_id != kInvalidDisplayId); | 329 UpdateTouchRadius(display_info_list.back()); |
| 327 single_display = display_manager_->GetDisplayInfo(single_display_id); | |
| 328 UpdateTouchRadius(single_display); | |
| 329 } else { | |
| 330 DisplayIdList list = display_manager_->GetCurrentDisplayIdList(); | |
| 331 display1_id = list[0]; | |
| 332 display2_id = list[1]; | |
| 333 DCHECK(display1_id != kInvalidDisplayId && | |
| 334 display2_id != kInvalidDisplayId); | |
| 335 display1 = display_manager_->GetDisplayInfo(display1_id); | |
| 336 display2 = display_manager_->GetDisplayInfo(display2_id); | |
| 337 UpdateTouchRadius(display1); | |
| 338 UpdateTouchRadius(display2); | |
| 339 } | 330 } |
| 340 | 331 |
| 341 if (display_manager_->IsInMirrorMode()) { | 332 if (display_manager_->IsInMirrorMode()) { |
| 342 int64_t primary_display_id = Screen::GetScreen()->GetPrimaryDisplay().id(); | 333 std::size_t primary_display_id_index = |
| 343 if (display_manager_->SoftwareMirroringEnabled()) { | 334 std::distance(display_id_list.begin(), |
| 344 // In extended but software mirroring mode, there is a WindowTreeHost for | 335 std::find(display_id_list.begin(), display_id_list.end(), |
| 345 // each display, but all touches are forwarded to the primary root | 336 Screen::GetScreen()->GetPrimaryDisplay().id())); |
| 337 |
| 338 for (std::size_t index = 0; index < display_id_list.size(); index++) { |
| 339 // In extended but software mirroring mode, there is a WindowTreeHost |
| 340 // for each display, but all touches are forwarded to the primary root |
| 346 // window's WindowTreeHost. | 341 // window's WindowTreeHost. |
| 347 ManagedDisplayInfo target_display = | 342 // In mirror mode, there is just one WindowTreeHost and two displays. |
| 348 primary_display_id == display1_id ? display1 : display2; | 343 // Make the WindowTreeHost accept touch events from both displays. |
| 349 UpdateTouchTransform(target_display.id(), display1, target_display); | 344 std::size_t touch_display_index = |
| 350 UpdateTouchTransform(target_display.id(), display2, target_display); | 345 display_manager_->SoftwareMirroringEnabled() |
| 351 } else { | 346 ? primary_display_id_index |
| 352 // In mirror mode, there is just one WindowTreeHost and two displays. Make | 347 : index; |
| 353 // the WindowTreeHost accept touch events from both displays. | 348 UpdateTouchTransform(display_id_list[primary_display_id_index], |
| 354 UpdateTouchTransform(primary_display_id, display1, display1); | 349 display_info_list[index], |
| 355 UpdateTouchTransform(primary_display_id, display2, display2); | 350 display_info_list[touch_display_index]); |
| 356 } | 351 } |
| 357 return; | 352 return; |
| 358 } | 353 } |
| 359 | 354 |
| 360 if (display_manager_->num_connected_displays() > 1) { | 355 for (std::size_t index = 0; index < display_id_list.size(); index++) { |
| 361 // In actual extended mode, each display is associated with one | 356 UpdateTouchTransform(display_id_list[index], display_info_list[index], |
| 362 // WindowTreeHost. | 357 display_info_list[index]); |
| 363 UpdateTouchTransform(display1_id, display1, display1); | |
| 364 UpdateTouchTransform(display2_id, display2, display2); | |
| 365 return; | |
| 366 } | 358 } |
| 367 | |
| 368 // Single display mode. The WindowTreeHost has one associated display id. | |
| 369 UpdateTouchTransform(single_display_id, single_display, single_display); | |
| 370 } | 359 } |
| 371 | 360 |
| 372 void TouchTransformController::SetForCalibration(bool is_calibrating) { | 361 void TouchTransformController::SetForCalibration(bool is_calibrating) { |
| 373 is_calibrating_ = is_calibrating; | 362 is_calibrating_ = is_calibrating; |
| 374 UpdateTouchTransforms(); | 363 UpdateTouchTransforms(); |
| 375 } | 364 } |
| 376 | 365 |
| 377 } // namespace display | 366 } // namespace display |
| OLD | NEW |