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

Side by Side Diff: ash/touch/touch_transformer_controller_unittest.cc

Issue 2557163002: Implements computation of touch calibration transform using user provided data (Closed)
Patch Set: Fixed unused variable error Created 4 years 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 "ash/touch/touch_transformer_controller.h"
6 6
7 #include "ash/shell.h" 7 #include "ash/shell.h"
8 #include "ash/test/ash_test_base.h" 8 #include "ash/test/ash_test_base.h"
9 #include "base/rand_util.h"
10 #include "base/strings/string_number_conversions.h"
9 #include "ui/aura/window_tree_host.h" 11 #include "ui/aura/window_tree_host.h"
10 #include "ui/events/devices/device_data_manager.h" 12 #include "ui/events/devices/device_data_manager.h"
11 13
12 namespace ash { 14 namespace ash {
13 15
14 namespace { 16 namespace {
15 17
18 constexpr int kDisplayId1 = 1;
19 constexpr int kTouchId1 = 5;
20
16 display::ManagedDisplayInfo CreateDisplayInfo(int64_t id, 21 display::ManagedDisplayInfo CreateDisplayInfo(int64_t id,
17 unsigned int touch_device_id, 22 unsigned int touch_device_id,
18 const gfx::Rect& bounds) { 23 const gfx::Rect& bounds) {
19 display::ManagedDisplayInfo info(id, std::string(), false); 24 display::ManagedDisplayInfo info(id, std::string(), false);
20 info.SetBounds(bounds); 25 info.SetBounds(bounds);
21 info.AddInputDevice(touch_device_id); 26 info.AddInputDevice(touch_device_id);
22 27
23 // Create a default mode. 28 // Create a default mode.
24 display::ManagedDisplayInfo::ManagedDisplayModeList default_modes( 29 display::ManagedDisplayInfo::ManagedDisplayModeList default_modes(
25 1, make_scoped_refptr( 30 1, make_scoped_refptr(
26 new display::ManagedDisplayMode(bounds.size(), 60, false, true))); 31 new display::ManagedDisplayMode(bounds.size(), 60, false, true)));
27 info.SetManagedDisplayModes(default_modes); 32 info.SetManagedDisplayModes(default_modes);
28 33
29 return info; 34 return info;
30 } 35 }
31 36
32 ui::TouchscreenDevice CreateTouchscreenDevice(unsigned int id, 37 ui::TouchscreenDevice CreateTouchscreenDevice(unsigned int id,
33 const gfx::Size& size) { 38 const gfx::Size& size) {
34 return ui::TouchscreenDevice(id, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, 39 return ui::TouchscreenDevice(id, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL,
35 std::string(), size, 0); 40 std::string(), size, 0);
36 } 41 }
37 42
43 std::string GetTouchPointString(
44 const display::TouchCalibrationData::CalibrationPointPairQuad& pts) {
45 std::string str = "Failed for point pairs: ";
46 for (std::size_t row = 0; row < pts.size(); row++) {
47 str += "{(" + base::IntToString(pts[row].first.x()) + "," +
48 base::IntToString(pts[row].first.y()) + "), (" +
49 base::IntToString(pts[row].second.x()) + "," +
50 base::IntToString(pts[row].second.y()) + ")} ";
51 }
52 return str;
53 }
54
55 // Checks if the touch input has been calibrated properly. The input is said to
56 // be calibrated if any touch input is transformed to the correct corresponding
57 // display point within an error delta of |max_error_delta.width()| along the X
58 // axis and |max_error_delta.height()| along the Y axis;
59 void CheckPointsOfInterests(const int touch_id,
60 const gfx::Size& touch_size,
61 const gfx::Size& display_size,
62 const gfx::Size& max_error_delta,
63 const std::string& error_msg) {
64 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance();
65 float x, y;
66
67 // Origin of the touch device should correspond to origin of the display.
68 x = y = 0.0;
69 device_manager->ApplyTouchTransformer(touch_id, &x, &y);
70 EXPECT_NEAR(0, x, max_error_delta.width()) << error_msg;
71 EXPECT_NEAR(0, y, max_error_delta.height()) << error_msg;
72
73 // Center of the touch device should correspond to the center of the display
74 // device.
75 x = touch_size.width() / 2;
76 y = touch_size.height() / 2;
77 device_manager->ApplyTouchTransformer(touch_id, &x, &y);
78 EXPECT_NEAR(display_size.width() / 2, x, max_error_delta.width())
79 << error_msg;
80 EXPECT_NEAR(display_size.height() / 2, y, max_error_delta.height())
81 << error_msg;
82
83 // Bottom right corner of the touch device should correspond to rightmost
84 // corner of display device.
85 x = touch_size.width();
86 y = touch_size.height();
87 device_manager->ApplyTouchTransformer(touch_id, &x, &y);
88 EXPECT_NEAR(display_size.width(), x, max_error_delta.width()) << error_msg;
89 EXPECT_NEAR(display_size.height(), y, max_error_delta.height()) << error_msg;
90 }
91
38 } // namespace 92 } // namespace
39 93
40 typedef test::AshTestBase TouchTransformerControllerTest; 94 class TouchTransformerControllerTest : public test::AshTestBase {
95 public:
96 TouchTransformerControllerTest() {}
97 ~TouchTransformerControllerTest() override {}
98
99 gfx::Transform GetTouchTransform(
100 const display::ManagedDisplayInfo& display,
101 const display::ManagedDisplayInfo& touch_display,
102 const ui::TouchscreenDevice& touchscreen,
103 const gfx::Size& framebuffer_size) const {
104 return Shell::GetInstance()
105 ->touch_transformer_controller()
106 ->GetTouchTransform(display, touch_display, touchscreen,
107 framebuffer_size);
108 }
109
110 double GetTouchResolutionScale(
111 const display::ManagedDisplayInfo& touch_display,
112 const ui::TouchscreenDevice& touch_device) const {
113 return Shell::GetInstance()
114 ->touch_transformer_controller()
115 ->GetTouchResolutionScale(touch_display, touch_device);
116 }
117
118 private:
119 DISALLOW_COPY_AND_ASSIGN(TouchTransformerControllerTest);
120 };
41 121
42 TEST_F(TouchTransformerControllerTest, MirrorModeLetterboxing) { 122 TEST_F(TouchTransformerControllerTest, MirrorModeLetterboxing) {
43 // The internal display has native resolution of 2560x1700, and in 123 // The internal display has native resolution of 2560x1700, and in
44 // mirror mode it is configured as 1920x1200. This is in letterboxing 124 // mirror mode it is configured as 1920x1200. This is in letterboxing
45 // mode. 125 // mode.
46 display::ManagedDisplayInfo internal_display_info = 126 display::ManagedDisplayInfo internal_display_info =
47 CreateDisplayInfo(1, 10u, gfx::Rect(0, 0, 1920, 1200)); 127 CreateDisplayInfo(1, 10u, gfx::Rect(0, 0, 1920, 1200));
48 internal_display_info.set_is_aspect_preserving_scaling(true); 128 internal_display_info.set_is_aspect_preserving_scaling(true);
49 129
50 display::ManagedDisplayInfo::ManagedDisplayModeList internal_modes; 130 display::ManagedDisplayInfo::ManagedDisplayModeList internal_modes;
51 131
52 internal_modes.push_back(make_scoped_refptr( 132 internal_modes.push_back(make_scoped_refptr(
53 new display::ManagedDisplayMode(gfx::Size(2560, 1700), 60, false, true))); 133 new display::ManagedDisplayMode(gfx::Size(2560, 1700), 60, false, true)));
54 internal_modes.push_back(make_scoped_refptr(new display::ManagedDisplayMode( 134 internal_modes.push_back(make_scoped_refptr(new display::ManagedDisplayMode(
55 gfx::Size(1920, 1200), 60, false, false))); 135 gfx::Size(1920, 1200), 60, false, false)));
56 internal_display_info.SetManagedDisplayModes(internal_modes); 136 internal_display_info.SetManagedDisplayModes(internal_modes);
57 137
58 display::ManagedDisplayInfo external_display_info = 138 display::ManagedDisplayInfo external_display_info =
59 CreateDisplayInfo(2, 11u, gfx::Rect(0, 0, 1920, 1200)); 139 CreateDisplayInfo(2, 11u, gfx::Rect(0, 0, 1920, 1200));
60 140
61 gfx::Size fb_size(1920, 1200); 141 gfx::Size fb_size(1920, 1200);
62 142
63 // Create the touchscreens with the same size as the framebuffer so we can 143 // Create the touchscreens with the same size as the framebuffer so we can
64 // share the tests between Ozone & X11. 144 // share the tests between Ozone & X11.
65 ui::TouchscreenDevice internal_touchscreen = 145 ui::TouchscreenDevice internal_touchscreen =
66 CreateTouchscreenDevice(10, fb_size); 146 CreateTouchscreenDevice(10, fb_size);
67 ui::TouchscreenDevice external_touchscreen = 147 ui::TouchscreenDevice external_touchscreen =
68 CreateTouchscreenDevice(11, fb_size); 148 CreateTouchscreenDevice(11, fb_size);
69 149
70 TouchTransformerController* tt_controller =
71 Shell::GetInstance()->touch_transformer_controller();
72 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance(); 150 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance();
73 151
74 device_manager->UpdateTouchInfoForDisplay( 152 device_manager->UpdateTouchInfoForDisplay(
75 internal_display_info.id(), internal_touchscreen.id, 153 internal_display_info.id(), internal_touchscreen.id,
76 tt_controller->GetTouchTransform(internal_display_info, 154 GetTouchTransform(internal_display_info, internal_display_info,
77 internal_display_info, 155 internal_touchscreen, fb_size));
78 internal_touchscreen, fb_size));
79 156
80 device_manager->UpdateTouchInfoForDisplay( 157 device_manager->UpdateTouchInfoForDisplay(
81 internal_display_info.id(), external_touchscreen.id, 158 internal_display_info.id(), external_touchscreen.id,
82 tt_controller->GetTouchTransform(external_display_info, 159 GetTouchTransform(external_display_info, external_display_info,
83 external_display_info, 160 external_touchscreen, fb_size));
84 external_touchscreen, fb_size));
85 161
86 EXPECT_EQ(1, device_manager->GetTargetDisplayForTouchDevice(10)); 162 EXPECT_EQ(1, device_manager->GetTargetDisplayForTouchDevice(10));
87 EXPECT_EQ(1, device_manager->GetTargetDisplayForTouchDevice(11)); 163 EXPECT_EQ(1, device_manager->GetTargetDisplayForTouchDevice(11));
88 164
89 // External touch display has the default TouchTransformer. 165 // External touch display has the default TouchTransformer.
90 float x = 100.0; 166 float x = 100.0;
91 float y = 100.0; 167 float y = 100.0;
92 device_manager->ApplyTouchTransformer(11, &x, &y); 168 device_manager->ApplyTouchTransformer(11, &x, &y);
93 EXPECT_EQ(100, x); 169 EXPECT_EQ(100, x);
94 EXPECT_EQ(100, y); 170 EXPECT_EQ(100, y);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 207
132 gfx::Size fb_size(1024, 768); 208 gfx::Size fb_size(1024, 768);
133 209
134 // Create the touchscreens with the same size as the framebuffer so we can 210 // Create the touchscreens with the same size as the framebuffer so we can
135 // share the tests between Ozone & X11. 211 // share the tests between Ozone & X11.
136 ui::TouchscreenDevice internal_touchscreen = 212 ui::TouchscreenDevice internal_touchscreen =
137 CreateTouchscreenDevice(10, fb_size); 213 CreateTouchscreenDevice(10, fb_size);
138 ui::TouchscreenDevice external_touchscreen = 214 ui::TouchscreenDevice external_touchscreen =
139 CreateTouchscreenDevice(11, fb_size); 215 CreateTouchscreenDevice(11, fb_size);
140 216
141 TouchTransformerController* tt_controller =
142 Shell::GetInstance()->touch_transformer_controller();
143 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance(); 217 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance();
144 218
145 device_manager->UpdateTouchInfoForDisplay( 219 device_manager->UpdateTouchInfoForDisplay(
146 internal_display_info.id(), internal_touchscreen.id, 220 internal_display_info.id(), internal_touchscreen.id,
147 tt_controller->GetTouchTransform(internal_display_info, 221 GetTouchTransform(internal_display_info, internal_display_info,
148 internal_display_info, 222 internal_touchscreen, fb_size));
149 internal_touchscreen, fb_size));
150 223
151 device_manager->UpdateTouchInfoForDisplay( 224 device_manager->UpdateTouchInfoForDisplay(
152 internal_display_info.id(), external_touchscreen.id, 225 internal_display_info.id(), external_touchscreen.id,
153 tt_controller->GetTouchTransform(external_display_info, 226 GetTouchTransform(external_display_info, external_display_info,
154 external_display_info, 227 external_touchscreen, fb_size));
155 external_touchscreen, fb_size));
156 228
157 EXPECT_EQ(1, device_manager->GetTargetDisplayForTouchDevice(10)); 229 EXPECT_EQ(1, device_manager->GetTargetDisplayForTouchDevice(10));
158 EXPECT_EQ(1, device_manager->GetTargetDisplayForTouchDevice(11)); 230 EXPECT_EQ(1, device_manager->GetTargetDisplayForTouchDevice(11));
159 231
160 // External touch display has the default TouchTransformer. 232 // External touch display has the default TouchTransformer.
161 float x = 100.0; 233 float x = 100.0;
162 float y = 100.0; 234 float y = 100.0;
163 device_manager->ApplyTouchTransformer(11, &x, &y); 235 device_manager->ApplyTouchTransformer(11, &x, &y);
164 EXPECT_EQ(100, x); 236 EXPECT_EQ(100, x);
165 EXPECT_EQ(100, y); 237 EXPECT_EQ(100, y);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 279
208 gfx::Size fb_size(1920, 1990); 280 gfx::Size fb_size(1920, 1990);
209 281
210 // Create the touchscreens with the same size as the framebuffer so we can 282 // Create the touchscreens with the same size as the framebuffer so we can
211 // share the tests between Ozone & X11. 283 // share the tests between Ozone & X11.
212 ui::TouchscreenDevice display1_touchscreen = 284 ui::TouchscreenDevice display1_touchscreen =
213 CreateTouchscreenDevice(10, fb_size); 285 CreateTouchscreenDevice(10, fb_size);
214 ui::TouchscreenDevice display2_touchscreen = 286 ui::TouchscreenDevice display2_touchscreen =
215 CreateTouchscreenDevice(11, fb_size); 287 CreateTouchscreenDevice(11, fb_size);
216 288
217 TouchTransformerController* tt_controller =
218 Shell::GetInstance()->touch_transformer_controller();
219 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance(); 289 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance();
220 290
221 device_manager->UpdateTouchInfoForDisplay( 291 device_manager->UpdateTouchInfoForDisplay(
222 display1_info.id(), display1_touchscreen.id, 292 display1_info.id(), display1_touchscreen.id,
223 tt_controller->GetTouchTransform(display1_info, display1_info, 293 GetTouchTransform(display1_info, display1_info, display1_touchscreen,
224 display1_touchscreen, fb_size)); 294 fb_size));
225 295
226 device_manager->UpdateTouchInfoForDisplay( 296 device_manager->UpdateTouchInfoForDisplay(
227 display1_info.id(), display2_touchscreen.id, 297 display1_info.id(), display2_touchscreen.id,
228 tt_controller->GetTouchTransform(display1_info, display2_info, 298 GetTouchTransform(display1_info, display2_info, display2_touchscreen,
229 display2_touchscreen, fb_size)); 299 fb_size));
230 300
231 EXPECT_EQ(1, device_manager->GetTargetDisplayForTouchDevice(10)); 301 EXPECT_EQ(1, device_manager->GetTargetDisplayForTouchDevice(10));
232 EXPECT_EQ(1, device_manager->GetTargetDisplayForTouchDevice(11)); 302 EXPECT_EQ(1, device_manager->GetTargetDisplayForTouchDevice(11));
233 303
234 // Mapping for touch events from display 1's touchscreen: 304 // Mapping for touch events from display 1's touchscreen:
235 // [0, 1920) x [0, 1990) -> [0, 1280) x [0, 850) 305 // [0, 1920) x [0, 1990) -> [0, 1280) x [0, 850)
236 float x = 0.0; 306 float x = 0.0;
237 float y = 0.0; 307 float y = 0.0;
238 device_manager->ApplyTouchTransformer(10, &x, &y); 308 device_manager->ApplyTouchTransformer(10, &x, &y);
239 EXPECT_NEAR(0, x, 0.5); 309 EXPECT_NEAR(0, x, 0.5);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 CreateDisplayInfo(1, 5u, gfx::Rect(0, 0, 1366, 768)); 348 CreateDisplayInfo(1, 5u, gfx::Rect(0, 0, 1366, 768));
279 display::ManagedDisplayInfo display2 = 349 display::ManagedDisplayInfo display2 =
280 CreateDisplayInfo(2, 6u, gfx::Rect(0, 828, 2560, 1600)); 350 CreateDisplayInfo(2, 6u, gfx::Rect(0, 828, 2560, 1600));
281 gfx::Size fb_size(2560, 2428); 351 gfx::Size fb_size(2560, 2428);
282 352
283 // Create the touchscreens with the same size as the framebuffer so we can 353 // Create the touchscreens with the same size as the framebuffer so we can
284 // share the tests between Ozone & X11. 354 // share the tests between Ozone & X11.
285 ui::TouchscreenDevice touchscreen1 = CreateTouchscreenDevice(5, fb_size); 355 ui::TouchscreenDevice touchscreen1 = CreateTouchscreenDevice(5, fb_size);
286 ui::TouchscreenDevice touchscreen2 = CreateTouchscreenDevice(6, fb_size); 356 ui::TouchscreenDevice touchscreen2 = CreateTouchscreenDevice(6, fb_size);
287 357
288 TouchTransformerController* tt_controller =
289 Shell::GetInstance()->touch_transformer_controller();
290 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance(); 358 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance();
291 359
292 device_manager->UpdateTouchInfoForDisplay( 360 device_manager->UpdateTouchInfoForDisplay(
293 display1.id(), touchscreen1.id, 361 display1.id(), touchscreen1.id,
294 tt_controller->GetTouchTransform(display1, display1, touchscreen1, 362 GetTouchTransform(display1, display1, touchscreen1, fb_size));
295 fb_size));
296 363
297 device_manager->UpdateTouchInfoForDisplay( 364 device_manager->UpdateTouchInfoForDisplay(
298 display2.id(), touchscreen2.id, 365 display2.id(), touchscreen2.id,
299 tt_controller->GetTouchTransform(display2, display2, touchscreen2, 366 GetTouchTransform(display2, display2, touchscreen2, fb_size));
300 fb_size));
301 367
302 EXPECT_EQ(1, device_manager->GetTargetDisplayForTouchDevice(5)); 368 EXPECT_EQ(1, device_manager->GetTargetDisplayForTouchDevice(5));
303 EXPECT_EQ(2, device_manager->GetTargetDisplayForTouchDevice(6)); 369 EXPECT_EQ(2, device_manager->GetTargetDisplayForTouchDevice(6));
304 370
305 // Mapping for touch events from internal touch display: 371 // Mapping for touch events from internal touch display:
306 // [0, 2560) x [0, 2428) -> [0, 1366) x [0, 768) 372 // [0, 2560) x [0, 2428) -> [0, 1366) x [0, 768)
307 float x = 0.0; 373 float x = 0.0;
308 float y = 0.0; 374 float y = 0.0;
309 device_manager->ApplyTouchTransformer(5, &x, &y); 375 device_manager->ApplyTouchTransformer(5, &x, &y);
310 EXPECT_NEAR(0, x, 0.5); 376 EXPECT_NEAR(0, x, 0.5);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 EXPECT_NEAR(1599, y, 0.5); 408 EXPECT_NEAR(1599, y, 0.5);
343 #endif 409 #endif
344 } 410 }
345 411
346 TEST_F(TouchTransformerControllerTest, TouchRadiusScale) { 412 TEST_F(TouchTransformerControllerTest, TouchRadiusScale) {
347 display::ManagedDisplayInfo display = 413 display::ManagedDisplayInfo display =
348 CreateDisplayInfo(1, 5u, gfx::Rect(0, 0, 2560, 1600)); 414 CreateDisplayInfo(1, 5u, gfx::Rect(0, 0, 2560, 1600));
349 ui::TouchscreenDevice touch_device = 415 ui::TouchscreenDevice touch_device =
350 CreateTouchscreenDevice(5, gfx::Size(1001, 1001)); 416 CreateTouchscreenDevice(5, gfx::Size(1001, 1001));
351 417
352 TouchTransformerController* tt_controller =
353 Shell::GetInstance()->touch_transformer_controller();
354 // Default touchscreen position range is 1001x1001; 418 // Default touchscreen position range is 1001x1001;
355 EXPECT_EQ(sqrt((2560.0 * 1600.0) / (1001.0 * 1001.0)), 419 EXPECT_EQ(sqrt((2560.0 * 1600.0) / (1001.0 * 1001.0)),
356 tt_controller->GetTouchResolutionScale(display, touch_device)); 420 GetTouchResolutionScale(display, touch_device));
421 }
422
423 TEST_F(TouchTransformerControllerTest, OzoneTranslation) {
424 #if defined(USE_OZONE)
425 // The internal display has size 1920 x 1200. The external display has
426 // size 1920x1200. The total frame buffer is 1920x2450,
427 // where 2458 = 1200 + 50 (hidden gap) + 1200
428 // and the second monitor is translated to Point (0, 1250) in the
429 // framebuffer.
430 const int kDisplayId2 = 2;
431 const int kTouchId2 = 6;
432 const gfx::Size kDisplaySize(1920, 1200);
433 const gfx::Size kTouchSize(1920, 1200);
434 const int kHiddenGap = 50;
435
436 display::ManagedDisplayInfo display1 = CreateDisplayInfo(
437 kDisplayId1, kTouchId1,
438 gfx::Rect(0, 0, kDisplaySize.width(), kDisplaySize.height()));
439 display::ManagedDisplayInfo display2 =
440 CreateDisplayInfo(kDisplayId2, kTouchId2,
441 gfx::Rect(0, kDisplaySize.height() + kHiddenGap,
442 kDisplaySize.width(), kDisplaySize.height()));
443
444 gfx::Size fb_size(1920, 2450);
445
446 ui::TouchscreenDevice touchscreen1 =
447 CreateTouchscreenDevice(kTouchId1, kDisplaySize);
448 ui::TouchscreenDevice touchscreen2 =
449 CreateTouchscreenDevice(kTouchId2, kDisplaySize);
450
451 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance();
452
453 // Mirror displays. Touch screen 2 is associated to display 1.
454 device_manager->UpdateTouchInfoForDisplay(
455 display1.id(), touchscreen1.id,
456 GetTouchTransform(display1, display1, touchscreen1, kTouchSize));
457
458 device_manager->UpdateTouchInfoForDisplay(
459 display1.id(), touchscreen2.id,
460 GetTouchTransform(display1, display2, touchscreen2, kTouchSize));
461
462 EXPECT_EQ(kDisplayId1,
463 device_manager->GetTargetDisplayForTouchDevice(kTouchId1));
464 EXPECT_EQ(kDisplayId1,
465 device_manager->GetTargetDisplayForTouchDevice(kTouchId2));
466
467 float x, y;
468
469 x = y = 0.0;
470 device_manager->ApplyTouchTransformer(kTouchId1, &x, &y);
471 EXPECT_NEAR(0, x, 0.5);
472 EXPECT_NEAR(0, y, 0.5);
473
474 x = y = 0.0;
475 device_manager->ApplyTouchTransformer(kTouchId2, &x, &y);
476 EXPECT_NEAR(0, x, 0.5);
477 EXPECT_NEAR(0, y, 0.5);
478
479 x = 1920.0;
480 y = 1200.0;
481 device_manager->ApplyTouchTransformer(kTouchId1, &x, &y);
482 EXPECT_NEAR(1920, x, 0.5);
483 EXPECT_NEAR(1200, y, 0.5);
484
485 x = 1920.0;
486 y = 1200.0;
487 device_manager->ApplyTouchTransformer(kTouchId2, &x, &y);
488 EXPECT_NEAR(1920, x, 0.5);
489 EXPECT_NEAR(1200, y, 0.5);
490
491 // Remove mirroring of displays.
492 device_manager->UpdateTouchInfoForDisplay(
493 display2.id(), touchscreen2.id,
494 GetTouchTransform(display2, display2, touchscreen2, kTouchSize));
495
496 x = 1920.0;
497 y = 1200.0;
498 device_manager->ApplyTouchTransformer(kTouchId1, &x, &y);
499 EXPECT_NEAR(1920, x, 0.5);
500 EXPECT_NEAR(1200, y, 0.5);
501
502 x = 1920.0;
503 y = 1200.0;
504 device_manager->ApplyTouchTransformer(kTouchId2, &x, &y);
505 EXPECT_NEAR(1920, x, 0.5);
506 EXPECT_NEAR(1200 + kDisplaySize.height() + kHiddenGap, y, 0.5);
507 #endif // USE_OZONE
508 }
509
510 TEST_F(TouchTransformerControllerTest, AccurateUserTouchCalibration) {
511 const gfx::Size kDisplaySize(1920, 1200);
512 const gfx::Size kTouchSize(1920, 1200);
513
514 display::ManagedDisplayInfo display = CreateDisplayInfo(
515 kDisplayId1, kTouchId1,
516 gfx::Rect(0, 0, kDisplaySize.width(), kDisplaySize.height()));
517
518 // Assuming the user provided accurate inputs during calibration. ie the user
519 // actually tapped (100,100) when asked to tap (100,100) with no human error.
520 display::TouchCalibrationData::CalibrationPointPairQuad user_input = {{
521 std::make_pair(gfx::Point(100, 100), gfx::Point(100, 100)),
522 std::make_pair(gfx::Point(1820, 100), gfx::Point(1820, 100)),
523 std::make_pair(gfx::Point(100, 1100), gfx::Point(100, 1100)),
524 std::make_pair(gfx::Point(1820, 1100), gfx::Point(1820, 1100)),
525 }};
526 display::TouchCalibrationData touch_data(user_input, kDisplaySize);
527 display.SetTouchCalibrationData(touch_data);
528 EXPECT_TRUE(display.has_touch_calibration_data());
529
530 const std::string msg = GetTouchPointString(user_input);
531
532 gfx::Size fb_size(1920, 1200);
533
534 ui::TouchscreenDevice touchscreen =
535 CreateTouchscreenDevice(kTouchId1, kTouchSize);
536
537 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance();
538
539 device_manager->UpdateTouchInfoForDisplay(
540 display.id(), touchscreen.id,
541 GetTouchTransform(display, display, touchscreen, kTouchSize));
542
543 EXPECT_EQ(kDisplayId1,
544 device_manager->GetTargetDisplayForTouchDevice(kTouchId1));
545
546 CheckPointsOfInterests(kTouchId1, kTouchSize, kDisplaySize, gfx::Size(1, 1),
547 msg);
548 }
549
550 TEST_F(TouchTransformerControllerTest, ErrorProneUserTouchCalibration) {
551 const gfx::Size kDisplaySize(1920, 1200);
552 const gfx::Size kTouchSize(1920, 1200);
553 // User touch inputs have a max error of 5%.
554 const float kError = 0.05;
555 // The maximum user error rate is |kError|%. Since the calibration is
556 // performed with a best fit algorithm, the error rate observed should be less
557 // than |kError|.
558 const gfx::Size kMaxErrorDelta = gfx::ScaleToCeiledSize(kTouchSize, kError);
559
560 display::ManagedDisplayInfo display = CreateDisplayInfo(
561 kDisplayId1, kTouchId1,
562 gfx::Rect(0, 0, kDisplaySize.width(), kDisplaySize.height()));
563
564 // Assuming the user provided inaccurate inputs during calibration. ie the
565 // user did not tap (100,100) when asked to tap (100,100) due to human error.
566 display::TouchCalibrationData::CalibrationPointPairQuad user_input = {
567 {std::make_pair(gfx::Point(100, 100), gfx::Point(130, 60)),
568 std::make_pair(gfx::Point(1820, 100), gfx::Point(1878, 130)),
569 std::make_pair(gfx::Point(100, 1100), gfx::Point(158, 1060)),
570 std::make_pair(gfx::Point(1820, 1100), gfx::Point(1790, 1140))}};
571 display::TouchCalibrationData touch_data(user_input, kDisplaySize);
572 display.SetTouchCalibrationData(touch_data);
573 EXPECT_TRUE(display.has_touch_calibration_data());
574
575 const std::string msg = GetTouchPointString(user_input);
576
577 ui::TouchscreenDevice touchscreen =
578 CreateTouchscreenDevice(kTouchId1, kTouchSize);
579
580 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance();
581
582 device_manager->UpdateTouchInfoForDisplay(
583 display.id(), touchscreen.id,
584 GetTouchTransform(display, display, touchscreen, kTouchSize));
585
586 EXPECT_EQ(kDisplayId1,
587 device_manager->GetTargetDisplayForTouchDevice(kTouchId1));
588
589 CheckPointsOfInterests(kTouchId1, kTouchSize, kDisplaySize, kMaxErrorDelta,
590 msg);
591 }
592
593 TEST_F(TouchTransformerControllerTest, ResolutionChangeUserTouchCalibration) {
594 const gfx::Size kDisplaySize(2560, 1600);
595 const gfx::Size kTouchSize(1920, 1200);
596 // User touch inputs have a max error of 5%.
597 const float kError = 0.05;
598 // The maximum user error rate is |kError|%. Since the calibration is
599 // performed with a best fit algorithm, the error rate observed should be less
600 // tha |kError|.
601 gfx::Size kMaxErrorDelta = gfx::ScaleToCeiledSize(kDisplaySize, kError);
602
603 display::ManagedDisplayInfo display = CreateDisplayInfo(
604 kDisplayId1, kTouchId1,
605 gfx::Rect(0, 0, kDisplaySize.width(), kDisplaySize.height()));
606
607 // The calibration was performed at a resolution different from the curent
608 // resolution of the display.
609 const gfx::Size CALIBRATION_SIZE(1920, 1200);
610 display::TouchCalibrationData::CalibrationPointPairQuad user_input = {
611 {std::make_pair(gfx::Point(100, 100), gfx::Point(50, 70)),
612 std::make_pair(gfx::Point(1820, 100), gfx::Point(1780, 70)),
613 std::make_pair(gfx::Point(100, 1100), gfx::Point(70, 1060)),
614 std::make_pair(gfx::Point(1820, 1100), gfx::Point(1770, 1140))}};
615
616 display::TouchCalibrationData touch_data(user_input, CALIBRATION_SIZE);
617 display.SetTouchCalibrationData(touch_data);
618 EXPECT_TRUE(display.has_touch_calibration_data());
619
620 const std::string msg = GetTouchPointString(user_input);
621
622 ui::TouchscreenDevice touchscreen =
623 CreateTouchscreenDevice(kTouchId1, kTouchSize);
624
625 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance();
626
627 device_manager->UpdateTouchInfoForDisplay(
628 display.id(), touchscreen.id,
629 GetTouchTransform(display, display, touchscreen, kTouchSize));
630
631 EXPECT_EQ(kDisplayId1,
632 device_manager->GetTargetDisplayForTouchDevice(kTouchId1));
633
634 CheckPointsOfInterests(kTouchId1, kTouchSize, kDisplaySize, kMaxErrorDelta,
635 msg);
636 }
637
638 TEST_F(TouchTransformerControllerTest, DifferentBoundsUserTouchCalibration) {
639 // The display bounds is different from the touch device bounds in this test.
640 const gfx::Size kDisplaySize(1024, 600);
641 const gfx::Size kTouchSize(4096, 4096);
642 const float kAcceptableError = 0.04;
643 gfx::Size kMaxErrorDelta =
644 gfx::ScaleToCeiledSize(kDisplaySize, kAcceptableError);
645
646 display::ManagedDisplayInfo display = CreateDisplayInfo(
647 kDisplayId1, kTouchId1,
648 gfx::Rect(0, 0, kDisplaySize.width(), kDisplaySize.height()));
649
650 // Real world data.
651 display::TouchCalibrationData::CalibrationPointPairQuad user_input = {
652 {std::make_pair(gfx::Point(136, 136), gfx::Point(538, 931)),
653 std::make_pair(gfx::Point(873, 136), gfx::Point(3475, 922)),
654 std::make_pair(gfx::Point(136, 411), gfx::Point(611, 2800)),
655 std::make_pair(gfx::Point(873, 411), gfx::Point(3535, 2949))}};
656 display::TouchCalibrationData touch_data(user_input, kDisplaySize);
657 display.SetTouchCalibrationData(touch_data);
658 EXPECT_TRUE(display.has_touch_calibration_data());
659
660 const std::string msg = GetTouchPointString(user_input);
661
662 ui::TouchscreenDevice touchscreen =
663 CreateTouchscreenDevice(kTouchId1, kTouchSize);
664
665 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance();
666
667 device_manager->UpdateTouchInfoForDisplay(
668 display.id(), touchscreen.id,
669 GetTouchTransform(display, display, touchscreen, kTouchSize));
670
671 EXPECT_EQ(kDisplayId1,
672 device_manager->GetTargetDisplayForTouchDevice(kTouchId1));
673
674 CheckPointsOfInterests(kTouchId1, kTouchSize, kDisplaySize, kMaxErrorDelta,
675 msg);
676 }
677
678 TEST_F(TouchTransformerControllerTest, LetterboxingUserTouchCalibration) {
679 // The internal display has native resolution of 2560x1700, and in
680 // mirror mode it is configured as 1920x1200. This is in letterboxing
681 // mode.
682 const gfx::Size kNativeDisplaySize(2560, 1700);
683 const gfx::Size kDisplaySize(1920, 1200);
684 const gfx::Size kTouchSize(1920, 1200);
685
686 display::ManagedDisplayInfo internal_display_info = CreateDisplayInfo(
687 kDisplayId1, kTouchId1,
688 gfx::Rect(0, 0, kDisplaySize.width(), kDisplaySize.height()));
689 internal_display_info.set_is_aspect_preserving_scaling(true);
690
691 display::ManagedDisplayInfo::ManagedDisplayModeList internal_modes;
692
693 internal_modes.push_back(make_scoped_refptr(new display::ManagedDisplayMode(
694 gfx::Size(kNativeDisplaySize.width(), kNativeDisplaySize.height()), 60,
695 false, true)));
696 internal_modes.push_back(make_scoped_refptr(new display::ManagedDisplayMode(
697 gfx::Size(kDisplaySize.width(), kDisplaySize.height()), 60, false,
698 false)));
699 internal_display_info.SetManagedDisplayModes(internal_modes);
700
701 gfx::Size fb_size(kDisplaySize);
702
703 // Create the touchscreens with the same size as the framebuffer so we can
704 // share the tests between Ozone & X11.
705 ui::TouchscreenDevice internal_touchscreen =
706 CreateTouchscreenDevice(kTouchId1, fb_size);
707
708 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance();
709
710 // Assuming the user provided inaccurate inputs during calibration. ie the
711 // user did not tap (100,100) when asked to tap (100,100) due to human error.
712 // Since the display is of size 2560x1700 and the touch device is of size
713 // 1920x1200, the corresponding points have to be scaled.
714 display::TouchCalibrationData::CalibrationPointPairQuad user_input = {{
715 std::make_pair(gfx::Point(100, 100), gfx::Point(75, 71)),
716 std::make_pair(gfx::Point(2460, 100), gfx::Point(1845, 71)),
717 std::make_pair(gfx::Point(100, 1600), gfx::Point(75, 1130)),
718 std::make_pair(gfx::Point(2460, 1600), gfx::Point(1845, 1130)),
719 }};
720 // The calibration was performed at the native display resolution.
721 display::TouchCalibrationData touch_data(user_input, kNativeDisplaySize);
722 internal_display_info.SetTouchCalibrationData(touch_data);
723 EXPECT_TRUE(internal_display_info.has_touch_calibration_data());
724
725 device_manager->UpdateTouchInfoForDisplay(
726 internal_display_info.id(), internal_touchscreen.id,
727 GetTouchTransform(internal_display_info, internal_display_info,
728 internal_touchscreen, fb_size));
729
730 EXPECT_EQ(kDisplayId1,
731 device_manager->GetTargetDisplayForTouchDevice(kTouchId1));
732
733 float x, y;
734 // In letterboxing, there is (1-2560*(1200/1920)/1700)/2 = 2.95% of the
735 // height on both the top & bottom region of the screen is blank.
736 // When touch events coming at Y range [0, 1200), the mapping should be
737 // [0, ~35] ---> < 0
738 // [~35, ~1165] ---> [0, 1200)
739 // [~1165, 1200] ---> >= 1200
740 x = 100.0;
741 y = 35.0;
742 device_manager->ApplyTouchTransformer(kTouchId1, &x, &y);
743 EXPECT_NEAR(100, x, 0.5);
744 EXPECT_NEAR(0, y, 0.5);
745
746 x = 100.0;
747 y = 1165.0;
748 device_manager->ApplyTouchTransformer(kTouchId1, &x, &y);
749 EXPECT_NEAR(100, x, 0.5);
750 EXPECT_NEAR(1200, y, 0.5);
751 }
752
753 TEST_F(TouchTransformerControllerTest, PillarBoxingUserTouchCalibration) {
754 // The internal display has native resolution of 2560x1700, and in
755 // mirror mode it is configured as 1920x1200. This is in letterboxing
756 // mode.
757 const gfx::Size kNativeDisplaySize(2560, 1600);
758 const gfx::Size kDisplaySize(1920, 1400);
759 const gfx::Size kTouchSize(1920, 1400);
760
761 display::ManagedDisplayInfo internal_display_info = CreateDisplayInfo(
762 kDisplayId1, kTouchId1,
763 gfx::Rect(0, 0, kDisplaySize.width(), kDisplaySize.height()));
764 internal_display_info.set_is_aspect_preserving_scaling(true);
765
766 display::ManagedDisplayInfo::ManagedDisplayModeList internal_modes;
767
768 internal_modes.push_back(make_scoped_refptr(new display::ManagedDisplayMode(
769 gfx::Size(kNativeDisplaySize.width(), kNativeDisplaySize.height()), 60,
770 false, true)));
771 internal_modes.push_back(make_scoped_refptr(new display::ManagedDisplayMode(
772 gfx::Size(kDisplaySize.width(), kDisplaySize.height()), 60, false,
773 false)));
774 internal_display_info.SetManagedDisplayModes(internal_modes);
775
776 gfx::Size fb_size(kDisplaySize);
777
778 // Create the touchscreens with the same size as the framebuffer so we can
779 // share the tests between Ozone & X11.
780 ui::TouchscreenDevice internal_touchscreen =
781 CreateTouchscreenDevice(kTouchId1, fb_size);
782
783 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance();
784
785 // Assuming the user provided accurate inputs during calibration. ie the user
786 // actually tapped (100,100) when asked to tap (100,100) with no human error.
787 // Since the display is of size 2560x1600 and the touch device is of size
788 // 1920x1400, the corresponding points have to be scaled.
789 display::TouchCalibrationData::CalibrationPointPairQuad user_input = {{
790 std::make_pair(gfx::Point(100, 100), gfx::Point(75, 88)),
791 std::make_pair(gfx::Point(2460, 100), gfx::Point(1845, 88)),
792 std::make_pair(gfx::Point(100, 1500), gfx::Point(75, 1313)),
793 std::make_pair(gfx::Point(2460, 1500), gfx::Point(1845, 1313)),
794 }};
795 // The calibration was performed at the native display resolution.
796 display::TouchCalibrationData touch_data(user_input, kNativeDisplaySize);
797 internal_display_info.SetTouchCalibrationData(touch_data);
798 EXPECT_TRUE(internal_display_info.has_touch_calibration_data());
799
800 device_manager->UpdateTouchInfoForDisplay(
801 internal_display_info.id(), internal_touchscreen.id,
802 GetTouchTransform(internal_display_info, internal_display_info,
803 internal_touchscreen, fb_size));
804
805 EXPECT_EQ(kDisplayId1,
806 device_manager->GetTargetDisplayForTouchDevice(kTouchId1));
807
808 float x, y;
809 // In pillarboxing, there is (1-1600*(1920/1400)/2560)/2 = 7.14% of the
810 // width on both the left & region region of the screen is blank.
811 // When touch events coming at X range [0, 1920), the mapping should be
812 // [0, ~137] ---> < 0
813 // [~137, ~1782] ---> [0, 1920)
814 // [~1782, 1920] ---> >= 1920
815 x = 137.0;
816 y = 0.0;
817 device_manager->ApplyTouchTransformer(kTouchId1, &x, &y);
818 EXPECT_NEAR(0, x, 0.5);
819 EXPECT_NEAR(0, y, 0.5);
820
821 x = 1782.0;
822 y = 0.0;
823 device_manager->ApplyTouchTransformer(kTouchId1, &x, &y);
824 EXPECT_NEAR(1920, x, 0.5);
825 EXPECT_NEAR(0, y, 0.5);
357 } 826 }
358 827
359 } // namespace ash 828 } // namespace ash
OLDNEW
« ash/touch/touch_transformer_controller.cc ('K') | « ash/touch/touch_transformer_controller.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698