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

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

Issue 2617043003: Move TouchTransformerController to ui/display/. (Closed)
Patch Set: Add comments. Created 3 years, 11 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 "ash/touch/touch_transformer_controller.h" 5 #include "ui/display/manager/chromeos/touch_transform_controller.h"
6 6
7 #include "ash/display/window_tree_host_manager.h" 7 #include <utility>
8 #include "ash/host/ash_window_tree_host.h" 8 #include <vector>
9 #include "ash/root_window_controller.h" 9
10 #include "ash/shell.h"
11 #include "third_party/skia/include/core/SkMatrix44.h" 10 #include "third_party/skia/include/core/SkMatrix44.h"
12 #include "ui/aura/window_tree_host.h"
13 #include "ui/display/display_layout.h" 11 #include "ui/display/display_layout.h"
14 #include "ui/display/manager/chromeos/display_configurator.h" 12 #include "ui/display/manager/chromeos/display_configurator.h"
15 #include "ui/display/manager/display_manager.h" 13 #include "ui/display/manager/display_manager.h"
14 #include "ui/display/manager/managed_display_info.h"
15 #include "ui/display/screen.h"
16 #include "ui/display/types/display_constants.h" 16 #include "ui/display/types/display_constants.h"
17 #include "ui/display/types/display_snapshot.h" 17 #include "ui/display/types/display_snapshot.h"
18 #include "ui/events/devices/device_data_manager.h" 18 #include "ui/events/devices/device_data_manager.h"
19 19
20 namespace ash { 20 namespace display {
21 21
22 namespace { 22 namespace {
23 23
24 display::DisplayManager* GetDisplayManager() {
25 return Shell::GetInstance()->display_manager();
26 }
27
28 ui::TouchscreenDevice FindTouchscreenById(int id) { 24 ui::TouchscreenDevice FindTouchscreenById(int id) {
29 const std::vector<ui::TouchscreenDevice>& touchscreens = 25 const std::vector<ui::TouchscreenDevice>& touchscreens =
30 ui::DeviceDataManager::GetInstance()->GetTouchscreenDevices(); 26 ui::DeviceDataManager::GetInstance()->GetTouchscreenDevices();
31 for (const auto& touchscreen : touchscreens) { 27 for (const auto& touchscreen : touchscreens) {
32 if (touchscreen.id == id) 28 if (touchscreen.id == id)
33 return touchscreen; 29 return touchscreen;
34 } 30 }
35 31
36 return ui::TouchscreenDevice(); 32 return ui::TouchscreenDevice();
37 } 33 }
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 111
116 // Create a transform matrix using the touch calibration data. 112 // Create a transform matrix using the touch calibration data.
117 ctm->ConcatTransform(gfx::Transform( 113 ctm->ConcatTransform(gfx::Transform(
118 x_constants.fData[0], x_constants.fData[1], 0, x_constants.fData[2], 114 x_constants.fData[0], x_constants.fData[1], 0, x_constants.fData[2],
119 y_constants.fData[0], y_constants.fData[1], 0, y_constants.fData[2], 0, 0, 115 y_constants.fData[0], y_constants.fData[1], 0, y_constants.fData[2], 0, 0,
120 1, 0, 0, 0, 0, 1)); 116 1, 0, 0, 0, 0, 1));
121 return true; 117 return true;
122 } 118 }
123 119
124 // Returns an uncalibrated touch transform. 120 // Returns an uncalibrated touch transform.
125 gfx::Transform GetUncalibratedTransform( 121 gfx::Transform GetUncalibratedTransform(const gfx::Transform& tm,
126 const gfx::Transform& tm, 122 const ManagedDisplayInfo& display,
127 const display::ManagedDisplayInfo& display, 123 const ManagedDisplayInfo& touch_display,
128 const display::ManagedDisplayInfo& touch_display, 124 const gfx::SizeF& touch_area,
129 const gfx::SizeF& touch_area, 125 const gfx::SizeF& touch_native_size) {
130 const gfx::SizeF& touch_native_size) {
131 gfx::SizeF current_size(display.bounds_in_native().size()); 126 gfx::SizeF current_size(display.bounds_in_native().size());
132 gfx::Transform ctm(tm); 127 gfx::Transform ctm(tm);
133 // Take care of panel fitting only if supported. Panel fitting is emulated 128 // Take care of panel fitting only if supported. Panel fitting is emulated
134 // in software mirroring mode (display != touch_display). 129 // in software mirroring mode (display != touch_display).
135 // If panel fitting is enabled then the aspect ratio is preserved and the 130 // If panel fitting is enabled then the aspect ratio is preserved and the
136 // display is scaled acordingly. In this case blank regions would be present 131 // display is scaled acordingly. In this case blank regions would be present
137 // in order to center the displayed area. 132 // in order to center the displayed area.
138 if (display.is_aspect_preserving_scaling() || 133 if (display.is_aspect_preserving_scaling() ||
139 display.id() != touch_display.id()) { 134 display.id() != touch_display.id()) {
140 float touch_calib_ar = 135 float touch_calib_ar =
(...skipping 19 matching lines...) Expand all
160 } // namespace 155 } // namespace
161 156
162 // This is to compute the scale ratio for the TouchEvent's radius. The 157 // This is to compute the scale ratio for the TouchEvent's radius. The
163 // configured resolution of the display is not always the same as the touch 158 // configured resolution of the display is not always the same as the touch
164 // screen's reporting resolution, e.g. the display could be set as 159 // screen's reporting resolution, e.g. the display could be set as
165 // 1920x1080 while the touchscreen is reporting touch position range at 160 // 1920x1080 while the touchscreen is reporting touch position range at
166 // 32767x32767. Touch radius is reported in the units the same as touch position 161 // 32767x32767. Touch radius is reported in the units the same as touch position
167 // so we need to scale the touch radius to be compatible with the display's 162 // so we need to scale the touch radius to be compatible with the display's
168 // resolution. We compute the scale as 163 // resolution. We compute the scale as
169 // sqrt of (display_area / touchscreen_area) 164 // sqrt of (display_area / touchscreen_area)
170 double TouchTransformerController::GetTouchResolutionScale( 165 double TouchTransformController::GetTouchResolutionScale(
171 const display::ManagedDisplayInfo& touch_display, 166 const ManagedDisplayInfo& touch_display,
172 const ui::TouchscreenDevice& touch_device) const { 167 const ui::TouchscreenDevice& touch_device) const {
173 if (touch_device.id == ui::InputDevice::kInvalidId || 168 if (touch_device.id == ui::InputDevice::kInvalidId ||
174 touch_device.size.IsEmpty() || 169 touch_device.size.IsEmpty() ||
175 touch_display.bounds_in_native().size().IsEmpty()) 170 touch_display.bounds_in_native().size().IsEmpty())
176 return 1.0; 171 return 1.0;
177 172
178 double display_area = touch_display.bounds_in_native().size().GetArea(); 173 double display_area = touch_display.bounds_in_native().size().GetArea();
179 double touch_area = touch_device.size.GetArea(); 174 double touch_area = touch_device.size.GetArea();
180 double ratio = std::sqrt(display_area / touch_area); 175 double ratio = std::sqrt(display_area / touch_area);
181 176
182 VLOG(2) << "Display size: " 177 VLOG(2) << "Display size: "
183 << touch_display.bounds_in_native().size().ToString() 178 << touch_display.bounds_in_native().size().ToString()
184 << ", Touchscreen size: " << touch_device.size.ToString() 179 << ", Touchscreen size: " << touch_device.size.ToString()
185 << ", Touch radius scale ratio: " << ratio; 180 << ", Touch radius scale ratio: " << ratio;
186 return ratio; 181 return ratio;
187 } 182 }
188 183
189 gfx::Transform TouchTransformerController::GetTouchTransform( 184 gfx::Transform TouchTransformController::GetTouchTransform(
190 const display::ManagedDisplayInfo& display, 185 const ManagedDisplayInfo& display,
191 const display::ManagedDisplayInfo& touch_display, 186 const ManagedDisplayInfo& touch_display,
192 const ui::TouchscreenDevice& touchscreen, 187 const ui::TouchscreenDevice& touchscreen,
193 const gfx::Size& framebuffer_size) const { 188 const gfx::Size& framebuffer_size) const {
194 auto current_size = gfx::SizeF(display.bounds_in_native().size()); 189 auto current_size = gfx::SizeF(display.bounds_in_native().size());
195 auto touch_native_size = gfx::SizeF(touch_display.GetNativeModeSize()); 190 auto touch_native_size = gfx::SizeF(touch_display.GetNativeModeSize());
196 #if defined(USE_OZONE) 191 #if defined(USE_OZONE)
197 auto touch_area = gfx::SizeF(touchscreen.size); 192 auto touch_area = gfx::SizeF(touchscreen.size);
198 #elif defined(USE_X11) 193 #elif defined(USE_X11)
199 // On X11 touches are reported in the framebuffer coordinate space. 194 // On X11 touches are reported in the framebuffer coordinate space.
200 auto touch_area = gfx::SizeF(framebuffer_size); 195 auto touch_area = gfx::SizeF(framebuffer_size);
201 #endif 196 #endif
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 // Solve for coefficients and compute transform matrix. 251 // Solve for coefficients and compute transform matrix.
257 gfx::Transform stored_ctm; 252 gfx::Transform stored_ctm;
258 if (!GetCalibratedTransform( 253 if (!GetCalibratedTransform(
259 touch_display.GetTouchCalibrationData().point_pairs, pre_transform, 254 touch_display.GetTouchCalibrationData().point_pairs, pre_transform,
260 &stored_ctm)) { 255 &stored_ctm)) {
261 // TODO(malaykeshav): This can be checked at the calibration step before 256 // TODO(malaykeshav): This can be checked at the calibration step before
262 // storing the calibration associated data. This will allow us to explicitly 257 // storing the calibration associated data. This will allow us to explicitly
263 // inform the user with proper UX. 258 // inform the user with proper UX.
264 259
265 // Clear stored calibration data. 260 // Clear stored calibration data.
266 GetDisplayManager()->ClearTouchCalibrationData(touch_display.id()); 261 display_manager_->ClearTouchCalibrationData(touch_display.id());
267 262
268 // Return uncalibrated transform. 263 // Return uncalibrated transform.
269 return GetUncalibratedTransform(ctm, display, touch_display, touch_area, 264 return GetUncalibratedTransform(ctm, display, touch_display, touch_area,
270 touch_native_size); 265 touch_native_size);
271 } 266 }
272 267
273 stored_ctm.ConcatTransform(ctm); 268 stored_ctm.ConcatTransform(ctm);
274 return stored_ctm; 269 return stored_ctm;
275 } 270 }
276 271
277 TouchTransformerController::TouchTransformerController() { 272 TouchTransformController::TouchTransformController(
278 Shell::GetInstance()->window_tree_host_manager()->AddObserver(this); 273 DisplayConfigurator* display_configurator,
279 } 274 DisplayManager* display_manager)
275 : display_configurator_(display_configurator),
276 display_manager_(display_manager) {}
280 277
281 TouchTransformerController::~TouchTransformerController() { 278 TouchTransformController::~TouchTransformController() {}
282 Shell::GetInstance()->window_tree_host_manager()->RemoveObserver(this);
283 }
284 279
285 void TouchTransformerController::UpdateTouchRadius( 280 void TouchTransformController::UpdateTouchRadius(
286 const display::ManagedDisplayInfo& display) const { 281 const ManagedDisplayInfo& display) const {
287 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance(); 282 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance();
288 for (const auto& device_id : display.input_devices()) { 283 for (const auto& device_id : display.input_devices()) {
289 device_manager->UpdateTouchRadiusScale( 284 device_manager->UpdateTouchRadiusScale(
290 device_id, 285 device_id,
291 GetTouchResolutionScale(display, FindTouchscreenById(device_id))); 286 GetTouchResolutionScale(display, FindTouchscreenById(device_id)));
292 } 287 }
293 } 288 }
294 289
295 void TouchTransformerController::UpdateTouchTransform( 290 void TouchTransformController::UpdateTouchTransform(
296 int64_t target_display_id, 291 int64_t target_display_id,
297 const display::ManagedDisplayInfo& touch_display, 292 const ManagedDisplayInfo& touch_display,
298 const display::ManagedDisplayInfo& target_display) const { 293 const ManagedDisplayInfo& target_display) const {
299 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance(); 294 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance();
300 gfx::Size fb_size = 295 gfx::Size fb_size = display_configurator_->framebuffer_size();
301 Shell::GetInstance()->display_configurator()->framebuffer_size();
302 for (const auto& device_id : touch_display.input_devices()) { 296 for (const auto& device_id : touch_display.input_devices()) {
303 device_manager->UpdateTouchInfoForDisplay( 297 device_manager->UpdateTouchInfoForDisplay(
304 target_display_id, device_id, 298 target_display_id, device_id,
305 GetTouchTransform(target_display, touch_display, 299 GetTouchTransform(target_display, touch_display,
306 FindTouchscreenById(device_id), fb_size)); 300 FindTouchscreenById(device_id), fb_size));
307 } 301 }
308 } 302 }
309 303
310 void TouchTransformerController::UpdateTouchTransformer() const { 304 void TouchTransformController::UpdateTouchTransforms() const {
311 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance(); 305 ui::DeviceDataManager::GetInstance()->ClearTouchDeviceAssociations();
312 device_manager->ClearTouchDeviceAssociations();
313 306
314 // Display IDs and display::ManagedDisplayInfo for mirror or extended mode. 307 // Display IDs and ManagedDisplayInfo for mirror or extended mode.
315 int64_t display1_id = display::kInvalidDisplayId; 308 int64_t display1_id = kInvalidDisplayId;
316 int64_t display2_id = display::kInvalidDisplayId; 309 int64_t display2_id = kInvalidDisplayId;
317 display::ManagedDisplayInfo display1; 310 ManagedDisplayInfo display1;
318 display::ManagedDisplayInfo display2; 311 ManagedDisplayInfo display2;
319 // Display ID and display::ManagedDisplayInfo for single display mode. 312 // Display ID and ManagedDisplayInfo for single display mode.
320 int64_t single_display_id = display::kInvalidDisplayId; 313 int64_t single_display_id = kInvalidDisplayId;
321 display::ManagedDisplayInfo single_display; 314 ManagedDisplayInfo single_display;
322 315
323 WindowTreeHostManager* window_tree_host_manager = 316 if (display_manager_->num_connected_displays() == 0) {
324 Shell::GetInstance()->window_tree_host_manager();
325 display::DisplayManager* display_manager = GetDisplayManager();
326 if (display_manager->num_connected_displays() == 0) {
327 return; 317 return;
328 } else if (display_manager->num_connected_displays() == 1 || 318 } else if (display_manager_->num_connected_displays() == 1 ||
329 display_manager->IsInUnifiedMode()) { 319 display_manager_->IsInUnifiedMode()) {
330 single_display_id = display_manager->first_display_id(); 320 single_display_id = display_manager_->first_display_id();
331 DCHECK(single_display_id != display::kInvalidDisplayId); 321 DCHECK(single_display_id != kInvalidDisplayId);
332 single_display = display_manager->GetDisplayInfo(single_display_id); 322 single_display = display_manager_->GetDisplayInfo(single_display_id);
333 UpdateTouchRadius(single_display); 323 UpdateTouchRadius(single_display);
334 } else { 324 } else {
335 display::DisplayIdList list = display_manager->GetCurrentDisplayIdList(); 325 DisplayIdList list = display_manager_->GetCurrentDisplayIdList();
336 display1_id = list[0]; 326 display1_id = list[0];
337 display2_id = list[1]; 327 display2_id = list[1];
338 DCHECK(display1_id != display::kInvalidDisplayId && 328 DCHECK(display1_id != kInvalidDisplayId &&
339 display2_id != display::kInvalidDisplayId); 329 display2_id != kInvalidDisplayId);
340 display1 = display_manager->GetDisplayInfo(display1_id); 330 display1 = display_manager_->GetDisplayInfo(display1_id);
341 display2 = display_manager->GetDisplayInfo(display2_id); 331 display2 = display_manager_->GetDisplayInfo(display2_id);
342 UpdateTouchRadius(display1); 332 UpdateTouchRadius(display1);
343 UpdateTouchRadius(display2); 333 UpdateTouchRadius(display2);
344 } 334 }
345 335
346 if (display_manager->IsInMirrorMode()) { 336 if (display_manager_->IsInMirrorMode()) {
347 int64_t primary_display_id = 337 int64_t primary_display_id = Screen::GetScreen()->GetPrimaryDisplay().id();
348 window_tree_host_manager->GetPrimaryDisplayId(); 338 if (display_manager_->SoftwareMirroringEnabled()) {
349 if (GetDisplayManager()->SoftwareMirroringEnabled()) {
350 // In extended but software mirroring mode, there is a WindowTreeHost for 339 // In extended but software mirroring mode, there is a WindowTreeHost for
351 // each display, but all touches are forwarded to the primary root 340 // each display, but all touches are forwarded to the primary root
352 // window's WindowTreeHost. 341 // window's WindowTreeHost.
353 display::ManagedDisplayInfo target_display = 342 ManagedDisplayInfo target_display =
354 primary_display_id == display1_id ? display1 : display2; 343 primary_display_id == display1_id ? display1 : display2;
355 UpdateTouchTransform(target_display.id(), display1, target_display); 344 UpdateTouchTransform(target_display.id(), display1, target_display);
356 UpdateTouchTransform(target_display.id(), display2, target_display); 345 UpdateTouchTransform(target_display.id(), display2, target_display);
357 } else { 346 } else {
358 // In mirror mode, there is just one WindowTreeHost and two displays. Make 347 // In mirror mode, there is just one WindowTreeHost and two displays. Make
359 // the WindowTreeHost accept touch events from both displays. 348 // the WindowTreeHost accept touch events from both displays.
360 UpdateTouchTransform(primary_display_id, display1, display1); 349 UpdateTouchTransform(primary_display_id, display1, display1);
361 UpdateTouchTransform(primary_display_id, display2, display2); 350 UpdateTouchTransform(primary_display_id, display2, display2);
362 } 351 }
363 return; 352 return;
364 } 353 }
365 354
366 if (display_manager->num_connected_displays() > 1) { 355 if (display_manager_->num_connected_displays() > 1) {
367 // In actual extended mode, each display is associated with one 356 // In actual extended mode, each display is associated with one
368 // WindowTreeHost. 357 // WindowTreeHost.
369 UpdateTouchTransform(display1_id, display1, display1); 358 UpdateTouchTransform(display1_id, display1, display1);
370 UpdateTouchTransform(display2_id, display2, display2); 359 UpdateTouchTransform(display2_id, display2, display2);
371 return; 360 return;
372 } 361 }
373 362
374 // Single display mode. The WindowTreeHost has one associated display id. 363 // Single display mode. The WindowTreeHost has one associated display id.
375 UpdateTouchTransform(single_display_id, single_display, single_display); 364 UpdateTouchTransform(single_display_id, single_display, single_display);
376 } 365 }
377 366
378 void TouchTransformerController::OnDisplaysInitialized() { 367 } // namespace display
379 UpdateTouchTransformer();
380 }
381
382 void TouchTransformerController::OnDisplayConfigurationChanged() {
383 UpdateTouchTransformer();
384 }
385
386 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698