diff options
author | oshima <oshima@chromium.org> | 2015-07-23 09:39:12 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-07-23 16:40:18 +0000 |
commit | 8130b67e3b35e3debc36637b630646c1dbb61c60 (patch) | |
tree | 76ae75d93f8d55b3db7e3f5ef441c1cb7fbb5a70 /ash | |
parent | e7b3668e80aee2008f89354479a7800a42dbe8de (diff) | |
download | chromium_src-8130b67e3b35e3debc36637b630646c1dbb61c60.zip chromium_src-8130b67e3b35e3debc36637b630646c1dbb61c60.tar.gz chromium_src-8130b67e3b35e3debc36637b630646c1dbb61c60.tar.bz2 |
Cleanup: Introduce gfx::Display::IsInternalDisplayId
Add DCHECKS to InternalDisplay to make sure invalid display
won't be used as a internal display in tests.
BUG=None
Review URL: https://codereview.chromium.org/1251953004
Cr-Commit-Position: refs/heads/master@{#340102}
Diffstat (limited to 'ash')
-rw-r--r-- | ash/content/display/display_color_manager_chromeos.cc | 2 | ||||
-rw-r--r-- | ash/content/display/screen_orientation_controller_chromeos_unittest.cc | 26 | ||||
-rw-r--r-- | ash/display/display_change_observer_chromeos.cc | 3 | ||||
-rw-r--r-- | ash/display/display_change_observer_chromeos_unittest.cc | 8 | ||||
-rw-r--r-- | ash/display/display_info.cc | 9 | ||||
-rw-r--r-- | ash/display/display_manager.cc | 33 | ||||
-rw-r--r-- | ash/system/audio/tray_audio.cc | 8 | ||||
-rw-r--r-- | ash/system/chromeos/tray_display.cc | 8 | ||||
-rw-r--r-- | ash/touch/touchscreen_util.cc | 4 |
9 files changed, 54 insertions, 47 deletions
diff --git a/ash/content/display/display_color_manager_chromeos.cc b/ash/content/display/display_color_manager_chromeos.cc index 1f177fd..b185dc9 100644 --- a/ash/content/display/display_color_manager_chromeos.cc +++ b/ash/content/display/display_color_manager_chromeos.cc @@ -64,7 +64,7 @@ bool ParseFile(const base::FilePath& path, } base::FilePath PathForDisplaySnapshot(const ui::DisplaySnapshot* snapshot) { - if (snapshot->display_id() == gfx::Display::InternalDisplayId()) { + if (gfx::Display::IsInternalDisplayId(snapshot->display_id())) { const base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); if (command_line->HasSwitch( diff --git a/ash/content/display/screen_orientation_controller_chromeos_unittest.cc b/ash/content/display/screen_orientation_controller_chromeos_unittest.cc index 22c355c..84bbb5d 100644 --- a/ash/content/display/screen_orientation_controller_chromeos_unittest.cc +++ b/ash/content/display/screen_orientation_controller_chromeos_unittest.cc @@ -56,10 +56,13 @@ bool RotationLocked() { ->rotation_locked(); } -void SetInternalDisplayRotation(gfx::Display::Rotation rotation) { +void SetDisplayRotationById(int64 display_id, gfx::Display::Rotation rotation) { Shell::GetInstance()->display_manager()->SetDisplayRotation( - gfx::Display::InternalDisplayId(), rotation, - gfx::Display::ROTATION_SOURCE_USER); + display_id, rotation, gfx::Display::ROTATION_SOURCE_USER); +} + +void SetInternalDisplayRotation(gfx::Display::Rotation rotation) { + SetDisplayRotationById(gfx::Display::InternalDisplayId(), rotation); } void SetRotationLocked(bool rotation_locked) { @@ -416,6 +419,8 @@ TEST_F(ScreenOrientationControllerTest, BlockRotationNotifications) { static_cast<test::TestSystemTrayDelegate*>( Shell::GetInstance()->system_tray_delegate()); tray_delegate->set_should_show_display_notification(true); + test::DisplayManagerTestApi(Shell::GetInstance()->display_manager()) + .SetFirstDisplayAsInternalDisplay(); message_center::MessageCenter* message_center = message_center::MessageCenter::Get(); @@ -465,6 +470,9 @@ TEST_F(ScreenOrientationControllerTest, BlockRotationNotifications) { // Tests that if a user has set a display rotation that it is restored upon // exiting maximize mode. TEST_F(ScreenOrientationControllerTest, ResetUserRotationUponExit) { + test::DisplayManagerTestApi(Shell::GetInstance()->display_manager()) + .SetFirstDisplayAsInternalDisplay(); + SetInternalDisplayRotation(gfx::Display::ROTATE_90); EnableMaximizeMode(true); @@ -589,13 +597,21 @@ TEST_F(ScreenOrientationControllerTest, UserRotationLockDisallowsRotation) { // ready, that ScreenOrientationController still begins listening to events, // which require an internal display to be acted upon. TEST_F(ScreenOrientationControllerTest, InternalDisplayNotAvailableAtStartup) { + test::DisplayManagerTestApi(Shell::GetInstance()->display_manager()) + .SetFirstDisplayAsInternalDisplay(); + int64 internal_display_id = gfx::Display::InternalDisplayId(); gfx::Display::SetInternalDisplayId(gfx::Display::kInvalidDisplayID); EnableMaximizeMode(true); - // Should not crash, even thought there is no internal display. - SetInternalDisplayRotation(gfx::Display::ROTATE_180); + // Should not crash, even though there is no internal display. + SetDisplayRotationById(internal_display_id, gfx::Display::ROTATE_180); + EXPECT_FALSE(RotationLocked()); + + // Should not crash, even though the invalid display id is requested. + SetDisplayRotationById(gfx::Display::kInvalidDisplayID, + gfx::Display::ROTATE_180); EXPECT_FALSE(RotationLocked()); // With an internal display now available, functionality should resume. diff --git a/ash/display/display_change_observer_chromeos.cc b/ash/display/display_change_observer_chromeos.cc index fe2e479..ac6b995 100644 --- a/ash/display/display_change_observer_chromeos.cc +++ b/ash/display/display_change_observer_chromeos.cc @@ -167,8 +167,7 @@ void DisplayChangeObserver::OnDisplayModeChanged( std::set<int64> ids; for (const ui::DisplaySnapshot* state : display_states) { if (state->type() == ui::DISPLAY_CONNECTION_TYPE_INTERNAL) { - if (gfx::Display::InternalDisplayId() == - gfx::Display::kInvalidDisplayID) { + if (!gfx::Display::HasInternalDisplay()) { gfx::Display::SetInternalDisplayId(state->display_id()); } else { #if defined(USE_OZONE) diff --git a/ash/display/display_change_observer_chromeos_unittest.cc b/ash/display/display_change_observer_chromeos_unittest.cc index f437437..bbf01fc 100644 --- a/ash/display/display_change_observer_chromeos_unittest.cc +++ b/ash/display/display_change_observer_chromeos_unittest.cc @@ -94,7 +94,7 @@ TEST_F(DisplayChangeObserverTest, GetInternalDisplayModeList) { display_snapshot.set_modes(modes.get()); display_snapshot.set_native_mode(modes[0]); - DisplayInfo info; + DisplayInfo info(1, "", false); info.SetBounds(gfx::Rect(0, 0, 1366, 768)); std::vector<DisplayMode> display_modes = @@ -137,7 +137,7 @@ TEST_F(DisplayChangeObserverTest, GetInternalHiDPIDisplayModeList) { display_snapshot.set_modes(modes.get()); display_snapshot.set_native_mode(modes[0]); - DisplayInfo info; + DisplayInfo info(1, "", false); info.SetBounds(gfx::Rect(0, 0, 2560, 1700)); info.set_device_scale_factor(2.0f); @@ -194,7 +194,7 @@ TEST_F(DisplayChangeObserverTest, GetInternalDisplayModeList1_25) { display_snapshot.set_modes(modes.get()); display_snapshot.set_native_mode(modes[0]); - DisplayInfo info; + DisplayInfo info(1, "", false); info.SetBounds(gfx::Rect(0, 0, 1920, 1080)); info.set_device_scale_factor(1.25); @@ -259,7 +259,7 @@ TEST_F(DisplayChangeObserverTest, GetExternalDisplayModeList4K) { std::vector<DisplayMode> display_modes = DisplayChangeObserver::GetExternalDisplayModeList(display_snapshot); - DisplayInfo info; + DisplayInfo info(1, "", false); info.SetDisplayModes(display_modes); // Sort as external display. display_modes = info.display_modes(); diff --git a/ash/display/display_info.cc b/ash/display/display_info.cc index 9c26281..d352917 100644 --- a/ash/display/display_info.cc +++ b/ash/display/display_info.cc @@ -61,11 +61,6 @@ struct DisplayModeSorter { bool is_internal; }; -bool IsInternalDisplayId(int64 id) { - return id == gfx::Display::InternalDisplayId() && - id != gfx::Display::kInvalidDisplayID; -} - } // namespace DisplayMode::DisplayMode() @@ -369,7 +364,7 @@ void DisplayInfo::SetDisplayModes( const std::vector<DisplayMode>& display_modes) { display_modes_ = display_modes; std::sort(display_modes_.begin(), display_modes_.end(), - DisplayModeSorter(IsInternalDisplayId(id_))); + DisplayModeSorter(gfx::Display::IsInternalDisplayId(id_))); } gfx::Size DisplayInfo::GetNativeModeSize() const { @@ -439,7 +434,7 @@ bool DisplayInfo::IsColorProfileAvailable( } bool DisplayInfo::Use125DSFForUIScaling() const { - return use_125_dsf_for_ui_scaling && IsInternalDisplayId(id_); + return use_125_dsf_for_ui_scaling && gfx::Display::IsInternalDisplayId(id_); } void DisplayInfo::AddInputDevice(int id) { diff --git a/ash/display/display_manager.cc b/ash/display/display_manager.cc index ca7dc4e..00f2102 100644 --- a/ash/display/display_manager.cc +++ b/ash/display/display_manager.cc @@ -109,10 +109,6 @@ void MaybeInitInternalDisplay(DisplayInfo* info) { } } -bool IsInternalDisplayId(int64 id) { - return gfx::Display::InternalDisplayId() == id; -} - } // namespace using std::string; @@ -236,7 +232,7 @@ DisplayIdPair DisplayManager::GetCurrentDisplayIdPair() const { } else { CHECK_LE(2u, active_display_list_.size()); int64 id_at_zero = active_display_list_[0].id(); - if (id_at_zero == gfx::Display::InternalDisplayId() || + if (gfx::Display::IsInternalDisplayId(id_at_zero) || id_at_zero == first_display_id()) { return std::make_pair(id_at_zero, active_display_list_[1].id()); } else { @@ -388,8 +384,8 @@ bool DisplayManager::SetDisplayUIScale(int64 display_id, void DisplayManager::SetDisplayResolution(int64 display_id, const gfx::Size& resolution) { - DCHECK_NE(gfx::Display::InternalDisplayId(), display_id); - if (gfx::Display::InternalDisplayId() == display_id) + DCHECK(!gfx::Display::IsInternalDisplayId(display_id)); + if (gfx::Display::IsInternalDisplayId(display_id)) return; const DisplayInfo& display_info = GetDisplayInfo(display_id); const std::vector<DisplayMode>& modes = display_info.display_modes(); @@ -482,7 +478,7 @@ void DisplayManager::RegisterDisplayProperty( if (overscan_insets) display_info_[display_id].SetOverscanInsets(*overscan_insets); if (!resolution_in_pixels.IsEmpty()) { - DCHECK(!IsInternalDisplayId(display_id)); + DCHECK(!gfx::Display::IsInternalDisplayId(display_id)); // Default refresh rate, until OnNativeDisplaysChanged() updates us with the // actual display info, is 60 Hz. DisplayMode mode(resolution_in_pixels, 60.0f, false, false); @@ -617,7 +613,8 @@ void DisplayManager::OnNativeDisplaysChanged( iter != updated_displays.end(); ++iter) { if (!internal_display_connected) - internal_display_connected = IsInternalDisplayId(iter->id()); + internal_display_connected = + gfx::Display::IsInternalDisplayId(iter->id()); // Mirrored monitors have the same origins. gfx::Point origin = iter->bounds_in_native().origin(); if (origins.find(origin) != origins.end()) { @@ -959,7 +956,9 @@ std::string DisplayManager::GetDisplayNameForId(int64 id) { int64 DisplayManager::GetDisplayIdForUIScaling() const { // UI Scaling is effective on internal display or on unified desktop. return IsInUnifiedMode() ? kUnifiedDisplayId - : gfx::Display::InternalDisplayId(); + : (gfx::Display::HasInternalDisplay() + ? gfx::Display::InternalDisplayId() + : gfx::Display::kInvalidDisplayID); } void DisplayManager::SetMirrorMode(bool mirror) { @@ -1116,7 +1115,8 @@ void DisplayManager::CreateScreenForShutdown() const { } void DisplayManager::UpdateInternalDisplayModeListForTest() { - if (display_info_.count(gfx::Display::InternalDisplayId()) == 0) + if (!gfx::Display::HasInternalDisplay() || + display_info_.count(gfx::Display::InternalDisplayId()) == 0) return; DisplayInfo* info = &display_info_[gfx::Display::InternalDisplayId()]; SetInternalDisplayModeList(info); @@ -1133,7 +1133,7 @@ void DisplayManager::CreateSoftwareMirroringDisplayInfo( case MIRRORING: { bool zero_is_source = first_display_id_ == (*display_info_list)[0].id() || - gfx::Display::InternalDisplayId() == (*display_info_list)[0].id(); + gfx::Display::IsInternalDisplayId((*display_info_list)[0].id()); DCHECK_EQ(MIRRORING, multi_display_mode_); mirroring_display_id_ = (*display_info_list)[zero_is_source ? 1 : 0].id(); @@ -1301,11 +1301,10 @@ bool DisplayManager::UpdateNonPrimaryDisplayBoundsForLayout( } int64 id_at_zero = displays->at(0).id(); - DisplayIdPair pair = - (id_at_zero == first_display_id_ || - id_at_zero == gfx::Display::InternalDisplayId()) ? - std::make_pair(id_at_zero, displays->at(1).id()) : - std::make_pair(displays->at(1).id(), id_at_zero); + DisplayIdPair pair = (id_at_zero == first_display_id_ || + gfx::Display::IsInternalDisplayId(id_at_zero)) + ? std::make_pair(id_at_zero, displays->at(1).id()) + : std::make_pair(displays->at(1).id(), id_at_zero); DisplayLayout layout = layout_store_->ComputeDisplayLayoutForDisplayIdPair(pair); diff --git a/ash/system/audio/tray_audio.cc b/ash/system/audio/tray_audio.cc index 13269bc..0109f29 100644 --- a/ash/system/audio/tray_audio.cc +++ b/ash/system/audio/tray_audio.cc @@ -142,7 +142,7 @@ void TrayAudio::ChangeInternalSpeakerChannelMode() { // Swap left/right channel only if it is in Yoga mode. system::TrayAudioDelegate::AudioChannelMode channel_mode = system::TrayAudioDelegate::NORMAL; - if (gfx::Display::InternalDisplayId() != gfx::Display::kInvalidDisplayID) { + if (gfx::Display::HasInternalDisplay()) { const DisplayInfo& display_info = Shell::GetInstance()->display_manager()->GetDisplayInfo( gfx::Display::InternalDisplayId()); @@ -154,20 +154,20 @@ void TrayAudio::ChangeInternalSpeakerChannelMode() { } void TrayAudio::OnDisplayAdded(const gfx::Display& new_display) { - if (new_display.id() != gfx::Display::InternalDisplayId()) + if (!new_display.IsInternal()) return; ChangeInternalSpeakerChannelMode(); } void TrayAudio::OnDisplayRemoved(const gfx::Display& old_display) { - if (old_display.id() != gfx::Display::InternalDisplayId()) + if (!old_display.IsInternal()) return; ChangeInternalSpeakerChannelMode(); } void TrayAudio::OnDisplayMetricsChanged(const gfx::Display& display, uint32_t changed_metrics) { - if (display.id() != gfx::Display::InternalDisplayId()) + if (!display.IsInternal()) return; if (changed_metrics & gfx::DisplayObserver::DISPLAY_METRIC_ROTATION) diff --git a/ash/system/chromeos/tray_display.cc b/ash/system/chromeos/tray_display.cc index 20040ec..be9adec 100644 --- a/ash/system/chromeos/tray_display.cc +++ b/ash/system/chromeos/tray_display.cc @@ -94,9 +94,7 @@ base::string16 GetAllDisplayInfo() { int64 internal_id = gfx::Display::kInvalidDisplayID; // Make sure to show the internal display first. if (!display_manager->IsInUnifiedMode() && - gfx::Display::HasInternalDisplay() && - gfx::Display::InternalDisplayId() == - display_manager->first_display_id()) { + gfx::Display::IsInternalDisplayId(display_manager->first_display_id())) { internal_id = display_manager->first_display_id(); lines.push_back(GetDisplayInfoLine(internal_id)); } @@ -193,7 +191,7 @@ class DisplayView : public ActionableView { int64 external_id = gfx::Display::kInvalidDisplayID; for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) { int64 id = display_manager->GetDisplayAt(i).id(); - if (id != gfx::Display::InternalDisplayId()) { + if (!gfx::Display::IsInternalDisplayId(id)) { external_id = id; break; } @@ -253,7 +251,7 @@ class DisplayView : public ActionableView { int64 primary_id = Shell::GetScreen()->GetPrimaryDisplay().id(); if (gfx::Display::HasInternalDisplay() && - !(gfx::Display::InternalDisplayId() == primary_id)) { + !(gfx::Display::IsInternalDisplayId(primary_id))) { if (additional_message_out) { *additional_message_out = ash::SubstituteChromeOSDeviceType( IDS_ASH_STATUS_TRAY_DISPLAY_DOCKED_DESCRIPTION); diff --git a/ash/touch/touchscreen_util.cc b/ash/touch/touchscreen_util.cc index 92a12e5..8242c4b 100644 --- a/ash/touch/touchscreen_util.cc +++ b/ash/touch/touchscreen_util.cc @@ -16,7 +16,7 @@ void AssociateTouchscreens(std::vector<DisplayInfo>* displays, DisplayInfo* internal_state = NULL; for (size_t i = 0; i < displays->size(); ++i) { DisplayInfo* state = &(*displays)[i]; - if (state->id() == gfx::Display::InternalDisplayId() && + if (gfx::Display::IsInternalDisplayId(state->id()) && !state->GetNativeModeSize().IsEmpty() && state->touch_support() == gfx::Display::TOUCH_SUPPORT_UNKNOWN) { DCHECK(!internal_state); @@ -81,7 +81,7 @@ void AssociateTouchscreens(std::vector<DisplayInfo>* displays, ++it) { for (size_t i = 0; i < displays->size(); ++i) { DisplayInfo* state = &(*displays)[i]; - if (state->id() != gfx::Display::InternalDisplayId() && + if (!gfx::Display::IsInternalDisplayId(state->id()) && !state->GetNativeModeSize().IsEmpty() && state->touch_support() == gfx::Display::TOUCH_SUPPORT_UNKNOWN) { state->AddInputDevice(*it); |