| 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 "ash/display/display_manager.h" | 5 #include "ash/display/display_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 #include "base/memory/ptr_util.h" | 26 #include "base/memory/ptr_util.h" |
| 27 #include "base/metrics/histogram.h" | 27 #include "base/metrics/histogram.h" |
| 28 #include "base/run_loop.h" | 28 #include "base/run_loop.h" |
| 29 #include "base/strings/string_number_conversions.h" | 29 #include "base/strings/string_number_conversions.h" |
| 30 #include "base/strings/string_split.h" | 30 #include "base/strings/string_split.h" |
| 31 #include "base/strings/stringprintf.h" | 31 #include "base/strings/stringprintf.h" |
| 32 #include "base/strings/utf_string_conversions.h" | 32 #include "base/strings/utf_string_conversions.h" |
| 33 #include "base/thread_task_runner_handle.h" | 33 #include "base/thread_task_runner_handle.h" |
| 34 #include "grit/ash_strings.h" | 34 #include "grit/ash_strings.h" |
| 35 #include "ui/base/l10n/l10n_util.h" | 35 #include "ui/base/l10n/l10n_util.h" |
| 36 #include "ui/gfx/display.h" | 36 #include "ui/display/display.h" |
| 37 #include "ui/gfx/display_observer.h" | 37 #include "ui/display/display_observer.h" |
| 38 #include "ui/display/screen.h" |
| 38 #include "ui/gfx/font_render_params.h" | 39 #include "ui/gfx/font_render_params.h" |
| 39 #include "ui/gfx/geometry/rect.h" | 40 #include "ui/gfx/geometry/rect.h" |
| 40 #include "ui/gfx/geometry/size_conversions.h" | 41 #include "ui/gfx/geometry/size_conversions.h" |
| 41 #include "ui/gfx/screen.h" | |
| 42 | 42 |
| 43 #if defined(USE_X11) | 43 #if defined(USE_X11) |
| 44 #include "ui/base/x/x11_util.h" | 44 #include "ui/base/x/x11_util.h" |
| 45 #endif | 45 #endif |
| 46 | 46 |
| 47 #if defined(OS_CHROMEOS) | 47 #if defined(OS_CHROMEOS) |
| 48 #include "base/sys_info.h" | 48 #include "base/sys_info.h" |
| 49 #endif | 49 #endif |
| 50 | 50 |
| 51 #if defined(OS_WIN) | 51 #if defined(OS_WIN) |
| 52 #include "base/win/windows_version.h" | 52 #include "base/win/windows_version.h" |
| 53 #endif | 53 #endif |
| 54 | 54 |
| 55 namespace ash { | 55 namespace ash { |
| 56 typedef std::vector<DisplayInfo> DisplayInfoList; | 56 typedef std::vector<DisplayInfo> DisplayInfoList; |
| 57 | 57 |
| 58 namespace { | 58 namespace { |
| 59 | 59 |
| 60 // We need to keep this in order for unittests to tell if | 60 // We need to keep this in order for unittests to tell if |
| 61 // the object in gfx::Screen::GetScreenByType is for shutdown. | 61 // the object in display::Screen::GetScreenByType is for shutdown. |
| 62 gfx::Screen* screen_for_shutdown = nullptr; | 62 display::Screen* screen_for_shutdown = nullptr; |
| 63 | 63 |
| 64 // The number of pixels to overlap between the primary and secondary displays, | 64 // The number of pixels to overlap between the primary and secondary displays, |
| 65 // in case that the offset value is too large. | 65 // in case that the offset value is too large. |
| 66 const int kMinimumOverlapForInvalidOffset = 100; | 66 const int kMinimumOverlapForInvalidOffset = 100; |
| 67 | 67 |
| 68 struct DisplaySortFunctor { | 68 struct DisplaySortFunctor { |
| 69 bool operator()(const gfx::Display& a, const gfx::Display& b) { | 69 bool operator()(const display::Display& a, const display::Display& b) { |
| 70 return CompareDisplayIds(a.id(), b.id()); | 70 return CompareDisplayIds(a.id(), b.id()); |
| 71 } | 71 } |
| 72 }; | 72 }; |
| 73 | 73 |
| 74 struct DisplayInfoSortFunctor { | 74 struct DisplayInfoSortFunctor { |
| 75 bool operator()(const DisplayInfo& a, const DisplayInfo& b) { | 75 bool operator()(const DisplayInfo& a, const DisplayInfo& b) { |
| 76 return CompareDisplayIds(a.id(), b.id()); | 76 return CompareDisplayIds(a.id(), b.id()); |
| 77 } | 77 } |
| 78 }; | 78 }; |
| 79 | 79 |
| 80 gfx::Display& GetInvalidDisplay() { | 80 display::Display& GetInvalidDisplay() { |
| 81 static gfx::Display* invalid_display = new gfx::Display(); | 81 static display::Display* invalid_display = new display::Display(); |
| 82 return *invalid_display; | 82 return *invalid_display; |
| 83 } | 83 } |
| 84 | 84 |
| 85 std::vector<DisplayMode>::const_iterator FindDisplayMode( | 85 std::vector<DisplayMode>::const_iterator FindDisplayMode( |
| 86 const DisplayInfo& info, | 86 const DisplayInfo& info, |
| 87 const DisplayMode& target_mode) { | 87 const DisplayMode& target_mode) { |
| 88 const std::vector<DisplayMode>& modes = info.display_modes(); | 88 const std::vector<DisplayMode>& modes = info.display_modes(); |
| 89 return std::find_if(modes.begin(), modes.end(), | 89 return std::find_if(modes.begin(), modes.end(), |
| 90 [target_mode](const DisplayMode& mode) { | 90 [target_mode](const DisplayMode& mode) { |
| 91 return target_mode.IsEquivalent(mode); | 91 return target_mode.IsEquivalent(mode); |
| 92 }); | 92 }); |
| 93 } | 93 } |
| 94 | 94 |
| 95 void SetInternalDisplayModeList(DisplayInfo* info) { | 95 void SetInternalDisplayModeList(DisplayInfo* info) { |
| 96 DisplayMode native_mode; | 96 DisplayMode native_mode; |
| 97 native_mode.size = info->bounds_in_native().size(); | 97 native_mode.size = info->bounds_in_native().size(); |
| 98 native_mode.device_scale_factor = info->device_scale_factor(); | 98 native_mode.device_scale_factor = info->device_scale_factor(); |
| 99 native_mode.ui_scale = 1.0f; | 99 native_mode.ui_scale = 1.0f; |
| 100 info->SetDisplayModes(CreateInternalDisplayModeList(native_mode)); | 100 info->SetDisplayModes(CreateInternalDisplayModeList(native_mode)); |
| 101 } | 101 } |
| 102 | 102 |
| 103 void MaybeInitInternalDisplay(DisplayInfo* info) { | 103 void MaybeInitInternalDisplay(DisplayInfo* info) { |
| 104 int64_t id = info->id(); | 104 int64_t id = info->id(); |
| 105 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 105 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 106 if (command_line->HasSwitch(switches::kAshUseFirstDisplayAsInternal)) { | 106 if (command_line->HasSwitch(switches::kAshUseFirstDisplayAsInternal)) { |
| 107 gfx::Display::SetInternalDisplayId(id); | 107 display::Display::SetInternalDisplayId(id); |
| 108 SetInternalDisplayModeList(info); | 108 SetInternalDisplayModeList(info); |
| 109 } | 109 } |
| 110 } | 110 } |
| 111 | 111 |
| 112 gfx::Size GetMaxNativeSize(const DisplayInfo& info) { | 112 gfx::Size GetMaxNativeSize(const DisplayInfo& info) { |
| 113 gfx::Size size; | 113 gfx::Size size; |
| 114 for (auto& mode : info.display_modes()) { | 114 for (auto& mode : info.display_modes()) { |
| 115 if (mode.size.GetArea() > size.GetArea()) | 115 if (mode.size.GetArea() > size.GetArea()) |
| 116 size = mode.size; | 116 size = mode.size; |
| 117 } | 117 } |
| 118 return size; | 118 return size; |
| 119 } | 119 } |
| 120 | 120 |
| 121 } // namespace | 121 } // namespace |
| 122 | 122 |
| 123 using std::string; | 123 using std::string; |
| 124 using std::vector; | 124 using std::vector; |
| 125 | 125 |
| 126 // static | 126 // static |
| 127 int64_t DisplayManager::kUnifiedDisplayId = -10; | 127 int64_t DisplayManager::kUnifiedDisplayId = -10; |
| 128 | 128 |
| 129 DisplayManager::DisplayManager() | 129 DisplayManager::DisplayManager() |
| 130 : delegate_(nullptr), | 130 : delegate_(nullptr), |
| 131 screen_(new ScreenAsh), | 131 screen_(new ScreenAsh), |
| 132 layout_store_(new DisplayLayoutStore), | 132 layout_store_(new DisplayLayoutStore), |
| 133 first_display_id_(gfx::Display::kInvalidDisplayID), | 133 first_display_id_(display::Display::kInvalidDisplayID), |
| 134 num_connected_displays_(0), | 134 num_connected_displays_(0), |
| 135 force_bounds_changed_(false), | 135 force_bounds_changed_(false), |
| 136 change_display_upon_host_resize_(false), | 136 change_display_upon_host_resize_(false), |
| 137 multi_display_mode_(EXTENDED), | 137 multi_display_mode_(EXTENDED), |
| 138 current_default_multi_display_mode_(EXTENDED), | 138 current_default_multi_display_mode_(EXTENDED), |
| 139 mirroring_display_id_(gfx::Display::kInvalidDisplayID), | 139 mirroring_display_id_(display::Display::kInvalidDisplayID), |
| 140 registered_internal_display_rotation_lock_(false), | 140 registered_internal_display_rotation_lock_(false), |
| 141 registered_internal_display_rotation_(gfx::Display::ROTATE_0), | 141 registered_internal_display_rotation_(display::Display::ROTATE_0), |
| 142 unified_desktop_enabled_(false), | 142 unified_desktop_enabled_(false), |
| 143 weak_ptr_factory_(this) { | 143 weak_ptr_factory_(this) { |
| 144 #if defined(OS_CHROMEOS) | 144 #if defined(OS_CHROMEOS) |
| 145 change_display_upon_host_resize_ = !base::SysInfo::IsRunningOnChromeOS(); | 145 change_display_upon_host_resize_ = !base::SysInfo::IsRunningOnChromeOS(); |
| 146 unified_desktop_enabled_ = base::CommandLine::ForCurrentProcess()->HasSwitch( | 146 unified_desktop_enabled_ = base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 147 switches::kAshEnableUnifiedDesktop); | 147 switches::kAshEnableUnifiedDesktop); |
| 148 #endif | 148 #endif |
| 149 gfx::Screen* current = gfx::Screen::GetScreen(); | 149 display::Screen* current = display::Screen::GetScreen(); |
| 150 // If there is no native, or the native was for shutdown, | 150 // If there is no native, or the native was for shutdown, |
| 151 // use ash's screen. | 151 // use ash's screen. |
| 152 if (!current || current == screen_for_shutdown) | 152 if (!current || current == screen_for_shutdown) |
| 153 gfx::Screen::SetScreenInstance(screen_.get()); | 153 display::Screen::SetScreenInstance(screen_.get()); |
| 154 } | 154 } |
| 155 | 155 |
| 156 DisplayManager::~DisplayManager() { | 156 DisplayManager::~DisplayManager() { |
| 157 #if defined(OS_CHROMEOS) | 157 #if defined(OS_CHROMEOS) |
| 158 // Reset the font params. | 158 // Reset the font params. |
| 159 gfx::SetFontRenderParamsDeviceScaleFactor(1.0f); | 159 gfx::SetFontRenderParamsDeviceScaleFactor(1.0f); |
| 160 #endif | 160 #endif |
| 161 } | 161 } |
| 162 | 162 |
| 163 bool DisplayManager::InitFromCommandLine() { | 163 bool DisplayManager::InitFromCommandLine() { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 188 MaybeInitInternalDisplay(&info_list[0]); | 188 MaybeInitInternalDisplay(&info_list[0]); |
| 189 OnNativeDisplaysChanged(info_list); | 189 OnNativeDisplaysChanged(info_list); |
| 190 } | 190 } |
| 191 | 191 |
| 192 void DisplayManager::RefreshFontParams() { | 192 void DisplayManager::RefreshFontParams() { |
| 193 #if defined(OS_CHROMEOS) | 193 #if defined(OS_CHROMEOS) |
| 194 // Use the largest device scale factor among currently active displays. Non | 194 // Use the largest device scale factor among currently active displays. Non |
| 195 // internal display may have bigger scale factor in case the external display | 195 // internal display may have bigger scale factor in case the external display |
| 196 // is an 4K display. | 196 // is an 4K display. |
| 197 float largest_device_scale_factor = 1.0f; | 197 float largest_device_scale_factor = 1.0f; |
| 198 for (const gfx::Display& display : active_display_list_) { | 198 for (const display::Display& display : active_display_list_) { |
| 199 const ash::DisplayInfo& info = display_info_[display.id()]; | 199 const ash::DisplayInfo& info = display_info_[display.id()]; |
| 200 largest_device_scale_factor = std::max( | 200 largest_device_scale_factor = std::max( |
| 201 largest_device_scale_factor, info.GetEffectiveDeviceScaleFactor()); | 201 largest_device_scale_factor, info.GetEffectiveDeviceScaleFactor()); |
| 202 } | 202 } |
| 203 gfx::SetFontRenderParamsDeviceScaleFactor(largest_device_scale_factor); | 203 gfx::SetFontRenderParamsDeviceScaleFactor(largest_device_scale_factor); |
| 204 #endif // OS_CHROMEOS | 204 #endif // OS_CHROMEOS |
| 205 } | 205 } |
| 206 | 206 |
| 207 const display::DisplayLayout& DisplayManager::GetCurrentDisplayLayout() const { | 207 const display::DisplayLayout& DisplayManager::GetCurrentDisplayLayout() const { |
| 208 DCHECK_LE(2U, num_connected_displays()); | 208 DCHECK_LE(2U, num_connected_displays()); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 if (delegate_) | 253 if (delegate_) |
| 254 delegate_->PreDisplayConfigurationChange(false); | 254 delegate_->PreDisplayConfigurationChange(false); |
| 255 | 255 |
| 256 // TODO(oshima): Call UpdateDisplays instead. | 256 // TODO(oshima): Call UpdateDisplays instead. |
| 257 std::vector<int64_t> updated_ids; | 257 std::vector<int64_t> updated_ids; |
| 258 ApplyDisplayLayout(GetCurrentDisplayLayout(), &active_display_list_, | 258 ApplyDisplayLayout(GetCurrentDisplayLayout(), &active_display_list_, |
| 259 &updated_ids); | 259 &updated_ids); |
| 260 for (int64_t id : updated_ids) { | 260 for (int64_t id : updated_ids) { |
| 261 screen_->NotifyMetricsChanged( | 261 screen_->NotifyMetricsChanged( |
| 262 GetDisplayForId(id), | 262 GetDisplayForId(id), |
| 263 gfx::DisplayObserver::DISPLAY_METRIC_BOUNDS | | 263 display::DisplayObserver::DISPLAY_METRIC_BOUNDS | |
| 264 gfx::DisplayObserver::DISPLAY_METRIC_WORK_AREA); | 264 display::DisplayObserver::DISPLAY_METRIC_WORK_AREA); |
| 265 } | 265 } |
| 266 | 266 |
| 267 if (delegate_) | 267 if (delegate_) |
| 268 delegate_->PostDisplayConfigurationChange(); | 268 delegate_->PostDisplayConfigurationChange(); |
| 269 } | 269 } |
| 270 | 270 |
| 271 const gfx::Display& DisplayManager::GetDisplayForId(int64_t id) const { | 271 const display::Display& DisplayManager::GetDisplayForId(int64_t id) const { |
| 272 gfx::Display* display = | 272 display::Display* display = |
| 273 const_cast<DisplayManager*>(this)->FindDisplayForId(id); | 273 const_cast<DisplayManager*>(this)->FindDisplayForId(id); |
| 274 return display ? *display : GetInvalidDisplay(); | 274 return display ? *display : GetInvalidDisplay(); |
| 275 } | 275 } |
| 276 | 276 |
| 277 const gfx::Display& DisplayManager::FindDisplayContainingPoint( | 277 const display::Display& DisplayManager::FindDisplayContainingPoint( |
| 278 const gfx::Point& point_in_screen) const { | 278 const gfx::Point& point_in_screen) const { |
| 279 int index = | 279 int index = |
| 280 FindDisplayIndexContainingPoint(active_display_list_, point_in_screen); | 280 FindDisplayIndexContainingPoint(active_display_list_, point_in_screen); |
| 281 return index < 0 ? GetInvalidDisplay() : active_display_list_[index]; | 281 return index < 0 ? GetInvalidDisplay() : active_display_list_[index]; |
| 282 } | 282 } |
| 283 | 283 |
| 284 bool DisplayManager::UpdateWorkAreaOfDisplay(int64_t display_id, | 284 bool DisplayManager::UpdateWorkAreaOfDisplay(int64_t display_id, |
| 285 const gfx::Insets& insets) { | 285 const gfx::Insets& insets) { |
| 286 gfx::Display* display = FindDisplayForId(display_id); | 286 display::Display* display = FindDisplayForId(display_id); |
| 287 DCHECK(display); | 287 DCHECK(display); |
| 288 gfx::Rect old_work_area = display->work_area(); | 288 gfx::Rect old_work_area = display->work_area(); |
| 289 display->UpdateWorkAreaFromInsets(insets); | 289 display->UpdateWorkAreaFromInsets(insets); |
| 290 return old_work_area != display->work_area(); | 290 return old_work_area != display->work_area(); |
| 291 } | 291 } |
| 292 | 292 |
| 293 void DisplayManager::SetOverscanInsets(int64_t display_id, | 293 void DisplayManager::SetOverscanInsets(int64_t display_id, |
| 294 const gfx::Insets& insets_in_dip) { | 294 const gfx::Insets& insets_in_dip) { |
| 295 bool update = false; | 295 bool update = false; |
| 296 DisplayInfoList display_info_list; | 296 DisplayInfoList display_info_list; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 308 display_info_list.push_back(info); | 308 display_info_list.push_back(info); |
| 309 } | 309 } |
| 310 if (update) { | 310 if (update) { |
| 311 AddMirrorDisplayInfoIfAny(&display_info_list); | 311 AddMirrorDisplayInfoIfAny(&display_info_list); |
| 312 UpdateDisplaysWith(display_info_list); | 312 UpdateDisplaysWith(display_info_list); |
| 313 } else { | 313 } else { |
| 314 display_info_[display_id].SetOverscanInsets(insets_in_dip); | 314 display_info_[display_id].SetOverscanInsets(insets_in_dip); |
| 315 } | 315 } |
| 316 } | 316 } |
| 317 | 317 |
| 318 void DisplayManager::SetDisplayRotation(int64_t display_id, | 318 void DisplayManager::SetDisplayRotation( |
| 319 gfx::Display::Rotation rotation, | 319 int64_t display_id, |
| 320 gfx::Display::RotationSource source) { | 320 display::Display::Rotation rotation, |
| 321 display::Display::RotationSource source) { |
| 321 if (IsInUnifiedMode()) | 322 if (IsInUnifiedMode()) |
| 322 return; | 323 return; |
| 323 | 324 |
| 324 DisplayInfoList display_info_list; | 325 DisplayInfoList display_info_list; |
| 325 bool is_active = false; | 326 bool is_active = false; |
| 326 for (const auto& display : active_display_list_) { | 327 for (const auto& display : active_display_list_) { |
| 327 DisplayInfo info = GetDisplayInfo(display.id()); | 328 DisplayInfo info = GetDisplayInfo(display.id()); |
| 328 if (info.id() == display_id) { | 329 if (info.id() == display_id) { |
| 329 if (info.GetRotation(source) == rotation && | 330 if (info.GetRotation(source) == rotation && |
| 330 info.GetActiveRotation() == rotation) { | 331 info.GetActiveRotation() == rotation) { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 #if defined(OS_CHROMEOS) | 390 #if defined(OS_CHROMEOS) |
| 390 } else if (resolution_changed && base::SysInfo::IsRunningOnChromeOS()) { | 391 } else if (resolution_changed && base::SysInfo::IsRunningOnChromeOS()) { |
| 391 Shell::GetInstance()->display_configurator()->OnConfigurationChanged(); | 392 Shell::GetInstance()->display_configurator()->OnConfigurationChanged(); |
| 392 #endif | 393 #endif |
| 393 } | 394 } |
| 394 return resolution_changed || display_property_changed; | 395 return resolution_changed || display_property_changed; |
| 395 } | 396 } |
| 396 | 397 |
| 397 void DisplayManager::RegisterDisplayProperty( | 398 void DisplayManager::RegisterDisplayProperty( |
| 398 int64_t display_id, | 399 int64_t display_id, |
| 399 gfx::Display::Rotation rotation, | 400 display::Display::Rotation rotation, |
| 400 float ui_scale, | 401 float ui_scale, |
| 401 const gfx::Insets* overscan_insets, | 402 const gfx::Insets* overscan_insets, |
| 402 const gfx::Size& resolution_in_pixels, | 403 const gfx::Size& resolution_in_pixels, |
| 403 float device_scale_factor, | 404 float device_scale_factor, |
| 404 ui::ColorCalibrationProfile color_profile) { | 405 ui::ColorCalibrationProfile color_profile) { |
| 405 if (display_info_.find(display_id) == display_info_.end()) | 406 if (display_info_.find(display_id) == display_info_.end()) |
| 406 display_info_[display_id] = DisplayInfo(display_id, std::string(), false); | 407 display_info_[display_id] = DisplayInfo(display_id, std::string(), false); |
| 407 | 408 |
| 408 // Do not allow rotation in unified desktop mode. | 409 // Do not allow rotation in unified desktop mode. |
| 409 if (display_id == kUnifiedDisplayId) | 410 if (display_id == kUnifiedDisplayId) |
| 410 rotation = gfx::Display::ROTATE_0; | 411 rotation = display::Display::ROTATE_0; |
| 411 | 412 |
| 412 display_info_[display_id].SetRotation(rotation, | 413 display_info_[display_id].SetRotation(rotation, |
| 413 gfx::Display::ROTATION_SOURCE_USER); | 414 display::Display::ROTATION_SOURCE_USER); |
| 414 display_info_[display_id].SetRotation(rotation, | 415 display_info_[display_id].SetRotation( |
| 415 gfx::Display::ROTATION_SOURCE_ACTIVE); | 416 rotation, display::Display::ROTATION_SOURCE_ACTIVE); |
| 416 display_info_[display_id].SetColorProfile(color_profile); | 417 display_info_[display_id].SetColorProfile(color_profile); |
| 417 // Just in case the preference file was corrupted. | 418 // Just in case the preference file was corrupted. |
| 418 // TODO(mukai): register |display_modes_| here as well, so the lookup for the | 419 // TODO(mukai): register |display_modes_| here as well, so the lookup for the |
| 419 // default mode in GetActiveModeForDisplayId() gets much simpler. | 420 // default mode in GetActiveModeForDisplayId() gets much simpler. |
| 420 if (0.5f <= ui_scale && ui_scale <= 2.0f) | 421 if (0.5f <= ui_scale && ui_scale <= 2.0f) |
| 421 display_info_[display_id].set_configured_ui_scale(ui_scale); | 422 display_info_[display_id].set_configured_ui_scale(ui_scale); |
| 422 if (overscan_insets) | 423 if (overscan_insets) |
| 423 display_info_[display_id].SetOverscanInsets(*overscan_insets); | 424 display_info_[display_id].SetOverscanInsets(*overscan_insets); |
| 424 if (!resolution_in_pixels.IsEmpty()) { | 425 if (!resolution_in_pixels.IsEmpty()) { |
| 425 DCHECK(!gfx::Display::IsInternalDisplayId(display_id)); | 426 DCHECK(!display::Display::IsInternalDisplayId(display_id)); |
| 426 // Default refresh rate, until OnNativeDisplaysChanged() updates us with the | 427 // Default refresh rate, until OnNativeDisplaysChanged() updates us with the |
| 427 // actual display info, is 60 Hz. | 428 // actual display info, is 60 Hz. |
| 428 DisplayMode mode(resolution_in_pixels, 60.0f, false, false); | 429 DisplayMode mode(resolution_in_pixels, 60.0f, false, false); |
| 429 mode.device_scale_factor = device_scale_factor; | 430 mode.device_scale_factor = device_scale_factor; |
| 430 display_modes_[display_id] = mode; | 431 display_modes_[display_id] = mode; |
| 431 } | 432 } |
| 432 } | 433 } |
| 433 | 434 |
| 434 DisplayMode DisplayManager::GetActiveModeForDisplayId( | 435 DisplayMode DisplayManager::GetActiveModeForDisplayId( |
| 435 int64_t display_id) const { | 436 int64_t display_id) const { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 448 if (GetDisplayIdForUIScaling() == display_id) { | 449 if (GetDisplayIdForUIScaling() == display_id) { |
| 449 if (info.configured_ui_scale() == mode.ui_scale) | 450 if (info.configured_ui_scale() == mode.ui_scale) |
| 450 return mode; | 451 return mode; |
| 451 } else if (mode.native) { | 452 } else if (mode.native) { |
| 452 return mode; | 453 return mode; |
| 453 } | 454 } |
| 454 } | 455 } |
| 455 return selected_mode; | 456 return selected_mode; |
| 456 } | 457 } |
| 457 | 458 |
| 458 void DisplayManager::RegisterDisplayRotationProperties(bool rotation_lock, | 459 void DisplayManager::RegisterDisplayRotationProperties( |
| 459 gfx::Display::Rotation rotation) { | 460 bool rotation_lock, |
| 461 display::Display::Rotation rotation) { |
| 460 if (delegate_) | 462 if (delegate_) |
| 461 delegate_->PreDisplayConfigurationChange(false); | 463 delegate_->PreDisplayConfigurationChange(false); |
| 462 registered_internal_display_rotation_lock_ = rotation_lock; | 464 registered_internal_display_rotation_lock_ = rotation_lock; |
| 463 registered_internal_display_rotation_ = rotation; | 465 registered_internal_display_rotation_ = rotation; |
| 464 if (delegate_) | 466 if (delegate_) |
| 465 delegate_->PostDisplayConfigurationChange(); | 467 delegate_->PostDisplayConfigurationChange(); |
| 466 } | 468 } |
| 467 | 469 |
| 468 bool DisplayManager::GetSelectedModeForDisplayId(int64_t id, | 470 bool DisplayManager::GetSelectedModeForDisplayId(int64_t id, |
| 469 DisplayMode* mode_out) const { | 471 DisplayMode* mode_out) const { |
| 470 std::map<int64_t, DisplayMode>::const_iterator iter = display_modes_.find(id); | 472 std::map<int64_t, DisplayMode>::const_iterator iter = display_modes_.find(id); |
| 471 if (iter == display_modes_.end()) | 473 if (iter == display_modes_.end()) |
| 472 return false; | 474 return false; |
| 473 *mode_out = iter->second; | 475 *mode_out = iter->second; |
| 474 return true; | 476 return true; |
| 475 } | 477 } |
| 476 | 478 |
| 477 bool DisplayManager::IsDisplayUIScalingEnabled() const { | 479 bool DisplayManager::IsDisplayUIScalingEnabled() const { |
| 478 return GetDisplayIdForUIScaling() != gfx::Display::kInvalidDisplayID; | 480 return GetDisplayIdForUIScaling() != display::Display::kInvalidDisplayID; |
| 479 } | 481 } |
| 480 | 482 |
| 481 gfx::Insets DisplayManager::GetOverscanInsets(int64_t display_id) const { | 483 gfx::Insets DisplayManager::GetOverscanInsets(int64_t display_id) const { |
| 482 std::map<int64_t, DisplayInfo>::const_iterator it = | 484 std::map<int64_t, DisplayInfo>::const_iterator it = |
| 483 display_info_.find(display_id); | 485 display_info_.find(display_id); |
| 484 return (it != display_info_.end()) ? | 486 return (it != display_info_.end()) ? |
| 485 it->second.overscan_insets_in_dip() : gfx::Insets(); | 487 it->second.overscan_insets_in_dip() : gfx::Insets(); |
| 486 } | 488 } |
| 487 | 489 |
| 488 void DisplayManager::SetColorCalibrationProfile( | 490 void DisplayManager::SetColorCalibrationProfile( |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 540 if (updated_displays.size() == 1) { | 542 if (updated_displays.size() == 1) { |
| 541 VLOG(1) << "OnNativeDisplaysChanged(1):" << updated_displays[0].ToString(); | 543 VLOG(1) << "OnNativeDisplaysChanged(1):" << updated_displays[0].ToString(); |
| 542 } else { | 544 } else { |
| 543 VLOG(1) << "OnNativeDisplaysChanged(" << updated_displays.size() | 545 VLOG(1) << "OnNativeDisplaysChanged(" << updated_displays.size() |
| 544 << ") [0]=" << updated_displays[0].ToString() | 546 << ") [0]=" << updated_displays[0].ToString() |
| 545 << ", [1]=" << updated_displays[1].ToString(); | 547 << ", [1]=" << updated_displays[1].ToString(); |
| 546 } | 548 } |
| 547 | 549 |
| 548 bool internal_display_connected = false; | 550 bool internal_display_connected = false; |
| 549 num_connected_displays_ = updated_displays.size(); | 551 num_connected_displays_ = updated_displays.size(); |
| 550 mirroring_display_id_ = gfx::Display::kInvalidDisplayID; | 552 mirroring_display_id_ = display::Display::kInvalidDisplayID; |
| 551 software_mirroring_display_list_.clear(); | 553 software_mirroring_display_list_.clear(); |
| 552 DisplayInfoList new_display_info_list; | 554 DisplayInfoList new_display_info_list; |
| 553 for (DisplayInfoList::const_iterator iter = updated_displays.begin(); | 555 for (DisplayInfoList::const_iterator iter = updated_displays.begin(); |
| 554 iter != updated_displays.end(); | 556 iter != updated_displays.end(); |
| 555 ++iter) { | 557 ++iter) { |
| 556 if (!internal_display_connected) | 558 if (!internal_display_connected) |
| 557 internal_display_connected = | 559 internal_display_connected = |
| 558 gfx::Display::IsInternalDisplayId(iter->id()); | 560 display::Display::IsInternalDisplayId(iter->id()); |
| 559 // Mirrored monitors have the same origins. | 561 // Mirrored monitors have the same origins. |
| 560 gfx::Point origin = iter->bounds_in_native().origin(); | 562 gfx::Point origin = iter->bounds_in_native().origin(); |
| 561 if (origins.find(origin) != origins.end()) { | 563 if (origins.find(origin) != origins.end()) { |
| 562 InsertAndUpdateDisplayInfo(*iter); | 564 InsertAndUpdateDisplayInfo(*iter); |
| 563 mirroring_display_id_ = iter->id(); | 565 mirroring_display_id_ = iter->id(); |
| 564 } else { | 566 } else { |
| 565 origins.insert(origin); | 567 origins.insert(origin); |
| 566 new_display_info_list.push_back(*iter); | 568 new_display_info_list.push_back(*iter); |
| 567 } | 569 } |
| 568 | 570 |
| 569 DisplayMode new_mode; | 571 DisplayMode new_mode; |
| 570 new_mode.size = iter->bounds_in_native().size(); | 572 new_mode.size = iter->bounds_in_native().size(); |
| 571 new_mode.device_scale_factor = iter->device_scale_factor(); | 573 new_mode.device_scale_factor = iter->device_scale_factor(); |
| 572 new_mode.ui_scale = iter->configured_ui_scale(); | 574 new_mode.ui_scale = iter->configured_ui_scale(); |
| 573 const std::vector<DisplayMode>& display_modes = iter->display_modes(); | 575 const std::vector<DisplayMode>& display_modes = iter->display_modes(); |
| 574 // This is empty the displays are initialized from InitFromCommandLine. | 576 // This is empty the displays are initialized from InitFromCommandLine. |
| 575 if (!display_modes.size()) | 577 if (!display_modes.size()) |
| 576 continue; | 578 continue; |
| 577 auto display_modes_iter = FindDisplayMode(*iter, new_mode); | 579 auto display_modes_iter = FindDisplayMode(*iter, new_mode); |
| 578 // Update the actual resolution selected as the resolution request may fail. | 580 // Update the actual resolution selected as the resolution request may fail. |
| 579 if (display_modes_iter == display_modes.end()) | 581 if (display_modes_iter == display_modes.end()) |
| 580 display_modes_.erase(iter->id()); | 582 display_modes_.erase(iter->id()); |
| 581 else if (display_modes_.find(iter->id()) != display_modes_.end()) | 583 else if (display_modes_.find(iter->id()) != display_modes_.end()) |
| 582 display_modes_[iter->id()] = *display_modes_iter; | 584 display_modes_[iter->id()] = *display_modes_iter; |
| 583 } | 585 } |
| 584 if (gfx::Display::HasInternalDisplay() && !internal_display_connected) { | 586 if (display::Display::HasInternalDisplay() && !internal_display_connected) { |
| 585 if (display_info_.find(gfx::Display::InternalDisplayId()) == | 587 if (display_info_.find(display::Display::InternalDisplayId()) == |
| 586 display_info_.end()) { | 588 display_info_.end()) { |
| 587 // Create a dummy internal display if the chrome restarted | 589 // Create a dummy internal display if the chrome restarted |
| 588 // in docked mode. | 590 // in docked mode. |
| 589 DisplayInfo internal_display_info( | 591 DisplayInfo internal_display_info( |
| 590 gfx::Display::InternalDisplayId(), | 592 display::Display::InternalDisplayId(), |
| 591 l10n_util::GetStringUTF8(IDS_ASH_INTERNAL_DISPLAY_NAME), | 593 l10n_util::GetStringUTF8(IDS_ASH_INTERNAL_DISPLAY_NAME), |
| 592 false /*Internal display must not have overscan */); | 594 false /*Internal display must not have overscan */); |
| 593 internal_display_info.SetBounds(gfx::Rect(0, 0, 800, 600)); | 595 internal_display_info.SetBounds(gfx::Rect(0, 0, 800, 600)); |
| 594 display_info_[gfx::Display::InternalDisplayId()] = internal_display_info; | 596 display_info_[display::Display::InternalDisplayId()] = |
| 597 internal_display_info; |
| 595 } else { | 598 } else { |
| 596 // Internal display is no longer active. Reset its rotation to user | 599 // Internal display is no longer active. Reset its rotation to user |
| 597 // preference, so that it is restored when the internal display becomes | 600 // preference, so that it is restored when the internal display becomes |
| 598 // active again. | 601 // active again. |
| 599 gfx::Display::Rotation user_rotation = | 602 display::Display::Rotation user_rotation = |
| 600 display_info_[gfx::Display::InternalDisplayId()].GetRotation( | 603 display_info_[display::Display::InternalDisplayId()].GetRotation( |
| 601 gfx::Display::ROTATION_SOURCE_USER); | 604 display::Display::ROTATION_SOURCE_USER); |
| 602 display_info_[gfx::Display::InternalDisplayId()].SetRotation( | 605 display_info_[display::Display::InternalDisplayId()].SetRotation( |
| 603 user_rotation, gfx::Display::ROTATION_SOURCE_USER); | 606 user_rotation, display::Display::ROTATION_SOURCE_USER); |
| 604 } | 607 } |
| 605 } | 608 } |
| 606 | 609 |
| 607 #if defined(OS_CHROMEOS) | 610 #if defined(OS_CHROMEOS) |
| 608 if (!base::SysInfo::IsRunningOnChromeOS() && | 611 if (!base::SysInfo::IsRunningOnChromeOS() && |
| 609 new_display_info_list.size() > 1) { | 612 new_display_info_list.size() > 1) { |
| 610 display::DisplayIdList list = GenerateDisplayIdList( | 613 display::DisplayIdList list = GenerateDisplayIdList( |
| 611 new_display_info_list.begin(), new_display_info_list.end(), | 614 new_display_info_list.begin(), new_display_info_list.end(), |
| 612 [](const DisplayInfo& info) { return info.id(); }); | 615 [](const DisplayInfo& info) { return info.id(); }); |
| 613 | 616 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 682 added_display_indices.push_back(new_displays.size()); | 685 added_display_indices.push_back(new_displays.size()); |
| 683 InsertAndUpdateDisplayInfo(*new_info_iter); | 686 InsertAndUpdateDisplayInfo(*new_info_iter); |
| 684 new_displays.push_back( | 687 new_displays.push_back( |
| 685 CreateDisplayFromDisplayInfoById(new_info_iter->id())); | 688 CreateDisplayFromDisplayInfoById(new_info_iter->id())); |
| 686 ++new_info_iter; | 689 ++new_info_iter; |
| 687 } else if (new_info_iter == new_display_info_list.end()) { | 690 } else if (new_info_iter == new_display_info_list.end()) { |
| 688 // more displays in current list. | 691 // more displays in current list. |
| 689 removed_displays.push_back(*curr_iter); | 692 removed_displays.push_back(*curr_iter); |
| 690 ++curr_iter; | 693 ++curr_iter; |
| 691 } else if (curr_iter->id() == new_info_iter->id()) { | 694 } else if (curr_iter->id() == new_info_iter->id()) { |
| 692 const gfx::Display& current_display = *curr_iter; | 695 const display::Display& current_display = *curr_iter; |
| 693 // Copy the info because |InsertAndUpdateDisplayInfo| updates the | 696 // Copy the info because |InsertAndUpdateDisplayInfo| updates the |
| 694 // instance. | 697 // instance. |
| 695 const DisplayInfo current_display_info = | 698 const DisplayInfo current_display_info = |
| 696 GetDisplayInfo(current_display.id()); | 699 GetDisplayInfo(current_display.id()); |
| 697 InsertAndUpdateDisplayInfo(*new_info_iter); | 700 InsertAndUpdateDisplayInfo(*new_info_iter); |
| 698 gfx::Display new_display = | 701 display::Display new_display = |
| 699 CreateDisplayFromDisplayInfoById(new_info_iter->id()); | 702 CreateDisplayFromDisplayInfoById(new_info_iter->id()); |
| 700 const DisplayInfo& new_display_info = GetDisplayInfo(new_display.id()); | 703 const DisplayInfo& new_display_info = GetDisplayInfo(new_display.id()); |
| 701 | 704 |
| 702 uint32_t metrics = gfx::DisplayObserver::DISPLAY_METRIC_NONE; | 705 uint32_t metrics = display::DisplayObserver::DISPLAY_METRIC_NONE; |
| 703 | 706 |
| 704 // At that point the new Display objects we have are not entirely updated, | 707 // At that point the new Display objects we have are not entirely updated, |
| 705 // they are missing the translation related to the Display disposition in | 708 // they are missing the translation related to the Display disposition in |
| 706 // the layout. | 709 // the layout. |
| 707 // Using display.bounds() and display.work_area() would fail most of the | 710 // Using display.bounds() and display.work_area() would fail most of the |
| 708 // time. | 711 // time. |
| 709 if (force_bounds_changed_ || | 712 if (force_bounds_changed_ || |
| 710 (current_display_info.bounds_in_native() != | 713 (current_display_info.bounds_in_native() != |
| 711 new_display_info.bounds_in_native()) || | 714 new_display_info.bounds_in_native()) || |
| 712 (current_display_info.GetOverscanInsetsInPixel() != | 715 (current_display_info.GetOverscanInsetsInPixel() != |
| 713 new_display_info.GetOverscanInsetsInPixel()) || | 716 new_display_info.GetOverscanInsetsInPixel()) || |
| 714 current_display.size() != new_display.size()) { | 717 current_display.size() != new_display.size()) { |
| 715 metrics |= gfx::DisplayObserver::DISPLAY_METRIC_BOUNDS | | 718 metrics |= display::DisplayObserver::DISPLAY_METRIC_BOUNDS | |
| 716 gfx::DisplayObserver::DISPLAY_METRIC_WORK_AREA; | 719 display::DisplayObserver::DISPLAY_METRIC_WORK_AREA; |
| 717 } | 720 } |
| 718 | 721 |
| 719 if (current_display.device_scale_factor() != | 722 if (current_display.device_scale_factor() != |
| 720 new_display.device_scale_factor()) { | 723 new_display.device_scale_factor()) { |
| 721 metrics |= gfx::DisplayObserver::DISPLAY_METRIC_DEVICE_SCALE_FACTOR; | 724 metrics |= display::DisplayObserver::DISPLAY_METRIC_DEVICE_SCALE_FACTOR; |
| 722 } | 725 } |
| 723 | 726 |
| 724 if (current_display.rotation() != new_display.rotation()) | 727 if (current_display.rotation() != new_display.rotation()) |
| 725 metrics |= gfx::DisplayObserver::DISPLAY_METRIC_ROTATION; | 728 metrics |= display::DisplayObserver::DISPLAY_METRIC_ROTATION; |
| 726 | 729 |
| 727 if (metrics != gfx::DisplayObserver::DISPLAY_METRIC_NONE) { | 730 if (metrics != display::DisplayObserver::DISPLAY_METRIC_NONE) { |
| 728 display_changes.insert( | 731 display_changes.insert( |
| 729 std::pair<size_t, uint32_t>(new_displays.size(), metrics)); | 732 std::pair<size_t, uint32_t>(new_displays.size(), metrics)); |
| 730 } | 733 } |
| 731 | 734 |
| 732 new_display.UpdateWorkAreaFromInsets(current_display.GetWorkAreaInsets()); | 735 new_display.UpdateWorkAreaFromInsets(current_display.GetWorkAreaInsets()); |
| 733 new_displays.push_back(new_display); | 736 new_displays.push_back(new_display); |
| 734 ++curr_iter; | 737 ++curr_iter; |
| 735 ++new_info_iter; | 738 ++new_info_iter; |
| 736 } else if (curr_iter->id() < new_info_iter->id()) { | 739 } else if (curr_iter->id() < new_info_iter->id()) { |
| 737 // more displays in current list between ids, which means it is deleted. | 740 // more displays in current list between ids, which means it is deleted. |
| 738 removed_displays.push_back(*curr_iter); | 741 removed_displays.push_back(*curr_iter); |
| 739 ++curr_iter; | 742 ++curr_iter; |
| 740 } else { | 743 } else { |
| 741 // more displays in new list between ids, which means it is added. | 744 // more displays in new list between ids, which means it is added. |
| 742 added_display_indices.push_back(new_displays.size()); | 745 added_display_indices.push_back(new_displays.size()); |
| 743 InsertAndUpdateDisplayInfo(*new_info_iter); | 746 InsertAndUpdateDisplayInfo(*new_info_iter); |
| 744 new_displays.push_back( | 747 new_displays.push_back( |
| 745 CreateDisplayFromDisplayInfoById(new_info_iter->id())); | 748 CreateDisplayFromDisplayInfoById(new_info_iter->id())); |
| 746 ++new_info_iter; | 749 ++new_info_iter; |
| 747 } | 750 } |
| 748 } | 751 } |
| 749 gfx::Display old_primary; | 752 display::Display old_primary; |
| 750 if (delegate_) | 753 if (delegate_) |
| 751 old_primary = screen_->GetPrimaryDisplay(); | 754 old_primary = screen_->GetPrimaryDisplay(); |
| 752 | 755 |
| 753 // Clear focus if the display has been removed, but don't clear focus if | 756 // Clear focus if the display has been removed, but don't clear focus if |
| 754 // the destkop has been moved from one display to another | 757 // the destkop has been moved from one display to another |
| 755 // (mirror -> docked, docked -> single internal). | 758 // (mirror -> docked, docked -> single internal). |
| 756 bool clear_focus = | 759 bool clear_focus = |
| 757 !removed_displays.empty() && | 760 !removed_displays.empty() && |
| 758 !(removed_displays.size() == 1 && added_display_indices.size() == 1); | 761 !(removed_displays.size() == 1 && added_display_indices.size() == 1); |
| 759 if (delegate_) | 762 if (delegate_) |
| 760 delegate_->PreDisplayConfigurationChange(clear_focus); | 763 delegate_->PreDisplayConfigurationChange(clear_focus); |
| 761 | 764 |
| 762 std::vector<size_t> updated_indices; | 765 std::vector<size_t> updated_indices; |
| 763 UpdateNonPrimaryDisplayBoundsForLayout(&new_displays, &updated_indices); | 766 UpdateNonPrimaryDisplayBoundsForLayout(&new_displays, &updated_indices); |
| 764 for (size_t updated_index : updated_indices) { | 767 for (size_t updated_index : updated_indices) { |
| 765 if (std::find(added_display_indices.begin(), added_display_indices.end(), | 768 if (std::find(added_display_indices.begin(), added_display_indices.end(), |
| 766 updated_index) == added_display_indices.end()) { | 769 updated_index) == added_display_indices.end()) { |
| 767 uint32_t metrics = gfx::DisplayObserver::DISPLAY_METRIC_BOUNDS | | 770 uint32_t metrics = display::DisplayObserver::DISPLAY_METRIC_BOUNDS | |
| 768 gfx::DisplayObserver::DISPLAY_METRIC_WORK_AREA; | 771 display::DisplayObserver::DISPLAY_METRIC_WORK_AREA; |
| 769 if (display_changes.find(updated_index) != display_changes.end()) | 772 if (display_changes.find(updated_index) != display_changes.end()) |
| 770 metrics |= display_changes[updated_index]; | 773 metrics |= display_changes[updated_index]; |
| 771 | 774 |
| 772 display_changes[updated_index] = metrics; | 775 display_changes[updated_index] = metrics; |
| 773 } | 776 } |
| 774 } | 777 } |
| 775 | 778 |
| 776 active_display_list_ = new_displays; | 779 active_display_list_ = new_displays; |
| 777 | 780 |
| 778 RefreshFontParams(); | 781 RefreshFontParams(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 792 | 795 |
| 793 active_display_list_.resize(active_display_list_size); | 796 active_display_list_.resize(active_display_list_size); |
| 794 | 797 |
| 795 bool notify_primary_change = | 798 bool notify_primary_change = |
| 796 delegate_ ? old_primary.id() != screen_->GetPrimaryDisplay().id() : false; | 799 delegate_ ? old_primary.id() != screen_->GetPrimaryDisplay().id() : false; |
| 797 | 800 |
| 798 for (std::map<size_t, uint32_t>::iterator iter = display_changes.begin(); | 801 for (std::map<size_t, uint32_t>::iterator iter = display_changes.begin(); |
| 799 iter != display_changes.end(); | 802 iter != display_changes.end(); |
| 800 ++iter) { | 803 ++iter) { |
| 801 uint32_t metrics = iter->second; | 804 uint32_t metrics = iter->second; |
| 802 const gfx::Display& updated_display = active_display_list_[iter->first]; | 805 const display::Display& updated_display = active_display_list_[iter->first]; |
| 803 | 806 |
| 804 if (notify_primary_change && | 807 if (notify_primary_change && |
| 805 updated_display.id() == screen_->GetPrimaryDisplay().id()) { | 808 updated_display.id() == screen_->GetPrimaryDisplay().id()) { |
| 806 metrics |= gfx::DisplayObserver::DISPLAY_METRIC_PRIMARY; | 809 metrics |= display::DisplayObserver::DISPLAY_METRIC_PRIMARY; |
| 807 notify_primary_change = false; | 810 notify_primary_change = false; |
| 808 } | 811 } |
| 809 screen_->NotifyMetricsChanged(updated_display, metrics); | 812 screen_->NotifyMetricsChanged(updated_display, metrics); |
| 810 } | 813 } |
| 811 | 814 |
| 812 if (notify_primary_change) { | 815 if (notify_primary_change) { |
| 813 // This happens when a primary display has moved to anther display without | 816 // This happens when a primary display has moved to anther display without |
| 814 // bounds change. | 817 // bounds change. |
| 815 const gfx::Display& primary = screen_->GetPrimaryDisplay(); | 818 const display::Display& primary = screen_->GetPrimaryDisplay(); |
| 816 if (primary.id() != old_primary.id()) { | 819 if (primary.id() != old_primary.id()) { |
| 817 uint32_t metrics = gfx::DisplayObserver::DISPLAY_METRIC_PRIMARY; | 820 uint32_t metrics = display::DisplayObserver::DISPLAY_METRIC_PRIMARY; |
| 818 if (primary.size() != old_primary.size()) { | 821 if (primary.size() != old_primary.size()) { |
| 819 metrics |= (gfx::DisplayObserver::DISPLAY_METRIC_BOUNDS | | 822 metrics |= (display::DisplayObserver::DISPLAY_METRIC_BOUNDS | |
| 820 gfx::DisplayObserver::DISPLAY_METRIC_WORK_AREA); | 823 display::DisplayObserver::DISPLAY_METRIC_WORK_AREA); |
| 821 } | 824 } |
| 822 if (primary.device_scale_factor() != old_primary.device_scale_factor()) | 825 if (primary.device_scale_factor() != old_primary.device_scale_factor()) |
| 823 metrics |= gfx::DisplayObserver::DISPLAY_METRIC_DEVICE_SCALE_FACTOR; | 826 metrics |= display::DisplayObserver::DISPLAY_METRIC_DEVICE_SCALE_FACTOR; |
| 824 | 827 |
| 825 screen_->NotifyMetricsChanged(primary, metrics); | 828 screen_->NotifyMetricsChanged(primary, metrics); |
| 826 } | 829 } |
| 827 } | 830 } |
| 828 | 831 |
| 829 if (delegate_) | 832 if (delegate_) |
| 830 delegate_->PostDisplayConfigurationChange(); | 833 delegate_->PostDisplayConfigurationChange(); |
| 831 | 834 |
| 832 #if defined(USE_X11) && defined(OS_CHROMEOS) | 835 #if defined(USE_X11) && defined(OS_CHROMEOS) |
| 833 if (!display_changes.empty() && base::SysInfo::IsRunningOnChromeOS()) | 836 if (!display_changes.empty() && base::SysInfo::IsRunningOnChromeOS()) |
| 834 ui::ClearX11DefaultRootWindow(); | 837 ui::ClearX11DefaultRootWindow(); |
| 835 #endif | 838 #endif |
| 836 | 839 |
| 837 // Create the mirroring window asynchronously after all displays | 840 // Create the mirroring window asynchronously after all displays |
| 838 // are added so that it can mirror the display newly added. This can | 841 // are added so that it can mirror the display newly added. This can |
| 839 // happen when switching from dock mode to software mirror mode. | 842 // happen when switching from dock mode to software mirror mode. |
| 840 CreateMirrorWindowAsyncIfAny(); | 843 CreateMirrorWindowAsyncIfAny(); |
| 841 } | 844 } |
| 842 | 845 |
| 843 const gfx::Display& DisplayManager::GetDisplayAt(size_t index) const { | 846 const display::Display& DisplayManager::GetDisplayAt(size_t index) const { |
| 844 DCHECK_LT(index, active_display_list_.size()); | 847 DCHECK_LT(index, active_display_list_.size()); |
| 845 return active_display_list_[index]; | 848 return active_display_list_[index]; |
| 846 } | 849 } |
| 847 | 850 |
| 848 const gfx::Display& DisplayManager::GetPrimaryDisplayCandidate() const { | 851 const display::Display& DisplayManager::GetPrimaryDisplayCandidate() const { |
| 849 if (GetNumDisplays() != 2) | 852 if (GetNumDisplays() != 2) |
| 850 return active_display_list_[0]; | 853 return active_display_list_[0]; |
| 851 const display::DisplayLayout& layout = | 854 const display::DisplayLayout& layout = |
| 852 layout_store_->GetRegisteredDisplayLayout(GetCurrentDisplayIdList()); | 855 layout_store_->GetRegisteredDisplayLayout(GetCurrentDisplayIdList()); |
| 853 return GetDisplayForId(layout.primary_id); | 856 return GetDisplayForId(layout.primary_id); |
| 854 } | 857 } |
| 855 | 858 |
| 856 size_t DisplayManager::GetNumDisplays() const { | 859 size_t DisplayManager::GetNumDisplays() const { |
| 857 return active_display_list_.size(); | 860 return active_display_list_.size(); |
| 858 } | 861 } |
| 859 | 862 |
| 860 bool DisplayManager::IsActiveDisplayId(int64_t display_id) const { | 863 bool DisplayManager::IsActiveDisplayId(int64_t display_id) const { |
| 861 return std::find_if(active_display_list_.begin(), active_display_list_.end(), | 864 return std::find_if(active_display_list_.begin(), active_display_list_.end(), |
| 862 [display_id](const gfx::Display& display) { | 865 [display_id](const display::Display& display) { |
| 863 return display.id() == display_id; | 866 return display.id() == display_id; |
| 864 }) != active_display_list_.end(); | 867 }) != active_display_list_.end(); |
| 865 } | 868 } |
| 866 | 869 |
| 867 bool DisplayManager::IsInMirrorMode() const { | 870 bool DisplayManager::IsInMirrorMode() const { |
| 868 return mirroring_display_id_ != gfx::Display::kInvalidDisplayID; | 871 return mirroring_display_id_ != display::Display::kInvalidDisplayID; |
| 869 } | 872 } |
| 870 | 873 |
| 871 void DisplayManager::SetUnifiedDesktopEnabled(bool enable) { | 874 void DisplayManager::SetUnifiedDesktopEnabled(bool enable) { |
| 872 unified_desktop_enabled_ = enable; | 875 unified_desktop_enabled_ = enable; |
| 873 // There is no need to update the displays in mirror mode. Doing | 876 // There is no need to update the displays in mirror mode. Doing |
| 874 // this in hardware mirroring mode can cause crash because display | 877 // this in hardware mirroring mode can cause crash because display |
| 875 // info in hardware mirroring comes from DisplayConfigurator. | 878 // info in hardware mirroring comes from DisplayConfigurator. |
| 876 if (!IsInMirrorMode()) | 879 if (!IsInMirrorMode()) |
| 877 ReconfigureDisplays(); | 880 ReconfigureDisplays(); |
| 878 } | 881 } |
| 879 | 882 |
| 880 bool DisplayManager::IsInUnifiedMode() const { | 883 bool DisplayManager::IsInUnifiedMode() const { |
| 881 return multi_display_mode_ == UNIFIED && | 884 return multi_display_mode_ == UNIFIED && |
| 882 !software_mirroring_display_list_.empty(); | 885 !software_mirroring_display_list_.empty(); |
| 883 } | 886 } |
| 884 | 887 |
| 885 const DisplayInfo& DisplayManager::GetDisplayInfo(int64_t display_id) const { | 888 const DisplayInfo& DisplayManager::GetDisplayInfo(int64_t display_id) const { |
| 886 DCHECK_NE(gfx::Display::kInvalidDisplayID, display_id); | 889 DCHECK_NE(display::Display::kInvalidDisplayID, display_id); |
| 887 | 890 |
| 888 std::map<int64_t, DisplayInfo>::const_iterator iter = | 891 std::map<int64_t, DisplayInfo>::const_iterator iter = |
| 889 display_info_.find(display_id); | 892 display_info_.find(display_id); |
| 890 CHECK(iter != display_info_.end()) << display_id; | 893 CHECK(iter != display_info_.end()) << display_id; |
| 891 return iter->second; | 894 return iter->second; |
| 892 } | 895 } |
| 893 | 896 |
| 894 const gfx::Display DisplayManager::GetMirroringDisplayById( | 897 const display::Display DisplayManager::GetMirroringDisplayById( |
| 895 int64_t display_id) const { | 898 int64_t display_id) const { |
| 896 auto iter = std::find_if(software_mirroring_display_list_.begin(), | 899 auto iter = std::find_if(software_mirroring_display_list_.begin(), |
| 897 software_mirroring_display_list_.end(), | 900 software_mirroring_display_list_.end(), |
| 898 [display_id](const gfx::Display& display) { | 901 [display_id](const display::Display& display) { |
| 899 return display.id() == display_id; | 902 return display.id() == display_id; |
| 900 }); | 903 }); |
| 901 return iter == software_mirroring_display_list_.end() ? gfx::Display() | 904 return iter == software_mirroring_display_list_.end() ? display::Display() |
| 902 : *iter; | 905 : *iter; |
| 903 } | 906 } |
| 904 | 907 |
| 905 std::string DisplayManager::GetDisplayNameForId(int64_t id) { | 908 std::string DisplayManager::GetDisplayNameForId(int64_t id) { |
| 906 if (id == gfx::Display::kInvalidDisplayID) | 909 if (id == display::Display::kInvalidDisplayID) |
| 907 return l10n_util::GetStringUTF8(IDS_ASH_STATUS_TRAY_UNKNOWN_DISPLAY_NAME); | 910 return l10n_util::GetStringUTF8(IDS_ASH_STATUS_TRAY_UNKNOWN_DISPLAY_NAME); |
| 908 | 911 |
| 909 std::map<int64_t, DisplayInfo>::const_iterator iter = display_info_.find(id); | 912 std::map<int64_t, DisplayInfo>::const_iterator iter = display_info_.find(id); |
| 910 if (iter != display_info_.end() && !iter->second.name().empty()) | 913 if (iter != display_info_.end() && !iter->second.name().empty()) |
| 911 return iter->second.name(); | 914 return iter->second.name(); |
| 912 | 915 |
| 913 return base::StringPrintf("Display %d", static_cast<int>(id)); | 916 return base::StringPrintf("Display %d", static_cast<int>(id)); |
| 914 } | 917 } |
| 915 | 918 |
| 916 int64_t DisplayManager::GetDisplayIdForUIScaling() const { | 919 int64_t DisplayManager::GetDisplayIdForUIScaling() const { |
| 917 // UI Scaling is effective on internal display. | 920 // UI Scaling is effective on internal display. |
| 918 return gfx::Display::HasInternalDisplay() ? gfx::Display::InternalDisplayId() | 921 return display::Display::HasInternalDisplay() |
| 919 : gfx::Display::kInvalidDisplayID; | 922 ? display::Display::InternalDisplayId() |
| 923 : display::Display::kInvalidDisplayID; |
| 920 } | 924 } |
| 921 | 925 |
| 922 void DisplayManager::SetMirrorMode(bool mirror) { | 926 void DisplayManager::SetMirrorMode(bool mirror) { |
| 923 // TODO(oshima): Enable mirror mode for 2> displays. crbug.com/589319. | 927 // TODO(oshima): Enable mirror mode for 2> displays. crbug.com/589319. |
| 924 if (num_connected_displays() != 2) | 928 if (num_connected_displays() != 2) |
| 925 return; | 929 return; |
| 926 | 930 |
| 927 #if defined(OS_CHROMEOS) | 931 #if defined(OS_CHROMEOS) |
| 928 if (base::SysInfo::IsRunningOnChromeOS()) { | 932 if (base::SysInfo::IsRunningOnChromeOS()) { |
| 929 ui::MultipleDisplayState new_state = | 933 ui::MultipleDisplayState new_state = |
| (...skipping 20 matching lines...) Expand all Loading... |
| 950 if (num_connected_displays() == 1) { | 954 if (num_connected_displays() == 1) { |
| 951 const int kVerticalOffsetPx = 100; | 955 const int kVerticalOffsetPx = 100; |
| 952 // Layout the 2nd display below the primary as with the real device. | 956 // Layout the 2nd display below the primary as with the real device. |
| 953 gfx::Rect host_bounds = first_display.bounds_in_native(); | 957 gfx::Rect host_bounds = first_display.bounds_in_native(); |
| 954 new_display_info_list.push_back( | 958 new_display_info_list.push_back( |
| 955 DisplayInfo::CreateFromSpec(base::StringPrintf( | 959 DisplayInfo::CreateFromSpec(base::StringPrintf( |
| 956 "%d+%d-600x%d", host_bounds.x(), | 960 "%d+%d-600x%d", host_bounds.x(), |
| 957 host_bounds.bottom() + kVerticalOffsetPx, host_bounds.height()))); | 961 host_bounds.bottom() + kVerticalOffsetPx, host_bounds.height()))); |
| 958 } | 962 } |
| 959 num_connected_displays_ = new_display_info_list.size(); | 963 num_connected_displays_ = new_display_info_list.size(); |
| 960 mirroring_display_id_ = gfx::Display::kInvalidDisplayID; | 964 mirroring_display_id_ = display::Display::kInvalidDisplayID; |
| 961 software_mirroring_display_list_.clear(); | 965 software_mirroring_display_list_.clear(); |
| 962 UpdateDisplaysWith(new_display_info_list); | 966 UpdateDisplaysWith(new_display_info_list); |
| 963 } | 967 } |
| 964 | 968 |
| 965 void DisplayManager::ToggleDisplayScaleFactor() { | 969 void DisplayManager::ToggleDisplayScaleFactor() { |
| 966 DCHECK(!active_display_list_.empty()); | 970 DCHECK(!active_display_list_.empty()); |
| 967 std::vector<DisplayInfo> new_display_info_list; | 971 std::vector<DisplayInfo> new_display_info_list; |
| 968 for (display::DisplayList::const_iterator iter = active_display_list_.begin(); | 972 for (display::DisplayList::const_iterator iter = active_display_list_.begin(); |
| 969 iter != active_display_list_.end(); ++iter) { | 973 iter != active_display_list_.end(); ++iter) { |
| 970 DisplayInfo display_info = GetDisplayInfo(iter->id()); | 974 DisplayInfo display_info = GetDisplayInfo(iter->id()); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 991 MultiDisplayMode mode) { | 995 MultiDisplayMode mode) { |
| 992 DCHECK_NE(MIRRORING, mode); | 996 DCHECK_NE(MIRRORING, mode); |
| 993 display::DisplayIdList list = GetCurrentDisplayIdList(); | 997 display::DisplayIdList list = GetCurrentDisplayIdList(); |
| 994 layout_store_->UpdateMultiDisplayState(list, IsInMirrorMode(), | 998 layout_store_->UpdateMultiDisplayState(list, IsInMirrorMode(), |
| 995 mode == UNIFIED); | 999 mode == UNIFIED); |
| 996 ReconfigureDisplays(); | 1000 ReconfigureDisplays(); |
| 997 } | 1001 } |
| 998 | 1002 |
| 999 void DisplayManager::SetMultiDisplayMode(MultiDisplayMode mode) { | 1003 void DisplayManager::SetMultiDisplayMode(MultiDisplayMode mode) { |
| 1000 multi_display_mode_ = mode; | 1004 multi_display_mode_ = mode; |
| 1001 mirroring_display_id_ = gfx::Display::kInvalidDisplayID; | 1005 mirroring_display_id_ = display::Display::kInvalidDisplayID; |
| 1002 software_mirroring_display_list_.clear(); | 1006 software_mirroring_display_list_.clear(); |
| 1003 } | 1007 } |
| 1004 | 1008 |
| 1005 void DisplayManager::ReconfigureDisplays() { | 1009 void DisplayManager::ReconfigureDisplays() { |
| 1006 DisplayInfoList display_info_list; | 1010 DisplayInfoList display_info_list; |
| 1007 for (const gfx::Display& display : active_display_list_) { | 1011 for (const display::Display& display : active_display_list_) { |
| 1008 if (display.id() == kUnifiedDisplayId) | 1012 if (display.id() == kUnifiedDisplayId) |
| 1009 continue; | 1013 continue; |
| 1010 display_info_list.push_back(GetDisplayInfo(display.id())); | 1014 display_info_list.push_back(GetDisplayInfo(display.id())); |
| 1011 } | 1015 } |
| 1012 for (const gfx::Display& display : software_mirroring_display_list_) | 1016 for (const display::Display& display : software_mirroring_display_list_) |
| 1013 display_info_list.push_back(GetDisplayInfo(display.id())); | 1017 display_info_list.push_back(GetDisplayInfo(display.id())); |
| 1014 mirroring_display_id_ = gfx::Display::kInvalidDisplayID; | 1018 mirroring_display_id_ = display::Display::kInvalidDisplayID; |
| 1015 software_mirroring_display_list_.clear(); | 1019 software_mirroring_display_list_.clear(); |
| 1016 UpdateDisplaysWith(display_info_list); | 1020 UpdateDisplaysWith(display_info_list); |
| 1017 } | 1021 } |
| 1018 | 1022 |
| 1019 bool DisplayManager::UpdateDisplayBounds(int64_t display_id, | 1023 bool DisplayManager::UpdateDisplayBounds(int64_t display_id, |
| 1020 const gfx::Rect& new_bounds) { | 1024 const gfx::Rect& new_bounds) { |
| 1021 if (change_display_upon_host_resize_) { | 1025 if (change_display_upon_host_resize_) { |
| 1022 display_info_[display_id].SetBounds(new_bounds); | 1026 display_info_[display_id].SetBounds(new_bounds); |
| 1023 // Don't notify observers if the mirrored window has changed. | 1027 // Don't notify observers if the mirrored window has changed. |
| 1024 if (software_mirroring_enabled() && mirroring_display_id_ == display_id) | 1028 if (software_mirroring_enabled() && mirroring_display_id_ == display_id) |
| 1025 return false; | 1029 return false; |
| 1026 gfx::Display* display = FindDisplayForId(display_id); | 1030 display::Display* display = FindDisplayForId(display_id); |
| 1027 display->SetSize(display_info_[display_id].size_in_pixel()); | 1031 display->SetSize(display_info_[display_id].size_in_pixel()); |
| 1028 screen_->NotifyMetricsChanged(*display, | 1032 screen_->NotifyMetricsChanged( |
| 1029 gfx::DisplayObserver::DISPLAY_METRIC_BOUNDS); | 1033 *display, display::DisplayObserver::DISPLAY_METRIC_BOUNDS); |
| 1030 return true; | 1034 return true; |
| 1031 } | 1035 } |
| 1032 return false; | 1036 return false; |
| 1033 } | 1037 } |
| 1034 | 1038 |
| 1035 void DisplayManager::CreateMirrorWindowAsyncIfAny() { | 1039 void DisplayManager::CreateMirrorWindowAsyncIfAny() { |
| 1036 // Do not post a task if the software mirroring doesn't exist, or | 1040 // Do not post a task if the software mirroring doesn't exist, or |
| 1037 // during initialization when compositor's init task isn't posted yet. | 1041 // during initialization when compositor's init task isn't posted yet. |
| 1038 // ash::Shell::Init() will call this after the compositor is initialized. | 1042 // ash::Shell::Init() will call this after the compositor is initialized. |
| 1039 if (software_mirroring_display_list_.empty() || !delegate_) | 1043 if (software_mirroring_display_list_.empty() || !delegate_) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1050 // Extra check for |num_connected_displays()| is for SystemDisplayApiTest | 1054 // Extra check for |num_connected_displays()| is for SystemDisplayApiTest |
| 1051 // that injects MockScreen. | 1055 // that injects MockScreen. |
| 1052 if (GetNumDisplays() < 2 || num_connected_displays() < 2) | 1056 if (GetNumDisplays() < 2 || num_connected_displays() < 2) |
| 1053 return base::WrapUnique(new NullMouseWarpController()); | 1057 return base::WrapUnique(new NullMouseWarpController()); |
| 1054 return base::WrapUnique(new ExtendedMouseWarpController(drag_source)); | 1058 return base::WrapUnique(new ExtendedMouseWarpController(drag_source)); |
| 1055 } | 1059 } |
| 1056 | 1060 |
| 1057 void DisplayManager::CreateScreenForShutdown() const { | 1061 void DisplayManager::CreateScreenForShutdown() const { |
| 1058 delete screen_for_shutdown; | 1062 delete screen_for_shutdown; |
| 1059 screen_for_shutdown = screen_->CloneForShutdown(); | 1063 screen_for_shutdown = screen_->CloneForShutdown(); |
| 1060 gfx::Screen::SetScreenInstance(screen_for_shutdown); | 1064 display::Screen::SetScreenInstance(screen_for_shutdown); |
| 1061 } | 1065 } |
| 1062 | 1066 |
| 1063 void DisplayManager::UpdateInternalDisplayModeListForTest() { | 1067 void DisplayManager::UpdateInternalDisplayModeListForTest() { |
| 1064 if (!gfx::Display::HasInternalDisplay() || | 1068 if (!display::Display::HasInternalDisplay() || |
| 1065 display_info_.count(gfx::Display::InternalDisplayId()) == 0) | 1069 display_info_.count(display::Display::InternalDisplayId()) == 0) |
| 1066 return; | 1070 return; |
| 1067 DisplayInfo* info = &display_info_[gfx::Display::InternalDisplayId()]; | 1071 DisplayInfo* info = &display_info_[display::Display::InternalDisplayId()]; |
| 1068 SetInternalDisplayModeList(info); | 1072 SetInternalDisplayModeList(info); |
| 1069 } | 1073 } |
| 1070 | 1074 |
| 1071 void DisplayManager::CreateSoftwareMirroringDisplayInfo( | 1075 void DisplayManager::CreateSoftwareMirroringDisplayInfo( |
| 1072 DisplayInfoList* display_info_list) { | 1076 DisplayInfoList* display_info_list) { |
| 1073 // Use the internal display or 1st as the mirror source, then scale | 1077 // Use the internal display or 1st as the mirror source, then scale |
| 1074 // the root window so that it matches the external display's | 1078 // the root window so that it matches the external display's |
| 1075 // resolution. This is necessary in order for scaling to work while | 1079 // resolution. This is necessary in order for scaling to work while |
| 1076 // mirrored. | 1080 // mirrored. |
| 1077 switch (multi_display_mode_) { | 1081 switch (multi_display_mode_) { |
| 1078 case MIRRORING: { | 1082 case MIRRORING: { |
| 1079 if (display_info_list->size() != 2) | 1083 if (display_info_list->size() != 2) |
| 1080 return; | 1084 return; |
| 1081 bool zero_is_source = | 1085 bool zero_is_source = |
| 1082 first_display_id_ == (*display_info_list)[0].id() || | 1086 first_display_id_ == (*display_info_list)[0].id() || |
| 1083 gfx::Display::IsInternalDisplayId((*display_info_list)[0].id()); | 1087 display::Display::IsInternalDisplayId((*display_info_list)[0].id()); |
| 1084 DCHECK_EQ(MIRRORING, multi_display_mode_); | 1088 DCHECK_EQ(MIRRORING, multi_display_mode_); |
| 1085 mirroring_display_id_ = (*display_info_list)[zero_is_source ? 1 : 0].id(); | 1089 mirroring_display_id_ = (*display_info_list)[zero_is_source ? 1 : 0].id(); |
| 1086 | 1090 |
| 1087 int64_t display_id = mirroring_display_id_; | 1091 int64_t display_id = mirroring_display_id_; |
| 1088 auto iter = | 1092 auto iter = |
| 1089 std::find_if(display_info_list->begin(), display_info_list->end(), | 1093 std::find_if(display_info_list->begin(), display_info_list->end(), |
| 1090 [display_id](const DisplayInfo& info) { | 1094 [display_id](const DisplayInfo& info) { |
| 1091 return info.id() == display_id; | 1095 return info.id() == display_id; |
| 1092 }); | 1096 }); |
| 1093 DCHECK(iter != display_info_list->end()); | 1097 DCHECK(iter != display_info_list->end()); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1109 // right to left, or vertical layouts. | 1113 // right to left, or vertical layouts. |
| 1110 gfx::Rect unified_bounds; | 1114 gfx::Rect unified_bounds; |
| 1111 software_mirroring_display_list_.clear(); | 1115 software_mirroring_display_list_.clear(); |
| 1112 // 1st Pass. Find the max size. | 1116 // 1st Pass. Find the max size. |
| 1113 int max_height = std::numeric_limits<int>::min(); | 1117 int max_height = std::numeric_limits<int>::min(); |
| 1114 | 1118 |
| 1115 int default_height = 0; | 1119 int default_height = 0; |
| 1116 float default_device_scale_factor = 1.0f; | 1120 float default_device_scale_factor = 1.0f; |
| 1117 for (auto& info : *display_info_list) { | 1121 for (auto& info : *display_info_list) { |
| 1118 max_height = std::max(max_height, info.size_in_pixel().height()); | 1122 max_height = std::max(max_height, info.size_in_pixel().height()); |
| 1119 if (!default_height || gfx::Display::IsInternalDisplayId(info.id())) { | 1123 if (!default_height || |
| 1124 display::Display::IsInternalDisplayId(info.id())) { |
| 1120 default_height = info.size_in_pixel().height(); | 1125 default_height = info.size_in_pixel().height(); |
| 1121 default_device_scale_factor = info.device_scale_factor(); | 1126 default_device_scale_factor = info.device_scale_factor(); |
| 1122 } | 1127 } |
| 1123 } | 1128 } |
| 1124 | 1129 |
| 1125 std::vector<DisplayMode> display_mode_list; | 1130 std::vector<DisplayMode> display_mode_list; |
| 1126 std::set<std::pair<float, float>> dsf_scale_list; | 1131 std::set<std::pair<float, float>> dsf_scale_list; |
| 1127 | 1132 |
| 1128 // 2nd Pass. Compute the unified display size. | 1133 // 2nd Pass. Compute the unified display size. |
| 1129 for (auto& info : *display_info_list) { | 1134 for (auto& info : *display_info_list) { |
| 1130 InsertAndUpdateDisplayInfo(info); | 1135 InsertAndUpdateDisplayInfo(info); |
| 1131 gfx::Point origin(unified_bounds.right(), 0); | 1136 gfx::Point origin(unified_bounds.right(), 0); |
| 1132 float scale = | 1137 float scale = |
| 1133 info.size_in_pixel().height() / static_cast<float>(max_height); | 1138 info.size_in_pixel().height() / static_cast<float>(max_height); |
| 1134 // The display is scaled to fit the unified desktop size. | 1139 // The display is scaled to fit the unified desktop size. |
| 1135 gfx::Display display = CreateMirroringDisplayFromDisplayInfoById( | 1140 display::Display display = CreateMirroringDisplayFromDisplayInfoById( |
| 1136 info.id(), origin, 1.0f / scale); | 1141 info.id(), origin, 1.0f / scale); |
| 1137 unified_bounds.Union(display.bounds()); | 1142 unified_bounds.Union(display.bounds()); |
| 1138 | 1143 |
| 1139 dsf_scale_list.insert( | 1144 dsf_scale_list.insert( |
| 1140 std::make_pair(info.device_scale_factor(), scale)); | 1145 std::make_pair(info.device_scale_factor(), scale)); |
| 1141 } | 1146 } |
| 1142 | 1147 |
| 1143 DisplayInfo info(kUnifiedDisplayId, "Unified Desktop", false); | 1148 DisplayInfo info(kUnifiedDisplayId, "Unified Desktop", false); |
| 1144 | 1149 |
| 1145 DisplayMode native_mode(unified_bounds.size(), 60.0f, false, true); | 1150 DisplayMode native_mode(unified_bounds.size(), 60.0f, false, true); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1176 info.SetBounds(gfx::Rect(mode.size)); | 1181 info.SetBounds(gfx::Rect(mode.size)); |
| 1177 } else { | 1182 } else { |
| 1178 display_modes_.erase(kUnifiedDisplayId); | 1183 display_modes_.erase(kUnifiedDisplayId); |
| 1179 } | 1184 } |
| 1180 | 1185 |
| 1181 int unified_display_height = info.size_in_pixel().height(); | 1186 int unified_display_height = info.size_in_pixel().height(); |
| 1182 gfx::Point origin; | 1187 gfx::Point origin; |
| 1183 for (auto& info : *display_info_list) { | 1188 for (auto& info : *display_info_list) { |
| 1184 float display_scale = info.size_in_pixel().height() / | 1189 float display_scale = info.size_in_pixel().height() / |
| 1185 static_cast<float>(unified_display_height); | 1190 static_cast<float>(unified_display_height); |
| 1186 gfx::Display display = CreateMirroringDisplayFromDisplayInfoById( | 1191 display::Display display = CreateMirroringDisplayFromDisplayInfoById( |
| 1187 info.id(), origin, 1.0f / display_scale); | 1192 info.id(), origin, 1.0f / display_scale); |
| 1188 origin.Offset(display.size().width(), 0); | 1193 origin.Offset(display.size().width(), 0); |
| 1189 display.UpdateWorkAreaFromInsets(gfx::Insets()); | 1194 display.UpdateWorkAreaFromInsets(gfx::Insets()); |
| 1190 software_mirroring_display_list_.push_back(display); | 1195 software_mirroring_display_list_.push_back(display); |
| 1191 } | 1196 } |
| 1192 | 1197 |
| 1193 display_info_list->clear(); | 1198 display_info_list->clear(); |
| 1194 display_info_list->push_back(info); | 1199 display_info_list->push_back(info); |
| 1195 InsertAndUpdateDisplayInfo(info); | 1200 InsertAndUpdateDisplayInfo(info); |
| 1196 break; | 1201 break; |
| 1197 } | 1202 } |
| 1198 case EXTENDED: | 1203 case EXTENDED: |
| 1199 break; | 1204 break; |
| 1200 } | 1205 } |
| 1201 } | 1206 } |
| 1202 | 1207 |
| 1203 gfx::Display* DisplayManager::FindDisplayForId(int64_t id) { | 1208 display::Display* DisplayManager::FindDisplayForId(int64_t id) { |
| 1204 auto iter = std::find_if( | 1209 auto iter = std::find_if( |
| 1205 active_display_list_.begin(), active_display_list_.end(), | 1210 active_display_list_.begin(), active_display_list_.end(), |
| 1206 [id](const gfx::Display& display) { return display.id() == id; }); | 1211 [id](const display::Display& display) { return display.id() == id; }); |
| 1207 if (iter != active_display_list_.end()) | 1212 if (iter != active_display_list_.end()) |
| 1208 return &(*iter); | 1213 return &(*iter); |
| 1209 // TODO(oshima): This happens when a windows in unified desktop have | 1214 // TODO(oshima): This happens when a windows in unified desktop have |
| 1210 // been moved to normal window. Fix this. | 1215 // been moved to normal window. Fix this. |
| 1211 if (id != kUnifiedDisplayId) | 1216 if (id != kUnifiedDisplayId) |
| 1212 DLOG(WARNING) << "Could not find display:" << id; | 1217 DLOG(WARNING) << "Could not find display:" << id; |
| 1213 return nullptr; | 1218 return nullptr; |
| 1214 } | 1219 } |
| 1215 | 1220 |
| 1216 void DisplayManager::AddMirrorDisplayInfoIfAny( | 1221 void DisplayManager::AddMirrorDisplayInfoIfAny( |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1237 void DisplayManager::OnDisplayInfoUpdated(const DisplayInfo& display_info) { | 1242 void DisplayManager::OnDisplayInfoUpdated(const DisplayInfo& display_info) { |
| 1238 #if defined(OS_CHROMEOS) | 1243 #if defined(OS_CHROMEOS) |
| 1239 ui::ColorCalibrationProfile color_profile = display_info.color_profile(); | 1244 ui::ColorCalibrationProfile color_profile = display_info.color_profile(); |
| 1240 if (color_profile != ui::COLOR_PROFILE_STANDARD) { | 1245 if (color_profile != ui::COLOR_PROFILE_STANDARD) { |
| 1241 Shell::GetInstance()->display_configurator()->SetColorCalibrationProfile( | 1246 Shell::GetInstance()->display_configurator()->SetColorCalibrationProfile( |
| 1242 display_info.id(), color_profile); | 1247 display_info.id(), color_profile); |
| 1243 } | 1248 } |
| 1244 #endif | 1249 #endif |
| 1245 } | 1250 } |
| 1246 | 1251 |
| 1247 gfx::Display DisplayManager::CreateDisplayFromDisplayInfoById(int64_t id) { | 1252 display::Display DisplayManager::CreateDisplayFromDisplayInfoById(int64_t id) { |
| 1248 DCHECK(display_info_.find(id) != display_info_.end()) << "id=" << id; | 1253 DCHECK(display_info_.find(id) != display_info_.end()) << "id=" << id; |
| 1249 const DisplayInfo& display_info = display_info_[id]; | 1254 const DisplayInfo& display_info = display_info_[id]; |
| 1250 | 1255 |
| 1251 gfx::Display new_display(display_info.id()); | 1256 display::Display new_display(display_info.id()); |
| 1252 gfx::Rect bounds_in_native(display_info.size_in_pixel()); | 1257 gfx::Rect bounds_in_native(display_info.size_in_pixel()); |
| 1253 float device_scale_factor = display_info.GetEffectiveDeviceScaleFactor(); | 1258 float device_scale_factor = display_info.GetEffectiveDeviceScaleFactor(); |
| 1254 | 1259 |
| 1255 // Simply set the origin to (0,0). The primary display's origin is | 1260 // Simply set the origin to (0,0). The primary display's origin is |
| 1256 // always (0,0) and the bounds of non-primary display(s) will be updated | 1261 // always (0,0) and the bounds of non-primary display(s) will be updated |
| 1257 // in |UpdateNonPrimaryDisplayBoundsForLayout| called in |UpdateDisplay|. | 1262 // in |UpdateNonPrimaryDisplayBoundsForLayout| called in |UpdateDisplay|. |
| 1258 new_display.SetScaleAndBounds( | 1263 new_display.SetScaleAndBounds( |
| 1259 device_scale_factor, gfx::Rect(bounds_in_native.size())); | 1264 device_scale_factor, gfx::Rect(bounds_in_native.size())); |
| 1260 new_display.set_rotation(display_info.GetActiveRotation()); | 1265 new_display.set_rotation(display_info.GetActiveRotation()); |
| 1261 new_display.set_touch_support(display_info.touch_support()); | 1266 new_display.set_touch_support(display_info.touch_support()); |
| 1262 new_display.set_maximum_cursor_size(display_info.maximum_cursor_size()); | 1267 new_display.set_maximum_cursor_size(display_info.maximum_cursor_size()); |
| 1263 return new_display; | 1268 return new_display; |
| 1264 } | 1269 } |
| 1265 | 1270 |
| 1266 gfx::Display DisplayManager::CreateMirroringDisplayFromDisplayInfoById( | 1271 display::Display DisplayManager::CreateMirroringDisplayFromDisplayInfoById( |
| 1267 int64_t id, | 1272 int64_t id, |
| 1268 const gfx::Point& origin, | 1273 const gfx::Point& origin, |
| 1269 float scale) { | 1274 float scale) { |
| 1270 DCHECK(display_info_.find(id) != display_info_.end()) << "id=" << id; | 1275 DCHECK(display_info_.find(id) != display_info_.end()) << "id=" << id; |
| 1271 const DisplayInfo& display_info = display_info_[id]; | 1276 const DisplayInfo& display_info = display_info_[id]; |
| 1272 | 1277 |
| 1273 gfx::Display new_display(display_info.id()); | 1278 display::Display new_display(display_info.id()); |
| 1274 new_display.SetScaleAndBounds( | 1279 new_display.SetScaleAndBounds( |
| 1275 1.0f, gfx::Rect(origin, gfx::ScaleToFlooredSize( | 1280 1.0f, gfx::Rect(origin, gfx::ScaleToFlooredSize( |
| 1276 display_info.size_in_pixel(), scale))); | 1281 display_info.size_in_pixel(), scale))); |
| 1277 new_display.set_touch_support(display_info.touch_support()); | 1282 new_display.set_touch_support(display_info.touch_support()); |
| 1278 new_display.set_maximum_cursor_size(display_info.maximum_cursor_size()); | 1283 new_display.set_maximum_cursor_size(display_info.maximum_cursor_size()); |
| 1279 return new_display; | 1284 return new_display; |
| 1280 } | 1285 } |
| 1281 | 1286 |
| 1282 void DisplayManager::UpdateNonPrimaryDisplayBoundsForLayout( | 1287 void DisplayManager::UpdateNonPrimaryDisplayBoundsForLayout( |
| 1283 display::DisplayList* display_list, | 1288 display::DisplayList* display_list, |
| 1284 std::vector<size_t>* updated_indices) { | 1289 std::vector<size_t>* updated_indices) { |
| 1285 if (display_list->size() == 1u) | 1290 if (display_list->size() == 1u) |
| 1286 return; | 1291 return; |
| 1287 | 1292 |
| 1288 const display::DisplayLayout& layout = | 1293 const display::DisplayLayout& layout = |
| 1289 layout_store_->GetRegisteredDisplayLayout( | 1294 layout_store_->GetRegisteredDisplayLayout( |
| 1290 CreateDisplayIdList(*display_list)); | 1295 CreateDisplayIdList(*display_list)); |
| 1291 | 1296 |
| 1292 // Ignore if a user has a old format (should be extremely rare) | 1297 // Ignore if a user has a old format (should be extremely rare) |
| 1293 // and this will be replaced with DCHECK. | 1298 // and this will be replaced with DCHECK. |
| 1294 if (layout.primary_id == gfx::Display::kInvalidDisplayID) | 1299 if (layout.primary_id == display::Display::kInvalidDisplayID) |
| 1295 return; | 1300 return; |
| 1296 | 1301 |
| 1297 // display_list does not have translation set, so ApplyDisplayLayout cannot | 1302 // display_list does not have translation set, so ApplyDisplayLayout cannot |
| 1298 // provide accurate change information. We'll find the changes after the call. | 1303 // provide accurate change information. We'll find the changes after the call. |
| 1299 ApplyDisplayLayout(layout, display_list, nullptr); | 1304 ApplyDisplayLayout(layout, display_list, nullptr); |
| 1300 size_t num_displays = display_list->size(); | 1305 size_t num_displays = display_list->size(); |
| 1301 for (size_t index = 0; index < num_displays; ++index) { | 1306 for (size_t index = 0; index < num_displays; ++index) { |
| 1302 const gfx::Display& display = (*display_list)[index]; | 1307 const display::Display& display = (*display_list)[index]; |
| 1303 int64_t id = display.id(); | 1308 int64_t id = display.id(); |
| 1304 const gfx::Display* active_display = FindDisplayForId(id); | 1309 const display::Display* active_display = FindDisplayForId(id); |
| 1305 if (!active_display || (active_display->bounds() != display.bounds())) | 1310 if (!active_display || (active_display->bounds() != display.bounds())) |
| 1306 updated_indices->push_back(index); | 1311 updated_indices->push_back(index); |
| 1307 } | 1312 } |
| 1308 } | 1313 } |
| 1309 | 1314 |
| 1310 void DisplayManager::CreateMirrorWindowIfAny() { | 1315 void DisplayManager::CreateMirrorWindowIfAny() { |
| 1311 if (software_mirroring_display_list_.empty() || !delegate_) | 1316 if (software_mirroring_display_list_.empty() || !delegate_) |
| 1312 return; | 1317 return; |
| 1313 DisplayInfoList list; | 1318 DisplayInfoList list; |
| 1314 for (auto& display : software_mirroring_display_list_) | 1319 for (auto& display : software_mirroring_display_list_) |
| 1315 list.push_back(GetDisplayInfo(display.id())); | 1320 list.push_back(GetDisplayInfo(display.id())); |
| 1316 delegate_->CreateOrUpdateMirroringDisplay(list); | 1321 delegate_->CreateOrUpdateMirroringDisplay(list); |
| 1317 } | 1322 } |
| 1318 | 1323 |
| 1319 void DisplayManager::ApplyDisplayLayout(const display::DisplayLayout& layout, | 1324 void DisplayManager::ApplyDisplayLayout(const display::DisplayLayout& layout, |
| 1320 display::DisplayList* display_list, | 1325 display::DisplayList* display_list, |
| 1321 std::vector<int64_t>* updated_ids) { | 1326 std::vector<int64_t>* updated_ids) { |
| 1322 layout.ApplyToDisplayList(display_list, updated_ids, | 1327 layout.ApplyToDisplayList(display_list, updated_ids, |
| 1323 kMinimumOverlapForInvalidOffset); | 1328 kMinimumOverlapForInvalidOffset); |
| 1324 } | 1329 } |
| 1325 | 1330 |
| 1326 void DisplayManager::RunPendingTasksForTest() { | 1331 void DisplayManager::RunPendingTasksForTest() { |
| 1327 if (!software_mirroring_display_list_.empty()) | 1332 if (!software_mirroring_display_list_.empty()) |
| 1328 base::RunLoop().RunUntilIdle(); | 1333 base::RunLoop().RunUntilIdle(); |
| 1329 } | 1334 } |
| 1330 | 1335 |
| 1331 } // namespace ash | 1336 } // namespace ash |
| OLD | NEW |