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/display/display_layout_store.h" | 8 #include "ash/display/display_layout_store.h" |
9 #include "ash/screen_util.h" | 9 #include "ash/screen_util.h" |
10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
(...skipping 718 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
729 display_modes.push_back( | 729 display_modes.push_back( |
730 DisplayMode(gfx::Size(400, 500), 60.0f, false, false)); | 730 DisplayMode(gfx::Size(400, 500), 60.0f, false, false)); |
731 | 731 |
732 native_display_info.set_display_modes(display_modes); | 732 native_display_info.set_display_modes(display_modes); |
733 | 733 |
734 std::vector<DisplayInfo> display_info_list; | 734 std::vector<DisplayInfo> display_info_list; |
735 display_info_list.push_back(native_display_info); | 735 display_info_list.push_back(native_display_info); |
736 display_manager()->OnNativeDisplaysChanged(display_info_list); | 736 display_manager()->OnNativeDisplaysChanged(display_info_list); |
737 | 737 |
738 DisplayMode mode; | 738 DisplayMode mode; |
| 739 DisplayMode expected_mode; |
| 740 expected_mode.size = gfx::Size(1000, 500); |
739 EXPECT_FALSE( | 741 EXPECT_FALSE( |
740 display_manager()->GetSelectedModeForDisplayId(display_id, &mode)); | 742 display_manager()->GetSelectedModeForDisplayId(display_id, &mode)); |
| 743 EXPECT_TRUE(expected_mode.IsEquivalent( |
| 744 display_manager()->GetActiveModeForDisplayId(display_id))); |
741 | 745 |
742 // Unsupported resolution. | 746 // Unsupported resolution. |
743 display_manager()->SetDisplayResolution(display_id, gfx::Size(800, 4000)); | 747 display_manager()->SetDisplayResolution(display_id, gfx::Size(800, 4000)); |
744 EXPECT_FALSE( | 748 EXPECT_FALSE( |
745 display_manager()->GetSelectedModeForDisplayId(display_id, &mode)); | 749 display_manager()->GetSelectedModeForDisplayId(display_id, &mode)); |
| 750 EXPECT_TRUE(expected_mode.IsEquivalent( |
| 751 display_manager()->GetActiveModeForDisplayId(display_id))); |
746 | 752 |
747 // Supported resolution. | 753 // Supported resolution. |
748 display_manager()->SetDisplayResolution(display_id, gfx::Size(800, 300)); | 754 display_manager()->SetDisplayResolution(display_id, gfx::Size(800, 300)); |
749 EXPECT_TRUE( | 755 EXPECT_TRUE( |
750 display_manager()->GetSelectedModeForDisplayId(display_id, &mode)); | 756 display_manager()->GetSelectedModeForDisplayId(display_id, &mode)); |
751 EXPECT_EQ("800x300", mode.size.ToString()); | 757 EXPECT_EQ("800x300", mode.size.ToString()); |
752 EXPECT_EQ(59.0f, mode.refresh_rate); | 758 EXPECT_EQ(59.0f, mode.refresh_rate); |
753 EXPECT_FALSE(mode.native); | 759 EXPECT_FALSE(mode.native); |
| 760 expected_mode.size = gfx::Size(800, 300); |
| 761 EXPECT_TRUE(expected_mode.IsEquivalent( |
| 762 display_manager()->GetActiveModeForDisplayId(display_id))); |
754 | 763 |
755 // Best resolution. | 764 // Best resolution. |
756 display_manager()->SetDisplayResolution(display_id, gfx::Size(1000, 500)); | 765 display_manager()->SetDisplayResolution(display_id, gfx::Size(1000, 500)); |
757 EXPECT_TRUE( | 766 EXPECT_TRUE( |
758 display_manager()->GetSelectedModeForDisplayId(display_id, &mode)); | 767 display_manager()->GetSelectedModeForDisplayId(display_id, &mode)); |
759 EXPECT_EQ("1000x500", mode.size.ToString()); | 768 EXPECT_EQ("1000x500", mode.size.ToString()); |
760 EXPECT_EQ(58.0f, mode.refresh_rate); | 769 EXPECT_EQ(58.0f, mode.refresh_rate); |
761 EXPECT_TRUE(mode.native); | 770 EXPECT_TRUE(mode.native); |
| 771 expected_mode.size = gfx::Size(1000, 500); |
| 772 EXPECT_TRUE(expected_mode.IsEquivalent( |
| 773 display_manager()->GetActiveModeForDisplayId(display_id))); |
762 } | 774 } |
763 | 775 |
764 TEST_F(DisplayManagerTest, ResolutionFallback) { | 776 TEST_F(DisplayManagerTest, ResolutionFallback) { |
765 int display_id = 1000; | 777 int display_id = 1000; |
766 DisplayInfo native_display_info = | 778 DisplayInfo native_display_info = |
767 CreateDisplayInfo(display_id, gfx::Rect(0, 0, 1000, 500)); | 779 CreateDisplayInfo(display_id, gfx::Rect(0, 0, 1000, 500)); |
768 std::vector<DisplayMode> display_modes; | 780 std::vector<DisplayMode> display_modes; |
769 display_modes.push_back( | 781 display_modes.push_back( |
770 DisplayMode(gfx::Size(1000, 500), 58.0f, false, true)); | 782 DisplayMode(gfx::Size(1000, 500), 58.0f, false, true)); |
771 display_modes.push_back( | 783 display_modes.push_back( |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
958 // on screen. | 970 // on screen. |
959 UpdateDisplay("1280x850*1.25"); | 971 UpdateDisplay("1280x850*1.25"); |
960 display_manager()->SetDisplayUIScale(display_id, 1.25f); | 972 display_manager()->SetDisplayUIScale(display_id, 1.25f); |
961 EXPECT_EQ(1.25f, GetDisplayInfoAt(0).configured_ui_scale()); | 973 EXPECT_EQ(1.25f, GetDisplayInfoAt(0).configured_ui_scale()); |
962 EXPECT_EQ(1.0f, GetDisplayInfoAt(0).GetEffectiveUIScale()); | 974 EXPECT_EQ(1.0f, GetDisplayInfoAt(0).GetEffectiveUIScale()); |
963 display = Shell::GetScreen()->GetPrimaryDisplay(); | 975 display = Shell::GetScreen()->GetPrimaryDisplay(); |
964 EXPECT_EQ(1.0f, display.device_scale_factor()); | 976 EXPECT_EQ(1.0f, display.device_scale_factor()); |
965 EXPECT_EQ("1280x850", display.bounds().size().ToString()); | 977 EXPECT_EQ("1280x850", display.bounds().size().ToString()); |
966 } | 978 } |
967 | 979 |
| 980 TEST_F(DisplayManagerTest, UIScaleWithDisplayMode) { |
| 981 int display_id = 1000; |
| 982 |
| 983 // Setup the display modes with UI-scale. |
| 984 DisplayInfo native_display_info = |
| 985 CreateDisplayInfo(display_id, gfx::Rect(0, 0, 1280, 800)); |
| 986 std::vector<DisplayMode> display_modes; |
| 987 const DisplayMode base_mode(gfx::Size(1280, 800), 60.0f, false, false); |
| 988 std::vector<float> scales = |
| 989 DisplayManager::GetScalesForDisplay(native_display_info); |
| 990 for (size_t i = 0; i < scales.size(); i++) { |
| 991 DisplayMode mode = base_mode; |
| 992 mode.ui_scale = scales[i]; |
| 993 mode.native = (scales[i] == 1.0f); |
| 994 display_modes.push_back(mode); |
| 995 } |
| 996 native_display_info.set_display_modes(display_modes); |
| 997 std::vector<DisplayInfo> display_info_list; |
| 998 display_info_list.push_back(native_display_info); |
| 999 display_manager()->OnNativeDisplaysChanged(display_info_list); |
| 1000 |
| 1001 DisplayMode expected_mode = base_mode; |
| 1002 EXPECT_TRUE(expected_mode.IsEquivalent( |
| 1003 display_manager()->GetActiveModeForDisplayId(display_id))); |
| 1004 |
| 1005 display_manager()->SetDisplayUIScale(display_id, 1.125f); |
| 1006 EXPECT_EQ(1.0, GetDisplayInfoAt(0).configured_ui_scale()); |
| 1007 EXPECT_TRUE(expected_mode.IsEquivalent( |
| 1008 display_manager()->GetActiveModeForDisplayId(display_id))); |
| 1009 display_manager()->SetDisplayUIScale(display_id, 0.8f); |
| 1010 EXPECT_EQ(1.0f, GetDisplayInfoAt(0).configured_ui_scale()); |
| 1011 EXPECT_TRUE(expected_mode.IsEquivalent( |
| 1012 display_manager()->GetActiveModeForDisplayId(display_id))); |
| 1013 display_manager()->SetDisplayUIScale(display_id, 0.75f); |
| 1014 EXPECT_EQ(1.0f, GetDisplayInfoAt(0).configured_ui_scale()); |
| 1015 EXPECT_TRUE(expected_mode.IsEquivalent( |
| 1016 display_manager()->GetActiveModeForDisplayId(display_id))); |
| 1017 display_manager()->SetDisplayUIScale(display_id, 0.625f); |
| 1018 EXPECT_EQ(1.0f, GetDisplayInfoAt(0).configured_ui_scale()); |
| 1019 EXPECT_TRUE(expected_mode.IsEquivalent( |
| 1020 display_manager()->GetActiveModeForDisplayId(display_id))); |
| 1021 |
| 1022 gfx::Display::SetInternalDisplayId(display_id); |
| 1023 |
| 1024 display_manager()->SetDisplayUIScale(display_id, 1.5f); |
| 1025 EXPECT_EQ(1.0f, GetDisplayInfoAt(0).configured_ui_scale()); |
| 1026 EXPECT_TRUE(expected_mode.IsEquivalent( |
| 1027 display_manager()->GetActiveModeForDisplayId(display_id))); |
| 1028 display_manager()->SetDisplayUIScale(display_id, 1.25f); |
| 1029 EXPECT_EQ(1.0f, GetDisplayInfoAt(0).configured_ui_scale()); |
| 1030 EXPECT_TRUE(expected_mode.IsEquivalent( |
| 1031 display_manager()->GetActiveModeForDisplayId(display_id))); |
| 1032 display_manager()->SetDisplayUIScale(display_id, 1.125f); |
| 1033 EXPECT_EQ(1.125f, GetDisplayInfoAt(0).configured_ui_scale()); |
| 1034 expected_mode.ui_scale = 1.125f; |
| 1035 EXPECT_TRUE(expected_mode.IsEquivalent( |
| 1036 display_manager()->GetActiveModeForDisplayId(display_id))); |
| 1037 display_manager()->SetDisplayUIScale(display_id, 0.8f); |
| 1038 EXPECT_EQ(0.8f, GetDisplayInfoAt(0).configured_ui_scale()); |
| 1039 expected_mode.ui_scale = 0.8f; |
| 1040 EXPECT_TRUE(expected_mode.IsEquivalent( |
| 1041 display_manager()->GetActiveModeForDisplayId(display_id))); |
| 1042 display_manager()->SetDisplayUIScale(display_id, 0.75f); |
| 1043 EXPECT_EQ(0.8f, GetDisplayInfoAt(0).configured_ui_scale()); |
| 1044 EXPECT_TRUE(expected_mode.IsEquivalent( |
| 1045 display_manager()->GetActiveModeForDisplayId(display_id))); |
| 1046 display_manager()->SetDisplayUIScale(display_id, 0.625f); |
| 1047 EXPECT_EQ(0.625f, GetDisplayInfoAt(0).configured_ui_scale()); |
| 1048 expected_mode.ui_scale = 0.625f; |
| 1049 EXPECT_TRUE(expected_mode.IsEquivalent( |
| 1050 display_manager()->GetActiveModeForDisplayId(display_id))); |
| 1051 display_manager()->SetDisplayUIScale(display_id, 0.6f); |
| 1052 EXPECT_EQ(0.625f, GetDisplayInfoAt(0).configured_ui_scale()); |
| 1053 EXPECT_TRUE(expected_mode.IsEquivalent( |
| 1054 display_manager()->GetActiveModeForDisplayId(display_id))); |
| 1055 display_manager()->SetDisplayUIScale(display_id, 0.5f); |
| 1056 EXPECT_EQ(0.5f, GetDisplayInfoAt(0).configured_ui_scale()); |
| 1057 expected_mode.ui_scale = 0.5f; |
| 1058 EXPECT_TRUE(expected_mode.IsEquivalent( |
| 1059 display_manager()->GetActiveModeForDisplayId(display_id))); |
| 1060 } |
| 1061 |
968 TEST_F(DisplayManagerTest, UIScaleUpgradeToHighDPI) { | 1062 TEST_F(DisplayManagerTest, UIScaleUpgradeToHighDPI) { |
969 int64 display_id = Shell::GetScreen()->GetPrimaryDisplay().id(); | 1063 int64 display_id = Shell::GetScreen()->GetPrimaryDisplay().id(); |
970 gfx::Display::SetInternalDisplayId(display_id); | 1064 gfx::Display::SetInternalDisplayId(display_id); |
971 UpdateDisplay("1920x1080"); | 1065 UpdateDisplay("1920x1080"); |
972 | 1066 |
973 DisplayInfo::SetAllowUpgradeToHighDPI(false); | 1067 DisplayInfo::SetAllowUpgradeToHighDPI(false); |
974 display_manager()->SetDisplayUIScale(display_id, 1.125f); | 1068 display_manager()->SetDisplayUIScale(display_id, 1.125f); |
975 EXPECT_EQ(1.0f, GetDisplayInfoAt(0).GetEffectiveDeviceScaleFactor()); | 1069 EXPECT_EQ(1.0f, GetDisplayInfoAt(0).GetEffectiveDeviceScaleFactor()); |
976 EXPECT_EQ(1.125f, GetDisplayInfoAt(0).GetEffectiveUIScale()); | 1070 EXPECT_EQ(1.125f, GetDisplayInfoAt(0).GetEffectiveUIScale()); |
977 EXPECT_EQ("2160x1215", GetDisplayForId(display_id).size().ToString()); | 1071 EXPECT_EQ("2160x1215", GetDisplayForId(display_id).size().ToString()); |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1281 DISALLOW_COPY_AND_ASSIGN(ScreenShutdownTest); | 1375 DISALLOW_COPY_AND_ASSIGN(ScreenShutdownTest); |
1282 }; | 1376 }; |
1283 | 1377 |
1284 TEST_F(ScreenShutdownTest, ScreenAfterShutdown) { | 1378 TEST_F(ScreenShutdownTest, ScreenAfterShutdown) { |
1285 if (!SupportsMultipleDisplays()) | 1379 if (!SupportsMultipleDisplays()) |
1286 return; | 1380 return; |
1287 UpdateDisplay("500x300,800x400"); | 1381 UpdateDisplay("500x300,800x400"); |
1288 } | 1382 } |
1289 | 1383 |
1290 } // namespace ash | 1384 } // namespace ash |
OLD | NEW |