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