| 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 <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "ash/display/display_controller.h" | 10 #include "ash/display/display_controller.h" |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 | 84 |
| 85 using aura::RootWindow; | 85 using aura::RootWindow; |
| 86 using aura::Window; | 86 using aura::Window; |
| 87 using std::string; | 87 using std::string; |
| 88 using std::vector; | 88 using std::vector; |
| 89 | 89 |
| 90 DEFINE_WINDOW_PROPERTY_KEY(int64, kDisplayIdKey, | 90 DEFINE_WINDOW_PROPERTY_KEY(int64, kDisplayIdKey, |
| 91 gfx::Display::kInvalidDisplayID); | 91 gfx::Display::kInvalidDisplayID); |
| 92 | 92 |
| 93 DisplayManager::DisplayManager() : | 93 DisplayManager::DisplayManager() : |
| 94 internal_display_id_(gfx::Display::kInvalidDisplayID), | |
| 95 force_bounds_changed_(false) { | 94 force_bounds_changed_(false) { |
| 96 Init(); | 95 Init(); |
| 97 } | 96 } |
| 98 | 97 |
| 99 DisplayManager::~DisplayManager() { | 98 DisplayManager::~DisplayManager() { |
| 100 } | 99 } |
| 101 | 100 |
| 102 // static | 101 // static |
| 103 void DisplayManager::CycleDisplay() { | 102 void DisplayManager::CycleDisplay() { |
| 104 Shell::GetInstance()->display_manager()->CycleDisplayImpl(); | 103 Shell::GetInstance()->display_manager()->CycleDisplayImpl(); |
| 105 } | 104 } |
| 106 | 105 |
| 107 // static | 106 // static |
| 108 void DisplayManager::ToggleDisplayScale() { | 107 void DisplayManager::ToggleDisplayScale() { |
| 109 Shell::GetInstance()->display_manager()->ScaleDisplayImpl(); | 108 Shell::GetInstance()->display_manager()->ScaleDisplayImpl(); |
| 110 } | 109 } |
| 111 | 110 |
| 112 bool DisplayManager::IsActiveDisplay(const gfx::Display& display) const { | 111 bool DisplayManager::IsActiveDisplay(const gfx::Display& display) const { |
| 113 for (DisplayList::const_iterator iter = displays_.begin(); | 112 for (DisplayList::const_iterator iter = displays_.begin(); |
| 114 iter != displays_.end(); ++iter) { | 113 iter != displays_.end(); ++iter) { |
| 115 if ((*iter).id() == display.id()) | 114 if ((*iter).id() == display.id()) |
| 116 return true; | 115 return true; |
| 117 } | 116 } |
| 118 return false; | 117 return false; |
| 119 } | 118 } |
| 120 | 119 |
| 121 bool DisplayManager::HasInternalDisplay() const { | 120 bool DisplayManager::HasInternalDisplay() const { |
| 122 return internal_display_id_ != gfx::Display::kInvalidDisplayID; | 121 return gfx::Display::internal_display_id() != gfx::Display::kInvalidDisplayID; |
| 123 } | 122 } |
| 124 | 123 |
| 125 bool DisplayManager::IsInternalDisplayId(int64 id) const { | 124 bool DisplayManager::IsInternalDisplayId(int64 id) const { |
| 126 return internal_display_id_ == id; | 125 return gfx::Display::internal_display_id() == id; |
| 127 } | 126 } |
| 128 | 127 |
| 129 bool DisplayManager::UpdateWorkAreaOfDisplayNearestWindow( | 128 bool DisplayManager::UpdateWorkAreaOfDisplayNearestWindow( |
| 130 const aura::Window* window, | 129 const aura::Window* window, |
| 131 const gfx::Insets& insets) { | 130 const gfx::Insets& insets) { |
| 132 const RootWindow* root = window->GetRootWindow(); | 131 const RootWindow* root = window->GetRootWindow(); |
| 133 gfx::Display& display = FindDisplayForRootWindow(root); | 132 gfx::Display& display = FindDisplayForRootWindow(root); |
| 134 gfx::Rect old_work_area = display.work_area(); | 133 gfx::Rect old_work_area = display.work_area(); |
| 135 display.UpdateWorkAreaFromInsets(insets); | 134 display.UpdateWorkAreaFromInsets(insets); |
| 136 return old_work_area != display.work_area(); | 135 return old_work_area != display.work_area(); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 // - the device is suspended. (kernel turns off all displays) | 177 // - the device is suspended. (kernel turns off all displays) |
| 179 // - the internal display's brightness is set to 0 and no external | 178 // - the internal display's brightness is set to 0 and no external |
| 180 // display is connected. | 179 // display is connected. |
| 181 // - the internal display's brightness is 0 and external display is | 180 // - the internal display's brightness is 0 and external display is |
| 182 // disconnected. | 181 // disconnected. |
| 183 // The display will be updated when one of displays is turned on, and the | 182 // The display will be updated when one of displays is turned on, and the |
| 184 // display list will be updated correctly. | 183 // display list will be updated correctly. |
| 185 return; | 184 return; |
| 186 } | 185 } |
| 187 DisplayList new_displays = updated_displays; | 186 DisplayList new_displays = updated_displays; |
| 188 if (internal_display_id_ != gfx::Display::kInvalidDisplayID) { | 187 if (HasInternalDisplay()) { |
| 189 bool internal_display_connected = false; | 188 bool internal_display_connected = false; |
| 190 for (DisplayList::const_iterator iter = updated_displays.begin(); | 189 for (DisplayList::const_iterator iter = updated_displays.begin(); |
| 191 iter != updated_displays.end(); ++iter) { | 190 iter != updated_displays.end(); ++iter) { |
| 192 if ((*iter).id() == internal_display_id_) { | 191 if ((*iter).is_internal()) { |
| 193 internal_display_connected = true; | 192 internal_display_connected = true; |
| 194 // Update the internal display cache. | 193 // Update the internal display cache. |
| 195 internal_display_.reset(new gfx::Display); | 194 internal_display_.reset(new gfx::Display); |
| 196 *internal_display_.get() = *iter; | 195 *internal_display_.get() = *iter; |
| 197 break; | 196 break; |
| 198 } | 197 } |
| 199 } | 198 } |
| 200 // If the internal display wasn't connected, use the cached value. | 199 // If the internal display wasn't connected, use the cached value. |
| 201 if (!internal_display_connected) { | 200 if (!internal_display_connected) { |
| 202 // Internal display may be reported as disconnect during startup time. | 201 // Internal display may be reported as disconnect during startup time. |
| 203 if (!internal_display_.get()) { | 202 if (!internal_display_.get()) { |
| 204 internal_display_.reset(new gfx::Display(internal_display_id_, | 203 internal_display_.reset( |
| 205 gfx::Rect(800, 600))); | 204 new gfx::Display(gfx::Display::internal_display_id(), |
| 205 gfx::Rect(800, 600))); |
| 206 } | 206 } |
| 207 new_displays.push_back(*internal_display_.get()); | 207 new_displays.push_back(*internal_display_.get()); |
| 208 } | 208 } |
| 209 } else { | 209 } else { |
| 210 new_displays = updated_displays; | 210 new_displays = updated_displays; |
| 211 } | 211 } |
| 212 | 212 |
| 213 RefreshDisplayInfo(); | 213 RefreshDisplayInfo(); |
| 214 | 214 |
| 215 for (DisplayList::const_iterator iter = new_displays.begin(); | 215 for (DisplayList::const_iterator iter = new_displays.begin(); |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 | 434 |
| 435 void DisplayManager::Init() { | 435 void DisplayManager::Init() { |
| 436 #if defined(OS_CHROMEOS) | 436 #if defined(OS_CHROMEOS) |
| 437 if (base::chromeos::IsRunningOnChromeOS()) { | 437 if (base::chromeos::IsRunningOnChromeOS()) { |
| 438 std::vector<XID> outputs; | 438 std::vector<XID> outputs; |
| 439 ui::GetOutputDeviceHandles(&outputs); | 439 ui::GetOutputDeviceHandles(&outputs); |
| 440 std::vector<std::string> output_names = ui::GetOutputNames(outputs); | 440 std::vector<std::string> output_names = ui::GetOutputNames(outputs); |
| 441 for (size_t i = 0; i < output_names.size(); ++i) { | 441 for (size_t i = 0; i < output_names.size(); ++i) { |
| 442 if (chromeos::OutputConfigurator::IsInternalOutputName( | 442 if (chromeos::OutputConfigurator::IsInternalOutputName( |
| 443 output_names[i])) { | 443 output_names[i])) { |
| 444 internal_display_id_ = GetDisplayIdForOutput(outputs[i], i); | 444 gfx::Display::set_internal_display_id( |
| 445 GetDisplayIdForOutput(outputs[i], i)); |
| 445 break; | 446 break; |
| 446 } | 447 } |
| 447 } | 448 } |
| 448 } | 449 } |
| 449 #endif | 450 #endif |
| 450 | 451 |
| 451 RefreshDisplayInfo(); | 452 RefreshDisplayInfo(); |
| 452 | 453 |
| 453 #if defined(OS_WIN) | 454 #if defined(OS_WIN) |
| 454 if (base::win::GetVersion() >= base::win::VERSION_WIN8) | 455 if (base::win::GetVersion() >= base::win::VERSION_WIN8) |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 gfx::Display display = aura::CreateDisplayFromSpec(spec); | 524 gfx::Display display = aura::CreateDisplayFromSpec(spec); |
| 524 | 525 |
| 525 const gfx::Insets insets = display.GetWorkAreaInsets(); | 526 const gfx::Insets insets = display.GetWorkAreaInsets(); |
| 526 const gfx::Rect& native_bounds = display.bounds_in_pixel(); | 527 const gfx::Rect& native_bounds = display.bounds_in_pixel(); |
| 527 display.SetScaleAndBounds(display.device_scale_factor(), native_bounds); | 528 display.SetScaleAndBounds(display.device_scale_factor(), native_bounds); |
| 528 display.UpdateWorkAreaFromInsets(insets); | 529 display.UpdateWorkAreaFromInsets(insets); |
| 529 displays_.push_back(display); | 530 displays_.push_back(display); |
| 530 } | 531 } |
| 531 | 532 |
| 532 int64 DisplayManager::SetFirstDisplayAsInternalDisplayForTest() { | 533 int64 DisplayManager::SetFirstDisplayAsInternalDisplayForTest() { |
| 533 internal_display_id_ = displays_[0].id(); | 534 gfx::Display::set_internal_display_id(displays_[0].id()); |
| 534 internal_display_.reset(new gfx::Display); | 535 internal_display_.reset(new gfx::Display); |
| 535 *internal_display_ = displays_[0]; | 536 *internal_display_ = displays_[0]; |
| 536 return internal_display_id_; | 537 return gfx::Display::internal_display_id(); |
| 538 } |
| 539 |
| 540 void DisplayManager::ResetInternalDisplayForTest() { |
| 541 gfx::Display::set_internal_display_id(gfx::Display::kInvalidDisplayID); |
| 537 } | 542 } |
| 538 | 543 |
| 539 void DisplayManager::EnsurePointerInDisplays() { | 544 void DisplayManager::EnsurePointerInDisplays() { |
| 540 // Don't try to move the pointer during the boot/startup. | 545 // Don't try to move the pointer during the boot/startup. |
| 541 if (!DisplayController::HasPrimaryDisplay()) | 546 if (!DisplayController::HasPrimaryDisplay()) |
| 542 return; | 547 return; |
| 543 gfx::Point location_in_screen = Shell::GetScreen()->GetCursorScreenPoint(); | 548 gfx::Point location_in_screen = Shell::GetScreen()->GetCursorScreenPoint(); |
| 544 gfx::Point target_location; | 549 gfx::Point target_location; |
| 545 int64 closest_distance_squared = -1; | 550 int64 closest_distance_squared = -1; |
| 546 | 551 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 618 (*iter_to_update).set_id((*iter).id()); | 623 (*iter_to_update).set_id((*iter).id()); |
| 619 } | 624 } |
| 620 } | 625 } |
| 621 | 626 |
| 622 void DisplayManager::SetHasOverscanFlagForTest(int64 id, bool has_overscan) { | 627 void DisplayManager::SetHasOverscanFlagForTest(int64 id, bool has_overscan) { |
| 623 display_info_[id].has_overscan = has_overscan; | 628 display_info_[id].has_overscan = has_overscan; |
| 624 } | 629 } |
| 625 | 630 |
| 626 } // namespace internal | 631 } // namespace internal |
| 627 } // namespace ash | 632 } // namespace ash |
| OLD | NEW |