diff options
-rw-r--r-- | ash/accelerators/accelerator_controller.cc | 3 | ||||
-rw-r--r-- | ash/ash.gyp | 2 | ||||
-rw-r--r-- | ash/display/display_change_observer_chromeos.cc | 3 | ||||
-rw-r--r-- | ash/display/display_manager.cc | 108 | ||||
-rw-r--r-- | ash/display/display_manager.h | 15 | ||||
-rw-r--r-- | ash/display/display_manager_unittest.cc | 4 | ||||
-rw-r--r-- | ash/display/display_util.cc | 107 | ||||
-rw-r--r-- | ash/display/display_util.h | 30 |
8 files changed, 150 insertions, 122 deletions
diff --git a/ash/accelerators/accelerator_controller.cc b/ash/accelerators/accelerator_controller.cc index c8c9932..84f565c 100644 --- a/ash/accelerators/accelerator_controller.cc +++ b/ash/accelerators/accelerator_controller.cc @@ -14,6 +14,7 @@ #include "ash/debug.h" #include "ash/display/display_controller.h" #include "ash/display/display_manager.h" +#include "ash/display/display_util.h" #include "ash/focus_cycler.h" #include "ash/gpu_support.h" #include "ash/ime_control_delegate.h" @@ -345,7 +346,7 @@ void HandleScaleUI(bool up) { } const DisplayInfo& display_info = display_manager->GetDisplayInfo(display_id); - float next_scale = DisplayManager::GetNextUIScale(display_info, up); + float next_scale = GetNextUIScale(display_info, up); display_manager->SetDisplayUIScale(display_id, next_scale); } diff --git a/ash/ash.gyp b/ash/ash.gyp index 973eded..0af524a 100644 --- a/ash/ash.gyp +++ b/ash/ash.gyp @@ -79,6 +79,8 @@ 'display/display_manager.cc', 'display/display_manager.h', 'display/display_pref_util.h', + 'display/display_util.cc', + 'display/display_util.h', 'display/event_transformation_handler.cc', 'display/event_transformation_handler.h', 'display/mirror_window_controller.cc', diff --git a/ash/display/display_change_observer_chromeos.cc b/ash/display/display_change_observer_chromeos.cc index ec9ea2a..791279f 100644 --- a/ash/display/display_change_observer_chromeos.cc +++ b/ash/display/display_change_observer_chromeos.cc @@ -15,6 +15,7 @@ #include "ash/display/display_info.h" #include "ash/display/display_layout_store.h" #include "ash/display/display_manager.h" +#include "ash/display/display_util.h" #include "ash/shell.h" #include "ash/touch/touchscreen_util.h" #include "base/command_line.h" @@ -72,7 +73,7 @@ std::vector<DisplayMode> DisplayChangeObserver::GetInternalDisplayModeList( true); native_mode.device_scale_factor = display_info.device_scale_factor(); - return DisplayManager::CreateInternalDisplayModeList(native_mode); + return CreateInternalDisplayModeList(native_mode); } // static diff --git a/ash/display/display_manager.cc b/ash/display/display_manager.cc index 3fbf41c..23f9db8 100644 --- a/ash/display/display_manager.cc +++ b/ash/display/display_manager.cc @@ -12,6 +12,7 @@ #include "ash/ash_switches.h" #include "ash/display/display_layout_store.h" +#include "ash/display/display_util.h" #include "ash/display/screen_ash.h" #include "ash/screen_util.h" #include "ash/shell.h" @@ -59,16 +60,6 @@ gfx::Screen* screen_for_shutdown = NULL; // in case that the offset value is too large. const int kMinimumOverlapForInvalidOffset = 100; -// List of value UI Scale values. Scales for 2x are equivalent to 640, -// 800, 1024, 1280, 1440, 1600 and 1920 pixel width respectively on -// 2560 pixel width 2x density display. Please see crbug.com/233375 -// for the full list of resolutions. -const float kUIScalesFor2x[] = - {0.5f, 0.625f, 0.8f, 1.0f, 1.125f, 1.25f, 1.5f, 2.0f}; -const float kUIScalesFor1_25x[] = {0.5f, 0.625f, 0.8f, 1.0f, 1.25f }; -const float kUIScalesFor1280[] = {0.5f, 0.625f, 0.8f, 1.0f, 1.125f }; -const float kUIScalesFor1366[] = {0.5f, 0.6f, 0.75f, 1.0f, 1.125f }; - struct DisplaySortFunctor { bool operator()(const gfx::Display& a, const gfx::Display& b) { return a.id() < b.id(); @@ -90,16 +81,6 @@ struct DisplayModeMatcher { DisplayMode target_mode; }; -struct ScaleComparator { - explicit ScaleComparator(float s) : scale(s) {} - - bool operator()(const DisplayMode& mode) const { - const float kEpsilon = 0.0001f; - return std::abs(scale - mode.ui_scale) < kEpsilon; - } - float scale; -}; - gfx::Display& GetInvalidDisplay() { static gfx::Display* invalid_display = new gfx::Display(); return *invalid_display; @@ -110,8 +91,7 @@ void SetInternalDisplayModeList(DisplayInfo* info) { 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)); + info->SetDisplayModes(CreateInternalDisplayModeList(native_mode)); } void MaybeInitInternalDisplay(DisplayInfo* info) { @@ -123,34 +103,6 @@ void MaybeInitInternalDisplay(DisplayInfo* 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 using std::string; @@ -198,41 +150,6 @@ DisplayManager::~DisplayManager() { #endif } -// static -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); - } - return display_mode_list; -} - -// static -float DisplayManager::GetNextUIScale(const DisplayInfo& info, bool up) { - 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. - return 1.0f; -} - bool DisplayManager::InitFromCommandLine() { DisplayInfoList info_list; base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); @@ -275,18 +192,6 @@ void DisplayManager::RefreshFontParams() { #endif // OS_CHROMEOS } -// static -void DisplayManager::UpdateDisplayBoundsForLayoutById( - const DisplayLayout& layout, - const gfx::Display& primary_display, - int64 secondary_display_id) { - DCHECK_NE(gfx::Display::kInvalidDisplayID, secondary_display_id); - UpdateDisplayBoundsForLayout( - layout, primary_display, - Shell::GetInstance()->display_manager()-> - FindDisplayForId(secondary_display_id)); -} - bool DisplayManager::IsActiveDisplay(const gfx::Display& display) const { for (DisplayList::const_iterator iter = displays_.begin(); iter != displays_.end(); ++iter) { @@ -366,9 +271,9 @@ void DisplayManager::SetLayoutForCurrentDisplays( // PreDisplayConfigurationChange(false); // TODO(oshima): Call UpdateDisplays instead. const DisplayLayout layout = GetCurrentDisplayLayout(); - UpdateDisplayBoundsForLayoutById( + UpdateDisplayBoundsForLayout( layout, primary, - ScreenUtil::GetSecondaryDisplay().id()); + FindDisplayForId(ScreenUtil::GetSecondaryDisplay().id())); // Primary's bounds stay the same. Just notify bounds change // on the secondary. @@ -466,10 +371,7 @@ bool DisplayManager::SetDisplayUIScale(int64 display_id, found = true; if (info.configured_ui_scale() == ui_scale) return true; - const std::vector<DisplayMode>& modes = info.display_modes(); - - ScaleComparator comparator(ui_scale); - if (std::find_if(modes.begin(), modes.end(), comparator) == modes.end()) + if (!HasDisplayModeForUIScale(info, ui_scale)) return false; info.set_configured_ui_scale(ui_scale); } diff --git a/ash/display/display_manager.h b/ash/display/display_manager.h index ec45589..d9e4efa 100644 --- a/ash/display/display_manager.h +++ b/ash/display/display_manager.h @@ -77,21 +77,6 @@ class ASH_EXPORT DisplayManager MIRRORING }; - // 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); - - // Updates the bounds of the display given by |secondary_display_id| - // according to |layout|. - static void UpdateDisplayBoundsForLayoutById( - const DisplayLayout& layout, - const gfx::Display& primary_display, - int64 secondary_display_id); - DisplayManager(); virtual ~DisplayManager(); diff --git a/ash/display/display_manager_unittest.cc b/ash/display/display_manager_unittest.cc index f9c5c3c..3741a7b 100644 --- a/ash/display/display_manager_unittest.cc +++ b/ash/display/display_manager_unittest.cc @@ -8,6 +8,7 @@ #include "ash/display/display_controller.h" #include "ash/display/display_info.h" #include "ash/display/display_layout_store.h" +#include "ash/display/display_util.h" #include "ash/screen_util.h" #include "ash/shell.h" #include "ash/test/ash_test_base.h" @@ -1089,8 +1090,7 @@ 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<DisplayMode> mode_list = - DisplayManager::CreateInternalDisplayModeList(base_mode); + std::vector<DisplayMode> mode_list = CreateInternalDisplayModeList(base_mode); native_display_info.SetDisplayModes(mode_list); std::vector<DisplayInfo> display_info_list; diff --git a/ash/display/display_util.cc b/ash/display/display_util.cc new file mode 100644 index 0000000..d152d13 --- /dev/null +++ b/ash/display/display_util.cc @@ -0,0 +1,107 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ash/display/display_util.h" + +#include <algorithm> + +#include "ash/display/display_info.h" + +#if defined(OS_CHROMEOS) +#include "base/sys_info.h" +#endif + +namespace ash { +namespace { + +// List of value UI Scale values. Scales for 2x are equivalent to 640, +// 800, 1024, 1280, 1440, 1600 and 1920 pixel width respectively on +// 2560 pixel width 2x density display. Please see crbug.com/233375 +// for the full list of resolutions. +const float kUIScalesFor2x[] = + {0.5f, 0.625f, 0.8f, 1.0f, 1.125f, 1.25f, 1.5f, 2.0f}; +const float kUIScalesFor1_25x[] = {0.5f, 0.625f, 0.8f, 1.0f, 1.25f }; +const float kUIScalesFor1280[] = {0.5f, 0.625f, 0.8f, 1.0f, 1.125f }; +const float kUIScalesFor1366[] = {0.5f, 0.6f, 0.75f, 1.0f, 1.125f }; + +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; +} + +struct ScaleComparator { + explicit ScaleComparator(float s) : scale(s) {} + + bool operator()(const DisplayMode& mode) const { + const float kEpsilon = 0.0001f; + return std::abs(scale - mode.ui_scale) < kEpsilon; + } + float scale; +}; + +} // namespace + +std::vector<DisplayMode> CreateInternalDisplayModeList( + const DisplayMode& native_mode) { + std::vector<DisplayMode> display_mode_list; + + float native_ui_scale = (native_mode.device_scale_factor == 1.25f) + ? 1.0f + : native_mode.device_scale_factor; + for (float ui_scale : GetScalesForDisplay(native_mode)) { + DisplayMode mode = native_mode; + mode.ui_scale = ui_scale; + mode.native = (ui_scale == native_ui_scale); + display_mode_list.push_back(mode); + } + return display_mode_list; +} + +// static +float GetNextUIScale(const DisplayInfo& info, bool up) { + 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. + return 1.0f; +} + +bool HasDisplayModeForUIScale(const DisplayInfo& info, float ui_scale) { + ScaleComparator comparator(ui_scale); + const std::vector<DisplayMode>& modes = info.display_modes(); + return std::find_if(modes.begin(), modes.end(), comparator) != modes.end(); +} + +} // namespace ash diff --git a/ash/display/display_util.h b/ash/display/display_util.h new file mode 100644 index 0000000..1a032b4 --- /dev/null +++ b/ash/display/display_util.h @@ -0,0 +1,30 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef ASH_DISPLAY_DISPLAY_UTIL_H_ +#define ASH_DISPLAY_DISPLAY_UTIL_H_ + +#include <vector> + +#include "ash/ash_export.h" + +namespace ash { + +struct DisplayMode; +class DisplayInfo; + +// Creates the display mode list for internal display +// based on |native_mode|. +ASH_EXPORT std::vector<DisplayMode> CreateInternalDisplayModeList( + const DisplayMode& native_mode); + +// Returns next valid UI scale. +float GetNextUIScale(const DisplayInfo& info, bool up); + +// Tests if the |info| has display mode that matches |ui_scale|. +bool HasDisplayModeForUIScale(const DisplayInfo& info, float ui_scale); + +} // namespace ash + +#endif // ASH_DISPLAY_DISPLAY_UTIL_H_ |