| 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 #if defined(OS_CHROMEOS) | 65 #if defined(OS_CHROMEOS) |
| 66 int64 GetDisplayIdForOutput(XID output) { | 66 int64 GetDisplayIdForOutput(XID output) { |
| 67 uint16 manufacturer_id = 0; | 67 uint16 manufacturer_id = 0; |
| 68 uint32 serial_number = 0; | 68 uint32 serial_number = 0; |
| 69 ui::GetOutputDeviceData( | 69 ui::GetOutputDeviceData( |
| 70 output, &manufacturer_id, &serial_number, NULL); | 70 output, &manufacturer_id, &serial_number, NULL); |
| 71 return gfx::Display::GetID(manufacturer_id, serial_number); | 71 return gfx::Display::GetID(manufacturer_id, serial_number); |
| 72 } | 72 } |
| 73 #endif | 73 #endif |
| 74 | 74 |
| 75 gfx::Insets GetDefaultDisplayOverscan(const gfx::Display& display) { |
| 76 // Currently we assume 5% overscan and hope for the best if TV claims it |
| 77 // overscan, but doesn't expose how much. |
| 78 int width = display.bounds().width() / 40; |
| 79 int height = display.bounds().height() / 40; |
| 80 return gfx::Insets(height, width, height, width); |
| 81 } |
| 82 |
| 75 } // namespace | 83 } // namespace |
| 76 | 84 |
| 77 using aura::RootWindow; | 85 using aura::RootWindow; |
| 78 using aura::Window; | 86 using aura::Window; |
| 79 using std::string; | 87 using std::string; |
| 80 using std::vector; | 88 using std::vector; |
| 81 | 89 |
| 82 DEFINE_WINDOW_PROPERTY_KEY(int64, kDisplayIdKey, | 90 DEFINE_WINDOW_PROPERTY_KEY(int64, kDisplayIdKey, |
| 83 gfx::Display::kInvalidDisplayID); | 91 gfx::Display::kInvalidDisplayID); |
| 84 | 92 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 const gfx::Display& display = *iter; | 147 const gfx::Display& display = *iter; |
| 140 if (display.bounds().Contains(point_in_screen)) | 148 if (display.bounds().Contains(point_in_screen)) |
| 141 return display; | 149 return display; |
| 142 } | 150 } |
| 143 return GetInvalidDisplay(); | 151 return GetInvalidDisplay(); |
| 144 } | 152 } |
| 145 | 153 |
| 146 void DisplayManager::SetOverscanInsets(int64 display_id, | 154 void DisplayManager::SetOverscanInsets(int64 display_id, |
| 147 const gfx::Insets& insets_in_dip) { | 155 const gfx::Insets& insets_in_dip) { |
| 148 display_info_[display_id].overscan_insets_in_dip = insets_in_dip; | 156 display_info_[display_id].overscan_insets_in_dip = insets_in_dip; |
| 157 display_info_[display_id].has_custom_overscan_insets = true; |
| 149 | 158 |
| 150 // Copies the |displays_| because UpdateDisplays() compares the passed | 159 // Copies the |displays_| because UpdateDisplays() compares the passed |
| 151 // displays and its internal |displays_|. | 160 // displays and its internal |displays_|. |
| 152 DisplayList displays = displays_; | 161 DisplayList displays = displays_; |
| 153 UpdateDisplays(displays); | 162 UpdateDisplays(displays); |
| 154 } | 163 } |
| 155 | 164 |
| 156 gfx::Insets DisplayManager::GetOverscanInsets(int64 display_id) const { | 165 gfx::Insets DisplayManager::GetOverscanInsets(int64 display_id) const { |
| 157 std::map<int64, DisplayInfo>::const_iterator it = | 166 std::map<int64, DisplayInfo>::const_iterator it = |
| 158 display_info_.find(display_id); | 167 display_info_.find(display_id); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 if (!internal_display_.get()) { | 203 if (!internal_display_.get()) { |
| 195 internal_display_.reset(new gfx::Display(internal_display_id_, | 204 internal_display_.reset(new gfx::Display(internal_display_id_, |
| 196 gfx::Rect(800, 600))); | 205 gfx::Rect(800, 600))); |
| 197 } | 206 } |
| 198 new_displays.push_back(*internal_display_.get()); | 207 new_displays.push_back(*internal_display_.get()); |
| 199 } | 208 } |
| 200 } else { | 209 } else { |
| 201 new_displays = updated_displays; | 210 new_displays = updated_displays; |
| 202 } | 211 } |
| 203 | 212 |
| 213 RefreshDisplayInfo(); |
| 214 |
| 204 for (DisplayList::const_iterator iter = new_displays.begin(); | 215 for (DisplayList::const_iterator iter = new_displays.begin(); |
| 205 iter != new_displays.end(); ++iter) { | 216 iter != new_displays.end(); ++iter) { |
| 206 std::map<int64, DisplayInfo>::iterator info = | 217 std::map<int64, DisplayInfo>::iterator info = |
| 207 display_info_.find(iter->id()); | 218 display_info_.find(iter->id()); |
| 208 if (info != display_info_.end()) { | 219 if (info != display_info_.end()) { |
| 209 info->second.original_bounds_in_pixel = iter->bounds_in_pixel(); | 220 info->second.original_bounds_in_pixel = iter->bounds_in_pixel(); |
| 221 if (info->second.has_overscan && !info->second.has_custom_overscan_insets) |
| 222 info->second.overscan_insets_in_dip = GetDefaultDisplayOverscan(*iter); |
| 210 } else { | 223 } else { |
| 211 display_info_[iter->id()].original_bounds_in_pixel = | 224 display_info_[iter->id()].original_bounds_in_pixel = |
| 212 iter->bounds_in_pixel(); | 225 iter->bounds_in_pixel(); |
| 213 } | 226 } |
| 214 } | 227 } |
| 215 | 228 |
| 216 UpdateDisplays(new_displays); | 229 UpdateDisplays(new_displays); |
| 217 RefreshDisplayNames(); | |
| 218 } | 230 } |
| 219 | 231 |
| 220 void DisplayManager::UpdateDisplays( | 232 void DisplayManager::UpdateDisplays( |
| 221 const std::vector<gfx::Display>& updated_displays) { | 233 const std::vector<gfx::Display>& updated_displays) { |
| 222 DisplayList new_displays = updated_displays; | 234 DisplayList new_displays = updated_displays; |
| 223 | 235 |
| 224 for (DisplayList::iterator iter = new_displays.begin(); | 236 for (DisplayList::iterator iter = new_displays.begin(); |
| 225 iter != new_displays.end(); ++iter) { | 237 iter != new_displays.end(); ++iter) { |
| 226 std::map<int64, DisplayInfo>::const_iterator info = | 238 std::map<int64, DisplayInfo>::const_iterator info = |
| 227 display_info_.find(iter->id()); | 239 display_info_.find(iter->id()); |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 for (size_t i = 0; i < output_names.size(); ++i) { | 429 for (size_t i = 0; i < output_names.size(); ++i) { |
| 418 if (chromeos::OutputConfigurator::IsInternalOutputName( | 430 if (chromeos::OutputConfigurator::IsInternalOutputName( |
| 419 output_names[i])) { | 431 output_names[i])) { |
| 420 internal_display_id_ = GetDisplayIdForOutput(outputs[i]); | 432 internal_display_id_ = GetDisplayIdForOutput(outputs[i]); |
| 421 break; | 433 break; |
| 422 } | 434 } |
| 423 } | 435 } |
| 424 } | 436 } |
| 425 #endif | 437 #endif |
| 426 | 438 |
| 427 RefreshDisplayNames(); | 439 RefreshDisplayInfo(); |
| 428 | 440 |
| 429 #if defined(OS_WIN) | 441 #if defined(OS_WIN) |
| 430 if (base::win::GetVersion() >= base::win::VERSION_WIN8) | 442 if (base::win::GetVersion() >= base::win::VERSION_WIN8) |
| 431 aura::SetUseFullscreenHostWindow(true); | 443 aura::SetUseFullscreenHostWindow(true); |
| 432 #endif | 444 #endif |
| 433 // TODO(oshima): Move this logic to DisplayChangeObserver. | 445 // TODO(oshima): Move this logic to DisplayChangeObserver. |
| 434 const string size_str = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 446 const string size_str = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 435 switches::kAuraHostWindowSize); | 447 switches::kAuraHostWindowSize); |
| 436 vector<string> parts; | 448 vector<string> parts; |
| 437 base::SplitString(size_str, ',', &parts); | 449 base::SplitString(size_str, ',', &parts); |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 543 } | 555 } |
| 544 | 556 |
| 545 aura::RootWindow* root_window = Shell::GetPrimaryRootWindow(); | 557 aura::RootWindow* root_window = Shell::GetPrimaryRootWindow(); |
| 546 aura::client::ScreenPositionClient* client = | 558 aura::client::ScreenPositionClient* client = |
| 547 aura::client::GetScreenPositionClient(root_window); | 559 aura::client::GetScreenPositionClient(root_window); |
| 548 client->ConvertPointFromScreen(root_window, &target_location); | 560 client->ConvertPointFromScreen(root_window, &target_location); |
| 549 | 561 |
| 550 root_window->MoveCursorTo(target_location); | 562 root_window->MoveCursorTo(target_location); |
| 551 } | 563 } |
| 552 | 564 |
| 553 void DisplayManager::RefreshDisplayNames() { | 565 DisplayManager::DisplayInfo::DisplayInfo() |
| 566 : has_overscan(false), |
| 567 has_custom_overscan_insets(false) { |
| 568 } |
| 569 |
| 570 void DisplayManager::RefreshDisplayInfo() { |
| 554 #if defined(OS_CHROMEOS) | 571 #if defined(OS_CHROMEOS) |
| 555 if (!base::chromeos::IsRunningOnChromeOS()) | 572 if (!base::chromeos::IsRunningOnChromeOS()) |
| 556 return; | 573 return; |
| 557 #endif | 574 #endif |
| 558 | 575 |
| 559 #if defined(USE_X11) | 576 #if defined(USE_X11) |
| 560 std::vector<XID> outputs; | 577 std::vector<XID> outputs; |
| 561 if (!ui::GetOutputDeviceHandles(&outputs)) | 578 if (!ui::GetOutputDeviceHandles(&outputs)) |
| 562 return; | 579 return; |
| 563 | 580 |
| 564 for (size_t i = 0; i < outputs.size(); ++i) { | 581 for (size_t i = 0; i < outputs.size(); ++i) { |
| 565 uint16 manufacturer_id = 0; | 582 uint16 manufacturer_id = 0; |
| 566 uint32 serial_number = 0; | 583 uint32 serial_number = 0; |
| 567 std::string name; | 584 std::string name; |
| 568 ui::GetOutputDeviceData( | 585 ui::GetOutputDeviceData( |
| 569 outputs[i], &manufacturer_id, &serial_number, &name); | 586 outputs[i], &manufacturer_id, &serial_number, &name); |
| 570 int64 id = gfx::Display::GetID(manufacturer_id, serial_number); | 587 int64 id = gfx::Display::GetID(manufacturer_id, serial_number); |
| 571 if (IsInternalDisplayId(id)) { | 588 if (IsInternalDisplayId(id)) { |
| 572 display_info_[id].name = | 589 display_info_[id].name = |
| 573 l10n_util::GetStringUTF8(IDS_ASH_INTERNAL_DISPLAY_NAME); | 590 l10n_util::GetStringUTF8(IDS_ASH_INTERNAL_DISPLAY_NAME); |
| 574 } else if (!name.empty()) { | 591 } else if (!name.empty()) { |
| 575 display_info_[id].name = name; | 592 display_info_[id].name = name; |
| 576 } | 593 } |
| 594 |
| 595 ui::GetOutputOverscanFlag(outputs[i], &display_info_[id].has_overscan); |
| 577 } | 596 } |
| 578 #endif | 597 #endif |
| 579 } | 598 } |
| 580 | 599 |
| 581 void DisplayManager::SetDisplayIdsForTest(DisplayList* to_update) const { | 600 void DisplayManager::SetDisplayIdsForTest(DisplayList* to_update) const { |
| 582 DisplayList::iterator iter_to_update = to_update->begin(); | 601 DisplayList::iterator iter_to_update = to_update->begin(); |
| 583 DisplayList::const_iterator iter = displays_.begin(); | 602 DisplayList::const_iterator iter = displays_.begin(); |
| 584 for (; iter != displays_.end() && iter_to_update != to_update->end(); | 603 for (; iter != displays_.end() && iter_to_update != to_update->end(); |
| 585 ++iter, ++iter_to_update) { | 604 ++iter, ++iter_to_update) { |
| 586 (*iter_to_update).set_id((*iter).id()); | 605 (*iter_to_update).set_id((*iter).id()); |
| 587 } | 606 } |
| 588 } | 607 } |
| 589 | 608 |
| 609 void DisplayManager::SetHasOverscanFlagForTest(int64 id, bool has_overscan) { |
| 610 display_info_[id].has_overscan = has_overscan; |
| 611 } |
| 612 |
| 590 } // namespace internal | 613 } // namespace internal |
| 591 } // namespace ash | 614 } // namespace ash |
| OLD | NEW |