diff options
author | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-22 21:13:31 +0000 |
---|---|---|
committer | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-22 21:13:31 +0000 |
commit | 8b2447ecbe6d9816975fd2978a439332cd3a78cb (patch) | |
tree | 81e901ec326c1fcecd6c38636848d5bf102972d1 /ash | |
parent | 7c6942232d73e06fa7e6cc94bc9e4017710ffe79 (diff) | |
download | chromium_src-8b2447ecbe6d9816975fd2978a439332cd3a78cb.zip chromium_src-8b2447ecbe6d9816975fd2978a439332cd3a78cb.tar.gz chromium_src-8b2447ecbe6d9816975fd2978a439332cd3a78cb.tar.bz2 |
- Store rotation/ui scale to local state.
- Reset the overscan to the default value if the display has overscan.
- Move overscan data into kDisplayProperties dictionary value.
- Remove Rotate/Scale shortcut from login screen as we can't store the state in login screen.
BUG=196818
TEST=covered by unit test.
Review URL: https://codereview.chromium.org/12505005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@189910 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash')
-rw-r--r-- | ash/accelerators/accelerator_controller.cc | 27 | ||||
-rw-r--r-- | ash/accelerators/accelerator_table.cc | 3 | ||||
-rw-r--r-- | ash/dip_unittest.cc | 2 | ||||
-rw-r--r-- | ash/display/display_change_observer_x11.cc | 1 | ||||
-rw-r--r-- | ash/display/display_controller.cc | 37 | ||||
-rw-r--r-- | ash/display/display_controller.h | 3 | ||||
-rw-r--r-- | ash/display/display_controller_unittest.cc | 40 | ||||
-rw-r--r-- | ash/display/display_info.cc | 25 | ||||
-rw-r--r-- | ash/display/display_info.h | 18 | ||||
-rw-r--r-- | ash/display/display_manager.cc | 85 | ||||
-rw-r--r-- | ash/display/display_manager.h | 20 | ||||
-rw-r--r-- | ash/display/display_manager_unittest.cc | 2 | ||||
-rw-r--r-- | ash/shell.cc | 3 | ||||
-rw-r--r-- | ash/test/display_manager_test_api.cc | 2 |
14 files changed, 191 insertions, 77 deletions
diff --git a/ash/accelerators/accelerator_controller.cc b/ash/accelerators/accelerator_controller.cc index 79f8f41..9a1f309 100644 --- a/ash/accelerators/accelerator_controller.cc +++ b/ash/accelerators/accelerator_controller.cc @@ -170,24 +170,6 @@ gfx::Display::Rotation GetNextRotation(gfx::Display::Rotation current) { return gfx::Display::ROTATE_0; } -float GetNextScale(float scale, bool up) { - // These scales are equivalent to 1024, 1280, 1600 and 1920 pixel width - // respectively on 2560 pixel width 2x density display. - static const float kScales[] = {0.8f, 1.0f, 1.25f, 1.5f}; - static const size_t kScaleTableSize = arraysize(kScales); - for (size_t i = 0; i < kScaleTableSize; ++i) { - if (kScales[i] == scale) { - if (up && i != kScaleTableSize -1) - return kScales[i + 1]; - if (!up && i != 0) - return kScales[i - 1]; - return kScales[i]; - } - } - // Fallback to 1.0f if the |scale| wasn't in the list. - return 1.0f; -} - bool HandleScaleUI(bool up) { // UI Scaling is effective only on internal display. int64 display_id = gfx::Display::InternalDisplayId(); @@ -196,12 +178,11 @@ bool HandleScaleUI(bool up) { if (!base::chromeos::IsRunningOnChromeOS()) display_id = Shell::GetInstance()->display_manager()->first_display_id(); #endif - const gfx::Display& display = Shell::GetInstance()->display_manager()-> - GetDisplayForId(display_id); const DisplayInfo& display_info = Shell::GetInstance()->display_manager()-> - GetDisplayInfo(display); + GetDisplayInfo(display_id); Shell::GetInstance()->display_manager()->SetDisplayUIScale( - display.id(), GetNextScale(display_info.ui_scale(), up)); + display_id, + internal::DisplayManager::GetNextUIScale(display_info.ui_scale(), up)); return true; } @@ -210,7 +191,7 @@ bool HandleRotateScreen() { gfx::Point point = Shell::GetScreen()->GetCursorScreenPoint(); gfx::Display display = Shell::GetScreen()->GetDisplayNearestPoint(point); const DisplayInfo& display_info = - Shell::GetInstance()->display_manager()->GetDisplayInfo(display); + Shell::GetInstance()->display_manager()->GetDisplayInfo(display.id()); Shell::GetInstance()->display_manager()->SetDisplayRotation( display.id(), GetNextRotation(display_info.rotation())); return true; diff --git a/ash/accelerators/accelerator_table.cc b/ash/accelerators/accelerator_table.cc index 75e858d..a8b21ca 100644 --- a/ash/accelerators/accelerator_table.cc +++ b/ash/accelerators/accelerator_table.cc @@ -241,10 +241,7 @@ const AcceleratorAction kActionsAllowedAtLoginOrLockScreen[] = { VOLUME_DOWN, VOLUME_MUTE, VOLUME_UP, - ROTATE_SCREEN, ROTATE_WINDOW, - SCALE_UI_UP, - SCALE_UI_DOWN, #if !defined(NDEBUG) PRINT_LAYER_HIERARCHY, PRINT_VIEW_HIERARCHY, diff --git a/ash/dip_unittest.cc b/ash/dip_unittest.cc index c21fb88..9869a01 100644 --- a/ash/dip_unittest.cc +++ b/ash/dip_unittest.cc @@ -47,7 +47,7 @@ TEST_F(DIPTest, WorkArea) { const gfx::Display display_2x = screen->GetDisplayNearestWindow(root); const internal::DisplayInfo display_info_2x = - Shell::GetInstance()->display_manager()->GetDisplayInfo(display_2x); + Shell::GetInstance()->display_manager()->GetDisplayInfo(display_2x.id()); // The |bounds_in_pixel()| should report bounds in pixel coordinate. EXPECT_EQ("1,1 2000x1800", diff --git a/ash/display/display_change_observer_x11.cc b/ash/display/display_change_observer_x11.cc index 3f3f9bb..c7539a3 100644 --- a/ash/display/display_change_observer_x11.cc +++ b/ash/display/display_change_observer_x11.cc @@ -196,6 +196,7 @@ void DisplayChangeObserverX11::OnDisplayModeChanged() { displays.push_back(DisplayInfo(id, name, has_overscan)); displays.back().set_device_scale_factor(device_scale_factor); displays.back().SetBounds(display_bounds); + displays.back().set_native(true); } // Free all allocated resources. diff --git a/ash/display/display_controller.cc b/ash/display/display_controller.cc index af5e2d6..e777dfc 100644 --- a/ash/display/display_controller.cc +++ b/ash/display/display_controller.cc @@ -48,7 +48,7 @@ DECLARE_WINDOW_PROPERTY_TYPE(gfx::Display::Rotation); namespace ash { namespace { -DEFINE_WINDOW_PROPERTY_KEY(gfx::Display::Rotation, kRotationKey, +DEFINE_WINDOW_PROPERTY_KEY(gfx::Display::Rotation, kRotationPropertyKey, gfx::Display::ROTATE_0); // Primary display stored in global object as it can be @@ -79,6 +79,10 @@ const int64 kAfterDisplayChangeThrottleTimeoutMs = 500; const int64 kCycleDisplayThrottleTimeoutMs = 4000; const int64 kSwapDisplayThrottleTimeoutMs = 500; +// Persistent key names +const char kPositionKey[] = "position"; +const char kOffsetKey[] = "offset"; + bool GetPositionFromString(const base::StringPiece& position, DisplayLayout::Position* field) { if (position == "top") { @@ -125,9 +129,9 @@ void RotateRootWindow(aura::RootWindow* root_window, // updating the transform results in incorrectly resizing // the root window. Don't apply the transform unless // necessary so that unit tests pass on win8 bots. - if (info.rotation() == root_window->GetProperty(kRotationKey)) + if (info.rotation() == root_window->GetProperty(kRotationPropertyKey)) return; - root_window->SetProperty(kRotationKey, info.rotation()); + root_window->SetProperty(kRotationPropertyKey, info.rotation()); #endif gfx::Transform rotate; // The origin is (0, 0), so the translate width/height must be reduced by 1. @@ -153,7 +157,8 @@ void RotateRootWindow(aura::RootWindow* root_window, void SetDisplayPropertiesOnHostWindow(aura::RootWindow* root, const gfx::Display& display) { - internal::DisplayInfo info = GetDisplayManager()->GetDisplayInfo(display); + internal::DisplayInfo info = + GetDisplayManager()->GetDisplayInfo(display.id()); #if defined(OS_CHROMEOS) // Native window property (Atom in X11) that specifies the display's // rotation, scale factor and if it's internal display. They are @@ -256,8 +261,8 @@ bool DisplayLayout::ConvertToValue(const DisplayLayout& layout, return false; const std::string position_str = GetStringFromPosition(layout.position); - dict_value->SetString("position", position_str); - dict_value->SetInteger("offset", layout.offset); + dict_value->SetString(kPositionKey, position_str); + dict_value->SetInteger(kOffsetKey, layout.offset); return true; } @@ -270,8 +275,8 @@ std::string DisplayLayout::ToString() const { void DisplayLayout::RegisterJSONConverter( base::JSONValueConverter<DisplayLayout>* converter) { converter->RegisterCustomField<Position>( - "position", &DisplayLayout::position, &GetPositionFromString); - converter->RegisterIntField("offset", &DisplayLayout::offset); + kPositionKey, &DisplayLayout::position, &GetPositionFromString); + converter->RegisterIntField(kOffsetKey, &DisplayLayout::offset); } //////////////////////////////////////////////////////////////////////////////// @@ -326,14 +331,16 @@ DisplayController::DisplayController() delete primary_display_for_shutdown; primary_display_for_shutdown = NULL; num_displays_for_shutdown = -1; - - Shell::GetScreen()->AddObserver(this); } DisplayController::~DisplayController() { DCHECK(primary_display_for_shutdown); } +void DisplayController::Start() { + Shell::GetScreen()->AddObserver(this); +} + void DisplayController::Shutdown() { DCHECK(!primary_display_for_shutdown); primary_display_for_shutdown = new gfx::Display( @@ -666,9 +673,9 @@ void DisplayController::SetPrimaryDisplay( // Update the dispay manager with new display info. std::vector<internal::DisplayInfo> display_info_list; display_info_list.push_back(display_manager->GetDisplayInfo( - display_manager->GetDisplayForId(primary_display_id))); + primary_display_id)); display_info_list.push_back(display_manager->GetDisplayInfo( - *GetSecondaryDisplay())); + GetSecondaryDisplay()->id())); GetDisplayManager()->set_force_bounds_changed(true); GetDisplayManager()->UpdateDisplays(display_info_list); GetDisplayManager()->set_force_bounds_changed(false); @@ -685,7 +692,7 @@ void DisplayController::OnDisplayBoundsChanged(const gfx::Display& display) { if (limiter_.get()) limiter_->SetThrottleTimeout(kAfterDisplayChangeThrottleTimeoutMs); const internal::DisplayInfo& display_info = - GetDisplayManager()->GetDisplayInfo(display); + GetDisplayManager()->GetDisplayInfo(display.id()); DCHECK(!display_info.bounds_in_pixel().IsEmpty()); UpdateDisplayBoundsForLayout(); @@ -710,7 +717,7 @@ void DisplayController::OnDisplayAdded(const gfx::Display& display) { primary_root_window_for_replace_ = NULL; UpdateDisplayBoundsForLayout(); const internal::DisplayInfo& display_info = - GetDisplayManager()->GetDisplayInfo(display); + GetDisplayManager()->GetDisplayInfo(display.id()); root_windows_[display.id()]->SetHostBoundsAndInsetsAndRootWindowScale( display_info.bounds_in_pixel(), display_info.GetOverscanInsetsInPixel(), @@ -775,7 +782,7 @@ aura::RootWindow* DisplayController::CreateRootWindowForDisplay( const gfx::Display& display) { static int root_window_count = 0; const internal::DisplayInfo& display_info = - GetDisplayManager()->GetDisplayInfo(display); + GetDisplayManager()->GetDisplayInfo(display.id()); const gfx::Rect& bounds_in_pixel = display_info.bounds_in_pixel(); aura::RootWindow::CreateParams params(bounds_in_pixel); params.host = Shell::GetInstance()->root_window_host_factory()-> diff --git a/ash/display/display_controller.h b/ash/display/display_controller.h index 051704c..3927dc2 100644 --- a/ash/display/display_controller.h +++ b/ash/display/display_controller.h @@ -94,6 +94,7 @@ class ASH_EXPORT DisplayController : public gfx::DisplayObserver { DisplayController(); virtual ~DisplayController(); + void Start(); void Shutdown(); // Returns primary display. This is safe to use after ash::Shell is @@ -166,6 +167,8 @@ class ASH_EXPORT DisplayController : public gfx::DisplayObserver { void RegisterLayoutForDisplayIdPair(int64 id1, int64 id2, const DisplayLayout& layout); + // OBSOLETE + // TODO(oshima): Remove this in m28. void RegisterLayoutForDisplayId(int64 id, const DisplayLayout& layout); // Sets the layout for the current display pair. The |layout| specifies diff --git a/ash/display/display_controller_unittest.cc b/ash/display/display_controller_unittest.cc index d1713f0..1f221c5 100644 --- a/ash/display/display_controller_unittest.cc +++ b/ash/display/display_controller_unittest.cc @@ -122,6 +122,14 @@ class TestEventHandler : public ui::EventHandler { DISALLOW_COPY_AND_ASSIGN(TestEventHandler); }; +gfx::Display::Rotation GetStoredRotation(int64 id) { + return Shell::GetInstance()->display_manager()->GetDisplayInfo(id).rotation(); +} + +float GetStoredUIScale(int64 id) { + return Shell::GetInstance()->display_manager()->GetDisplayInfo(id).ui_scale(); +} + } // namespace typedef test::AshTestBase DisplayControllerTest; @@ -459,9 +467,10 @@ TEST_F(DisplayControllerTest, SwapPrimaryById) { // Adding 2nd display with the same ID. The 2nd display should become primary // since secondary id is still stored as desirable_primary_id. std::vector<internal::DisplayInfo> display_info_list; - display_info_list.push_back(display_manager->GetDisplayInfo(primary_display)); display_info_list.push_back( - display_manager->GetDisplayInfo(secondary_display)); + display_manager->GetDisplayInfo(primary_display.id())); + display_info_list.push_back( + display_manager->GetDisplayInfo(secondary_display.id())); display_manager->OnNativeDisplaysChanged(display_info_list); EXPECT_EQ(2, Shell::GetScreen()->GetNumDisplays()); @@ -485,7 +494,7 @@ TEST_F(DisplayControllerTest, SwapPrimaryById) { ASSERT_NE(primary_display.id(), third_display_info.id()); const internal::DisplayInfo& primary_display_info = - display_manager->GetDisplayInfo(primary_display); + display_manager->GetDisplayInfo(primary_display.id()); std::vector<internal::DisplayInfo> display_info_list2; display_info_list2.push_back(primary_display_info); display_info_list2.push_back(third_display_info); @@ -664,6 +673,8 @@ TEST_F(DisplayControllerTest, MAYBE_Rotate) { ScreenAsh::GetSecondaryDisplay().bounds().ToString()); generator1.MoveMouseTo(50, 40); EXPECT_EQ("50,40", event_handler.GetLocationAndReset()); + EXPECT_EQ(gfx::Display::ROTATE_0, GetStoredRotation(display1.id())); + EXPECT_EQ(gfx::Display::ROTATE_0, GetStoredRotation(display2_id)); display_manager->SetDisplayRotation(display1.id(), gfx::Display::ROTATE_90); @@ -673,6 +684,8 @@ TEST_F(DisplayControllerTest, MAYBE_Rotate) { ScreenAsh::GetSecondaryDisplay().bounds().ToString()); generator1.MoveMouseTo(50, 40); EXPECT_EQ("40,69", event_handler.GetLocationAndReset()); + EXPECT_EQ(gfx::Display::ROTATE_90, GetStoredRotation(display1.id())); + EXPECT_EQ(gfx::Display::ROTATE_0, GetStoredRotation(display2_id)); DisplayLayout display_layout(DisplayLayout::BOTTOM, 50); display_controller->SetLayoutForCurrentDisplays(display_layout); @@ -685,6 +698,8 @@ TEST_F(DisplayControllerTest, MAYBE_Rotate) { EXPECT_EQ("200x150", root_windows[1]->bounds().size().ToString()); EXPECT_EQ("50,120 200x150", ScreenAsh::GetSecondaryDisplay().bounds().ToString()); + EXPECT_EQ(gfx::Display::ROTATE_90, GetStoredRotation(display1.id())); + EXPECT_EQ(gfx::Display::ROTATE_270, GetStoredRotation(display2_id)); aura::test::EventGenerator generator2(root_windows[1]); generator2.MoveMouseTo(50, 40); @@ -697,6 +712,8 @@ TEST_F(DisplayControllerTest, MAYBE_Rotate) { // Dislay must share at least 100, so the x's offset becomes 20. EXPECT_EQ("20,200 200x150", ScreenAsh::GetSecondaryDisplay().bounds().ToString()); + EXPECT_EQ(gfx::Display::ROTATE_180, GetStoredRotation(display1.id())); + EXPECT_EQ(gfx::Display::ROTATE_270, GetStoredRotation(display2_id)); generator1.MoveMouseTo(50, 40); EXPECT_EQ("69,159", event_handler.GetLocationAndReset()); @@ -717,17 +734,32 @@ TEST_F(DisplayControllerTest, MAYBE_ScaleRootWindow) { TestEventHandler event_handler; Shell::GetInstance()->AddPreTargetHandler(&event_handler); - UpdateDisplay("600x400*2@1.5"); + UpdateDisplay("600x400*2@1.5,500x300"); gfx::Display display1 = Shell::GetScreen()->GetPrimaryDisplay(); + gfx::Display display2 = ScreenAsh::GetSecondaryDisplay(); Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); EXPECT_EQ("0,0 450x300", display1.bounds().ToString()); EXPECT_EQ("0,0 450x300", root_windows[0]->bounds().ToString()); + EXPECT_EQ("450,0 500x300", display2.bounds().ToString()); + EXPECT_EQ(1.5f, GetStoredUIScale(display1.id())); + EXPECT_EQ(1.0f, GetStoredUIScale(display2.id())); aura::test::EventGenerator generator(root_windows[0]); generator.MoveMouseTo(599, 200); EXPECT_EQ("449,150", event_handler.GetLocationAndReset()); + internal::DisplayManager* display_manager = + Shell::GetInstance()->display_manager(); + display_manager->SetDisplayUIScale(display1.id(), 1.25); + display1 = Shell::GetScreen()->GetPrimaryDisplay(); + display2 = ScreenAsh::GetSecondaryDisplay(); + EXPECT_EQ("0,0 375x250", display1.bounds().ToString()); + EXPECT_EQ("0,0 375x250", root_windows[0]->bounds().ToString()); + EXPECT_EQ("375,0 500x300", display2.bounds().ToString()); + EXPECT_EQ(1.25f, GetStoredUIScale(display1.id())); + EXPECT_EQ(1.0f, GetStoredUIScale(display2.id())); + Shell::GetInstance()->RemovePreTargetHandler(&event_handler); } diff --git a/ash/display/display_info.cc b/ash/display/display_info.cc index b46dceb..739be890 100644 --- a/ash/display/display_info.cc +++ b/ash/display/display_info.cc @@ -110,7 +110,8 @@ DisplayInfo::DisplayInfo() device_scale_factor_(1.0f), overscan_insets_in_dip_(0, 0, 0, 0), has_custom_overscan_insets_(false), - ui_scale_(1.0f) { + ui_scale_(1.0f), + native_(false) { } DisplayInfo::DisplayInfo(int64 id, @@ -123,13 +124,14 @@ DisplayInfo::DisplayInfo(int64 id, device_scale_factor_(1.0f), overscan_insets_in_dip_(0, 0, 0, 0), has_custom_overscan_insets_(false), - ui_scale_(1.0f) { + ui_scale_(1.0f), + native_(false) { } DisplayInfo::~DisplayInfo() { } -void DisplayInfo::CopyFromNative(const DisplayInfo& native_info) { +void DisplayInfo::Copy(const DisplayInfo& native_info) { DCHECK(id_ == native_info.id_); name_ = native_info.name_; has_overscan_ = native_info.has_overscan_; @@ -138,8 +140,21 @@ void DisplayInfo::CopyFromNative(const DisplayInfo& native_info) { bounds_in_pixel_ = native_info.bounds_in_pixel_; size_in_pixel_ = native_info.size_in_pixel_; device_scale_factor_ = native_info.device_scale_factor_; - rotation_ = native_info.rotation_; - ui_scale_ = native_info.ui_scale_; + + // Rotation_ and ui_scale_ are given by preference, or unit + // tests. Don't copy if this native_info came from + // DisplayChangeObserverX11. + if (!native_info.native()) { + 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_info.h b/ash/display/display_info.h index 520a8f7..e89c7c4 100644 --- a/ash/display/display_info.h +++ b/ash/display/display_info.h @@ -93,9 +93,11 @@ class ASH_EXPORT DisplayInfo { float ui_scale() const { return ui_scale_; } void set_ui_scale(float scale) { ui_scale_ = scale; } - // Copy the display info except for two fields that can be modified by a user - // (|has_custom_overscan_insets_| and |custom_overscan_insets_in_dip_|). - void CopyFromNative(const DisplayInfo& native_info); + // Copy the display info except for fields that can be modified by a user + // (|has_custom_overscan_insets_| and |custom_overscan_insets_in_dip_|, + // |rotation_| and |ui_scale_|). |rotation_| and |ui_scale_| are copied + // when the |another_info| isn't native one. + void Copy(const DisplayInfo& another_info); // Update the |bounds_in_pixel_| and |size_in_pixel_| using // given |bounds_in_pixel|. @@ -117,9 +119,16 @@ class ASH_EXPORT DisplayInfo { void SetOverscanInsets(bool custom, const gfx::Insets& insets_in_dip); gfx::Insets GetOverscanInsetsInPixel() const; + void clear_has_custom_overscan_insets() { has_custom_overscan_insets_ = false; } + bool has_custom_overscan_insets() const { + return has_custom_overscan_insets_; + } + + void set_native(bool native) { native_ = native; } + bool native() const { return native_; } // Returns a string representation of the DisplayInfo; std::string ToString() const; @@ -148,6 +157,9 @@ class ASH_EXPORT DisplayInfo { // UI scale of the display. float ui_scale_; + + // True if this comes from native platform (DisplayChangeObserverX11). + bool native_; }; } // namespace internal diff --git a/ash/display/display_manager.cc b/ash/display/display_manager.cc index e577571..de75d83 100644 --- a/ash/display/display_manager.cc +++ b/ash/display/display_manager.cc @@ -54,6 +54,12 @@ typedef std::vector<DisplayInfo> DisplayInfoList; namespace { +// List of value UI Scale values. These scales are equivalent to 1024, +// 1280, 1600 and 1920 pixel width respectively on 2560 pixel width 2x +// density display. +const float kUIScales[] = {0.8f, 1.0f, 1.25f, 1.5f}; +const size_t kUIScaleTableSize = arraysize(kUIScales); + struct DisplaySortFunctor { bool operator()(const gfx::Display& a, const gfx::Display& b) { return a.id() < b.id(); @@ -71,6 +77,14 @@ gfx::Display& GetInvalidDisplay() { 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; @@ -106,6 +120,21 @@ void DisplayManager::ToggleDisplayScaleFactor() { Shell::GetInstance()->display_manager()->ScaleDisplayImpl(); } +// 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]; + if (!up && i != 0) + return kUIScales[i - 1]; + return kUIScales[i]; + } + } + // Fallback to 1.0f if the |scale| wasn't in the list. + return 1.0f; +} + bool DisplayManager::IsActiveDisplay(const gfx::Display& display) const { for (DisplayList::const_iterator iter = displays_.begin(); iter != displays_.end(); ++iter) { @@ -156,7 +185,7 @@ void DisplayManager::SetOverscanInsets(int64 display_id, DisplayInfoList display_info_list; for (DisplayList::const_iterator iter = displays_.begin(); iter != displays_.end(); ++iter) { - display_info_list.push_back(GetDisplayInfo(*iter)); + display_info_list.push_back(GetDisplayInfo(iter->id())); } UpdateDisplays(display_info_list); } @@ -166,7 +195,7 @@ void DisplayManager::ClearCustomOverscanInsets(int64 display_id) { DisplayInfoList display_info_list; for (DisplayList::const_iterator iter = displays_.begin(); iter != displays_.end(); ++iter) { - display_info_list.push_back(GetDisplayInfo(*iter)); + display_info_list.push_back(GetDisplayInfo(iter->id())); } UpdateDisplays(display_info_list); } @@ -178,7 +207,7 @@ void DisplayManager::SetDisplayRotation(int64 display_id, DisplayInfoList display_info_list; for (DisplayList::const_iterator iter = displays_.begin(); iter != displays_.end(); ++iter) { - DisplayInfo info = GetDisplayInfo(*iter); + DisplayInfo info = GetDisplayInfo(iter->id()); if (info.id() == display_id) { if (info.rotation() == rotation) return; @@ -191,12 +220,13 @@ void DisplayManager::SetDisplayRotation(int64 display_id, void DisplayManager::SetDisplayUIScale(int64 display_id, float ui_scale) { - if (!IsDisplayUIScalingEnabled()) + if (!IsDisplayUIScalingEnabled() || !IsValidUIScale(ui_scale)) return; + DisplayInfoList display_info_list; for (DisplayList::const_iterator iter = displays_.begin(); iter != displays_.end(); ++iter) { - DisplayInfo info = GetDisplayInfo(*iter); + DisplayInfo info = GetDisplayInfo(iter->id()); if (info.id() == display_id) { if (info.ui_scale() == ui_scale) return; @@ -207,6 +237,18 @@ void DisplayManager::SetDisplayUIScale(int64 display_id, UpdateDisplays(display_info_list); } +void DisplayManager::RegisterDisplayProperty( + int64 display_id, + gfx::Display::Rotation rotation, + float ui_scale, + const gfx::Insets* overscan_insets) { + display_info_[display_id].set_rotation(rotation); + + if (IsValidUIScale(ui_scale)) + display_info_[display_id].set_ui_scale(ui_scale); + if (overscan_insets) + display_info_[display_id].SetOverscanInsets(true, *overscan_insets); +} bool DisplayManager::IsDisplayRotationEnabled() const { static bool enabled = !CommandLine::ForCurrentProcess()-> @@ -295,6 +337,15 @@ void DisplayManager::OnNativeDisplaysChanged( UpdateDisplays(new_display_info_list); } +void DisplayManager::UpdateDisplays() { + DisplayInfoList display_info_list; + for (DisplayList::const_iterator iter = displays_.begin(); + iter != displays_.end(); ++iter) { + display_info_list.push_back(GetDisplayInfo(iter->id())); + } + UpdateDisplays(display_info_list); +} + void DisplayManager::UpdateDisplays( const std::vector<DisplayInfo>& updated_display_info_list) { DisplayInfoList new_display_info_list = updated_display_info_list; @@ -329,11 +380,12 @@ void DisplayManager::UpdateDisplays( } else if (curr_iter->id() == new_info_iter->id()) { const gfx::Display& current_display = *curr_iter; // Copy the info because |CreateDisplayFromInfo| updates the instance. - const DisplayInfo current_display_info = GetDisplayInfo(current_display); + const DisplayInfo current_display_info = + GetDisplayInfo(current_display.id()); InsertAndUpdateDisplayInfo(*new_info_iter); gfx::Display new_display = CreateDisplayFromDisplayInfoById(new_info_iter->id()); - const DisplayInfo& new_display_info = GetDisplayInfo(new_display); + const DisplayInfo& new_display_info = GetDisplayInfo(new_display.id()); // TODO(oshima): Rotating square dislay doesn't work as the size // won't change. This doesn't cause a problem now as there is no // such display. This will be fixed by comparing the rotation as @@ -420,10 +472,10 @@ const gfx::Display* DisplayManager::GetPrimaryDisplayCandidate() const { // On ChromeOS device, root windows are stacked vertically, and // default primary is the one on top. int count = GetNumDisplays(); - int y = GetDisplayInfo(*primary_candidate).bounds_in_pixel().y(); + int y = GetDisplayInfo(primary_candidate->id()).bounds_in_pixel().y(); for (int i = 1; i < count; ++i) { const gfx::Display* display = &displays_[i]; - const DisplayInfo& display_info = GetDisplayInfo(*display); + const DisplayInfo& display_info = GetDisplayInfo(display->id()); if (display->IsInternal()) { primary_candidate = display; break; @@ -485,10 +537,9 @@ const gfx::Display& DisplayManager::GetDisplayMatching( return matching ? *matching : DisplayController::GetPrimaryDisplay(); } -const DisplayInfo& DisplayManager::GetDisplayInfo( - const gfx::Display& display) const { +const DisplayInfo& DisplayManager::GetDisplayInfo(int64 display_id) const { std::map<int64, DisplayInfo>::const_iterator iter = - display_info_.find(display.id()); + display_info_.find(display_id); CHECK(iter != display_info_.end()); return iter->second; } @@ -539,7 +590,7 @@ void DisplayManager::CycleDisplayImpl() { DCHECK(!displays_.empty()); std::vector<DisplayInfo> new_display_info_list; new_display_info_list.push_back( - GetDisplayInfo(DisplayController::GetPrimaryDisplay())); + GetDisplayInfo(DisplayController::GetPrimaryDisplay().id())); // Add if there is only one display. if (displays_.size() == 1) { // Layout the 2nd display below the primary as with the real device. @@ -558,7 +609,7 @@ void DisplayManager::ScaleDisplayImpl() { std::vector<DisplayInfo> new_display_info_list; for (DisplayList::const_iterator iter = displays_.begin(); iter != displays_.end(); ++iter) { - DisplayInfo display_info = GetDisplayInfo(*iter); + DisplayInfo display_info = GetDisplayInfo(iter->id()); display_info.set_device_scale_factor( display_info.device_scale_factor() == 1.0f ? 2.0f : 1.0f); new_display_info_list.push_back(display_info); @@ -635,9 +686,11 @@ void DisplayManager::InsertAndUpdateDisplayInfo(const DisplayInfo& new_info) { std::map<int64, DisplayInfo>::iterator info = display_info_.find(new_info.id()); if (info != display_info_.end()) - info->second.CopyFromNative(new_info); - else + info->second.Copy(new_info); + else { 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(); diff --git a/ash/display/display_manager.h b/ash/display/display_manager.h index 4fc72f6..679a8ad 100644 --- a/ash/display/display_manager.h +++ b/ash/display/display_manager.h @@ -33,8 +33,7 @@ namespace internal { // and notifies observers when configuration changes. // This is exported for unittest. // -// TODO(oshima): gfx::Screen needs to return translated coordinates -// if the root window is translated. crbug.com/119268. +// TODO(oshima): Make this non internal. class ASH_EXPORT DisplayManager : public aura::RootWindowObserver { public: DisplayManager(); @@ -45,6 +44,9 @@ class ASH_EXPORT DisplayManager : public aura::RootWindowObserver { static void CycleDisplay(); static void ToggleDisplayScaleFactor(); + // Returns next valid UI scale. + static float GetNextUIScale(float scale, bool up); + // When set to true, the MonitorManager calls OnDisplayBoundsChanged // even if the display's bounds didn't change. Used to swap primary // display. @@ -89,6 +91,13 @@ class ASH_EXPORT DisplayManager : public aura::RootWindowObserver { // Sets the display's ui scale. void SetDisplayUIScale(int64 display_id, float ui_scale); + // Register per display properties. |overscan_insets| is NULL if + // the display has no custom overscan insets. + void RegisterDisplayProperty(int64 display_id, + gfx::Display::Rotation rotation, + float ui_scale, + const gfx::Insets* overscan_insets); + // Tells if display rotation/ui scaling features are enabled. bool IsDisplayRotationEnabled() const; bool IsDisplayUIScalingEnabled() const; @@ -107,6 +116,9 @@ class ASH_EXPORT DisplayManager : public aura::RootWindowObserver { // Updates the internal display data and notifies observers about the changes. void UpdateDisplays(const std::vector<DisplayInfo>& display_info_list); + // Updates current displays using current |display_info_|. + void UpdateDisplays(); + // Obsoleted: Do not use in new code. // Returns the display at |index|. The display at 0 is // no longer considered "primary". @@ -138,8 +150,8 @@ class ASH_EXPORT DisplayManager : public aura::RootWindowObserver { const gfx::Display& GetDisplayMatching( const gfx::Rect& match_rect)const; - // Retuns the display info associated with |display|. - const DisplayInfo& GetDisplayInfo(const gfx::Display& display) const; + // Retuns the display info associated with |display_id|. + const DisplayInfo& GetDisplayInfo(int64 display_id) const; // Returns the human-readable name for the display |id|. std::string GetDisplayNameForId(int64 id); diff --git a/ash/display/display_manager_unittest.cc b/ash/display/display_manager_unittest.cc index e4305fa..68b67e2a 100644 --- a/ash/display/display_manager_unittest.cc +++ b/ash/display/display_manager_unittest.cc @@ -69,7 +69,7 @@ class DisplayManagerTest : public test::AshTestBase, } const DisplayInfo& GetDisplayInfo(const gfx::Display& display) { - return display_manager()->GetDisplayInfo(display); + return display_manager()->GetDisplayInfo(display.id()); } const DisplayInfo& GetDisplayInfoAt(int index) { diff --git a/ash/shell.cc b/ash/shell.cc index 8660194..27223e1 100644 --- a/ash/shell.cc +++ b/ash/shell.cc @@ -213,6 +213,7 @@ Shell::Shell(ShellDelegate* delegate) gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_ALTERNATE, screen_); if (!gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_NATIVE)) gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen_); + display_controller_.reset(new DisplayController); #if defined(OS_CHROMEOS) content::GpuFeatureType blacklisted_features = content::GpuDataManager::GetInstance()->GetBlacklistedFeatures(); @@ -462,7 +463,7 @@ void Shell::Init() { screen_position_controller_.reset(new internal::ScreenPositionController); root_window_host_factory_.reset(delegate_->CreateRootWindowHostFactory()); - display_controller_.reset(new DisplayController); + display_controller_->Start(); display_controller_->InitPrimaryDisplay(); aura::RootWindow* root_window = display_controller_->GetPrimaryRootWindow(); active_root_window_ = root_window; diff --git a/ash/test/display_manager_test_api.cc b/ash/test/display_manager_test_api.cc index f4e2930..f057765 100644 --- a/ash/test/display_manager_test_api.cc +++ b/ash/test/display_manager_test_api.cc @@ -85,7 +85,7 @@ int64 DisplayManagerTestApi::SetFirstDisplayAsInternalDisplay() { const gfx::Display& internal = display_manager_->displays_[0]; gfx::Display::SetInternalDisplayId(internal.id()); display_manager_->internal_display_info_.reset(new DisplayInfo( - display_manager_->GetDisplayInfo(internal))); + display_manager_->GetDisplayInfo(internal.id()))); return gfx::Display::InternalDisplayId(); } |