| 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_manager.h" | 5 #include "ash/display/display_manager.h" |
| 6 | 6 |
| 7 #include "ash/display/display_controller.h" | 7 #include "ash/display/display_controller.h" |
| 8 #include "ash/screen_ash.h" | 8 #include "ash/screen_ash.h" |
| 9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
| 10 #include "ash/test/ash_test_base.h" | 10 #include "ash/test/ash_test_base.h" |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 const DisplayInfo& display_info1 = GetDisplayInfoAt(0); | 226 const DisplayInfo& display_info1 = GetDisplayInfoAt(0); |
| 227 const DisplayInfo& display_info2 = GetDisplayInfoAt(1); | 227 const DisplayInfo& display_info2 = GetDisplayInfoAt(1); |
| 228 display_manager()->SetOverscanInsets( | 228 display_manager()->SetOverscanInsets( |
| 229 display_info2.id(), gfx::Insets(13, 12, 11, 10)); | 229 display_info2.id(), gfx::Insets(13, 12, 11, 10)); |
| 230 | 230 |
| 231 std::vector<gfx::Display> changed_displays = changed(); | 231 std::vector<gfx::Display> changed_displays = changed(); |
| 232 EXPECT_EQ(1u, changed_displays.size()); | 232 EXPECT_EQ(1u, changed_displays.size()); |
| 233 EXPECT_EQ(display_info2.id(), changed_displays[0].id()); | 233 EXPECT_EQ(display_info2.id(), changed_displays[0].id()); |
| 234 EXPECT_EQ("0,0 500x500", | 234 EXPECT_EQ("0,0 500x500", |
| 235 GetDisplayInfoAt(0).bounds_in_pixel().ToString()); | 235 GetDisplayInfoAt(0).bounds_in_pixel().ToString()); |
| 236 EXPECT_EQ("12,514 378x376", | 236 DisplayInfo updated_display_info2 = GetDisplayInfoAt(1); |
| 237 GetDisplayInfoAt(1).bounds_in_pixel().ToString()); | 237 EXPECT_EQ("0,501 400x400", |
| 238 updated_display_info2.bounds_in_pixel().ToString()); |
| 239 EXPECT_EQ("378x376", |
| 240 updated_display_info2.size_in_pixel().ToString()); |
| 241 EXPECT_EQ("13,12,11,10", |
| 242 updated_display_info2.overscan_insets_in_dip().ToString()); |
| 243 EXPECT_EQ("500,0 378x376", |
| 244 ScreenAsh::GetSecondaryDisplay().bounds().ToString()); |
| 238 | 245 |
| 239 // Make sure that SetOverscanInsets() is idempotent. | 246 // Make sure that SetOverscanInsets() is idempotent. |
| 240 display_manager()->SetOverscanInsets(display_info1.id(), gfx::Insets()); | 247 display_manager()->SetOverscanInsets(display_info1.id(), gfx::Insets()); |
| 241 display_manager()->SetOverscanInsets( | 248 display_manager()->SetOverscanInsets( |
| 242 display_info2.id(), gfx::Insets(13, 12, 11, 10)); | 249 display_info2.id(), gfx::Insets(13, 12, 11, 10)); |
| 243 EXPECT_EQ("0,0 500x500", | 250 EXPECT_EQ("0,0 500x500", |
| 244 GetDisplayInfoAt(0).bounds_in_pixel().ToString()); | 251 GetDisplayInfoAt(0).bounds_in_pixel().ToString()); |
| 245 EXPECT_EQ("12,514 378x376", | 252 updated_display_info2 = GetDisplayInfoAt(1); |
| 246 GetDisplayInfoAt(1).bounds_in_pixel().ToString()); | 253 EXPECT_EQ("0,501 400x400", |
| 254 updated_display_info2.bounds_in_pixel().ToString()); |
| 255 EXPECT_EQ("378x376", |
| 256 updated_display_info2.size_in_pixel().ToString()); |
| 257 EXPECT_EQ("13,12,11,10", |
| 258 updated_display_info2.overscan_insets_in_dip().ToString()); |
| 247 | 259 |
| 248 display_manager()->SetOverscanInsets( | 260 display_manager()->SetOverscanInsets( |
| 249 display_info2.id(), gfx::Insets(10, 11, 12, 13)); | 261 display_info2.id(), gfx::Insets(10, 11, 12, 13)); |
| 250 EXPECT_EQ("0,0 500x500", | 262 EXPECT_EQ("0,0 500x500", |
| 251 GetDisplayInfoAt(0).bounds_in_pixel().ToString()); | 263 GetDisplayInfoAt(0).bounds_in_pixel().ToString()); |
| 252 EXPECT_EQ("11,511 376x378", | 264 EXPECT_EQ("376x378", |
| 253 GetDisplayInfoAt(1).bounds_in_pixel().ToString()); | 265 GetDisplayInfoAt(1).size_in_pixel().ToString()); |
| 266 EXPECT_EQ("10,11,12,13", |
| 267 GetDisplayInfoAt(1).overscan_insets_in_dip().ToString()); |
| 254 | 268 |
| 255 // Recreate a new 2nd display. It won't apply the overscan inset because the | 269 // Recreate a new 2nd display. It won't apply the overscan inset because the |
| 256 // new display has a different ID. | 270 // new display has a different ID. |
| 257 UpdateDisplay("0+0-500x500"); | 271 UpdateDisplay("0+0-500x500"); |
| 258 UpdateDisplay("0+0-500x500,0+501-400x400"); | 272 UpdateDisplay("0+0-500x500,0+501-400x400"); |
| 259 EXPECT_EQ("0,0 500x500", | 273 EXPECT_EQ("0,0 500x500", |
| 260 GetDisplayInfoAt(0).bounds_in_pixel().ToString()); | 274 GetDisplayInfoAt(0).bounds_in_pixel().ToString()); |
| 261 EXPECT_EQ("0,501 400x400", | 275 EXPECT_EQ("0,501 400x400", |
| 262 GetDisplayInfoAt(1).bounds_in_pixel().ToString()); | 276 GetDisplayInfoAt(1).bounds_in_pixel().ToString()); |
| 263 | 277 |
| 264 // Recreate the displays with the same ID. It should apply the overscan | 278 // Recreate the displays with the same ID. It should apply the overscan |
| 265 // inset. | 279 // inset. |
| 266 UpdateDisplay("0+0-500x500"); | 280 UpdateDisplay("0+0-500x500"); |
| 267 std::vector<DisplayInfo> display_info_list; | 281 std::vector<DisplayInfo> display_info_list; |
| 268 display_info_list.push_back(display_info1); | 282 display_info_list.push_back(display_info1); |
| 269 display_info_list.push_back(display_info2); | 283 display_info_list.push_back(display_info2); |
| 270 display_manager()->OnNativeDisplaysChanged(display_info_list); | 284 display_manager()->OnNativeDisplaysChanged(display_info_list); |
| 271 EXPECT_EQ("1,1 500x500", | 285 EXPECT_EQ("1,1 500x500", |
| 272 GetDisplayInfoAt(0).bounds_in_pixel().ToString()); | 286 GetDisplayInfoAt(0).bounds_in_pixel().ToString()); |
| 273 EXPECT_EQ("11,511 376x378", | 287 updated_display_info2 = GetDisplayInfoAt(1); |
| 274 GetDisplayInfoAt(1).bounds_in_pixel().ToString()); | 288 EXPECT_EQ("376x378", |
| 289 updated_display_info2.size_in_pixel().ToString()); |
| 290 EXPECT_EQ("10,11,12,13", |
| 291 updated_display_info2.overscan_insets_in_dip().ToString()); |
| 275 | 292 |
| 276 // HiDPI but overscan display. The specified insets size should be doubled. | 293 // HiDPI but overscan display. The specified insets size should be doubled. |
| 277 UpdateDisplay("0+0-500x500,0+501-400x400*2"); | 294 UpdateDisplay("0+0-500x500,0+501-400x400*2"); |
| 278 display_manager()->SetOverscanInsets( | 295 display_manager()->SetOverscanInsets( |
| 279 display_manager()->GetDisplayAt(1)->id(), gfx::Insets(4, 5, 6, 7)); | 296 display_manager()->GetDisplayAt(1)->id(), gfx::Insets(4, 5, 6, 7)); |
| 280 EXPECT_EQ("0,0 500x500", | 297 EXPECT_EQ("0,0 500x500", |
| 281 GetDisplayInfoAt(0).bounds_in_pixel().ToString()); | 298 GetDisplayInfoAt(0).bounds_in_pixel().ToString()); |
| 282 EXPECT_EQ("10,509 376x380", | 299 updated_display_info2 = GetDisplayInfoAt(1); |
| 283 GetDisplayInfoAt(1).bounds_in_pixel().ToString()); | 300 EXPECT_EQ("0,501 400x400", |
| 284 EXPECT_EQ("188x190", display_manager()->GetDisplayAt(1)->size().ToString()); | 301 updated_display_info2.bounds_in_pixel().ToString()); |
| 302 EXPECT_EQ("376x380", |
| 303 updated_display_info2.size_in_pixel().ToString()); |
| 304 EXPECT_EQ("4,5,6,7", |
| 305 updated_display_info2.overscan_insets_in_dip().ToString()); |
| 306 EXPECT_EQ("8,10,12,14", |
| 307 updated_display_info2.GetOverscanInsetsInPixel().ToString()); |
| 285 | 308 |
| 286 // Make sure switching primary display applies the overscan offset only once. | 309 // Make sure switching primary display applies the overscan offset only once. |
| 287 ash::Shell::GetInstance()->display_controller()->SetPrimaryDisplay( | 310 ash::Shell::GetInstance()->display_controller()->SetPrimaryDisplay( |
| 288 ScreenAsh::GetSecondaryDisplay()); | 311 ScreenAsh::GetSecondaryDisplay()); |
| 312 EXPECT_EQ("-500,0 500x500", |
| 313 ScreenAsh::GetSecondaryDisplay().bounds().ToString()); |
| 289 EXPECT_EQ("0,0 500x500", | 314 EXPECT_EQ("0,0 500x500", |
| 290 GetDisplayInfo(ScreenAsh::GetSecondaryDisplay()). | 315 GetDisplayInfo(ScreenAsh::GetSecondaryDisplay()). |
| 291 bounds_in_pixel().ToString()); | 316 bounds_in_pixel().ToString()); |
| 292 EXPECT_EQ("10,509 376x380", | 317 EXPECT_EQ("0,501 400x400", |
| 293 GetDisplayInfo(gfx::Screen::GetNativeScreen()->GetPrimaryDisplay()). | 318 GetDisplayInfo(gfx::Screen::GetNativeScreen()->GetPrimaryDisplay()). |
| 294 bounds_in_pixel().ToString()); | 319 bounds_in_pixel().ToString()); |
| 320 EXPECT_EQ("0,0 188x190", |
| 321 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().bounds() |
| 322 .ToString()); |
| 295 } | 323 } |
| 296 | 324 |
| 297 TEST_F(DisplayManagerTest, ZeroOverscanInsets) { | 325 TEST_F(DisplayManagerTest, ZeroOverscanInsets) { |
| 298 // Make sure the display change events is emitted for overscan inset changes. | 326 // Make sure the display change events is emitted for overscan inset changes. |
| 299 UpdateDisplay("0+0-500x500,0+501-400x400"); | 327 UpdateDisplay("0+0-500x500,0+501-400x400"); |
| 300 ASSERT_EQ(2u, display_manager()->GetNumDisplays()); | 328 ASSERT_EQ(2u, display_manager()->GetNumDisplays()); |
| 301 int64 display2_id = display_manager()->GetDisplayAt(1)->id(); | 329 int64 display2_id = display_manager()->GetDisplayAt(1)->id(); |
| 302 | 330 |
| 303 reset(); | 331 reset(); |
| 304 display_manager()->SetOverscanInsets(display2_id, gfx::Insets(0, 0, 0, 0)); | 332 display_manager()->SetOverscanInsets(display2_id, gfx::Insets(0, 0, 0, 0)); |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 557 UpdateDisplay("200x200,400x400"); | 585 UpdateDisplay("200x200,400x400"); |
| 558 | 586 |
| 559 std::vector<DisplayInfo> display_info_list; | 587 std::vector<DisplayInfo> display_info_list; |
| 560 display_info_list.push_back(GetDisplayInfoAt(0)); | 588 display_info_list.push_back(GetDisplayInfoAt(0)); |
| 561 display_info_list.push_back(GetDisplayInfoAt(1)); | 589 display_info_list.push_back(GetDisplayInfoAt(1)); |
| 562 display_info_list[1].set_has_overscan_for_test(true); | 590 display_info_list[1].set_has_overscan_for_test(true); |
| 563 int64 id = display_info_list[1].id(); | 591 int64 id = display_info_list[1].id(); |
| 564 // SetDefaultOverscanInsets(&display_info_list[1]); | 592 // SetDefaultOverscanInsets(&display_info_list[1]); |
| 565 display_manager()->OnNativeDisplaysChanged(display_info_list); | 593 display_manager()->OnNativeDisplaysChanged(display_info_list); |
| 566 // It has overscan insets, although SetOverscanInsets() isn't called. | 594 // It has overscan insets, although SetOverscanInsets() isn't called. |
| 567 EXPECT_EQ("11,211 380x380", | 595 EXPECT_EQ("380x380", |
| 568 GetDisplayInfoAt(1).bounds_in_pixel().ToString()); | 596 GetDisplayInfoAt(1).size_in_pixel().ToString()); |
| 569 | 597 |
| 570 // If custom overscan insets is specified, the specified value is used. | 598 // If custom overscan insets is specified, the specified value is used. |
| 571 display_manager()->SetOverscanInsets(id, gfx::Insets(5, 6, 7, 8)); | 599 display_manager()->SetOverscanInsets(id, gfx::Insets(5, 6, 7, 8)); |
| 572 display_manager()->OnNativeDisplaysChanged(display_info_list); | 600 display_manager()->OnNativeDisplaysChanged(display_info_list); |
| 573 EXPECT_EQ("7,206 386x388", | 601 EXPECT_EQ("386x388", |
| 574 GetDisplayInfoAt(1).bounds_in_pixel().ToString()); | 602 GetDisplayInfoAt(1).size_in_pixel().ToString()); |
| 575 | 603 |
| 576 // Do not overscan even though it has 'has_overscan' flag, if the custom | 604 // Do not overscan even though it has 'has_overscan' flag, if the custom |
| 577 // insets is empty. | 605 // insets is empty. |
| 578 display_manager()->SetOverscanInsets(id, gfx::Insets()); | 606 display_manager()->SetOverscanInsets(id, gfx::Insets()); |
| 579 display_manager()->OnNativeDisplaysChanged(display_info_list); | 607 display_manager()->OnNativeDisplaysChanged(display_info_list); |
| 580 EXPECT_EQ("1,201 400x400", | 608 EXPECT_EQ("400x400", |
| 581 GetDisplayInfoAt(1).bounds_in_pixel().ToString()); | 609 GetDisplayInfoAt(1).size_in_pixel().ToString()); |
| 582 | 610 |
| 583 // Clearing the custom overscan should set the bounds to | 611 // Clearing the custom overscan should set the bounds to |
| 584 // original. | 612 // original. |
| 585 display_manager()->ClearCustomOverscanInsets(id); | 613 display_manager()->ClearCustomOverscanInsets(id); |
| 586 EXPECT_EQ("11,211 380x380", | 614 EXPECT_EQ("380x380", |
| 615 GetDisplayInfoAt(1).size_in_pixel().ToString()); |
| 616 } |
| 617 |
| 618 TEST_F(DisplayManagerTest, Rotate) { |
| 619 UpdateDisplay("100x200/r,300x400/l"); |
| 620 EXPECT_EQ("1,1 100x200", |
| 621 GetDisplayInfoAt(0).bounds_in_pixel().ToString()); |
| 622 EXPECT_EQ("200x100", |
| 623 GetDisplayInfoAt(0).size_in_pixel().ToString()); |
| 624 |
| 625 EXPECT_EQ("1,201 300x400", |
| 587 GetDisplayInfoAt(1).bounds_in_pixel().ToString()); | 626 GetDisplayInfoAt(1).bounds_in_pixel().ToString()); |
| 627 EXPECT_EQ("400x300", |
| 628 GetDisplayInfoAt(1).size_in_pixel().ToString()); |
| 629 UpdateDisplay("100x200/b,300x400"); |
| 630 EXPECT_EQ("1,1 100x200", |
| 631 GetDisplayInfoAt(0).bounds_in_pixel().ToString()); |
| 632 EXPECT_EQ("100x200", |
| 633 GetDisplayInfoAt(0).size_in_pixel().ToString()); |
| 634 |
| 635 EXPECT_EQ("1,201 300x400", |
| 636 GetDisplayInfoAt(1).bounds_in_pixel().ToString()); |
| 637 EXPECT_EQ("300x400", |
| 638 GetDisplayInfoAt(1).size_in_pixel().ToString()); |
| 588 } | 639 } |
| 589 | 640 |
| 590 } // namespace internal | 641 } // namespace internal |
| 591 } // namespace ash | 642 } // namespace ash |
| OLD | NEW |