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..985302fa3d6294d32b606ec6b07241edfbc4c449 100644 |
| --- a/ash/touch/touch_transformer_controller_unittest.cc |
| +++ b/ash/touch/touch_transformer_controller_unittest.cc |
| @@ -6,8 +6,10 @@ |
| #include "ash/shell.h" |
| #include "ash/test/ash_test_base.h" |
| +#include "base/rand_util.h" |
| #include "ui/aura/window_tree_host.h" |
| #include "ui/events/devices/device_data_manager.h" |
| +// #include "ui/gfx/geometry/point.h" |
|
malaykeshav
2016/12/19 19:12:01
Remove
malaykeshav
2016/12/20 09:56:05
Done
|
| namespace ash { |
| @@ -35,6 +37,49 @@ ui::TouchscreenDevice CreateTouchscreenDevice(unsigned int id, |
| std::string(), size, 0); |
| } |
| +// 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) { |
|
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
|
| + return gfx::Point( |
| + 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
|
| + 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, |
|
kylechar
2016/12/19 20:00:22
Don't pass int by const ref.
malaykeshav
2016/12/20 09:56:05
done
|
| + const gfx::Size& touch_size, |
| + const gfx::Size& display_size, |
| + const gfx::Size& max_error_delta) { |
| + 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()); |
| + EXPECT_NEAR(0, y, max_error_delta.height()); |
| + |
| + // 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()); |
| + EXPECT_NEAR(display_size.height() / 2, y, max_error_delta.height()); |
| + |
| + // 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()); |
| + EXPECT_NEAR(display_size.height(), y, max_error_delta.height()); |
| +} |
| + |
| } // namespace |
| typedef test::AshTestBase TouchTransformerControllerTest; |
| @@ -356,4 +401,431 @@ TEST_F(TouchTransformerControllerTest, TouchRadiusScale) { |
| tt_controller->GetTouchResolutionScale(display, touch_device)); |
| } |
| +TEST_F(TouchTransformerControllerTest, OzoneTrasnlation) { |
|
kylechar
2016/12/19 20:00:22
OzoneTranslation?
malaykeshav
2016/12/20 09:56:05
done
|
| +#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 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
|
| + const int HIDDEN_GAP = 50; |
| + 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
|
| + |
| + display::ManagedDisplayInfo display1 = CreateDisplayInfo( |
|
kylechar
2016/12/19 20:00:21
optional: auto display1 = ...;
malaykeshav
2016/12/20 09:56:05
Ack
|
| + DISPLAY_ID_1, TOUCH_ID_1, |
| + gfx::Rect(0, 0, DISPLAY_SIZE.width(), DISPLAY_SIZE.height())); |
| + display::ManagedDisplayInfo display2 = |
| + CreateDisplayInfo(DISPLAY_ID_2, TOUCH_ID_2, |
| + gfx::Rect(0, DISPLAY_SIZE.height() + HIDDEN_GAP, |
| + DISPLAY_SIZE.width(), DISPLAY_SIZE.height())); |
| + |
| + gfx::Size fb_size(1920, 2450); |
| + |
| + ui::TouchscreenDevice touchscreen1 = |
| + CreateTouchscreenDevice(TOUCH_ID_1, DISPLAY_SIZE); |
| + ui::TouchscreenDevice touchscreen2 = |
| + CreateTouchscreenDevice(TOUCH_ID_2, DISPLAY_SIZE); |
| + |
| + TouchTransformerController* tt_controller = |
| + Shell::GetInstance()->touch_transformer_controller(); |
| + ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance(); |
| + |
| + // Mirror displays. Touch screen 2 is associated to display 1. |
| + device_manager->UpdateTouchInfoForDisplay( |
| + display1.id(), touchscreen1.id, |
| + tt_controller->GetTouchTransform(display1, display1, touchscreen1, |
| + TOUCH_SIZE)); |
| + |
| + device_manager->UpdateTouchInfoForDisplay( |
| + display1.id(), touchscreen2.id, |
| + tt_controller->GetTouchTransform(display1, display2, touchscreen2, |
| + TOUCH_SIZE)); |
| + |
| + EXPECT_EQ(DISPLAY_ID_1, |
| + device_manager->GetTargetDisplayForTouchDevice(TOUCH_ID_1)); |
| + EXPECT_EQ(DISPLAY_ID_1, |
| + device_manager->GetTargetDisplayForTouchDevice(TOUCH_ID_2)); |
| + |
| + float x, y; |
| + |
| + x = y = 0.0; |
| + device_manager->ApplyTouchTransformer(TOUCH_ID_1, &x, &y); |
| + EXPECT_NEAR(0, x, 0.5); |
| + EXPECT_NEAR(0, y, 0.5); |
| + |
| + x = y = 0.0; |
| + device_manager->ApplyTouchTransformer(TOUCH_ID_2, &x, &y); |
| + EXPECT_NEAR(0, x, 0.5); |
| + EXPECT_NEAR(0, y, 0.5); |
| + |
| + x = 1920.0; |
| + y = 1200.0; |
| + device_manager->ApplyTouchTransformer(TOUCH_ID_1, &x, &y); |
| + EXPECT_NEAR(1920, x, 0.5); |
| + EXPECT_NEAR(1200, y, 0.5); |
| + |
| + x = 1920.0; |
| + y = 1200.0; |
| + device_manager->ApplyTouchTransformer(TOUCH_ID_2, &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, |
| + tt_controller->GetTouchTransform(display2, display2, touchscreen2, |
| + TOUCH_SIZE)); |
| + |
| + x = 1920.0; |
| + y = 1200.0; |
| + device_manager->ApplyTouchTransformer(TOUCH_ID_1, &x, &y); |
| + EXPECT_NEAR(1920, x, 0.5); |
| + EXPECT_NEAR(1200, y, 0.5); |
| + |
| + x = 1920.0; |
| + y = 1200.0; |
| + device_manager->ApplyTouchTransformer(TOUCH_ID_2, &x, &y); |
| + EXPECT_NEAR(1920, x, 0.5); |
| + EXPECT_NEAR(1200 + DISPLAY_SIZE.height() + HIDDEN_GAP, y, 0.5); |
| +#endif |
| +} |
| + |
| +TEST_F(TouchTransformerControllerTest, AccurateUserTouchCalibration) { |
| + const gfx::Size DISPLAY_SIZE(1920, 1200), TOUCH_SIZE(1920, 1200); |
| + const int DISPLAY_ID = 1, TOUCH_ID = 5; |
| + |
| + display::ManagedDisplayInfo display = CreateDisplayInfo( |
| + DISPLAY_ID, TOUCH_ID, |
| + gfx::Rect(0, 0, DISPLAY_SIZE.width(), DISPLAY_SIZE.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, DISPLAY_SIZE); |
| + display.SetTouchCalibrationData(touch_data); |
| + EXPECT_TRUE(display.has_touch_calibration_data()); |
| + |
| + gfx::Size fb_size(1920, 1200); |
| + |
| + ui::TouchscreenDevice touchscreen = |
| + CreateTouchscreenDevice(TOUCH_ID, TOUCH_SIZE); |
| + |
| + TouchTransformerController* tt_controller = |
| + Shell::GetInstance()->touch_transformer_controller(); |
| + ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance(); |
| + |
| + device_manager->UpdateTouchInfoForDisplay( |
| + display.id(), touchscreen.id, |
| + tt_controller->GetTouchTransform(display, display, touchscreen, |
| + TOUCH_SIZE)); |
| + |
| + EXPECT_EQ(DISPLAY_ID, |
| + device_manager->GetTargetDisplayForTouchDevice(TOUCH_ID)); |
| + |
| + CheckPointsOfInterests(TOUCH_ID, TOUCH_SIZE, DISPLAY_SIZE, gfx::Size(1, 1)); |
| +} |
| + |
| +TEST_F(TouchTransformerControllerTest, ErrorProneUserTouchCalibration) { |
| + const gfx::Size DISPLAY_SIZE(1920, 1200), TOUCH_SIZE(1920, 1200); |
| + const int DISPLAY_ID = 1, TOUCH_ID = 5; |
| + // User touch inputs have a max error of 5%. |
| + const float ERROR = 0.05; |
| + // The maximum user error rate is |ERROR|%. Since the calibration is performed |
| + // with a best fit algorithm, the error rate observed should be less than |
| + // |ERROR|. |
| + const gfx::Size MAX_ERROR_DELTA = gfx::ScaleToCeiledSize(TOUCH_SIZE, ERROR); |
| + |
| + display::ManagedDisplayInfo display = CreateDisplayInfo( |
| + DISPLAY_ID, TOUCH_ID, |
| + gfx::Rect(0, 0, DISPLAY_SIZE.width(), DISPLAY_SIZE.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. |
|
malaykeshav
2016/12/19 19:12:01
Update comment.
This is not accurate user input. I
malaykeshav
2016/12/20 09:56:05
Done.
|
| + display::TouchCalibrationData::CalibrationPointPairQuad user_input = { |
| + {std::make_pair(gfx::Point(100, 100), |
| + GetPointWithError(gfx::Point(100, 100), MAX_ERROR_DELTA)), |
| + std::make_pair( |
| + gfx::Point(1820, 100), |
| + GetPointWithError(gfx::Point(1820, 100), MAX_ERROR_DELTA)), |
| + std::make_pair( |
| + gfx::Point(100, 1100), |
| + GetPointWithError(gfx::Point(100, 1100), MAX_ERROR_DELTA)), |
| + std::make_pair( |
| + gfx::Point(1820, 1100), |
| + GetPointWithError(gfx::Point(1820, 1100), MAX_ERROR_DELTA))}}; |
| + display::TouchCalibrationData touch_data(user_input, DISPLAY_SIZE); |
| + display.SetTouchCalibrationData(touch_data); |
| + EXPECT_TRUE(display.has_touch_calibration_data()); |
| + |
| + ui::TouchscreenDevice touchscreen = |
| + CreateTouchscreenDevice(TOUCH_ID, TOUCH_SIZE); |
| + |
| + TouchTransformerController* tt_controller = |
| + Shell::GetInstance()->touch_transformer_controller(); |
| + ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance(); |
| + |
| + device_manager->UpdateTouchInfoForDisplay( |
| + display.id(), touchscreen.id, |
| + tt_controller->GetTouchTransform(display, display, touchscreen, |
| + TOUCH_SIZE)); |
| + |
| + EXPECT_EQ(DISPLAY_ID, |
| + device_manager->GetTargetDisplayForTouchDevice(TOUCH_ID)); |
| + |
| + CheckPointsOfInterests(TOUCH_ID, TOUCH_SIZE, DISPLAY_SIZE, MAX_ERROR_DELTA); |
| +} |
| + |
| +TEST_F(TouchTransformerControllerTest, ResolutionChangeUserTouchCalibration) { |
| + const gfx::Size DISPLAY_SIZE(2560, 1600), TOUCH_SIZE(1920, 1200); |
| + const int DISPLAY_ID = 1, TOUCH_ID = 5; |
| + // User touch inputs have a max error of 5%. |
| + const float ERROR = 0.05; |
| + // The maximum user error rate is |ERROR|%. Since the calibration is performed |
| + // with a best fit algorithm, the error rate observed should be less than |
| + // |ERROR|. |
| + gfx::Size MAX_ERROR_DELTA = gfx::ScaleToCeiledSize(DISPLAY_SIZE, ERROR); |
| + |
| + display::ManagedDisplayInfo display = CreateDisplayInfo( |
| + DISPLAY_ID, TOUCH_ID, |
| + gfx::Rect(0, 0, DISPLAY_SIZE.width(), DISPLAY_SIZE.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), MAX_ERROR_DELTA)), |
| + std::make_pair( |
| + gfx::Point(1820, 100), |
| + GetPointWithError(gfx::Point(1820, 100), MAX_ERROR_DELTA)), |
| + std::make_pair( |
| + gfx::Point(100, 1100), |
| + GetPointWithError(gfx::Point(100, 1100), MAX_ERROR_DELTA)), |
| + std::make_pair( |
| + gfx::Point(1820, 1100), |
| + GetPointWithError(gfx::Point(1820, 1100), MAX_ERROR_DELTA))}}; |
| + display::TouchCalibrationData touch_data(user_input, CALIBRATION_SIZE); |
| + display.SetTouchCalibrationData(touch_data); |
| + EXPECT_TRUE(display.has_touch_calibration_data()); |
| + |
| + ui::TouchscreenDevice touchscreen = |
| + CreateTouchscreenDevice(TOUCH_ID, TOUCH_SIZE); |
| + |
| + TouchTransformerController* tt_controller = |
| + Shell::GetInstance()->touch_transformer_controller(); |
| + ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance(); |
| + |
| + device_manager->UpdateTouchInfoForDisplay( |
| + display.id(), touchscreen.id, |
| + tt_controller->GetTouchTransform(display, display, touchscreen, |
| + TOUCH_SIZE)); |
| + |
| + EXPECT_EQ(DISPLAY_ID, |
| + device_manager->GetTargetDisplayForTouchDevice(TOUCH_ID)); |
| + |
| + CheckPointsOfInterests(TOUCH_ID, TOUCH_SIZE, DISPLAY_SIZE, MAX_ERROR_DELTA); |
| +} |
| + |
| +TEST_F(TouchTransformerControllerTest, DifferentBoundsUserTouchCalibration) { |
| + // The display bounds is different from the touch device bounds in this test. |
| + const gfx::Size DISPLAY_SIZE(1024, 600), TOUCH_SIZE(4096, 4096); |
| + const int DISPLAY_ID = 1, TOUCH_ID = 5; |
| + const float ACCEPTABLE_ERROR = 0.04; |
| + gfx::Size MAX_ERROR_DELTA = |
| + gfx::ScaleToCeiledSize(DISPLAY_SIZE, ACCEPTABLE_ERROR); |
| + |
| + display::ManagedDisplayInfo display = CreateDisplayInfo( |
| + DISPLAY_ID, TOUCH_ID, |
| + gfx::Rect(0, 0, DISPLAY_SIZE.width(), DISPLAY_SIZE.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, DISPLAY_SIZE); |
| + display.SetTouchCalibrationData(touch_data); |
| + EXPECT_TRUE(display.has_touch_calibration_data()); |
| + |
| + ui::TouchscreenDevice touchscreen = |
| + CreateTouchscreenDevice(TOUCH_ID, TOUCH_SIZE); |
| + |
| + TouchTransformerController* tt_controller = |
| + Shell::GetInstance()->touch_transformer_controller(); |
| + ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance(); |
| + |
| + device_manager->UpdateTouchInfoForDisplay( |
| + display.id(), touchscreen.id, |
| + tt_controller->GetTouchTransform(display, display, touchscreen, |
| + TOUCH_SIZE)); |
| + |
| + EXPECT_EQ(DISPLAY_ID, |
| + device_manager->GetTargetDisplayForTouchDevice(TOUCH_ID)); |
| + |
| + CheckPointsOfInterests(TOUCH_ID, TOUCH_SIZE, DISPLAY_SIZE, MAX_ERROR_DELTA); |
| +} |
| + |
| +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 NATIVE_DISPLAY_SIZE(2560, 1700), DISPLAY_SIZE(1920, 1200), |
| + TOUCH_SIZE(1920, 1200); |
| + const int DISPLAY_ID = 1, TOUCH_ID = 5; |
| + |
| + display::ManagedDisplayInfo internal_display_info = CreateDisplayInfo( |
| + DISPLAY_ID, TOUCH_ID, |
| + gfx::Rect(0, 0, DISPLAY_SIZE.width(), DISPLAY_SIZE.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(NATIVE_DISPLAY_SIZE.width(), NATIVE_DISPLAY_SIZE.height()), 60, |
| + false, true))); |
| + internal_modes.push_back(make_scoped_refptr(new display::ManagedDisplayMode( |
| + gfx::Size(DISPLAY_SIZE.width(), DISPLAY_SIZE.height()), 60, false, |
| + false))); |
| + internal_display_info.SetManagedDisplayModes(internal_modes); |
| + |
| + gfx::Size fb_size(DISPLAY_SIZE); |
| + |
| + // Create the touchscreens with the same size as the framebuffer so we can |
| + // share the tests between Ozone & X11. |
| + ui::TouchscreenDevice internal_touchscreen = |
| + CreateTouchscreenDevice(TOUCH_ID, fb_size); |
| + |
| + TouchTransformerController* tt_controller = |
| + Shell::GetInstance()->touch_transformer_controller(); |
| + 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 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, NATIVE_DISPLAY_SIZE); |
| + 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, |
| + tt_controller->GetTouchTransform(internal_display_info, |
| + internal_display_info, |
| + internal_touchscreen, fb_size)); |
| + |
| + EXPECT_EQ(DISPLAY_ID, |
| + device_manager->GetTargetDisplayForTouchDevice(TOUCH_ID)); |
| + |
| + 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(TOUCH_ID, &x, &y); |
| + EXPECT_NEAR(100, x, 0.5); |
| + EXPECT_NEAR(0, y, 0.5); |
| + |
| + x = 100.0; |
| + y = 1165.0; |
| + device_manager->ApplyTouchTransformer(TOUCH_ID, &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 NATIVE_DISPLAY_SIZE(2560, 1600), DISPLAY_SIZE(1920, 1400), |
| + TOUCH_SIZE(1920, 1400); |
| + const int DISPLAY_ID = 1, TOUCH_ID = 5; |
| + |
| + display::ManagedDisplayInfo internal_display_info = CreateDisplayInfo( |
| + DISPLAY_ID, TOUCH_ID, |
| + gfx::Rect(0, 0, DISPLAY_SIZE.width(), DISPLAY_SIZE.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(NATIVE_DISPLAY_SIZE.width(), NATIVE_DISPLAY_SIZE.height()), 60, |
| + false, true))); |
| + internal_modes.push_back(make_scoped_refptr(new display::ManagedDisplayMode( |
| + gfx::Size(DISPLAY_SIZE.width(), DISPLAY_SIZE.height()), 60, false, |
| + false))); |
| + internal_display_info.SetManagedDisplayModes(internal_modes); |
| + |
| + gfx::Size fb_size(DISPLAY_SIZE); |
| + |
| + // Create the touchscreens with the same size as the framebuffer so we can |
| + // share the tests between Ozone & X11. |
| + ui::TouchscreenDevice internal_touchscreen = |
| + CreateTouchscreenDevice(TOUCH_ID, fb_size); |
| + |
| + TouchTransformerController* tt_controller = |
| + Shell::GetInstance()->touch_transformer_controller(); |
| + 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, NATIVE_DISPLAY_SIZE); |
| + 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, |
| + tt_controller->GetTouchTransform(internal_display_info, |
| + internal_display_info, |
| + internal_touchscreen, fb_size)); |
| + |
| + EXPECT_EQ(DISPLAY_ID, |
| + device_manager->GetTargetDisplayForTouchDevice(TOUCH_ID)); |
| + |
| + 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(TOUCH_ID, &x, &y); |
| + EXPECT_NEAR(0, x, 0.5); |
| + EXPECT_NEAR(0, y, 0.5); |
| + |
| + x = 1782.0; |
| + y = 0.0; |
| + device_manager->ApplyTouchTransformer(TOUCH_ID, &x, &y); |
| + EXPECT_NEAR(1920, x, 0.5); |
| + EXPECT_NEAR(0, y, 0.5); |
| +} |
| + |
| } // namespace ash |