| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/display/manager/display_manager.h" | 5 #include "ui/display/manager/display_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 #include <limits> | 9 #include <limits> |
| 10 #include <map> | 10 #include <map> |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 | 46 |
| 47 namespace display { | 47 namespace display { |
| 48 | 48 |
| 49 namespace { | 49 namespace { |
| 50 | 50 |
| 51 // The number of pixels to overlap between the primary and secondary displays, | 51 // The number of pixels to overlap between the primary and secondary displays, |
| 52 // in case that the offset value is too large. | 52 // in case that the offset value is too large. |
| 53 const int kMinimumOverlapForInvalidOffset = 100; | 53 const int kMinimumOverlapForInvalidOffset = 100; |
| 54 | 54 |
| 55 struct DisplaySortFunctor { | 55 struct DisplaySortFunctor { |
| 56 bool operator()(const display::Display& a, const display::Display& b) { | 56 bool operator()(const Display& a, const Display& b) { |
| 57 return display::CompareDisplayIds(a.id(), b.id()); | 57 return CompareDisplayIds(a.id(), b.id()); |
| 58 } | 58 } |
| 59 }; | 59 }; |
| 60 | 60 |
| 61 struct DisplayInfoSortFunctor { | 61 struct DisplayInfoSortFunctor { |
| 62 bool operator()(const display::ManagedDisplayInfo& a, | 62 bool operator()(const ManagedDisplayInfo& a, const ManagedDisplayInfo& b) { |
| 63 const display::ManagedDisplayInfo& b) { | 63 return CompareDisplayIds(a.id(), b.id()); |
| 64 return display::CompareDisplayIds(a.id(), b.id()); | |
| 65 } | 64 } |
| 66 }; | 65 }; |
| 67 | 66 |
| 68 display::Display& GetInvalidDisplay() { | 67 Display& GetInvalidDisplay() { |
| 69 static display::Display* invalid_display = new display::Display(); | 68 static Display* invalid_display = new Display(); |
| 70 return *invalid_display; | 69 return *invalid_display; |
| 71 } | 70 } |
| 72 | 71 |
| 73 display::ManagedDisplayInfo::ManagedDisplayModeList::const_iterator | 72 ManagedDisplayInfo::ManagedDisplayModeList::const_iterator FindDisplayMode( |
| 74 FindDisplayMode(const display::ManagedDisplayInfo& info, | 73 const ManagedDisplayInfo& info, |
| 75 const scoped_refptr<display::ManagedDisplayMode>& target_mode) { | 74 const scoped_refptr<ManagedDisplayMode>& target_mode) { |
| 76 const display::ManagedDisplayInfo::ManagedDisplayModeList& modes = | 75 const ManagedDisplayInfo::ManagedDisplayModeList& modes = |
| 77 info.display_modes(); | 76 info.display_modes(); |
| 78 return std::find_if( | 77 return std::find_if( |
| 79 modes.begin(), modes.end(), | 78 modes.begin(), modes.end(), |
| 80 [target_mode](const scoped_refptr<display::ManagedDisplayMode>& mode) { | 79 [target_mode](const scoped_refptr<ManagedDisplayMode>& mode) { |
| 81 return target_mode->IsEquivalent(mode); | 80 return target_mode->IsEquivalent(mode); |
| 82 }); | 81 }); |
| 83 } | 82 } |
| 84 | 83 |
| 85 void SetInternalManagedDisplayModeList(display::ManagedDisplayInfo* info) { | 84 void SetInternalManagedDisplayModeList(ManagedDisplayInfo* info) { |
| 86 scoped_refptr<display::ManagedDisplayMode> native_mode = | 85 scoped_refptr<ManagedDisplayMode> native_mode = new ManagedDisplayMode( |
| 87 new display::ManagedDisplayMode( | 86 info->bounds_in_native().size(), 0.0 /* refresh_rate */, |
| 88 info->bounds_in_native().size(), 0.0 /* refresh_rate */, | 87 false /* interlaced */, false /* native_mode */, 1.0 /* ui_scale */, |
| 89 false /* interlaced */, false /* native_mode */, 1.0 /* ui_scale */, | 88 info->device_scale_factor()); |
| 90 info->device_scale_factor()); | |
| 91 info->SetManagedDisplayModes( | 89 info->SetManagedDisplayModes( |
| 92 display::CreateInternalManagedDisplayModeList(native_mode)); | 90 CreateInternalManagedDisplayModeList(native_mode)); |
| 93 } | 91 } |
| 94 | 92 |
| 95 void MaybeInitInternalDisplay(display::ManagedDisplayInfo* info) { | 93 void MaybeInitInternalDisplay(ManagedDisplayInfo* info) { |
| 96 int64_t id = info->id(); | 94 int64_t id = info->id(); |
| 97 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 95 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 98 if (command_line->HasSwitch(::switches::kUseFirstDisplayAsInternal)) { | 96 if (command_line->HasSwitch(::switches::kUseFirstDisplayAsInternal)) { |
| 99 display::Display::SetInternalDisplayId(id); | 97 Display::SetInternalDisplayId(id); |
| 100 SetInternalManagedDisplayModeList(info); | 98 SetInternalManagedDisplayModeList(info); |
| 101 } | 99 } |
| 102 } | 100 } |
| 103 | 101 |
| 104 gfx::Size GetMaxNativeSize(const display::ManagedDisplayInfo& info) { | 102 gfx::Size GetMaxNativeSize(const ManagedDisplayInfo& info) { |
| 105 gfx::Size size; | 103 gfx::Size size; |
| 106 for (auto& mode : info.display_modes()) { | 104 for (auto& mode : info.display_modes()) { |
| 107 if (mode->size().GetArea() > size.GetArea()) | 105 if (mode->size().GetArea() > size.GetArea()) |
| 108 size = mode->size(); | 106 size = mode->size(); |
| 109 } | 107 } |
| 110 return size; | 108 return size; |
| 111 } | 109 } |
| 112 | 110 |
| 113 scoped_refptr<display::ManagedDisplayMode> GetDefaultDisplayMode( | 111 scoped_refptr<ManagedDisplayMode> GetDefaultDisplayMode( |
| 114 const display::ManagedDisplayInfo& info) { | 112 const ManagedDisplayInfo& info) { |
| 115 const auto& modes = info.display_modes(); | 113 const auto& modes = info.display_modes(); |
| 116 auto iter = | 114 auto iter = std::find_if(modes.begin(), modes.end(), |
| 117 std::find_if(modes.begin(), modes.end(), | 115 [](const scoped_refptr<ManagedDisplayMode>& mode) { |
| 118 [](const scoped_refptr<display::ManagedDisplayMode>& mode) { | 116 return mode->is_default(); |
| 119 return mode->is_default(); | 117 }); |
| 120 }); | |
| 121 | 118 |
| 122 if (iter == modes.end()) | 119 if (iter == modes.end()) |
| 123 return scoped_refptr<display::ManagedDisplayMode>(); | 120 return scoped_refptr<ManagedDisplayMode>(); |
| 124 return *iter; | 121 return *iter; |
| 125 } | 122 } |
| 126 | 123 |
| 127 } // namespace | 124 } // namespace |
| 128 | 125 |
| 129 using std::string; | 126 using std::string; |
| 130 using std::vector; | 127 using std::vector; |
| 131 | 128 |
| 132 // static | 129 // static |
| 133 int64_t DisplayManager::kUnifiedDisplayId = -10; | 130 int64_t DisplayManager::kUnifiedDisplayId = -10; |
| 134 | 131 |
| 135 DisplayManager::DisplayManager(std::unique_ptr<display::Screen> screen) | 132 DisplayManager::DisplayManager(std::unique_ptr<Screen> screen) |
| 136 : screen_(std::move(screen)), | 133 : screen_(std::move(screen)), |
| 137 layout_store_(new display::DisplayLayoutStore), | 134 layout_store_(new DisplayLayoutStore), |
| 138 weak_ptr_factory_(this) { | 135 weak_ptr_factory_(this) { |
| 139 #if defined(OS_CHROMEOS) | 136 #if defined(OS_CHROMEOS) |
| 140 change_display_upon_host_resize_ = !base::SysInfo::IsRunningOnChromeOS(); | 137 change_display_upon_host_resize_ = !base::SysInfo::IsRunningOnChromeOS(); |
| 141 unified_desktop_enabled_ = base::CommandLine::ForCurrentProcess()->HasSwitch( | 138 unified_desktop_enabled_ = base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 142 ::switches::kEnableUnifiedDesktop); | 139 ::switches::kEnableUnifiedDesktop); |
| 143 #endif | 140 #endif |
| 144 } | 141 } |
| 145 | 142 |
| 146 DisplayManager::~DisplayManager() { | 143 DisplayManager::~DisplayManager() { |
| 147 #if defined(OS_CHROMEOS) | 144 #if defined(OS_CHROMEOS) |
| 148 // Reset the font params. | 145 // Reset the font params. |
| 149 gfx::SetFontRenderParamsDeviceScaleFactor(1.0f); | 146 gfx::SetFontRenderParamsDeviceScaleFactor(1.0f); |
| 150 #endif | 147 #endif |
| 151 } | 148 } |
| 152 | 149 |
| 153 bool DisplayManager::InitFromCommandLine() { | 150 bool DisplayManager::InitFromCommandLine() { |
| 154 DisplayInfoList info_list; | 151 DisplayInfoList info_list; |
| 155 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 152 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 156 if (!command_line->HasSwitch(::switches::kHostWindowBounds)) | 153 if (!command_line->HasSwitch(::switches::kHostWindowBounds)) |
| 157 return false; | 154 return false; |
| 158 const string size_str = | 155 const string size_str = |
| 159 command_line->GetSwitchValueASCII(::switches::kHostWindowBounds); | 156 command_line->GetSwitchValueASCII(::switches::kHostWindowBounds); |
| 160 for (const std::string& part : base::SplitString( | 157 for (const std::string& part : base::SplitString( |
| 161 size_str, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) { | 158 size_str, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) { |
| 162 info_list.push_back(display::ManagedDisplayInfo::CreateFromSpec(part)); | 159 info_list.push_back(ManagedDisplayInfo::CreateFromSpec(part)); |
| 163 info_list.back().set_native(true); | 160 info_list.back().set_native(true); |
| 164 } | 161 } |
| 165 MaybeInitInternalDisplay(&info_list[0]); | 162 MaybeInitInternalDisplay(&info_list[0]); |
| 166 if (info_list.size() > 1 && | 163 if (info_list.size() > 1 && |
| 167 command_line->HasSwitch(::switches::kEnableSoftwareMirroring)) { | 164 command_line->HasSwitch(::switches::kEnableSoftwareMirroring)) { |
| 168 SetMultiDisplayMode(MIRRORING); | 165 SetMultiDisplayMode(MIRRORING); |
| 169 } | 166 } |
| 170 OnNativeDisplaysChanged(info_list); | 167 OnNativeDisplaysChanged(info_list); |
| 171 return true; | 168 return true; |
| 172 } | 169 } |
| 173 | 170 |
| 174 void DisplayManager::InitDefaultDisplay() { | 171 void DisplayManager::InitDefaultDisplay() { |
| 175 DisplayInfoList info_list; | 172 DisplayInfoList info_list; |
| 176 info_list.push_back( | 173 info_list.push_back(ManagedDisplayInfo::CreateFromSpec(std::string())); |
| 177 display::ManagedDisplayInfo::CreateFromSpec(std::string())); | |
| 178 info_list.back().set_native(true); | 174 info_list.back().set_native(true); |
| 179 MaybeInitInternalDisplay(&info_list[0]); | 175 MaybeInitInternalDisplay(&info_list[0]); |
| 180 OnNativeDisplaysChanged(info_list); | 176 OnNativeDisplaysChanged(info_list); |
| 181 } | 177 } |
| 182 | 178 |
| 183 void DisplayManager::RefreshFontParams() { | 179 void DisplayManager::RefreshFontParams() { |
| 184 #if defined(OS_CHROMEOS) | 180 #if defined(OS_CHROMEOS) |
| 185 // Use the largest device scale factor among currently active displays. Non | 181 // Use the largest device scale factor among currently active displays. Non |
| 186 // internal display may have bigger scale factor in case the external display | 182 // internal display may have bigger scale factor in case the external display |
| 187 // is an 4K display. | 183 // is an 4K display. |
| 188 float largest_device_scale_factor = 1.0f; | 184 float largest_device_scale_factor = 1.0f; |
| 189 for (const display::Display& display : active_display_list_) { | 185 for (const Display& display : active_display_list_) { |
| 190 const display::ManagedDisplayInfo& info = display_info_[display.id()]; | 186 const ManagedDisplayInfo& info = display_info_[display.id()]; |
| 191 largest_device_scale_factor = std::max( | 187 largest_device_scale_factor = std::max( |
| 192 largest_device_scale_factor, info.GetEffectiveDeviceScaleFactor()); | 188 largest_device_scale_factor, info.GetEffectiveDeviceScaleFactor()); |
| 193 } | 189 } |
| 194 gfx::SetFontRenderParamsDeviceScaleFactor(largest_device_scale_factor); | 190 gfx::SetFontRenderParamsDeviceScaleFactor(largest_device_scale_factor); |
| 195 #endif // OS_CHROMEOS | 191 #endif // OS_CHROMEOS |
| 196 } | 192 } |
| 197 | 193 |
| 198 const display::DisplayLayout& DisplayManager::GetCurrentDisplayLayout() const { | 194 const DisplayLayout& DisplayManager::GetCurrentDisplayLayout() const { |
| 199 DCHECK_LE(2U, num_connected_displays()); | 195 DCHECK_LE(2U, num_connected_displays()); |
| 200 if (num_connected_displays() > 1) { | 196 if (num_connected_displays() > 1) { |
| 201 display::DisplayIdList list = GetCurrentDisplayIdList(); | 197 DisplayIdList list = GetCurrentDisplayIdList(); |
| 202 return layout_store_->GetRegisteredDisplayLayout(list); | 198 return layout_store_->GetRegisteredDisplayLayout(list); |
| 203 } | 199 } |
| 204 LOG(ERROR) << "DisplayLayout is requested for single display"; | 200 LOG(ERROR) << "DisplayLayout is requested for single display"; |
| 205 // On release build, just fallback to default instead of blowing up. | 201 // On release build, just fallback to default instead of blowing up. |
| 206 static display::DisplayLayout layout; | 202 static DisplayLayout layout; |
| 207 layout.primary_id = active_display_list_[0].id(); | 203 layout.primary_id = active_display_list_[0].id(); |
| 208 return layout; | 204 return layout; |
| 209 } | 205 } |
| 210 | 206 |
| 211 display::DisplayIdList DisplayManager::GetCurrentDisplayIdList() const { | 207 DisplayIdList DisplayManager::GetCurrentDisplayIdList() const { |
| 212 if (IsInUnifiedMode()) { | 208 if (IsInUnifiedMode()) { |
| 213 return display::CreateDisplayIdList(software_mirroring_display_list_); | 209 return CreateDisplayIdList(software_mirroring_display_list_); |
| 214 } else if (IsInMirrorMode()) { | 210 } else if (IsInMirrorMode()) { |
| 215 if (software_mirroring_enabled()) { | 211 if (software_mirroring_enabled()) { |
| 216 CHECK_EQ(2u, num_connected_displays()); | 212 CHECK_EQ(2u, num_connected_displays()); |
| 217 // This comment is to make it easy to distinguish the crash | 213 // This comment is to make it easy to distinguish the crash |
| 218 // between two checks. | 214 // between two checks. |
| 219 CHECK_EQ(1u, active_display_list_.size()); | 215 CHECK_EQ(1u, active_display_list_.size()); |
| 220 } | 216 } |
| 221 int64_t ids[] = {active_display_list_[0].id(), mirroring_display_id_}; | 217 int64_t ids[] = {active_display_list_[0].id(), mirroring_display_id_}; |
| 222 return display::GenerateDisplayIdList(std::begin(ids), std::end(ids)); | 218 return GenerateDisplayIdList(std::begin(ids), std::end(ids)); |
| 223 } else { | 219 } else { |
| 224 CHECK_LE(2u, active_display_list_.size()); | 220 CHECK_LE(2u, active_display_list_.size()); |
| 225 return display::CreateDisplayIdList(active_display_list_); | 221 return CreateDisplayIdList(active_display_list_); |
| 226 } | 222 } |
| 227 } | 223 } |
| 228 | 224 |
| 229 void DisplayManager::SetLayoutForCurrentDisplays( | 225 void DisplayManager::SetLayoutForCurrentDisplays( |
| 230 std::unique_ptr<display::DisplayLayout> layout) { | 226 std::unique_ptr<DisplayLayout> layout) { |
| 231 if (GetNumDisplays() == 1) | 227 if (GetNumDisplays() == 1) |
| 232 return; | 228 return; |
| 233 const display::DisplayIdList list = GetCurrentDisplayIdList(); | 229 const DisplayIdList list = GetCurrentDisplayIdList(); |
| 234 | 230 |
| 235 DCHECK(display::DisplayLayout::Validate(list, *layout)); | 231 DCHECK(DisplayLayout::Validate(list, *layout)); |
| 236 | 232 |
| 237 const display::DisplayLayout& current_layout = | 233 const DisplayLayout& current_layout = |
| 238 layout_store_->GetRegisteredDisplayLayout(list); | 234 layout_store_->GetRegisteredDisplayLayout(list); |
| 239 | 235 |
| 240 if (layout->HasSamePlacementList(current_layout)) | 236 if (layout->HasSamePlacementList(current_layout)) |
| 241 return; | 237 return; |
| 242 | 238 |
| 243 layout_store_->RegisterLayoutForDisplayIdList(list, std::move(layout)); | 239 layout_store_->RegisterLayoutForDisplayIdList(list, std::move(layout)); |
| 244 if (delegate_) | 240 if (delegate_) |
| 245 delegate_->PreDisplayConfigurationChange(false); | 241 delegate_->PreDisplayConfigurationChange(false); |
| 246 | 242 |
| 247 // TODO(oshima): Call UpdateDisplays instead. | 243 // TODO(oshima): Call UpdateDisplays instead. |
| 248 std::vector<int64_t> updated_ids; | 244 std::vector<int64_t> updated_ids; |
| 249 ApplyDisplayLayout(GetCurrentDisplayLayout(), &active_display_list_, | 245 ApplyDisplayLayout(GetCurrentDisplayLayout(), &active_display_list_, |
| 250 &updated_ids); | 246 &updated_ids); |
| 251 for (int64_t id : updated_ids) { | 247 for (int64_t id : updated_ids) { |
| 252 NotifyMetricsChanged( | 248 NotifyMetricsChanged(GetDisplayForId(id), |
| 253 GetDisplayForId(id), | 249 DisplayObserver::DISPLAY_METRIC_BOUNDS | |
| 254 display::DisplayObserver::DISPLAY_METRIC_BOUNDS | | 250 DisplayObserver::DISPLAY_METRIC_WORK_AREA); |
| 255 display::DisplayObserver::DISPLAY_METRIC_WORK_AREA); | |
| 256 } | 251 } |
| 257 | 252 |
| 258 if (delegate_) | 253 if (delegate_) |
| 259 delegate_->PostDisplayConfigurationChange(false); | 254 delegate_->PostDisplayConfigurationChange(false); |
| 260 } | 255 } |
| 261 | 256 |
| 262 const display::Display& DisplayManager::GetDisplayForId(int64_t id) const { | 257 const Display& DisplayManager::GetDisplayForId(int64_t id) const { |
| 263 display::Display* display = | 258 Display* display = const_cast<DisplayManager*>(this)->FindDisplayForId(id); |
| 264 const_cast<DisplayManager*>(this)->FindDisplayForId(id); | |
| 265 return display ? *display : GetInvalidDisplay(); | 259 return display ? *display : GetInvalidDisplay(); |
| 266 } | 260 } |
| 267 | 261 |
| 268 const display::Display& DisplayManager::FindDisplayContainingPoint( | 262 const Display& DisplayManager::FindDisplayContainingPoint( |
| 269 const gfx::Point& point_in_screen) const { | 263 const gfx::Point& point_in_screen) const { |
| 270 int index = display::FindDisplayIndexContainingPoint(active_display_list_, | 264 int index = |
| 271 point_in_screen); | 265 FindDisplayIndexContainingPoint(active_display_list_, point_in_screen); |
| 272 return index < 0 ? GetInvalidDisplay() : active_display_list_[index]; | 266 return index < 0 ? GetInvalidDisplay() : active_display_list_[index]; |
| 273 } | 267 } |
| 274 | 268 |
| 275 bool DisplayManager::UpdateWorkAreaOfDisplay(int64_t display_id, | 269 bool DisplayManager::UpdateWorkAreaOfDisplay(int64_t display_id, |
| 276 const gfx::Insets& insets) { | 270 const gfx::Insets& insets) { |
| 277 display::Display* display = FindDisplayForId(display_id); | 271 Display* display = FindDisplayForId(display_id); |
| 278 DCHECK(display); | 272 DCHECK(display); |
| 279 gfx::Rect old_work_area = display->work_area(); | 273 gfx::Rect old_work_area = display->work_area(); |
| 280 display->UpdateWorkAreaFromInsets(insets); | 274 display->UpdateWorkAreaFromInsets(insets); |
| 281 bool workarea_changed = old_work_area != display->work_area(); | 275 bool workarea_changed = old_work_area != display->work_area(); |
| 282 if (workarea_changed) { | 276 if (workarea_changed) { |
| 283 NotifyMetricsChanged(*display, | 277 NotifyMetricsChanged(*display, DisplayObserver::DISPLAY_METRIC_WORK_AREA); |
| 284 display::DisplayObserver::DISPLAY_METRIC_WORK_AREA); | |
| 285 } | 278 } |
| 286 return workarea_changed; | 279 return workarea_changed; |
| 287 } | 280 } |
| 288 | 281 |
| 289 void DisplayManager::SetOverscanInsets(int64_t display_id, | 282 void DisplayManager::SetOverscanInsets(int64_t display_id, |
| 290 const gfx::Insets& insets_in_dip) { | 283 const gfx::Insets& insets_in_dip) { |
| 291 bool update = false; | 284 bool update = false; |
| 292 DisplayInfoList display_info_list; | 285 DisplayInfoList display_info_list; |
| 293 for (const auto& display : active_display_list_) { | 286 for (const auto& display : active_display_list_) { |
| 294 display::ManagedDisplayInfo info = GetDisplayInfo(display.id()); | 287 ManagedDisplayInfo info = GetDisplayInfo(display.id()); |
| 295 if (info.id() == display_id) { | 288 if (info.id() == display_id) { |
| 296 if (insets_in_dip.IsEmpty()) { | 289 if (insets_in_dip.IsEmpty()) { |
| 297 info.set_clear_overscan_insets(true); | 290 info.set_clear_overscan_insets(true); |
| 298 } else { | 291 } else { |
| 299 info.set_clear_overscan_insets(false); | 292 info.set_clear_overscan_insets(false); |
| 300 info.SetOverscanInsets(insets_in_dip); | 293 info.SetOverscanInsets(insets_in_dip); |
| 301 } | 294 } |
| 302 update = true; | 295 update = true; |
| 303 } | 296 } |
| 304 display_info_list.push_back(info); | 297 display_info_list.push_back(info); |
| 305 } | 298 } |
| 306 if (update) { | 299 if (update) { |
| 307 AddMirrorDisplayInfoIfAny(&display_info_list); | 300 AddMirrorDisplayInfoIfAny(&display_info_list); |
| 308 UpdateDisplaysWith(display_info_list); | 301 UpdateDisplaysWith(display_info_list); |
| 309 } else { | 302 } else { |
| 310 display_info_[display_id].SetOverscanInsets(insets_in_dip); | 303 display_info_[display_id].SetOverscanInsets(insets_in_dip); |
| 311 } | 304 } |
| 312 } | 305 } |
| 313 | 306 |
| 314 void DisplayManager::SetDisplayRotation( | 307 void DisplayManager::SetDisplayRotation(int64_t display_id, |
| 315 int64_t display_id, | 308 Display::Rotation rotation, |
| 316 display::Display::Rotation rotation, | 309 Display::RotationSource source) { |
| 317 display::Display::RotationSource source) { | |
| 318 if (IsInUnifiedMode()) | 310 if (IsInUnifiedMode()) |
| 319 return; | 311 return; |
| 320 | 312 |
| 321 DisplayInfoList display_info_list; | 313 DisplayInfoList display_info_list; |
| 322 bool is_active = false; | 314 bool is_active = false; |
| 323 for (const auto& display : active_display_list_) { | 315 for (const auto& display : active_display_list_) { |
| 324 display::ManagedDisplayInfo info = GetDisplayInfo(display.id()); | 316 ManagedDisplayInfo info = GetDisplayInfo(display.id()); |
| 325 if (info.id() == display_id) { | 317 if (info.id() == display_id) { |
| 326 if (info.GetRotation(source) == rotation && | 318 if (info.GetRotation(source) == rotation && |
| 327 info.GetActiveRotation() == rotation) { | 319 info.GetActiveRotation() == rotation) { |
| 328 return; | 320 return; |
| 329 } | 321 } |
| 330 info.SetRotation(rotation, source); | 322 info.SetRotation(rotation, source); |
| 331 is_active = true; | 323 is_active = true; |
| 332 } | 324 } |
| 333 display_info_list.push_back(info); | 325 display_info_list.push_back(info); |
| 334 } | 326 } |
| 335 if (is_active) { | 327 if (is_active) { |
| 336 AddMirrorDisplayInfoIfAny(&display_info_list); | 328 AddMirrorDisplayInfoIfAny(&display_info_list); |
| 337 UpdateDisplaysWith(display_info_list); | 329 UpdateDisplaysWith(display_info_list); |
| 338 } else if (display_info_.find(display_id) != display_info_.end()) { | 330 } else if (display_info_.find(display_id) != display_info_.end()) { |
| 339 // Inactive displays can reactivate, ensure they have been updated. | 331 // Inactive displays can reactivate, ensure they have been updated. |
| 340 display_info_[display_id].SetRotation(rotation, source); | 332 display_info_[display_id].SetRotation(rotation, source); |
| 341 } | 333 } |
| 342 } | 334 } |
| 343 | 335 |
| 344 bool DisplayManager::SetDisplayMode( | 336 bool DisplayManager::SetDisplayMode( |
| 345 int64_t display_id, | 337 int64_t display_id, |
| 346 const scoped_refptr<display::ManagedDisplayMode>& display_mode) { | 338 const scoped_refptr<ManagedDisplayMode>& display_mode) { |
| 347 bool change_ui_scale = GetDisplayIdForUIScaling() == display_id; | 339 bool change_ui_scale = GetDisplayIdForUIScaling() == display_id; |
| 348 | 340 |
| 349 DisplayInfoList display_info_list; | 341 DisplayInfoList display_info_list; |
| 350 bool display_property_changed = false; | 342 bool display_property_changed = false; |
| 351 bool resolution_changed = false; | 343 bool resolution_changed = false; |
| 352 for (const auto& display : active_display_list_) { | 344 for (const auto& display : active_display_list_) { |
| 353 display::ManagedDisplayInfo info = GetDisplayInfo(display.id()); | 345 ManagedDisplayInfo info = GetDisplayInfo(display.id()); |
| 354 if (info.id() == display_id) { | 346 if (info.id() == display_id) { |
| 355 auto iter = FindDisplayMode(info, display_mode); | 347 auto iter = FindDisplayMode(info, display_mode); |
| 356 if (iter == info.display_modes().end()) { | 348 if (iter == info.display_modes().end()) { |
| 357 LOG(WARNING) << "Unsupported display mode was requested:" | 349 LOG(WARNING) << "Unsupported display mode was requested:" |
| 358 << "size=" << display_mode->size().ToString() | 350 << "size=" << display_mode->size().ToString() |
| 359 << ", ui scale=" << display_mode->ui_scale() | 351 << ", ui scale=" << display_mode->ui_scale() |
| 360 << ", scale factor=" | 352 << ", scale factor=" |
| 361 << display_mode->device_scale_factor(); | 353 << display_mode->device_scale_factor(); |
| 362 return false; | 354 return false; |
| 363 } | 355 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 388 #if defined(OS_CHROMEOS) | 380 #if defined(OS_CHROMEOS) |
| 389 } else if (resolution_changed && base::SysInfo::IsRunningOnChromeOS()) { | 381 } else if (resolution_changed && base::SysInfo::IsRunningOnChromeOS()) { |
| 390 delegate_->display_configurator()->OnConfigurationChanged(); | 382 delegate_->display_configurator()->OnConfigurationChanged(); |
| 391 #endif | 383 #endif |
| 392 } | 384 } |
| 393 return resolution_changed || display_property_changed; | 385 return resolution_changed || display_property_changed; |
| 394 } | 386 } |
| 395 | 387 |
| 396 void DisplayManager::RegisterDisplayProperty( | 388 void DisplayManager::RegisterDisplayProperty( |
| 397 int64_t display_id, | 389 int64_t display_id, |
| 398 display::Display::Rotation rotation, | 390 Display::Rotation rotation, |
| 399 float ui_scale, | 391 float ui_scale, |
| 400 const gfx::Insets* overscan_insets, | 392 const gfx::Insets* overscan_insets, |
| 401 const gfx::Size& resolution_in_pixels, | 393 const gfx::Size& resolution_in_pixels, |
| 402 float device_scale_factor, | 394 float device_scale_factor, |
| 403 ui::ColorCalibrationProfile color_profile) { | 395 ui::ColorCalibrationProfile color_profile) { |
| 404 if (display_info_.find(display_id) == display_info_.end()) | 396 if (display_info_.find(display_id) == display_info_.end()) |
| 405 display_info_[display_id] = | 397 display_info_[display_id] = |
| 406 display::ManagedDisplayInfo(display_id, std::string(), false); | 398 ManagedDisplayInfo(display_id, std::string(), false); |
| 407 | 399 |
| 408 // Do not allow rotation in unified desktop mode. | 400 // Do not allow rotation in unified desktop mode. |
| 409 if (display_id == kUnifiedDisplayId) | 401 if (display_id == kUnifiedDisplayId) |
| 410 rotation = display::Display::ROTATE_0; | 402 rotation = Display::ROTATE_0; |
| 411 | 403 |
| 412 display_info_[display_id].SetRotation(rotation, | 404 display_info_[display_id].SetRotation(rotation, |
| 413 display::Display::ROTATION_SOURCE_USER); | 405 Display::ROTATION_SOURCE_USER); |
| 414 display_info_[display_id].SetRotation( | 406 display_info_[display_id].SetRotation(rotation, |
| 415 rotation, display::Display::ROTATION_SOURCE_ACTIVE); | 407 Display::ROTATION_SOURCE_ACTIVE); |
| 416 display_info_[display_id].SetColorProfile(color_profile); | 408 display_info_[display_id].SetColorProfile(color_profile); |
| 417 // Just in case the preference file was corrupted. | 409 // Just in case the preference file was corrupted. |
| 418 // TODO(mukai): register |display_modes_| here as well, so the lookup for the | 410 // TODO(mukai): register |display_modes_| here as well, so the lookup for the |
| 419 // default mode in GetActiveModeForDisplayId() gets much simpler. | 411 // default mode in GetActiveModeForDisplayId() gets much simpler. |
| 420 if (0.5f <= ui_scale && ui_scale <= 2.0f) | 412 if (0.5f <= ui_scale && ui_scale <= 2.0f) |
| 421 display_info_[display_id].set_configured_ui_scale(ui_scale); | 413 display_info_[display_id].set_configured_ui_scale(ui_scale); |
| 422 if (overscan_insets) | 414 if (overscan_insets) |
| 423 display_info_[display_id].SetOverscanInsets(*overscan_insets); | 415 display_info_[display_id].SetOverscanInsets(*overscan_insets); |
| 424 if (!resolution_in_pixels.IsEmpty()) { | 416 if (!resolution_in_pixels.IsEmpty()) { |
| 425 DCHECK(!display::Display::IsInternalDisplayId(display_id)); | 417 DCHECK(!Display::IsInternalDisplayId(display_id)); |
| 426 // Default refresh rate, until OnNativeDisplaysChanged() updates us with the | 418 // Default refresh rate, until OnNativeDisplaysChanged() updates us with the |
| 427 // actual display info, is 60 Hz. | 419 // actual display info, is 60 Hz. |
| 428 scoped_refptr<display::ManagedDisplayMode> mode = | 420 scoped_refptr<ManagedDisplayMode> mode = new ManagedDisplayMode( |
| 429 new display::ManagedDisplayMode(resolution_in_pixels, 60.0f, false, | 421 resolution_in_pixels, 60.0f, false, false, 1.0, device_scale_factor); |
| 430 false, 1.0, device_scale_factor); | |
| 431 display_modes_[display_id] = mode; | 422 display_modes_[display_id] = mode; |
| 432 } | 423 } |
| 433 } | 424 } |
| 434 | 425 |
| 435 scoped_refptr<display::ManagedDisplayMode> | 426 scoped_refptr<ManagedDisplayMode> DisplayManager::GetActiveModeForDisplayId( |
| 436 DisplayManager::GetActiveModeForDisplayId(int64_t display_id) const { | 427 int64_t display_id) const { |
| 437 scoped_refptr<display::ManagedDisplayMode> selected_mode( | 428 scoped_refptr<ManagedDisplayMode> selected_mode( |
| 438 GetSelectedModeForDisplayId(display_id)); | 429 GetSelectedModeForDisplayId(display_id)); |
| 439 if (selected_mode) | 430 if (selected_mode) |
| 440 return selected_mode; | 431 return selected_mode; |
| 441 | 432 |
| 442 // If 'selected' mode is empty, it should return the default mode. This means | 433 // If 'selected' mode is empty, it should return the default mode. This means |
| 443 // the native mode for the external display. Unfortunately this is not true | 434 // the native mode for the external display. Unfortunately this is not true |
| 444 // for the internal display because restoring UI-scale doesn't register the | 435 // for the internal display because restoring UI-scale doesn't register the |
| 445 // restored mode to |display_mode_|, so it needs to look up the mode whose | 436 // restored mode to |display_mode_|, so it needs to look up the mode whose |
| 446 // UI-scale value matches. See the TODO in RegisterDisplayProperty(). | 437 // UI-scale value matches. See the TODO in RegisterDisplayProperty(). |
| 447 const display::ManagedDisplayInfo& info = GetDisplayInfo(display_id); | 438 const ManagedDisplayInfo& info = GetDisplayInfo(display_id); |
| 448 | 439 |
| 449 for (auto& mode : info.display_modes()) { | 440 for (auto& mode : info.display_modes()) { |
| 450 if (GetDisplayIdForUIScaling() == display_id) { | 441 if (GetDisplayIdForUIScaling() == display_id) { |
| 451 if (info.configured_ui_scale() == mode->ui_scale()) | 442 if (info.configured_ui_scale() == mode->ui_scale()) |
| 452 return mode.get(); | 443 return mode.get(); |
| 453 } else if (mode->native()) { | 444 } else if (mode->native()) { |
| 454 return mode.get(); | 445 return mode.get(); |
| 455 } | 446 } |
| 456 } | 447 } |
| 457 return selected_mode; | 448 return selected_mode; |
| 458 } | 449 } |
| 459 | 450 |
| 460 void DisplayManager::RegisterDisplayRotationProperties( | 451 void DisplayManager::RegisterDisplayRotationProperties( |
| 461 bool rotation_lock, | 452 bool rotation_lock, |
| 462 display::Display::Rotation rotation) { | 453 Display::Rotation rotation) { |
| 463 if (delegate_) | 454 if (delegate_) |
| 464 delegate_->PreDisplayConfigurationChange(false); | 455 delegate_->PreDisplayConfigurationChange(false); |
| 465 registered_internal_display_rotation_lock_ = rotation_lock; | 456 registered_internal_display_rotation_lock_ = rotation_lock; |
| 466 registered_internal_display_rotation_ = rotation; | 457 registered_internal_display_rotation_ = rotation; |
| 467 if (delegate_) | 458 if (delegate_) |
| 468 delegate_->PostDisplayConfigurationChange(false); | 459 delegate_->PostDisplayConfigurationChange(false); |
| 469 } | 460 } |
| 470 | 461 |
| 471 scoped_refptr<display::ManagedDisplayMode> | 462 scoped_refptr<ManagedDisplayMode> DisplayManager::GetSelectedModeForDisplayId( |
| 472 DisplayManager::GetSelectedModeForDisplayId(int64_t id) const { | 463 int64_t id) const { |
| 473 std::map<int64_t, scoped_refptr<display::ManagedDisplayMode>>::const_iterator | 464 std::map<int64_t, scoped_refptr<ManagedDisplayMode>>::const_iterator iter = |
| 474 iter = display_modes_.find(id); | 465 display_modes_.find(id); |
| 475 if (iter == display_modes_.end()) | 466 if (iter == display_modes_.end()) |
| 476 return scoped_refptr<display::ManagedDisplayMode>(); | 467 return scoped_refptr<ManagedDisplayMode>(); |
| 477 return iter->second; | 468 return iter->second; |
| 478 } | 469 } |
| 479 | 470 |
| 480 bool DisplayManager::IsDisplayUIScalingEnabled() const { | 471 bool DisplayManager::IsDisplayUIScalingEnabled() const { |
| 481 return GetDisplayIdForUIScaling() != kInvalidDisplayId; | 472 return GetDisplayIdForUIScaling() != kInvalidDisplayId; |
| 482 } | 473 } |
| 483 | 474 |
| 484 gfx::Insets DisplayManager::GetOverscanInsets(int64_t display_id) const { | 475 gfx::Insets DisplayManager::GetOverscanInsets(int64_t display_id) const { |
| 485 std::map<int64_t, display::ManagedDisplayInfo>::const_iterator it = | 476 std::map<int64_t, ManagedDisplayInfo>::const_iterator it = |
| 486 display_info_.find(display_id); | 477 display_info_.find(display_id); |
| 487 return (it != display_info_.end()) ? it->second.overscan_insets_in_dip() | 478 return (it != display_info_.end()) ? it->second.overscan_insets_in_dip() |
| 488 : gfx::Insets(); | 479 : gfx::Insets(); |
| 489 } | 480 } |
| 490 | 481 |
| 491 void DisplayManager::SetColorCalibrationProfile( | 482 void DisplayManager::SetColorCalibrationProfile( |
| 492 int64_t display_id, | 483 int64_t display_id, |
| 493 ui::ColorCalibrationProfile profile) { | 484 ui::ColorCalibrationProfile profile) { |
| 494 #if defined(OS_CHROMEOS) | 485 #if defined(OS_CHROMEOS) |
| 495 if (!display_info_[display_id].IsColorProfileAvailable(profile)) | 486 if (!display_info_[display_id].IsColorProfileAvailable(profile)) |
| (...skipping 18 matching lines...) Expand all Loading... |
| 514 const DisplayInfoList& updated_displays) { | 505 const DisplayInfoList& updated_displays) { |
| 515 if (updated_displays.empty()) { | 506 if (updated_displays.empty()) { |
| 516 VLOG(1) << "OnNativeDisplaysChanged(0): # of current displays=" | 507 VLOG(1) << "OnNativeDisplaysChanged(0): # of current displays=" |
| 517 << active_display_list_.size(); | 508 << active_display_list_.size(); |
| 518 // If the device is booted without display, or chrome is started | 509 // If the device is booted without display, or chrome is started |
| 519 // without --ash-host-window-bounds on linux desktop, use the | 510 // without --ash-host-window-bounds on linux desktop, use the |
| 520 // default display. | 511 // default display. |
| 521 if (active_display_list_.empty()) { | 512 if (active_display_list_.empty()) { |
| 522 DisplayInfoList init_displays; | 513 DisplayInfoList init_displays; |
| 523 init_displays.push_back( | 514 init_displays.push_back( |
| 524 display::ManagedDisplayInfo::CreateFromSpec(std::string())); | 515 ManagedDisplayInfo::CreateFromSpec(std::string())); |
| 525 MaybeInitInternalDisplay(&init_displays[0]); | 516 MaybeInitInternalDisplay(&init_displays[0]); |
| 526 OnNativeDisplaysChanged(init_displays); | 517 OnNativeDisplaysChanged(init_displays); |
| 527 } else { | 518 } else { |
| 528 // Otherwise don't update the displays when all displays are disconnected. | 519 // Otherwise don't update the displays when all displays are disconnected. |
| 529 // This happens when: | 520 // This happens when: |
| 530 // - the device is idle and powerd requested to turn off all displays. | 521 // - the device is idle and powerd requested to turn off all displays. |
| 531 // - the device is suspended. (kernel turns off all displays) | 522 // - the device is suspended. (kernel turns off all displays) |
| 532 // - the internal display's brightness is set to 0 and no external | 523 // - the internal display's brightness is set to 0 and no external |
| 533 // display is connected. | 524 // display is connected. |
| 534 // - the internal display's brightness is 0 and external display is | 525 // - the internal display's brightness is 0 and external display is |
| (...skipping 15 matching lines...) Expand all Loading... |
| 550 } | 541 } |
| 551 | 542 |
| 552 bool internal_display_connected = false; | 543 bool internal_display_connected = false; |
| 553 num_connected_displays_ = updated_displays.size(); | 544 num_connected_displays_ = updated_displays.size(); |
| 554 mirroring_display_id_ = kInvalidDisplayId; | 545 mirroring_display_id_ = kInvalidDisplayId; |
| 555 software_mirroring_display_list_.clear(); | 546 software_mirroring_display_list_.clear(); |
| 556 DisplayInfoList new_display_info_list; | 547 DisplayInfoList new_display_info_list; |
| 557 for (DisplayInfoList::const_iterator iter = updated_displays.begin(); | 548 for (DisplayInfoList::const_iterator iter = updated_displays.begin(); |
| 558 iter != updated_displays.end(); ++iter) { | 549 iter != updated_displays.end(); ++iter) { |
| 559 if (!internal_display_connected) | 550 if (!internal_display_connected) |
| 560 internal_display_connected = | 551 internal_display_connected = Display::IsInternalDisplayId(iter->id()); |
| 561 display::Display::IsInternalDisplayId(iter->id()); | |
| 562 // Mirrored monitors have the same origins. | 552 // Mirrored monitors have the same origins. |
| 563 gfx::Point origin = iter->bounds_in_native().origin(); | 553 gfx::Point origin = iter->bounds_in_native().origin(); |
| 564 if (origins.find(origin) != origins.end()) { | 554 if (origins.find(origin) != origins.end()) { |
| 565 InsertAndUpdateDisplayInfo(*iter); | 555 InsertAndUpdateDisplayInfo(*iter); |
| 566 mirroring_display_id_ = iter->id(); | 556 mirroring_display_id_ = iter->id(); |
| 567 } else { | 557 } else { |
| 568 origins.insert(origin); | 558 origins.insert(origin); |
| 569 new_display_info_list.push_back(*iter); | 559 new_display_info_list.push_back(*iter); |
| 570 } | 560 } |
| 571 | 561 |
| 572 scoped_refptr<display::ManagedDisplayMode> new_mode( | 562 scoped_refptr<ManagedDisplayMode> new_mode(new ManagedDisplayMode( |
| 573 new display::ManagedDisplayMode( | 563 iter->bounds_in_native().size(), 0.0 /* refresh rate */, |
| 574 iter->bounds_in_native().size(), 0.0 /* refresh rate */, | 564 false /* interlaced */, false /* native */, iter->configured_ui_scale(), |
| 575 false /* interlaced */, false /* native */, | 565 iter->device_scale_factor())); |
| 576 iter->configured_ui_scale(), iter->device_scale_factor())); | 566 const ManagedDisplayInfo::ManagedDisplayModeList& display_modes = |
| 577 const display::ManagedDisplayInfo::ManagedDisplayModeList& display_modes = | |
| 578 iter->display_modes(); | 567 iter->display_modes(); |
| 579 // This is empty the displays are initialized from InitFromCommandLine. | 568 // This is empty the displays are initialized from InitFromCommandLine. |
| 580 if (display_modes.empty()) | 569 if (display_modes.empty()) |
| 581 continue; | 570 continue; |
| 582 auto display_modes_iter = FindDisplayMode(*iter, new_mode); | 571 auto display_modes_iter = FindDisplayMode(*iter, new_mode); |
| 583 // Update the actual resolution selected as the resolution request may fail. | 572 // Update the actual resolution selected as the resolution request may fail. |
| 584 if (display_modes_iter == display_modes.end()) | 573 if (display_modes_iter == display_modes.end()) |
| 585 display_modes_.erase(iter->id()); | 574 display_modes_.erase(iter->id()); |
| 586 else if (display_modes_.find(iter->id()) != display_modes_.end()) | 575 else if (display_modes_.find(iter->id()) != display_modes_.end()) |
| 587 display_modes_[iter->id()] = *display_modes_iter; | 576 display_modes_[iter->id()] = *display_modes_iter; |
| 588 } | 577 } |
| 589 if (display::Display::HasInternalDisplay() && !internal_display_connected) { | 578 if (Display::HasInternalDisplay() && !internal_display_connected) { |
| 590 if (display_info_.find(display::Display::InternalDisplayId()) == | 579 if (display_info_.find(Display::InternalDisplayId()) == |
| 591 display_info_.end()) { | 580 display_info_.end()) { |
| 592 // Create a dummy internal display if the chrome restarted | 581 // Create a dummy internal display if the chrome restarted |
| 593 // in docked mode. | 582 // in docked mode. |
| 594 display::ManagedDisplayInfo internal_display_info( | 583 ManagedDisplayInfo internal_display_info( |
| 595 display::Display::InternalDisplayId(), | 584 Display::InternalDisplayId(), |
| 596 delegate_->GetInternalDisplayNameString(), | 585 delegate_->GetInternalDisplayNameString(), |
| 597 false /*Internal display must not have overscan */); | 586 false /*Internal display must not have overscan */); |
| 598 internal_display_info.SetBounds(gfx::Rect(0, 0, 800, 600)); | 587 internal_display_info.SetBounds(gfx::Rect(0, 0, 800, 600)); |
| 599 display_info_[display::Display::InternalDisplayId()] = | 588 display_info_[Display::InternalDisplayId()] = internal_display_info; |
| 600 internal_display_info; | |
| 601 } else { | 589 } else { |
| 602 // Internal display is no longer active. Reset its rotation to user | 590 // Internal display is no longer active. Reset its rotation to user |
| 603 // preference, so that it is restored when the internal display becomes | 591 // preference, so that it is restored when the internal display becomes |
| 604 // active again. | 592 // active again. |
| 605 display::Display::Rotation user_rotation = | 593 Display::Rotation user_rotation = |
| 606 display_info_[display::Display::InternalDisplayId()].GetRotation( | 594 display_info_[Display::InternalDisplayId()].GetRotation( |
| 607 display::Display::ROTATION_SOURCE_USER); | 595 Display::ROTATION_SOURCE_USER); |
| 608 display_info_[display::Display::InternalDisplayId()].SetRotation( | 596 display_info_[Display::InternalDisplayId()].SetRotation( |
| 609 user_rotation, display::Display::ROTATION_SOURCE_USER); | 597 user_rotation, Display::ROTATION_SOURCE_USER); |
| 610 } | 598 } |
| 611 } | 599 } |
| 612 | 600 |
| 613 #if defined(OS_CHROMEOS) | 601 #if defined(OS_CHROMEOS) |
| 614 if (!base::SysInfo::IsRunningOnChromeOS() && | 602 if (!base::SysInfo::IsRunningOnChromeOS() && |
| 615 new_display_info_list.size() > 1) { | 603 new_display_info_list.size() > 1) { |
| 616 display::DisplayIdList list = GenerateDisplayIdList( | 604 DisplayIdList list = GenerateDisplayIdList( |
| 617 new_display_info_list.begin(), new_display_info_list.end(), | 605 new_display_info_list.begin(), new_display_info_list.end(), |
| 618 [](const display::ManagedDisplayInfo& info) { return info.id(); }); | 606 [](const ManagedDisplayInfo& info) { return info.id(); }); |
| 619 | 607 |
| 620 const display::DisplayLayout& layout = | 608 const DisplayLayout& layout = |
| 621 layout_store_->GetRegisteredDisplayLayout(list); | 609 layout_store_->GetRegisteredDisplayLayout(list); |
| 622 // Mirror mode is set by DisplayConfigurator on the device. | 610 // Mirror mode is set by DisplayConfigurator on the device. |
| 623 // Emulate it when running on linux desktop. | 611 // Emulate it when running on linux desktop. |
| 624 if (layout.mirrored) | 612 if (layout.mirrored) |
| 625 SetMultiDisplayMode(MIRRORING); | 613 SetMultiDisplayMode(MIRRORING); |
| 626 } | 614 } |
| 627 #endif | 615 #endif |
| 628 | 616 |
| 629 UpdateDisplaysWith(new_display_info_list); | 617 UpdateDisplaysWith(new_display_info_list); |
| 630 } | 618 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 645 "skip (don't disable) the test using SupportsMultipleDisplays()"; | 633 "skip (don't disable) the test using SupportsMultipleDisplays()"; |
| 646 #endif | 634 #endif |
| 647 | 635 |
| 648 DisplayInfoList new_display_info_list = updated_display_info_list; | 636 DisplayInfoList new_display_info_list = updated_display_info_list; |
| 649 std::sort(active_display_list_.begin(), active_display_list_.end(), | 637 std::sort(active_display_list_.begin(), active_display_list_.end(), |
| 650 DisplaySortFunctor()); | 638 DisplaySortFunctor()); |
| 651 std::sort(new_display_info_list.begin(), new_display_info_list.end(), | 639 std::sort(new_display_info_list.begin(), new_display_info_list.end(), |
| 652 DisplayInfoSortFunctor()); | 640 DisplayInfoSortFunctor()); |
| 653 | 641 |
| 654 if (new_display_info_list.size() > 1) { | 642 if (new_display_info_list.size() > 1) { |
| 655 display::DisplayIdList list = GenerateDisplayIdList( | 643 DisplayIdList list = GenerateDisplayIdList( |
| 656 new_display_info_list.begin(), new_display_info_list.end(), | 644 new_display_info_list.begin(), new_display_info_list.end(), |
| 657 [](const display::ManagedDisplayInfo& info) { return info.id(); }); | 645 [](const ManagedDisplayInfo& info) { return info.id(); }); |
| 658 const display::DisplayLayout& layout = | 646 const DisplayLayout& layout = |
| 659 layout_store_->GetRegisteredDisplayLayout(list); | 647 layout_store_->GetRegisteredDisplayLayout(list); |
| 660 current_default_multi_display_mode_ = | 648 current_default_multi_display_mode_ = |
| 661 (layout.default_unified && unified_desktop_enabled_) ? UNIFIED | 649 (layout.default_unified && unified_desktop_enabled_) ? UNIFIED |
| 662 : EXTENDED; | 650 : EXTENDED; |
| 663 } | 651 } |
| 664 | 652 |
| 665 if (multi_display_mode_ != MIRRORING) | 653 if (multi_display_mode_ != MIRRORING) |
| 666 multi_display_mode_ = current_default_multi_display_mode_; | 654 multi_display_mode_ = current_default_multi_display_mode_; |
| 667 | 655 |
| 668 CreateSoftwareMirroringDisplayInfo(&new_display_info_list); | 656 CreateSoftwareMirroringDisplayInfo(&new_display_info_list); |
| 669 | 657 |
| 670 // Close the mirroring window if any here to avoid creating two compositor on | 658 // Close the mirroring window if any here to avoid creating two compositor on |
| 671 // one display. | 659 // one display. |
| 672 if (delegate_) | 660 if (delegate_) |
| 673 delegate_->CloseMirroringDisplayIfNotNecessary(); | 661 delegate_->CloseMirroringDisplayIfNotNecessary(); |
| 674 | 662 |
| 675 display::Displays new_displays; | 663 Displays new_displays; |
| 676 display::Displays removed_displays; | 664 Displays removed_displays; |
| 677 std::map<size_t, uint32_t> display_changes; | 665 std::map<size_t, uint32_t> display_changes; |
| 678 std::vector<size_t> added_display_indices; | 666 std::vector<size_t> added_display_indices; |
| 679 | 667 |
| 680 display::Displays::iterator curr_iter = active_display_list_.begin(); | 668 Displays::iterator curr_iter = active_display_list_.begin(); |
| 681 DisplayInfoList::const_iterator new_info_iter = new_display_info_list.begin(); | 669 DisplayInfoList::const_iterator new_info_iter = new_display_info_list.begin(); |
| 682 | 670 |
| 683 while (curr_iter != active_display_list_.end() || | 671 while (curr_iter != active_display_list_.end() || |
| 684 new_info_iter != new_display_info_list.end()) { | 672 new_info_iter != new_display_info_list.end()) { |
| 685 if (curr_iter == active_display_list_.end()) { | 673 if (curr_iter == active_display_list_.end()) { |
| 686 // more displays in new list. | 674 // more displays in new list. |
| 687 added_display_indices.push_back(new_displays.size()); | 675 added_display_indices.push_back(new_displays.size()); |
| 688 InsertAndUpdateDisplayInfo(*new_info_iter); | 676 InsertAndUpdateDisplayInfo(*new_info_iter); |
| 689 new_displays.push_back( | 677 new_displays.push_back( |
| 690 CreateDisplayFromDisplayInfoById(new_info_iter->id())); | 678 CreateDisplayFromDisplayInfoById(new_info_iter->id())); |
| 691 ++new_info_iter; | 679 ++new_info_iter; |
| 692 } else if (new_info_iter == new_display_info_list.end()) { | 680 } else if (new_info_iter == new_display_info_list.end()) { |
| 693 // more displays in current list. | 681 // more displays in current list. |
| 694 removed_displays.push_back(*curr_iter); | 682 removed_displays.push_back(*curr_iter); |
| 695 ++curr_iter; | 683 ++curr_iter; |
| 696 } else if (curr_iter->id() == new_info_iter->id()) { | 684 } else if (curr_iter->id() == new_info_iter->id()) { |
| 697 const display::Display& current_display = *curr_iter; | 685 const Display& current_display = *curr_iter; |
| 698 // Copy the info because |InsertAndUpdateDisplayInfo| updates the | 686 // Copy the info because |InsertAndUpdateDisplayInfo| updates the |
| 699 // instance. | 687 // instance. |
| 700 const display::ManagedDisplayInfo current_display_info = | 688 const ManagedDisplayInfo current_display_info = |
| 701 GetDisplayInfo(current_display.id()); | 689 GetDisplayInfo(current_display.id()); |
| 702 InsertAndUpdateDisplayInfo(*new_info_iter); | 690 InsertAndUpdateDisplayInfo(*new_info_iter); |
| 703 display::Display new_display = | 691 Display new_display = |
| 704 CreateDisplayFromDisplayInfoById(new_info_iter->id()); | 692 CreateDisplayFromDisplayInfoById(new_info_iter->id()); |
| 705 const display::ManagedDisplayInfo& new_display_info = | 693 const ManagedDisplayInfo& new_display_info = |
| 706 GetDisplayInfo(new_display.id()); | 694 GetDisplayInfo(new_display.id()); |
| 707 | 695 |
| 708 uint32_t metrics = display::DisplayObserver::DISPLAY_METRIC_NONE; | 696 uint32_t metrics = DisplayObserver::DISPLAY_METRIC_NONE; |
| 709 | 697 |
| 710 // At that point the new Display objects we have are not entirely updated, | 698 // At that point the new Display objects we have are not entirely updated, |
| 711 // they are missing the translation related to the Display disposition in | 699 // they are missing the translation related to the Display disposition in |
| 712 // the layout. | 700 // the layout. |
| 713 // Using display.bounds() and display.work_area() would fail most of the | 701 // Using display.bounds() and display.work_area() would fail most of the |
| 714 // time. | 702 // time. |
| 715 if (force_bounds_changed_ || (current_display_info.bounds_in_native() != | 703 if (force_bounds_changed_ || (current_display_info.bounds_in_native() != |
| 716 new_display_info.bounds_in_native()) || | 704 new_display_info.bounds_in_native()) || |
| 717 (current_display_info.GetOverscanInsetsInPixel() != | 705 (current_display_info.GetOverscanInsetsInPixel() != |
| 718 new_display_info.GetOverscanInsetsInPixel()) || | 706 new_display_info.GetOverscanInsetsInPixel()) || |
| 719 current_display.size() != new_display.size()) { | 707 current_display.size() != new_display.size()) { |
| 720 metrics |= display::DisplayObserver::DISPLAY_METRIC_BOUNDS | | 708 metrics |= DisplayObserver::DISPLAY_METRIC_BOUNDS | |
| 721 display::DisplayObserver::DISPLAY_METRIC_WORK_AREA; | 709 DisplayObserver::DISPLAY_METRIC_WORK_AREA; |
| 722 } | 710 } |
| 723 | 711 |
| 724 if (current_display.device_scale_factor() != | 712 if (current_display.device_scale_factor() != |
| 725 new_display.device_scale_factor()) { | 713 new_display.device_scale_factor()) { |
| 726 metrics |= display::DisplayObserver::DISPLAY_METRIC_DEVICE_SCALE_FACTOR; | 714 metrics |= DisplayObserver::DISPLAY_METRIC_DEVICE_SCALE_FACTOR; |
| 727 } | 715 } |
| 728 | 716 |
| 729 if (current_display.rotation() != new_display.rotation()) | 717 if (current_display.rotation() != new_display.rotation()) |
| 730 metrics |= display::DisplayObserver::DISPLAY_METRIC_ROTATION; | 718 metrics |= DisplayObserver::DISPLAY_METRIC_ROTATION; |
| 731 | 719 |
| 732 if (metrics != display::DisplayObserver::DISPLAY_METRIC_NONE) { | 720 if (metrics != DisplayObserver::DISPLAY_METRIC_NONE) { |
| 733 display_changes.insert( | 721 display_changes.insert( |
| 734 std::pair<size_t, uint32_t>(new_displays.size(), metrics)); | 722 std::pair<size_t, uint32_t>(new_displays.size(), metrics)); |
| 735 } | 723 } |
| 736 | 724 |
| 737 new_display.UpdateWorkAreaFromInsets(current_display.GetWorkAreaInsets()); | 725 new_display.UpdateWorkAreaFromInsets(current_display.GetWorkAreaInsets()); |
| 738 new_displays.push_back(new_display); | 726 new_displays.push_back(new_display); |
| 739 ++curr_iter; | 727 ++curr_iter; |
| 740 ++new_info_iter; | 728 ++new_info_iter; |
| 741 } else if (curr_iter->id() < new_info_iter->id()) { | 729 } else if (curr_iter->id() < new_info_iter->id()) { |
| 742 // more displays in current list between ids, which means it is deleted. | 730 // more displays in current list between ids, which means it is deleted. |
| 743 removed_displays.push_back(*curr_iter); | 731 removed_displays.push_back(*curr_iter); |
| 744 ++curr_iter; | 732 ++curr_iter; |
| 745 } else { | 733 } else { |
| 746 // more displays in new list between ids, which means it is added. | 734 // more displays in new list between ids, which means it is added. |
| 747 added_display_indices.push_back(new_displays.size()); | 735 added_display_indices.push_back(new_displays.size()); |
| 748 InsertAndUpdateDisplayInfo(*new_info_iter); | 736 InsertAndUpdateDisplayInfo(*new_info_iter); |
| 749 new_displays.push_back( | 737 new_displays.push_back( |
| 750 CreateDisplayFromDisplayInfoById(new_info_iter->id())); | 738 CreateDisplayFromDisplayInfoById(new_info_iter->id())); |
| 751 ++new_info_iter; | 739 ++new_info_iter; |
| 752 } | 740 } |
| 753 } | 741 } |
| 754 display::Display old_primary; | 742 Display old_primary; |
| 755 if (delegate_) | 743 if (delegate_) |
| 756 old_primary = screen_->GetPrimaryDisplay(); | 744 old_primary = screen_->GetPrimaryDisplay(); |
| 757 | 745 |
| 758 // Clear focus if the display has been removed, but don't clear focus if | 746 // Clear focus if the display has been removed, but don't clear focus if |
| 759 // the destkop has been moved from one display to another | 747 // the destkop has been moved from one display to another |
| 760 // (mirror -> docked, docked -> single internal). | 748 // (mirror -> docked, docked -> single internal). |
| 761 bool clear_focus = | 749 bool clear_focus = |
| 762 !removed_displays.empty() && | 750 !removed_displays.empty() && |
| 763 !(removed_displays.size() == 1 && added_display_indices.size() == 1); | 751 !(removed_displays.size() == 1 && added_display_indices.size() == 1); |
| 764 if (delegate_) | 752 if (delegate_) |
| 765 delegate_->PreDisplayConfigurationChange(clear_focus); | 753 delegate_->PreDisplayConfigurationChange(clear_focus); |
| 766 | 754 |
| 767 std::vector<size_t> updated_indices; | 755 std::vector<size_t> updated_indices; |
| 768 UpdateNonPrimaryDisplayBoundsForLayout(&new_displays, &updated_indices); | 756 UpdateNonPrimaryDisplayBoundsForLayout(&new_displays, &updated_indices); |
| 769 for (size_t updated_index : updated_indices) { | 757 for (size_t updated_index : updated_indices) { |
| 770 if (std::find(added_display_indices.begin(), added_display_indices.end(), | 758 if (std::find(added_display_indices.begin(), added_display_indices.end(), |
| 771 updated_index) == added_display_indices.end()) { | 759 updated_index) == added_display_indices.end()) { |
| 772 uint32_t metrics = display::DisplayObserver::DISPLAY_METRIC_BOUNDS | | 760 uint32_t metrics = DisplayObserver::DISPLAY_METRIC_BOUNDS | |
| 773 display::DisplayObserver::DISPLAY_METRIC_WORK_AREA; | 761 DisplayObserver::DISPLAY_METRIC_WORK_AREA; |
| 774 if (display_changes.find(updated_index) != display_changes.end()) | 762 if (display_changes.find(updated_index) != display_changes.end()) |
| 775 metrics |= display_changes[updated_index]; | 763 metrics |= display_changes[updated_index]; |
| 776 | 764 |
| 777 display_changes[updated_index] = metrics; | 765 display_changes[updated_index] = metrics; |
| 778 } | 766 } |
| 779 } | 767 } |
| 780 | 768 |
| 781 active_display_list_ = new_displays; | 769 active_display_list_ = new_displays; |
| 782 active_only_display_list_ = active_display_list_; | 770 active_only_display_list_ = active_display_list_; |
| 783 | 771 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 799 | 787 |
| 800 active_display_list_.resize(active_display_list_size); | 788 active_display_list_.resize(active_display_list_size); |
| 801 is_updating_display_list_ = false; | 789 is_updating_display_list_ = false; |
| 802 | 790 |
| 803 bool notify_primary_change = | 791 bool notify_primary_change = |
| 804 delegate_ ? old_primary.id() != screen_->GetPrimaryDisplay().id() : false; | 792 delegate_ ? old_primary.id() != screen_->GetPrimaryDisplay().id() : false; |
| 805 | 793 |
| 806 for (std::map<size_t, uint32_t>::iterator iter = display_changes.begin(); | 794 for (std::map<size_t, uint32_t>::iterator iter = display_changes.begin(); |
| 807 iter != display_changes.end(); ++iter) { | 795 iter != display_changes.end(); ++iter) { |
| 808 uint32_t metrics = iter->second; | 796 uint32_t metrics = iter->second; |
| 809 const display::Display& updated_display = active_display_list_[iter->first]; | 797 const Display& updated_display = active_display_list_[iter->first]; |
| 810 | 798 |
| 811 if (notify_primary_change && | 799 if (notify_primary_change && |
| 812 updated_display.id() == screen_->GetPrimaryDisplay().id()) { | 800 updated_display.id() == screen_->GetPrimaryDisplay().id()) { |
| 813 metrics |= display::DisplayObserver::DISPLAY_METRIC_PRIMARY; | 801 metrics |= DisplayObserver::DISPLAY_METRIC_PRIMARY; |
| 814 notify_primary_change = false; | 802 notify_primary_change = false; |
| 815 } | 803 } |
| 816 NotifyMetricsChanged(updated_display, metrics); | 804 NotifyMetricsChanged(updated_display, metrics); |
| 817 } | 805 } |
| 818 | 806 |
| 819 if (notify_primary_change) { | 807 if (notify_primary_change) { |
| 820 // This happens when a primary display has moved to anther display without | 808 // This happens when a primary display has moved to anther display without |
| 821 // bounds change. | 809 // bounds change. |
| 822 const display::Display& primary = screen_->GetPrimaryDisplay(); | 810 const Display& primary = screen_->GetPrimaryDisplay(); |
| 823 if (primary.id() != old_primary.id()) { | 811 if (primary.id() != old_primary.id()) { |
| 824 uint32_t metrics = display::DisplayObserver::DISPLAY_METRIC_PRIMARY; | 812 uint32_t metrics = DisplayObserver::DISPLAY_METRIC_PRIMARY; |
| 825 if (primary.size() != old_primary.size()) { | 813 if (primary.size() != old_primary.size()) { |
| 826 metrics |= (display::DisplayObserver::DISPLAY_METRIC_BOUNDS | | 814 metrics |= (DisplayObserver::DISPLAY_METRIC_BOUNDS | |
| 827 display::DisplayObserver::DISPLAY_METRIC_WORK_AREA); | 815 DisplayObserver::DISPLAY_METRIC_WORK_AREA); |
| 828 } | 816 } |
| 829 if (primary.device_scale_factor() != old_primary.device_scale_factor()) | 817 if (primary.device_scale_factor() != old_primary.device_scale_factor()) |
| 830 metrics |= display::DisplayObserver::DISPLAY_METRIC_DEVICE_SCALE_FACTOR; | 818 metrics |= DisplayObserver::DISPLAY_METRIC_DEVICE_SCALE_FACTOR; |
| 831 | 819 |
| 832 NotifyMetricsChanged(primary, metrics); | 820 NotifyMetricsChanged(primary, metrics); |
| 833 } | 821 } |
| 834 } | 822 } |
| 835 | 823 |
| 836 bool must_clear_window = false; | 824 bool must_clear_window = false; |
| 837 #if defined(USE_X11) && defined(OS_CHROMEOS) | 825 #if defined(USE_X11) && defined(OS_CHROMEOS) |
| 838 must_clear_window = | 826 must_clear_window = |
| 839 !display_changes.empty() && base::SysInfo::IsRunningOnChromeOS(); | 827 !display_changes.empty() && base::SysInfo::IsRunningOnChromeOS(); |
| 840 #endif | 828 #endif |
| 841 | 829 |
| 842 if (delegate_) | 830 if (delegate_) |
| 843 delegate_->PostDisplayConfigurationChange(must_clear_window); | 831 delegate_->PostDisplayConfigurationChange(must_clear_window); |
| 844 | 832 |
| 845 // Create the mirroring window asynchronously after all displays | 833 // Create the mirroring window asynchronously after all displays |
| 846 // are added so that it can mirror the display newly added. This can | 834 // are added so that it can mirror the display newly added. This can |
| 847 // happen when switching from dock mode to software mirror mode. | 835 // happen when switching from dock mode to software mirror mode. |
| 848 CreateMirrorWindowAsyncIfAny(); | 836 CreateMirrorWindowAsyncIfAny(); |
| 849 } | 837 } |
| 850 | 838 |
| 851 const display::Display& DisplayManager::GetDisplayAt(size_t index) const { | 839 const Display& DisplayManager::GetDisplayAt(size_t index) const { |
| 852 DCHECK_LT(index, active_display_list_.size()); | 840 DCHECK_LT(index, active_display_list_.size()); |
| 853 return active_display_list_[index]; | 841 return active_display_list_[index]; |
| 854 } | 842 } |
| 855 | 843 |
| 856 const display::Display& DisplayManager::GetPrimaryDisplayCandidate() const { | 844 const Display& DisplayManager::GetPrimaryDisplayCandidate() const { |
| 857 if (GetNumDisplays() != 2) | 845 if (GetNumDisplays() != 2) |
| 858 return active_display_list_[0]; | 846 return active_display_list_[0]; |
| 859 const display::DisplayLayout& layout = | 847 const DisplayLayout& layout = |
| 860 layout_store_->GetRegisteredDisplayLayout(GetCurrentDisplayIdList()); | 848 layout_store_->GetRegisteredDisplayLayout(GetCurrentDisplayIdList()); |
| 861 return GetDisplayForId(layout.primary_id); | 849 return GetDisplayForId(layout.primary_id); |
| 862 } | 850 } |
| 863 | 851 |
| 864 size_t DisplayManager::GetNumDisplays() const { | 852 size_t DisplayManager::GetNumDisplays() const { |
| 865 return active_display_list_.size(); | 853 return active_display_list_.size(); |
| 866 } | 854 } |
| 867 | 855 |
| 868 bool DisplayManager::IsActiveDisplayId(int64_t display_id) const { | 856 bool DisplayManager::IsActiveDisplayId(int64_t display_id) const { |
| 869 return std::find_if(active_display_list_.begin(), active_display_list_.end(), | 857 return std::find_if(active_display_list_.begin(), active_display_list_.end(), |
| 870 [display_id](const display::Display& display) { | 858 [display_id](const Display& display) { |
| 871 return display.id() == display_id; | 859 return display.id() == display_id; |
| 872 }) != active_display_list_.end(); | 860 }) != active_display_list_.end(); |
| 873 } | 861 } |
| 874 | 862 |
| 875 bool DisplayManager::IsInMirrorMode() const { | 863 bool DisplayManager::IsInMirrorMode() const { |
| 876 return mirroring_display_id_ != kInvalidDisplayId; | 864 return mirroring_display_id_ != kInvalidDisplayId; |
| 877 } | 865 } |
| 878 | 866 |
| 879 void DisplayManager::SetUnifiedDesktopEnabled(bool enable) { | 867 void DisplayManager::SetUnifiedDesktopEnabled(bool enable) { |
| 880 unified_desktop_enabled_ = enable; | 868 unified_desktop_enabled_ = enable; |
| 881 // There is no need to update the displays in mirror mode. Doing | 869 // There is no need to update the displays in mirror mode. Doing |
| 882 // this in hardware mirroring mode can cause crash because display | 870 // this in hardware mirroring mode can cause crash because display |
| 883 // info in hardware mirroring comes from DisplayConfigurator. | 871 // info in hardware mirroring comes from DisplayConfigurator. |
| 884 if (!IsInMirrorMode()) | 872 if (!IsInMirrorMode()) |
| 885 ReconfigureDisplays(); | 873 ReconfigureDisplays(); |
| 886 } | 874 } |
| 887 | 875 |
| 888 bool DisplayManager::IsInUnifiedMode() const { | 876 bool DisplayManager::IsInUnifiedMode() const { |
| 889 return multi_display_mode_ == UNIFIED && | 877 return multi_display_mode_ == UNIFIED && |
| 890 !software_mirroring_display_list_.empty(); | 878 !software_mirroring_display_list_.empty(); |
| 891 } | 879 } |
| 892 | 880 |
| 893 const display::ManagedDisplayInfo& DisplayManager::GetDisplayInfo( | 881 const ManagedDisplayInfo& DisplayManager::GetDisplayInfo( |
| 894 int64_t display_id) const { | 882 int64_t display_id) const { |
| 895 DCHECK_NE(kInvalidDisplayId, display_id); | 883 DCHECK_NE(kInvalidDisplayId, display_id); |
| 896 | 884 |
| 897 std::map<int64_t, display::ManagedDisplayInfo>::const_iterator iter = | 885 std::map<int64_t, ManagedDisplayInfo>::const_iterator iter = |
| 898 display_info_.find(display_id); | 886 display_info_.find(display_id); |
| 899 CHECK(iter != display_info_.end()) << display_id; | 887 CHECK(iter != display_info_.end()) << display_id; |
| 900 return iter->second; | 888 return iter->second; |
| 901 } | 889 } |
| 902 | 890 |
| 903 const display::Display DisplayManager::GetMirroringDisplayById( | 891 const Display DisplayManager::GetMirroringDisplayById( |
| 904 int64_t display_id) const { | 892 int64_t display_id) const { |
| 905 auto iter = std::find_if(software_mirroring_display_list_.begin(), | 893 auto iter = std::find_if(software_mirroring_display_list_.begin(), |
| 906 software_mirroring_display_list_.end(), | 894 software_mirroring_display_list_.end(), |
| 907 [display_id](const display::Display& display) { | 895 [display_id](const Display& display) { |
| 908 return display.id() == display_id; | 896 return display.id() == display_id; |
| 909 }); | 897 }); |
| 910 return iter == software_mirroring_display_list_.end() ? display::Display() | 898 return iter == software_mirroring_display_list_.end() ? Display() : *iter; |
| 911 : *iter; | |
| 912 } | 899 } |
| 913 | 900 |
| 914 std::string DisplayManager::GetDisplayNameForId(int64_t id) { | 901 std::string DisplayManager::GetDisplayNameForId(int64_t id) { |
| 915 if (id == kInvalidDisplayId) | 902 if (id == kInvalidDisplayId) |
| 916 return delegate_->GetInternalDisplayNameString(); | 903 return delegate_->GetInternalDisplayNameString(); |
| 917 | 904 |
| 918 std::map<int64_t, display::ManagedDisplayInfo>::const_iterator iter = | 905 std::map<int64_t, ManagedDisplayInfo>::const_iterator iter = |
| 919 display_info_.find(id); | 906 display_info_.find(id); |
| 920 if (iter != display_info_.end() && !iter->second.name().empty()) | 907 if (iter != display_info_.end() && !iter->second.name().empty()) |
| 921 return iter->second.name(); | 908 return iter->second.name(); |
| 922 | 909 |
| 923 return base::StringPrintf("Display %d", static_cast<int>(id)); | 910 return base::StringPrintf("Display %d", static_cast<int>(id)); |
| 924 } | 911 } |
| 925 | 912 |
| 926 int64_t DisplayManager::GetDisplayIdForUIScaling() const { | 913 int64_t DisplayManager::GetDisplayIdForUIScaling() const { |
| 927 // UI Scaling is effective on internal display. | 914 // UI Scaling is effective on internal display. |
| 928 return display::Display::HasInternalDisplay() | 915 return Display::HasInternalDisplay() ? Display::InternalDisplayId() |
| 929 ? display::Display::InternalDisplayId() | 916 : kInvalidDisplayId; |
| 930 : kInvalidDisplayId; | |
| 931 } | 917 } |
| 932 | 918 |
| 933 void DisplayManager::SetMirrorMode(bool mirror) { | 919 void DisplayManager::SetMirrorMode(bool mirror) { |
| 934 // TODO(oshima): Enable mirror mode for 2> displays. crbug.com/589319. | 920 // TODO(oshima): Enable mirror mode for 2> displays. crbug.com/589319. |
| 935 if (num_connected_displays() != 2) | 921 if (num_connected_displays() != 2) |
| 936 return; | 922 return; |
| 937 | 923 |
| 938 #if defined(OS_CHROMEOS) | 924 #if defined(OS_CHROMEOS) |
| 939 if (base::SysInfo::IsRunningOnChromeOS()) { | 925 if (base::SysInfo::IsRunningOnChromeOS()) { |
| 940 ui::MultipleDisplayState new_state = | 926 ui::MultipleDisplayState new_state = |
| 941 mirror ? ui::MULTIPLE_DISPLAY_STATE_DUAL_MIRROR | 927 mirror ? ui::MULTIPLE_DISPLAY_STATE_DUAL_MIRROR |
| 942 : ui::MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED; | 928 : ui::MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED; |
| 943 delegate_->display_configurator()->SetDisplayMode(new_state); | 929 delegate_->display_configurator()->SetDisplayMode(new_state); |
| 944 return; | 930 return; |
| 945 } | 931 } |
| 946 #endif | 932 #endif |
| 947 multi_display_mode_ = | 933 multi_display_mode_ = |
| 948 mirror ? MIRRORING : current_default_multi_display_mode_; | 934 mirror ? MIRRORING : current_default_multi_display_mode_; |
| 949 ReconfigureDisplays(); | 935 ReconfigureDisplays(); |
| 950 } | 936 } |
| 951 | 937 |
| 952 void DisplayManager::AddRemoveDisplay() { | 938 void DisplayManager::AddRemoveDisplay() { |
| 953 DCHECK(!active_display_list_.empty()); | 939 DCHECK(!active_display_list_.empty()); |
| 954 DisplayInfoList new_display_info_list; | 940 DisplayInfoList new_display_info_list; |
| 955 const display::ManagedDisplayInfo& first_display = | 941 const ManagedDisplayInfo& first_display = |
| 956 IsInUnifiedMode() | 942 IsInUnifiedMode() |
| 957 ? GetDisplayInfo(software_mirroring_display_list_[0].id()) | 943 ? GetDisplayInfo(software_mirroring_display_list_[0].id()) |
| 958 : GetDisplayInfo(active_display_list_[0].id()); | 944 : GetDisplayInfo(active_display_list_[0].id()); |
| 959 new_display_info_list.push_back(first_display); | 945 new_display_info_list.push_back(first_display); |
| 960 // Add if there is only one display connected. | 946 // Add if there is only one display connected. |
| 961 if (num_connected_displays() == 1) { | 947 if (num_connected_displays() == 1) { |
| 962 const int kVerticalOffsetPx = 100; | 948 const int kVerticalOffsetPx = 100; |
| 963 // Layout the 2nd display below the primary as with the real device. | 949 // Layout the 2nd display below the primary as with the real device. |
| 964 gfx::Rect host_bounds = first_display.bounds_in_native(); | 950 gfx::Rect host_bounds = first_display.bounds_in_native(); |
| 965 new_display_info_list.push_back( | 951 new_display_info_list.push_back( |
| 966 display::ManagedDisplayInfo::CreateFromSpec(base::StringPrintf( | 952 ManagedDisplayInfo::CreateFromSpec(base::StringPrintf( |
| 967 "%d+%d-600x%d", host_bounds.x(), | 953 "%d+%d-600x%d", host_bounds.x(), |
| 968 host_bounds.bottom() + kVerticalOffsetPx, host_bounds.height()))); | 954 host_bounds.bottom() + kVerticalOffsetPx, host_bounds.height()))); |
| 969 } | 955 } |
| 970 num_connected_displays_ = new_display_info_list.size(); | 956 num_connected_displays_ = new_display_info_list.size(); |
| 971 mirroring_display_id_ = kInvalidDisplayId; | 957 mirroring_display_id_ = kInvalidDisplayId; |
| 972 software_mirroring_display_list_.clear(); | 958 software_mirroring_display_list_.clear(); |
| 973 UpdateDisplaysWith(new_display_info_list); | 959 UpdateDisplaysWith(new_display_info_list); |
| 974 } | 960 } |
| 975 | 961 |
| 976 void DisplayManager::ToggleDisplayScaleFactor() { | 962 void DisplayManager::ToggleDisplayScaleFactor() { |
| 977 DCHECK(!active_display_list_.empty()); | 963 DCHECK(!active_display_list_.empty()); |
| 978 DisplayInfoList new_display_info_list; | 964 DisplayInfoList new_display_info_list; |
| 979 for (display::Displays::const_iterator iter = active_display_list_.begin(); | 965 for (Displays::const_iterator iter = active_display_list_.begin(); |
| 980 iter != active_display_list_.end(); ++iter) { | 966 iter != active_display_list_.end(); ++iter) { |
| 981 display::ManagedDisplayInfo display_info = GetDisplayInfo(iter->id()); | 967 ManagedDisplayInfo display_info = GetDisplayInfo(iter->id()); |
| 982 display_info.set_device_scale_factor( | 968 display_info.set_device_scale_factor( |
| 983 display_info.device_scale_factor() == 1.0f ? 2.0f : 1.0f); | 969 display_info.device_scale_factor() == 1.0f ? 2.0f : 1.0f); |
| 984 new_display_info_list.push_back(display_info); | 970 new_display_info_list.push_back(display_info); |
| 985 } | 971 } |
| 986 AddMirrorDisplayInfoIfAny(&new_display_info_list); | 972 AddMirrorDisplayInfoIfAny(&new_display_info_list); |
| 987 UpdateDisplaysWith(new_display_info_list); | 973 UpdateDisplaysWith(new_display_info_list); |
| 988 } | 974 } |
| 989 | 975 |
| 990 #if defined(OS_CHROMEOS) | 976 #if defined(OS_CHROMEOS) |
| 991 void DisplayManager::SetSoftwareMirroring(bool enabled) { | 977 void DisplayManager::SetSoftwareMirroring(bool enabled) { |
| 992 SetMultiDisplayMode(enabled ? MIRRORING | 978 SetMultiDisplayMode(enabled ? MIRRORING |
| 993 : current_default_multi_display_mode_); | 979 : current_default_multi_display_mode_); |
| 994 } | 980 } |
| 995 | 981 |
| 996 bool DisplayManager::SoftwareMirroringEnabled() const { | 982 bool DisplayManager::SoftwareMirroringEnabled() const { |
| 997 return software_mirroring_enabled(); | 983 return software_mirroring_enabled(); |
| 998 } | 984 } |
| 999 #endif | 985 #endif |
| 1000 | 986 |
| 1001 void DisplayManager::SetDefaultMultiDisplayModeForCurrentDisplays( | 987 void DisplayManager::SetDefaultMultiDisplayModeForCurrentDisplays( |
| 1002 MultiDisplayMode mode) { | 988 MultiDisplayMode mode) { |
| 1003 DCHECK_NE(MIRRORING, mode); | 989 DCHECK_NE(MIRRORING, mode); |
| 1004 display::DisplayIdList list = GetCurrentDisplayIdList(); | 990 DisplayIdList list = GetCurrentDisplayIdList(); |
| 1005 layout_store_->UpdateMultiDisplayState(list, IsInMirrorMode(), | 991 layout_store_->UpdateMultiDisplayState(list, IsInMirrorMode(), |
| 1006 mode == UNIFIED); | 992 mode == UNIFIED); |
| 1007 ReconfigureDisplays(); | 993 ReconfigureDisplays(); |
| 1008 } | 994 } |
| 1009 | 995 |
| 1010 void DisplayManager::SetMultiDisplayMode(MultiDisplayMode mode) { | 996 void DisplayManager::SetMultiDisplayMode(MultiDisplayMode mode) { |
| 1011 multi_display_mode_ = mode; | 997 multi_display_mode_ = mode; |
| 1012 mirroring_display_id_ = kInvalidDisplayId; | 998 mirroring_display_id_ = kInvalidDisplayId; |
| 1013 software_mirroring_display_list_.clear(); | 999 software_mirroring_display_list_.clear(); |
| 1014 } | 1000 } |
| 1015 | 1001 |
| 1016 void DisplayManager::ReconfigureDisplays() { | 1002 void DisplayManager::ReconfigureDisplays() { |
| 1017 DisplayInfoList display_info_list; | 1003 DisplayInfoList display_info_list; |
| 1018 for (const display::Display& display : active_display_list_) { | 1004 for (const Display& display : active_display_list_) { |
| 1019 if (display.id() == kUnifiedDisplayId) | 1005 if (display.id() == kUnifiedDisplayId) |
| 1020 continue; | 1006 continue; |
| 1021 display_info_list.push_back(GetDisplayInfo(display.id())); | 1007 display_info_list.push_back(GetDisplayInfo(display.id())); |
| 1022 } | 1008 } |
| 1023 for (const display::Display& display : software_mirroring_display_list_) | 1009 for (const Display& display : software_mirroring_display_list_) |
| 1024 display_info_list.push_back(GetDisplayInfo(display.id())); | 1010 display_info_list.push_back(GetDisplayInfo(display.id())); |
| 1025 mirroring_display_id_ = kInvalidDisplayId; | 1011 mirroring_display_id_ = kInvalidDisplayId; |
| 1026 software_mirroring_display_list_.clear(); | 1012 software_mirroring_display_list_.clear(); |
| 1027 UpdateDisplaysWith(display_info_list); | 1013 UpdateDisplaysWith(display_info_list); |
| 1028 } | 1014 } |
| 1029 | 1015 |
| 1030 bool DisplayManager::UpdateDisplayBounds(int64_t display_id, | 1016 bool DisplayManager::UpdateDisplayBounds(int64_t display_id, |
| 1031 const gfx::Rect& new_bounds) { | 1017 const gfx::Rect& new_bounds) { |
| 1032 if (change_display_upon_host_resize_) { | 1018 if (change_display_upon_host_resize_) { |
| 1033 display_info_[display_id].SetBounds(new_bounds); | 1019 display_info_[display_id].SetBounds(new_bounds); |
| 1034 // Don't notify observers if the mirrored window has changed. | 1020 // Don't notify observers if the mirrored window has changed. |
| 1035 if (software_mirroring_enabled() && mirroring_display_id_ == display_id) | 1021 if (software_mirroring_enabled() && mirroring_display_id_ == display_id) |
| 1036 return false; | 1022 return false; |
| 1037 display::Display* display = FindDisplayForId(display_id); | 1023 Display* display = FindDisplayForId(display_id); |
| 1038 display->SetSize(display_info_[display_id].size_in_pixel()); | 1024 display->SetSize(display_info_[display_id].size_in_pixel()); |
| 1039 NotifyMetricsChanged(*display, | 1025 NotifyMetricsChanged(*display, DisplayObserver::DISPLAY_METRIC_BOUNDS); |
| 1040 display::DisplayObserver::DISPLAY_METRIC_BOUNDS); | |
| 1041 return true; | 1026 return true; |
| 1042 } | 1027 } |
| 1043 return false; | 1028 return false; |
| 1044 } | 1029 } |
| 1045 | 1030 |
| 1046 void DisplayManager::CreateMirrorWindowAsyncIfAny() { | 1031 void DisplayManager::CreateMirrorWindowAsyncIfAny() { |
| 1047 // Do not post a task if the software mirroring doesn't exist, or | 1032 // Do not post a task if the software mirroring doesn't exist, or |
| 1048 // during initialization when compositor's init task isn't posted yet. | 1033 // during initialization when compositor's init task isn't posted yet. |
| 1049 // ash::Shell::Init() will call this after the compositor is initialized. | 1034 // ash::Shell::Init() will call this after the compositor is initialized. |
| 1050 if (software_mirroring_display_list_.empty() || !delegate_) | 1035 if (software_mirroring_display_list_.empty() || !delegate_) |
| 1051 return; | 1036 return; |
| 1052 base::ThreadTaskRunnerHandle::Get()->PostTask( | 1037 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 1053 FROM_HERE, base::Bind(&DisplayManager::CreateMirrorWindowIfAny, | 1038 FROM_HERE, base::Bind(&DisplayManager::CreateMirrorWindowIfAny, |
| 1054 weak_ptr_factory_.GetWeakPtr())); | 1039 weak_ptr_factory_.GetWeakPtr())); |
| 1055 } | 1040 } |
| 1056 | 1041 |
| 1057 void DisplayManager::UpdateInternalManagedDisplayModeListForTest() { | 1042 void DisplayManager::UpdateInternalManagedDisplayModeListForTest() { |
| 1058 if (!display::Display::HasInternalDisplay() || | 1043 if (!Display::HasInternalDisplay() || |
| 1059 display_info_.count(display::Display::InternalDisplayId()) == 0) | 1044 display_info_.count(Display::InternalDisplayId()) == 0) |
| 1060 return; | 1045 return; |
| 1061 display::ManagedDisplayInfo* info = | 1046 ManagedDisplayInfo* info = &display_info_[Display::InternalDisplayId()]; |
| 1062 &display_info_[display::Display::InternalDisplayId()]; | |
| 1063 SetInternalManagedDisplayModeList(info); | 1047 SetInternalManagedDisplayModeList(info); |
| 1064 } | 1048 } |
| 1065 | 1049 |
| 1066 bool DisplayManager::ZoomInternalDisplay(bool up) { | 1050 bool DisplayManager::ZoomInternalDisplay(bool up) { |
| 1067 int64_t display_id = | 1051 int64_t display_id = |
| 1068 IsInUnifiedMode() ? kUnifiedDisplayId : GetDisplayIdForUIScaling(); | 1052 IsInUnifiedMode() ? kUnifiedDisplayId : GetDisplayIdForUIScaling(); |
| 1069 const display::ManagedDisplayInfo& display_info = GetDisplayInfo(display_id); | 1053 const ManagedDisplayInfo& display_info = GetDisplayInfo(display_id); |
| 1070 | 1054 |
| 1071 scoped_refptr<display::ManagedDisplayMode> mode; | 1055 scoped_refptr<ManagedDisplayMode> mode; |
| 1072 if (IsInUnifiedMode()) { | 1056 if (IsInUnifiedMode()) { |
| 1073 mode = GetDisplayModeForNextResolution(display_info, up); | 1057 mode = GetDisplayModeForNextResolution(display_info, up); |
| 1074 } else { | 1058 } else { |
| 1075 if (!IsActiveDisplayId(display_info.id()) || | 1059 if (!IsActiveDisplayId(display_info.id()) || |
| 1076 !display::Display::IsInternalDisplayId(display_info.id())) { | 1060 !Display::IsInternalDisplayId(display_info.id())) { |
| 1077 return false; | 1061 return false; |
| 1078 } | 1062 } |
| 1079 mode = GetDisplayModeForNextUIScale(display_info, up); | 1063 mode = GetDisplayModeForNextUIScale(display_info, up); |
| 1080 } | 1064 } |
| 1081 | 1065 |
| 1082 return mode ? SetDisplayMode(display_id, mode) : false; | 1066 return mode ? SetDisplayMode(display_id, mode) : false; |
| 1083 } | 1067 } |
| 1084 | 1068 |
| 1085 bool DisplayManager::ResetDisplayToDefaultMode(int64_t id) { | 1069 bool DisplayManager::ResetDisplayToDefaultMode(int64_t id) { |
| 1086 if (!IsActiveDisplayId(id) || !display::Display::IsInternalDisplayId(id)) | 1070 if (!IsActiveDisplayId(id) || !Display::IsInternalDisplayId(id)) |
| 1087 return false; | 1071 return false; |
| 1088 | 1072 |
| 1089 const display::ManagedDisplayInfo& info = GetDisplayInfo(id); | 1073 const ManagedDisplayInfo& info = GetDisplayInfo(id); |
| 1090 scoped_refptr<display::ManagedDisplayMode> mode = GetDefaultDisplayMode(info); | 1074 scoped_refptr<ManagedDisplayMode> mode = GetDefaultDisplayMode(info); |
| 1091 | 1075 |
| 1092 return mode ? SetDisplayMode(id, mode) : false; | 1076 return mode ? SetDisplayMode(id, mode) : false; |
| 1093 } | 1077 } |
| 1094 | 1078 |
| 1095 void DisplayManager::ResetInternalDisplayZoom() { | 1079 void DisplayManager::ResetInternalDisplayZoom() { |
| 1096 if (IsInUnifiedMode()) { | 1080 if (IsInUnifiedMode()) { |
| 1097 const display::ManagedDisplayInfo& display_info = | 1081 const ManagedDisplayInfo& display_info = |
| 1098 GetDisplayInfo(DisplayManager::kUnifiedDisplayId); | 1082 GetDisplayInfo(DisplayManager::kUnifiedDisplayId); |
| 1099 const display::ManagedDisplayInfo::ManagedDisplayModeList& modes = | 1083 const ManagedDisplayInfo::ManagedDisplayModeList& modes = |
| 1100 display_info.display_modes(); | 1084 display_info.display_modes(); |
| 1101 auto iter = std::find_if( | 1085 auto iter = std::find_if(modes.begin(), modes.end(), |
| 1102 modes.begin(), modes.end(), | 1086 [](const scoped_refptr<ManagedDisplayMode>& mode) { |
| 1103 [](const scoped_refptr<display::ManagedDisplayMode>& mode) { | 1087 return mode->native(); |
| 1104 return mode->native(); | 1088 }); |
| 1105 }); | |
| 1106 SetDisplayMode(kUnifiedDisplayId, *iter); | 1089 SetDisplayMode(kUnifiedDisplayId, *iter); |
| 1107 } else { | 1090 } else { |
| 1108 ResetDisplayToDefaultMode(GetDisplayIdForUIScaling()); | 1091 ResetDisplayToDefaultMode(GetDisplayIdForUIScaling()); |
| 1109 } | 1092 } |
| 1110 } | 1093 } |
| 1111 | 1094 |
| 1112 void DisplayManager::CreateSoftwareMirroringDisplayInfo( | 1095 void DisplayManager::CreateSoftwareMirroringDisplayInfo( |
| 1113 DisplayInfoList* display_info_list) { | 1096 DisplayInfoList* display_info_list) { |
| 1114 // Use the internal display or 1st as the mirror source, then scale | 1097 // Use the internal display or 1st as the mirror source, then scale |
| 1115 // the root window so that it matches the external display's | 1098 // the root window so that it matches the external display's |
| 1116 // resolution. This is necessary in order for scaling to work while | 1099 // resolution. This is necessary in order for scaling to work while |
| 1117 // mirrored. | 1100 // mirrored. |
| 1118 switch (multi_display_mode_) { | 1101 switch (multi_display_mode_) { |
| 1119 case MIRRORING: { | 1102 case MIRRORING: { |
| 1120 if (display_info_list->size() != 2) | 1103 if (display_info_list->size() != 2) |
| 1121 return; | 1104 return; |
| 1122 bool zero_is_source = | 1105 bool zero_is_source = |
| 1123 first_display_id_ == (*display_info_list)[0].id() || | 1106 first_display_id_ == (*display_info_list)[0].id() || |
| 1124 display::Display::IsInternalDisplayId((*display_info_list)[0].id()); | 1107 Display::IsInternalDisplayId((*display_info_list)[0].id()); |
| 1125 DCHECK_EQ(MIRRORING, multi_display_mode_); | 1108 DCHECK_EQ(MIRRORING, multi_display_mode_); |
| 1126 mirroring_display_id_ = (*display_info_list)[zero_is_source ? 1 : 0].id(); | 1109 mirroring_display_id_ = (*display_info_list)[zero_is_source ? 1 : 0].id(); |
| 1127 | 1110 |
| 1128 int64_t display_id = mirroring_display_id_; | 1111 int64_t display_id = mirroring_display_id_; |
| 1129 auto iter = | 1112 auto iter = |
| 1130 std::find_if(display_info_list->begin(), display_info_list->end(), | 1113 std::find_if(display_info_list->begin(), display_info_list->end(), |
| 1131 [display_id](const display::ManagedDisplayInfo& info) { | 1114 [display_id](const ManagedDisplayInfo& info) { |
| 1132 return info.id() == display_id; | 1115 return info.id() == display_id; |
| 1133 }); | 1116 }); |
| 1134 DCHECK(iter != display_info_list->end()); | 1117 DCHECK(iter != display_info_list->end()); |
| 1135 | 1118 |
| 1136 display::ManagedDisplayInfo info = *iter; | 1119 ManagedDisplayInfo info = *iter; |
| 1137 info.SetOverscanInsets(gfx::Insets()); | 1120 info.SetOverscanInsets(gfx::Insets()); |
| 1138 InsertAndUpdateDisplayInfo(info); | 1121 InsertAndUpdateDisplayInfo(info); |
| 1139 software_mirroring_display_list_.push_back( | 1122 software_mirroring_display_list_.push_back( |
| 1140 CreateMirroringDisplayFromDisplayInfoById(mirroring_display_id_, | 1123 CreateMirroringDisplayFromDisplayInfoById(mirroring_display_id_, |
| 1141 gfx::Point(), 1.0f)); | 1124 gfx::Point(), 1.0f)); |
| 1142 display_info_list->erase(iter); | 1125 display_info_list->erase(iter); |
| 1143 break; | 1126 break; |
| 1144 } | 1127 } |
| 1145 case UNIFIED: { | 1128 case UNIFIED: { |
| 1146 if (display_info_list->size() == 1) | 1129 if (display_info_list->size() == 1) |
| 1147 return; | 1130 return; |
| 1148 // TODO(oshima): Currently, all displays are laid out horizontally, | 1131 // TODO(oshima): Currently, all displays are laid out horizontally, |
| 1149 // from left to right. Allow more flexible layouts, such as | 1132 // from left to right. Allow more flexible layouts, such as |
| 1150 // right to left, or vertical layouts. | 1133 // right to left, or vertical layouts. |
| 1151 gfx::Rect unified_bounds; | 1134 gfx::Rect unified_bounds; |
| 1152 software_mirroring_display_list_.clear(); | 1135 software_mirroring_display_list_.clear(); |
| 1153 // 1st Pass. Find the max size. | 1136 // 1st Pass. Find the max size. |
| 1154 int max_height = std::numeric_limits<int>::min(); | 1137 int max_height = std::numeric_limits<int>::min(); |
| 1155 | 1138 |
| 1156 int default_height = 0; | 1139 int default_height = 0; |
| 1157 float default_device_scale_factor = 1.0f; | 1140 float default_device_scale_factor = 1.0f; |
| 1158 for (auto& info : *display_info_list) { | 1141 for (auto& info : *display_info_list) { |
| 1159 max_height = std::max(max_height, info.size_in_pixel().height()); | 1142 max_height = std::max(max_height, info.size_in_pixel().height()); |
| 1160 if (!default_height || | 1143 if (!default_height || Display::IsInternalDisplayId(info.id())) { |
| 1161 display::Display::IsInternalDisplayId(info.id())) { | |
| 1162 default_height = info.size_in_pixel().height(); | 1144 default_height = info.size_in_pixel().height(); |
| 1163 default_device_scale_factor = info.device_scale_factor(); | 1145 default_device_scale_factor = info.device_scale_factor(); |
| 1164 } | 1146 } |
| 1165 } | 1147 } |
| 1166 | 1148 |
| 1167 display::ManagedDisplayInfo::ManagedDisplayModeList display_mode_list; | 1149 ManagedDisplayInfo::ManagedDisplayModeList display_mode_list; |
| 1168 std::set<std::pair<float, float>> dsf_scale_list; | 1150 std::set<std::pair<float, float>> dsf_scale_list; |
| 1169 | 1151 |
| 1170 // 2nd Pass. Compute the unified display size. | 1152 // 2nd Pass. Compute the unified display size. |
| 1171 for (auto& info : *display_info_list) { | 1153 for (auto& info : *display_info_list) { |
| 1172 InsertAndUpdateDisplayInfo(info); | 1154 InsertAndUpdateDisplayInfo(info); |
| 1173 gfx::Point origin(unified_bounds.right(), 0); | 1155 gfx::Point origin(unified_bounds.right(), 0); |
| 1174 float scale = | 1156 float scale = |
| 1175 info.size_in_pixel().height() / static_cast<float>(max_height); | 1157 info.size_in_pixel().height() / static_cast<float>(max_height); |
| 1176 // The display is scaled to fit the unified desktop size. | 1158 // The display is scaled to fit the unified desktop size. |
| 1177 display::Display display = CreateMirroringDisplayFromDisplayInfoById( | 1159 Display display = CreateMirroringDisplayFromDisplayInfoById( |
| 1178 info.id(), origin, 1.0f / scale); | 1160 info.id(), origin, 1.0f / scale); |
| 1179 unified_bounds.Union(display.bounds()); | 1161 unified_bounds.Union(display.bounds()); |
| 1180 | 1162 |
| 1181 dsf_scale_list.insert( | 1163 dsf_scale_list.insert( |
| 1182 std::make_pair(info.device_scale_factor(), scale)); | 1164 std::make_pair(info.device_scale_factor(), scale)); |
| 1183 } | 1165 } |
| 1184 | 1166 |
| 1185 display::ManagedDisplayInfo info(kUnifiedDisplayId, "Unified Desktop", | 1167 ManagedDisplayInfo info(kUnifiedDisplayId, "Unified Desktop", false); |
| 1186 false); | |
| 1187 | 1168 |
| 1188 scoped_refptr<display::ManagedDisplayMode> native_mode( | 1169 scoped_refptr<ManagedDisplayMode> native_mode(new ManagedDisplayMode( |
| 1189 new display::ManagedDisplayMode(unified_bounds.size(), 60.0f, false, | 1170 unified_bounds.size(), 60.0f, false, true, 1.0, 1.0)); |
| 1190 true, 1.0, 1.0)); | 1171 ManagedDisplayInfo::ManagedDisplayModeList modes = |
| 1191 display::ManagedDisplayInfo::ManagedDisplayModeList modes = | |
| 1192 CreateUnifiedManagedDisplayModeList(native_mode, dsf_scale_list); | 1172 CreateUnifiedManagedDisplayModeList(native_mode, dsf_scale_list); |
| 1193 | 1173 |
| 1194 // Find the default mode. | 1174 // Find the default mode. |
| 1195 auto iter = std::find_if( | 1175 auto iter = std::find_if( |
| 1196 modes.begin(), modes.end(), | 1176 modes.begin(), modes.end(), |
| 1197 [default_height, default_device_scale_factor]( | 1177 [default_height, default_device_scale_factor]( |
| 1198 const scoped_refptr<display::ManagedDisplayMode>& mode) { | 1178 const scoped_refptr<ManagedDisplayMode>& mode) { |
| 1199 return mode->size().height() == default_height && | 1179 return mode->size().height() == default_height && |
| 1200 mode->device_scale_factor() == default_device_scale_factor; | 1180 mode->device_scale_factor() == default_device_scale_factor; |
| 1201 }); | 1181 }); |
| 1202 | 1182 |
| 1203 scoped_refptr<display::ManagedDisplayMode> dm(*iter); | 1183 scoped_refptr<ManagedDisplayMode> dm(*iter); |
| 1204 *iter = make_scoped_refptr(new display::ManagedDisplayMode( | 1184 *iter = make_scoped_refptr(new ManagedDisplayMode( |
| 1205 dm->size(), dm->refresh_rate(), dm->is_interlaced(), | 1185 dm->size(), dm->refresh_rate(), dm->is_interlaced(), |
| 1206 true /* native */, dm->ui_scale(), dm->device_scale_factor())); | 1186 true /* native */, dm->ui_scale(), dm->device_scale_factor())); |
| 1207 | 1187 |
| 1208 info.SetManagedDisplayModes(modes); | 1188 info.SetManagedDisplayModes(modes); |
| 1209 info.set_device_scale_factor(dm->device_scale_factor()); | 1189 info.set_device_scale_factor(dm->device_scale_factor()); |
| 1210 info.SetBounds(gfx::Rect(dm->size())); | 1190 info.SetBounds(gfx::Rect(dm->size())); |
| 1211 | 1191 |
| 1212 // Forget the configured resolution if the original unified | 1192 // Forget the configured resolution if the original unified |
| 1213 // desktop resolution has changed. | 1193 // desktop resolution has changed. |
| 1214 if (display_info_.count(kUnifiedDisplayId) != 0 && | 1194 if (display_info_.count(kUnifiedDisplayId) != 0 && |
| 1215 GetMaxNativeSize(display_info_[kUnifiedDisplayId]) != | 1195 GetMaxNativeSize(display_info_[kUnifiedDisplayId]) != |
| 1216 unified_bounds.size()) { | 1196 unified_bounds.size()) { |
| 1217 display_modes_.erase(kUnifiedDisplayId); | 1197 display_modes_.erase(kUnifiedDisplayId); |
| 1218 } | 1198 } |
| 1219 | 1199 |
| 1220 // 3rd Pass. Set the selected mode, then recompute the mirroring | 1200 // 3rd Pass. Set the selected mode, then recompute the mirroring |
| 1221 // display size. | 1201 // display size. |
| 1222 scoped_refptr<display::ManagedDisplayMode> mode = | 1202 scoped_refptr<ManagedDisplayMode> mode = |
| 1223 GetSelectedModeForDisplayId(kUnifiedDisplayId); | 1203 GetSelectedModeForDisplayId(kUnifiedDisplayId); |
| 1224 if (mode && FindDisplayMode(info, mode) != info.display_modes().end()) { | 1204 if (mode && FindDisplayMode(info, mode) != info.display_modes().end()) { |
| 1225 info.set_device_scale_factor(mode->device_scale_factor()); | 1205 info.set_device_scale_factor(mode->device_scale_factor()); |
| 1226 info.SetBounds(gfx::Rect(mode->size())); | 1206 info.SetBounds(gfx::Rect(mode->size())); |
| 1227 } else { | 1207 } else { |
| 1228 display_modes_.erase(kUnifiedDisplayId); | 1208 display_modes_.erase(kUnifiedDisplayId); |
| 1229 } | 1209 } |
| 1230 | 1210 |
| 1231 int unified_display_height = info.size_in_pixel().height(); | 1211 int unified_display_height = info.size_in_pixel().height(); |
| 1232 gfx::Point origin; | 1212 gfx::Point origin; |
| 1233 for (auto& info : *display_info_list) { | 1213 for (auto& info : *display_info_list) { |
| 1234 float display_scale = info.size_in_pixel().height() / | 1214 float display_scale = info.size_in_pixel().height() / |
| 1235 static_cast<float>(unified_display_height); | 1215 static_cast<float>(unified_display_height); |
| 1236 display::Display display = CreateMirroringDisplayFromDisplayInfoById( | 1216 Display display = CreateMirroringDisplayFromDisplayInfoById( |
| 1237 info.id(), origin, 1.0f / display_scale); | 1217 info.id(), origin, 1.0f / display_scale); |
| 1238 origin.Offset(display.size().width(), 0); | 1218 origin.Offset(display.size().width(), 0); |
| 1239 display.UpdateWorkAreaFromInsets(gfx::Insets()); | 1219 display.UpdateWorkAreaFromInsets(gfx::Insets()); |
| 1240 software_mirroring_display_list_.push_back(display); | 1220 software_mirroring_display_list_.push_back(display); |
| 1241 } | 1221 } |
| 1242 | 1222 |
| 1243 display_info_list->clear(); | 1223 display_info_list->clear(); |
| 1244 display_info_list->push_back(info); | 1224 display_info_list->push_back(info); |
| 1245 InsertAndUpdateDisplayInfo(info); | 1225 InsertAndUpdateDisplayInfo(info); |
| 1246 break; | 1226 break; |
| 1247 } | 1227 } |
| 1248 case EXTENDED: | 1228 case EXTENDED: |
| 1249 break; | 1229 break; |
| 1250 } | 1230 } |
| 1251 } | 1231 } |
| 1252 | 1232 |
| 1253 display::Display* DisplayManager::FindDisplayForId(int64_t id) { | 1233 Display* DisplayManager::FindDisplayForId(int64_t id) { |
| 1254 auto iter = std::find_if( | 1234 auto iter = |
| 1255 active_display_list_.begin(), active_display_list_.end(), | 1235 std::find_if(active_display_list_.begin(), active_display_list_.end(), |
| 1256 [id](const display::Display& display) { return display.id() == id; }); | 1236 [id](const Display& display) { return display.id() == id; }); |
| 1257 if (iter != active_display_list_.end()) | 1237 if (iter != active_display_list_.end()) |
| 1258 return &(*iter); | 1238 return &(*iter); |
| 1259 // TODO(oshima): This happens when windows in unified desktop have | 1239 // TODO(oshima): This happens when windows in unified desktop have |
| 1260 // been moved to a normal window. Fix this. | 1240 // been moved to a normal window. Fix this. |
| 1261 if (id != kUnifiedDisplayId) | 1241 if (id != kUnifiedDisplayId) |
| 1262 DLOG(WARNING) << "Could not find display:" << id; | 1242 DLOG(WARNING) << "Could not find display:" << id; |
| 1263 return nullptr; | 1243 return nullptr; |
| 1264 } | 1244 } |
| 1265 | 1245 |
| 1266 void DisplayManager::AddMirrorDisplayInfoIfAny( | 1246 void DisplayManager::AddMirrorDisplayInfoIfAny( |
| 1267 DisplayInfoList* display_info_list) { | 1247 DisplayInfoList* display_info_list) { |
| 1268 if (software_mirroring_enabled() && IsInMirrorMode()) { | 1248 if (software_mirroring_enabled() && IsInMirrorMode()) { |
| 1269 display_info_list->push_back(GetDisplayInfo(mirroring_display_id_)); | 1249 display_info_list->push_back(GetDisplayInfo(mirroring_display_id_)); |
| 1270 software_mirroring_display_list_.clear(); | 1250 software_mirroring_display_list_.clear(); |
| 1271 } | 1251 } |
| 1272 } | 1252 } |
| 1273 | 1253 |
| 1274 void DisplayManager::InsertAndUpdateDisplayInfo( | 1254 void DisplayManager::InsertAndUpdateDisplayInfo( |
| 1275 const display::ManagedDisplayInfo& new_info) { | 1255 const ManagedDisplayInfo& new_info) { |
| 1276 std::map<int64_t, display::ManagedDisplayInfo>::iterator info = | 1256 std::map<int64_t, ManagedDisplayInfo>::iterator info = |
| 1277 display_info_.find(new_info.id()); | 1257 display_info_.find(new_info.id()); |
| 1278 if (info != display_info_.end()) { | 1258 if (info != display_info_.end()) { |
| 1279 info->second.Copy(new_info); | 1259 info->second.Copy(new_info); |
| 1280 } else { | 1260 } else { |
| 1281 display_info_[new_info.id()] = new_info; | 1261 display_info_[new_info.id()] = new_info; |
| 1282 display_info_[new_info.id()].set_native(false); | 1262 display_info_[new_info.id()].set_native(false); |
| 1283 // FHD with 1.25 DSF behaves differently from other configuration. | 1263 // FHD with 1.25 DSF behaves differently from other configuration. |
| 1284 // It uses 1.25 DSF only when UI-Scale is set to 0.8. | 1264 // It uses 1.25 DSF only when UI-Scale is set to 0.8. |
| 1285 // For new users, use the UI-scale to 0.8 so that it will use DSF=1.25 | 1265 // For new users, use the UI-scale to 0.8 so that it will use DSF=1.25 |
| 1286 // internally. | 1266 // internally. |
| 1287 if (display::Display::IsInternalDisplayId(new_info.id()) && | 1267 if (Display::IsInternalDisplayId(new_info.id()) && |
| 1288 new_info.bounds_in_native().height() == 1080 && | 1268 new_info.bounds_in_native().height() == 1080 && |
| 1289 new_info.device_scale_factor() == 1.25f) { | 1269 new_info.device_scale_factor() == 1.25f) { |
| 1290 display_info_[new_info.id()].set_configured_ui_scale(0.8f); | 1270 display_info_[new_info.id()].set_configured_ui_scale(0.8f); |
| 1291 } | 1271 } |
| 1292 } | 1272 } |
| 1293 display_info_[new_info.id()].UpdateDisplaySize(); | 1273 display_info_[new_info.id()].UpdateDisplaySize(); |
| 1294 OnDisplayInfoUpdated(display_info_[new_info.id()]); | 1274 OnDisplayInfoUpdated(display_info_[new_info.id()]); |
| 1295 } | 1275 } |
| 1296 | 1276 |
| 1297 void DisplayManager::OnDisplayInfoUpdated( | 1277 void DisplayManager::OnDisplayInfoUpdated( |
| 1298 const display::ManagedDisplayInfo& display_info) { | 1278 const ManagedDisplayInfo& display_info) { |
| 1299 #if defined(OS_CHROMEOS) | 1279 #if defined(OS_CHROMEOS) |
| 1300 ui::ColorCalibrationProfile color_profile = display_info.color_profile(); | 1280 ui::ColorCalibrationProfile color_profile = display_info.color_profile(); |
| 1301 if (color_profile != ui::COLOR_PROFILE_STANDARD) { | 1281 if (color_profile != ui::COLOR_PROFILE_STANDARD) { |
| 1302 delegate_->display_configurator()->SetColorCalibrationProfile( | 1282 delegate_->display_configurator()->SetColorCalibrationProfile( |
| 1303 display_info.id(), color_profile); | 1283 display_info.id(), color_profile); |
| 1304 } | 1284 } |
| 1305 #endif | 1285 #endif |
| 1306 } | 1286 } |
| 1307 | 1287 |
| 1308 display::Display DisplayManager::CreateDisplayFromDisplayInfoById(int64_t id) { | 1288 Display DisplayManager::CreateDisplayFromDisplayInfoById(int64_t id) { |
| 1309 DCHECK(display_info_.find(id) != display_info_.end()) << "id=" << id; | 1289 DCHECK(display_info_.find(id) != display_info_.end()) << "id=" << id; |
| 1310 const display::ManagedDisplayInfo& display_info = display_info_[id]; | 1290 const ManagedDisplayInfo& display_info = display_info_[id]; |
| 1311 | 1291 |
| 1312 display::Display new_display(display_info.id()); | 1292 Display new_display(display_info.id()); |
| 1313 gfx::Rect bounds_in_native(display_info.size_in_pixel()); | 1293 gfx::Rect bounds_in_native(display_info.size_in_pixel()); |
| 1314 float device_scale_factor = display_info.GetEffectiveDeviceScaleFactor(); | 1294 float device_scale_factor = display_info.GetEffectiveDeviceScaleFactor(); |
| 1315 | 1295 |
| 1316 // Simply set the origin to (0,0). The primary display's origin is | 1296 // Simply set the origin to (0,0). The primary display's origin is |
| 1317 // always (0,0) and the bounds of non-primary display(s) will be updated | 1297 // always (0,0) and the bounds of non-primary display(s) will be updated |
| 1318 // in |UpdateNonPrimaryDisplayBoundsForLayout| called in |UpdateDisplay|. | 1298 // in |UpdateNonPrimaryDisplayBoundsForLayout| called in |UpdateDisplay|. |
| 1319 new_display.SetScaleAndBounds(device_scale_factor, | 1299 new_display.SetScaleAndBounds(device_scale_factor, |
| 1320 gfx::Rect(bounds_in_native.size())); | 1300 gfx::Rect(bounds_in_native.size())); |
| 1321 new_display.set_rotation(display_info.GetActiveRotation()); | 1301 new_display.set_rotation(display_info.GetActiveRotation()); |
| 1322 new_display.set_touch_support(display_info.touch_support()); | 1302 new_display.set_touch_support(display_info.touch_support()); |
| 1323 new_display.set_maximum_cursor_size(display_info.maximum_cursor_size()); | 1303 new_display.set_maximum_cursor_size(display_info.maximum_cursor_size()); |
| 1324 return new_display; | 1304 return new_display; |
| 1325 } | 1305 } |
| 1326 | 1306 |
| 1327 display::Display DisplayManager::CreateMirroringDisplayFromDisplayInfoById( | 1307 Display DisplayManager::CreateMirroringDisplayFromDisplayInfoById( |
| 1328 int64_t id, | 1308 int64_t id, |
| 1329 const gfx::Point& origin, | 1309 const gfx::Point& origin, |
| 1330 float scale) { | 1310 float scale) { |
| 1331 DCHECK(display_info_.find(id) != display_info_.end()) << "id=" << id; | 1311 DCHECK(display_info_.find(id) != display_info_.end()) << "id=" << id; |
| 1332 const display::ManagedDisplayInfo& display_info = display_info_[id]; | 1312 const ManagedDisplayInfo& display_info = display_info_[id]; |
| 1333 | 1313 |
| 1334 display::Display new_display(display_info.id()); | 1314 Display new_display(display_info.id()); |
| 1335 new_display.SetScaleAndBounds( | 1315 new_display.SetScaleAndBounds( |
| 1336 1.0f, gfx::Rect(origin, gfx::ScaleToFlooredSize( | 1316 1.0f, gfx::Rect(origin, gfx::ScaleToFlooredSize( |
| 1337 display_info.size_in_pixel(), scale))); | 1317 display_info.size_in_pixel(), scale))); |
| 1338 new_display.set_touch_support(display_info.touch_support()); | 1318 new_display.set_touch_support(display_info.touch_support()); |
| 1339 new_display.set_maximum_cursor_size(display_info.maximum_cursor_size()); | 1319 new_display.set_maximum_cursor_size(display_info.maximum_cursor_size()); |
| 1340 return new_display; | 1320 return new_display; |
| 1341 } | 1321 } |
| 1342 | 1322 |
| 1343 void DisplayManager::UpdateNonPrimaryDisplayBoundsForLayout( | 1323 void DisplayManager::UpdateNonPrimaryDisplayBoundsForLayout( |
| 1344 display::Displays* display_list, | 1324 Displays* display_list, |
| 1345 std::vector<size_t>* updated_indices) { | 1325 std::vector<size_t>* updated_indices) { |
| 1346 if (display_list->size() == 1u) | 1326 if (display_list->size() == 1u) |
| 1347 return; | 1327 return; |
| 1348 | 1328 |
| 1349 const display::DisplayLayout& layout = | 1329 const DisplayLayout& layout = layout_store_->GetRegisteredDisplayLayout( |
| 1350 layout_store_->GetRegisteredDisplayLayout( | 1330 CreateDisplayIdList(*display_list)); |
| 1351 display::CreateDisplayIdList(*display_list)); | |
| 1352 | 1331 |
| 1353 // Ignore if a user has a old format (should be extremely rare) | 1332 // Ignore if a user has a old format (should be extremely rare) |
| 1354 // and this will be replaced with DCHECK. | 1333 // and this will be replaced with DCHECK. |
| 1355 if (layout.primary_id == kInvalidDisplayId) | 1334 if (layout.primary_id == kInvalidDisplayId) |
| 1356 return; | 1335 return; |
| 1357 | 1336 |
| 1358 // display_list does not have translation set, so ApplyDisplayLayout cannot | 1337 // display_list does not have translation set, so ApplyDisplayLayout cannot |
| 1359 // provide accurate change information. We'll find the changes after the call. | 1338 // provide accurate change information. We'll find the changes after the call. |
| 1360 ApplyDisplayLayout(layout, display_list, nullptr); | 1339 ApplyDisplayLayout(layout, display_list, nullptr); |
| 1361 size_t num_displays = display_list->size(); | 1340 size_t num_displays = display_list->size(); |
| 1362 for (size_t index = 0; index < num_displays; ++index) { | 1341 for (size_t index = 0; index < num_displays; ++index) { |
| 1363 const display::Display& display = (*display_list)[index]; | 1342 const Display& display = (*display_list)[index]; |
| 1364 int64_t id = display.id(); | 1343 int64_t id = display.id(); |
| 1365 const display::Display* active_display = FindDisplayForId(id); | 1344 const Display* active_display = FindDisplayForId(id); |
| 1366 if (!active_display || (active_display->bounds() != display.bounds())) | 1345 if (!active_display || (active_display->bounds() != display.bounds())) |
| 1367 updated_indices->push_back(index); | 1346 updated_indices->push_back(index); |
| 1368 } | 1347 } |
| 1369 } | 1348 } |
| 1370 | 1349 |
| 1371 void DisplayManager::CreateMirrorWindowIfAny() { | 1350 void DisplayManager::CreateMirrorWindowIfAny() { |
| 1372 if (software_mirroring_display_list_.empty() || !delegate_) | 1351 if (software_mirroring_display_list_.empty() || !delegate_) |
| 1373 return; | 1352 return; |
| 1374 DisplayInfoList list; | 1353 DisplayInfoList list; |
| 1375 for (auto& display : software_mirroring_display_list_) | 1354 for (auto& display : software_mirroring_display_list_) |
| 1376 list.push_back(GetDisplayInfo(display.id())); | 1355 list.push_back(GetDisplayInfo(display.id())); |
| 1377 delegate_->CreateOrUpdateMirroringDisplay(list); | 1356 delegate_->CreateOrUpdateMirroringDisplay(list); |
| 1378 } | 1357 } |
| 1379 | 1358 |
| 1380 void DisplayManager::ApplyDisplayLayout(const display::DisplayLayout& layout, | 1359 void DisplayManager::ApplyDisplayLayout(const DisplayLayout& layout, |
| 1381 display::Displays* display_list, | 1360 Displays* display_list, |
| 1382 std::vector<int64_t>* updated_ids) { | 1361 std::vector<int64_t>* updated_ids) { |
| 1383 layout.ApplyToDisplayList(display_list, updated_ids, | 1362 layout.ApplyToDisplayList(display_list, updated_ids, |
| 1384 kMinimumOverlapForInvalidOffset); | 1363 kMinimumOverlapForInvalidOffset); |
| 1385 } | 1364 } |
| 1386 | 1365 |
| 1387 void DisplayManager::RunPendingTasksForTest() { | 1366 void DisplayManager::RunPendingTasksForTest() { |
| 1388 if (!software_mirroring_display_list_.empty()) | 1367 if (!software_mirroring_display_list_.empty()) |
| 1389 base::RunLoop().RunUntilIdle(); | 1368 base::RunLoop().RunUntilIdle(); |
| 1390 } | 1369 } |
| 1391 | 1370 |
| 1392 void DisplayManager::NotifyMetricsChanged(const display::Display& display, | 1371 void DisplayManager::NotifyMetricsChanged(const Display& display, |
| 1393 uint32_t metrics) { | 1372 uint32_t metrics) { |
| 1394 for (auto& observer : observers_) | 1373 for (auto& observer : observers_) |
| 1395 observer.OnDisplayMetricsChanged(display, metrics); | 1374 observer.OnDisplayMetricsChanged(display, metrics); |
| 1396 } | 1375 } |
| 1397 | 1376 |
| 1398 void DisplayManager::NotifyDisplayAdded(const display::Display& display) { | 1377 void DisplayManager::NotifyDisplayAdded(const Display& display) { |
| 1399 for (auto& observer : observers_) | 1378 for (auto& observer : observers_) |
| 1400 observer.OnDisplayAdded(display); | 1379 observer.OnDisplayAdded(display); |
| 1401 } | 1380 } |
| 1402 | 1381 |
| 1403 void DisplayManager::NotifyDisplayRemoved(const display::Display& display) { | 1382 void DisplayManager::NotifyDisplayRemoved(const Display& display) { |
| 1404 for (auto& observer : observers_) | 1383 for (auto& observer : observers_) |
| 1405 observer.OnDisplayRemoved(display); | 1384 observer.OnDisplayRemoved(display); |
| 1406 } | 1385 } |
| 1407 | 1386 |
| 1408 void DisplayManager::AddObserver(display::DisplayObserver* observer) { | 1387 void DisplayManager::AddObserver(DisplayObserver* observer) { |
| 1409 observers_.AddObserver(observer); | 1388 observers_.AddObserver(observer); |
| 1410 } | 1389 } |
| 1411 | 1390 |
| 1412 void DisplayManager::RemoveObserver(display::DisplayObserver* observer) { | 1391 void DisplayManager::RemoveObserver(DisplayObserver* observer) { |
| 1413 observers_.RemoveObserver(observer); | 1392 observers_.RemoveObserver(observer); |
| 1414 } | 1393 } |
| 1415 | 1394 |
| 1416 const display::Display& DisplayManager::GetSecondaryDisplay() const { | 1395 const Display& DisplayManager::GetSecondaryDisplay() const { |
| 1417 CHECK_LE(2U, GetNumDisplays()); | 1396 CHECK_LE(2U, GetNumDisplays()); |
| 1418 return GetDisplayAt(0).id() == | 1397 return GetDisplayAt(0).id() == Screen::GetScreen()->GetPrimaryDisplay().id() |
| 1419 display::Screen::GetScreen()->GetPrimaryDisplay().id() | |
| 1420 ? GetDisplayAt(1) | 1398 ? GetDisplayAt(1) |
| 1421 : GetDisplayAt(0); | 1399 : GetDisplayAt(0); |
| 1422 } | 1400 } |
| 1423 | 1401 |
| 1424 } // namespace display | 1402 } // namespace display |
| OLD | NEW |