Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(307)

Side by Side Diff: ash/display/display_manager.cc

Issue 1540753002: Switch to standard integer types in ash/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: arraysize Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ash/display/display_manager.h ('k') | ash/display/display_manager_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 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 gfx::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 DisplayManager::kUnifiedDisplayId = -10; 127 int64_t DisplayManager::kUnifiedDisplayId = -10;
128 128
129 DisplayManager::DisplayManager() 129 DisplayManager::DisplayManager()
130 : delegate_(NULL), 130 : delegate_(NULL),
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_(gfx::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),
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 // on the secondary. 277 // on the secondary.
278 screen_->NotifyMetricsChanged( 278 screen_->NotifyMetricsChanged(
279 ScreenUtil::GetSecondaryDisplay(), 279 ScreenUtil::GetSecondaryDisplay(),
280 gfx::DisplayObserver::DISPLAY_METRIC_BOUNDS | 280 gfx::DisplayObserver::DISPLAY_METRIC_BOUNDS |
281 gfx::DisplayObserver::DISPLAY_METRIC_WORK_AREA); 281 gfx::DisplayObserver::DISPLAY_METRIC_WORK_AREA);
282 if (delegate_) 282 if (delegate_)
283 delegate_->PostDisplayConfigurationChange(); 283 delegate_->PostDisplayConfigurationChange();
284 } 284 }
285 } 285 }
286 286
287 const gfx::Display& DisplayManager::GetDisplayForId(int64 id) const { 287 const gfx::Display& DisplayManager::GetDisplayForId(int64_t id) const {
288 gfx::Display* display = 288 gfx::Display* display =
289 const_cast<DisplayManager*>(this)->FindDisplayForId(id); 289 const_cast<DisplayManager*>(this)->FindDisplayForId(id);
290 return display ? *display : GetInvalidDisplay(); 290 return display ? *display : GetInvalidDisplay();
291 } 291 }
292 292
293 const gfx::Display& DisplayManager::FindDisplayContainingPoint( 293 const gfx::Display& DisplayManager::FindDisplayContainingPoint(
294 const gfx::Point& point_in_screen) const { 294 const gfx::Point& point_in_screen) const {
295 int index = 295 int index =
296 FindDisplayIndexContainingPoint(active_display_list_, point_in_screen); 296 FindDisplayIndexContainingPoint(active_display_list_, point_in_screen);
297 return index < 0 ? GetInvalidDisplay() : active_display_list_[index]; 297 return index < 0 ? GetInvalidDisplay() : active_display_list_[index];
298 } 298 }
299 299
300 bool DisplayManager::UpdateWorkAreaOfDisplay(int64 display_id, 300 bool DisplayManager::UpdateWorkAreaOfDisplay(int64_t display_id,
301 const gfx::Insets& insets) { 301 const gfx::Insets& insets) {
302 gfx::Display* display = FindDisplayForId(display_id); 302 gfx::Display* display = FindDisplayForId(display_id);
303 DCHECK(display); 303 DCHECK(display);
304 gfx::Rect old_work_area = display->work_area(); 304 gfx::Rect old_work_area = display->work_area();
305 display->UpdateWorkAreaFromInsets(insets); 305 display->UpdateWorkAreaFromInsets(insets);
306 return old_work_area != display->work_area(); 306 return old_work_area != display->work_area();
307 } 307 }
308 308
309 void DisplayManager::SetOverscanInsets(int64 display_id, 309 void DisplayManager::SetOverscanInsets(int64_t display_id,
310 const gfx::Insets& insets_in_dip) { 310 const gfx::Insets& insets_in_dip) {
311 bool update = false; 311 bool update = false;
312 DisplayInfoList display_info_list; 312 DisplayInfoList display_info_list;
313 for (const auto& display : active_display_list_) { 313 for (const auto& display : active_display_list_) {
314 DisplayInfo info = GetDisplayInfo(display.id()); 314 DisplayInfo info = GetDisplayInfo(display.id());
315 if (info.id() == display_id) { 315 if (info.id() == display_id) {
316 if (insets_in_dip.IsEmpty()) { 316 if (insets_in_dip.IsEmpty()) {
317 info.set_clear_overscan_insets(true); 317 info.set_clear_overscan_insets(true);
318 } else { 318 } else {
319 info.set_clear_overscan_insets(false); 319 info.set_clear_overscan_insets(false);
320 info.SetOverscanInsets(insets_in_dip); 320 info.SetOverscanInsets(insets_in_dip);
321 } 321 }
322 update = true; 322 update = true;
323 } 323 }
324 display_info_list.push_back(info); 324 display_info_list.push_back(info);
325 } 325 }
326 if (update) { 326 if (update) {
327 AddMirrorDisplayInfoIfAny(&display_info_list); 327 AddMirrorDisplayInfoIfAny(&display_info_list);
328 UpdateDisplays(display_info_list); 328 UpdateDisplays(display_info_list);
329 } else { 329 } else {
330 display_info_[display_id].SetOverscanInsets(insets_in_dip); 330 display_info_[display_id].SetOverscanInsets(insets_in_dip);
331 } 331 }
332 } 332 }
333 333
334 void DisplayManager::SetDisplayRotation(int64 display_id, 334 void DisplayManager::SetDisplayRotation(int64_t display_id,
335 gfx::Display::Rotation rotation, 335 gfx::Display::Rotation rotation,
336 gfx::Display::RotationSource source) { 336 gfx::Display::RotationSource source) {
337 if (IsInUnifiedMode()) 337 if (IsInUnifiedMode())
338 return; 338 return;
339 339
340 DisplayInfoList display_info_list; 340 DisplayInfoList display_info_list;
341 bool is_active = false; 341 bool is_active = false;
342 for (const auto& display : active_display_list_) { 342 for (const auto& display : active_display_list_) {
343 DisplayInfo info = GetDisplayInfo(display.id()); 343 DisplayInfo info = GetDisplayInfo(display.id());
344 if (info.id() == display_id) { 344 if (info.id() == display_id) {
345 if (info.GetRotation(source) == rotation && 345 if (info.GetRotation(source) == rotation &&
346 info.GetActiveRotation() == rotation) { 346 info.GetActiveRotation() == rotation) {
347 return; 347 return;
348 } 348 }
349 info.SetRotation(rotation, source); 349 info.SetRotation(rotation, source);
350 is_active = true; 350 is_active = true;
351 } 351 }
352 display_info_list.push_back(info); 352 display_info_list.push_back(info);
353 } 353 }
354 if (is_active) { 354 if (is_active) {
355 AddMirrorDisplayInfoIfAny(&display_info_list); 355 AddMirrorDisplayInfoIfAny(&display_info_list);
356 UpdateDisplays(display_info_list); 356 UpdateDisplays(display_info_list);
357 } else if (display_info_.find(display_id) != display_info_.end()) { 357 } else if (display_info_.find(display_id) != display_info_.end()) {
358 // Inactive displays can reactivate, ensure they have been updated. 358 // Inactive displays can reactivate, ensure they have been updated.
359 display_info_[display_id].SetRotation(rotation, source); 359 display_info_[display_id].SetRotation(rotation, source);
360 } 360 }
361 } 361 }
362 362
363 bool DisplayManager::SetDisplayMode(int64 display_id, 363 bool DisplayManager::SetDisplayMode(int64_t display_id,
364 const DisplayMode& display_mode) { 364 const DisplayMode& display_mode) {
365 bool change_ui_scale = GetDisplayIdForUIScaling() == display_id; 365 bool change_ui_scale = GetDisplayIdForUIScaling() == display_id;
366 366
367 DisplayInfoList display_info_list; 367 DisplayInfoList display_info_list;
368 bool display_property_changed = false; 368 bool display_property_changed = false;
369 bool resolution_changed = false; 369 bool resolution_changed = false;
370 for (const auto& display : active_display_list_) { 370 for (const auto& display : active_display_list_) {
371 DisplayInfo info = GetDisplayInfo(display.id()); 371 DisplayInfo info = GetDisplayInfo(display.id());
372 if (info.id() == display_id) { 372 if (info.id() == display_id) {
373 auto iter = FindDisplayMode(info, display_mode); 373 auto iter = FindDisplayMode(info, display_mode);
(...skipping 30 matching lines...) Expand all
404 ReconfigureDisplays(); 404 ReconfigureDisplays();
405 #if defined(OS_CHROMEOS) 405 #if defined(OS_CHROMEOS)
406 } else if (resolution_changed && base::SysInfo::IsRunningOnChromeOS()) { 406 } else if (resolution_changed && base::SysInfo::IsRunningOnChromeOS()) {
407 Shell::GetInstance()->display_configurator()->OnConfigurationChanged(); 407 Shell::GetInstance()->display_configurator()->OnConfigurationChanged();
408 #endif 408 #endif
409 } 409 }
410 return resolution_changed || display_property_changed; 410 return resolution_changed || display_property_changed;
411 } 411 }
412 412
413 void DisplayManager::RegisterDisplayProperty( 413 void DisplayManager::RegisterDisplayProperty(
414 int64 display_id, 414 int64_t display_id,
415 gfx::Display::Rotation rotation, 415 gfx::Display::Rotation rotation,
416 float ui_scale, 416 float ui_scale,
417 const gfx::Insets* overscan_insets, 417 const gfx::Insets* overscan_insets,
418 const gfx::Size& resolution_in_pixels, 418 const gfx::Size& resolution_in_pixels,
419 float device_scale_factor, 419 float device_scale_factor,
420 ui::ColorCalibrationProfile color_profile) { 420 ui::ColorCalibrationProfile color_profile) {
421 if (display_info_.find(display_id) == display_info_.end()) 421 if (display_info_.find(display_id) == display_info_.end())
422 display_info_[display_id] = DisplayInfo(display_id, std::string(), false); 422 display_info_[display_id] = DisplayInfo(display_id, std::string(), false);
423 423
424 // Do not allow rotation in unified desktop mode. 424 // Do not allow rotation in unified desktop mode.
(...skipping 15 matching lines...) Expand all
440 if (!resolution_in_pixels.IsEmpty()) { 440 if (!resolution_in_pixels.IsEmpty()) {
441 DCHECK(!gfx::Display::IsInternalDisplayId(display_id)); 441 DCHECK(!gfx::Display::IsInternalDisplayId(display_id));
442 // Default refresh rate, until OnNativeDisplaysChanged() updates us with the 442 // Default refresh rate, until OnNativeDisplaysChanged() updates us with the
443 // actual display info, is 60 Hz. 443 // actual display info, is 60 Hz.
444 DisplayMode mode(resolution_in_pixels, 60.0f, false, false); 444 DisplayMode mode(resolution_in_pixels, 60.0f, false, false);
445 mode.device_scale_factor = device_scale_factor; 445 mode.device_scale_factor = device_scale_factor;
446 display_modes_[display_id] = mode; 446 display_modes_[display_id] = mode;
447 } 447 }
448 } 448 }
449 449
450 DisplayMode DisplayManager::GetActiveModeForDisplayId(int64 display_id) const { 450 DisplayMode DisplayManager::GetActiveModeForDisplayId(
451 int64_t display_id) const {
451 DisplayMode selected_mode; 452 DisplayMode selected_mode;
452 if (GetSelectedModeForDisplayId(display_id, &selected_mode)) 453 if (GetSelectedModeForDisplayId(display_id, &selected_mode))
453 return selected_mode; 454 return selected_mode;
454 455
455 // If 'selected' mode is empty, it should return the default mode. This means 456 // If 'selected' mode is empty, it should return the default mode. This means
456 // the native mode for the external display. Unfortunately this is not true 457 // the native mode for the external display. Unfortunately this is not true
457 // for the internal display because restoring UI-scale doesn't register the 458 // for the internal display because restoring UI-scale doesn't register the
458 // restored mode to |display_mode_|, so it needs to look up the mode whose 459 // restored mode to |display_mode_|, so it needs to look up the mode whose
459 // UI-scale value matches. See the TODO in RegisterDisplayProperty(). 460 // UI-scale value matches. See the TODO in RegisterDisplayProperty().
460 const DisplayInfo& info = GetDisplayInfo(display_id); 461 const DisplayInfo& info = GetDisplayInfo(display_id);
(...skipping 12 matching lines...) Expand all
473 void DisplayManager::RegisterDisplayRotationProperties(bool rotation_lock, 474 void DisplayManager::RegisterDisplayRotationProperties(bool rotation_lock,
474 gfx::Display::Rotation rotation) { 475 gfx::Display::Rotation rotation) {
475 if (delegate_) 476 if (delegate_)
476 delegate_->PreDisplayConfigurationChange(false); 477 delegate_->PreDisplayConfigurationChange(false);
477 registered_internal_display_rotation_lock_ = rotation_lock; 478 registered_internal_display_rotation_lock_ = rotation_lock;
478 registered_internal_display_rotation_ = rotation; 479 registered_internal_display_rotation_ = rotation;
479 if (delegate_) 480 if (delegate_)
480 delegate_->PostDisplayConfigurationChange(); 481 delegate_->PostDisplayConfigurationChange();
481 } 482 }
482 483
483 bool DisplayManager::GetSelectedModeForDisplayId(int64 id, 484 bool DisplayManager::GetSelectedModeForDisplayId(int64_t id,
484 DisplayMode* mode_out) const { 485 DisplayMode* mode_out) const {
485 std::map<int64, DisplayMode>::const_iterator iter = display_modes_.find(id); 486 std::map<int64_t, DisplayMode>::const_iterator iter = display_modes_.find(id);
486 if (iter == display_modes_.end()) 487 if (iter == display_modes_.end())
487 return false; 488 return false;
488 *mode_out = iter->second; 489 *mode_out = iter->second;
489 return true; 490 return true;
490 } 491 }
491 492
492 bool DisplayManager::IsDisplayUIScalingEnabled() const { 493 bool DisplayManager::IsDisplayUIScalingEnabled() const {
493 return GetDisplayIdForUIScaling() != gfx::Display::kInvalidDisplayID; 494 return GetDisplayIdForUIScaling() != gfx::Display::kInvalidDisplayID;
494 } 495 }
495 496
496 gfx::Insets DisplayManager::GetOverscanInsets(int64 display_id) const { 497 gfx::Insets DisplayManager::GetOverscanInsets(int64_t display_id) const {
497 std::map<int64, DisplayInfo>::const_iterator it = 498 std::map<int64_t, DisplayInfo>::const_iterator it =
498 display_info_.find(display_id); 499 display_info_.find(display_id);
499 return (it != display_info_.end()) ? 500 return (it != display_info_.end()) ?
500 it->second.overscan_insets_in_dip() : gfx::Insets(); 501 it->second.overscan_insets_in_dip() : gfx::Insets();
501 } 502 }
502 503
503 void DisplayManager::SetColorCalibrationProfile( 504 void DisplayManager::SetColorCalibrationProfile(
504 int64 display_id, 505 int64_t display_id,
505 ui::ColorCalibrationProfile profile) { 506 ui::ColorCalibrationProfile profile) {
506 #if defined(OS_CHROMEOS) 507 #if defined(OS_CHROMEOS)
507 if (!display_info_[display_id].IsColorProfileAvailable(profile)) 508 if (!display_info_[display_id].IsColorProfileAvailable(profile))
508 return; 509 return;
509 510
510 if (delegate_) 511 if (delegate_)
511 delegate_->PreDisplayConfigurationChange(false); 512 delegate_->PreDisplayConfigurationChange(false);
512 // Just sets color profile if it's not running on ChromeOS (like tests). 513 // Just sets color profile if it's not running on ChromeOS (like tests).
513 if (!base::SysInfo::IsRunningOnChromeOS() || 514 if (!base::SysInfo::IsRunningOnChromeOS() ||
514 Shell::GetInstance()->display_configurator()->SetColorCalibrationProfile( 515 Shell::GetInstance()->display_configurator()->SetColorCalibrationProfile(
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
863 return active_display_list_[0]; 864 return active_display_list_[0];
864 DisplayLayout layout = layout_store_->GetRegisteredDisplayLayout( 865 DisplayLayout layout = layout_store_->GetRegisteredDisplayLayout(
865 GetCurrentDisplayIdPair()); 866 GetCurrentDisplayIdPair());
866 return GetDisplayForId(layout.primary_id); 867 return GetDisplayForId(layout.primary_id);
867 } 868 }
868 869
869 size_t DisplayManager::GetNumDisplays() const { 870 size_t DisplayManager::GetNumDisplays() const {
870 return active_display_list_.size(); 871 return active_display_list_.size();
871 } 872 }
872 873
873 bool DisplayManager::IsActiveDisplayId(int64 display_id) const { 874 bool DisplayManager::IsActiveDisplayId(int64_t display_id) const {
874 return std::find_if(active_display_list_.begin(), active_display_list_.end(), 875 return std::find_if(active_display_list_.begin(), active_display_list_.end(),
875 [display_id](const gfx::Display& display) { 876 [display_id](const gfx::Display& display) {
876 return display.id() == display_id; 877 return display.id() == display_id;
877 }) != active_display_list_.end(); 878 }) != active_display_list_.end();
878 } 879 }
879 880
880 bool DisplayManager::IsInMirrorMode() const { 881 bool DisplayManager::IsInMirrorMode() const {
881 return mirroring_display_id_ != gfx::Display::kInvalidDisplayID; 882 return mirroring_display_id_ != gfx::Display::kInvalidDisplayID;
882 } 883 }
883 884
884 void DisplayManager::SetUnifiedDesktopEnabled(bool enable) { 885 void DisplayManager::SetUnifiedDesktopEnabled(bool enable) {
885 unified_desktop_enabled_ = enable; 886 unified_desktop_enabled_ = enable;
886 // There is no need to update the displays in mirror mode. Doing 887 // There is no need to update the displays in mirror mode. Doing
887 // this in hardware mirroring mode can cause crash because display 888 // this in hardware mirroring mode can cause crash because display
888 // info in hardware mirroring comes from DisplayConfigurator. 889 // info in hardware mirroring comes from DisplayConfigurator.
889 if (!IsInMirrorMode()) 890 if (!IsInMirrorMode())
890 ReconfigureDisplays(); 891 ReconfigureDisplays();
891 } 892 }
892 893
893 bool DisplayManager::IsInUnifiedMode() const { 894 bool DisplayManager::IsInUnifiedMode() const {
894 return multi_display_mode_ == UNIFIED && 895 return multi_display_mode_ == UNIFIED &&
895 !software_mirroring_display_list_.empty(); 896 !software_mirroring_display_list_.empty();
896 } 897 }
897 898
898 const DisplayInfo& DisplayManager::GetDisplayInfo(int64 display_id) const { 899 const DisplayInfo& DisplayManager::GetDisplayInfo(int64_t display_id) const {
899 DCHECK_NE(gfx::Display::kInvalidDisplayID, display_id); 900 DCHECK_NE(gfx::Display::kInvalidDisplayID, display_id);
900 901
901 std::map<int64, DisplayInfo>::const_iterator iter = 902 std::map<int64_t, DisplayInfo>::const_iterator iter =
902 display_info_.find(display_id); 903 display_info_.find(display_id);
903 CHECK(iter != display_info_.end()) << display_id; 904 CHECK(iter != display_info_.end()) << display_id;
904 return iter->second; 905 return iter->second;
905 } 906 }
906 907
907 const gfx::Display DisplayManager::GetMirroringDisplayById( 908 const gfx::Display DisplayManager::GetMirroringDisplayById(
908 int64 display_id) const { 909 int64_t display_id) const {
909 auto iter = std::find_if(software_mirroring_display_list_.begin(), 910 auto iter = std::find_if(software_mirroring_display_list_.begin(),
910 software_mirroring_display_list_.end(), 911 software_mirroring_display_list_.end(),
911 [display_id](const gfx::Display& display) { 912 [display_id](const gfx::Display& display) {
912 return display.id() == display_id; 913 return display.id() == display_id;
913 }); 914 });
914 return iter == software_mirroring_display_list_.end() ? gfx::Display() 915 return iter == software_mirroring_display_list_.end() ? gfx::Display()
915 : *iter; 916 : *iter;
916 } 917 }
917 918
918 std::string DisplayManager::GetDisplayNameForId(int64 id) { 919 std::string DisplayManager::GetDisplayNameForId(int64_t id) {
919 if (id == gfx::Display::kInvalidDisplayID) 920 if (id == gfx::Display::kInvalidDisplayID)
920 return l10n_util::GetStringUTF8(IDS_ASH_STATUS_TRAY_UNKNOWN_DISPLAY_NAME); 921 return l10n_util::GetStringUTF8(IDS_ASH_STATUS_TRAY_UNKNOWN_DISPLAY_NAME);
921 922
922 std::map<int64, DisplayInfo>::const_iterator iter = display_info_.find(id); 923 std::map<int64_t, DisplayInfo>::const_iterator iter = display_info_.find(id);
923 if (iter != display_info_.end() && !iter->second.name().empty()) 924 if (iter != display_info_.end() && !iter->second.name().empty())
924 return iter->second.name(); 925 return iter->second.name();
925 926
926 return base::StringPrintf("Display %d", static_cast<int>(id)); 927 return base::StringPrintf("Display %d", static_cast<int>(id));
927 } 928 }
928 929
929 int64 DisplayManager::GetDisplayIdForUIScaling() const { 930 int64_t DisplayManager::GetDisplayIdForUIScaling() const {
930 // UI Scaling is effective on internal display. 931 // UI Scaling is effective on internal display.
931 return gfx::Display::HasInternalDisplay() ? gfx::Display::InternalDisplayId() 932 return gfx::Display::HasInternalDisplay() ? gfx::Display::InternalDisplayId()
932 : gfx::Display::kInvalidDisplayID; 933 : gfx::Display::kInvalidDisplayID;
933 } 934 }
934 935
935 void DisplayManager::SetMirrorMode(bool mirror) { 936 void DisplayManager::SetMirrorMode(bool mirror) {
936 #if defined(OS_CHROMEOS) 937 #if defined(OS_CHROMEOS)
937 if (num_connected_displays() <= 1) 938 if (num_connected_displays() <= 1)
938 return; 939 return;
939 940
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
1031 (display_info_list.size() < 2 && 1032 (display_info_list.size() < 2 &&
1032 iter != software_mirroring_display_list_.end()); 1033 iter != software_mirroring_display_list_.end());
1033 ++iter) { 1034 ++iter) {
1034 display_info_list.push_back(GetDisplayInfo(iter->id())); 1035 display_info_list.push_back(GetDisplayInfo(iter->id()));
1035 } 1036 }
1036 mirroring_display_id_ = gfx::Display::kInvalidDisplayID; 1037 mirroring_display_id_ = gfx::Display::kInvalidDisplayID;
1037 software_mirroring_display_list_.clear(); 1038 software_mirroring_display_list_.clear();
1038 UpdateDisplays(display_info_list); 1039 UpdateDisplays(display_info_list);
1039 } 1040 }
1040 1041
1041 bool DisplayManager::UpdateDisplayBounds(int64 display_id, 1042 bool DisplayManager::UpdateDisplayBounds(int64_t display_id,
1042 const gfx::Rect& new_bounds) { 1043 const gfx::Rect& new_bounds) {
1043 if (change_display_upon_host_resize_) { 1044 if (change_display_upon_host_resize_) {
1044 display_info_[display_id].SetBounds(new_bounds); 1045 display_info_[display_id].SetBounds(new_bounds);
1045 // Don't notify observers if the mirrored window has changed. 1046 // Don't notify observers if the mirrored window has changed.
1046 if (software_mirroring_enabled() && mirroring_display_id_ == display_id) 1047 if (software_mirroring_enabled() && mirroring_display_id_ == display_id)
1047 return false; 1048 return false;
1048 gfx::Display* display = FindDisplayForId(display_id); 1049 gfx::Display* display = FindDisplayForId(display_id);
1049 display->SetSize(display_info_[display_id].size_in_pixel()); 1050 display->SetSize(display_info_[display_id].size_in_pixel());
1050 screen_->NotifyMetricsChanged(*display, 1051 screen_->NotifyMetricsChanged(*display,
1051 gfx::DisplayObserver::DISPLAY_METRIC_BOUNDS); 1052 gfx::DisplayObserver::DISPLAY_METRIC_BOUNDS);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1107 if (display_info_list->size() == 2) { 1108 if (display_info_list->size() == 2) {
1108 switch (multi_display_mode_) { 1109 switch (multi_display_mode_) {
1109 case MIRRORING: { 1110 case MIRRORING: {
1110 bool zero_is_source = 1111 bool zero_is_source =
1111 first_display_id_ == (*display_info_list)[0].id() || 1112 first_display_id_ == (*display_info_list)[0].id() ||
1112 gfx::Display::IsInternalDisplayId((*display_info_list)[0].id()); 1113 gfx::Display::IsInternalDisplayId((*display_info_list)[0].id());
1113 DCHECK_EQ(MIRRORING, multi_display_mode_); 1114 DCHECK_EQ(MIRRORING, multi_display_mode_);
1114 mirroring_display_id_ = 1115 mirroring_display_id_ =
1115 (*display_info_list)[zero_is_source ? 1 : 0].id(); 1116 (*display_info_list)[zero_is_source ? 1 : 0].id();
1116 1117
1117 int64 display_id = mirroring_display_id_; 1118 int64_t display_id = mirroring_display_id_;
1118 auto iter = 1119 auto iter =
1119 std::find_if(display_info_list->begin(), display_info_list->end(), 1120 std::find_if(display_info_list->begin(), display_info_list->end(),
1120 [display_id](const DisplayInfo& info) { 1121 [display_id](const DisplayInfo& info) {
1121 return info.id() == display_id; 1122 return info.id() == display_id;
1122 }); 1123 });
1123 DCHECK(iter != display_info_list->end()); 1124 DCHECK(iter != display_info_list->end());
1124 1125
1125 DisplayInfo info = *iter; 1126 DisplayInfo info = *iter;
1126 info.SetOverscanInsets(gfx::Insets()); 1127 info.SetOverscanInsets(gfx::Insets());
1127 InsertAndUpdateDisplayInfo(info); 1128 InsertAndUpdateDisplayInfo(info);
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
1223 display_info_list->push_back(info); 1224 display_info_list->push_back(info);
1224 InsertAndUpdateDisplayInfo(info); 1225 InsertAndUpdateDisplayInfo(info);
1225 break; 1226 break;
1226 } 1227 }
1227 case EXTENDED: 1228 case EXTENDED:
1228 break; 1229 break;
1229 } 1230 }
1230 } 1231 }
1231 } 1232 }
1232 1233
1233 gfx::Display* DisplayManager::FindDisplayForId(int64 id) { 1234 gfx::Display* DisplayManager::FindDisplayForId(int64_t id) {
1234 auto iter = std::find_if( 1235 auto iter = std::find_if(
1235 active_display_list_.begin(), active_display_list_.end(), 1236 active_display_list_.begin(), active_display_list_.end(),
1236 [id](const gfx::Display& display) { return display.id() == id; }); 1237 [id](const gfx::Display& display) { return display.id() == id; });
1237 if (iter != active_display_list_.end()) 1238 if (iter != active_display_list_.end())
1238 return &(*iter); 1239 return &(*iter);
1239 // TODO(oshima): This happens when a windows in unified desktop have 1240 // TODO(oshima): This happens when a windows in unified desktop have
1240 // been moved to normal window. Fix this. 1241 // been moved to normal window. Fix this.
1241 if (id != kUnifiedDisplayId) 1242 if (id != kUnifiedDisplayId)
1242 DLOG(WARNING) << "Could not find display:" << id; 1243 DLOG(WARNING) << "Could not find display:" << id;
1243 return NULL; 1244 return NULL;
1244 } 1245 }
1245 1246
1246 void DisplayManager::AddMirrorDisplayInfoIfAny( 1247 void DisplayManager::AddMirrorDisplayInfoIfAny(
1247 std::vector<DisplayInfo>* display_info_list) { 1248 std::vector<DisplayInfo>* display_info_list) {
1248 if (software_mirroring_enabled() && IsInMirrorMode()) 1249 if (software_mirroring_enabled() && IsInMirrorMode())
1249 display_info_list->push_back(GetDisplayInfo(mirroring_display_id_)); 1250 display_info_list->push_back(GetDisplayInfo(mirroring_display_id_));
1250 } 1251 }
1251 1252
1252 void DisplayManager::InsertAndUpdateDisplayInfo(const DisplayInfo& new_info) { 1253 void DisplayManager::InsertAndUpdateDisplayInfo(const DisplayInfo& new_info) {
1253 std::map<int64, DisplayInfo>::iterator info = 1254 std::map<int64_t, DisplayInfo>::iterator info =
1254 display_info_.find(new_info.id()); 1255 display_info_.find(new_info.id());
1255 if (info != display_info_.end()) { 1256 if (info != display_info_.end()) {
1256 info->second.Copy(new_info); 1257 info->second.Copy(new_info);
1257 } else { 1258 } else {
1258 display_info_[new_info.id()] = new_info; 1259 display_info_[new_info.id()] = new_info;
1259 display_info_[new_info.id()].set_native(false); 1260 display_info_[new_info.id()].set_native(false);
1260 } 1261 }
1261 display_info_[new_info.id()].UpdateDisplaySize(); 1262 display_info_[new_info.id()].UpdateDisplaySize();
1262 OnDisplayInfoUpdated(display_info_[new_info.id()]); 1263 OnDisplayInfoUpdated(display_info_[new_info.id()]);
1263 } 1264 }
1264 1265
1265 void DisplayManager::OnDisplayInfoUpdated(const DisplayInfo& display_info) { 1266 void DisplayManager::OnDisplayInfoUpdated(const DisplayInfo& display_info) {
1266 #if defined(OS_CHROMEOS) 1267 #if defined(OS_CHROMEOS)
1267 ui::ColorCalibrationProfile color_profile = display_info.color_profile(); 1268 ui::ColorCalibrationProfile color_profile = display_info.color_profile();
1268 if (color_profile != ui::COLOR_PROFILE_STANDARD) { 1269 if (color_profile != ui::COLOR_PROFILE_STANDARD) {
1269 Shell::GetInstance()->display_configurator()->SetColorCalibrationProfile( 1270 Shell::GetInstance()->display_configurator()->SetColorCalibrationProfile(
1270 display_info.id(), color_profile); 1271 display_info.id(), color_profile);
1271 } 1272 }
1272 #endif 1273 #endif
1273 } 1274 }
1274 1275
1275 gfx::Display DisplayManager::CreateDisplayFromDisplayInfoById(int64 id) { 1276 gfx::Display DisplayManager::CreateDisplayFromDisplayInfoById(int64_t id) {
1276 DCHECK(display_info_.find(id) != display_info_.end()) << "id=" << id; 1277 DCHECK(display_info_.find(id) != display_info_.end()) << "id=" << id;
1277 const DisplayInfo& display_info = display_info_[id]; 1278 const DisplayInfo& display_info = display_info_[id];
1278 1279
1279 gfx::Display new_display(display_info.id()); 1280 gfx::Display new_display(display_info.id());
1280 gfx::Rect bounds_in_native(display_info.size_in_pixel()); 1281 gfx::Rect bounds_in_native(display_info.size_in_pixel());
1281 float device_scale_factor = display_info.GetEffectiveDeviceScaleFactor(); 1282 float device_scale_factor = display_info.GetEffectiveDeviceScaleFactor();
1282 1283
1283 // Simply set the origin to (0,0). The primary display's origin is 1284 // Simply set the origin to (0,0). The primary display's origin is
1284 // always (0,0) and the bounds of non-primary display(s) will be updated 1285 // always (0,0) and the bounds of non-primary display(s) will be updated
1285 // in |UpdateNonPrimaryDisplayBoundsForLayout| called in |UpdateDisplay|. 1286 // in |UpdateNonPrimaryDisplayBoundsForLayout| called in |UpdateDisplay|.
1286 new_display.SetScaleAndBounds( 1287 new_display.SetScaleAndBounds(
1287 device_scale_factor, gfx::Rect(bounds_in_native.size())); 1288 device_scale_factor, gfx::Rect(bounds_in_native.size()));
1288 new_display.set_rotation(display_info.GetActiveRotation()); 1289 new_display.set_rotation(display_info.GetActiveRotation());
1289 new_display.set_touch_support(display_info.touch_support()); 1290 new_display.set_touch_support(display_info.touch_support());
1290 return new_display; 1291 return new_display;
1291 } 1292 }
1292 1293
1293 gfx::Display DisplayManager::CreateMirroringDisplayFromDisplayInfoById( 1294 gfx::Display DisplayManager::CreateMirroringDisplayFromDisplayInfoById(
1294 int64 id, 1295 int64_t id,
1295 const gfx::Point& origin, 1296 const gfx::Point& origin,
1296 float scale) { 1297 float scale) {
1297 DCHECK(display_info_.find(id) != display_info_.end()) << "id=" << id; 1298 DCHECK(display_info_.find(id) != display_info_.end()) << "id=" << id;
1298 const DisplayInfo& display_info = display_info_[id]; 1299 const DisplayInfo& display_info = display_info_[id];
1299 1300
1300 gfx::Display new_display(display_info.id()); 1301 gfx::Display new_display(display_info.id());
1301 new_display.SetScaleAndBounds( 1302 new_display.SetScaleAndBounds(
1302 1.0f, gfx::Rect(origin, gfx::ScaleToFlooredSize( 1303 1.0f, gfx::Rect(origin, gfx::ScaleToFlooredSize(
1303 display_info.size_in_pixel(), scale))); 1304 display_info.size_in_pixel(), scale)));
1304 new_display.set_touch_support(display_info.touch_support()); 1305 new_display.set_touch_support(display_info.touch_support());
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
1410 gfx::Rect(new_secondary_origin, secondary_bounds.size())); 1411 gfx::Rect(new_secondary_origin, secondary_bounds.size()));
1411 secondary_display->UpdateWorkAreaFromInsets(insets); 1412 secondary_display->UpdateWorkAreaFromInsets(insets);
1412 } 1413 }
1413 1414
1414 void DisplayManager::RunPendingTasksForTest() { 1415 void DisplayManager::RunPendingTasksForTest() {
1415 if (!software_mirroring_display_list_.empty()) 1416 if (!software_mirroring_display_list_.empty())
1416 base::RunLoop().RunUntilIdle(); 1417 base::RunLoop().RunUntilIdle();
1417 } 1418 }
1418 1419
1419 } // namespace ash 1420 } // namespace ash
OLDNEW
« no previous file with comments | « ash/display/display_manager.h ('k') | ash/display/display_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698