diff options
Diffstat (limited to 'ash/display')
-rw-r--r-- | ash/display/display_change_observer_chromeos.cc | 36 | ||||
-rw-r--r-- | ash/display/display_change_observer_chromeos_unittest.cc | 4 | ||||
-rw-r--r-- | ash/display/display_controller_unittest.cc | 9 | ||||
-rw-r--r-- | ash/display/display_info.cc | 26 | ||||
-rw-r--r-- | ash/display/display_info.h | 6 | ||||
-rw-r--r-- | ash/display/display_info_unittest.cc | 35 | ||||
-rw-r--r-- | ash/display/display_manager.cc | 146 | ||||
-rw-r--r-- | ash/display/display_manager.h | 18 | ||||
-rw-r--r-- | ash/display/display_manager_unittest.cc | 33 | ||||
-rw-r--r-- | ash/display/root_window_transformers_unittest.cc | 4 |
10 files changed, 185 insertions, 132 deletions
diff --git a/ash/display/display_change_observer_chromeos.cc b/ash/display/display_change_observer_chromeos.cc index 0c73b14e..ec9ea2a 100644 --- a/ash/display/display_change_observer_chromeos.cc +++ b/ash/display/display_change_observer_chromeos.cc @@ -59,50 +59,20 @@ const int kMinimumWidthFor4K = 3840; // available in extrenal large monitors. const float kAdditionalDeviceScaleFactorsFor4k[] = {1.25f, 2.0f}; -// Display mode list is sorted by: -// * the area in pixels in ascending order -// * refresh rate in descending order -struct DisplayModeSorter { - explicit DisplayModeSorter(bool is_internal) : is_internal(is_internal) {} - - bool operator()(const DisplayMode& a, const DisplayMode& b) { - gfx::Size size_a_dip = a.GetSizeInDIP(is_internal); - gfx::Size size_b_dip = b.GetSizeInDIP(is_internal); - if (size_a_dip.GetArea() == size_b_dip.GetArea()) - return (a.refresh_rate > b.refresh_rate); - return (size_a_dip.GetArea() < size_b_dip.GetArea()); - } - - bool is_internal; -}; - } // namespace // static std::vector<DisplayMode> DisplayChangeObserver::GetInternalDisplayModeList( const DisplayInfo& display_info, const DisplayConfigurator::DisplayState& output) { - std::vector<DisplayMode> display_mode_list; const ui::DisplayMode* ui_native_mode = output.display->native_mode(); DisplayMode native_mode(ui_native_mode->size(), ui_native_mode->refresh_rate(), ui_native_mode->is_interlaced(), true); native_mode.device_scale_factor = display_info.device_scale_factor(); - std::vector<float> ui_scales = - DisplayManager::GetScalesForDisplay(display_info); - float native_ui_scale = (display_info.device_scale_factor() == 1.25f) ? - 1.0f : display_info.device_scale_factor(); - for (size_t i = 0; i < ui_scales.size(); ++i) { - DisplayMode mode = native_mode; - mode.ui_scale = ui_scales[i]; - mode.native = (ui_scales[i] == native_ui_scale); - display_mode_list.push_back(mode); - } - std::sort(display_mode_list.begin(), display_mode_list.end(), - DisplayModeSorter(true)); - return display_mode_list; + return DisplayManager::CreateInternalDisplayModeList(native_mode); } // static @@ -164,8 +134,6 @@ std::vector<DisplayMode> DisplayChangeObserver::GetExternalDisplayModeList( } } - std::sort(display_mode_list.begin(), display_mode_list.end(), - DisplayModeSorter(false)); return display_mode_list; } @@ -265,7 +233,7 @@ void DisplayChangeObserver::OnDisplayModeChanged( (state.display->type() == ui::DISPLAY_CONNECTION_TYPE_INTERNAL) ? GetInternalDisplayModeList(new_info, state) : GetExternalDisplayModeList(state); - new_info.set_display_modes(display_modes); + new_info.SetDisplayModes(display_modes); new_info.set_available_color_profiles( Shell::GetInstance() diff --git a/ash/display/display_change_observer_chromeos_unittest.cc b/ash/display/display_change_observer_chromeos_unittest.cc index ad52e2e..7b18b08 100644 --- a/ash/display/display_change_observer_chromeos_unittest.cc +++ b/ash/display/display_change_observer_chromeos_unittest.cc @@ -268,6 +268,10 @@ TEST_F(DisplayChangeObserverTest, GetExternalDisplayModeList4K) { std::vector<DisplayMode> display_modes = DisplayChangeObserver::GetExternalDisplayModeList(output); + DisplayInfo info; + info.SetDisplayModes(display_modes); // Sort as external display. + display_modes = info.display_modes(); + ASSERT_EQ(9u, display_modes.size()); EXPECT_EQ("640x480", display_modes[0].size.ToString()); EXPECT_TRUE(display_modes[0].interlaced); diff --git a/ash/display/display_controller_unittest.cc b/ash/display/display_controller_unittest.cc index 05a977b..320c3a3 100644 --- a/ash/display/display_controller_unittest.cc +++ b/ash/display/display_controller_unittest.cc @@ -678,7 +678,9 @@ TEST_F(DisplayControllerTest, BoundsUpdated) { // UI scale is eanbled only on internal display. int64 secondary_id = GetSecondaryDisplay().id(); - gfx::Display::SetInternalDisplayId(secondary_id); + test::DisplayManagerTestApi(display_manager) + .SetInternalDisplayId(secondary_id); + display_manager->SetDisplayUIScale(secondary_id, 1.125f); EXPECT_EQ(1, observer.CountAndReset()); EXPECT_EQ(0, observer.GetFocusChangedCountAndReset()); @@ -1141,8 +1143,10 @@ TEST_F(DisplayControllerTest, ScaleRootWindow) { UpdateDisplay("600x400*2@1.5,500x300"); + DisplayManager* display_manager = Shell::GetInstance()->display_manager(); gfx::Display display1 = Shell::GetScreen()->GetPrimaryDisplay(); - gfx::Display::SetInternalDisplayId(display1.id()); + test::DisplayManagerTestApi(display_manager) + .SetInternalDisplayId(display1.id()); gfx::Display display2 = ScreenUtil::GetSecondaryDisplay(); aura::Window::Windows root_windows = Shell::GetAllRootWindows(); @@ -1156,7 +1160,6 @@ TEST_F(DisplayControllerTest, ScaleRootWindow) { generator.MoveMouseToInHost(599, 200); EXPECT_EQ("449,150", event_handler.GetLocationAndReset()); - DisplayManager* display_manager = Shell::GetInstance()->display_manager(); display_manager->SetDisplayUIScale(display1.id(), 1.25f); display1 = Shell::GetScreen()->GetPrimaryDisplay(); display2 = ScreenUtil::GetSecondaryDisplay(); diff --git a/ash/display/display_info.cc b/ash/display/display_info.cc index 1e5ce17..7f6cfff 100644 --- a/ash/display/display_info.cc +++ b/ash/display/display_info.cc @@ -43,6 +43,23 @@ bool GetDisplayBounds( return false; } +// Display mode list is sorted by: +// * the area in pixels in ascending order +// * refresh rate in descending order +struct DisplayModeSorter { + explicit DisplayModeSorter(bool is_internal) : is_internal(is_internal) {} + + bool operator()(const DisplayMode& a, const DisplayMode& b) { + gfx::Size size_a_dip = a.GetSizeInDIP(is_internal); + gfx::Size size_b_dip = b.GetSizeInDIP(is_internal); + if (size_a_dip.GetArea() == size_b_dip.GetArea()) + return (a.refresh_rate > b.refresh_rate); + return (size_a_dip.GetArea() < size_b_dip.GetArea()); + } + + bool is_internal; +}; + } // namespace DisplayMode::DisplayMode() @@ -193,7 +210,7 @@ DisplayInfo DisplayInfo::CreateFromSpecWithID(const std::string& spec, display_info.set_rotation(rotation); display_info.set_configured_ui_scale(ui_scale); display_info.SetBounds(bounds_in_native); - display_info.set_display_modes(display_modes); + display_info.SetDisplayModes(display_modes); // To test the overscan, it creates the default 5% overscan. if (has_overscan) { @@ -328,6 +345,13 @@ gfx::Insets DisplayInfo::GetOverscanInsetsInPixel() const { return overscan_insets_in_dip_.Scale(device_scale_factor_); } +void DisplayInfo::SetDisplayModes( + const std::vector<DisplayMode>& display_modes) { + display_modes_ = display_modes; + std::sort(display_modes_.begin(), display_modes_.end(), + DisplayModeSorter(id_ == gfx::Display::InternalDisplayId())); +} + gfx::Size DisplayInfo::GetNativeModeSize() const { for (size_t i = 0; i < display_modes_.size(); ++i) { if (display_modes_[i].native) diff --git a/ash/display/display_info.h b/ash/display/display_info.h index b24205b..d8c57c6 100644 --- a/ash/display/display_info.h +++ b/ash/display/display_info.h @@ -178,9 +178,9 @@ class ASH_EXPORT DisplayInfo { const std::vector<DisplayMode>& display_modes() const { return display_modes_; } - void set_display_modes(std::vector<DisplayMode>& display_modes) { - display_modes_.swap(display_modes); - } + // Sets the display mode list. The mode list will be sorted for the + // display. + void SetDisplayModes(const std::vector<DisplayMode>& display_modes); // Returns the native mode size. If a native mode is not present, return an // empty size. diff --git a/ash/display/display_info_unittest.cc b/ash/display/display_info_unittest.cc index 2f30e94..01362b4 100644 --- a/ash/display/display_info_unittest.cc +++ b/ash/display/display_info_unittest.cc @@ -59,26 +59,33 @@ TEST_F(DisplayInfoTest, CreateFromSpec) { info = DisplayInfo::CreateFromSpecWithID( "200x200#300x200|200x200%59.9|100x100%60|150x100*2|150x150*1.25%30", 10); + EXPECT_EQ("0,0 200x200", info.bounds_in_native().ToString()); EXPECT_EQ(5u, info.display_modes().size()); - EXPECT_EQ("300x200", info.display_modes()[0].size.ToString()); - EXPECT_EQ("200x200", info.display_modes()[1].size.ToString()); - EXPECT_EQ("100x100", info.display_modes()[2].size.ToString()); - EXPECT_EQ("150x100", info.display_modes()[3].size.ToString()); - EXPECT_EQ("150x150", info.display_modes()[4].size.ToString()); - EXPECT_EQ(59.9f, info.display_modes()[1].refresh_rate); - EXPECT_EQ(60.0f, info.display_modes()[2].refresh_rate); - EXPECT_EQ(30.0f, info.display_modes()[4].refresh_rate); - EXPECT_EQ(1.0f, info.display_modes()[0].device_scale_factor); + // Modes are sorted in DIP for external display. + EXPECT_EQ("150x100", info.display_modes()[0].size.ToString()); + EXPECT_EQ("100x100", info.display_modes()[1].size.ToString()); + EXPECT_EQ("150x150", info.display_modes()[2].size.ToString()); + EXPECT_EQ("200x200", info.display_modes()[3].size.ToString()); + EXPECT_EQ("300x200", info.display_modes()[4].size.ToString()); + + EXPECT_EQ(0.0f, info.display_modes()[0].refresh_rate); + EXPECT_EQ(60.0f, info.display_modes()[1].refresh_rate); + EXPECT_EQ(30.0f, info.display_modes()[2].refresh_rate); + EXPECT_EQ(59.9f, info.display_modes()[3].refresh_rate); + EXPECT_EQ(0.0f, info.display_modes()[4].refresh_rate); + + EXPECT_EQ(2.0f, info.display_modes()[0].device_scale_factor); EXPECT_EQ(1.0f, info.display_modes()[1].device_scale_factor); - EXPECT_EQ(1.0f, info.display_modes()[2].device_scale_factor); - EXPECT_EQ(2.0f, info.display_modes()[3].device_scale_factor); - EXPECT_EQ(1.25f, info.display_modes()[4].device_scale_factor); - EXPECT_TRUE(info.display_modes()[0].native); + EXPECT_EQ(1.25f, info.display_modes()[2].device_scale_factor); + EXPECT_EQ(1.0f, info.display_modes()[3].device_scale_factor); + EXPECT_EQ(1.0f, info.display_modes()[4].device_scale_factor); + + EXPECT_FALSE(info.display_modes()[0].native); EXPECT_FALSE(info.display_modes()[1].native); EXPECT_FALSE(info.display_modes()[2].native); EXPECT_FALSE(info.display_modes()[3].native); - EXPECT_FALSE(info.display_modes()[4].native); + EXPECT_TRUE(info.display_modes()[4].native); } TEST_F(DisplayInfoTest, DisplayModeGetSizeInDIPNormal) { diff --git a/ash/display/display_manager.cc b/ash/display/display_manager.cc index 84051a1..3fbf41c 100644 --- a/ash/display/display_manager.cc +++ b/ash/display/display_manager.cc @@ -93,9 +93,9 @@ struct DisplayModeMatcher { struct ScaleComparator { explicit ScaleComparator(float s) : scale(s) {} - bool operator()(float s) const { + bool operator()(const DisplayMode& mode) const { const float kEpsilon = 0.0001f; - return std::abs(scale - s) < kEpsilon; + return std::abs(scale - mode.ui_scale) < kEpsilon; } float scale; }; @@ -105,10 +105,50 @@ gfx::Display& GetInvalidDisplay() { return *invalid_display; } -void MaybeInitInternalDisplay(int64 id) { +void SetInternalDisplayModeList(DisplayInfo* info) { + DisplayMode native_mode; + native_mode.size = info->bounds_in_native().size(); + native_mode.device_scale_factor = info->device_scale_factor(); + native_mode.ui_scale = 1.0f; + info->SetDisplayModes( + DisplayManager::CreateInternalDisplayModeList(native_mode)); +} + +void MaybeInitInternalDisplay(DisplayInfo* info) { + int64 id = info->id(); base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); - if (command_line->HasSwitch(switches::kAshUseFirstDisplayAsInternal)) + if (command_line->HasSwitch(switches::kAshUseFirstDisplayAsInternal)) { gfx::Display::SetInternalDisplayId(id); + SetInternalDisplayModeList(info); + } +} + +std::vector<float> GetScalesForDisplay(const DisplayMode& native_mode) { +#define ASSIGN_ARRAY(v, a) v.assign(a, a + arraysize(a)) + + std::vector<float> ret; + if (native_mode.device_scale_factor == 2.0f) { + ASSIGN_ARRAY(ret, kUIScalesFor2x); + return ret; + } else if (native_mode.device_scale_factor == 1.25f) { + ASSIGN_ARRAY(ret, kUIScalesFor1_25x); + return ret; + } + switch (native_mode.size.width()) { + case 1280: + ASSIGN_ARRAY(ret, kUIScalesFor1280); + break; + case 1366: + ASSIGN_ARRAY(ret, kUIScalesFor1366); + break; + default: + ASSIGN_ARRAY(ret, kUIScalesFor1280); +#if defined(OS_CHROMEOS) + if (base::SysInfo::IsRunningOnChromeOS()) + NOTREACHED() << "Unknown resolution:" << native_mode.size.ToString(); +#endif + } + return ret; } } // namespace @@ -159,47 +199,34 @@ DisplayManager::~DisplayManager() { } // static -std::vector<float> DisplayManager::GetScalesForDisplay( - const DisplayInfo& info) { - -#define ASSIGN_ARRAY(v, a) v.assign(a, a + arraysize(a)) - - std::vector<float> ret; - if (info.device_scale_factor() == 2.0f) { - ASSIGN_ARRAY(ret, kUIScalesFor2x); - return ret; - } else if (info.device_scale_factor() == 1.25f) { - ASSIGN_ARRAY(ret, kUIScalesFor1_25x); - return ret; +std::vector<DisplayMode> DisplayManager::CreateInternalDisplayModeList( + const DisplayMode& native_mode) { + std::vector<DisplayMode> display_mode_list; + + std::vector<float> ui_scales = GetScalesForDisplay(native_mode); + float native_ui_scale = (native_mode.device_scale_factor == 1.25f) + ? 1.0f + : native_mode.device_scale_factor; + for (size_t i = 0; i < ui_scales.size(); ++i) { + DisplayMode mode = native_mode; + mode.ui_scale = ui_scales[i]; + mode.native = (ui_scales[i] == native_ui_scale); + display_mode_list.push_back(mode); } - switch (info.bounds_in_native().width()) { - case 1280: - ASSIGN_ARRAY(ret, kUIScalesFor1280); - break; - case 1366: - ASSIGN_ARRAY(ret, kUIScalesFor1366); - break; - default: - ASSIGN_ARRAY(ret, kUIScalesFor1280); -#if defined(OS_CHROMEOS) - if (base::SysInfo::IsRunningOnChromeOS()) - NOTREACHED() << "Unknown resolution:" << info.ToString(); -#endif - } - return ret; + return display_mode_list; } // static float DisplayManager::GetNextUIScale(const DisplayInfo& info, bool up) { - float scale = info.configured_ui_scale(); - std::vector<float> scales = GetScalesForDisplay(info); - for (size_t i = 0; i < scales.size(); ++i) { - if (ScaleComparator(scales[i])(scale)) { - if (up && i != scales.size() - 1) - return scales[i + 1]; - if (!up && i != 0) - return scales[i - 1]; - return scales[i]; + ScaleComparator comparator(info.configured_ui_scale()); + const std::vector<DisplayMode>& modes = info.display_modes(); + for (auto iter = modes.begin(); iter != modes.end(); ++iter) { + if (comparator(*iter)) { + if (up && (iter + 1) != modes.end()) + return (iter + 1)->ui_scale; + if (!up && iter != modes.begin()) + return (iter - 1)->ui_scale; + return info.configured_ui_scale(); } } // Fallback to 1.0f if the |scale| wasn't in the list. @@ -220,7 +247,7 @@ bool DisplayManager::InitFromCommandLine() { info_list.push_back(DisplayInfo::CreateFromSpec(*iter)); info_list.back().set_native(true); } - MaybeInitInternalDisplay(info_list[0].id()); + MaybeInitInternalDisplay(&info_list[0]); if (info_list.size() > 1 && command_line->HasSwitch(switches::kAshEnableSoftwareMirroring)) { SetSecondDisplayMode(MIRRORING); @@ -233,7 +260,7 @@ void DisplayManager::InitDefaultDisplay() { DisplayInfoList info_list; info_list.push_back(DisplayInfo::CreateFromSpec(std::string())); info_list.back().set_native(true); - MaybeInitInternalDisplay(info_list[0].id()); + MaybeInitInternalDisplay(&info_list[0]); OnNativeDisplaysChanged(info_list); } @@ -423,33 +450,37 @@ void DisplayManager::SetDisplayRotation(int64 display_id, UpdateDisplays(display_info_list); } -void DisplayManager::SetDisplayUIScale(int64 display_id, +bool DisplayManager::SetDisplayUIScale(int64 display_id, float ui_scale) { if (!IsDisplayUIScalingEnabled() || gfx::Display::InternalDisplayId() != display_id) { - return; + return false; } - + bool found = false; // TODO(mukai): merge this implementation into SetDisplayMode(). DisplayInfoList display_info_list; for (DisplayList::const_iterator iter = displays_.begin(); iter != displays_.end(); ++iter) { DisplayInfo info = GetDisplayInfo(iter->id()); if (info.id() == display_id) { + found = true; if (info.configured_ui_scale() == ui_scale) - return; - std::vector<float> scales = GetScalesForDisplay(info); + return true; + const std::vector<DisplayMode>& modes = info.display_modes(); + ScaleComparator comparator(ui_scale); - if (std::find_if(scales.begin(), scales.end(), comparator) == - scales.end()) { - return; - } + if (std::find_if(modes.begin(), modes.end(), comparator) == modes.end()) + return false; info.set_configured_ui_scale(ui_scale); } display_info_list.push_back(info); } - AddMirrorDisplayInfoIfAny(&display_info_list); - UpdateDisplays(display_info_list); + if (found) { + AddMirrorDisplayInfoIfAny(&display_info_list); + UpdateDisplays(display_info_list); + return true; + } + return false; } void DisplayManager::SetDisplayResolution(int64 display_id, @@ -641,7 +672,7 @@ void DisplayManager::OnNativeDisplaysChanged( if (displays_.empty()) { std::vector<DisplayInfo> init_displays; init_displays.push_back(DisplayInfo::CreateFromSpec(std::string())); - MaybeInitInternalDisplay(init_displays[0].id()); + MaybeInitInternalDisplay(&init_displays[0]); OnNativeDisplaysChanged(init_displays); } else { // Otherwise don't update the displays when all displays are disconnected. @@ -1145,6 +1176,13 @@ void DisplayManager::CreateScreenForShutdown() const { } } +void DisplayManager::UpdateInternalDisplayModeListForTest() { + if (display_info_.count(gfx::Display::InternalDisplayId()) == 0) + return; + DisplayInfo* info = &display_info_[gfx::Display::InternalDisplayId()]; + SetInternalDisplayModeList(info); +} + gfx::Display* DisplayManager::FindDisplayForId(int64 id) { for (DisplayList::iterator iter = displays_.begin(); iter != displays_.end(); ++iter) { diff --git a/ash/display/display_manager.h b/ash/display/display_manager.h index 188e5d8..ec45589 100644 --- a/ash/display/display_manager.h +++ b/ash/display/display_manager.h @@ -77,8 +77,10 @@ class ASH_EXPORT DisplayManager MIRRORING }; - // Returns the list of possible UI scales for the display. - static std::vector<float> GetScalesForDisplay(const DisplayInfo& info); + // Creates the display modes list for internal display given + // by |native_mode|. + static std::vector<DisplayMode> CreateInternalDisplayModeList( + const DisplayMode& native_mode); // Returns next valid UI scale. static float GetNextUIScale(const DisplayInfo& info, bool up); @@ -163,9 +165,10 @@ class ASH_EXPORT DisplayManager // Sets the display's rotation. void SetDisplayRotation(int64 display_id, gfx::Display::Rotation rotation); - // Sets the display's ui scale. - // TODO(mukai): remove this and merge into SetDisplayMode. - void SetDisplayUIScale(int64 display_id, float ui_scale); + // Sets the display's ui scale. Returns true if it's successful, or + // false otherwise. TODO(mukai): remove this and merge into + // SetDisplayMode. + bool SetDisplayUIScale(int64 display_id, float ui_scale); // Sets the display's resolution. // TODO(mukai): remove this and merge into SetDisplayMode. @@ -306,6 +309,11 @@ class ASH_EXPORT DisplayManager // Create a screen instance to be used during shutdown. void CreateScreenForShutdown() const; + // A unit test may change the internal display id (which never happens on + // a real device). This will update the mode list for internal display + // for this test scenario. + void UpdateInternalDisplayModeListForTest(); + private: FRIEND_TEST_ALL_PREFIXES(ExtendedDesktopTest, ConvertPoint); FRIEND_TEST_ALL_PREFIXES(DisplayManagerTest, TestNativeDisplaysChanged); diff --git a/ash/display/display_manager_unittest.cc b/ash/display/display_manager_unittest.cc index 1fdaadd..f9c5c3c 100644 --- a/ash/display/display_manager_unittest.cc +++ b/ash/display/display_manager_unittest.cc @@ -830,7 +830,7 @@ TEST_F(DisplayManagerTest, DontRememberBestResolution) { display_modes.push_back( DisplayMode(gfx::Size(400, 500), 60.0f, false, false)); - native_display_info.set_display_modes(display_modes); + native_display_info.SetDisplayModes(display_modes); std::vector<DisplayInfo> display_info_list; display_info_list.push_back(native_display_info); @@ -887,7 +887,7 @@ TEST_F(DisplayManagerTest, ResolutionFallback) { DisplayMode(gfx::Size(400, 500), 60.0f, false, false)); std::vector<DisplayMode> copy = display_modes; - native_display_info.set_display_modes(copy); + native_display_info.SetDisplayModes(copy); std::vector<DisplayInfo> display_info_list; display_info_list.push_back(native_display_info); @@ -897,7 +897,7 @@ TEST_F(DisplayManagerTest, ResolutionFallback) { DisplayInfo new_native_display_info = CreateDisplayInfo(display_id, gfx::Rect(0, 0, 400, 500)); copy = display_modes; - new_native_display_info.set_display_modes(copy); + new_native_display_info.SetDisplayModes(copy); std::vector<DisplayInfo> new_display_info_list; new_display_info_list.push_back(new_native_display_info); display_manager()->OnNativeDisplaysChanged(new_display_info_list); @@ -915,7 +915,7 @@ TEST_F(DisplayManagerTest, ResolutionFallback) { DisplayInfo new_native_display_info = CreateDisplayInfo(display_id, gfx::Rect(0, 0, 1000, 500)); std::vector<DisplayMode> copy = display_modes; - new_native_display_info.set_display_modes(copy); + new_native_display_info.SetDisplayModes(copy); std::vector<DisplayInfo> new_display_info_list; new_display_info_list.push_back(new_native_display_info); display_manager()->OnNativeDisplaysChanged(new_display_info_list); @@ -1000,7 +1000,8 @@ TEST_F(DisplayManagerTest, UIScale) { display_manager()->SetDisplayUIScale(display_id, 0.625f); EXPECT_EQ(1.0f, GetDisplayInfoAt(0).configured_ui_scale()); - gfx::Display::SetInternalDisplayId(display_id); + test::DisplayManagerTestApi(display_manager()) + .SetInternalDisplayId(display_id); display_manager()->SetDisplayUIScale(display_id, 1.5f); EXPECT_EQ(1.0f, GetDisplayInfoAt(0).configured_ui_scale()); @@ -1088,15 +1089,10 @@ TEST_F(DisplayManagerTest, UIScaleWithDisplayMode) { CreateDisplayInfo(display_id, gfx::Rect(0, 0, 1280, 800)); std::vector<DisplayMode> display_modes; const DisplayMode base_mode(gfx::Size(1280, 800), 60.0f, false, false); - std::vector<float> scales = - DisplayManager::GetScalesForDisplay(native_display_info); - for (size_t i = 0; i < scales.size(); i++) { - DisplayMode mode = base_mode; - mode.ui_scale = scales[i]; - mode.native = (scales[i] == 1.0f); - display_modes.push_back(mode); - } - native_display_info.set_display_modes(display_modes); + std::vector<DisplayMode> mode_list = + DisplayManager::CreateInternalDisplayModeList(base_mode); + native_display_info.SetDisplayModes(mode_list); + std::vector<DisplayInfo> display_info_list; display_info_list.push_back(native_display_info); display_manager()->OnNativeDisplaysChanged(display_info_list); @@ -1122,7 +1118,8 @@ TEST_F(DisplayManagerTest, UIScaleWithDisplayMode) { EXPECT_TRUE(expected_mode.IsEquivalent( display_manager()->GetActiveModeForDisplayId(display_id))); - gfx::Display::SetInternalDisplayId(display_id); + test::DisplayManagerTestApi(display_manager()) + .SetInternalDisplayId(display_id); display_manager()->SetDisplayUIScale(display_id, 1.5f); EXPECT_EQ(1.0f, GetDisplayInfoAt(0).configured_ui_scale()); @@ -1163,10 +1160,12 @@ TEST_F(DisplayManagerTest, UIScaleWithDisplayMode) { } TEST_F(DisplayManagerTest, Use125DSFRorUIScaling) { - int64 display_id = Shell::GetScreen()->GetPrimaryDisplay().id(); - gfx::Display::SetInternalDisplayId(display_id); DisplayInfo::SetUse125DSFForUIScaling(true); + int64 display_id = Shell::GetScreen()->GetPrimaryDisplay().id(); + test::DisplayManagerTestApi(display_manager()) + .SetInternalDisplayId(display_id); + UpdateDisplay("1920x1080*1.25"); EXPECT_EQ(1.0f, GetDisplayInfoAt(0).GetEffectiveDeviceScaleFactor()); EXPECT_EQ(1.0f, GetDisplayInfoAt(0).GetEffectiveUIScale()); diff --git a/ash/display/root_window_transformers_unittest.cc b/ash/display/root_window_transformers_unittest.cc index 32f4be6..698d7bc 100644 --- a/ash/display/root_window_transformers_unittest.cc +++ b/ash/display/root_window_transformers_unittest.cc @@ -14,6 +14,7 @@ #include "ash/shell.h" #include "ash/test/ash_test_base.h" #include "ash/test/cursor_manager_test_api.h" +#include "ash/test/display_manager_test_api.h" #include "ash/test/mirror_window_test_api.h" #include "base/synchronization/waitable_event.h" #include "ui/aura/env.h" @@ -233,7 +234,8 @@ TEST_F(RootWindowTransformersTest, ScaleAndMagnify) { UpdateDisplay("600x400*2@1.5,500x300"); gfx::Display display1 = Shell::GetScreen()->GetPrimaryDisplay(); - gfx::Display::SetInternalDisplayId(display1.id()); + test::DisplayManagerTestApi(Shell::GetInstance()->display_manager()) + .SetInternalDisplayId(display1.id()); gfx::Display display2 = ScreenUtil::GetSecondaryDisplay(); aura::Window::Windows root_windows = Shell::GetAllRootWindows(); MagnificationController* magnifier = |