| Index: ash/display/display_controller_unittest.cc
|
| diff --git a/ash/display/display_controller_unittest.cc b/ash/display/display_controller_unittest.cc
|
| index bf2eeb3f048835593cc89d7e1e5f44a2b8083827..a2b5e1eb6f5a43b1d4ddc90b34b1aec972865d14 100644
|
| --- a/ash/display/display_controller_unittest.cc
|
| +++ b/ash/display/display_controller_unittest.cc
|
| @@ -1334,4 +1334,214 @@ 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, TouchCTMSingleDisplay) {
|
| + // Non-touch display.
|
| + UpdateDisplay("500x500");
|
| + aura::Window* primary = Shell::GetPrimaryRootWindow();
|
| + std::map<int, aura::TouchCTM>* touch_ctm_map =
|
| + primary->GetDispatcher()->host()->GetTouchCTMMap();
|
| + EXPECT_EQ(0U, touch_ctm_map->size());
|
| +
|
| + // 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);
|
| +
|
| + primary = Shell::GetPrimaryRootWindow();
|
| + touch_ctm_map = primary->GetDispatcher()->host()->GetTouchCTMMap();
|
| + EXPECT_EQ(1U, touch_ctm_map->size());
|
| + EXPECT_TRUE(touch_ctm_map->find(10) != touch_ctm_map->end());
|
| + aura::TouchCTM default_ctm;
|
| + aura::TouchCTM touch_ctm = (*touch_ctm_map)[10];
|
| + EXPECT_EQ(default_ctm.x_scale, touch_ctm.x_scale);
|
| + EXPECT_EQ(default_ctm.x_offset, touch_ctm.x_offset);
|
| + EXPECT_EQ(default_ctm.y_scale, touch_ctm.y_scale);
|
| + EXPECT_EQ(default_ctm.y_offset, touch_ctm.y_offset);
|
| +}
|
| +
|
| +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);
|
| +
|
| + aura::Window* primary = Shell::GetPrimaryRootWindow();
|
| + std::map<int, aura::TouchCTM>* touch_ctm_map =
|
| + primary->GetDispatcher()->host()->GetTouchCTMMap();
|
| + // In mirror mode, there is only root window and it has the TouchCTM
|
| + // for both touch devices.
|
| + EXPECT_EQ(2U, touch_ctm_map->size());
|
| +
|
| + // External touchscreen has the default TouchCTM.
|
| + aura::TouchCTM default_ctm;
|
| + aura::TouchCTM external_ctm = (*touch_ctm_map)[11];
|
| + EXPECT_EQ(default_ctm.x_scale, external_ctm.x_scale);
|
| + EXPECT_EQ(default_ctm.x_offset, external_ctm.x_offset);
|
| +
|
| + // 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
|
| + aura::TouchCTM internal_ctm = (*touch_ctm_map)[10];
|
| + EXPECT_EQ(1, internal_ctm.x_scale);
|
| + EXPECT_EQ(0, internal_ctm.x_offset);
|
| + LOG(ERROR) << internal_ctm.x_scale << " " << internal_ctm.x_offset << " "
|
| + << internal_ctm.y_scale << " " << internal_ctm.y_offset;
|
| + float blank_percent = (1.0 - 2560.0 * (1200.0 / 1920.0) / 1700.0) / 2.0;
|
| + float blank_pixel = 1200.0 * blank_percent;
|
| + int transformed_y_min =
|
| + blank_pixel * internal_ctm.y_scale + internal_ctm.y_offset;
|
| + int transformed_y_max =
|
| + (1200 - blank_pixel) * internal_ctm.y_scale + internal_ctm.y_offset;
|
| + EXPECT_LT(abs(transformed_y_min - 0), 2);
|
| + EXPECT_LT(abs(transformed_y_max - 1200), 2);
|
| +}
|
| +
|
| +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);
|
| +
|
| + aura::Window* primary = Shell::GetPrimaryRootWindow();
|
| + std::map<int, aura::TouchCTM>* touch_ctm_map =
|
| + primary->GetDispatcher()->host()->GetTouchCTMMap();
|
| + // In mirror mode, there is only root window and it has the TouchCTM
|
| + // for both touch devices.
|
| + EXPECT_EQ(2U, touch_ctm_map->size());
|
| +
|
| + // External touchscreen has the default TouchCTM.
|
| + aura::TouchCTM default_ctm;
|
| + aura::TouchCTM external_ctm = (*touch_ctm_map)[11];
|
| + EXPECT_EQ(default_ctm.x_scale, external_ctm.x_scale);
|
| + EXPECT_EQ(default_ctm.x_offset, external_ctm.x_offset);
|
| +
|
| + // 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
|
| + aura::TouchCTM internal_ctm = (*touch_ctm_map)[10];
|
| + EXPECT_EQ(1, internal_ctm.y_scale);
|
| + EXPECT_EQ(0, internal_ctm.y_offset);
|
| + LOG(ERROR) << internal_ctm.x_scale << " " << internal_ctm.x_offset << " "
|
| + << internal_ctm.y_scale << " " << internal_ctm.y_offset;
|
| + float blank_percent = (1.0 - 768.0 * (1024.0 / 768.0) / 1366.0) / 2.0;
|
| + float blank_pixel = 1024.0 * blank_percent;
|
| + int transformed_x_min =
|
| + blank_pixel * internal_ctm.x_scale + internal_ctm.x_offset;
|
| + int transformed_x_max =
|
| + (1024 - blank_pixel) * internal_ctm.x_scale + internal_ctm.x_offset;
|
| + EXPECT_LT(abs(transformed_x_min - 0), 2);
|
| + EXPECT_LT(abs(transformed_x_max - 1024), 2);
|
| +}
|
| +
|
| +TEST_F(DisplayControllerTest, TouchCTMExtendedMode) {
|
| + // The internal display has size 1366 x 768. The external display has
|
| + // size 2560x1600. The total frame buffer is 2560x2418,
|
| + // 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::map<int, aura::TouchCTM>* primary_touch_ctm_map =
|
| + primary->GetDispatcher()->host()->GetTouchCTMMap();
|
| + aura::Window* secondary = display_controller->GetRootWindowForDisplayId(2);
|
| + std::map<int, aura::TouchCTM>* secondary_touch_ctm_map =
|
| + secondary->GetDispatcher()->host()->GetTouchCTMMap();
|
| + EXPECT_EQ(1U, primary_touch_ctm_map->size());
|
| + EXPECT_EQ(1U, secondary_touch_ctm_map->size());
|
| + aura::TouchCTM primary_ctm = (*primary_touch_ctm_map)[10];
|
| + aura::TouchCTM secondary_ctm = (*secondary_touch_ctm_map)[11];
|
| +
|
| + // Mapping for touch events from internal touch display:
|
| + // [0, 2560) x [0, 2428) -> [0, 1366) x [0, 768)
|
| + EXPECT_EQ(0, primary_ctm.x_scale * 0 + primary_ctm.x_offset);
|
| + EXPECT_EQ(0, primary_ctm.y_scale * 0 + primary_ctm.y_offset);
|
| + EXPECT_EQ(1365, primary_ctm.x_scale * 2559 + primary_ctm.x_offset);
|
| + EXPECT_EQ(767, primary_ctm.y_scale * 2427 + primary_ctm.y_offset);
|
| +
|
| + // Mapping for touch events from external touch display:
|
| + // [0, 2560) x [0, 2428) -> [0, 2560) x [828, 2428)
|
| + EXPECT_EQ(0, secondary_ctm.x_scale * 0 + secondary_ctm.x_offset);
|
| + EXPECT_EQ(828, secondary_ctm.y_scale * 0 + secondary_ctm.y_offset);
|
| + EXPECT_EQ(2559, secondary_ctm.x_scale * 2559 + secondary_ctm.x_offset);
|
| + EXPECT_EQ(2427, secondary_ctm.y_scale * 2427 + secondary_ctm.y_offset);
|
| +}
|
| +#endif
|
| +
|
| } // namespace ash
|
|
|