diff options
author | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-23 06:20:39 +0000 |
---|---|---|
committer | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-23 06:20:39 +0000 |
commit | 564833e1bf8ee59ec0ba7955e0abbec4a488e14a (patch) | |
tree | 32d300b6c4ae34bd0534db5bd68ff1dc46d34e18 /ash | |
parent | 987eb23f86237972209d362023622e7887ae7e62 (diff) | |
download | chromium_src-564833e1bf8ee59ec0ba7955e0abbec4a488e14a.zip chromium_src-564833e1bf8ee59ec0ba7955e0abbec4a488e14a.tar.gz chromium_src-564833e1bf8ee59ec0ba7955e0abbec4a488e14a.tar.bz2 |
Revert "Revert 195733 "Enable virtual resolution on low DPI displays""
Reverted wrong CL by mistake
TBR=oshima@chromium.org
BUG=none
Review URL: https://codereview.chromium.org/14081019
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@195742 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash')
-rw-r--r-- | ash/accelerators/accelerator_controller.cc | 2 | ||||
-rw-r--r-- | ash/ash_root_window_transformer.cc | 4 | ||||
-rw-r--r-- | ash/ash_switches.cc | 8 | ||||
-rw-r--r-- | ash/ash_switches.h | 2 | ||||
-rw-r--r-- | ash/display/display_controller_unittest.cc | 16 | ||||
-rw-r--r-- | ash/display/display_info.cc | 7 | ||||
-rw-r--r-- | ash/display/display_manager.cc | 113 | ||||
-rw-r--r-- | ash/display/display_manager.h | 2 | ||||
-rw-r--r-- | ash/display/display_manager_unittest.cc | 48 |
9 files changed, 128 insertions, 74 deletions
diff --git a/ash/accelerators/accelerator_controller.cc b/ash/accelerators/accelerator_controller.cc index 6450c87..07b92f2 100644 --- a/ash/accelerators/accelerator_controller.cc +++ b/ash/accelerators/accelerator_controller.cc @@ -180,7 +180,7 @@ bool HandleScaleUI(bool up) { return false; const DisplayInfo& display_info = display_manager->GetDisplayInfo(display_id); float next_scale = - internal::DisplayManager::GetNextUIScale(display_info.ui_scale(), up); + internal::DisplayManager::GetNextUIScale(display_info, up); display_manager->SetDisplayUIScale(display_id, next_scale); return true; } diff --git a/ash/ash_root_window_transformer.cc b/ash/ash_root_window_transformer.cc index 2cfb019..e0aa26c 100644 --- a/ash/ash_root_window_transformer.cc +++ b/ash/ash_root_window_transformer.cc @@ -51,10 +51,6 @@ gfx::Rect AshRootWindowTransformer::GetRootWindowBounds( bounds = ui::ConvertRectToDIP(root_window_->layer(), bounds); gfx::RectF new_bounds(bounds); root_window_->layer()->transform().TransformRect(&new_bounds); - // It makes little sense to scale beyond the original - // resolution. - DCHECK_LE(root_window_scale_, - ui::GetDeviceScaleFactor(root_window_->layer())); // Apply |root_window_scale_| twice as the downscaling // is already applied once in |SetTransformInternal()|. // TODO(oshima): This is a bit ugly. Consider specifying diff --git a/ash/ash_switches.cc b/ash/ash_switches.cc index 3cf177b..696e8c3 100644 --- a/ash/ash_switches.cc +++ b/ash/ash_switches.cc @@ -106,9 +106,6 @@ const char kAshHostWindowBounds[] = "ash-host-window-bounds"; const char kAshImmersiveHideTabIndicators[] = "ash-immersive-hide-tab-indicators"; -// Specifies the internal display's ui scale. -const char kAshInternalDisplayUIScale[] = "ash-internal-display-ui-scale"; - // Specifies the layout mode and offsets for the secondary display for // testing. The format is "<t|r|b|l>,<offset>" where t=TOP, r=RIGHT, // b=BOTTOM and L=LEFT. For example, 'r,-100' means the secondary display @@ -118,6 +115,11 @@ const char kAshSecondaryDisplayLayout[] = "ash-secondary-display-layout"; // Enables the heads-up display for tracking touch points. const char kAshTouchHud[] = "ash-touch-hud"; +// Uses the 1st display in --ash-host-window-bounds as internal display. +// This is for debugging on linux desktop. +const char kAshUseFirstDisplayAsInternal[] = + "ash-use-first-display-as-internal"; + // (Most) Chrome OS hardware reports ACPI power button releases correctly. // Standard hardware reports releases immediately after presses. If set, we // lock the screen or shutdown the system immediately in response to a press diff --git a/ash/ash_switches.h b/ash/ash_switches.h index 57b5c64..80e9160 100644 --- a/ash/ash_switches.h +++ b/ash/ash_switches.h @@ -45,9 +45,9 @@ ASH_EXPORT extern const char kAshEnableTrayDragging[]; ASH_EXPORT extern const char kAshEnableWorkspaceScrubbing[]; ASH_EXPORT extern const char kAshHostWindowBounds[]; ASH_EXPORT extern const char kAshImmersiveHideTabIndicators[]; -ASH_EXPORT extern const char kAshInternalDisplayUIScale[]; ASH_EXPORT extern const char kAshSecondaryDisplayLayout[]; ASH_EXPORT extern const char kAshTouchHud[]; +ASH_EXPORT extern const char kAshUseFirstDisplayAsInternal[]; ASH_EXPORT extern const char kAuraLegacyPowerButton[]; #if defined(OS_WIN) ASH_EXPORT extern const char kForceAshToDesktop[]; diff --git a/ash/display/display_controller_unittest.cc b/ash/display/display_controller_unittest.cc index c9ecff4..84f615f 100644 --- a/ash/display/display_controller_unittest.cc +++ b/ash/display/display_controller_unittest.cc @@ -319,14 +319,16 @@ TEST_F(DisplayControllerTest, BoundsUpdated) { display_manager->SetDisplayRotation(primary_id, gfx::Display::ROTATE_90); EXPECT_EQ(0, observer.CountAndReset()); - // UI scale is eanbled only on internal display (=1st display in unittest). + // UI scale is eanbled only on internal display. int64 secondary_id = GetSecondaryDisplay().id(); gfx::Display::SetInternalDisplayId(secondary_id); - display_manager->SetDisplayUIScale(secondary_id, 1.25f); - EXPECT_EQ(0, observer.CountAndReset()); - display_manager->SetDisplayUIScale(primary_id, 1.25f); + display_manager->SetDisplayUIScale(secondary_id, 1.125f); EXPECT_EQ(1, observer.CountAndReset()); - display_manager->SetDisplayUIScale(primary_id, 1.25f); + display_manager->SetDisplayUIScale(secondary_id, 1.125f); + EXPECT_EQ(0, observer.CountAndReset()); + display_manager->SetDisplayUIScale(primary_id, 1.125f); + EXPECT_EQ(0, observer.CountAndReset()); + display_manager->SetDisplayUIScale(primary_id, 1.125f); EXPECT_EQ(0, observer.CountAndReset()); } @@ -817,6 +819,8 @@ TEST_F(DisplayControllerTest, MAYBE_ScaleRootWindow) { UpdateDisplay("600x400*2@1.5,500x300"); gfx::Display display1 = Shell::GetScreen()->GetPrimaryDisplay(); + gfx::Display::SetInternalDisplayId(display1.id()); + gfx::Display display2 = ScreenAsh::GetSecondaryDisplay(); Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); EXPECT_EQ("0,0 450x300", display1.bounds().ToString()); @@ -831,7 +835,7 @@ TEST_F(DisplayControllerTest, MAYBE_ScaleRootWindow) { internal::DisplayManager* display_manager = Shell::GetInstance()->display_manager(); - display_manager->SetDisplayUIScale(display1.id(), 1.25); + display_manager->SetDisplayUIScale(display1.id(), 1.25f); display1 = Shell::GetScreen()->GetPrimaryDisplay(); display2 = ScreenAsh::GetSecondaryDisplay(); EXPECT_EQ("0,0 375x250", display1.bounds().ToString()); diff --git a/ash/display/display_info.cc b/ash/display/display_info.cc index 2b8fb54..fa72bdc 100644 --- a/ash/display/display_info.cc +++ b/ash/display/display_info.cc @@ -148,13 +148,6 @@ void DisplayInfo::Copy(const DisplayInfo& native_info) { rotation_ = native_info.rotation_; ui_scale_ = native_info.ui_scale_; } - // It makes little sense to scale beyond the original - // resolution. This guard is to protect applying - // ui_scale to an external display whose DPI has changed - // from 2.0 to 1.0 for some reason. - if (ui_scale_ > device_scale_factor_) - ui_scale_ = 1.0f; - // Don't copy insets as it may be given by preference. |rotation_| // is treated as a native so that it can be specified in // |CreateFromSpec|. diff --git a/ash/display/display_manager.cc b/ash/display/display_manager.cc index 3e38236..bb5a148 100644 --- a/ash/display/display_manager.cc +++ b/ash/display/display_manager.cc @@ -4,6 +4,7 @@ #include "ash/display/display_manager.h" +#include <cmath> #include <set> #include <string> #include <vector> @@ -55,11 +56,13 @@ typedef std::vector<DisplayInfo> DisplayInfoList; namespace { -// List of value UI Scale values. These scales are equivalent to 640, 800, 1024, -// 1280, 1440, 1600 and 1920 pixel width respectively on 2560 pixel width 2x -// density display. -const float kUIScales[] = {0.5f, 0.625f, 0.8f, 1.0f, 1.125f, 1.25f, 1.5f}; -const size_t kUIScaleTableSize = arraysize(kUIScales); +// 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}; +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) { @@ -73,19 +76,47 @@ struct DisplayInfoSortFunctor { } }; +struct ScaleComparator { + ScaleComparator(float s) : scale(s) {} + + bool operator()(float s) const { + const float kEpsilon = 0.0001f; + return std::abs(scale - s) < kEpsilon; + } + float scale; +}; + +std::vector<float> GetScalesForDisplay(const DisplayInfo& info) { + std::vector<float> ret; + if (info.device_scale_factor() == 2.0f) { + ret.assign(kUIScalesFor2x, kUIScalesFor2x + arraysize(kUIScalesFor2x)); + return ret; + } + switch (info.bounds_in_pixel().width()) { + case 1280: + ret.assign(kUIScalesFor1280, + kUIScalesFor1280 + arraysize(kUIScalesFor1280)); + break; + case 1366: + ret.assign(kUIScalesFor1366, + kUIScalesFor1366 + arraysize(kUIScalesFor1366)); + break; + default: + ret.assign(kUIScalesFor1280, + kUIScalesFor1280 + arraysize(kUIScalesFor1280)); +#if defined(OS_CHROMEOS) + if (base::chromeos::IsRunningOnChromeOS()) + NOTREACHED() << "Unknown resolution:" << info.ToString(); +#endif + } + return ret; +} + gfx::Display& GetInvalidDisplay() { static gfx::Display* invalid_display = new gfx::Display(); return *invalid_display; } -bool IsValidUIScale(float scale) { - for (size_t i = 0; i < kUIScaleTableSize; ++i) { - if (kUIScales[i] == scale) - return true; - } - return false; -} - } // namespace using aura::RootWindow; @@ -122,14 +153,16 @@ void DisplayManager::ToggleDisplayScaleFactor() { } // static -float DisplayManager::GetNextUIScale(float scale, bool up) { - for (size_t i = 0; i < kUIScaleTableSize; ++i) { - if (kUIScales[i] == scale) { - if (up && i != kUIScaleTableSize -1) - return kUIScales[i + 1]; +float DisplayManager::GetNextUIScale(const DisplayInfo& info, bool up) { + float scale = info.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 kUIScales[i - 1]; - return kUIScales[i]; + return scales[i - 1]; + return scales[i]; } } // Fallback to 1.0f if the |scale| wasn't in the list. @@ -221,8 +254,10 @@ void DisplayManager::SetDisplayRotation(int64 display_id, void DisplayManager::SetDisplayUIScale(int64 display_id, float ui_scale) { - if (!IsDisplayUIScalingEnabled() || !IsValidUIScale(ui_scale)) + if (!IsDisplayUIScalingEnabled() || + gfx::Display::InternalDisplayId() != display_id) { return; + } DisplayInfoList display_info_list; for (DisplayList::const_iterator iter = displays_.begin(); @@ -231,6 +266,12 @@ void DisplayManager::SetDisplayUIScale(int64 display_id, if (info.id() == display_id) { if (info.ui_scale() == ui_scale) return; + std::vector<float> scales = GetScalesForDisplay(info); + ScaleComparator comparator(ui_scale); + if (std::find_if(scales.begin(), scales.end(), comparator) == + scales.end()) { + return; + } info.set_ui_scale(ui_scale); } display_info_list.push_back(info); @@ -249,7 +290,8 @@ void DisplayManager::RegisterDisplayProperty( } display_info_[display_id].set_rotation(rotation); - if (IsValidUIScale(ui_scale)) + // Just in case the preference file was corrupted. + if (0.5f <= ui_scale && ui_scale <= 2.0f) display_info_[display_id].set_ui_scale(ui_scale); if (overscan_insets) display_info_[display_id].SetOverscanInsets(true, *overscan_insets); @@ -586,15 +628,10 @@ void DisplayManager::OnRootWindowResized(const aura::RootWindow* root, int64 DisplayManager::GetDisplayIdForUIScaling() const { // UI Scaling is effective only on internal display. int64 display_id = gfx::Display::InternalDisplayId(); -#if defined(OS_CHROMEOS) - // On linux desktop, allow ui scalacing on the first dislpay. - if (!base::chromeos::IsRunningOnChromeOS()) - display_id = first_display_id(); -#elif defined(OS_WIN) +#if defined(OS_WIN) display_id = first_display_id(); #endif - return GetDisplayForId(display_id).device_scale_factor() == 2.0f ? - display_id : gfx::Display::kInvalidDisplayID; + return display_id; } void DisplayManager::Init() { @@ -610,6 +647,9 @@ void DisplayManager::Init() { if (displays_.empty()) AddDisplayFromSpec(std::string() /* default */); first_display_id_ = displays_[0].id(); + CommandLine* command_line = CommandLine::ForCurrentProcess(); + if (command_line->HasSwitch(switches::kAshUseFirstDisplayAsInternal)) + gfx::Display::SetInternalDisplayId(first_display_id_); num_connected_displays_ = displays_.size(); } @@ -681,21 +721,6 @@ void DisplayManager::InsertAndUpdateDisplayInfo(const DisplayInfo& new_info) { display_info_[new_info.id()] = new_info; display_info_[new_info.id()].set_native(false); } - bool on_chromeos = false; -#if defined(OS_CHROMEOS) - on_chromeos = base::chromeos::IsRunningOnChromeOS(); -#endif - CommandLine* command_line = CommandLine::ForCurrentProcess(); - if ((new_info.id() == gfx::Display::InternalDisplayId() || !on_chromeos) && - command_line->HasSwitch(switches::kAshInternalDisplayUIScale)) { - double scale_in_double = 1.0; - std::string value = CommandLine::ForCurrentProcess()-> - GetSwitchValueASCII(switches::kAshInternalDisplayUIScale); - if (!base::StringToDouble(value, &scale_in_double)) - LOG(ERROR) << "Failed to parse the display scale:" << value; - display_info_[new_info.id()].set_ui_scale(scale_in_double); - } - display_info_[new_info.id()].UpdateDisplaySize(); } diff --git a/ash/display/display_manager.h b/ash/display/display_manager.h index b63aec4..ffd4e18 100644 --- a/ash/display/display_manager.h +++ b/ash/display/display_manager.h @@ -45,7 +45,7 @@ class ASH_EXPORT DisplayManager : public aura::RootWindowObserver { static void ToggleDisplayScaleFactor(); // Returns next valid UI scale. - static float GetNextUIScale(float scale, bool up); + static float GetNextUIScale(const DisplayInfo& info, bool up); // When set to true, the MonitorManager calls OnDisplayBoundsChanged // even if the display's bounds didn't change. Used to swap primary diff --git a/ash/display/display_manager_unittest.cc b/ash/display/display_manager_unittest.cc index 7ddb8a5..66ad123 100644 --- a/ash/display/display_manager_unittest.cc +++ b/ash/display/display_manager_unittest.cc @@ -714,25 +714,55 @@ TEST_F(DisplayManagerTest, Rotate) { } TEST_F(DisplayManagerTest, UIScale) { - // 1x display does not support scaling. - UpdateDisplay("100x200"); + UpdateDisplay("1280x800"); int64 display_id = Shell::GetScreen()->GetPrimaryDisplay().id(); + display_manager()->SetDisplayUIScale(display_id, 1.125f); + EXPECT_EQ(1.0, GetDisplayInfoAt(0).ui_scale()); + display_manager()->SetDisplayUIScale(display_id, 0.8f); + EXPECT_EQ(1.0f, GetDisplayInfoAt(0).ui_scale()); + display_manager()->SetDisplayUIScale(display_id, 0.75f); + EXPECT_EQ(1.0f, GetDisplayInfoAt(0).ui_scale()); + display_manager()->SetDisplayUIScale(display_id, 0.625f); + EXPECT_EQ(1.0f, GetDisplayInfoAt(0).ui_scale()); + + gfx::Display::SetInternalDisplayId(display_id); display_manager()->SetDisplayUIScale(display_id, 1.5f); EXPECT_EQ(1.0f, GetDisplayInfoAt(0).ui_scale()); display_manager()->SetDisplayUIScale(display_id, 1.25f); EXPECT_EQ(1.0f, GetDisplayInfoAt(0).ui_scale()); display_manager()->SetDisplayUIScale(display_id, 1.125f); - EXPECT_EQ(1.0, GetDisplayInfoAt(0).ui_scale()); + EXPECT_EQ(1.125f, GetDisplayInfoAt(0).ui_scale()); display_manager()->SetDisplayUIScale(display_id, 0.8f); - EXPECT_EQ(1.0f, GetDisplayInfoAt(0).ui_scale()); + EXPECT_EQ(0.8f, GetDisplayInfoAt(0).ui_scale()); + display_manager()->SetDisplayUIScale(display_id, 0.75f); + EXPECT_EQ(0.8f, GetDisplayInfoAt(0).ui_scale()); display_manager()->SetDisplayUIScale(display_id, 0.625f); - EXPECT_EQ(1.0f, GetDisplayInfoAt(0).ui_scale()); + EXPECT_EQ(0.625f, GetDisplayInfoAt(0).ui_scale()); + display_manager()->SetDisplayUIScale(display_id, 0.6f); + EXPECT_EQ(0.625f, GetDisplayInfoAt(0).ui_scale()); display_manager()->SetDisplayUIScale(display_id, 0.5f); + EXPECT_EQ(0.5f, GetDisplayInfoAt(0).ui_scale()); + + UpdateDisplay("1366x768"); + display_manager()->SetDisplayUIScale(display_id, 1.5f); EXPECT_EQ(1.0f, GetDisplayInfoAt(0).ui_scale()); + display_manager()->SetDisplayUIScale(display_id, 1.25f); + EXPECT_EQ(1.0f, GetDisplayInfoAt(0).ui_scale()); + display_manager()->SetDisplayUIScale(display_id, 1.125f); + EXPECT_EQ(1.125f, GetDisplayInfoAt(0).ui_scale()); + display_manager()->SetDisplayUIScale(display_id, 0.8f); + EXPECT_EQ(1.125f, GetDisplayInfoAt(0).ui_scale()); + display_manager()->SetDisplayUIScale(display_id, 0.75f); + EXPECT_EQ(0.75f, GetDisplayInfoAt(0).ui_scale()); + display_manager()->SetDisplayUIScale(display_id, 0.6f); + EXPECT_EQ(0.6f, GetDisplayInfoAt(0).ui_scale()); + display_manager()->SetDisplayUIScale(display_id, 0.625f); + EXPECT_EQ(0.6f, GetDisplayInfoAt(0).ui_scale()); + display_manager()->SetDisplayUIScale(display_id, 0.5f); + EXPECT_EQ(0.5f, GetDisplayInfoAt(0).ui_scale()); - // 2x display supports all scales. - UpdateDisplay("100x200*2"); + UpdateDisplay("1280x850*2"); EXPECT_EQ(1.0f, GetDisplayInfoAt(0).ui_scale()); display_manager()->SetDisplayUIScale(display_id, 1.5f); EXPECT_EQ(1.5f, GetDisplayInfoAt(0).ui_scale()); @@ -742,8 +772,12 @@ TEST_F(DisplayManagerTest, UIScale) { EXPECT_EQ(1.125f, GetDisplayInfoAt(0).ui_scale()); display_manager()->SetDisplayUIScale(display_id, 0.8f); EXPECT_EQ(0.8f, GetDisplayInfoAt(0).ui_scale()); + display_manager()->SetDisplayUIScale(display_id, 0.75f); + EXPECT_EQ(0.8f, GetDisplayInfoAt(0).ui_scale()); display_manager()->SetDisplayUIScale(display_id, 0.625f); EXPECT_EQ(0.625f, GetDisplayInfoAt(0).ui_scale()); + display_manager()->SetDisplayUIScale(display_id, 0.6f); + EXPECT_EQ(0.625f, GetDisplayInfoAt(0).ui_scale()); display_manager()->SetDisplayUIScale(display_id, 0.5f); EXPECT_EQ(0.5f, GetDisplayInfoAt(0).ui_scale()); } |