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" | |
| 9 #include "ui/aura/window_tree_host.h" | 10 #include "ui/aura/window_tree_host.h" |
| 10 #include "ui/events/devices/device_data_manager.h" | 11 #include "ui/events/devices/device_data_manager.h" |
| 12 // #include "ui/gfx/geometry/point.h" | |
|
malaykeshav
2016/12/19 19:12:01
Remove
malaykeshav
2016/12/20 09:56:05
Done
| |
| 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 // Returns a point close to |point| with some error. This is to simulate human | |
| 41 // input that is prone to a max delta error of |error.width()| or | |
| 42 // |error.height()|. | |
| 43 gfx::Point GetPointWithError(const gfx::Point& point, const gfx::Size& error) { | |
|
kylechar
2016/12/19 20:00:22
Do you really want to use non-deterministic random
malaykeshav
2016/12/20 09:56:05
This is not completely non-deterministic. It produ
sadrul
2016/12/20 17:31:05
Boilerplate code is a good trade-off to possibly f
malaykeshav
2016/12/20 19:16:55
Done
Adding debug message that includes the point
| |
| 44 return gfx::Point( | |
| 45 point.x() + base::RandInt(-error.width() / 2, error.width()) / 2, | |
|
malaykeshav
2016/12/19 19:12:01
point.x() + base::RandInt(-error.width() / 2, erro
malaykeshav
2016/12/20 09:56:05
done
| |
| 46 point.y() + base::RandInt(-error.height() / 2, error.height() / 2)); | |
| 47 } | |
| 48 | |
| 49 // Checks if the touch input has been calibrated properly. The input is said to | |
| 50 // be calibrated if any touch input is transformed to the correct corresponding | |
| 51 // display point within an error delta of |max_error_delta.width()| along the X | |
| 52 // axis and |max_error_delta.height()| along the Y axis; | |
| 53 void CheckPointsOfInterests(const int& touch_id, | |
|
kylechar
2016/12/19 20:00:22
Don't pass int by const ref.
malaykeshav
2016/12/20 09:56:05
done
| |
| 54 const gfx::Size& touch_size, | |
| 55 const gfx::Size& display_size, | |
| 56 const gfx::Size& max_error_delta) { | |
| 57 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance(); | |
| 58 float x, y; | |
| 59 | |
| 60 // Origin of the touch device should correspond to origin of the display. | |
| 61 x = y = 0.0; | |
| 62 device_manager->ApplyTouchTransformer(touch_id, &x, &y); | |
| 63 EXPECT_NEAR(0, x, max_error_delta.width()); | |
| 64 EXPECT_NEAR(0, y, max_error_delta.height()); | |
| 65 | |
| 66 // Center of the touch device should correspond to the center of the display | |
| 67 // device. | |
| 68 x = touch_size.width() / 2; | |
| 69 y = touch_size.height() / 2; | |
| 70 device_manager->ApplyTouchTransformer(touch_id, &x, &y); | |
| 71 EXPECT_NEAR(display_size.width() / 2, x, max_error_delta.width()); | |
| 72 EXPECT_NEAR(display_size.height() / 2, y, max_error_delta.height()); | |
| 73 | |
| 74 // Bottom right corner of the touch device should correspond to rightmost | |
| 75 // corner of display device. | |
| 76 x = touch_size.width(); | |
| 77 y = touch_size.height(); | |
| 78 device_manager->ApplyTouchTransformer(touch_id, &x, &y); | |
| 79 EXPECT_NEAR(display_size.width(), x, max_error_delta.width()); | |
| 80 EXPECT_NEAR(display_size.height(), y, max_error_delta.height()); | |
| 81 } | |
| 82 | |
| 38 } // namespace | 83 } // namespace |
| 39 | 84 |
| 40 typedef test::AshTestBase TouchTransformerControllerTest; | 85 typedef test::AshTestBase TouchTransformerControllerTest; |
| 41 | 86 |
| 42 TEST_F(TouchTransformerControllerTest, MirrorModeLetterboxing) { | 87 TEST_F(TouchTransformerControllerTest, MirrorModeLetterboxing) { |
| 43 // The internal display has native resolution of 2560x1700, and in | 88 // The internal display has native resolution of 2560x1700, and in |
| 44 // mirror mode it is configured as 1920x1200. This is in letterboxing | 89 // mirror mode it is configured as 1920x1200. This is in letterboxing |
| 45 // mode. | 90 // mode. |
| 46 display::ManagedDisplayInfo internal_display_info = | 91 display::ManagedDisplayInfo internal_display_info = |
| 47 CreateDisplayInfo(1, 10u, gfx::Rect(0, 0, 1920, 1200)); | 92 CreateDisplayInfo(1, 10u, gfx::Rect(0, 0, 1920, 1200)); |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 349 ui::TouchscreenDevice touch_device = | 394 ui::TouchscreenDevice touch_device = |
| 350 CreateTouchscreenDevice(5, gfx::Size(1001, 1001)); | 395 CreateTouchscreenDevice(5, gfx::Size(1001, 1001)); |
| 351 | 396 |
| 352 TouchTransformerController* tt_controller = | 397 TouchTransformerController* tt_controller = |
| 353 Shell::GetInstance()->touch_transformer_controller(); | 398 Shell::GetInstance()->touch_transformer_controller(); |
| 354 // Default touchscreen position range is 1001x1001; | 399 // Default touchscreen position range is 1001x1001; |
| 355 EXPECT_EQ(sqrt((2560.0 * 1600.0) / (1001.0 * 1001.0)), | 400 EXPECT_EQ(sqrt((2560.0 * 1600.0) / (1001.0 * 1001.0)), |
| 356 tt_controller->GetTouchResolutionScale(display, touch_device)); | 401 tt_controller->GetTouchResolutionScale(display, touch_device)); |
| 357 } | 402 } |
| 358 | 403 |
| 404 TEST_F(TouchTransformerControllerTest, OzoneTrasnlation) { | |
|
kylechar
2016/12/19 20:00:22
OzoneTranslation?
malaykeshav
2016/12/20 09:56:05
done
| |
| 405 #if defined(USE_OZONE) | |
| 406 // The internal display has size 1920 x 1200. The external display has | |
| 407 // size 1920x1200. The total frame buffer is 1920x2450, | |
| 408 // where 2458 = 1200 + 50 (hidden gap) + 1200 | |
| 409 // and the second monitor is translated to Point (0, 1250) in the | |
| 410 // framebuffer. | |
| 411 const gfx::Size DISPLAY_SIZE(1920, 1200), TOUCH_SIZE(1920, 1200); | |
|
kylechar
2016/12/19 20:00:21
Constant names are supported be like kDisplaySize.
malaykeshav
2016/12/20 09:56:05
Done
| |
| 412 const int HIDDEN_GAP = 50; | |
| 413 const int DISPLAY_ID_1 = 1, DISPLAY_ID_2 = 2, TOUCH_ID_1 = 5, TOUCH_ID_2 = 6; | |
|
kylechar
2016/12/19 20:00:21
One variable per line.
malaykeshav
2016/12/20 09:56:05
Done
| |
| 414 | |
| 415 display::ManagedDisplayInfo display1 = CreateDisplayInfo( | |
|
kylechar
2016/12/19 20:00:21
optional: auto display1 = ...;
malaykeshav
2016/12/20 09:56:05
Ack
| |
| 416 DISPLAY_ID_1, TOUCH_ID_1, | |
| 417 gfx::Rect(0, 0, DISPLAY_SIZE.width(), DISPLAY_SIZE.height())); | |
| 418 display::ManagedDisplayInfo display2 = | |
| 419 CreateDisplayInfo(DISPLAY_ID_2, TOUCH_ID_2, | |
| 420 gfx::Rect(0, DISPLAY_SIZE.height() + HIDDEN_GAP, | |
| 421 DISPLAY_SIZE.width(), DISPLAY_SIZE.height())); | |
| 422 | |
| 423 gfx::Size fb_size(1920, 2450); | |
| 424 | |
| 425 ui::TouchscreenDevice touchscreen1 = | |
| 426 CreateTouchscreenDevice(TOUCH_ID_1, DISPLAY_SIZE); | |
| 427 ui::TouchscreenDevice touchscreen2 = | |
| 428 CreateTouchscreenDevice(TOUCH_ID_2, DISPLAY_SIZE); | |
| 429 | |
| 430 TouchTransformerController* tt_controller = | |
| 431 Shell::GetInstance()->touch_transformer_controller(); | |
| 432 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance(); | |
| 433 | |
| 434 // Mirror displays. Touch screen 2 is associated to display 1. | |
| 435 device_manager->UpdateTouchInfoForDisplay( | |
| 436 display1.id(), touchscreen1.id, | |
| 437 tt_controller->GetTouchTransform(display1, display1, touchscreen1, | |
| 438 TOUCH_SIZE)); | |
| 439 | |
| 440 device_manager->UpdateTouchInfoForDisplay( | |
| 441 display1.id(), touchscreen2.id, | |
| 442 tt_controller->GetTouchTransform(display1, display2, touchscreen2, | |
| 443 TOUCH_SIZE)); | |
| 444 | |
| 445 EXPECT_EQ(DISPLAY_ID_1, | |
| 446 device_manager->GetTargetDisplayForTouchDevice(TOUCH_ID_1)); | |
| 447 EXPECT_EQ(DISPLAY_ID_1, | |
| 448 device_manager->GetTargetDisplayForTouchDevice(TOUCH_ID_2)); | |
| 449 | |
| 450 float x, y; | |
| 451 | |
| 452 x = y = 0.0; | |
| 453 device_manager->ApplyTouchTransformer(TOUCH_ID_1, &x, &y); | |
| 454 EXPECT_NEAR(0, x, 0.5); | |
| 455 EXPECT_NEAR(0, y, 0.5); | |
| 456 | |
| 457 x = y = 0.0; | |
| 458 device_manager->ApplyTouchTransformer(TOUCH_ID_2, &x, &y); | |
| 459 EXPECT_NEAR(0, x, 0.5); | |
| 460 EXPECT_NEAR(0, y, 0.5); | |
| 461 | |
| 462 x = 1920.0; | |
| 463 y = 1200.0; | |
| 464 device_manager->ApplyTouchTransformer(TOUCH_ID_1, &x, &y); | |
| 465 EXPECT_NEAR(1920, x, 0.5); | |
| 466 EXPECT_NEAR(1200, y, 0.5); | |
| 467 | |
| 468 x = 1920.0; | |
| 469 y = 1200.0; | |
| 470 device_manager->ApplyTouchTransformer(TOUCH_ID_2, &x, &y); | |
| 471 EXPECT_NEAR(1920, x, 0.5); | |
| 472 EXPECT_NEAR(1200, y, 0.5); | |
| 473 | |
| 474 // Remove mirroring of displays. | |
| 475 device_manager->UpdateTouchInfoForDisplay( | |
| 476 display2.id(), touchscreen2.id, | |
| 477 tt_controller->GetTouchTransform(display2, display2, touchscreen2, | |
| 478 TOUCH_SIZE)); | |
| 479 | |
| 480 x = 1920.0; | |
| 481 y = 1200.0; | |
| 482 device_manager->ApplyTouchTransformer(TOUCH_ID_1, &x, &y); | |
| 483 EXPECT_NEAR(1920, x, 0.5); | |
| 484 EXPECT_NEAR(1200, y, 0.5); | |
| 485 | |
| 486 x = 1920.0; | |
| 487 y = 1200.0; | |
| 488 device_manager->ApplyTouchTransformer(TOUCH_ID_2, &x, &y); | |
| 489 EXPECT_NEAR(1920, x, 0.5); | |
| 490 EXPECT_NEAR(1200 + DISPLAY_SIZE.height() + HIDDEN_GAP, y, 0.5); | |
| 491 #endif | |
| 492 } | |
| 493 | |
| 494 TEST_F(TouchTransformerControllerTest, AccurateUserTouchCalibration) { | |
| 495 const gfx::Size DISPLAY_SIZE(1920, 1200), TOUCH_SIZE(1920, 1200); | |
| 496 const int DISPLAY_ID = 1, TOUCH_ID = 5; | |
| 497 | |
| 498 display::ManagedDisplayInfo display = CreateDisplayInfo( | |
| 499 DISPLAY_ID, TOUCH_ID, | |
| 500 gfx::Rect(0, 0, DISPLAY_SIZE.width(), DISPLAY_SIZE.height())); | |
| 501 | |
| 502 // Assuming the user provided accurate inputs during calibration. ie the user | |
| 503 // actually tapped (100,100) when asked to tap (100,100) with no human error. | |
| 504 display::TouchCalibrationData::CalibrationPointPairQuad user_input = {{ | |
| 505 std::make_pair(gfx::Point(100, 100), gfx::Point(100, 100)), | |
| 506 std::make_pair(gfx::Point(1820, 100), gfx::Point(1820, 100)), | |
| 507 std::make_pair(gfx::Point(100, 1100), gfx::Point(100, 1100)), | |
| 508 std::make_pair(gfx::Point(1820, 1100), gfx::Point(1820, 1100)), | |
| 509 }}; | |
| 510 display::TouchCalibrationData touch_data(user_input, DISPLAY_SIZE); | |
| 511 display.SetTouchCalibrationData(touch_data); | |
| 512 EXPECT_TRUE(display.has_touch_calibration_data()); | |
| 513 | |
| 514 gfx::Size fb_size(1920, 1200); | |
| 515 | |
| 516 ui::TouchscreenDevice touchscreen = | |
| 517 CreateTouchscreenDevice(TOUCH_ID, TOUCH_SIZE); | |
| 518 | |
| 519 TouchTransformerController* tt_controller = | |
| 520 Shell::GetInstance()->touch_transformer_controller(); | |
| 521 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance(); | |
| 522 | |
| 523 device_manager->UpdateTouchInfoForDisplay( | |
| 524 display.id(), touchscreen.id, | |
| 525 tt_controller->GetTouchTransform(display, display, touchscreen, | |
| 526 TOUCH_SIZE)); | |
| 527 | |
| 528 EXPECT_EQ(DISPLAY_ID, | |
| 529 device_manager->GetTargetDisplayForTouchDevice(TOUCH_ID)); | |
| 530 | |
| 531 CheckPointsOfInterests(TOUCH_ID, TOUCH_SIZE, DISPLAY_SIZE, gfx::Size(1, 1)); | |
| 532 } | |
| 533 | |
| 534 TEST_F(TouchTransformerControllerTest, ErrorProneUserTouchCalibration) { | |
| 535 const gfx::Size DISPLAY_SIZE(1920, 1200), TOUCH_SIZE(1920, 1200); | |
| 536 const int DISPLAY_ID = 1, TOUCH_ID = 5; | |
| 537 // User touch inputs have a max error of 5%. | |
| 538 const float ERROR = 0.05; | |
| 539 // The maximum user error rate is |ERROR|%. Since the calibration is performed | |
| 540 // with a best fit algorithm, the error rate observed should be less than | |
| 541 // |ERROR|. | |
| 542 const gfx::Size MAX_ERROR_DELTA = gfx::ScaleToCeiledSize(TOUCH_SIZE, ERROR); | |
| 543 | |
| 544 display::ManagedDisplayInfo display = CreateDisplayInfo( | |
| 545 DISPLAY_ID, TOUCH_ID, | |
| 546 gfx::Rect(0, 0, DISPLAY_SIZE.width(), DISPLAY_SIZE.height())); | |
| 547 | |
| 548 // Assuming the user provided accurate inputs during calibration. ie the user | |
| 549 // actually tapped (100,100) when asked to tap (100,100) with no human error. | |
|
malaykeshav
2016/12/19 19:12:01
Update comment.
This is not accurate user input. I
malaykeshav
2016/12/20 09:56:05
Done.
| |
| 550 display::TouchCalibrationData::CalibrationPointPairQuad user_input = { | |
| 551 {std::make_pair(gfx::Point(100, 100), | |
| 552 GetPointWithError(gfx::Point(100, 100), MAX_ERROR_DELTA)), | |
| 553 std::make_pair( | |
| 554 gfx::Point(1820, 100), | |
| 555 GetPointWithError(gfx::Point(1820, 100), MAX_ERROR_DELTA)), | |
| 556 std::make_pair( | |
| 557 gfx::Point(100, 1100), | |
| 558 GetPointWithError(gfx::Point(100, 1100), MAX_ERROR_DELTA)), | |
| 559 std::make_pair( | |
| 560 gfx::Point(1820, 1100), | |
| 561 GetPointWithError(gfx::Point(1820, 1100), MAX_ERROR_DELTA))}}; | |
| 562 display::TouchCalibrationData touch_data(user_input, DISPLAY_SIZE); | |
| 563 display.SetTouchCalibrationData(touch_data); | |
| 564 EXPECT_TRUE(display.has_touch_calibration_data()); | |
| 565 | |
| 566 ui::TouchscreenDevice touchscreen = | |
| 567 CreateTouchscreenDevice(TOUCH_ID, TOUCH_SIZE); | |
| 568 | |
| 569 TouchTransformerController* tt_controller = | |
| 570 Shell::GetInstance()->touch_transformer_controller(); | |
| 571 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance(); | |
| 572 | |
| 573 device_manager->UpdateTouchInfoForDisplay( | |
| 574 display.id(), touchscreen.id, | |
| 575 tt_controller->GetTouchTransform(display, display, touchscreen, | |
| 576 TOUCH_SIZE)); | |
| 577 | |
| 578 EXPECT_EQ(DISPLAY_ID, | |
| 579 device_manager->GetTargetDisplayForTouchDevice(TOUCH_ID)); | |
| 580 | |
| 581 CheckPointsOfInterests(TOUCH_ID, TOUCH_SIZE, DISPLAY_SIZE, MAX_ERROR_DELTA); | |
| 582 } | |
| 583 | |
| 584 TEST_F(TouchTransformerControllerTest, ResolutionChangeUserTouchCalibration) { | |
| 585 const gfx::Size DISPLAY_SIZE(2560, 1600), TOUCH_SIZE(1920, 1200); | |
| 586 const int DISPLAY_ID = 1, TOUCH_ID = 5; | |
| 587 // User touch inputs have a max error of 5%. | |
| 588 const float ERROR = 0.05; | |
| 589 // The maximum user error rate is |ERROR|%. Since the calibration is performed | |
| 590 // with a best fit algorithm, the error rate observed should be less than | |
| 591 // |ERROR|. | |
| 592 gfx::Size MAX_ERROR_DELTA = gfx::ScaleToCeiledSize(DISPLAY_SIZE, ERROR); | |
| 593 | |
| 594 display::ManagedDisplayInfo display = CreateDisplayInfo( | |
| 595 DISPLAY_ID, TOUCH_ID, | |
| 596 gfx::Rect(0, 0, DISPLAY_SIZE.width(), DISPLAY_SIZE.height())); | |
| 597 | |
| 598 // The calibration was performed at a resolution different from the curent | |
| 599 // resolution of the display. | |
| 600 const gfx::Size CALIBRATION_SIZE(1920, 1200); | |
| 601 display::TouchCalibrationData::CalibrationPointPairQuad user_input = { | |
| 602 {std::make_pair(gfx::Point(100, 100), | |
| 603 GetPointWithError(gfx::Point(100, 100), MAX_ERROR_DELTA)), | |
| 604 std::make_pair( | |
| 605 gfx::Point(1820, 100), | |
| 606 GetPointWithError(gfx::Point(1820, 100), MAX_ERROR_DELTA)), | |
| 607 std::make_pair( | |
| 608 gfx::Point(100, 1100), | |
| 609 GetPointWithError(gfx::Point(100, 1100), MAX_ERROR_DELTA)), | |
| 610 std::make_pair( | |
| 611 gfx::Point(1820, 1100), | |
| 612 GetPointWithError(gfx::Point(1820, 1100), MAX_ERROR_DELTA))}}; | |
| 613 display::TouchCalibrationData touch_data(user_input, CALIBRATION_SIZE); | |
| 614 display.SetTouchCalibrationData(touch_data); | |
| 615 EXPECT_TRUE(display.has_touch_calibration_data()); | |
| 616 | |
| 617 ui::TouchscreenDevice touchscreen = | |
| 618 CreateTouchscreenDevice(TOUCH_ID, TOUCH_SIZE); | |
| 619 | |
| 620 TouchTransformerController* tt_controller = | |
| 621 Shell::GetInstance()->touch_transformer_controller(); | |
| 622 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance(); | |
| 623 | |
| 624 device_manager->UpdateTouchInfoForDisplay( | |
| 625 display.id(), touchscreen.id, | |
| 626 tt_controller->GetTouchTransform(display, display, touchscreen, | |
| 627 TOUCH_SIZE)); | |
| 628 | |
| 629 EXPECT_EQ(DISPLAY_ID, | |
| 630 device_manager->GetTargetDisplayForTouchDevice(TOUCH_ID)); | |
| 631 | |
| 632 CheckPointsOfInterests(TOUCH_ID, TOUCH_SIZE, DISPLAY_SIZE, MAX_ERROR_DELTA); | |
| 633 } | |
| 634 | |
| 635 TEST_F(TouchTransformerControllerTest, DifferentBoundsUserTouchCalibration) { | |
| 636 // The display bounds is different from the touch device bounds in this test. | |
| 637 const gfx::Size DISPLAY_SIZE(1024, 600), TOUCH_SIZE(4096, 4096); | |
| 638 const int DISPLAY_ID = 1, TOUCH_ID = 5; | |
| 639 const float ACCEPTABLE_ERROR = 0.04; | |
| 640 gfx::Size MAX_ERROR_DELTA = | |
| 641 gfx::ScaleToCeiledSize(DISPLAY_SIZE, ACCEPTABLE_ERROR); | |
| 642 | |
| 643 display::ManagedDisplayInfo display = CreateDisplayInfo( | |
| 644 DISPLAY_ID, TOUCH_ID, | |
| 645 gfx::Rect(0, 0, DISPLAY_SIZE.width(), DISPLAY_SIZE.height())); | |
| 646 | |
| 647 // Real world data. | |
| 648 display::TouchCalibrationData::CalibrationPointPairQuad user_input = { | |
| 649 {std::make_pair(gfx::Point(136, 136), gfx::Point(538, 931)), | |
| 650 std::make_pair(gfx::Point(873, 136), gfx::Point(3475, 922)), | |
| 651 std::make_pair(gfx::Point(136, 411), gfx::Point(611, 2800)), | |
| 652 std::make_pair(gfx::Point(873, 411), gfx::Point(3535, 2949))}}; | |
| 653 display::TouchCalibrationData touch_data(user_input, DISPLAY_SIZE); | |
| 654 display.SetTouchCalibrationData(touch_data); | |
| 655 EXPECT_TRUE(display.has_touch_calibration_data()); | |
| 656 | |
| 657 ui::TouchscreenDevice touchscreen = | |
| 658 CreateTouchscreenDevice(TOUCH_ID, TOUCH_SIZE); | |
| 659 | |
| 660 TouchTransformerController* tt_controller = | |
| 661 Shell::GetInstance()->touch_transformer_controller(); | |
| 662 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance(); | |
| 663 | |
| 664 device_manager->UpdateTouchInfoForDisplay( | |
| 665 display.id(), touchscreen.id, | |
| 666 tt_controller->GetTouchTransform(display, display, touchscreen, | |
| 667 TOUCH_SIZE)); | |
| 668 | |
| 669 EXPECT_EQ(DISPLAY_ID, | |
| 670 device_manager->GetTargetDisplayForTouchDevice(TOUCH_ID)); | |
| 671 | |
| 672 CheckPointsOfInterests(TOUCH_ID, TOUCH_SIZE, DISPLAY_SIZE, MAX_ERROR_DELTA); | |
| 673 } | |
| 674 | |
| 675 TEST_F(TouchTransformerControllerTest, LetterboxingUserTouchCalibration) { | |
| 676 // The internal display has native resolution of 2560x1700, and in | |
| 677 // mirror mode it is configured as 1920x1200. This is in letterboxing | |
| 678 // mode. | |
| 679 const gfx::Size NATIVE_DISPLAY_SIZE(2560, 1700), DISPLAY_SIZE(1920, 1200), | |
| 680 TOUCH_SIZE(1920, 1200); | |
| 681 const int DISPLAY_ID = 1, TOUCH_ID = 5; | |
| 682 | |
| 683 display::ManagedDisplayInfo internal_display_info = CreateDisplayInfo( | |
| 684 DISPLAY_ID, TOUCH_ID, | |
| 685 gfx::Rect(0, 0, DISPLAY_SIZE.width(), DISPLAY_SIZE.height())); | |
| 686 internal_display_info.set_is_aspect_preserving_scaling(true); | |
| 687 | |
| 688 display::ManagedDisplayInfo::ManagedDisplayModeList internal_modes; | |
| 689 | |
| 690 internal_modes.push_back(make_scoped_refptr(new display::ManagedDisplayMode( | |
| 691 gfx::Size(NATIVE_DISPLAY_SIZE.width(), NATIVE_DISPLAY_SIZE.height()), 60, | |
| 692 false, true))); | |
| 693 internal_modes.push_back(make_scoped_refptr(new display::ManagedDisplayMode( | |
| 694 gfx::Size(DISPLAY_SIZE.width(), DISPLAY_SIZE.height()), 60, false, | |
| 695 false))); | |
| 696 internal_display_info.SetManagedDisplayModes(internal_modes); | |
| 697 | |
| 698 gfx::Size fb_size(DISPLAY_SIZE); | |
| 699 | |
| 700 // Create the touchscreens with the same size as the framebuffer so we can | |
| 701 // share the tests between Ozone & X11. | |
| 702 ui::TouchscreenDevice internal_touchscreen = | |
| 703 CreateTouchscreenDevice(TOUCH_ID, fb_size); | |
| 704 | |
| 705 TouchTransformerController* tt_controller = | |
| 706 Shell::GetInstance()->touch_transformer_controller(); | |
| 707 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance(); | |
| 708 | |
| 709 // Assuming the user provided accurate inputs during calibration. ie the user | |
| 710 // actually tapped (100,100) when asked to tap (100,100) with no human error. | |
| 711 // Since the display is of size 2560x1700 and the touch device is of size | |
| 712 // 1920x1200, the corresponding points have to be scaled. | |
| 713 display::TouchCalibrationData::CalibrationPointPairQuad user_input = {{ | |
| 714 std::make_pair(gfx::Point(100, 100), gfx::Point(75, 71)), | |
| 715 std::make_pair(gfx::Point(2460, 100), gfx::Point(1845, 71)), | |
| 716 std::make_pair(gfx::Point(100, 1600), gfx::Point(75, 1130)), | |
| 717 std::make_pair(gfx::Point(2460, 1600), gfx::Point(1845, 1130)), | |
| 718 }}; | |
| 719 // The calibration was performed at the native display resolution. | |
| 720 display::TouchCalibrationData touch_data(user_input, NATIVE_DISPLAY_SIZE); | |
| 721 internal_display_info.SetTouchCalibrationData(touch_data); | |
| 722 EXPECT_TRUE(internal_display_info.has_touch_calibration_data()); | |
| 723 | |
| 724 device_manager->UpdateTouchInfoForDisplay( | |
| 725 internal_display_info.id(), internal_touchscreen.id, | |
| 726 tt_controller->GetTouchTransform(internal_display_info, | |
| 727 internal_display_info, | |
| 728 internal_touchscreen, fb_size)); | |
| 729 | |
| 730 EXPECT_EQ(DISPLAY_ID, | |
| 731 device_manager->GetTargetDisplayForTouchDevice(TOUCH_ID)); | |
| 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(TOUCH_ID, &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(TOUCH_ID, &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 NATIVE_DISPLAY_SIZE(2560, 1600), DISPLAY_SIZE(1920, 1400), | |
| 758 TOUCH_SIZE(1920, 1400); | |
| 759 const int DISPLAY_ID = 1, TOUCH_ID = 5; | |
| 760 | |
| 761 display::ManagedDisplayInfo internal_display_info = CreateDisplayInfo( | |
| 762 DISPLAY_ID, TOUCH_ID, | |
| 763 gfx::Rect(0, 0, DISPLAY_SIZE.width(), DISPLAY_SIZE.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(NATIVE_DISPLAY_SIZE.width(), NATIVE_DISPLAY_SIZE.height()), 60, | |
| 770 false, true))); | |
| 771 internal_modes.push_back(make_scoped_refptr(new display::ManagedDisplayMode( | |
| 772 gfx::Size(DISPLAY_SIZE.width(), DISPLAY_SIZE.height()), 60, false, | |
| 773 false))); | |
| 774 internal_display_info.SetManagedDisplayModes(internal_modes); | |
| 775 | |
| 776 gfx::Size fb_size(DISPLAY_SIZE); | |
| 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(TOUCH_ID, fb_size); | |
| 782 | |
| 783 TouchTransformerController* tt_controller = | |
| 784 Shell::GetInstance()->touch_transformer_controller(); | |
| 785 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance(); | |
| 786 | |
| 787 // Assuming the user provided accurate inputs during calibration. ie the user | |
| 788 // actually tapped (100,100) when asked to tap (100,100) with no human error. | |
| 789 // Since the display is of size 2560x1600 and the touch device is of size | |
| 790 // 1920x1400, the corresponding points have to be scaled. | |
| 791 display::TouchCalibrationData::CalibrationPointPairQuad user_input = {{ | |
| 792 std::make_pair(gfx::Point(100, 100), gfx::Point(75, 88)), | |
| 793 std::make_pair(gfx::Point(2460, 100), gfx::Point(1845, 88)), | |
| 794 std::make_pair(gfx::Point(100, 1500), gfx::Point(75, 1313)), | |
| 795 std::make_pair(gfx::Point(2460, 1500), gfx::Point(1845, 1313)), | |
| 796 }}; | |
| 797 // The calibration was performed at the native display resolution. | |
| 798 display::TouchCalibrationData touch_data(user_input, NATIVE_DISPLAY_SIZE); | |
| 799 internal_display_info.SetTouchCalibrationData(touch_data); | |
| 800 EXPECT_TRUE(internal_display_info.has_touch_calibration_data()); | |
| 801 | |
| 802 device_manager->UpdateTouchInfoForDisplay( | |
| 803 internal_display_info.id(), internal_touchscreen.id, | |
| 804 tt_controller->GetTouchTransform(internal_display_info, | |
| 805 internal_display_info, | |
| 806 internal_touchscreen, fb_size)); | |
| 807 | |
| 808 EXPECT_EQ(DISPLAY_ID, | |
| 809 device_manager->GetTargetDisplayForTouchDevice(TOUCH_ID)); | |
| 810 | |
| 811 float x, y; | |
| 812 // In pillarboxing, there is (1-1600*(1920/1400)/2560)/2 = 7.14% of the | |
| 813 // width on both the left & region region of the screen is blank. | |
| 814 // When touch events coming at X range [0, 1920), the mapping should be | |
| 815 // [0, ~137] ---> < 0 | |
| 816 // [~137, ~1782] ---> [0, 1920) | |
| 817 // [~1782, 1920] ---> >= 1920 | |
| 818 x = 137.0; | |
| 819 y = 0.0; | |
| 820 device_manager->ApplyTouchTransformer(TOUCH_ID, &x, &y); | |
| 821 EXPECT_NEAR(0, x, 0.5); | |
| 822 EXPECT_NEAR(0, y, 0.5); | |
| 823 | |
| 824 x = 1782.0; | |
| 825 y = 0.0; | |
| 826 device_manager->ApplyTouchTransformer(TOUCH_ID, &x, &y); | |
| 827 EXPECT_NEAR(1920, x, 0.5); | |
| 828 EXPECT_NEAR(0, y, 0.5); | |
| 829 } | |
| 830 | |
| 359 } // namespace ash | 831 } // namespace ash |
| OLD | NEW |