| OLD | NEW | 
|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/display/display_controller.h" | 5 #include "ash/display/display_controller.h" | 
| 6 | 6 | 
| 7 #include "ash/ash_switches.h" | 7 #include "ash/ash_switches.h" | 
| 8 #include "ash/display/display_info.h" | 8 #include "ash/display/display_info.h" | 
| 9 #include "ash/display/display_layout_store.h" | 9 #include "ash/display/display_layout_store.h" | 
| 10 #include "ash/display/display_manager.h" | 10 #include "ash/display/display_manager.h" | 
| (...skipping 1316 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1327   EXPECT_EQ("aura_root_0", GetXWindowName(primary->GetDispatcher()->host())); | 1327   EXPECT_EQ("aura_root_0", GetXWindowName(primary->GetDispatcher()->host())); | 
| 1328   EXPECT_EQ("aura_root_x", GetXWindowName(secondary->GetDispatcher()->host())); | 1328   EXPECT_EQ("aura_root_x", GetXWindowName(secondary->GetDispatcher()->host())); | 
| 1329 | 1329 | 
| 1330   // Switching back to single display. | 1330   // Switching back to single display. | 
| 1331   UpdateDisplay("300x400"); | 1331   UpdateDisplay("300x400"); | 
| 1332   EXPECT_EQ("aura_root_0", GetXWindowName( | 1332   EXPECT_EQ("aura_root_0", GetXWindowName( | 
| 1333       Shell::GetPrimaryRootWindow()->GetDispatcher()->host())); | 1333       Shell::GetPrimaryRootWindow()->GetDispatcher()->host())); | 
| 1334 } | 1334 } | 
| 1335 #endif | 1335 #endif | 
| 1336 | 1336 | 
|  | 1337 #if defined(OS_CHROMEOS) | 
|  | 1338 namespace { | 
|  | 1339 | 
|  | 1340 internal::DisplayInfo CreateDisplayInfo(int64 id, | 
|  | 1341                                         int touch_device_id, | 
|  | 1342                                         const gfx::Rect& bounds) { | 
|  | 1343   internal::DisplayInfo info(id, "", false); | 
|  | 1344   info.SetBounds(bounds); | 
|  | 1345   info.set_touch_device_id(touch_device_id); | 
|  | 1346   return info; | 
|  | 1347 } | 
|  | 1348 | 
|  | 1349 } | 
|  | 1350 | 
|  | 1351 TEST_F(DisplayControllerTest, TouchCTMSingleDisplay) { | 
|  | 1352   // Non-touch display. | 
|  | 1353   UpdateDisplay("500x500"); | 
|  | 1354   aura::Window* primary = Shell::GetPrimaryRootWindow(); | 
|  | 1355   std::map<int, aura::TouchCTM>* touch_ctm_map = | 
|  | 1356       primary->GetDispatcher()->host()->GetTouchCTMMap(); | 
|  | 1357   EXPECT_EQ(0U, touch_ctm_map->size()); | 
|  | 1358 | 
|  | 1359   // Touch display. | 
|  | 1360   const internal::DisplayInfo touch_display_info = | 
|  | 1361       CreateDisplayInfo(1, 10, gfx::Rect(0, 0, 500, 500)); | 
|  | 1362   std::vector<internal::DisplayInfo> display_info_list; | 
|  | 1363   display_info_list.push_back(touch_display_info); | 
|  | 1364   Shell::GetInstance()->display_manager()->OnNativeDisplaysChanged( | 
|  | 1365       display_info_list); | 
|  | 1366 | 
|  | 1367   primary = Shell::GetPrimaryRootWindow(); | 
|  | 1368   touch_ctm_map = primary->GetDispatcher()->host()->GetTouchCTMMap(); | 
|  | 1369   EXPECT_EQ(1U, touch_ctm_map->size()); | 
|  | 1370   EXPECT_TRUE(touch_ctm_map->find(10) != touch_ctm_map->end()); | 
|  | 1371   aura::TouchCTM default_ctm; | 
|  | 1372   aura::TouchCTM touch_ctm = (*touch_ctm_map)[10]; | 
|  | 1373   EXPECT_EQ(default_ctm.x_scale, touch_ctm.x_scale); | 
|  | 1374   EXPECT_EQ(default_ctm.x_offset, touch_ctm.x_offset); | 
|  | 1375   EXPECT_EQ(default_ctm.y_scale, touch_ctm.y_scale); | 
|  | 1376   EXPECT_EQ(default_ctm.y_offset, touch_ctm.y_offset); | 
|  | 1377 } | 
|  | 1378 | 
|  | 1379 TEST_F(DisplayControllerTest, TouchCTMMirrorModeLetterboxing) { | 
|  | 1380   // The internal display has native resolution of 2560x1700, and in | 
|  | 1381   // mirror mode it is configured as 1920x1200. This is in letterboxing | 
|  | 1382   // mode. | 
|  | 1383   internal::DisplayInfo internal_display_info = | 
|  | 1384       CreateDisplayInfo(1, 10, gfx::Rect(0, 0, 1920, 1200)); | 
|  | 1385   std::vector<internal::DisplayMode> internal_modes; | 
|  | 1386   internal_modes.push_back( | 
|  | 1387       internal::DisplayMode(gfx::Size(2560, 1700), 60, false, true)); | 
|  | 1388   internal_modes.push_back( | 
|  | 1389       internal::DisplayMode(gfx::Size(1920, 1200), 60, false, false)); | 
|  | 1390   internal_display_info.set_display_modes(internal_modes); | 
|  | 1391 | 
|  | 1392   internal::DisplayInfo external_display_info = | 
|  | 1393       CreateDisplayInfo(2, 11, gfx::Rect(0, 0, 1920, 1200)); | 
|  | 1394 | 
|  | 1395   gfx::Display::SetInternalDisplayId(1); | 
|  | 1396 | 
|  | 1397   std::vector<internal::DisplayInfo> display_info_list; | 
|  | 1398   display_info_list.push_back(internal_display_info); | 
|  | 1399   display_info_list.push_back(external_display_info); | 
|  | 1400   Shell::GetInstance()->output_configurator()->set_output_state( | 
|  | 1401       ui::OUTPUT_STATE_DUAL_MIRROR); | 
|  | 1402   Shell::GetInstance()->display_manager()->OnNativeDisplaysChanged( | 
|  | 1403       display_info_list); | 
|  | 1404 | 
|  | 1405   aura::Window* primary = Shell::GetPrimaryRootWindow(); | 
|  | 1406   std::map<int, aura::TouchCTM>* touch_ctm_map = | 
|  | 1407       primary->GetDispatcher()->host()->GetTouchCTMMap(); | 
|  | 1408   // In mirror mode, there is only root window and it has the TouchCTM | 
|  | 1409   // for both touch devices. | 
|  | 1410   EXPECT_EQ(2U, touch_ctm_map->size()); | 
|  | 1411 | 
|  | 1412   // External touchscreen has the default TouchCTM. | 
|  | 1413   aura::TouchCTM default_ctm; | 
|  | 1414   aura::TouchCTM external_ctm = (*touch_ctm_map)[11]; | 
|  | 1415   EXPECT_EQ(default_ctm.x_scale, external_ctm.x_scale); | 
|  | 1416   EXPECT_EQ(default_ctm.x_offset, external_ctm.x_offset); | 
|  | 1417 | 
|  | 1418   // In letterboxing, there is (1-2560*(1200/1920)/1700)/2 = 2.95% of the | 
|  | 1419   // height on both the top & bottom region of the screen is blank. | 
|  | 1420   // When touch events coming at Y range [0, 1200), the mapping should be | 
|  | 1421   // [0, ~35] ---> < 0 | 
|  | 1422   // [~35, ~1165] ---> [0, 1200) | 
|  | 1423   // [~1165, 1200] ---> >= 1200 | 
|  | 1424   aura::TouchCTM internal_ctm = (*touch_ctm_map)[10]; | 
|  | 1425   EXPECT_EQ(1, internal_ctm.x_scale); | 
|  | 1426   EXPECT_EQ(0, internal_ctm.x_offset); | 
|  | 1427   LOG(ERROR) << internal_ctm.x_scale << " " << internal_ctm.x_offset << " " | 
|  | 1428              << internal_ctm.y_scale << " " << internal_ctm.y_offset; | 
|  | 1429   float blank_percent = (1.0 - 2560.0 * (1200.0 / 1920.0) / 1700.0) / 2.0; | 
|  | 1430   float blank_pixel = 1200.0 * blank_percent; | 
|  | 1431   int transformed_y_min = | 
|  | 1432       blank_pixel * internal_ctm.y_scale + internal_ctm.y_offset; | 
|  | 1433   int transformed_y_max = | 
|  | 1434       (1200 - blank_pixel) * internal_ctm.y_scale + internal_ctm.y_offset; | 
|  | 1435   EXPECT_LT(abs(transformed_y_min - 0), 2); | 
|  | 1436   EXPECT_LT(abs(transformed_y_max - 1200), 2); | 
|  | 1437 } | 
|  | 1438 | 
|  | 1439 TEST_F(DisplayControllerTest, TouchCTMMirrorModePillarboxing) { | 
|  | 1440   // The internal display has native resolution of 1366x768, and in | 
|  | 1441   // mirror mode it is configured as 1024x768. This is in pillarboxing | 
|  | 1442   // mode. | 
|  | 1443   internal::DisplayInfo internal_display_info = | 
|  | 1444       CreateDisplayInfo(1, 10, gfx::Rect(0, 0, 1024, 768)); | 
|  | 1445   std::vector<internal::DisplayMode> internal_modes; | 
|  | 1446   internal_modes.push_back( | 
|  | 1447       internal::DisplayMode(gfx::Size(1366, 768), 60, false, true)); | 
|  | 1448   internal_modes.push_back( | 
|  | 1449       internal::DisplayMode(gfx::Size(1024, 768), 60, false, false)); | 
|  | 1450   internal_display_info.set_display_modes(internal_modes); | 
|  | 1451 | 
|  | 1452   internal::DisplayInfo external_display_info = | 
|  | 1453       CreateDisplayInfo(2, 11, gfx::Rect(0, 0, 1024, 768)); | 
|  | 1454 | 
|  | 1455   gfx::Display::SetInternalDisplayId(1); | 
|  | 1456 | 
|  | 1457   std::vector<internal::DisplayInfo> display_info_list; | 
|  | 1458   display_info_list.push_back(internal_display_info); | 
|  | 1459   display_info_list.push_back(external_display_info); | 
|  | 1460   Shell::GetInstance()->output_configurator()->set_output_state( | 
|  | 1461       ui::OUTPUT_STATE_DUAL_MIRROR); | 
|  | 1462   Shell::GetInstance()->display_manager()->OnNativeDisplaysChanged( | 
|  | 1463       display_info_list); | 
|  | 1464 | 
|  | 1465   aura::Window* primary = Shell::GetPrimaryRootWindow(); | 
|  | 1466   std::map<int, aura::TouchCTM>* touch_ctm_map = | 
|  | 1467       primary->GetDispatcher()->host()->GetTouchCTMMap(); | 
|  | 1468   // In mirror mode, there is only root window and it has the TouchCTM | 
|  | 1469   // for both touch devices. | 
|  | 1470   EXPECT_EQ(2U, touch_ctm_map->size()); | 
|  | 1471 | 
|  | 1472   // External touchscreen has the default TouchCTM. | 
|  | 1473   aura::TouchCTM default_ctm; | 
|  | 1474   aura::TouchCTM external_ctm = (*touch_ctm_map)[11]; | 
|  | 1475   EXPECT_EQ(default_ctm.x_scale, external_ctm.x_scale); | 
|  | 1476   EXPECT_EQ(default_ctm.x_offset, external_ctm.x_offset); | 
|  | 1477 | 
|  | 1478   // In pillarboxing, there is (1-768*(1024/768)/1366)/2 = 12.5% of the | 
|  | 1479   // width on both the left & rigth region of the screen is blank. | 
|  | 1480   // When touch events coming at X range [0, 1024), the mapping should be | 
|  | 1481   // [0, ~128] ---> < 0 | 
|  | 1482   // [~128, ~896] ---> [0, 1024) | 
|  | 1483   // [~896, 1024] ---> >= 1024 | 
|  | 1484   aura::TouchCTM internal_ctm = (*touch_ctm_map)[10]; | 
|  | 1485   EXPECT_EQ(1, internal_ctm.y_scale); | 
|  | 1486   EXPECT_EQ(0, internal_ctm.y_offset); | 
|  | 1487   LOG(ERROR) << internal_ctm.x_scale << " " << internal_ctm.x_offset << " " | 
|  | 1488              << internal_ctm.y_scale << " " << internal_ctm.y_offset; | 
|  | 1489   float blank_percent = (1.0 - 768.0 * (1024.0 / 768.0) / 1366.0) / 2.0; | 
|  | 1490   float blank_pixel = 1024.0 * blank_percent; | 
|  | 1491   int transformed_x_min = | 
|  | 1492       blank_pixel * internal_ctm.x_scale + internal_ctm.x_offset; | 
|  | 1493   int transformed_x_max = | 
|  | 1494       (1024 - blank_pixel) * internal_ctm.x_scale + internal_ctm.x_offset; | 
|  | 1495   EXPECT_LT(abs(transformed_x_min - 0), 2); | 
|  | 1496   EXPECT_LT(abs(transformed_x_max - 1024), 2); | 
|  | 1497 } | 
|  | 1498 | 
|  | 1499 TEST_F(DisplayControllerTest, TouchCTMExtendedMode) { | 
|  | 1500   // The internal display has size 1366 x 768. The external display has | 
|  | 1501   // size 2560x1600. The total frame buffer is 2560x2418, | 
|  | 1502   // where 2428 = 768 + 60 (hidden gap) + 1600 | 
|  | 1503   // and the sceond monitor is translated to Point (0, 828) in the | 
|  | 1504   // framebuffer. | 
|  | 1505   internal::DisplayInfo internal_display_info = | 
|  | 1506       CreateDisplayInfo(1, 10, gfx::Rect(0, 0, 1366, 768)); | 
|  | 1507   internal::DisplayInfo external_display_info = | 
|  | 1508       CreateDisplayInfo(2, 11, gfx::Rect(0, 828, 2560, 1600)); | 
|  | 1509 | 
|  | 1510   std::vector<internal::DisplayInfo> display_info_list; | 
|  | 1511   display_info_list.push_back(internal_display_info); | 
|  | 1512   display_info_list.push_back(external_display_info); | 
|  | 1513   Shell::GetInstance()->output_configurator()->set_output_state( | 
|  | 1514       ui::OUTPUT_STATE_DUAL_EXTENDED); | 
|  | 1515   Shell::GetInstance()->display_manager()->OnNativeDisplaysChanged( | 
|  | 1516       display_info_list); | 
|  | 1517 | 
|  | 1518   DisplayController* display_controller = | 
|  | 1519       Shell::GetInstance()->display_controller(); | 
|  | 1520   aura::Window* primary = display_controller->GetRootWindowForDisplayId(1); | 
|  | 1521   std::map<int, aura::TouchCTM>* primary_touch_ctm_map = | 
|  | 1522       primary->GetDispatcher()->host()->GetTouchCTMMap(); | 
|  | 1523   aura::Window* secondary = display_controller->GetRootWindowForDisplayId(2); | 
|  | 1524   std::map<int, aura::TouchCTM>* secondary_touch_ctm_map = | 
|  | 1525       secondary->GetDispatcher()->host()->GetTouchCTMMap(); | 
|  | 1526   EXPECT_EQ(1U, primary_touch_ctm_map->size()); | 
|  | 1527   EXPECT_EQ(1U, secondary_touch_ctm_map->size()); | 
|  | 1528   aura::TouchCTM primary_ctm = (*primary_touch_ctm_map)[10]; | 
|  | 1529   aura::TouchCTM secondary_ctm = (*secondary_touch_ctm_map)[11]; | 
|  | 1530 | 
|  | 1531   // Mapping for touch events from internal touch display: | 
|  | 1532   // [0, 2560) x [0, 2428) -> [0, 1366) x [0, 768) | 
|  | 1533   EXPECT_EQ(0, primary_ctm.x_scale * 0 + primary_ctm.x_offset); | 
|  | 1534   EXPECT_EQ(0, primary_ctm.y_scale * 0 + primary_ctm.y_offset); | 
|  | 1535   EXPECT_EQ(1365, primary_ctm.x_scale * 2559 + primary_ctm.x_offset); | 
|  | 1536   EXPECT_EQ(767, primary_ctm.y_scale * 2427 + primary_ctm.y_offset); | 
|  | 1537 | 
|  | 1538   // Mapping for touch events from external touch display: | 
|  | 1539   // [0, 2560) x [0, 2428) -> [0, 2560) x [828, 2428) | 
|  | 1540   EXPECT_EQ(0, secondary_ctm.x_scale * 0 + secondary_ctm.x_offset); | 
|  | 1541   EXPECT_EQ(828, secondary_ctm.y_scale * 0 + secondary_ctm.y_offset); | 
|  | 1542   EXPECT_EQ(2559, secondary_ctm.x_scale * 2559 + secondary_ctm.x_offset); | 
|  | 1543   EXPECT_EQ(2427, secondary_ctm.y_scale * 2427 + secondary_ctm.y_offset); | 
|  | 1544 } | 
|  | 1545 #endif | 
|  | 1546 | 
| 1337 }  // namespace ash | 1547 }  // namespace ash | 
| OLD | NEW | 
|---|