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