Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(89)

Side by Side Diff: ash/display/display_controller_unittest.cc

Issue 191223007: Move touch CTM from X into Chrome (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: restructuring Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 19 matching lines...) Expand all
30 #include "ui/gfx/display.h" 30 #include "ui/gfx/display.h"
31 #include "ui/gfx/screen.h" 31 #include "ui/gfx/screen.h"
32 #include "ui/views/widget/widget.h" 32 #include "ui/views/widget/widget.h"
33 33
34 #if defined(USE_X11) 34 #if defined(USE_X11)
35 #include <X11/Xlib.h> 35 #include <X11/Xlib.h>
36 #include "ui/gfx/x/x11_types.h" 36 #include "ui/gfx/x/x11_types.h"
37 #undef RootWindow 37 #undef RootWindow
38 #endif 38 #endif
39 39
40 #if defined(OS_CHROMEOS) && defined(USE_X11)
41 #include "ui/events/x/device_data_manager.h"
42 #endif
43
40 namespace ash { 44 namespace ash {
41 namespace { 45 namespace {
42 46
43 const char kDesktopBackgroundView[] = "DesktopBackgroundView"; 47 const char kDesktopBackgroundView[] = "DesktopBackgroundView";
44 48
45 template<typename T> 49 template<typename T>
46 class Resetter { 50 class Resetter {
47 public: 51 public:
48 explicit Resetter(T* value) : value_(*value) { 52 explicit Resetter(T* value) : value_(*value) {
49 *value = 0; 53 *value = 0;
(...skipping 1185 matching lines...) Expand 10 before | Expand all | Expand 10 after
1235 EXPECT_EQ("aura_root_0", GetXWindowName(primary->GetHost())); 1239 EXPECT_EQ("aura_root_0", GetXWindowName(primary->GetHost()));
1236 EXPECT_EQ("aura_root_x", GetXWindowName(secondary->GetHost())); 1240 EXPECT_EQ("aura_root_x", GetXWindowName(secondary->GetHost()));
1237 1241
1238 // Switching back to single display. 1242 // Switching back to single display.
1239 UpdateDisplay("300x400"); 1243 UpdateDisplay("300x400");
1240 EXPECT_EQ("aura_root_0", GetXWindowName( 1244 EXPECT_EQ("aura_root_0", GetXWindowName(
1241 Shell::GetPrimaryRootWindow()->GetHost())); 1245 Shell::GetPrimaryRootWindow()->GetHost()));
1242 } 1246 }
1243 #endif 1247 #endif
1244 1248
1249 #if defined(OS_CHROMEOS)
1250 namespace {
1251
1252 internal::DisplayInfo CreateDisplayInfo(int64 id,
1253 int touch_device_id,
1254 const gfx::Rect& bounds) {
1255 internal::DisplayInfo info(id, "", false);
1256 info.SetBounds(bounds);
1257 info.set_touch_device_id(touch_device_id);
1258 return info;
1259 }
1260
1261 }
1262
1263 TEST_F(DisplayControllerTest, TouchCTMSingleTouchDisplay) {
1264 // Touch display.
1265 const internal::DisplayInfo touch_display_info =
1266 CreateDisplayInfo(1, 10, gfx::Rect(0, 0, 500, 500));
1267 std::vector<internal::DisplayInfo> display_info_list;
1268 display_info_list.push_back(touch_display_info);
1269 Shell::GetInstance()->display_manager()->OnNativeDisplaysChanged(
1270 display_info_list);
1271
1272 std::pair<int64, int64> display_ids =
1273 Shell::GetPrimaryRootWindow()->GetHost()->display_ids();
1274 EXPECT_EQ(1, display_ids.first);
1275 EXPECT_EQ(gfx::Display::kInvalidDisplayID, display_ids.second);
1276
1277 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance();
1278 EXPECT_EQ(1, device_manager->GetDisplayForTouchDevice(10));
1279
1280 // Single touch display has the default TouchCTM.
1281 float x = 100.0;
1282 float y = 100.0;
1283 device_manager->ApplyTouchCTM(10, &x, &y);
1284 EXPECT_EQ(100, x);
1285 EXPECT_EQ(100, y);
1286 }
1287
1288 TEST_F(DisplayControllerTest, TouchCTMMirrorModeLetterboxing) {
1289 // The internal display has native resolution of 2560x1700, and in
1290 // mirror mode it is configured as 1920x1200. This is in letterboxing
1291 // mode.
1292 internal::DisplayInfo internal_display_info =
1293 CreateDisplayInfo(1, 10, gfx::Rect(0, 0, 1920, 1200));
1294 std::vector<internal::DisplayMode> internal_modes;
1295 internal_modes.push_back(
1296 internal::DisplayMode(gfx::Size(2560, 1700), 60, false, true));
1297 internal_modes.push_back(
1298 internal::DisplayMode(gfx::Size(1920, 1200), 60, false, false));
1299 internal_display_info.set_display_modes(internal_modes);
1300
1301 internal::DisplayInfo external_display_info =
1302 CreateDisplayInfo(2, 11, gfx::Rect(0, 0, 1920, 1200));
1303
1304 gfx::Display::SetInternalDisplayId(1);
1305
1306 std::vector<internal::DisplayInfo> display_info_list;
1307 display_info_list.push_back(internal_display_info);
1308 display_info_list.push_back(external_display_info);
1309 Shell::GetInstance()->output_configurator()->set_output_state(
1310 ui::OUTPUT_STATE_DUAL_MIRROR);
1311 Shell::GetInstance()->display_manager()->OnNativeDisplaysChanged(
1312 display_info_list);
1313
1314 // In mirror mode, the root window host is associated with both
1315 // display ids.
1316 std::pair<int64, int64> display_ids =
1317 Shell::GetPrimaryRootWindow()->GetHost()->display_ids();
1318 EXPECT_EQ(1, display_ids.first);
1319 EXPECT_EQ(2, display_ids.second);
1320
1321 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance();
1322 EXPECT_EQ(1, device_manager->GetDisplayForTouchDevice(10));
1323 EXPECT_EQ(2, device_manager->GetDisplayForTouchDevice(11));
1324
1325 // External touch display has the default TouchCTM.
1326 float x = 100.0;
1327 float y = 100.0;
1328 device_manager->ApplyTouchCTM(11, &x, &y);
1329 EXPECT_EQ(100, x);
1330 EXPECT_EQ(100, y);
1331
1332 // In letterboxing, there is (1-2560*(1200/1920)/1700)/2 = 2.95% of the
1333 // height on both the top & bottom region of the screen is blank.
1334 // When touch events coming at Y range [0, 1200), the mapping should be
1335 // [0, ~35] ---> < 0
1336 // [~35, ~1165] ---> [0, 1200)
1337 // [~1165, 1200] ---> >= 1200
1338 x = 100.0;
1339 y = 35.0;
1340 device_manager->ApplyTouchCTM(10, &x, &y);
1341 EXPECT_EQ(100, x);
1342 EXPECT_EQ(0, abs(y - 0));
1343
1344 x = 100.0;
1345 y = 1165.0;
1346 device_manager->ApplyTouchCTM(10, &x, &y);
1347 EXPECT_EQ(100, x);
1348 EXPECT_EQ(0, abs(y - 1200));
1349 }
1350
1351 TEST_F(DisplayControllerTest, TouchCTMMirrorModePillarboxing) {
1352 // The internal display has native resolution of 1366x768, and in
1353 // mirror mode it is configured as 1024x768. This is in pillarboxing
1354 // mode.
1355 internal::DisplayInfo internal_display_info =
1356 CreateDisplayInfo(1, 10, gfx::Rect(0, 0, 1024, 768));
1357 std::vector<internal::DisplayMode> internal_modes;
1358 internal_modes.push_back(
1359 internal::DisplayMode(gfx::Size(1366, 768), 60, false, true));
1360 internal_modes.push_back(
1361 internal::DisplayMode(gfx::Size(1024, 768), 60, false, false));
1362 internal_display_info.set_display_modes(internal_modes);
1363
1364 internal::DisplayInfo external_display_info =
1365 CreateDisplayInfo(2, 11, gfx::Rect(0, 0, 1024, 768));
1366
1367 gfx::Display::SetInternalDisplayId(1);
1368
1369 std::vector<internal::DisplayInfo> display_info_list;
1370 display_info_list.push_back(internal_display_info);
1371 display_info_list.push_back(external_display_info);
1372 Shell::GetInstance()->output_configurator()->set_output_state(
1373 ui::OUTPUT_STATE_DUAL_MIRROR);
1374 Shell::GetInstance()->display_manager()->OnNativeDisplaysChanged(
1375 display_info_list);
1376
1377 // In mirror mode, the root window host is associated with both
1378 // display ids.
1379 std::pair<int64, int64> display_ids =
1380 Shell::GetPrimaryRootWindow()->GetHost()->display_ids();
1381 EXPECT_EQ(1, display_ids.first);
1382 EXPECT_EQ(2, display_ids.second);
1383
1384 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance();
1385 EXPECT_EQ(1, device_manager->GetDisplayForTouchDevice(10));
1386 EXPECT_EQ(2, device_manager->GetDisplayForTouchDevice(11));
1387
1388 // External touch display has the default TouchCTM.
1389 float x = 100.0;
1390 float y = 100.0;
1391 device_manager->ApplyTouchCTM(11, &x, &y);
1392 EXPECT_EQ(100, x);
1393 EXPECT_EQ(100, y);
1394
1395 // In pillarboxing, there is (1-768*(1024/768)/1366)/2 = 12.5% of the
1396 // width on both the left & rigth region of the screen is blank.
1397 // When touch events coming at X range [0, 1024), the mapping should be
1398 // [0, ~128] ---> < 0
1399 // [~128, ~896] ---> [0, 1024)
1400 // [~896, 1024] ---> >= 1024
1401 x = 128.0;
1402 y = 100.0;
1403 device_manager->ApplyTouchCTM(10, &x, &y);
1404 EXPECT_EQ(0, abs(x - 0));
1405 EXPECT_EQ(100, y);
1406
1407 x = 896.0;
1408 y = 100.0;
1409 device_manager->ApplyTouchCTM(10, &x, &y);
1410 EXPECT_EQ(0, abs(x - 1024));
1411 EXPECT_EQ(100, y);
1412 }
1413
1414 TEST_F(DisplayControllerTest, TouchCTMExtendedMode) {
1415 // The internal display has size 1366 x 768. The external display has
1416 // size 2560x1600. The total frame buffer is 2560x2428,
1417 // where 2428 = 768 + 60 (hidden gap) + 1600
1418 // and the sceond monitor is translated to Point (0, 828) in the
1419 // framebuffer.
1420 internal::DisplayInfo internal_display_info =
1421 CreateDisplayInfo(1, 10, gfx::Rect(0, 0, 1366, 768));
1422 internal::DisplayInfo external_display_info =
1423 CreateDisplayInfo(2, 11, gfx::Rect(0, 828, 2560, 1600));
1424
1425 std::vector<internal::DisplayInfo> display_info_list;
1426 display_info_list.push_back(internal_display_info);
1427 display_info_list.push_back(external_display_info);
1428 Shell::GetInstance()->output_configurator()->set_output_state(
1429 ui::OUTPUT_STATE_DUAL_EXTENDED);
1430 Shell::GetInstance()->display_manager()->OnNativeDisplaysChanged(
1431 display_info_list);
1432
1433 DisplayController* display_controller =
1434 Shell::GetInstance()->display_controller();
1435 aura::Window* primary = display_controller->GetRootWindowForDisplayId(1);
1436 std::pair<int64, int64> primary_display_ids =
1437 primary->GetHost()->display_ids();
1438 aura::Window* secondary = display_controller->GetRootWindowForDisplayId(2);
1439 std::pair<int64, int64> secondary_display_ids =
1440 secondary->GetHost()->display_ids();
1441 // The primary root window is associated with display ID 1.
1442 EXPECT_EQ(1, primary_display_ids.first);
1443 EXPECT_EQ(gfx::Display::kInvalidDisplayID, primary_display_ids.second);
1444 // The secondary root window is associated with display ID 2.
1445 EXPECT_EQ(2, secondary_display_ids.first);
1446 EXPECT_EQ(gfx::Display::kInvalidDisplayID, secondary_display_ids.second);
1447
1448
1449 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance();
1450 EXPECT_EQ(1, device_manager->GetDisplayForTouchDevice(10));
1451 EXPECT_EQ(2, device_manager->GetDisplayForTouchDevice(11));
1452
1453 // Mapping for touch events from internal touch display:
1454 // [0, 2560) x [0, 2428) -> [0, 1366) x [0, 768)
1455 float x = 0.0;
1456 float y = 0.0;
1457 device_manager->ApplyTouchCTM(10, &x, &y);
1458 EXPECT_EQ(0, x);
1459 EXPECT_EQ(0, y);
1460
1461 x = 2559.0;
1462 y = 2427.0;
1463 device_manager->ApplyTouchCTM(10, &x, &y);
1464 EXPECT_EQ(1365, x);
1465 EXPECT_EQ(767, y);
1466
1467 // Mapping for touch events from external touch display:
1468 // [0, 2560) x [0, 2428) -> [0, 2560) x [0, 1600)
1469 x = 0.0;
1470 y = 0.0;
1471 device_manager->ApplyTouchCTM(11, &x, &y);
1472 EXPECT_EQ(0, x);
1473 EXPECT_EQ(0, y);
1474
1475 x = 2559.0;
1476 y = 2427.0;
1477 device_manager->ApplyTouchCTM(11, &x, &y);
1478 EXPECT_EQ(2559, x);
1479 EXPECT_EQ(1599, y);
1480 }
1481
1482 #endif
1483
1245 } // namespace ash 1484 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698