| 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 = "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 typedef test::AshTestBase TouchTransformerControllerTest; |
| 41 | 101 |
| 42 TEST_F(TouchTransformerControllerTest, MirrorModeLetterboxing) { | 102 TEST_F(TouchTransformerControllerTest, MirrorModeLetterboxing) { |
| 43 // The internal display has native resolution of 2560x1700, and in | 103 // The internal display has native resolution of 2560x1700, and in |
| 44 // mirror mode it is configured as 1920x1200. This is in letterboxing | 104 // mirror mode it is configured as 1920x1200. This is in letterboxing |
| 45 // mode. | 105 // mode. |
| 46 display::ManagedDisplayInfo internal_display_info = | 106 display::ManagedDisplayInfo internal_display_info = |
| 47 CreateDisplayInfo(1, 10u, gfx::Rect(0, 0, 1920, 1200)); | 107 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 = | 409 ui::TouchscreenDevice touch_device = |
| 350 CreateTouchscreenDevice(5, gfx::Size(1001, 1001)); | 410 CreateTouchscreenDevice(5, gfx::Size(1001, 1001)); |
| 351 | 411 |
| 352 TouchTransformerController* tt_controller = | 412 TouchTransformerController* tt_controller = |
| 353 Shell::GetInstance()->touch_transformer_controller(); | 413 Shell::GetInstance()->touch_transformer_controller(); |
| 354 // Default touchscreen position range is 1001x1001; | 414 // Default touchscreen position range is 1001x1001; |
| 355 EXPECT_EQ(sqrt((2560.0 * 1600.0) / (1001.0 * 1001.0)), | 415 EXPECT_EQ(sqrt((2560.0 * 1600.0) / (1001.0 * 1001.0)), |
| 356 tt_controller->GetTouchResolutionScale(display, touch_device)); | 416 tt_controller->GetTouchResolutionScale(display, touch_device)); |
| 357 } | 417 } |
| 358 | 418 |
| 419 TEST_F(TouchTransformerControllerTest, OzoneTranslation) { |
| 420 #if defined(USE_OZONE) |
| 421 // The internal display has size 1920 x 1200. The external display has |
| 422 // size 1920x1200. The total frame buffer is 1920x2450, |
| 423 // where 2458 = 1200 + 50 (hidden gap) + 1200 |
| 424 // and the second monitor is translated to Point (0, 1250) in the |
| 425 // framebuffer. |
| 426 const gfx::Size kDisplaySize(1920, 1200); |
| 427 const gfx::Size kTouchSize(1920, 1200); |
| 428 const int kHiddenGap = 50; |
| 429 const int kDisplayId1 = 1; |
| 430 const int kDisplayId2 = 2; |
| 431 const int kTouchId1 = 5; |
| 432 const int kTouchId2 = 6; |
| 433 |
| 434 display::ManagedDisplayInfo display1 = CreateDisplayInfo( |
| 435 kDisplayId1, kTouchId1, |
| 436 gfx::Rect(0, 0, kDisplaySize.width(), kDisplaySize.height())); |
| 437 display::ManagedDisplayInfo display2 = |
| 438 CreateDisplayInfo(kDisplayId2, kTouchId2, |
| 439 gfx::Rect(0, kDisplaySize.height() + kHiddenGap, |
| 440 kDisplaySize.width(), kDisplaySize.height())); |
| 441 |
| 442 gfx::Size fb_size(1920, 2450); |
| 443 |
| 444 ui::TouchscreenDevice touchscreen1 = |
| 445 CreateTouchscreenDevice(kTouchId1, kDisplaySize); |
| 446 ui::TouchscreenDevice touchscreen2 = |
| 447 CreateTouchscreenDevice(kTouchId2, kDisplaySize); |
| 448 |
| 449 TouchTransformerController* tt_controller = |
| 450 Shell::GetInstance()->touch_transformer_controller(); |
| 451 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance(); |
| 452 |
| 453 // Mirror displays. Touch screen 2 is associated to display 1. |
| 454 device_manager->UpdateTouchInfoForDisplay( |
| 455 display1.id(), touchscreen1.id, |
| 456 tt_controller->GetTouchTransform(display1, display1, touchscreen1, |
| 457 kTouchSize)); |
| 458 |
| 459 device_manager->UpdateTouchInfoForDisplay( |
| 460 display1.id(), touchscreen2.id, |
| 461 tt_controller->GetTouchTransform(display1, display2, touchscreen2, |
| 462 kTouchSize)); |
| 463 |
| 464 EXPECT_EQ(kDisplayId1, |
| 465 device_manager->GetTargetDisplayForTouchDevice(kTouchId1)); |
| 466 EXPECT_EQ(kDisplayId1, |
| 467 device_manager->GetTargetDisplayForTouchDevice(kTouchId2)); |
| 468 |
| 469 float x, y; |
| 470 |
| 471 x = y = 0.0; |
| 472 device_manager->ApplyTouchTransformer(kTouchId1, &x, &y); |
| 473 EXPECT_NEAR(0, x, 0.5); |
| 474 EXPECT_NEAR(0, y, 0.5); |
| 475 |
| 476 x = y = 0.0; |
| 477 device_manager->ApplyTouchTransformer(kTouchId2, &x, &y); |
| 478 EXPECT_NEAR(0, x, 0.5); |
| 479 EXPECT_NEAR(0, y, 0.5); |
| 480 |
| 481 x = 1920.0; |
| 482 y = 1200.0; |
| 483 device_manager->ApplyTouchTransformer(kTouchId1, &x, &y); |
| 484 EXPECT_NEAR(1920, x, 0.5); |
| 485 EXPECT_NEAR(1200, y, 0.5); |
| 486 |
| 487 x = 1920.0; |
| 488 y = 1200.0; |
| 489 device_manager->ApplyTouchTransformer(kTouchId2, &x, &y); |
| 490 EXPECT_NEAR(1920, x, 0.5); |
| 491 EXPECT_NEAR(1200, y, 0.5); |
| 492 |
| 493 // Remove mirroring of displays. |
| 494 device_manager->UpdateTouchInfoForDisplay( |
| 495 display2.id(), touchscreen2.id, |
| 496 tt_controller->GetTouchTransform(display2, display2, touchscreen2, |
| 497 kTouchSize)); |
| 498 |
| 499 x = 1920.0; |
| 500 y = 1200.0; |
| 501 device_manager->ApplyTouchTransformer(kTouchId1, &x, &y); |
| 502 EXPECT_NEAR(1920, x, 0.5); |
| 503 EXPECT_NEAR(1200, y, 0.5); |
| 504 |
| 505 x = 1920.0; |
| 506 y = 1200.0; |
| 507 device_manager->ApplyTouchTransformer(kTouchId2, &x, &y); |
| 508 EXPECT_NEAR(1920, x, 0.5); |
| 509 EXPECT_NEAR(1200 + kDisplaySize.height() + kHiddenGap, y, 0.5); |
| 510 #endif |
| 511 } |
| 512 |
| 513 TEST_F(TouchTransformerControllerTest, AccurateUserTouchCalibration) { |
| 514 const gfx::Size kDisplaySize(1920, 1200); |
| 515 const gfx::Size kTouchSize(1920, 1200); |
| 516 const int kDisplayId = 1; |
| 517 const int kTouchId = 5; |
| 518 |
| 519 display::ManagedDisplayInfo display = CreateDisplayInfo( |
| 520 kDisplayId, kTouchId, |
| 521 gfx::Rect(0, 0, kDisplaySize.width(), kDisplaySize.height())); |
| 522 |
| 523 // Assuming the user provided accurate inputs during calibration. ie the user |
| 524 // actually tapped (100,100) when asked to tap (100,100) with no human error. |
| 525 display::TouchCalibrationData::CalibrationPointPairQuad user_input = {{ |
| 526 std::make_pair(gfx::Point(100, 100), gfx::Point(100, 100)), |
| 527 std::make_pair(gfx::Point(1820, 100), gfx::Point(1820, 100)), |
| 528 std::make_pair(gfx::Point(100, 1100), gfx::Point(100, 1100)), |
| 529 std::make_pair(gfx::Point(1820, 1100), gfx::Point(1820, 1100)), |
| 530 }}; |
| 531 display::TouchCalibrationData touch_data(user_input, kDisplaySize); |
| 532 display.SetTouchCalibrationData(touch_data); |
| 533 EXPECT_TRUE(display.has_touch_calibration_data()); |
| 534 |
| 535 const std::string msg = GetTouchPointString(user_input); |
| 536 |
| 537 gfx::Size fb_size(1920, 1200); |
| 538 |
| 539 ui::TouchscreenDevice touchscreen = |
| 540 CreateTouchscreenDevice(kTouchId, kTouchSize); |
| 541 |
| 542 TouchTransformerController* tt_controller = |
| 543 Shell::GetInstance()->touch_transformer_controller(); |
| 544 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance(); |
| 545 |
| 546 device_manager->UpdateTouchInfoForDisplay( |
| 547 display.id(), touchscreen.id, |
| 548 tt_controller->GetTouchTransform(display, display, touchscreen, |
| 549 kTouchSize)); |
| 550 |
| 551 EXPECT_EQ(kDisplayId, |
| 552 device_manager->GetTargetDisplayForTouchDevice(kTouchId)); |
| 553 |
| 554 CheckPointsOfInterests(kTouchId, kTouchSize, kDisplaySize, gfx::Size(1, 1), |
| 555 msg); |
| 556 } |
| 557 |
| 558 TEST_F(TouchTransformerControllerTest, ErrorProneUserTouchCalibration) { |
| 559 const gfx::Size kDisplaySize(1920, 1200); |
| 560 const gfx::Size kTouchSize(1920, 1200); |
| 561 const int kDisplayId = 1; |
| 562 const int kTouchId = 5; |
| 563 // User touch inputs have a max error of 5%. |
| 564 const float kError = 0.05; |
| 565 // The maximum user error rate is |kError|%. Since the calibration is |
| 566 // performed with a best fit algorithm, the error rate observed should be less |
| 567 // than |kError|. |
| 568 const gfx::Size kMaxErrorDelta = gfx::ScaleToCeiledSize(kTouchSize, kError); |
| 569 |
| 570 display::ManagedDisplayInfo display = CreateDisplayInfo( |
| 571 kDisplayId, kTouchId, |
| 572 gfx::Rect(0, 0, kDisplaySize.width(), kDisplaySize.height())); |
| 573 |
| 574 // Assuming the user provided inaccurate inputs during calibration. ie the |
| 575 // user did not tap (100,100) when asked to tap (100,100) due no human error. |
| 576 display::TouchCalibrationData::CalibrationPointPairQuad user_input = { |
| 577 {std::make_pair(gfx::Point(100, 100), |
| 578 GetPointWithError(gfx::Point(100, 100), kMaxErrorDelta)), |
| 579 std::make_pair(gfx::Point(1820, 100), |
| 580 GetPointWithError(gfx::Point(1820, 100), kMaxErrorDelta)), |
| 581 std::make_pair(gfx::Point(100, 1100), |
| 582 GetPointWithError(gfx::Point(100, 1100), kMaxErrorDelta)), |
| 583 std::make_pair( |
| 584 gfx::Point(1820, 1100), |
| 585 GetPointWithError(gfx::Point(1820, 1100), kMaxErrorDelta))}}; |
| 586 display::TouchCalibrationData touch_data(user_input, kDisplaySize); |
| 587 display.SetTouchCalibrationData(touch_data); |
| 588 EXPECT_TRUE(display.has_touch_calibration_data()); |
| 589 |
| 590 const std::string msg = GetTouchPointString(user_input); |
| 591 |
| 592 ui::TouchscreenDevice touchscreen = |
| 593 CreateTouchscreenDevice(kTouchId, kTouchSize); |
| 594 |
| 595 TouchTransformerController* tt_controller = |
| 596 Shell::GetInstance()->touch_transformer_controller(); |
| 597 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance(); |
| 598 |
| 599 device_manager->UpdateTouchInfoForDisplay( |
| 600 display.id(), touchscreen.id, |
| 601 tt_controller->GetTouchTransform(display, display, touchscreen, |
| 602 kTouchSize)); |
| 603 |
| 604 EXPECT_EQ(kDisplayId, |
| 605 device_manager->GetTargetDisplayForTouchDevice(kTouchId)); |
| 606 |
| 607 CheckPointsOfInterests(kTouchId, kTouchSize, kDisplaySize, kMaxErrorDelta, |
| 608 msg); |
| 609 } |
| 610 |
| 611 TEST_F(TouchTransformerControllerTest, ResolutionChangeUserTouchCalibration) { |
| 612 const gfx::Size kDisplaySize(2560, 1600); |
| 613 const gfx::Size kTouchSize(1920, 1200); |
| 614 const int kDisplayId = 1; |
| 615 const int kTouchId = 5; |
| 616 // User touch inputs have a max error of 5%. |
| 617 const float kError = 0.05; |
| 618 // The maximum user error rate is |kError|%. Since the calibration is |
| 619 // performed with a best fit algorithm, the error rate observed should be less |
| 620 // tha |kError|. |
| 621 gfx::Size kMaxErrorDelta = gfx::ScaleToCeiledSize(kDisplaySize, kError); |
| 622 |
| 623 display::ManagedDisplayInfo display = CreateDisplayInfo( |
| 624 kDisplayId, kTouchId, |
| 625 gfx::Rect(0, 0, kDisplaySize.width(), kDisplaySize.height())); |
| 626 |
| 627 // The calibration was performed at a resolution different from the curent |
| 628 // resolution of the display. |
| 629 const gfx::Size CALIBRATION_SIZE(1920, 1200); |
| 630 display::TouchCalibrationData::CalibrationPointPairQuad user_input = { |
| 631 {std::make_pair(gfx::Point(100, 100), |
| 632 GetPointWithError(gfx::Point(100, 100), kMaxErrorDelta)), |
| 633 std::make_pair(gfx::Point(1820, 100), |
| 634 GetPointWithError(gfx::Point(1820, 100), kMaxErrorDelta)), |
| 635 std::make_pair(gfx::Point(100, 1100), |
| 636 GetPointWithError(gfx::Point(100, 1100), kMaxErrorDelta)), |
| 637 std::make_pair( |
| 638 gfx::Point(1820, 1100), |
| 639 GetPointWithError(gfx::Point(1820, 1100), kMaxErrorDelta))}}; |
| 640 display::TouchCalibrationData touch_data(user_input, CALIBRATION_SIZE); |
| 641 display.SetTouchCalibrationData(touch_data); |
| 642 EXPECT_TRUE(display.has_touch_calibration_data()); |
| 643 |
| 644 const std::string msg = GetTouchPointString(user_input); |
| 645 |
| 646 ui::TouchscreenDevice touchscreen = |
| 647 CreateTouchscreenDevice(kTouchId, kTouchSize); |
| 648 |
| 649 TouchTransformerController* tt_controller = |
| 650 Shell::GetInstance()->touch_transformer_controller(); |
| 651 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance(); |
| 652 |
| 653 device_manager->UpdateTouchInfoForDisplay( |
| 654 display.id(), touchscreen.id, |
| 655 tt_controller->GetTouchTransform(display, display, touchscreen, |
| 656 kTouchSize)); |
| 657 |
| 658 EXPECT_EQ(kDisplayId, |
| 659 device_manager->GetTargetDisplayForTouchDevice(kTouchId)); |
| 660 |
| 661 CheckPointsOfInterests(kTouchId, kTouchSize, kDisplaySize, kMaxErrorDelta, |
| 662 msg); |
| 663 } |
| 664 |
| 665 TEST_F(TouchTransformerControllerTest, DifferentBoundsUserTouchCalibration) { |
| 666 // The display bounds is different from the touch device bounds in this test. |
| 667 const gfx::Size kDisplaySize(1024, 600); |
| 668 const gfx::Size kTouchSize(4096, 4096); |
| 669 const int kDisplayId = 1; |
| 670 const int kTouchId = 5; |
| 671 const float kAcceptableError = 0.04; |
| 672 gfx::Size kMaxErrorDelta = |
| 673 gfx::ScaleToCeiledSize(kDisplaySize, kAcceptableError); |
| 674 |
| 675 display::ManagedDisplayInfo display = CreateDisplayInfo( |
| 676 kDisplayId, kTouchId, |
| 677 gfx::Rect(0, 0, kDisplaySize.width(), kDisplaySize.height())); |
| 678 |
| 679 // Real world data. |
| 680 display::TouchCalibrationData::CalibrationPointPairQuad user_input = { |
| 681 {std::make_pair(gfx::Point(136, 136), gfx::Point(538, 931)), |
| 682 std::make_pair(gfx::Point(873, 136), gfx::Point(3475, 922)), |
| 683 std::make_pair(gfx::Point(136, 411), gfx::Point(611, 2800)), |
| 684 std::make_pair(gfx::Point(873, 411), gfx::Point(3535, 2949))}}; |
| 685 display::TouchCalibrationData touch_data(user_input, kDisplaySize); |
| 686 display.SetTouchCalibrationData(touch_data); |
| 687 EXPECT_TRUE(display.has_touch_calibration_data()); |
| 688 |
| 689 const std::string msg = GetTouchPointString(user_input); |
| 690 |
| 691 ui::TouchscreenDevice touchscreen = |
| 692 CreateTouchscreenDevice(kTouchId, kTouchSize); |
| 693 |
| 694 TouchTransformerController* tt_controller = |
| 695 Shell::GetInstance()->touch_transformer_controller(); |
| 696 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance(); |
| 697 |
| 698 device_manager->UpdateTouchInfoForDisplay( |
| 699 display.id(), touchscreen.id, |
| 700 tt_controller->GetTouchTransform(display, display, touchscreen, |
| 701 kTouchSize)); |
| 702 |
| 703 EXPECT_EQ(kDisplayId, |
| 704 device_manager->GetTargetDisplayForTouchDevice(kTouchId)); |
| 705 |
| 706 CheckPointsOfInterests(kTouchId, kTouchSize, kDisplaySize, kMaxErrorDelta, |
| 707 msg); |
| 708 } |
| 709 |
| 710 TEST_F(TouchTransformerControllerTest, LetterboxingUserTouchCalibration) { |
| 711 // The internal display has native resolution of 2560x1700, and in |
| 712 // mirror mode it is configured as 1920x1200. This is in letterboxing |
| 713 // mode. |
| 714 const gfx::Size kNativeDisplaySize(2560, 1700); |
| 715 const gfx::Size kDisplaySize(1920, 1200); |
| 716 const gfx::Size kTouchSize(1920, 1200); |
| 717 const int kDisplayId = 1; |
| 718 const int kTouchId = 5; |
| 719 |
| 720 display::ManagedDisplayInfo internal_display_info = CreateDisplayInfo( |
| 721 kDisplayId, kTouchId, |
| 722 gfx::Rect(0, 0, kDisplaySize.width(), kDisplaySize.height())); |
| 723 internal_display_info.set_is_aspect_preserving_scaling(true); |
| 724 |
| 725 display::ManagedDisplayInfo::ManagedDisplayModeList internal_modes; |
| 726 |
| 727 internal_modes.push_back(make_scoped_refptr(new display::ManagedDisplayMode( |
| 728 gfx::Size(kNativeDisplaySize.width(), kNativeDisplaySize.height()), 60, |
| 729 false, true))); |
| 730 internal_modes.push_back(make_scoped_refptr(new display::ManagedDisplayMode( |
| 731 gfx::Size(kDisplaySize.width(), kDisplaySize.height()), 60, false, |
| 732 false))); |
| 733 internal_display_info.SetManagedDisplayModes(internal_modes); |
| 734 |
| 735 gfx::Size fb_size(kDisplaySize); |
| 736 |
| 737 // Create the touchscreens with the same size as the framebuffer so we can |
| 738 // share the tests between Ozone & X11. |
| 739 ui::TouchscreenDevice internal_touchscreen = |
| 740 CreateTouchscreenDevice(kTouchId, fb_size); |
| 741 |
| 742 TouchTransformerController* tt_controller = |
| 743 Shell::GetInstance()->touch_transformer_controller(); |
| 744 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance(); |
| 745 |
| 746 // Assuming the user provided inaccurate inputs during calibration. ie the |
| 747 // user did not tap (100,100) when asked to tap (100,100) due to human error. |
| 748 // Since the display is of size 2560x1700 and the touch device is of size |
| 749 // 1920x1200, the corresponding points have to be scaled. |
| 750 display::TouchCalibrationData::CalibrationPointPairQuad user_input = {{ |
| 751 std::make_pair(gfx::Point(100, 100), gfx::Point(75, 71)), |
| 752 std::make_pair(gfx::Point(2460, 100), gfx::Point(1845, 71)), |
| 753 std::make_pair(gfx::Point(100, 1600), gfx::Point(75, 1130)), |
| 754 std::make_pair(gfx::Point(2460, 1600), gfx::Point(1845, 1130)), |
| 755 }}; |
| 756 // The calibration was performed at the native display resolution. |
| 757 display::TouchCalibrationData touch_data(user_input, kNativeDisplaySize); |
| 758 internal_display_info.SetTouchCalibrationData(touch_data); |
| 759 EXPECT_TRUE(internal_display_info.has_touch_calibration_data()); |
| 760 |
| 761 device_manager->UpdateTouchInfoForDisplay( |
| 762 internal_display_info.id(), internal_touchscreen.id, |
| 763 tt_controller->GetTouchTransform(internal_display_info, |
| 764 internal_display_info, |
| 765 internal_touchscreen, fb_size)); |
| 766 |
| 767 EXPECT_EQ(kDisplayId, |
| 768 device_manager->GetTargetDisplayForTouchDevice(kTouchId)); |
| 769 |
| 770 float x, y; |
| 771 // In letterboxing, there is (1-2560*(1200/1920)/1700)/2 = 2.95% of the |
| 772 // height on both the top & bottom region of the screen is blank. |
| 773 // When touch events coming at Y range [0, 1200), the mapping should be |
| 774 // [0, ~35] ---> < 0 |
| 775 // [~35, ~1165] ---> [0, 1200) |
| 776 // [~1165, 1200] ---> >= 1200 |
| 777 x = 100.0; |
| 778 y = 35.0; |
| 779 device_manager->ApplyTouchTransformer(kTouchId, &x, &y); |
| 780 EXPECT_NEAR(100, x, 0.5); |
| 781 EXPECT_NEAR(0, y, 0.5); |
| 782 |
| 783 x = 100.0; |
| 784 y = 1165.0; |
| 785 device_manager->ApplyTouchTransformer(kTouchId, &x, &y); |
| 786 EXPECT_NEAR(100, x, 0.5); |
| 787 EXPECT_NEAR(1200, y, 0.5); |
| 788 } |
| 789 |
| 790 TEST_F(TouchTransformerControllerTest, PillarBoxingUserTouchCalibration) { |
| 791 // The internal display has native resolution of 2560x1700, and in |
| 792 // mirror mode it is configured as 1920x1200. This is in letterboxing |
| 793 // mode. |
| 794 const gfx::Size kNativeDisplaySize(2560, 1600); |
| 795 const gfx::Size kDisplaySize(1920, 1400); |
| 796 const gfx::Size kTouchSize(1920, 1400); |
| 797 const int kDisplayId = 1; |
| 798 const int kTouchId = 5; |
| 799 |
| 800 display::ManagedDisplayInfo internal_display_info = CreateDisplayInfo( |
| 801 kDisplayId, kTouchId, |
| 802 gfx::Rect(0, 0, kDisplaySize.width(), kDisplaySize.height())); |
| 803 internal_display_info.set_is_aspect_preserving_scaling(true); |
| 804 |
| 805 display::ManagedDisplayInfo::ManagedDisplayModeList internal_modes; |
| 806 |
| 807 internal_modes.push_back(make_scoped_refptr(new display::ManagedDisplayMode( |
| 808 gfx::Size(kNativeDisplaySize.width(), kNativeDisplaySize.height()), 60, |
| 809 false, true))); |
| 810 internal_modes.push_back(make_scoped_refptr(new display::ManagedDisplayMode( |
| 811 gfx::Size(kDisplaySize.width(), kDisplaySize.height()), 60, false, |
| 812 false))); |
| 813 internal_display_info.SetManagedDisplayModes(internal_modes); |
| 814 |
| 815 gfx::Size fb_size(kDisplaySize); |
| 816 |
| 817 // Create the touchscreens with the same size as the framebuffer so we can |
| 818 // share the tests between Ozone & X11. |
| 819 ui::TouchscreenDevice internal_touchscreen = |
| 820 CreateTouchscreenDevice(kTouchId, fb_size); |
| 821 |
| 822 TouchTransformerController* tt_controller = |
| 823 Shell::GetInstance()->touch_transformer_controller(); |
| 824 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance(); |
| 825 |
| 826 // Assuming the user provided accurate inputs during calibration. ie the user |
| 827 // actually tapped (100,100) when asked to tap (100,100) with no human error. |
| 828 // Since the display is of size 2560x1600 and the touch device is of size |
| 829 // 1920x1400, the corresponding points have to be scaled. |
| 830 display::TouchCalibrationData::CalibrationPointPairQuad user_input = {{ |
| 831 std::make_pair(gfx::Point(100, 100), gfx::Point(75, 88)), |
| 832 std::make_pair(gfx::Point(2460, 100), gfx::Point(1845, 88)), |
| 833 std::make_pair(gfx::Point(100, 1500), gfx::Point(75, 1313)), |
| 834 std::make_pair(gfx::Point(2460, 1500), gfx::Point(1845, 1313)), |
| 835 }}; |
| 836 // The calibration was performed at the native display resolution. |
| 837 display::TouchCalibrationData touch_data(user_input, kNativeDisplaySize); |
| 838 internal_display_info.SetTouchCalibrationData(touch_data); |
| 839 EXPECT_TRUE(internal_display_info.has_touch_calibration_data()); |
| 840 |
| 841 device_manager->UpdateTouchInfoForDisplay( |
| 842 internal_display_info.id(), internal_touchscreen.id, |
| 843 tt_controller->GetTouchTransform(internal_display_info, |
| 844 internal_display_info, |
| 845 internal_touchscreen, fb_size)); |
| 846 |
| 847 EXPECT_EQ(kDisplayId, |
| 848 device_manager->GetTargetDisplayForTouchDevice(kTouchId)); |
| 849 |
| 850 float x, y; |
| 851 // In pillarboxing, there is (1-1600*(1920/1400)/2560)/2 = 7.14% of the |
| 852 // width on both the left & region region of the screen is blank. |
| 853 // When touch events coming at X range [0, 1920), the mapping should be |
| 854 // [0, ~137] ---> < 0 |
| 855 // [~137, ~1782] ---> [0, 1920) |
| 856 // [~1782, 1920] ---> >= 1920 |
| 857 x = 137.0; |
| 858 y = 0.0; |
| 859 device_manager->ApplyTouchTransformer(kTouchId, &x, &y); |
| 860 EXPECT_NEAR(0, x, 0.5); |
| 861 EXPECT_NEAR(0, y, 0.5); |
| 862 |
| 863 x = 1782.0; |
| 864 y = 0.0; |
| 865 device_manager->ApplyTouchTransformer(kTouchId, &x, &y); |
| 866 EXPECT_NEAR(1920, x, 0.5); |
| 867 EXPECT_NEAR(0, y, 0.5); |
| 868 } |
| 869 |
| 359 } // namespace ash | 870 } // namespace ash |
| OLD | NEW |