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