Chromium Code Reviews| Index: ash/touch/touch_transformer_controller_unittest.cc |
| diff --git a/ash/touch/touch_transformer_controller_unittest.cc b/ash/touch/touch_transformer_controller_unittest.cc |
| index 09343bfce827859eebaae707461e9a516cf0e98e..09fe7010c4e43c77cf8b73c4779c909a0a3b9f80 100644 |
| --- a/ash/touch/touch_transformer_controller_unittest.cc |
| +++ b/ash/touch/touch_transformer_controller_unittest.cc |
| @@ -6,6 +6,8 @@ |
| #include "ash/shell.h" |
| #include "ash/test/ash_test_base.h" |
| +#include "base/rand_util.h" |
| +#include "base/strings/string_number_conversions.h" |
| #include "ui/aura/window_tree_host.h" |
| #include "ui/events/devices/device_data_manager.h" |
| @@ -35,9 +37,95 @@ ui::TouchscreenDevice CreateTouchscreenDevice(unsigned int id, |
| std::string(), size, 0); |
| } |
| +std::string GetTouchPointString( |
| + const display::TouchCalibrationData::CalibrationPointPairQuad& pts) { |
| + std::string str = "Failed for point pairs: "; |
| + for (std::size_t row = 0; row < pts.size(); row++) { |
| + str += "{(" + base::IntToString(pts[row].first.x()) + "," + |
| + base::IntToString(pts[row].first.y()) + "), (" + |
| + base::IntToString(pts[row].second.x()) + "," + |
| + base::IntToString(pts[row].second.y()) + ")} "; |
| + } |
| + return str; |
| +} |
| + |
| +// Returns a point close to |point| with some error. This is to simulate human |
| +// input that is prone to a max delta error of |error.width()| or |
| +// |error.height()|. |
| +gfx::Point GetPointWithError(const gfx::Point& point, const gfx::Size& error) { |
| + return gfx::Point( |
| + point.x() + base::RandInt(-error.width() / 2, error.width() / 2), |
| + point.y() + base::RandInt(-error.height() / 2, error.height() / 2)); |
| +} |
| + |
| +// Checks if the touch input has been calibrated properly. The input is said to |
| +// be calibrated if any touch input is transformed to the correct corresponding |
| +// display point within an error delta of |max_error_delta.width()| along the X |
| +// axis and |max_error_delta.height()| along the Y axis; |
| +void CheckPointsOfInterests(const int touch_id, |
| + const gfx::Size& touch_size, |
| + const gfx::Size& display_size, |
| + const gfx::Size& max_error_delta, |
| + const std::string error_msg) { |
|
sadrul
2016/12/22 02:25:43
const &
malaykeshav
2016/12/22 09:04:33
Done
|
| + ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance(); |
| + float x, y; |
| + |
| + // Origin of the touch device should correspond to origin of the display. |
| + x = y = 0.0; |
| + device_manager->ApplyTouchTransformer(touch_id, &x, &y); |
| + EXPECT_NEAR(0, x, max_error_delta.width()) << error_msg; |
| + EXPECT_NEAR(0, y, max_error_delta.height()) << error_msg; |
| + |
| + // Center of the touch device should correspond to the center of the display |
| + // device. |
| + x = touch_size.width() / 2; |
| + y = touch_size.height() / 2; |
| + device_manager->ApplyTouchTransformer(touch_id, &x, &y); |
| + EXPECT_NEAR(display_size.width() / 2, x, max_error_delta.width()) |
| + << error_msg; |
| + EXPECT_NEAR(display_size.height() / 2, y, max_error_delta.height()) |
| + << error_msg; |
| + |
| + // Bottom right corner of the touch device should correspond to rightmost |
| + // corner of display device. |
| + x = touch_size.width(); |
| + y = touch_size.height(); |
| + device_manager->ApplyTouchTransformer(touch_id, &x, &y); |
| + EXPECT_NEAR(display_size.width(), x, max_error_delta.width()) << error_msg; |
| + EXPECT_NEAR(display_size.height(), y, max_error_delta.height()) << error_msg; |
| +} |
| + |
| } // namespace |
| -typedef test::AshTestBase TouchTransformerControllerTest; |
| +class TouchTransformerControllerTest : public test::AshTestBase { |
| + public: |
| + TouchTransformerControllerTest() {} |
| + ~TouchTransformerControllerTest() override {} |
| + |
| + gfx::Transform GetTouchTransform( |
| + const display::ManagedDisplayInfo& display, |
| + const display::ManagedDisplayInfo& touch_display, |
| + const ui::TouchscreenDevice& touchscreen, |
| + const gfx::Size& framebuffer_size) const { |
| + return Shell::GetInstance() |
| + ->touch_transformer_controller() |
| + ->GetTouchTransform(display, touch_display, touchscreen, |
| + framebuffer_size); |
| + } |
| + |
| + double GetTouchResolutionScale( |
| + const display::ManagedDisplayInfo& touch_display, |
| + const ui::TouchscreenDevice& touch_device) const { |
| + return Shell::GetInstance() |
| + ->touch_transformer_controller() |
| + ->GetTouchResolutionScale(touch_display, touch_device); |
| + } |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(TouchTransformerControllerTest); |
| +}; |
| + |
| +// typedef test::AshTestBase TouchTransformerControllerTest; |
|
sadrul
2016/12/22 02:25:43
Remove.
malaykeshav
2016/12/22 09:04:33
Done
|
| TEST_F(TouchTransformerControllerTest, MirrorModeLetterboxing) { |
| // The internal display has native resolution of 2560x1700, and in |
| @@ -67,21 +155,17 @@ TEST_F(TouchTransformerControllerTest, MirrorModeLetterboxing) { |
| ui::TouchscreenDevice external_touchscreen = |
| CreateTouchscreenDevice(11, fb_size); |
| - TouchTransformerController* tt_controller = |
| - Shell::GetInstance()->touch_transformer_controller(); |
| ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance(); |
| device_manager->UpdateTouchInfoForDisplay( |
| internal_display_info.id(), internal_touchscreen.id, |
| - tt_controller->GetTouchTransform(internal_display_info, |
| - internal_display_info, |
| - internal_touchscreen, fb_size)); |
| + GetTouchTransform(internal_display_info, internal_display_info, |
| + internal_touchscreen, fb_size)); |
| device_manager->UpdateTouchInfoForDisplay( |
| internal_display_info.id(), external_touchscreen.id, |
| - tt_controller->GetTouchTransform(external_display_info, |
| - external_display_info, |
| - external_touchscreen, fb_size)); |
| + GetTouchTransform(external_display_info, external_display_info, |
| + external_touchscreen, fb_size)); |
| EXPECT_EQ(1, device_manager->GetTargetDisplayForTouchDevice(10)); |
| EXPECT_EQ(1, device_manager->GetTargetDisplayForTouchDevice(11)); |
| @@ -138,21 +222,17 @@ TEST_F(TouchTransformerControllerTest, MirrorModePillarboxing) { |
| ui::TouchscreenDevice external_touchscreen = |
| CreateTouchscreenDevice(11, fb_size); |
| - TouchTransformerController* tt_controller = |
| - Shell::GetInstance()->touch_transformer_controller(); |
| ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance(); |
| device_manager->UpdateTouchInfoForDisplay( |
| internal_display_info.id(), internal_touchscreen.id, |
| - tt_controller->GetTouchTransform(internal_display_info, |
| - internal_display_info, |
| - internal_touchscreen, fb_size)); |
| + GetTouchTransform(internal_display_info, internal_display_info, |
| + internal_touchscreen, fb_size)); |
| device_manager->UpdateTouchInfoForDisplay( |
| internal_display_info.id(), external_touchscreen.id, |
| - tt_controller->GetTouchTransform(external_display_info, |
| - external_display_info, |
| - external_touchscreen, fb_size)); |
| + GetTouchTransform(external_display_info, external_display_info, |
| + external_touchscreen, fb_size)); |
| EXPECT_EQ(1, device_manager->GetTargetDisplayForTouchDevice(10)); |
| EXPECT_EQ(1, device_manager->GetTargetDisplayForTouchDevice(11)); |
| @@ -214,19 +294,17 @@ TEST_F(TouchTransformerControllerTest, SoftwareMirrorMode) { |
| ui::TouchscreenDevice display2_touchscreen = |
| CreateTouchscreenDevice(11, fb_size); |
| - TouchTransformerController* tt_controller = |
| - Shell::GetInstance()->touch_transformer_controller(); |
| ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance(); |
| device_manager->UpdateTouchInfoForDisplay( |
| display1_info.id(), display1_touchscreen.id, |
| - tt_controller->GetTouchTransform(display1_info, display1_info, |
| - display1_touchscreen, fb_size)); |
| + GetTouchTransform(display1_info, display1_info, display1_touchscreen, |
| + fb_size)); |
| device_manager->UpdateTouchInfoForDisplay( |
| display1_info.id(), display2_touchscreen.id, |
| - tt_controller->GetTouchTransform(display1_info, display2_info, |
| - display2_touchscreen, fb_size)); |
| + GetTouchTransform(display1_info, display2_info, display2_touchscreen, |
| + fb_size)); |
| EXPECT_EQ(1, device_manager->GetTargetDisplayForTouchDevice(10)); |
| EXPECT_EQ(1, device_manager->GetTargetDisplayForTouchDevice(11)); |
| @@ -285,19 +363,15 @@ TEST_F(TouchTransformerControllerTest, ExtendedMode) { |
| ui::TouchscreenDevice touchscreen1 = CreateTouchscreenDevice(5, fb_size); |
| ui::TouchscreenDevice touchscreen2 = CreateTouchscreenDevice(6, fb_size); |
| - TouchTransformerController* tt_controller = |
| - Shell::GetInstance()->touch_transformer_controller(); |
| ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance(); |
| device_manager->UpdateTouchInfoForDisplay( |
| display1.id(), touchscreen1.id, |
| - tt_controller->GetTouchTransform(display1, display1, touchscreen1, |
| - fb_size)); |
| + GetTouchTransform(display1, display1, touchscreen1, fb_size)); |
| device_manager->UpdateTouchInfoForDisplay( |
| display2.id(), touchscreen2.id, |
| - tt_controller->GetTouchTransform(display2, display2, touchscreen2, |
| - fb_size)); |
| + GetTouchTransform(display2, display2, touchscreen2, fb_size)); |
| EXPECT_EQ(1, device_manager->GetTargetDisplayForTouchDevice(5)); |
| EXPECT_EQ(2, device_manager->GetTargetDisplayForTouchDevice(6)); |
| @@ -349,11 +423,437 @@ TEST_F(TouchTransformerControllerTest, TouchRadiusScale) { |
| ui::TouchscreenDevice touch_device = |
| CreateTouchscreenDevice(5, gfx::Size(1001, 1001)); |
| - TouchTransformerController* tt_controller = |
| - Shell::GetInstance()->touch_transformer_controller(); |
| // Default touchscreen position range is 1001x1001; |
| EXPECT_EQ(sqrt((2560.0 * 1600.0) / (1001.0 * 1001.0)), |
| - tt_controller->GetTouchResolutionScale(display, touch_device)); |
| + GetTouchResolutionScale(display, touch_device)); |
| +} |
| + |
| +TEST_F(TouchTransformerControllerTest, OzoneTranslation) { |
| +#if defined(USE_OZONE) |
| + // The internal display has size 1920 x 1200. The external display has |
| + // size 1920x1200. The total frame buffer is 1920x2450, |
| + // where 2458 = 1200 + 50 (hidden gap) + 1200 |
| + // and the second monitor is translated to Point (0, 1250) in the |
| + // framebuffer. |
| + const gfx::Size kDisplaySize(1920, 1200); |
| + const gfx::Size kTouchSize(1920, 1200); |
| + const int kHiddenGap = 50; |
| + const int kDisplayId1 = 1; |
| + const int kDisplayId2 = 2; |
| + const int kTouchId1 = 5; |
| + const int kTouchId2 = 6; |
| + |
| + display::ManagedDisplayInfo display1 = CreateDisplayInfo( |
| + kDisplayId1, kTouchId1, |
| + gfx::Rect(0, 0, kDisplaySize.width(), kDisplaySize.height())); |
| + display::ManagedDisplayInfo display2 = |
| + CreateDisplayInfo(kDisplayId2, kTouchId2, |
| + gfx::Rect(0, kDisplaySize.height() + kHiddenGap, |
| + kDisplaySize.width(), kDisplaySize.height())); |
| + |
| + gfx::Size fb_size(1920, 2450); |
| + |
| + ui::TouchscreenDevice touchscreen1 = |
| + CreateTouchscreenDevice(kTouchId1, kDisplaySize); |
| + ui::TouchscreenDevice touchscreen2 = |
| + CreateTouchscreenDevice(kTouchId2, kDisplaySize); |
| + |
| + ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance(); |
| + |
| + // Mirror displays. Touch screen 2 is associated to display 1. |
| + device_manager->UpdateTouchInfoForDisplay( |
| + display1.id(), touchscreen1.id, |
| + GetTouchTransform(display1, display1, touchscreen1, kTouchSize)); |
| + |
| + device_manager->UpdateTouchInfoForDisplay( |
| + display1.id(), touchscreen2.id, |
| + GetTouchTransform(display1, display2, touchscreen2, kTouchSize)); |
| + |
| + EXPECT_EQ(kDisplayId1, |
| + device_manager->GetTargetDisplayForTouchDevice(kTouchId1)); |
| + EXPECT_EQ(kDisplayId1, |
| + device_manager->GetTargetDisplayForTouchDevice(kTouchId2)); |
| + |
| + float x, y; |
| + |
| + x = y = 0.0; |
| + device_manager->ApplyTouchTransformer(kTouchId1, &x, &y); |
| + EXPECT_NEAR(0, x, 0.5); |
| + EXPECT_NEAR(0, y, 0.5); |
| + |
| + x = y = 0.0; |
| + device_manager->ApplyTouchTransformer(kTouchId2, &x, &y); |
| + EXPECT_NEAR(0, x, 0.5); |
| + EXPECT_NEAR(0, y, 0.5); |
| + |
| + x = 1920.0; |
| + y = 1200.0; |
| + device_manager->ApplyTouchTransformer(kTouchId1, &x, &y); |
| + EXPECT_NEAR(1920, x, 0.5); |
| + EXPECT_NEAR(1200, y, 0.5); |
| + |
| + x = 1920.0; |
| + y = 1200.0; |
| + device_manager->ApplyTouchTransformer(kTouchId2, &x, &y); |
| + EXPECT_NEAR(1920, x, 0.5); |
| + EXPECT_NEAR(1200, y, 0.5); |
| + |
| + // Remove mirroring of displays. |
| + device_manager->UpdateTouchInfoForDisplay( |
| + display2.id(), touchscreen2.id, |
| + GetTouchTransform(display2, display2, touchscreen2, kTouchSize)); |
| + |
| + x = 1920.0; |
| + y = 1200.0; |
| + device_manager->ApplyTouchTransformer(kTouchId1, &x, &y); |
| + EXPECT_NEAR(1920, x, 0.5); |
| + EXPECT_NEAR(1200, y, 0.5); |
| + |
| + x = 1920.0; |
| + y = 1200.0; |
| + device_manager->ApplyTouchTransformer(kTouchId2, &x, &y); |
| + EXPECT_NEAR(1920, x, 0.5); |
| + EXPECT_NEAR(1200 + kDisplaySize.height() + kHiddenGap, y, 0.5); |
| +#endif |
|
sadrul
2016/12/22 02:25:43
#endif // defined(USE_OZONE)
malaykeshav
2016/12/22 09:04:33
Done
|
| +} |
| + |
| +TEST_F(TouchTransformerControllerTest, AccurateUserTouchCalibration) { |
| + const gfx::Size kDisplaySize(1920, 1200); |
| + const gfx::Size kTouchSize(1920, 1200); |
| + const int kDisplayId = 1; |
| + const int kTouchId = 5; |
| + |
| + display::ManagedDisplayInfo display = CreateDisplayInfo( |
| + kDisplayId, kTouchId, |
| + gfx::Rect(0, 0, kDisplaySize.width(), kDisplaySize.height())); |
| + |
| + // Assuming the user provided accurate inputs during calibration. ie the user |
| + // actually tapped (100,100) when asked to tap (100,100) with no human error. |
| + display::TouchCalibrationData::CalibrationPointPairQuad user_input = {{ |
| + std::make_pair(gfx::Point(100, 100), gfx::Point(100, 100)), |
| + std::make_pair(gfx::Point(1820, 100), gfx::Point(1820, 100)), |
| + std::make_pair(gfx::Point(100, 1100), gfx::Point(100, 1100)), |
| + std::make_pair(gfx::Point(1820, 1100), gfx::Point(1820, 1100)), |
| + }}; |
| + display::TouchCalibrationData touch_data(user_input, kDisplaySize); |
| + display.SetTouchCalibrationData(touch_data); |
| + EXPECT_TRUE(display.has_touch_calibration_data()); |
| + |
| + const std::string msg = GetTouchPointString(user_input); |
| + |
| + gfx::Size fb_size(1920, 1200); |
| + |
| + ui::TouchscreenDevice touchscreen = |
| + CreateTouchscreenDevice(kTouchId, kTouchSize); |
| + |
| + ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance(); |
| + |
| + device_manager->UpdateTouchInfoForDisplay( |
| + display.id(), touchscreen.id, |
| + GetTouchTransform(display, display, touchscreen, kTouchSize)); |
| + |
| + EXPECT_EQ(kDisplayId, |
| + device_manager->GetTargetDisplayForTouchDevice(kTouchId)); |
| + |
| + CheckPointsOfInterests(kTouchId, kTouchSize, kDisplaySize, gfx::Size(1, 1), |
| + msg); |
| +} |
| + |
| +TEST_F(TouchTransformerControllerTest, ErrorProneUserTouchCalibration) { |
| + const gfx::Size kDisplaySize(1920, 1200); |
| + const gfx::Size kTouchSize(1920, 1200); |
| + const int kDisplayId = 1; |
| + const int kTouchId = 5; |
| + // User touch inputs have a max error of 5%. |
| + const float kError = 0.05; |
| + // The maximum user error rate is |kError|%. Since the calibration is |
| + // performed with a best fit algorithm, the error rate observed should be less |
| + // than |kError|. |
| + const gfx::Size kMaxErrorDelta = gfx::ScaleToCeiledSize(kTouchSize, kError); |
| + |
| + display::ManagedDisplayInfo display = CreateDisplayInfo( |
| + kDisplayId, kTouchId, |
| + gfx::Rect(0, 0, kDisplaySize.width(), kDisplaySize.height())); |
| + |
| + // Assuming the user provided inaccurate inputs during calibration. ie the |
| + // user did not tap (100,100) when asked to tap (100,100) due no human error. |
| + display::TouchCalibrationData::CalibrationPointPairQuad user_input = { |
| + {std::make_pair(gfx::Point(100, 100), |
| + GetPointWithError(gfx::Point(100, 100), kMaxErrorDelta)), |
| + std::make_pair(gfx::Point(1820, 100), |
| + GetPointWithError(gfx::Point(1820, 100), kMaxErrorDelta)), |
| + std::make_pair(gfx::Point(100, 1100), |
| + GetPointWithError(gfx::Point(100, 1100), kMaxErrorDelta)), |
| + std::make_pair( |
| + gfx::Point(1820, 1100), |
| + GetPointWithError(gfx::Point(1820, 1100), kMaxErrorDelta))}}; |
| + display::TouchCalibrationData touch_data(user_input, kDisplaySize); |
| + display.SetTouchCalibrationData(touch_data); |
| + EXPECT_TRUE(display.has_touch_calibration_data()); |
| + |
| + const std::string msg = GetTouchPointString(user_input); |
| + |
| + ui::TouchscreenDevice touchscreen = |
| + CreateTouchscreenDevice(kTouchId, kTouchSize); |
| + |
| + ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance(); |
| + |
| + device_manager->UpdateTouchInfoForDisplay( |
| + display.id(), touchscreen.id, |
| + GetTouchTransform(display, display, touchscreen, kTouchSize)); |
| + |
| + EXPECT_EQ(kDisplayId, |
| + device_manager->GetTargetDisplayForTouchDevice(kTouchId)); |
| + |
| + CheckPointsOfInterests(kTouchId, kTouchSize, kDisplaySize, kMaxErrorDelta, |
| + msg); |
| +} |
| + |
| +TEST_F(TouchTransformerControllerTest, ResolutionChangeUserTouchCalibration) { |
| + const gfx::Size kDisplaySize(2560, 1600); |
| + const gfx::Size kTouchSize(1920, 1200); |
| + const int kDisplayId = 1; |
| + const int kTouchId = 5; |
| + // User touch inputs have a max error of 5%. |
| + const float kError = 0.05; |
| + // The maximum user error rate is |kError|%. Since the calibration is |
| + // performed with a best fit algorithm, the error rate observed should be less |
| + // tha |kError|. |
| + gfx::Size kMaxErrorDelta = gfx::ScaleToCeiledSize(kDisplaySize, kError); |
| + |
| + display::ManagedDisplayInfo display = CreateDisplayInfo( |
| + kDisplayId, kTouchId, |
| + gfx::Rect(0, 0, kDisplaySize.width(), kDisplaySize.height())); |
| + |
| + // The calibration was performed at a resolution different from the curent |
| + // resolution of the display. |
| + const gfx::Size CALIBRATION_SIZE(1920, 1200); |
| + display::TouchCalibrationData::CalibrationPointPairQuad user_input = { |
| + {std::make_pair(gfx::Point(100, 100), |
| + GetPointWithError(gfx::Point(100, 100), kMaxErrorDelta)), |
| + std::make_pair(gfx::Point(1820, 100), |
| + GetPointWithError(gfx::Point(1820, 100), kMaxErrorDelta)), |
| + std::make_pair(gfx::Point(100, 1100), |
| + GetPointWithError(gfx::Point(100, 1100), kMaxErrorDelta)), |
| + std::make_pair( |
| + gfx::Point(1820, 1100), |
| + GetPointWithError(gfx::Point(1820, 1100), kMaxErrorDelta))}}; |
| + display::TouchCalibrationData touch_data(user_input, CALIBRATION_SIZE); |
| + display.SetTouchCalibrationData(touch_data); |
| + EXPECT_TRUE(display.has_touch_calibration_data()); |
| + |
| + const std::string msg = GetTouchPointString(user_input); |
| + |
| + ui::TouchscreenDevice touchscreen = |
| + CreateTouchscreenDevice(kTouchId, kTouchSize); |
| + |
| + ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance(); |
| + |
| + device_manager->UpdateTouchInfoForDisplay( |
| + display.id(), touchscreen.id, |
| + GetTouchTransform(display, display, touchscreen, kTouchSize)); |
| + |
| + EXPECT_EQ(kDisplayId, |
| + device_manager->GetTargetDisplayForTouchDevice(kTouchId)); |
| + |
| + CheckPointsOfInterests(kTouchId, kTouchSize, kDisplaySize, kMaxErrorDelta, |
| + msg); |
| +} |
| + |
| +TEST_F(TouchTransformerControllerTest, DifferentBoundsUserTouchCalibration) { |
| + // The display bounds is different from the touch device bounds in this test. |
| + const gfx::Size kDisplaySize(1024, 600); |
| + const gfx::Size kTouchSize(4096, 4096); |
| + const int kDisplayId = 1; |
| + const int kTouchId = 5; |
| + const float kAcceptableError = 0.04; |
| + gfx::Size kMaxErrorDelta = |
| + gfx::ScaleToCeiledSize(kDisplaySize, kAcceptableError); |
| + |
| + display::ManagedDisplayInfo display = CreateDisplayInfo( |
| + kDisplayId, kTouchId, |
| + gfx::Rect(0, 0, kDisplaySize.width(), kDisplaySize.height())); |
| + |
| + // Real world data. |
| + display::TouchCalibrationData::CalibrationPointPairQuad user_input = { |
| + {std::make_pair(gfx::Point(136, 136), gfx::Point(538, 931)), |
| + std::make_pair(gfx::Point(873, 136), gfx::Point(3475, 922)), |
| + std::make_pair(gfx::Point(136, 411), gfx::Point(611, 2800)), |
| + std::make_pair(gfx::Point(873, 411), gfx::Point(3535, 2949))}}; |
| + display::TouchCalibrationData touch_data(user_input, kDisplaySize); |
| + display.SetTouchCalibrationData(touch_data); |
| + EXPECT_TRUE(display.has_touch_calibration_data()); |
| + |
| + const std::string msg = GetTouchPointString(user_input); |
| + |
| + ui::TouchscreenDevice touchscreen = |
| + CreateTouchscreenDevice(kTouchId, kTouchSize); |
| + |
| + ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance(); |
| + |
| + device_manager->UpdateTouchInfoForDisplay( |
| + display.id(), touchscreen.id, |
| + GetTouchTransform(display, display, touchscreen, kTouchSize)); |
| + |
| + EXPECT_EQ(kDisplayId, |
| + device_manager->GetTargetDisplayForTouchDevice(kTouchId)); |
| + |
| + CheckPointsOfInterests(kTouchId, kTouchSize, kDisplaySize, kMaxErrorDelta, |
| + msg); |
| +} |
| + |
| +TEST_F(TouchTransformerControllerTest, LetterboxingUserTouchCalibration) { |
| + // The internal display has native resolution of 2560x1700, and in |
| + // mirror mode it is configured as 1920x1200. This is in letterboxing |
| + // mode. |
| + const gfx::Size kNativeDisplaySize(2560, 1700); |
| + const gfx::Size kDisplaySize(1920, 1200); |
| + const gfx::Size kTouchSize(1920, 1200); |
| + const int kDisplayId = 1; |
| + const int kTouchId = 5; |
| + |
| + display::ManagedDisplayInfo internal_display_info = CreateDisplayInfo( |
| + kDisplayId, kTouchId, |
| + gfx::Rect(0, 0, kDisplaySize.width(), kDisplaySize.height())); |
| + internal_display_info.set_is_aspect_preserving_scaling(true); |
| + |
| + display::ManagedDisplayInfo::ManagedDisplayModeList internal_modes; |
| + |
| + internal_modes.push_back(make_scoped_refptr(new display::ManagedDisplayMode( |
| + gfx::Size(kNativeDisplaySize.width(), kNativeDisplaySize.height()), 60, |
| + false, true))); |
| + internal_modes.push_back(make_scoped_refptr(new display::ManagedDisplayMode( |
| + gfx::Size(kDisplaySize.width(), kDisplaySize.height()), 60, false, |
| + false))); |
| + internal_display_info.SetManagedDisplayModes(internal_modes); |
| + |
| + gfx::Size fb_size(kDisplaySize); |
| + |
| + // Create the touchscreens with the same size as the framebuffer so we can |
| + // share the tests between Ozone & X11. |
| + ui::TouchscreenDevice internal_touchscreen = |
| + CreateTouchscreenDevice(kTouchId, fb_size); |
| + |
| + ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance(); |
| + |
| + // Assuming the user provided inaccurate inputs during calibration. ie the |
| + // user did not tap (100,100) when asked to tap (100,100) due to human error. |
| + // Since the display is of size 2560x1700 and the touch device is of size |
| + // 1920x1200, the corresponding points have to be scaled. |
| + display::TouchCalibrationData::CalibrationPointPairQuad user_input = {{ |
| + std::make_pair(gfx::Point(100, 100), gfx::Point(75, 71)), |
| + std::make_pair(gfx::Point(2460, 100), gfx::Point(1845, 71)), |
| + std::make_pair(gfx::Point(100, 1600), gfx::Point(75, 1130)), |
| + std::make_pair(gfx::Point(2460, 1600), gfx::Point(1845, 1130)), |
| + }}; |
| + // The calibration was performed at the native display resolution. |
| + display::TouchCalibrationData touch_data(user_input, kNativeDisplaySize); |
| + internal_display_info.SetTouchCalibrationData(touch_data); |
| + EXPECT_TRUE(internal_display_info.has_touch_calibration_data()); |
| + |
| + device_manager->UpdateTouchInfoForDisplay( |
| + internal_display_info.id(), internal_touchscreen.id, |
| + GetTouchTransform(internal_display_info, internal_display_info, |
| + internal_touchscreen, fb_size)); |
| + |
| + EXPECT_EQ(kDisplayId, |
| + device_manager->GetTargetDisplayForTouchDevice(kTouchId)); |
| + |
| + float x, y; |
| + // In letterboxing, there is (1-2560*(1200/1920)/1700)/2 = 2.95% of the |
| + // height on both the top & bottom region of the screen is blank. |
| + // When touch events coming at Y range [0, 1200), the mapping should be |
| + // [0, ~35] ---> < 0 |
| + // [~35, ~1165] ---> [0, 1200) |
| + // [~1165, 1200] ---> >= 1200 |
| + x = 100.0; |
| + y = 35.0; |
| + device_manager->ApplyTouchTransformer(kTouchId, &x, &y); |
| + EXPECT_NEAR(100, x, 0.5); |
| + EXPECT_NEAR(0, y, 0.5); |
| + |
| + x = 100.0; |
| + y = 1165.0; |
| + device_manager->ApplyTouchTransformer(kTouchId, &x, &y); |
| + EXPECT_NEAR(100, x, 0.5); |
| + EXPECT_NEAR(1200, y, 0.5); |
| +} |
| + |
| +TEST_F(TouchTransformerControllerTest, PillarBoxingUserTouchCalibration) { |
| + // The internal display has native resolution of 2560x1700, and in |
| + // mirror mode it is configured as 1920x1200. This is in letterboxing |
| + // mode. |
| + const gfx::Size kNativeDisplaySize(2560, 1600); |
| + const gfx::Size kDisplaySize(1920, 1400); |
| + const gfx::Size kTouchSize(1920, 1400); |
| + const int kDisplayId = 1; |
| + const int kTouchId = 5; |
| + |
| + display::ManagedDisplayInfo internal_display_info = CreateDisplayInfo( |
| + kDisplayId, kTouchId, |
| + gfx::Rect(0, 0, kDisplaySize.width(), kDisplaySize.height())); |
| + internal_display_info.set_is_aspect_preserving_scaling(true); |
| + |
| + display::ManagedDisplayInfo::ManagedDisplayModeList internal_modes; |
| + |
| + internal_modes.push_back(make_scoped_refptr(new display::ManagedDisplayMode( |
| + gfx::Size(kNativeDisplaySize.width(), kNativeDisplaySize.height()), 60, |
| + false, true))); |
| + internal_modes.push_back(make_scoped_refptr(new display::ManagedDisplayMode( |
| + gfx::Size(kDisplaySize.width(), kDisplaySize.height()), 60, false, |
| + false))); |
| + internal_display_info.SetManagedDisplayModes(internal_modes); |
| + |
| + gfx::Size fb_size(kDisplaySize); |
| + |
| + // Create the touchscreens with the same size as the framebuffer so we can |
| + // share the tests between Ozone & X11. |
| + ui::TouchscreenDevice internal_touchscreen = |
| + CreateTouchscreenDevice(kTouchId, fb_size); |
| + |
| + ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance(); |
| + |
| + // Assuming the user provided accurate inputs during calibration. ie the user |
| + // actually tapped (100,100) when asked to tap (100,100) with no human error. |
| + // Since the display is of size 2560x1600 and the touch device is of size |
| + // 1920x1400, the corresponding points have to be scaled. |
| + display::TouchCalibrationData::CalibrationPointPairQuad user_input = {{ |
| + std::make_pair(gfx::Point(100, 100), gfx::Point(75, 88)), |
| + std::make_pair(gfx::Point(2460, 100), gfx::Point(1845, 88)), |
| + std::make_pair(gfx::Point(100, 1500), gfx::Point(75, 1313)), |
| + std::make_pair(gfx::Point(2460, 1500), gfx::Point(1845, 1313)), |
| + }}; |
| + // The calibration was performed at the native display resolution. |
| + display::TouchCalibrationData touch_data(user_input, kNativeDisplaySize); |
| + internal_display_info.SetTouchCalibrationData(touch_data); |
| + EXPECT_TRUE(internal_display_info.has_touch_calibration_data()); |
| + |
| + device_manager->UpdateTouchInfoForDisplay( |
| + internal_display_info.id(), internal_touchscreen.id, |
| + GetTouchTransform(internal_display_info, internal_display_info, |
| + internal_touchscreen, fb_size)); |
| + |
| + EXPECT_EQ(kDisplayId, |
| + device_manager->GetTargetDisplayForTouchDevice(kTouchId)); |
| + |
| + float x, y; |
| + // In pillarboxing, there is (1-1600*(1920/1400)/2560)/2 = 7.14% of the |
| + // width on both the left & region region of the screen is blank. |
| + // When touch events coming at X range [0, 1920), the mapping should be |
| + // [0, ~137] ---> < 0 |
| + // [~137, ~1782] ---> [0, 1920) |
| + // [~1782, 1920] ---> >= 1920 |
| + x = 137.0; |
| + y = 0.0; |
| + device_manager->ApplyTouchTransformer(kTouchId, &x, &y); |
| + EXPECT_NEAR(0, x, 0.5); |
| + EXPECT_NEAR(0, y, 0.5); |
| + |
| + x = 1782.0; |
| + y = 0.0; |
| + device_manager->ApplyTouchTransformer(kTouchId, &x, &y); |
| + EXPECT_NEAR(1920, x, 0.5); |
| + EXPECT_NEAR(0, y, 0.5); |
| } |
| } // namespace ash |