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/multi_display_manager.h" | 5 #include "ash/display/multi_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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
119 const aura::Window* window, | 119 const aura::Window* window, |
120 const gfx::Insets& insets) { | 120 const gfx::Insets& insets) { |
121 const RootWindow* root = window->GetRootWindow(); | 121 const RootWindow* root = window->GetRootWindow(); |
122 gfx::Display& display = FindDisplayForRootWindow(root); | 122 gfx::Display& display = FindDisplayForRootWindow(root); |
123 gfx::Rect old_work_area = display.work_area(); | 123 gfx::Rect old_work_area = display.work_area(); |
124 display.UpdateWorkAreaFromInsets(insets); | 124 display.UpdateWorkAreaFromInsets(insets); |
125 return old_work_area != display.work_area(); | 125 return old_work_area != display.work_area(); |
126 } | 126 } |
127 | 127 |
128 const gfx::Display& MultiDisplayManager::GetDisplayForId(int64 id) const { | 128 const gfx::Display& MultiDisplayManager::GetDisplayForId(int64 id) const { |
129 for (DisplayList::const_iterator iter = displays_.begin(); | 129 return const_cast<MultiDisplayManager*>(this)->FindDisplayForId(id); |
130 iter != displays_.end(); ++iter) { | |
131 if ((*iter).id() == id) | |
132 return *iter; | |
133 } | |
134 VLOG(1) << "display not found for id:" << id; | |
135 return GetInvalidDisplay(); | |
136 } | 130 } |
137 | 131 |
138 const gfx::Display& MultiDisplayManager::FindDisplayContainingPoint( | 132 const gfx::Display& MultiDisplayManager::FindDisplayContainingPoint( |
139 const gfx::Point& point_in_screen) const { | 133 const gfx::Point& point_in_screen) const { |
140 for (DisplayList::const_iterator iter = displays_.begin(); | 134 for (DisplayList::const_iterator iter = displays_.begin(); |
141 iter != displays_.end(); ++iter) { | 135 iter != displays_.end(); ++iter) { |
142 const gfx::Display& display = *iter; | 136 const gfx::Display& display = *iter; |
143 if (display.bounds().Contains(point_in_screen)) | 137 if (display.bounds().Contains(point_in_screen)) |
144 return display; | 138 return display; |
145 } | 139 } |
146 return GetInvalidDisplay(); | 140 return GetInvalidDisplay(); |
147 } | 141 } |
148 | 142 |
149 void MultiDisplayManager::SetOverscanInsets(int64 display_id, | 143 void MultiDisplayManager::SetOverscanInsets(int64 display_id, |
150 const gfx::Insets& insets_in_dip) { | 144 const gfx::Insets& insets_in_dip) { |
145 std::map<int64, gfx::Insets>::const_iterator old_overscan = | |
146 overscan_mapping_.find(display_id); | |
147 if (old_overscan != overscan_mapping_.end()) { | |
148 gfx::Insets old_insets = old_overscan->second; | |
149 gfx::Display& display = FindDisplayForId(display_id); | |
150 if (display.is_valid()) { | |
151 // Reimburse the existing insets before applying the new insets. | |
Daniel Erat
2012/10/17 18:46:21
"Undo" might be clearer than "Reimburse" here
Jun Mukai
2012/10/17 20:54:39
Done.
| |
152 gfx::Rect bounds = display.bounds_in_pixel(); | |
153 bounds.Inset(old_insets.Scale(-display.device_scale_factor())); | |
154 display.SetScaleAndBounds(display.device_scale_factor(), bounds); | |
155 } | |
156 } | |
151 overscan_mapping_[display_id] = insets_in_dip; | 157 overscan_mapping_[display_id] = insets_in_dip; |
152 OnNativeDisplaysChanged(displays_); | 158 OnNativeDisplaysChanged(displays_); |
153 } | 159 } |
154 | 160 |
155 void MultiDisplayManager::OnNativeDisplaysChanged( | 161 void MultiDisplayManager::OnNativeDisplaysChanged( |
156 const std::vector<gfx::Display>& updated_displays) { | 162 const std::vector<gfx::Display>& updated_displays) { |
157 if (updated_displays.empty()) { | 163 if (updated_displays.empty()) { |
158 // Don't update the displays when all displays are disconnected. | 164 // Don't update the displays when all displays are disconnected. |
159 // This happens when: | 165 // This happens when: |
160 // - the device is idle and powerd requested to turn off all displays. | 166 // - the device is idle and powerd requested to turn off all displays. |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
430 new_displays.push_back(display); | 436 new_displays.push_back(display); |
431 } | 437 } |
432 OnNativeDisplaysChanged(new_displays); | 438 OnNativeDisplaysChanged(new_displays); |
433 } | 439 } |
434 | 440 |
435 gfx::Display& MultiDisplayManager::FindDisplayForRootWindow( | 441 gfx::Display& MultiDisplayManager::FindDisplayForRootWindow( |
436 const aura::RootWindow* root_window) { | 442 const aura::RootWindow* root_window) { |
437 int64 id = root_window->GetProperty(kDisplayIdKey); | 443 int64 id = root_window->GetProperty(kDisplayIdKey); |
438 // if id is |kInvaildDisplayID|, it's being deleted. | 444 // if id is |kInvaildDisplayID|, it's being deleted. |
439 DCHECK(id != gfx::Display::kInvalidDisplayID); | 445 DCHECK(id != gfx::Display::kInvalidDisplayID); |
440 return FindDisplayForId(id); | 446 gfx::Display& display = FindDisplayForId(id); |
447 DCHECK(display.is_valid()); | |
448 return display; | |
441 } | 449 } |
442 | 450 |
443 gfx::Display& MultiDisplayManager::FindDisplayForId(int64 id) { | 451 gfx::Display& MultiDisplayManager::FindDisplayForId(int64 id) { |
444 for (DisplayList::iterator iter = displays_.begin(); | 452 for (DisplayList::iterator iter = displays_.begin(); |
445 iter != displays_.end(); ++iter) { | 453 iter != displays_.end(); ++iter) { |
446 if ((*iter).id() == id) | 454 if ((*iter).id() == id) |
447 return *iter; | 455 return *iter; |
448 } | 456 } |
449 DLOG(FATAL) << "Could not find display:" << id; | 457 DLOG(WARNING) << "Could not find display:" << id; |
450 return GetInvalidDisplay(); | 458 return GetInvalidDisplay(); |
451 } | 459 } |
452 | 460 |
453 void MultiDisplayManager::AddDisplayFromSpec(const std::string& spec) { | 461 void MultiDisplayManager::AddDisplayFromSpec(const std::string& spec) { |
454 gfx::Display display = CreateDisplayFromSpec(spec); | 462 gfx::Display display = CreateDisplayFromSpec(spec); |
455 | 463 |
456 const gfx::Insets insets = display.GetWorkAreaInsets(); | 464 const gfx::Insets insets = display.GetWorkAreaInsets(); |
457 const gfx::Rect& native_bounds = display.bounds_in_pixel(); | 465 const gfx::Rect& native_bounds = display.bounds_in_pixel(); |
458 display.SetScaleAndBounds(display.device_scale_factor(), native_bounds); | 466 display.SetScaleAndBounds(display.device_scale_factor(), native_bounds); |
459 display.UpdateWorkAreaFromInsets(insets); | 467 display.UpdateWorkAreaFromInsets(insets); |
(...skipping 11 matching lines...) Expand all Loading... | |
471 DisplayList::iterator iter_to_update = to_update->begin(); | 479 DisplayList::iterator iter_to_update = to_update->begin(); |
472 DisplayList::const_iterator iter = displays_.begin(); | 480 DisplayList::const_iterator iter = displays_.begin(); |
473 for (; iter != displays_.end() && iter_to_update != to_update->end(); | 481 for (; iter != displays_.end() && iter_to_update != to_update->end(); |
474 ++iter, ++iter_to_update) { | 482 ++iter, ++iter_to_update) { |
475 (*iter_to_update).set_id((*iter).id()); | 483 (*iter_to_update).set_id((*iter).id()); |
476 } | 484 } |
477 } | 485 } |
478 | 486 |
479 } // namespace internal | 487 } // namespace internal |
480 } // namespace ash | 488 } // namespace ash |
OLD | NEW |