| 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 "chrome/browser/chromeos/display/display_preferences.h" | 5 #include "chrome/browser/chromeos/display/display_preferences.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 using ash::ResolutionNotificationController; | 44 using ash::ResolutionNotificationController; |
| 45 | 45 |
| 46 namespace chromeos { | 46 namespace chromeos { |
| 47 namespace { | 47 namespace { |
| 48 const char kPrimaryIdKey[] = "primary-id"; | 48 const char kPrimaryIdKey[] = "primary-id"; |
| 49 const char kMirroredKey[] = "mirrored"; | 49 const char kMirroredKey[] = "mirrored"; |
| 50 const char kPositionKey[] = "position"; | 50 const char kPositionKey[] = "position"; |
| 51 const char kOffsetKey[] = "offset"; | 51 const char kOffsetKey[] = "offset"; |
| 52 const char kPlacementDisplayIdKey[] = "placement.display_id"; | 52 const char kPlacementDisplayIdKey[] = "placement.display_id"; |
| 53 const char kPlacementParentDisplayIdKey[] = "placement.parent_display_id"; | 53 const char kPlacementParentDisplayIdKey[] = "placement.parent_display_id"; |
| 54 const char kTouchCalibrationWidth[] = "touch_calibration_width"; |
| 55 const char kTouchCalibrationHeight[] = "touch_calibration_height"; |
| 56 const char* kTouchCalibrationDataKeys[] = { |
| 57 "display_1_x", "display_1_y", "touch_1_x", "touch_1_y", // Pair 1 |
| 58 "display_2_x", "display_2_y", "touch_2_x", "touch_2_y", // Pair 2 |
| 59 "display_3_x", "display_3_y", "touch_3_x", "touch_3_y", // Pair 3 |
| 60 "display_4_x", "display_4_y", "touch_4_x", "touch_4_y" // Pair 4 |
| 61 }; |
| 54 | 62 |
| 55 // The mean acceleration due to gravity on Earth in m/s^2. | 63 // The mean acceleration due to gravity on Earth in m/s^2. |
| 56 const float kMeanGravity = -9.80665f; | 64 const float kMeanGravity = -9.80665f; |
| 57 | 65 |
| 58 bool IsRotationLocked() { | 66 bool IsRotationLocked() { |
| 59 return ash::Shell::GetInstance() | 67 return ash::Shell::GetInstance() |
| 60 ->screen_orientation_controller() | 68 ->screen_orientation_controller() |
| 61 ->rotation_locked(); | 69 ->rotation_locked(); |
| 62 } | 70 } |
| 63 | 71 |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 EXPECT_NE(dummy_id, display::Screen::GetScreen()->GetPrimaryDisplay().id()); | 308 EXPECT_NE(dummy_id, display::Screen::GetScreen()->GetPrimaryDisplay().id()); |
| 301 | 309 |
| 302 window_tree_host_manager->SetOverscanInsets(id1, gfx::Insets(10, 11, 12, 13)); | 310 window_tree_host_manager->SetOverscanInsets(id1, gfx::Insets(10, 11, 12, 13)); |
| 303 display_manager()->SetDisplayRotation(id1, display::Display::ROTATE_90, | 311 display_manager()->SetDisplayRotation(id1, display::Display::ROTATE_90, |
| 304 display::Display::ROTATION_SOURCE_USER); | 312 display::Display::ROTATION_SOURCE_USER); |
| 305 EXPECT_TRUE(display::test::DisplayManagerTestApi(display_manager()) | 313 EXPECT_TRUE(display::test::DisplayManagerTestApi(display_manager()) |
| 306 .SetDisplayUIScale(id1, 1.25f)); | 314 .SetDisplayUIScale(id1, 1.25f)); |
| 307 EXPECT_FALSE(display::test::DisplayManagerTestApi(display_manager()) | 315 EXPECT_FALSE(display::test::DisplayManagerTestApi(display_manager()) |
| 308 .SetDisplayUIScale(id2, 1.25f)); | 316 .SetDisplayUIScale(id2, 1.25f)); |
| 309 | 317 |
| 318 // Set touch calibration data for display |id2|. |
| 319 display::TouchCalibrationData::CalibrationPointPairQuad point_pair_quad = { |
| 320 {std::make_pair(gfx::Point(10, 10), gfx::Point(11, 12)), |
| 321 std::make_pair(gfx::Point(190, 10), gfx::Point(195, 8)), |
| 322 std::make_pair(gfx::Point(10, 90), gfx::Point(12, 94)), |
| 323 std::make_pair(gfx::Point(190, 90), gfx::Point(189, 88))}}; |
| 324 gfx::Size touch_size(200, 150); |
| 325 display_manager()->SetTouchCalibrationData(id2, point_pair_quad, touch_size); |
| 326 |
| 310 const base::DictionaryValue* displays = | 327 const base::DictionaryValue* displays = |
| 311 local_state()->GetDictionary(prefs::kSecondaryDisplays); | 328 local_state()->GetDictionary(prefs::kSecondaryDisplays); |
| 312 const base::DictionaryValue* layout_value = nullptr; | 329 const base::DictionaryValue* layout_value = nullptr; |
| 313 std::string key = base::Int64ToString(id1) + "," + base::Int64ToString(id2); | 330 std::string key = base::Int64ToString(id1) + "," + base::Int64ToString(id2); |
| 314 std::string dummy_key = | 331 std::string dummy_key = |
| 315 base::Int64ToString(id1) + "," + base::Int64ToString(dummy_id); | 332 base::Int64ToString(id1) + "," + base::Int64ToString(dummy_id); |
| 316 EXPECT_TRUE(displays->GetDictionary(dummy_key, &layout_value)); | 333 EXPECT_TRUE(displays->GetDictionary(dummy_key, &layout_value)); |
| 317 | 334 |
| 318 display::DisplayLayout stored_layout; | 335 display::DisplayLayout stored_layout; |
| 319 EXPECT_TRUE(ash::JsonToDisplayLayout(*layout_value, &stored_layout)); | 336 EXPECT_TRUE(ash::JsonToDisplayLayout(*layout_value, &stored_layout)); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 347 int top = 0, left = 0, bottom = 0, right = 0; | 364 int top = 0, left = 0, bottom = 0, right = 0; |
| 348 EXPECT_TRUE(property->GetInteger("insets_top", &top)); | 365 EXPECT_TRUE(property->GetInteger("insets_top", &top)); |
| 349 EXPECT_TRUE(property->GetInteger("insets_left", &left)); | 366 EXPECT_TRUE(property->GetInteger("insets_left", &left)); |
| 350 EXPECT_TRUE(property->GetInteger("insets_bottom", &bottom)); | 367 EXPECT_TRUE(property->GetInteger("insets_bottom", &bottom)); |
| 351 EXPECT_TRUE(property->GetInteger("insets_right", &right)); | 368 EXPECT_TRUE(property->GetInteger("insets_right", &right)); |
| 352 EXPECT_EQ(10, top); | 369 EXPECT_EQ(10, top); |
| 353 EXPECT_EQ(11, left); | 370 EXPECT_EQ(11, left); |
| 354 EXPECT_EQ(12, bottom); | 371 EXPECT_EQ(12, bottom); |
| 355 EXPECT_EQ(13, right); | 372 EXPECT_EQ(13, right); |
| 356 | 373 |
| 374 int x, y; |
| 375 for (std::size_t row = 0; row < point_pair_quad.size(); row++) { |
| 376 EXPECT_FALSE(property->GetInteger(kTouchCalibrationDataKeys[row * 4], &x)); |
| 377 EXPECT_FALSE( |
| 378 property->GetInteger(kTouchCalibrationDataKeys[row * 4 + 1], &y)); |
| 379 EXPECT_FALSE( |
| 380 property->GetInteger(kTouchCalibrationDataKeys[row * 4 + 2], &x)); |
| 381 EXPECT_FALSE( |
| 382 property->GetInteger(kTouchCalibrationDataKeys[row * 4 + 3], &y)); |
| 383 } |
| 384 EXPECT_FALSE(property->GetInteger(kTouchCalibrationWidth, &width)); |
| 385 EXPECT_FALSE(property->GetInteger(kTouchCalibrationHeight, &height)); |
| 386 |
| 357 std::string color_profile; | 387 std::string color_profile; |
| 358 EXPECT_TRUE(property->GetString("color_profile_name", &color_profile)); | 388 EXPECT_TRUE(property->GetString("color_profile_name", &color_profile)); |
| 359 EXPECT_EQ("dynamic", color_profile); | 389 EXPECT_EQ("dynamic", color_profile); |
| 360 | 390 |
| 361 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id2), &property)); | 391 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id2), &property)); |
| 362 EXPECT_TRUE(property->GetInteger("rotation", &rotation)); | 392 EXPECT_TRUE(property->GetInteger("rotation", &rotation)); |
| 363 EXPECT_TRUE(property->GetInteger("ui-scale", &ui_scale)); | 393 EXPECT_TRUE(property->GetInteger("ui-scale", &ui_scale)); |
| 364 EXPECT_EQ(0, rotation); | 394 EXPECT_EQ(0, rotation); |
| 365 // ui_scale works only on 2x scale factor/1st display. | 395 // ui_scale works only on 2x scale factor/1st display. |
| 366 EXPECT_EQ(1000, ui_scale); | 396 EXPECT_EQ(1000, ui_scale); |
| 367 EXPECT_FALSE(property->GetInteger("insets_top", &top)); | 397 EXPECT_FALSE(property->GetInteger("insets_top", &top)); |
| 368 EXPECT_FALSE(property->GetInteger("insets_left", &left)); | 398 EXPECT_FALSE(property->GetInteger("insets_left", &left)); |
| 369 EXPECT_FALSE(property->GetInteger("insets_bottom", &bottom)); | 399 EXPECT_FALSE(property->GetInteger("insets_bottom", &bottom)); |
| 370 EXPECT_FALSE(property->GetInteger("insets_right", &right)); | 400 EXPECT_FALSE(property->GetInteger("insets_right", &right)); |
| 371 | 401 |
| 402 for (std::size_t row = 0; row < point_pair_quad.size(); row++) { |
| 403 EXPECT_TRUE(property->GetInteger(kTouchCalibrationDataKeys[row * 4], &x)); |
| 404 EXPECT_TRUE( |
| 405 property->GetInteger(kTouchCalibrationDataKeys[row * 4 + 1], &y)); |
| 406 EXPECT_EQ(point_pair_quad[row].first.x(), x); |
| 407 EXPECT_EQ(point_pair_quad[row].first.y(), y); |
| 408 |
| 409 EXPECT_TRUE( |
| 410 property->GetInteger(kTouchCalibrationDataKeys[row * 4 + 2], &x)); |
| 411 EXPECT_TRUE( |
| 412 property->GetInteger(kTouchCalibrationDataKeys[row * 4 + 3], &y)); |
| 413 EXPECT_EQ(point_pair_quad[row].second.x(), x); |
| 414 EXPECT_EQ(point_pair_quad[row].second.y(), y); |
| 415 } |
| 416 width = height = 0; |
| 417 EXPECT_TRUE(property->GetInteger(kTouchCalibrationWidth, &width)); |
| 418 EXPECT_TRUE(property->GetInteger(kTouchCalibrationHeight, &height)); |
| 419 EXPECT_EQ(width, touch_size.width()); |
| 420 EXPECT_EQ(height, touch_size.height()); |
| 421 |
| 372 // |id2| doesn't have the color_profile because it doesn't have 'dynamic' in | 422 // |id2| doesn't have the color_profile because it doesn't have 'dynamic' in |
| 373 // its available list. | 423 // its available list. |
| 374 EXPECT_FALSE(property->GetString("color_profile_name", &color_profile)); | 424 EXPECT_FALSE(property->GetString("color_profile_name", &color_profile)); |
| 375 | 425 |
| 376 // Resolution is saved only when the resolution is set | 426 // Resolution is saved only when the resolution is set |
| 377 // by DisplayManager::SetDisplayMode | 427 // by DisplayManager::SetDisplayMode |
| 378 width = 0; | 428 width = 0; |
| 379 height = 0; | 429 height = 0; |
| 380 EXPECT_FALSE(property->GetInteger("width", &width)); | 430 EXPECT_FALSE(property->GetInteger("width", &width)); |
| 381 EXPECT_FALSE(property->GetInteger("height", &height)); | 431 EXPECT_FALSE(property->GetInteger("height", &height)); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 // by mirroring. | 516 // by mirroring. |
| 467 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id2), &property)); | 517 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id2), &property)); |
| 468 EXPECT_TRUE(property->GetInteger("width", &width)); | 518 EXPECT_TRUE(property->GetInteger("width", &width)); |
| 469 EXPECT_TRUE(property->GetInteger("height", &height)); | 519 EXPECT_TRUE(property->GetInteger("height", &height)); |
| 470 EXPECT_EQ(300, width); | 520 EXPECT_EQ(300, width); |
| 471 EXPECT_EQ(200, height); | 521 EXPECT_EQ(200, height); |
| 472 | 522 |
| 473 // Set new display's selected resolution. | 523 // Set new display's selected resolution. |
| 474 display_manager()->RegisterDisplayProperty( | 524 display_manager()->RegisterDisplayProperty( |
| 475 id2 + 1, display::Display::ROTATE_0, 1.0f, nullptr, gfx::Size(500, 400), | 525 id2 + 1, display::Display::ROTATE_0, 1.0f, nullptr, gfx::Size(500, 400), |
| 476 1.0f, ui::COLOR_PROFILE_STANDARD); | 526 1.0f, ui::COLOR_PROFILE_STANDARD, nullptr); |
| 477 | 527 |
| 478 UpdateDisplay("200x200*2, 600x500#600x500|500x400"); | 528 UpdateDisplay("200x200*2, 600x500#600x500|500x400"); |
| 479 | 529 |
| 480 // Update key as the 2nd display gets new id. | 530 // Update key as the 2nd display gets new id. |
| 481 id2 = display_manager()->GetSecondaryDisplay().id(); | 531 id2 = display_manager()->GetSecondaryDisplay().id(); |
| 482 key = base::Int64ToString(id1) + "," + base::Int64ToString(id2); | 532 key = base::Int64ToString(id1) + "," + base::Int64ToString(id2); |
| 483 EXPECT_TRUE(displays->GetDictionary(key, &layout_value)); | 533 EXPECT_TRUE(displays->GetDictionary(key, &layout_value)); |
| 484 EXPECT_TRUE(layout_value->GetString(kPositionKey, &position)); | 534 EXPECT_TRUE(layout_value->GetString(kPositionKey, &position)); |
| 485 EXPECT_EQ("right", position); | 535 EXPECT_EQ("right", position); |
| 486 EXPECT_TRUE(layout_value->GetInteger(kOffsetKey, &offset)); | 536 EXPECT_TRUE(layout_value->GetInteger(kOffsetKey, &offset)); |
| 487 EXPECT_EQ(0, offset); | 537 EXPECT_EQ(0, offset); |
| 488 mirrored = true; | 538 mirrored = true; |
| 489 EXPECT_TRUE(layout_value->GetBoolean(kMirroredKey, &mirrored)); | 539 EXPECT_TRUE(layout_value->GetBoolean(kMirroredKey, &mirrored)); |
| 490 EXPECT_FALSE(mirrored); | 540 EXPECT_FALSE(mirrored); |
| 491 EXPECT_TRUE(layout_value->GetString(kPrimaryIdKey, &primary_id_str)); | 541 EXPECT_TRUE(layout_value->GetString(kPrimaryIdKey, &primary_id_str)); |
| 492 EXPECT_EQ(base::Int64ToString(id1), primary_id_str); | 542 EXPECT_EQ(base::Int64ToString(id1), primary_id_str); |
| 493 | 543 |
| 494 // Best resolution should not be saved. | 544 // Best resolution should not be saved. |
| 495 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id2), &property)); | 545 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id2), &property)); |
| 496 EXPECT_FALSE(property->GetInteger("width", &width)); | 546 EXPECT_FALSE(property->GetInteger("width", &width)); |
| 497 EXPECT_FALSE(property->GetInteger("height", &height)); | 547 EXPECT_FALSE(property->GetInteger("height", &height)); |
| 498 | 548 |
| 499 // Set yet another new display's selected resolution. | 549 // Set yet another new display's selected resolution. |
| 500 display_manager()->RegisterDisplayProperty( | 550 display_manager()->RegisterDisplayProperty( |
| 501 id2 + 1, display::Display::ROTATE_0, 1.0f, nullptr, gfx::Size(500, 400), | 551 id2 + 1, display::Display::ROTATE_0, 1.0f, nullptr, gfx::Size(500, 400), |
| 502 1.0f, ui::COLOR_PROFILE_STANDARD); | 552 1.0f, ui::COLOR_PROFILE_STANDARD, nullptr); |
| 503 // Disconnect 2nd display first to generate new id for external display. | 553 // Disconnect 2nd display first to generate new id for external display. |
| 504 UpdateDisplay("200x200*2"); | 554 UpdateDisplay("200x200*2"); |
| 505 UpdateDisplay("200x200*2, 500x400#600x500|500x400%60.0f"); | 555 UpdateDisplay("200x200*2, 500x400#600x500|500x400%60.0f"); |
| 506 // Update key as the 2nd display gets new id. | 556 // Update key as the 2nd display gets new id. |
| 507 id2 = display_manager()->GetSecondaryDisplay().id(); | 557 id2 = display_manager()->GetSecondaryDisplay().id(); |
| 508 key = base::Int64ToString(id1) + "," + base::Int64ToString(id2); | 558 key = base::Int64ToString(id1) + "," + base::Int64ToString(id2); |
| 509 EXPECT_TRUE(displays->GetDictionary(key, &layout_value)); | 559 EXPECT_TRUE(displays->GetDictionary(key, &layout_value)); |
| 510 EXPECT_TRUE(layout_value->GetString(kPositionKey, &position)); | 560 EXPECT_TRUE(layout_value->GetString(kPositionKey, &position)); |
| 511 EXPECT_EQ("right", position); | 561 EXPECT_EQ("right", position); |
| 512 EXPECT_TRUE(layout_value->GetInteger(kOffsetKey, &offset)); | 562 EXPECT_TRUE(layout_value->GetInteger(kOffsetKey, &offset)); |
| (...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1118 | 1168 |
| 1119 EXPECT_EQ(gfx::Rect(0, 0, 200, 200), | 1169 EXPECT_EQ(gfx::Rect(0, 0, 200, 200), |
| 1120 display_manager()->GetDisplayForId(list[0]).bounds()); | 1170 display_manager()->GetDisplayForId(list[0]).bounds()); |
| 1121 EXPECT_EQ(gfx::Rect(-200, 0, 200, 200), | 1171 EXPECT_EQ(gfx::Rect(-200, 0, 200, 200), |
| 1122 display_manager()->GetDisplayForId(list[1]).bounds()); | 1172 display_manager()->GetDisplayForId(list[1]).bounds()); |
| 1123 EXPECT_EQ(gfx::Rect(-100, 200, 300, 300), | 1173 EXPECT_EQ(gfx::Rect(-100, 200, 300, 300), |
| 1124 display_manager()->GetDisplayForId(list[2]).bounds()); | 1174 display_manager()->GetDisplayForId(list[2]).bounds()); |
| 1125 } | 1175 } |
| 1126 | 1176 |
| 1127 } // namespace chromeos | 1177 } // namespace chromeos |
| OLD | NEW |