Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: ui/display/manager/chromeos/touch_transform_controller.cc

Issue 2653493008: Touch transform controller now handles more than 2 displays (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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) {
oshima 2017/01/24 18:22:07 DisplayManager already has GetCurrentDisplayIdList
malaykeshav 2017/01/24 21:20:53 I think GetCurrentDisplayIdList() is still a bette
156 if (display_manager->num_connected_displays() == 0)
oshima 2017/01/25 01:17:24 DCHECK because this condition is already checked o
157 return DisplayIdList{};
158 if (display_manager->num_connected_displays() == 1)
159 return DisplayIdList{display_manager->first_display_id()};
160 return display_manager->GetCurrentDisplayIdList();
oshima 2017/01/24 18:22:07 This returns single display when mirrored. is it o
malaykeshav 2017/01/24 21:20:53 No. It returns 2 IDs if I am not wrong.
oshima 2017/01/25 01:17:24 You're right. please disregard the comment.
161 }
162
155 } // namespace 163 } // namespace
156 164
157 // This is to compute the scale ratio for the TouchEvent's radius. The 165 // 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 166 // 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 167 // screen's reporting resolution, e.g. the display could be set as
160 // 1920x1080 while the touchscreen is reporting touch position range at 168 // 1920x1080 while the touchscreen is reporting touch position range at
161 // 32767x32767. Touch radius is reported in the units the same as touch position 169 // 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 170 // so we need to scale the touch radius to be compatible with the display's
163 // resolution. We compute the scale as 171 // resolution. We compute the scale as
164 // sqrt of (display_area / touchscreen_area) 172 // sqrt of (display_area / touchscreen_area)
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 for (const auto& device_id : touch_display.input_devices()) { 309 for (const auto& device_id : touch_display.input_devices()) {
302 device_manager->UpdateTouchInfoForDisplay( 310 device_manager->UpdateTouchInfoForDisplay(
303 target_display_id, device_id, 311 target_display_id, device_id,
304 GetTouchTransform(target_display, touch_display, 312 GetTouchTransform(target_display, touch_display,
305 FindTouchscreenById(device_id), fb_size)); 313 FindTouchscreenById(device_id), fb_size));
306 } 314 }
307 } 315 }
308 316
309 void TouchTransformController::UpdateTouchTransforms() const { 317 void TouchTransformController::UpdateTouchTransforms() const {
310 ui::DeviceDataManager::GetInstance()->ClearTouchDeviceAssociations(); 318 ui::DeviceDataManager::GetInstance()->ClearTouchDeviceAssociations();
319 if (display_manager_->num_connected_displays() == 0)
320 return;
311 321
312 // Display IDs and ManagedDisplayInfo for mirror or extended mode. 322 DisplayIdList display_id_list = GetCurrentDisplayIdList(display_manager_);
313 int64_t display1_id = kInvalidDisplayId; 323 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 324
321 if (display_manager_->num_connected_displays() == 0) { 325 DisplayInfoList display_info_list;
322 return; 326
323 } else if (display_manager_->num_connected_displays() == 1 || 327 for (int64_t display_id : display_id_list) {
324 display_manager_->IsInUnifiedMode()) { 328 DCHECK(display_id != kInvalidDisplayId);
325 single_display_id = display_manager_->first_display_id(); 329 display_info_list.push_back(display_manager_->GetDisplayInfo(display_id));
326 DCHECK(single_display_id != kInvalidDisplayId); 330 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 } 331 }
340 332
341 if (display_manager_->IsInMirrorMode()) { 333 if (display_manager_->IsInMirrorMode()) {
342 int64_t primary_display_id = Screen::GetScreen()->GetPrimaryDisplay().id(); 334 std::size_t primary_display_id_index =
343 if (display_manager_->SoftwareMirroringEnabled()) { 335 std::distance(display_id_list.begin(),
344 // In extended but software mirroring mode, there is a WindowTreeHost for 336 std::find(display_id_list.begin(), display_id_list.end(),
345 // each display, but all touches are forwarded to the primary root 337 Screen::GetScreen()->GetPrimaryDisplay().id()));
338
339 for (std::size_t index = 0; index < display_id_list.size(); index++) {
340 // In extended but software mirroring mode, there is a WindowTreeHost
341 // for each display, but all touches are forwarded to the primary root
346 // window's WindowTreeHost. 342 // window's WindowTreeHost.
347 ManagedDisplayInfo target_display = 343 // In mirror mode, there is just one WindowTreeHost and two displays.
348 primary_display_id == display1_id ? display1 : display2; 344 // Make the WindowTreeHost accept touch events from both displays.
349 UpdateTouchTransform(target_display.id(), display1, target_display); 345 std::size_t touch_display_index =
350 UpdateTouchTransform(target_display.id(), display2, target_display); 346 display_manager_->SoftwareMirroringEnabled()
351 } else { 347 ? primary_display_id_index
352 // In mirror mode, there is just one WindowTreeHost and two displays. Make 348 : index;
353 // the WindowTreeHost accept touch events from both displays. 349 UpdateTouchTransform(display_id_list[primary_display_id_index],
354 UpdateTouchTransform(primary_display_id, display1, display1); 350 display_info_list[index],
355 UpdateTouchTransform(primary_display_id, display2, display2); 351 display_info_list[touch_display_index]);
356 } 352 }
357 return; 353 return;
358 } 354 }
359 355
360 if (display_manager_->num_connected_displays() > 1) { 356 for (std::size_t index = 0; index < display_id_list.size(); index++) {
361 // In actual extended mode, each display is associated with one 357 UpdateTouchTransform(display_id_list[index], display_info_list[index],
362 // WindowTreeHost. 358 display_info_list[index]);
363 UpdateTouchTransform(display1_id, display1, display1);
364 UpdateTouchTransform(display2_id, display2, display2);
365 return;
366 } 359 }
367
368 // Single display mode. The WindowTreeHost has one associated display id.
369 UpdateTouchTransform(single_display_id, single_display, single_display);
370 } 360 }
371 361
372 void TouchTransformController::SetForCalibration(bool is_calibrating) { 362 void TouchTransformController::SetForCalibration(bool is_calibrating) {
373 is_calibrating_ = is_calibrating; 363 is_calibrating_ = is_calibrating;
374 UpdateTouchTransforms(); 364 UpdateTouchTransforms();
375 } 365 }
376 366
377 } // namespace display 367 } // namespace display
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698