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