Index: ash/display/display_controller_unittest.cc |
diff --git a/ash/display/display_controller_unittest.cc b/ash/display/display_controller_unittest.cc |
index a0612354fc527e7a497585857eca7c81785105bf..555d760251aec944d3de354e36baf39739d41496 100644 |
--- a/ash/display/display_controller_unittest.cc |
+++ b/ash/display/display_controller_unittest.cc |
@@ -37,6 +37,10 @@ |
#undef RootWindow |
#endif |
+#if defined(OS_CHROMEOS) && defined(USE_X11) |
+#include "ui/events/x/device_data_manager.h" |
+#endif |
+ |
namespace ash { |
namespace { |
@@ -1242,4 +1246,239 @@ TEST_F(DisplayControllerTest, XWidowNameForRootWindow) { |
} |
#endif |
+#if defined(OS_CHROMEOS) |
+namespace { |
+ |
+internal::DisplayInfo CreateDisplayInfo(int64 id, |
+ int touch_device_id, |
+ const gfx::Rect& bounds) { |
+ internal::DisplayInfo info(id, "", false); |
+ info.SetBounds(bounds); |
+ info.set_touch_device_id(touch_device_id); |
+ return info; |
+} |
+ |
+} |
+ |
+TEST_F(DisplayControllerTest, TouchCTMSingleTouchDisplay) { |
+ // Touch display. |
+ const internal::DisplayInfo touch_display_info = |
+ CreateDisplayInfo(1, 10, gfx::Rect(0, 0, 500, 500)); |
+ std::vector<internal::DisplayInfo> display_info_list; |
+ display_info_list.push_back(touch_display_info); |
+ Shell::GetInstance()->display_manager()->OnNativeDisplaysChanged( |
+ display_info_list); |
+ |
+ std::pair<int64, int64> display_ids = |
+ Shell::GetPrimaryRootWindow()->GetHost()->display_ids(); |
+ EXPECT_EQ(1, display_ids.first); |
+ EXPECT_EQ(gfx::Display::kInvalidDisplayID, display_ids.second); |
+ |
+ ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance(); |
+ EXPECT_EQ(1, device_manager->GetDisplayForTouchDevice(10)); |
+ |
+ // Single touch display has the default TouchCTM. |
+ float x = 100.0; |
+ float y = 100.0; |
+ device_manager->ApplyTouchCTM(10, &x, &y); |
+ EXPECT_EQ(100, x); |
+ EXPECT_EQ(100, y); |
+} |
+ |
+TEST_F(DisplayControllerTest, TouchCTMMirrorModeLetterboxing) { |
+ // The internal display has native resolution of 2560x1700, and in |
+ // mirror mode it is configured as 1920x1200. This is in letterboxing |
+ // mode. |
+ internal::DisplayInfo internal_display_info = |
+ CreateDisplayInfo(1, 10, gfx::Rect(0, 0, 1920, 1200)); |
+ std::vector<internal::DisplayMode> internal_modes; |
+ internal_modes.push_back( |
+ internal::DisplayMode(gfx::Size(2560, 1700), 60, false, true)); |
+ internal_modes.push_back( |
+ internal::DisplayMode(gfx::Size(1920, 1200), 60, false, false)); |
+ internal_display_info.set_display_modes(internal_modes); |
+ |
+ internal::DisplayInfo external_display_info = |
+ CreateDisplayInfo(2, 11, gfx::Rect(0, 0, 1920, 1200)); |
+ |
+ gfx::Display::SetInternalDisplayId(1); |
+ |
+ std::vector<internal::DisplayInfo> display_info_list; |
+ display_info_list.push_back(internal_display_info); |
+ display_info_list.push_back(external_display_info); |
+ Shell::GetInstance()->output_configurator()->set_output_state( |
+ ui::OUTPUT_STATE_DUAL_MIRROR); |
+ Shell::GetInstance()->display_manager()->OnNativeDisplaysChanged( |
+ display_info_list); |
+ |
+ // In mirror mode, the root window host is associated with both |
+ // display ids. |
+ std::pair<int64, int64> display_ids = |
+ Shell::GetPrimaryRootWindow()->GetHost()->display_ids(); |
+ EXPECT_EQ(1, display_ids.first); |
+ EXPECT_EQ(2, display_ids.second); |
+ |
+ ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance(); |
+ EXPECT_EQ(1, device_manager->GetDisplayForTouchDevice(10)); |
+ EXPECT_EQ(2, device_manager->GetDisplayForTouchDevice(11)); |
+ |
+ // External touch display has the default TouchCTM. |
+ float x = 100.0; |
+ float y = 100.0; |
+ device_manager->ApplyTouchCTM(11, &x, &y); |
+ EXPECT_EQ(100, x); |
+ EXPECT_EQ(100, 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->ApplyTouchCTM(10, &x, &y); |
+ EXPECT_EQ(100, x); |
+ EXPECT_EQ(0, abs(y - 0)); |
+ |
+ x = 100.0; |
+ y = 1165.0; |
+ device_manager->ApplyTouchCTM(10, &x, &y); |
+ EXPECT_EQ(100, x); |
+ EXPECT_EQ(0, abs(y - 1200)); |
+} |
+ |
+TEST_F(DisplayControllerTest, TouchCTMMirrorModePillarboxing) { |
+ // The internal display has native resolution of 1366x768, and in |
+ // mirror mode it is configured as 1024x768. This is in pillarboxing |
+ // mode. |
+ internal::DisplayInfo internal_display_info = |
+ CreateDisplayInfo(1, 10, gfx::Rect(0, 0, 1024, 768)); |
+ std::vector<internal::DisplayMode> internal_modes; |
+ internal_modes.push_back( |
+ internal::DisplayMode(gfx::Size(1366, 768), 60, false, true)); |
+ internal_modes.push_back( |
+ internal::DisplayMode(gfx::Size(1024, 768), 60, false, false)); |
+ internal_display_info.set_display_modes(internal_modes); |
+ |
+ internal::DisplayInfo external_display_info = |
+ CreateDisplayInfo(2, 11, gfx::Rect(0, 0, 1024, 768)); |
+ |
+ gfx::Display::SetInternalDisplayId(1); |
+ |
+ std::vector<internal::DisplayInfo> display_info_list; |
+ display_info_list.push_back(internal_display_info); |
+ display_info_list.push_back(external_display_info); |
+ Shell::GetInstance()->output_configurator()->set_output_state( |
+ ui::OUTPUT_STATE_DUAL_MIRROR); |
+ Shell::GetInstance()->display_manager()->OnNativeDisplaysChanged( |
+ display_info_list); |
+ |
+ // In mirror mode, the root window host is associated with both |
+ // display ids. |
+ std::pair<int64, int64> display_ids = |
+ Shell::GetPrimaryRootWindow()->GetHost()->display_ids(); |
+ EXPECT_EQ(1, display_ids.first); |
+ EXPECT_EQ(2, display_ids.second); |
+ |
+ ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance(); |
+ EXPECT_EQ(1, device_manager->GetDisplayForTouchDevice(10)); |
+ EXPECT_EQ(2, device_manager->GetDisplayForTouchDevice(11)); |
+ |
+ // External touch display has the default TouchCTM. |
+ float x = 100.0; |
+ float y = 100.0; |
+ device_manager->ApplyTouchCTM(11, &x, &y); |
+ EXPECT_EQ(100, x); |
+ EXPECT_EQ(100, y); |
+ |
+ // In pillarboxing, there is (1-768*(1024/768)/1366)/2 = 12.5% of the |
+ // width on both the left & rigth region of the screen is blank. |
+ // When touch events coming at X range [0, 1024), the mapping should be |
+ // [0, ~128] ---> < 0 |
+ // [~128, ~896] ---> [0, 1024) |
+ // [~896, 1024] ---> >= 1024 |
+ x = 128.0; |
+ y = 100.0; |
+ device_manager->ApplyTouchCTM(10, &x, &y); |
+ EXPECT_EQ(0, abs(x - 0)); |
+ EXPECT_EQ(100, y); |
+ |
+ x = 896.0; |
+ y = 100.0; |
+ device_manager->ApplyTouchCTM(10, &x, &y); |
+ EXPECT_EQ(0, abs(x - 1024)); |
+ EXPECT_EQ(100, y); |
+} |
+ |
+TEST_F(DisplayControllerTest, TouchCTMExtendedMode) { |
+ // The internal display has size 1366 x 768. The external display has |
+ // size 2560x1600. The total frame buffer is 2560x2428, |
+ // where 2428 = 768 + 60 (hidden gap) + 1600 |
+ // and the sceond monitor is translated to Point (0, 828) in the |
+ // framebuffer. |
+ internal::DisplayInfo internal_display_info = |
+ CreateDisplayInfo(1, 10, gfx::Rect(0, 0, 1366, 768)); |
+ internal::DisplayInfo external_display_info = |
+ CreateDisplayInfo(2, 11, gfx::Rect(0, 828, 2560, 1600)); |
+ |
+ std::vector<internal::DisplayInfo> display_info_list; |
+ display_info_list.push_back(internal_display_info); |
+ display_info_list.push_back(external_display_info); |
+ Shell::GetInstance()->output_configurator()->set_output_state( |
+ ui::OUTPUT_STATE_DUAL_EXTENDED); |
+ Shell::GetInstance()->display_manager()->OnNativeDisplaysChanged( |
+ display_info_list); |
+ |
+ DisplayController* display_controller = |
+ Shell::GetInstance()->display_controller(); |
+ aura::Window* primary = display_controller->GetRootWindowForDisplayId(1); |
+ std::pair<int64, int64> primary_display_ids = |
+ primary->GetHost()->display_ids(); |
+ aura::Window* secondary = display_controller->GetRootWindowForDisplayId(2); |
+ std::pair<int64, int64> secondary_display_ids = |
+ secondary->GetHost()->display_ids(); |
+ // The primary root window is associated with display ID 1. |
+ EXPECT_EQ(1, primary_display_ids.first); |
+ EXPECT_EQ(gfx::Display::kInvalidDisplayID, primary_display_ids.second); |
+ // The secondary root window is associated with display ID 2. |
+ EXPECT_EQ(2, secondary_display_ids.first); |
+ EXPECT_EQ(gfx::Display::kInvalidDisplayID, secondary_display_ids.second); |
+ |
+ |
+ ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance(); |
+ EXPECT_EQ(1, device_manager->GetDisplayForTouchDevice(10)); |
+ EXPECT_EQ(2, device_manager->GetDisplayForTouchDevice(11)); |
+ |
+ // Mapping for touch events from internal touch display: |
+ // [0, 2560) x [0, 2428) -> [0, 1366) x [0, 768) |
+ float x = 0.0; |
+ float y = 0.0; |
+ device_manager->ApplyTouchCTM(10, &x, &y); |
+ EXPECT_EQ(0, x); |
+ EXPECT_EQ(0, y); |
+ |
+ x = 2559.0; |
+ y = 2427.0; |
+ device_manager->ApplyTouchCTM(10, &x, &y); |
+ EXPECT_EQ(1365, x); |
+ EXPECT_EQ(767, y); |
+ |
+ // Mapping for touch events from external touch display: |
+ // [0, 2560) x [0, 2428) -> [0, 2560) x [0, 1600) |
+ x = 0.0; |
+ y = 0.0; |
+ device_manager->ApplyTouchCTM(11, &x, &y); |
+ EXPECT_EQ(0, x); |
+ EXPECT_EQ(0, y); |
+ |
+ x = 2559.0; |
+ y = 2427.0; |
+ device_manager->ApplyTouchCTM(11, &x, &y); |
+ EXPECT_EQ(2559, x); |
+ EXPECT_EQ(1599, y); |
+} |
+ |
+#endif |
+ |
} // namespace ash |