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

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

Issue 2557163002: Implements computation of touch calibration transform using user provided data (Closed)
Patch Set: Sync with ToT Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/touch/touch_transformer_controller.h" 5 #include "ash/touch/touch_transformer_controller.h"
6 6
7 #include "ash/shell.h" 7 #include "ash/shell.h"
8 #include "ash/test/ash_test_base.h" 8 #include "ash/test/ash_test_base.h"
9 #include "base/rand_util.h"
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"
11 12
12 namespace ash { 13 namespace ash {
13 14
14 namespace { 15 namespace {
15 16
16 display::ManagedDisplayInfo CreateDisplayInfo(int64_t id, 17 display::ManagedDisplayInfo CreateDisplayInfo(int64_t id,
17 unsigned int touch_device_id, 18 unsigned int touch_device_id,
18 const gfx::Rect& bounds) { 19 const gfx::Rect& bounds) {
19 display::ManagedDisplayInfo info(id, std::string(), false); 20 display::ManagedDisplayInfo info(id, std::string(), false);
20 info.SetBounds(bounds); 21 info.SetBounds(bounds);
21 info.AddInputDevice(touch_device_id); 22 info.AddInputDevice(touch_device_id);
22 23
23 // Create a default mode. 24 // Create a default mode.
24 display::ManagedDisplayInfo::ManagedDisplayModeList default_modes( 25 display::ManagedDisplayInfo::ManagedDisplayModeList default_modes(
25 1, make_scoped_refptr( 26 1, make_scoped_refptr(
26 new display::ManagedDisplayMode(bounds.size(), 60, false, true))); 27 new display::ManagedDisplayMode(bounds.size(), 60, false, true)));
27 info.SetManagedDisplayModes(default_modes); 28 info.SetManagedDisplayModes(default_modes);
28 29
29 return info; 30 return info;
30 } 31 }
31 32
32 ui::TouchscreenDevice CreateTouchscreenDevice(unsigned int id, 33 ui::TouchscreenDevice CreateTouchscreenDevice(unsigned int id,
33 const gfx::Size& size) { 34 const gfx::Size& size) {
34 return ui::TouchscreenDevice(id, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, 35 return ui::TouchscreenDevice(id, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL,
35 std::string(), size, 0); 36 std::string(), size, 0);
36 } 37 }
37 38
39 // Returns a point close to |point| with some error. This is to simulate human
40 // input that is prone to a max delta error of |error.width()| or
41 // |error.height()|.
42 gfx::Point GetPointWithError(const gfx::Point& point, const gfx::Size& error) {
43 return gfx::Point(
44 point.x() + base::RandInt(-error.width() / 2, error.width() / 2),
45 point.y() + base::RandInt(-error.height() / 2, error.height() / 2));
46 }
47
48 // Checks if the touch input has been calibrated properly. The input is said to
49 // be calibrated if any touch input is transformed to the correct corresponding
50 // display point within an error delta of |max_error_delta.width()| along the X
51 // axis and |max_error_delta.height()| along the Y axis;
52 void CheckPointsOfInterests(const int touch_id,
53 const gfx::Size& touch_size,
54 const gfx::Size& display_size,
55 const gfx::Size& max_error_delta) {
56 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance();
57 float x, y;
58
59 // Origin of the touch device should correspond to origin of the display.
60 x = y = 0.0;
61 device_manager->ApplyTouchTransformer(touch_id, &x, &y);
62 EXPECT_NEAR(0, x, max_error_delta.width());
63 EXPECT_NEAR(0, y, max_error_delta.height());
64
65 // Center of the touch device should correspond to the center of the display
66 // device.
67 x = touch_size.width() / 2;
68 y = touch_size.height() / 2;
69 device_manager->ApplyTouchTransformer(touch_id, &x, &y);
70 EXPECT_NEAR(display_size.width() / 2, x, max_error_delta.width());
71 EXPECT_NEAR(display_size.height() / 2, y, max_error_delta.height());
72
73 // Bottom right corner of the touch device should correspond to rightmost
74 // corner of display device.
75 x = touch_size.width();
76 y = touch_size.height();
77 device_manager->ApplyTouchTransformer(touch_id, &x, &y);
78 EXPECT_NEAR(display_size.width(), x, max_error_delta.width());
79 EXPECT_NEAR(display_size.height(), y, max_error_delta.height());
80 }
81
38 } // namespace 82 } // namespace
39 83
40 typedef test::AshTestBase TouchTransformerControllerTest; 84 typedef test::AshTestBase TouchTransformerControllerTest;
41 85
42 TEST_F(TouchTransformerControllerTest, MirrorModeLetterboxing) { 86 TEST_F(TouchTransformerControllerTest, MirrorModeLetterboxing) {
43 // The internal display has native resolution of 2560x1700, and in 87 // The internal display has native resolution of 2560x1700, and in
44 // mirror mode it is configured as 1920x1200. This is in letterboxing 88 // mirror mode it is configured as 1920x1200. This is in letterboxing
45 // mode. 89 // mode.
46 display::ManagedDisplayInfo internal_display_info = 90 display::ManagedDisplayInfo internal_display_info =
47 CreateDisplayInfo(1, 10u, gfx::Rect(0, 0, 1920, 1200)); 91 CreateDisplayInfo(1, 10u, gfx::Rect(0, 0, 1920, 1200));
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 ui::TouchscreenDevice touch_device = 393 ui::TouchscreenDevice touch_device =
350 CreateTouchscreenDevice(5, gfx::Size(1001, 1001)); 394 CreateTouchscreenDevice(5, gfx::Size(1001, 1001));
351 395
352 TouchTransformerController* tt_controller = 396 TouchTransformerController* tt_controller =
353 Shell::GetInstance()->touch_transformer_controller(); 397 Shell::GetInstance()->touch_transformer_controller();
354 // Default touchscreen position range is 1001x1001; 398 // Default touchscreen position range is 1001x1001;
355 EXPECT_EQ(sqrt((2560.0 * 1600.0) / (1001.0 * 1001.0)), 399 EXPECT_EQ(sqrt((2560.0 * 1600.0) / (1001.0 * 1001.0)),
356 tt_controller->GetTouchResolutionScale(display, touch_device)); 400 tt_controller->GetTouchResolutionScale(display, touch_device));
357 } 401 }
358 402
403 TEST_F(TouchTransformerControllerTest, OzoneTranslation) {
404 #if defined(USE_OZONE)
405 // The internal display has size 1920 x 1200. The external display has
406 // size 1920x1200. The total frame buffer is 1920x2450,
407 // where 2458 = 1200 + 50 (hidden gap) + 1200
408 // and the second monitor is translated to Point (0, 1250) in the
409 // framebuffer.
410 const gfx::Size kDisplaySize(1920, 1200);
411 const gfx::Size kTouchSize(1920, 1200);
412 const int kHiddenGap = 50;
413 const int kDisplayId1 = 1;
414 const int kDisplayId2 = 2;
415 const int kTouchId1 = 5;
416 const int kTouchId2 = 6;
417
418 display::ManagedDisplayInfo display1 = CreateDisplayInfo(
419 kDisplayId1, kTouchId1,
420 gfx::Rect(0, 0, kDisplaySize.width(), kDisplaySize.height()));
421 display::ManagedDisplayInfo display2 =
422 CreateDisplayInfo(kDisplayId2, kTouchId2,
423 gfx::Rect(0, kDisplaySize.height() + kHiddenGap,
424 kDisplaySize.width(), kDisplaySize.height()));
425
426 gfx::Size fb_size(1920, 2450);
427
428 ui::TouchscreenDevice touchscreen1 =
429 CreateTouchscreenDevice(kTouchId1, kDisplaySize);
430 ui::TouchscreenDevice touchscreen2 =
431 CreateTouchscreenDevice(kTouchId2, kDisplaySize);
432
433 TouchTransformerController* tt_controller =
434 Shell::GetInstance()->touch_transformer_controller();
435 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance();
436
437 // Mirror displays. Touch screen 2 is associated to display 1.
438 device_manager->UpdateTouchInfoForDisplay(
439 display1.id(), touchscreen1.id,
440 tt_controller->GetTouchTransform(display1, display1, touchscreen1,
441 kTouchSize));
442
443 device_manager->UpdateTouchInfoForDisplay(
444 display1.id(), touchscreen2.id,
445 tt_controller->GetTouchTransform(display1, display2, touchscreen2,
446 kTouchSize));
447
448 EXPECT_EQ(kDisplayId1,
449 device_manager->GetTargetDisplayForTouchDevice(kTouchId1));
450 EXPECT_EQ(kDisplayId1,
451 device_manager->GetTargetDisplayForTouchDevice(kTouchId2));
452
453 float x, y;
454
455 x = y = 0.0;
456 device_manager->ApplyTouchTransformer(kTouchId1, &x, &y);
457 EXPECT_NEAR(0, x, 0.5);
458 EXPECT_NEAR(0, y, 0.5);
459
460 x = y = 0.0;
461 device_manager->ApplyTouchTransformer(kTouchId2, &x, &y);
462 EXPECT_NEAR(0, x, 0.5);
463 EXPECT_NEAR(0, y, 0.5);
464
465 x = 1920.0;
466 y = 1200.0;
467 device_manager->ApplyTouchTransformer(kTouchId1, &x, &y);
468 EXPECT_NEAR(1920, x, 0.5);
469 EXPECT_NEAR(1200, y, 0.5);
470
471 x = 1920.0;
472 y = 1200.0;
473 device_manager->ApplyTouchTransformer(kTouchId2, &x, &y);
474 EXPECT_NEAR(1920, x, 0.5);
475 EXPECT_NEAR(1200, y, 0.5);
476
477 // Remove mirroring of displays.
478 device_manager->UpdateTouchInfoForDisplay(
479 display2.id(), touchscreen2.id,
480 tt_controller->GetTouchTransform(display2, display2, touchscreen2,
481 kTouchSize));
482
483 x = 1920.0;
484 y = 1200.0;
485 device_manager->ApplyTouchTransformer(kTouchId1, &x, &y);
486 EXPECT_NEAR(1920, x, 0.5);
487 EXPECT_NEAR(1200, y, 0.5);
488
489 x = 1920.0;
490 y = 1200.0;
491 device_manager->ApplyTouchTransformer(kTouchId2, &x, &y);
492 EXPECT_NEAR(1920, x, 0.5);
493 EXPECT_NEAR(1200 + kDisplaySize.height() + kHiddenGap, y, 0.5);
494 #endif
495 }
496
497 TEST_F(TouchTransformerControllerTest, AccurateUserTouchCalibration) {
498 const gfx::Size kDisplaySize(1920, 1200);
499 const gfx::Size kTouchSize(1920, 1200);
500 const int kDisplayId = 1;
501 const int kTouchId = 5;
502
503 display::ManagedDisplayInfo display = CreateDisplayInfo(
504 kDisplayId, kTouchId,
505 gfx::Rect(0, 0, kDisplaySize.width(), kDisplaySize.height()));
506
507 // Assuming the user provided accurate inputs during calibration. ie the user
508 // actually tapped (100,100) when asked to tap (100,100) with no human error.
509 display::TouchCalibrationData::CalibrationPointPairQuad user_input = {{
510 std::make_pair(gfx::Point(100, 100), gfx::Point(100, 100)),
511 std::make_pair(gfx::Point(1820, 100), gfx::Point(1820, 100)),
512 std::make_pair(gfx::Point(100, 1100), gfx::Point(100, 1100)),
513 std::make_pair(gfx::Point(1820, 1100), gfx::Point(1820, 1100)),
514 }};
515 display::TouchCalibrationData touch_data(user_input, kDisplaySize);
516 display.SetTouchCalibrationData(touch_data);
517 EXPECT_TRUE(display.has_touch_calibration_data());
518
519 gfx::Size fb_size(1920, 1200);
520
521 ui::TouchscreenDevice touchscreen =
522 CreateTouchscreenDevice(kTouchId, kTouchSize);
523
524 TouchTransformerController* tt_controller =
525 Shell::GetInstance()->touch_transformer_controller();
526 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance();
527
528 device_manager->UpdateTouchInfoForDisplay(
529 display.id(), touchscreen.id,
530 tt_controller->GetTouchTransform(display, display, touchscreen,
531 kTouchSize));
532
533 EXPECT_EQ(kDisplayId,
534 device_manager->GetTargetDisplayForTouchDevice(kTouchId));
535
536 CheckPointsOfInterests(kTouchId, kTouchSize, kDisplaySize, gfx::Size(1, 1));
537 }
538
539 TEST_F(TouchTransformerControllerTest, ErrorProneUserTouchCalibration) {
540 const gfx::Size kDisplaySize(1920, 1200);
541 const gfx::Size kTouchSize(1920, 1200);
542 const int kDisplayId = 1;
543 const int kTouchId = 5;
544 // User touch inputs have a max error of 5%.
545 const float kError = 0.05;
546 // The maximum user error rate is |ERROR|%. Since the calibration is performed
kylechar 2016/12/20 17:41:28 The variable names weren't updated with the variab
malaykeshav 2016/12/20 19:16:56 Yes. I seemed to have missed updating the comments
547 // with a best fit algorithm, the error rate observed should be less than
548 // |ERROR|.
549 const gfx::Size kMaxErrorDelta = gfx::ScaleToCeiledSize(kTouchSize, kError);
550
551 display::ManagedDisplayInfo display = CreateDisplayInfo(
552 kDisplayId, kTouchId,
553 gfx::Rect(0, 0, kDisplaySize.width(), kDisplaySize.height()));
554
555 // Assuming the user provided inaccurate inputs during calibration. ie the
556 // user did not tap (100,100) when asked to tap (100,100) due no human error.
557 display::TouchCalibrationData::CalibrationPointPairQuad user_input = {
558 {std::make_pair(gfx::Point(100, 100),
559 GetPointWithError(gfx::Point(100, 100), kMaxErrorDelta)),
560 std::make_pair(gfx::Point(1820, 100),
561 GetPointWithError(gfx::Point(1820, 100), kMaxErrorDelta)),
562 std::make_pair(gfx::Point(100, 1100),
563 GetPointWithError(gfx::Point(100, 1100), kMaxErrorDelta)),
564 std::make_pair(
565 gfx::Point(1820, 1100),
566 GetPointWithError(gfx::Point(1820, 1100), kMaxErrorDelta))}};
567 display::TouchCalibrationData touch_data(user_input, kDisplaySize);
568 display.SetTouchCalibrationData(touch_data);
569 EXPECT_TRUE(display.has_touch_calibration_data());
570
571 ui::TouchscreenDevice touchscreen =
572 CreateTouchscreenDevice(kTouchId, kTouchSize);
573
574 TouchTransformerController* tt_controller =
575 Shell::GetInstance()->touch_transformer_controller();
576 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance();
577
578 device_manager->UpdateTouchInfoForDisplay(
579 display.id(), touchscreen.id,
580 tt_controller->GetTouchTransform(display, display, touchscreen,
581 kTouchSize));
582
583 EXPECT_EQ(kDisplayId,
584 device_manager->GetTargetDisplayForTouchDevice(kTouchId));
585
586 CheckPointsOfInterests(kTouchId, kTouchSize, kDisplaySize, kMaxErrorDelta);
587 }
588
589 TEST_F(TouchTransformerControllerTest, ResolutionChangeUserTouchCalibration) {
590 const gfx::Size kDisplaySize(2560, 1600);
591 const gfx::Size kTouchSize(1920, 1200);
592 const int kDisplayId = 1;
593 const int kTouchId = 5;
594 // User touch inputs have a max error of 5%.
595 const float kError = 0.05;
596 // The maximum user error rate is |ERROR|%. Since the calibration is performed
597 // with a best fit algorithm, the error rate observed should be less than
598 // |ERROR|.
599 gfx::Size kMaxErrorDelta = gfx::ScaleToCeiledSize(kDisplaySize, kError);
600
601 display::ManagedDisplayInfo display = CreateDisplayInfo(
602 kDisplayId, kTouchId,
603 gfx::Rect(0, 0, kDisplaySize.width(), kDisplaySize.height()));
604
605 // The calibration was performed at a resolution different from the curent
606 // resolution of the display.
607 const gfx::Size CALIBRATION_SIZE(1920, 1200);
608 display::TouchCalibrationData::CalibrationPointPairQuad user_input = {
609 {std::make_pair(gfx::Point(100, 100),
610 GetPointWithError(gfx::Point(100, 100), kMaxErrorDelta)),
611 std::make_pair(gfx::Point(1820, 100),
612 GetPointWithError(gfx::Point(1820, 100), kMaxErrorDelta)),
613 std::make_pair(gfx::Point(100, 1100),
614 GetPointWithError(gfx::Point(100, 1100), kMaxErrorDelta)),
615 std::make_pair(
616 gfx::Point(1820, 1100),
617 GetPointWithError(gfx::Point(1820, 1100), kMaxErrorDelta))}};
618 display::TouchCalibrationData touch_data(user_input, CALIBRATION_SIZE);
619 display.SetTouchCalibrationData(touch_data);
620 EXPECT_TRUE(display.has_touch_calibration_data());
621
622 ui::TouchscreenDevice touchscreen =
623 CreateTouchscreenDevice(kTouchId, kTouchSize);
624
625 TouchTransformerController* tt_controller =
626 Shell::GetInstance()->touch_transformer_controller();
627 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance();
628
629 device_manager->UpdateTouchInfoForDisplay(
630 display.id(), touchscreen.id,
631 tt_controller->GetTouchTransform(display, display, touchscreen,
632 kTouchSize));
633
634 EXPECT_EQ(kDisplayId,
635 device_manager->GetTargetDisplayForTouchDevice(kTouchId));
636
637 CheckPointsOfInterests(kTouchId, kTouchSize, kDisplaySize, kMaxErrorDelta);
638 }
639
640 TEST_F(TouchTransformerControllerTest, DifferentBoundsUserTouchCalibration) {
641 // The display bounds is different from the touch device bounds in this test.
642 const gfx::Size kDisplaySize(1024, 600);
643 const gfx::Size kTouchSize(4096, 4096);
644 const int kDisplayId = 1;
645 const int kTouchId = 5;
646 const float kAcceptableError = 0.04;
647 gfx::Size kMaxErrorDelta =
648 gfx::ScaleToCeiledSize(kDisplaySize, kAcceptableError);
649
650 display::ManagedDisplayInfo display = CreateDisplayInfo(
651 kDisplayId, kTouchId,
652 gfx::Rect(0, 0, kDisplaySize.width(), kDisplaySize.height()));
653
654 // Real world data.
655 display::TouchCalibrationData::CalibrationPointPairQuad user_input = {
656 {std::make_pair(gfx::Point(136, 136), gfx::Point(538, 931)),
657 std::make_pair(gfx::Point(873, 136), gfx::Point(3475, 922)),
658 std::make_pair(gfx::Point(136, 411), gfx::Point(611, 2800)),
659 std::make_pair(gfx::Point(873, 411), gfx::Point(3535, 2949))}};
660 display::TouchCalibrationData touch_data(user_input, kDisplaySize);
661 display.SetTouchCalibrationData(touch_data);
662 EXPECT_TRUE(display.has_touch_calibration_data());
663
664 ui::TouchscreenDevice touchscreen =
665 CreateTouchscreenDevice(kTouchId, kTouchSize);
666
667 TouchTransformerController* tt_controller =
668 Shell::GetInstance()->touch_transformer_controller();
669 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance();
670
671 device_manager->UpdateTouchInfoForDisplay(
672 display.id(), touchscreen.id,
673 tt_controller->GetTouchTransform(display, display, touchscreen,
674 kTouchSize));
675
676 EXPECT_EQ(kDisplayId,
677 device_manager->GetTargetDisplayForTouchDevice(kTouchId));
678
679 CheckPointsOfInterests(kTouchId, kTouchSize, kDisplaySize, kMaxErrorDelta);
680 }
681
682 TEST_F(TouchTransformerControllerTest, LetterboxingUserTouchCalibration) {
683 // The internal display has native resolution of 2560x1700, and in
684 // mirror mode it is configured as 1920x1200. This is in letterboxing
685 // mode.
686 const gfx::Size kNativeDisplaySize(2560, 1700);
687 const gfx::Size kDisplaySize(1920, 1200);
688 const gfx::Size kTouchSize(1920, 1200);
689 const int kDisplayId = 1;
690 const int kTouchId = 5;
691
692 display::ManagedDisplayInfo internal_display_info = CreateDisplayInfo(
693 kDisplayId, kTouchId,
694 gfx::Rect(0, 0, kDisplaySize.width(), kDisplaySize.height()));
695 internal_display_info.set_is_aspect_preserving_scaling(true);
696
697 display::ManagedDisplayInfo::ManagedDisplayModeList internal_modes;
698
699 internal_modes.push_back(make_scoped_refptr(new display::ManagedDisplayMode(
700 gfx::Size(kNativeDisplaySize.width(), kNativeDisplaySize.height()), 60,
701 false, true)));
702 internal_modes.push_back(make_scoped_refptr(new display::ManagedDisplayMode(
703 gfx::Size(kDisplaySize.width(), kDisplaySize.height()), 60, false,
704 false)));
705 internal_display_info.SetManagedDisplayModes(internal_modes);
706
707 gfx::Size fb_size(kDisplaySize);
708
709 // Create the touchscreens with the same size as the framebuffer so we can
710 // share the tests between Ozone & X11.
711 ui::TouchscreenDevice internal_touchscreen =
712 CreateTouchscreenDevice(kTouchId, fb_size);
713
714 TouchTransformerController* tt_controller =
715 Shell::GetInstance()->touch_transformer_controller();
716 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance();
717
718 // Assuming the user provided accurate inputs during calibration. ie the user
719 // actually tapped (100,100) when asked to tap (100,100) with no human error.
720 // Since the display is of size 2560x1700 and the touch device is of size
721 // 1920x1200, the corresponding points have to be scaled.
722 display::TouchCalibrationData::CalibrationPointPairQuad user_input = {{
723 std::make_pair(gfx::Point(100, 100), gfx::Point(75, 71)),
724 std::make_pair(gfx::Point(2460, 100), gfx::Point(1845, 71)),
725 std::make_pair(gfx::Point(100, 1600), gfx::Point(75, 1130)),
726 std::make_pair(gfx::Point(2460, 1600), gfx::Point(1845, 1130)),
727 }};
728 // The calibration was performed at the native display resolution.
729 display::TouchCalibrationData touch_data(user_input, kNativeDisplaySize);
730 internal_display_info.SetTouchCalibrationData(touch_data);
731 EXPECT_TRUE(internal_display_info.has_touch_calibration_data());
732
733 device_manager->UpdateTouchInfoForDisplay(
734 internal_display_info.id(), internal_touchscreen.id,
735 tt_controller->GetTouchTransform(internal_display_info,
736 internal_display_info,
737 internal_touchscreen, fb_size));
738
739 EXPECT_EQ(kDisplayId,
740 device_manager->GetTargetDisplayForTouchDevice(kTouchId));
741
742 float x, y;
743 // In letterboxing, there is (1-2560*(1200/1920)/1700)/2 = 2.95% of the
744 // height on both the top & bottom region of the screen is blank.
745 // When touch events coming at Y range [0, 1200), the mapping should be
746 // [0, ~35] ---> < 0
747 // [~35, ~1165] ---> [0, 1200)
748 // [~1165, 1200] ---> >= 1200
749 x = 100.0;
750 y = 35.0;
751 device_manager->ApplyTouchTransformer(kTouchId, &x, &y);
752 EXPECT_NEAR(100, x, 0.5);
753 EXPECT_NEAR(0, y, 0.5);
754
755 x = 100.0;
756 y = 1165.0;
757 device_manager->ApplyTouchTransformer(kTouchId, &x, &y);
758 EXPECT_NEAR(100, x, 0.5);
759 EXPECT_NEAR(1200, y, 0.5);
760 }
761
762 TEST_F(TouchTransformerControllerTest, PillarBoxingUserTouchCalibration) {
763 // The internal display has native resolution of 2560x1700, and in
764 // mirror mode it is configured as 1920x1200. This is in letterboxing
765 // mode.
766 const gfx::Size kNativeDisplaySize(2560, 1600);
767 const gfx::Size kDisplaySize(1920, 1400);
768 const gfx::Size kTouchSize(1920, 1400);
769 const int kDisplayId = 1;
770 const int kTouchId = 5;
771
772 display::ManagedDisplayInfo internal_display_info = CreateDisplayInfo(
773 kDisplayId, kTouchId,
774 gfx::Rect(0, 0, kDisplaySize.width(), kDisplaySize.height()));
775 internal_display_info.set_is_aspect_preserving_scaling(true);
776
777 display::ManagedDisplayInfo::ManagedDisplayModeList internal_modes;
778
779 internal_modes.push_back(make_scoped_refptr(new display::ManagedDisplayMode(
780 gfx::Size(kNativeDisplaySize.width(), kNativeDisplaySize.height()), 60,
781 false, true)));
782 internal_modes.push_back(make_scoped_refptr(new display::ManagedDisplayMode(
783 gfx::Size(kDisplaySize.width(), kDisplaySize.height()), 60, false,
784 false)));
785 internal_display_info.SetManagedDisplayModes(internal_modes);
786
787 gfx::Size fb_size(kDisplaySize);
788
789 // Create the touchscreens with the same size as the framebuffer so we can
790 // share the tests between Ozone & X11.
791 ui::TouchscreenDevice internal_touchscreen =
792 CreateTouchscreenDevice(kTouchId, fb_size);
793
794 TouchTransformerController* tt_controller =
795 Shell::GetInstance()->touch_transformer_controller();
796 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance();
797
798 // Assuming the user provided accurate inputs during calibration. ie the user
799 // actually tapped (100,100) when asked to tap (100,100) with no human error.
800 // Since the display is of size 2560x1600 and the touch device is of size
801 // 1920x1400, the corresponding points have to be scaled.
802 display::TouchCalibrationData::CalibrationPointPairQuad user_input = {{
803 std::make_pair(gfx::Point(100, 100), gfx::Point(75, 88)),
804 std::make_pair(gfx::Point(2460, 100), gfx::Point(1845, 88)),
805 std::make_pair(gfx::Point(100, 1500), gfx::Point(75, 1313)),
806 std::make_pair(gfx::Point(2460, 1500), gfx::Point(1845, 1313)),
807 }};
808 // The calibration was performed at the native display resolution.
809 display::TouchCalibrationData touch_data(user_input, kNativeDisplaySize);
810 internal_display_info.SetTouchCalibrationData(touch_data);
811 EXPECT_TRUE(internal_display_info.has_touch_calibration_data());
812
813 device_manager->UpdateTouchInfoForDisplay(
814 internal_display_info.id(), internal_touchscreen.id,
815 tt_controller->GetTouchTransform(internal_display_info,
816 internal_display_info,
817 internal_touchscreen, fb_size));
818
819 EXPECT_EQ(kDisplayId,
820 device_manager->GetTargetDisplayForTouchDevice(kTouchId));
821
822 float x, y;
823 // In pillarboxing, there is (1-1600*(1920/1400)/2560)/2 = 7.14% of the
824 // width on both the left & region region of the screen is blank.
825 // When touch events coming at X range [0, 1920), the mapping should be
826 // [0, ~137] ---> < 0
827 // [~137, ~1782] ---> [0, 1920)
828 // [~1782, 1920] ---> >= 1920
829 x = 137.0;
830 y = 0.0;
831 device_manager->ApplyTouchTransformer(kTouchId, &x, &y);
832 EXPECT_NEAR(0, x, 0.5);
833 EXPECT_NEAR(0, y, 0.5);
834
835 x = 1782.0;
836 y = 0.0;
837 device_manager->ApplyTouchTransformer(kTouchId, &x, &y);
838 EXPECT_NEAR(1920, x, 0.5);
839 EXPECT_NEAR(0, y, 0.5);
840 }
841
359 } // namespace ash 842 } // namespace ash
OLDNEW
« ash/touch/touch_transformer_controller.cc ('K') | « ash/touch/touch_transformer_controller.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698