| 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 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 iter != displays_.end(); ++iter) { | 137 iter != displays_.end(); ++iter) { |
| 138 const gfx::Display& display = *iter; | 138 const gfx::Display& display = *iter; |
| 139 if (display.bounds().Contains(point_in_screen)) | 139 if (display.bounds().Contains(point_in_screen)) |
| 140 return display; | 140 return display; |
| 141 } | 141 } |
| 142 return GetInvalidDisplay(); | 142 return GetInvalidDisplay(); |
| 143 } | 143 } |
| 144 | 144 |
| 145 void DisplayManager::SetOverscanInsets(int64 display_id, | 145 void DisplayManager::SetOverscanInsets(int64 display_id, |
| 146 const gfx::Insets& insets_in_dip) { | 146 const gfx::Insets& insets_in_dip) { |
| 147 display_info_[display_id].overscan_insets_in_dip = insets_in_dip; |
| 148 |
| 149 // Copies the |displays_| because UpdateDisplays() compares the passed |
| 150 // displays and its internal |displays_|. |
| 147 DisplayList displays = displays_; | 151 DisplayList displays = displays_; |
| 148 std::map<int64, gfx::Insets>::const_iterator old_overscan = | 152 UpdateDisplays(displays); |
| 149 overscan_mapping_.find(display_id); | |
| 150 if (old_overscan != overscan_mapping_.end()) { | |
| 151 gfx::Insets old_insets = old_overscan->second; | |
| 152 for (DisplayList::iterator iter = displays.begin(); | |
| 153 iter != displays.end(); ++iter) { | |
| 154 if (iter->id() == display_id) { | |
| 155 // Undo the existing insets before applying the new insets. | |
| 156 gfx::Rect bounds = iter->bounds_in_pixel(); | |
| 157 bounds.Inset(old_insets.Scale(-iter->device_scale_factor())); | |
| 158 iter->SetScaleAndBounds(iter->device_scale_factor(), bounds); | |
| 159 break; | |
| 160 } | |
| 161 } | |
| 162 } | |
| 163 overscan_mapping_[display_id] = insets_in_dip; | |
| 164 OnNativeDisplaysChanged(displays); | |
| 165 } | 153 } |
| 166 | 154 |
| 167 gfx::Insets DisplayManager::GetOverscanInsets(int64 display_id) const { | 155 gfx::Insets DisplayManager::GetOverscanInsets(int64 display_id) const { |
| 168 std::map<int64, gfx::Insets>::const_iterator it = | 156 std::map<int64, DisplayInfo>::const_iterator it = |
| 169 overscan_mapping_.find(display_id); | 157 display_info_.find(display_id); |
| 170 return (it != overscan_mapping_.end()) ? it->second : gfx::Insets(); | 158 return (it != display_info_.end()) ? |
| 159 it->second.overscan_insets_in_dip : gfx::Insets(); |
| 171 } | 160 } |
| 172 | 161 |
| 173 void DisplayManager::OnNativeDisplaysChanged( | 162 void DisplayManager::OnNativeDisplaysChanged( |
| 174 const std::vector<gfx::Display>& updated_displays) { | 163 const std::vector<gfx::Display>& updated_displays) { |
| 175 if (updated_displays.empty()) { | 164 if (updated_displays.empty()) { |
| 176 // Don't update the displays when all displays are disconnected. | 165 // Don't update the displays when all displays are disconnected. |
| 177 // This happens when: | 166 // This happens when: |
| 178 // - the device is idle and powerd requested to turn off all displays. | 167 // - the device is idle and powerd requested to turn off all displays. |
| 179 // - the device is suspended. (kernel turns off all displays) | 168 // - the device is suspended. (kernel turns off all displays) |
| 180 // - the internal display's brightness is set to 0 and no external | 169 // - the internal display's brightness is set to 0 and no external |
| (...skipping 23 matching lines...) Expand all Loading... |
| 204 if (!internal_display_.get()) { | 193 if (!internal_display_.get()) { |
| 205 internal_display_.reset(new gfx::Display(internal_display_id_, | 194 internal_display_.reset(new gfx::Display(internal_display_id_, |
| 206 gfx::Rect(800, 600))); | 195 gfx::Rect(800, 600))); |
| 207 } | 196 } |
| 208 new_displays.push_back(*internal_display_.get()); | 197 new_displays.push_back(*internal_display_.get()); |
| 209 } | 198 } |
| 210 } else { | 199 } else { |
| 211 new_displays = updated_displays; | 200 new_displays = updated_displays; |
| 212 } | 201 } |
| 213 | 202 |
| 203 for (DisplayList::const_iterator iter = new_displays.begin(); |
| 204 iter != new_displays.end(); ++iter) { |
| 205 std::map<int64, DisplayInfo>::iterator info = |
| 206 display_info_.find(iter->id()); |
| 207 if (info != display_info_.end()) { |
| 208 info->second.original_bounds_in_pixel = iter->bounds_in_pixel(); |
| 209 } else { |
| 210 display_info_[iter->id()].original_bounds_in_pixel = |
| 211 iter->bounds_in_pixel(); |
| 212 } |
| 213 } |
| 214 |
| 215 UpdateDisplays(new_displays); |
| 216 RefreshDisplayNames(); |
| 217 } |
| 218 |
| 219 void DisplayManager::UpdateDisplays( |
| 220 const std::vector<gfx::Display>& updated_displays) { |
| 221 DisplayList new_displays = updated_displays; |
| 222 |
| 214 for (DisplayList::iterator iter = new_displays.begin(); | 223 for (DisplayList::iterator iter = new_displays.begin(); |
| 215 iter != new_displays.end(); ++iter) { | 224 iter != new_displays.end(); ++iter) { |
| 216 std::map<int64, gfx::Insets>::const_iterator overscan_insets = | 225 std::map<int64, DisplayInfo>::const_iterator info = |
| 217 overscan_mapping_.find(iter->id()); | 226 display_info_.find(iter->id()); |
| 218 if (overscan_insets != overscan_mapping_.end()) { | 227 if (info != display_info_.end()) { |
| 219 gfx::Rect bounds = iter->bounds_in_pixel(); | 228 gfx::Rect bounds = info->second.original_bounds_in_pixel; |
| 220 bounds.Inset(overscan_insets->second.Scale(iter->device_scale_factor())); | 229 bounds.Inset(info->second.overscan_insets_in_dip.Scale( |
| 230 iter->device_scale_factor())); |
| 221 iter->SetScaleAndBounds(iter->device_scale_factor(), bounds); | 231 iter->SetScaleAndBounds(iter->device_scale_factor(), bounds); |
| 222 } | 232 } |
| 223 } | 233 } |
| 224 | 234 |
| 225 std::sort(displays_.begin(), displays_.end(), DisplaySortFunctor()); | 235 std::sort(displays_.begin(), displays_.end(), DisplaySortFunctor()); |
| 226 std::sort(new_displays.begin(), new_displays.end(), DisplaySortFunctor()); | 236 std::sort(new_displays.begin(), new_displays.end(), DisplaySortFunctor()); |
| 227 DisplayList removed_displays; | 237 DisplayList removed_displays; |
| 228 std::vector<size_t> changed_display_indices; | 238 std::vector<size_t> changed_display_indices; |
| 229 std::vector<size_t> added_display_indices; | 239 std::vector<size_t> added_display_indices; |
| 230 gfx::Display current_primary; | 240 gfx::Display current_primary; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 | 284 |
| 275 // Do not update |displays_| if there's nothing to be updated. Without this, | 285 // Do not update |displays_| if there's nothing to be updated. Without this, |
| 276 // it will not update the display layout, which causes the bug | 286 // it will not update the display layout, which causes the bug |
| 277 // http://crbug.com/155948. | 287 // http://crbug.com/155948. |
| 278 if (changed_display_indices.empty() && added_display_indices.empty() && | 288 if (changed_display_indices.empty() && added_display_indices.empty() && |
| 279 removed_displays.empty()) { | 289 removed_displays.empty()) { |
| 280 return; | 290 return; |
| 281 } | 291 } |
| 282 | 292 |
| 283 displays_ = new_displays; | 293 displays_ = new_displays; |
| 284 RefreshDisplayNames(); | |
| 285 | 294 |
| 286 // Temporarily add displays to be removed because display object | 295 // Temporarily add displays to be removed because display object |
| 287 // being removed are accessed during shutting down the root. | 296 // being removed are accessed during shutting down the root. |
| 288 displays_.insert(displays_.end(), removed_displays.begin(), | 297 displays_.insert(displays_.end(), removed_displays.begin(), |
| 289 removed_displays.end()); | 298 removed_displays.end()); |
| 290 for (std::vector<size_t>::iterator iter = changed_display_indices.begin(); | 299 for (std::vector<size_t>::iterator iter = changed_display_indices.begin(); |
| 291 iter != changed_display_indices.end(); ++iter) { | 300 iter != changed_display_indices.end(); ++iter) { |
| 292 Shell::GetInstance()->screen()->NotifyBoundsChanged(displays_[*iter]); | 301 Shell::GetInstance()->screen()->NotifyBoundsChanged(displays_[*iter]); |
| 293 } | 302 } |
| 294 for (std::vector<size_t>::iterator iter = added_display_indices.begin(); | 303 for (std::vector<size_t>::iterator iter = added_display_indices.begin(); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 } | 381 } |
| 373 // Fallback to the primary display if there is no matching display. | 382 // Fallback to the primary display if there is no matching display. |
| 374 return matching ? *matching : DisplayController::GetPrimaryDisplay(); | 383 return matching ? *matching : DisplayController::GetPrimaryDisplay(); |
| 375 } | 384 } |
| 376 | 385 |
| 377 std::string DisplayManager::GetDisplayNameFor( | 386 std::string DisplayManager::GetDisplayNameFor( |
| 378 const gfx::Display& display) { | 387 const gfx::Display& display) { |
| 379 if (!display.is_valid()) | 388 if (!display.is_valid()) |
| 380 return l10n_util::GetStringUTF8(IDS_ASH_STATUS_TRAY_UNKNOWN_DISPLAY_NAME); | 389 return l10n_util::GetStringUTF8(IDS_ASH_STATUS_TRAY_UNKNOWN_DISPLAY_NAME); |
| 381 | 390 |
| 382 std::map<int64, std::string>::const_iterator iter = | 391 std::map<int64, DisplayInfo>::const_iterator iter = |
| 383 display_names_.find(display.id()); | 392 display_info_.find(display.id()); |
| 384 if (iter != display_names_.end()) | 393 if (iter != display_info_.end()) |
| 385 return iter->second; | 394 return iter->second.name; |
| 386 | 395 |
| 387 return base::StringPrintf("Display %d", static_cast<int>(display.id())); | 396 return base::StringPrintf("Display %d", static_cast<int>(display.id())); |
| 388 } | 397 } |
| 389 | 398 |
| 390 void DisplayManager::OnRootWindowResized(const aura::RootWindow* root, | 399 void DisplayManager::OnRootWindowResized(const aura::RootWindow* root, |
| 391 const gfx::Size& old_size) { | 400 const gfx::Size& old_size) { |
| 392 if (!aura::UseFullscreenHostWindow()) { | 401 if (!aura::UseFullscreenHostWindow()) { |
| 393 gfx::Display& display = FindDisplayForRootWindow(root); | 402 gfx::Display& display = FindDisplayForRootWindow(root); |
| 394 if (display.size() != root->GetHostSize()) { | 403 if (display.size() != root->GetHostSize()) { |
| 395 display.SetSize(root->GetHostSize()); | 404 display.SetSize(root->GetHostSize()); |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 528 | 537 |
| 529 aura::RootWindow* root_window = Shell::GetPrimaryRootWindow(); | 538 aura::RootWindow* root_window = Shell::GetPrimaryRootWindow(); |
| 530 aura::client::ScreenPositionClient* client = | 539 aura::client::ScreenPositionClient* client = |
| 531 aura::client::GetScreenPositionClient(root_window); | 540 aura::client::GetScreenPositionClient(root_window); |
| 532 client->ConvertPointFromScreen(root_window, &target_location); | 541 client->ConvertPointFromScreen(root_window, &target_location); |
| 533 | 542 |
| 534 root_window->MoveCursorTo(target_location); | 543 root_window->MoveCursorTo(target_location); |
| 535 } | 544 } |
| 536 | 545 |
| 537 void DisplayManager::RefreshDisplayNames() { | 546 void DisplayManager::RefreshDisplayNames() { |
| 538 display_names_.clear(); | |
| 539 | |
| 540 #if defined(OS_CHROMEOS) | 547 #if defined(OS_CHROMEOS) |
| 541 if (!base::chromeos::IsRunningOnChromeOS()) | 548 if (!base::chromeos::IsRunningOnChromeOS()) |
| 542 return; | 549 return; |
| 543 #endif | 550 #endif |
| 544 | 551 |
| 545 #if defined(USE_X11) | 552 #if defined(USE_X11) |
| 546 std::vector<XID> outputs; | 553 std::vector<XID> outputs; |
| 547 if (!ui::GetOutputDeviceHandles(&outputs)) | 554 if (!ui::GetOutputDeviceHandles(&outputs)) |
| 548 return; | 555 return; |
| 549 | 556 |
| 550 for (size_t i = 0; i < outputs.size(); ++i) { | 557 for (size_t i = 0; i < outputs.size(); ++i) { |
| 551 uint16 manufacturer_id = 0; | 558 uint16 manufacturer_id = 0; |
| 552 uint32 serial_number = 0; | 559 uint32 serial_number = 0; |
| 553 std::string name; | 560 std::string name; |
| 554 if (ui::GetOutputDeviceData( | 561 if (ui::GetOutputDeviceData( |
| 555 outputs[i], &manufacturer_id, &serial_number, &name)) { | 562 outputs[i], &manufacturer_id, &serial_number, &name)) { |
| 556 int64 id = gfx::Display::GetID(manufacturer_id, serial_number); | 563 int64 id = gfx::Display::GetID(manufacturer_id, serial_number); |
| 557 if (IsInternalDisplayId(id)) { | 564 if (IsInternalDisplayId(id)) { |
| 558 display_names_[id] = | 565 display_info_[id].name = |
| 559 l10n_util::GetStringUTF8(IDS_ASH_INTERNAL_DISPLAY_NAME); | 566 l10n_util::GetStringUTF8(IDS_ASH_INTERNAL_DISPLAY_NAME); |
| 560 } else { | 567 } else { |
| 561 display_names_[id] = name; | 568 display_info_[id].name = name; |
| 562 } | 569 } |
| 563 } | 570 } |
| 564 } | 571 } |
| 565 #endif | 572 #endif |
| 566 } | 573 } |
| 567 | 574 |
| 568 void DisplayManager::SetDisplayIdsForTest(DisplayList* to_update) const { | 575 void DisplayManager::SetDisplayIdsForTest(DisplayList* to_update) const { |
| 569 DisplayList::iterator iter_to_update = to_update->begin(); | 576 DisplayList::iterator iter_to_update = to_update->begin(); |
| 570 DisplayList::const_iterator iter = displays_.begin(); | 577 DisplayList::const_iterator iter = displays_.begin(); |
| 571 for (; iter != displays_.end() && iter_to_update != to_update->end(); | 578 for (; iter != displays_.end() && iter_to_update != to_update->end(); |
| 572 ++iter, ++iter_to_update) { | 579 ++iter, ++iter_to_update) { |
| 573 (*iter_to_update).set_id((*iter).id()); | 580 (*iter_to_update).set_id((*iter).id()); |
| 574 } | 581 } |
| 575 } | 582 } |
| 576 | 583 |
| 577 } // namespace internal | 584 } // namespace internal |
| 578 } // namespace ash | 585 } // namespace ash |
| OLD | NEW |