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

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

Issue 2887413004: chromeos: moves setting of touch state to a separate class (Closed)
Patch Set: feedback Created 3 years, 7 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
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"
11 #include "ui/display/display_layout.h" 11 #include "ui/display/display_layout.h"
12 #include "ui/display/manager/chromeos/display_configurator.h" 12 #include "ui/display/manager/chromeos/display_configurator.h"
13 #include "ui/display/manager/chromeos/touch_device_transform.h"
14 #include "ui/display/manager/chromeos/touch_transform_setter.h"
13 #include "ui/display/manager/display_manager.h" 15 #include "ui/display/manager/display_manager.h"
14 #include "ui/display/manager/managed_display_info.h" 16 #include "ui/display/manager/managed_display_info.h"
15 #include "ui/display/screen.h" 17 #include "ui/display/screen.h"
16 #include "ui/display/types/display_constants.h" 18 #include "ui/display/types/display_constants.h"
17 #include "ui/display/types/display_snapshot.h" 19 #include "ui/display/types/display_snapshot.h"
18 #include "ui/events/devices/device_data_manager.h" 20 #include "ui/events/devices/input_device_manager.h"
19 21
20 namespace display { 22 namespace display {
21 23
22 namespace { 24 namespace {
23 25
24 ui::TouchscreenDevice FindTouchscreenById(int id) { 26 ui::TouchscreenDevice FindTouchscreenById(int id) {
25 const std::vector<ui::TouchscreenDevice>& touchscreens = 27 const std::vector<ui::TouchscreenDevice>& touchscreens =
26 ui::DeviceDataManager::GetInstance()->GetTouchscreenDevices(); 28 ui::InputDeviceManager::GetInstance()->GetTouchscreenDevices();
27 for (const auto& touchscreen : touchscreens) { 29 for (const auto& touchscreen : touchscreens) {
28 if (touchscreen.id == id) 30 if (touchscreen.id == id)
29 return touchscreen; 31 return touchscreen;
30 } 32 }
31 33
32 return ui::TouchscreenDevice(); 34 return ui::TouchscreenDevice();
33 } 35 }
34 36
35 // Given an array of touch point and display point pairs, this function computes 37 // Given an array of touch point and display point pairs, this function computes
36 // and returns the constants(defined below) using a least fit algorithm. 38 // and returns the constants(defined below) using a least fit algorithm.
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 156
155 DisplayIdList GetCurrentDisplayIdList(const DisplayManager* display_manager) { 157 DisplayIdList GetCurrentDisplayIdList(const DisplayManager* display_manager) {
156 DCHECK(display_manager->num_connected_displays()); 158 DCHECK(display_manager->num_connected_displays());
157 if (display_manager->num_connected_displays() == 1) 159 if (display_manager->num_connected_displays() == 1)
158 return DisplayIdList{display_manager->first_display_id()}; 160 return DisplayIdList{display_manager->first_display_id()};
159 return display_manager->GetCurrentDisplayIdList(); 161 return display_manager->GetCurrentDisplayIdList();
160 } 162 }
161 163
162 } // namespace 164 } // namespace
163 165
166 TouchTransformController::UpdateData::UpdateData() = default;
167
168 TouchTransformController::UpdateData::~UpdateData() = default;
169
164 // This is to compute the scale ratio for the TouchEvent's radius. The 170 // This is to compute the scale ratio for the TouchEvent's radius. The
165 // configured resolution of the display is not always the same as the touch 171 // configured resolution of the display is not always the same as the touch
166 // screen's reporting resolution, e.g. the display could be set as 172 // screen's reporting resolution, e.g. the display could be set as
167 // 1920x1080 while the touchscreen is reporting touch position range at 173 // 1920x1080 while the touchscreen is reporting touch position range at
168 // 32767x32767. Touch radius is reported in the units the same as touch position 174 // 32767x32767. Touch radius is reported in the units the same as touch position
169 // so we need to scale the touch radius to be compatible with the display's 175 // so we need to scale the touch radius to be compatible with the display's
170 // resolution. We compute the scale as 176 // resolution. We compute the scale as
171 // sqrt of (display_area / touchscreen_area) 177 // sqrt of (display_area / touchscreen_area)
172 double TouchTransformController::GetTouchResolutionScale( 178 double TouchTransformController::GetTouchResolutionScale(
173 const ManagedDisplayInfo& touch_display, 179 const ManagedDisplayInfo& touch_display,
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 return GetUncalibratedTransform(ctm, display, touch_display, touch_area, 282 return GetUncalibratedTransform(ctm, display, touch_display, touch_area,
277 touch_native_size); 283 touch_native_size);
278 } 284 }
279 285
280 stored_ctm.ConcatTransform(ctm); 286 stored_ctm.ConcatTransform(ctm);
281 return stored_ctm; 287 return stored_ctm;
282 } 288 }
283 289
284 TouchTransformController::TouchTransformController( 290 TouchTransformController::TouchTransformController(
285 DisplayConfigurator* display_configurator, 291 DisplayConfigurator* display_configurator,
286 DisplayManager* display_manager) 292 DisplayManager* display_manager,
293 std::unique_ptr<TouchTransformSetter> setter)
287 : display_configurator_(display_configurator), 294 : display_configurator_(display_configurator),
288 display_manager_(display_manager) {} 295 display_manager_(display_manager),
296 setter_(std::move(setter)) {}
289 297
290 TouchTransformController::~TouchTransformController() {} 298 TouchTransformController::~TouchTransformController() {}
291 299
300 void TouchTransformController::UpdateTouchTransforms() const {
301 UpdateData update_data;
302 UpdateTouchTransforms(&update_data);
303 setter_->ConfigureTouchDevices(update_data.device_to_scale,
304 update_data.touch_device_transforms);
305 }
306
292 void TouchTransformController::UpdateTouchRadius( 307 void TouchTransformController::UpdateTouchRadius(
293 const ManagedDisplayInfo& display) const { 308 const ManagedDisplayInfo& display,
294 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance(); 309 UpdateData* update_data) const {
295 for (const auto& device_id : display.input_devices()) { 310 for (const auto& device_id : display.input_devices()) {
296 device_manager->UpdateTouchRadiusScale( 311 DCHECK_EQ(0u, update_data->device_to_scale.count(device_id));
297 device_id, 312 update_data->device_to_scale[device_id] =
298 GetTouchResolutionScale(display, FindTouchscreenById(device_id))); 313 GetTouchResolutionScale(display, FindTouchscreenById(device_id));
299 } 314 }
300 } 315 }
301 316
302 void TouchTransformController::UpdateTouchTransform( 317 void TouchTransformController::UpdateTouchTransform(
303 int64_t target_display_id, 318 int64_t target_display_id,
304 const ManagedDisplayInfo& touch_display, 319 const ManagedDisplayInfo& touch_display,
305 const ManagedDisplayInfo& target_display) const { 320 const ManagedDisplayInfo& target_display,
306 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance(); 321 UpdateData* update_data) const {
322 TouchDeviceTransform touch_device_transform;
323 touch_device_transform.display_id = target_display_id;
307 gfx::Size fb_size = display_configurator_->framebuffer_size(); 324 gfx::Size fb_size = display_configurator_->framebuffer_size();
308 for (const auto& device_id : touch_display.input_devices()) { 325 for (const auto& device_id : touch_display.input_devices()) {
309 device_manager->UpdateTouchInfoForDisplay( 326 touch_device_transform.device_id = device_id;
310 target_display_id, device_id, 327 touch_device_transform.transform = GetTouchTransform(
311 GetTouchTransform(target_display, touch_display, 328 target_display, touch_display, FindTouchscreenById(device_id), fb_size);
312 FindTouchscreenById(device_id), fb_size)); 329 update_data->touch_device_transforms.push_back(touch_device_transform);
313 } 330 }
314 } 331 }
315 332
316 void TouchTransformController::UpdateTouchTransforms() const { 333 void TouchTransformController::UpdateTouchTransforms(
317 ui::DeviceDataManager::GetInstance()->ClearTouchDeviceAssociations(); 334 UpdateData* update_data) const {
318 if (display_manager_->num_connected_displays() == 0) 335 if (display_manager_->num_connected_displays() == 0)
319 return; 336 return;
320 337
321 DisplayIdList display_id_list = GetCurrentDisplayIdList(display_manager_); 338 DisplayIdList display_id_list = GetCurrentDisplayIdList(display_manager_);
322 DCHECK(display_id_list.size()); 339 DCHECK(display_id_list.size());
323 340
324 DisplayInfoList display_info_list; 341 DisplayInfoList display_info_list;
325 342
326 for (int64_t display_id : display_id_list) { 343 for (int64_t display_id : display_id_list) {
327 DCHECK(display_id != kInvalidDisplayId); 344 DCHECK(display_id != kInvalidDisplayId);
328 display_info_list.push_back(display_manager_->GetDisplayInfo(display_id)); 345 display_info_list.push_back(display_manager_->GetDisplayInfo(display_id));
329 UpdateTouchRadius(display_info_list.back()); 346 UpdateTouchRadius(display_info_list.back(), update_data);
330 } 347 }
331 348
332 if (display_manager_->IsInMirrorMode()) { 349 if (display_manager_->IsInMirrorMode()) {
333 std::size_t primary_display_id_index = 350 std::size_t primary_display_id_index =
334 std::distance(display_id_list.begin(), 351 std::distance(display_id_list.begin(),
335 std::find(display_id_list.begin(), display_id_list.end(), 352 std::find(display_id_list.begin(), display_id_list.end(),
336 Screen::GetScreen()->GetPrimaryDisplay().id())); 353 Screen::GetScreen()->GetPrimaryDisplay().id()));
337 354
338 for (std::size_t index = 0; index < display_id_list.size(); index++) { 355 for (std::size_t index = 0; index < display_id_list.size(); index++) {
339 // In extended but software mirroring mode, there is a WindowTreeHost 356 // In extended but software mirroring mode, there is a WindowTreeHost
340 // for each display, but all touches are forwarded to the primary root 357 // for each display, but all touches are forwarded to the primary root
341 // window's WindowTreeHost. 358 // window's WindowTreeHost.
342 // In mirror mode, there is just one WindowTreeHost and two displays. 359 // In mirror mode, there is just one WindowTreeHost and two displays.
343 // Make the WindowTreeHost accept touch events from both displays. 360 // Make the WindowTreeHost accept touch events from both displays.
344 std::size_t touch_display_index = 361 std::size_t touch_display_index =
345 display_manager_->SoftwareMirroringEnabled() 362 display_manager_->SoftwareMirroringEnabled()
346 ? primary_display_id_index 363 ? primary_display_id_index
347 : index; 364 : index;
348 UpdateTouchTransform(display_id_list[primary_display_id_index], 365 UpdateTouchTransform(display_id_list[primary_display_id_index],
349 display_info_list[index], 366 display_info_list[index],
350 display_info_list[touch_display_index]); 367 display_info_list[touch_display_index], update_data);
351 } 368 }
352 return; 369 return;
353 } 370 }
354 371
355 for (std::size_t index = 0; index < display_id_list.size(); index++) { 372 for (std::size_t index = 0; index < display_id_list.size(); index++) {
356 UpdateTouchTransform(display_id_list[index], display_info_list[index], 373 UpdateTouchTransform(display_id_list[index], display_info_list[index],
357 display_info_list[index]); 374 display_info_list[index], update_data);
358 } 375 }
359 } 376 }
360 377
361 void TouchTransformController::SetForCalibration(bool is_calibrating) { 378 void TouchTransformController::SetForCalibration(bool is_calibrating) {
362 is_calibrating_ = is_calibrating; 379 is_calibrating_ = is_calibrating;
363 UpdateTouchTransforms(); 380 UpdateTouchTransforms();
364 } 381 }
365 382
366 } // namespace display 383 } // namespace display
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698