Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(262)

Side by Side Diff: ash/display/display_manager.cc

Issue 15730006: Use the source display's pixel size as a mirror window's size. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addressed comments Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ash/display/display_manager.h ('k') | ash/display/display_manager_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <cmath> 7 #include <cmath>
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 void DisplayManager::SetOverscanInsets(int64 display_id, 243 void DisplayManager::SetOverscanInsets(int64 display_id,
244 const gfx::Insets& insets_in_dip) { 244 const gfx::Insets& insets_in_dip) {
245 // TODO(oshima): insets has to be rotated according to the 245 // TODO(oshima): insets has to be rotated according to the
246 // the current display rotation. 246 // the current display rotation.
247 display_info_[display_id].SetOverscanInsets(true, insets_in_dip); 247 display_info_[display_id].SetOverscanInsets(true, insets_in_dip);
248 DisplayInfoList display_info_list; 248 DisplayInfoList display_info_list;
249 for (DisplayList::const_iterator iter = displays_.begin(); 249 for (DisplayList::const_iterator iter = displays_.begin();
250 iter != displays_.end(); ++iter) { 250 iter != displays_.end(); ++iter) {
251 display_info_list.push_back(GetDisplayInfo(iter->id())); 251 display_info_list.push_back(GetDisplayInfo(iter->id()));
252 } 252 }
253 AddMirrorDisplayInfoIfAny(&display_info_list);
253 UpdateDisplays(display_info_list); 254 UpdateDisplays(display_info_list);
254 } 255 }
255 256
256 void DisplayManager::ClearCustomOverscanInsets(int64 display_id) { 257 void DisplayManager::ClearCustomOverscanInsets(int64 display_id) {
257 display_info_[display_id].clear_has_custom_overscan_insets(); 258 display_info_[display_id].clear_has_custom_overscan_insets();
258 DisplayInfoList display_info_list; 259 DisplayInfoList display_info_list;
259 for (DisplayList::const_iterator iter = displays_.begin(); 260 for (DisplayList::const_iterator iter = displays_.begin();
260 iter != displays_.end(); ++iter) { 261 iter != displays_.end(); ++iter) {
261 display_info_list.push_back(GetDisplayInfo(iter->id())); 262 display_info_list.push_back(GetDisplayInfo(iter->id()));
262 } 263 }
264 AddMirrorDisplayInfoIfAny(&display_info_list);
263 UpdateDisplays(display_info_list); 265 UpdateDisplays(display_info_list);
264 } 266 }
265 267
266 void DisplayManager::SetDisplayRotation(int64 display_id, 268 void DisplayManager::SetDisplayRotation(int64 display_id,
267 gfx::Display::Rotation rotation) { 269 gfx::Display::Rotation rotation) {
268 if (!IsDisplayRotationEnabled()) 270 if (!IsDisplayRotationEnabled())
269 return; 271 return;
270 DisplayInfoList display_info_list; 272 DisplayInfoList display_info_list;
271 for (DisplayList::const_iterator iter = displays_.begin(); 273 for (DisplayList::const_iterator iter = displays_.begin();
272 iter != displays_.end(); ++iter) { 274 iter != displays_.end(); ++iter) {
273 DisplayInfo info = GetDisplayInfo(iter->id()); 275 DisplayInfo info = GetDisplayInfo(iter->id());
274 if (info.id() == display_id) { 276 if (info.id() == display_id) {
275 if (info.rotation() == rotation) 277 if (info.rotation() == rotation)
276 return; 278 return;
277 info.set_rotation(rotation); 279 info.set_rotation(rotation);
278 } 280 }
279 display_info_list.push_back(info); 281 display_info_list.push_back(info);
280 } 282 }
283 AddMirrorDisplayInfoIfAny(&display_info_list);
281 UpdateDisplays(display_info_list); 284 UpdateDisplays(display_info_list);
282 } 285 }
283 286
284 void DisplayManager::SetDisplayUIScale(int64 display_id, 287 void DisplayManager::SetDisplayUIScale(int64 display_id,
285 float ui_scale) { 288 float ui_scale) {
286 if (!IsDisplayUIScalingEnabled() || 289 if (!IsDisplayUIScalingEnabled() ||
287 gfx::Display::InternalDisplayId() != display_id) { 290 gfx::Display::InternalDisplayId() != display_id) {
288 return; 291 return;
289 } 292 }
290 293
291 DisplayInfoList display_info_list; 294 DisplayInfoList display_info_list;
292 for (DisplayList::const_iterator iter = displays_.begin(); 295 for (DisplayList::const_iterator iter = displays_.begin();
293 iter != displays_.end(); ++iter) { 296 iter != displays_.end(); ++iter) {
294 DisplayInfo info = GetDisplayInfo(iter->id()); 297 DisplayInfo info = GetDisplayInfo(iter->id());
295 if (info.id() == display_id) { 298 if (info.id() == display_id) {
296 if (info.ui_scale() == ui_scale) 299 if (info.ui_scale() == ui_scale)
297 return; 300 return;
298 std::vector<float> scales = GetScalesForDisplay(info); 301 std::vector<float> scales = GetScalesForDisplay(info);
299 ScaleComparator comparator(ui_scale); 302 ScaleComparator comparator(ui_scale);
300 if (std::find_if(scales.begin(), scales.end(), comparator) == 303 if (std::find_if(scales.begin(), scales.end(), comparator) ==
301 scales.end()) { 304 scales.end()) {
302 return; 305 return;
303 } 306 }
304 info.set_ui_scale(ui_scale); 307 info.set_ui_scale(ui_scale);
305 } 308 }
306 display_info_list.push_back(info); 309 display_info_list.push_back(info);
307 } 310 }
311 AddMirrorDisplayInfoIfAny(&display_info_list);
308 UpdateDisplays(display_info_list); 312 UpdateDisplays(display_info_list);
309 } 313 }
310 314
311 void DisplayManager::RegisterDisplayProperty( 315 void DisplayManager::RegisterDisplayProperty(
312 int64 display_id, 316 int64 display_id,
313 gfx::Display::Rotation rotation, 317 gfx::Display::Rotation rotation,
314 float ui_scale, 318 float ui_scale,
315 const gfx::Insets* overscan_insets) { 319 const gfx::Insets* overscan_insets) {
316 if (display_info_.find(display_id) == display_info_.end()) { 320 if (display_info_.find(display_id) == display_info_.end()) {
317 display_info_[display_id] = 321 display_info_[display_id] =
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 } 408 }
405 UpdateDisplays(new_display_info_list); 409 UpdateDisplays(new_display_info_list);
406 } 410 }
407 411
408 void DisplayManager::UpdateDisplays() { 412 void DisplayManager::UpdateDisplays() {
409 DisplayInfoList display_info_list; 413 DisplayInfoList display_info_list;
410 for (DisplayList::const_iterator iter = displays_.begin(); 414 for (DisplayList::const_iterator iter = displays_.begin();
411 iter != displays_.end(); ++iter) { 415 iter != displays_.end(); ++iter) {
412 display_info_list.push_back(GetDisplayInfo(iter->id())); 416 display_info_list.push_back(GetDisplayInfo(iter->id()));
413 } 417 }
418 AddMirrorDisplayInfoIfAny(&display_info_list);
414 UpdateDisplays(display_info_list); 419 UpdateDisplays(display_info_list);
415 } 420 }
416 421
417 void DisplayManager::UpdateDisplays( 422 void DisplayManager::UpdateDisplays(
418 const std::vector<DisplayInfo>& updated_display_info_list) { 423 const std::vector<DisplayInfo>& updated_display_info_list) {
419 DisplayInfoList new_display_info_list = updated_display_info_list; 424 DisplayInfoList new_display_info_list = updated_display_info_list;
420 std::sort(displays_.begin(), displays_.end(), DisplaySortFunctor()); 425 std::sort(displays_.begin(), displays_.end(), DisplaySortFunctor());
421 std::sort(new_display_info_list.begin(), 426 std::sort(new_display_info_list.begin(),
422 new_display_info_list.end(), 427 new_display_info_list.end(),
423 DisplayInfoSortFunctor()); 428 DisplayInfoSortFunctor());
424 DisplayList removed_displays; 429 DisplayList removed_displays;
425 std::vector<size_t> changed_display_indices; 430 std::vector<size_t> changed_display_indices;
426 std::vector<size_t> added_display_indices; 431 std::vector<size_t> added_display_indices;
427 432
428 DisplayList::iterator curr_iter = displays_.begin(); 433 DisplayList::iterator curr_iter = displays_.begin();
429 DisplayInfoList::const_iterator new_info_iter = new_display_info_list.begin(); 434 DisplayInfoList::const_iterator new_info_iter = new_display_info_list.begin();
430 435
431 DisplayList new_displays; 436 DisplayList new_displays;
432 bool update_mouse_location = false; 437 bool update_mouse_location = false;
433 438
434 scoped_ptr<MirrorWindowUpdater> mirror_window_updater; 439 scoped_ptr<MirrorWindowUpdater> mirror_window_updater;
435 // TODO(oshima): We may want to use external as the source. 440 // Use the internal display or 1st as the mirror source, then scale
441 // the root window so that it matches the external display's
442 // resolution. This is necessary in order for scaling to work while
443 // mirrored.
436 int mirrored_display_id = gfx::Display::kInvalidDisplayID; 444 int mirrored_display_id = gfx::Display::kInvalidDisplayID;
437 if (software_mirroring_enabled_ && updated_display_info_list.size() == 2) 445 if (software_mirroring_enabled_ && new_display_info_list.size() == 2)
438 mirrored_display_id = updated_display_info_list[1].id(); 446 mirrored_display_id = new_display_info_list[1].id();
439 447
440 while (curr_iter != displays_.end() || 448 while (curr_iter != displays_.end() ||
441 new_info_iter != new_display_info_list.end()) { 449 new_info_iter != new_display_info_list.end()) {
442 if (new_info_iter != new_display_info_list.end() && 450 if (new_info_iter != new_display_info_list.end() &&
443 mirrored_display_id == new_info_iter->id()) { 451 mirrored_display_id == new_info_iter->id()) {
444 InsertAndUpdateDisplayInfo(*new_info_iter); 452 DisplayInfo info = *new_info_iter;
453 info.SetOverscanInsets(true, gfx::Insets());
454 InsertAndUpdateDisplayInfo(info);
455
445 mirrored_display_ = CreateDisplayFromDisplayInfoById(new_info_iter->id()); 456 mirrored_display_ = CreateDisplayFromDisplayInfoById(new_info_iter->id());
446 mirror_window_updater.reset( 457 mirror_window_updater.reset(
447 new MirrorWindowCreator(display_info_[new_info_iter->id()])); 458 new MirrorWindowCreator(display_info_[new_info_iter->id()]));
448 ++new_info_iter; 459 ++new_info_iter;
449 // Remove existing external dispaly if it is going to be mirrored. 460 // Remove existing external dispaly if it is going to be mirrored.
450 if (curr_iter != displays_.end() && 461 if (curr_iter != displays_.end() &&
451 curr_iter->id() == mirrored_display_id) { 462 curr_iter->id() == mirrored_display_id) {
452 removed_displays.push_back(*curr_iter); 463 removed_displays.push_back(*curr_iter);
453 ++curr_iter; 464 ++curr_iter;
454 } 465 }
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 displays_.pop_back(); 561 displays_.pop_back();
551 } 562 }
552 for (std::vector<size_t>::iterator iter = added_display_indices.begin(); 563 for (std::vector<size_t>::iterator iter = added_display_indices.begin();
553 iter != added_display_indices.end(); ++iter) { 564 iter != added_display_indices.end(); ++iter) {
554 Shell::GetInstance()->screen()->NotifyDisplayAdded(displays_[*iter]); 565 Shell::GetInstance()->screen()->NotifyDisplayAdded(displays_[*iter]);
555 } 566 }
556 for (std::vector<size_t>::iterator iter = changed_display_indices.begin(); 567 for (std::vector<size_t>::iterator iter = changed_display_indices.begin();
557 iter != changed_display_indices.end(); ++iter) { 568 iter != changed_display_indices.end(); ++iter) {
558 Shell::GetInstance()->screen()->NotifyBoundsChanged(displays_[*iter]); 569 Shell::GetInstance()->screen()->NotifyBoundsChanged(displays_[*iter]);
559 } 570 }
571 mirror_window_updater.reset();
560 display_controller->NotifyDisplayConfigurationChanged(); 572 display_controller->NotifyDisplayConfigurationChanged();
561 if (update_mouse_location) 573 if (update_mouse_location)
562 display_controller->EnsurePointerInDisplays(); 574 display_controller->EnsurePointerInDisplays();
563 else 575 else
564 display_controller->UpdateMouseCursor(mouse_location_in_native); 576 display_controller->UpdateMouseCursor(mouse_location_in_native);
565 577
566 #if defined(USE_X11) && defined(OS_CHROMEOS) 578 #if defined(USE_X11) && defined(OS_CHROMEOS)
567 if (!changed_display_indices.empty() && base::chromeos::IsRunningOnChromeOS()) 579 if (!changed_display_indices.empty() && base::chromeos::IsRunningOnChromeOS())
568 ui::ClearX11DefaultRootWindow(); 580 ui::ClearX11DefaultRootWindow();
569 #endif 581 #endif
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 matching = &(*iter); 653 matching = &(*iter);
642 } 654 }
643 } 655 }
644 // Fallback to the primary display if there is no matching display. 656 // Fallback to the primary display if there is no matching display.
645 return matching ? *matching : DisplayController::GetPrimaryDisplay(); 657 return matching ? *matching : DisplayController::GetPrimaryDisplay();
646 } 658 }
647 659
648 const DisplayInfo& DisplayManager::GetDisplayInfo(int64 display_id) const { 660 const DisplayInfo& DisplayManager::GetDisplayInfo(int64 display_id) const {
649 std::map<int64, DisplayInfo>::const_iterator iter = 661 std::map<int64, DisplayInfo>::const_iterator iter =
650 display_info_.find(display_id); 662 display_info_.find(display_id);
651 CHECK(iter != display_info_.end()); 663 CHECK(iter != display_info_.end()) << display_id;
652 return iter->second; 664 return iter->second;
653 } 665 }
654 666
655 std::string DisplayManager::GetDisplayNameForId(int64 id) { 667 std::string DisplayManager::GetDisplayNameForId(int64 id) {
656 if (id == gfx::Display::kInvalidDisplayID) 668 if (id == gfx::Display::kInvalidDisplayID)
657 return l10n_util::GetStringUTF8(IDS_ASH_STATUS_TRAY_UNKNOWN_DISPLAY_NAME); 669 return l10n_util::GetStringUTF8(IDS_ASH_STATUS_TRAY_UNKNOWN_DISPLAY_NAME);
658 670
659 std::map<int64, DisplayInfo>::const_iterator iter = display_info_.find(id); 671 std::map<int64, DisplayInfo>::const_iterator iter = display_info_.find(id);
660 if (iter != display_info_.end() && !iter->second.name().empty()) 672 if (iter != display_info_.end() && !iter->second.name().empty())
661 return iter->second.name(); 673 return iter->second.name();
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
701 if (num_connected_displays() == 1) { 713 if (num_connected_displays() == 1) {
702 // Layout the 2nd display below the primary as with the real device. 714 // Layout the 2nd display below the primary as with the real device.
703 aura::RootWindow* primary = Shell::GetPrimaryRootWindow(); 715 aura::RootWindow* primary = Shell::GetPrimaryRootWindow();
704 gfx::Rect host_bounds = 716 gfx::Rect host_bounds =
705 gfx::Rect(primary->GetHostOrigin(), primary->GetHostSize()); 717 gfx::Rect(primary->GetHostOrigin(), primary->GetHostSize());
706 new_display_info_list.push_back(DisplayInfo::CreateFromSpec( 718 new_display_info_list.push_back(DisplayInfo::CreateFromSpec(
707 base::StringPrintf( 719 base::StringPrintf(
708 "%d+%d-500x400", host_bounds.x(), host_bounds.bottom()))); 720 "%d+%d-500x400", host_bounds.x(), host_bounds.bottom())));
709 } 721 }
710 num_connected_displays_ = new_display_info_list.size(); 722 num_connected_displays_ = new_display_info_list.size();
723 mirrored_display_ = gfx::Display();
711 UpdateDisplays(new_display_info_list); 724 UpdateDisplays(new_display_info_list);
712 } 725 }
713 726
714 void DisplayManager::ToggleDisplayScaleFactor() { 727 void DisplayManager::ToggleDisplayScaleFactor() {
715 DCHECK(!displays_.empty()); 728 DCHECK(!displays_.empty());
716 std::vector<DisplayInfo> new_display_info_list; 729 std::vector<DisplayInfo> new_display_info_list;
717 for (DisplayList::const_iterator iter = displays_.begin(); 730 for (DisplayList::const_iterator iter = displays_.begin();
718 iter != displays_.end(); ++iter) { 731 iter != displays_.end(); ++iter) {
719 DisplayInfo display_info = GetDisplayInfo(iter->id()); 732 DisplayInfo display_info = GetDisplayInfo(iter->id());
720 display_info.set_device_scale_factor( 733 display_info.set_device_scale_factor(
721 display_info.device_scale_factor() == 1.0f ? 2.0f : 1.0f); 734 display_info.device_scale_factor() == 1.0f ? 2.0f : 1.0f);
722 new_display_info_list.push_back(display_info); 735 new_display_info_list.push_back(display_info);
723 } 736 }
737 AddMirrorDisplayInfoIfAny(&new_display_info_list);
724 UpdateDisplays(new_display_info_list); 738 UpdateDisplays(new_display_info_list);
725 } 739 }
726 740
727 void DisplayManager::OnRootWindowResized(const aura::RootWindow* root, 741 void DisplayManager::OnRootWindowResized(const aura::RootWindow* root,
728 const gfx::Size& old_size) { 742 const gfx::Size& old_size) {
729 if (change_display_upon_host_resize_) { 743 if (change_display_upon_host_resize_) {
730 gfx::Display& display = FindDisplayForRootWindow(root); 744 gfx::Display& display = FindDisplayForRootWindow(root);
731 gfx::Size old_display_size_in_pixel = display.GetSizeInPixel(); 745 gfx::Size old_display_size_in_pixel = display.GetSizeInPixel();
732 display_info_[display.id()].SetBounds( 746 display_info_[display.id()].SetBounds(
733 gfx::Rect(root->GetHostOrigin(), root->GetHostSize())); 747 gfx::Rect(root->GetHostOrigin(), root->GetHostSize()));
734 const gfx::Size& new_root_size = root->bounds().size(); 748 const gfx::Size& new_root_size = root->bounds().size();
749 // It's tricky to support resizing mirror window on desktop.
750 if (software_mirroring_enabled_ && mirrored_display_.id() == display.id())
751 return;
735 if (old_size != new_root_size) { 752 if (old_size != new_root_size) {
736 display.SetSize(display_info_[display.id()].size_in_pixel()); 753 display.SetSize(display_info_[display.id()].size_in_pixel());
737 Shell::GetInstance()->screen()->NotifyBoundsChanged(display); 754 Shell::GetInstance()->screen()->NotifyBoundsChanged(display);
755 Shell::GetInstance()->mirror_window_controller()->
756 UpdateWindow();
738 } 757 }
739 } 758 }
740 } 759 }
741 760
742 void DisplayManager::SetSoftwareMirroring(bool enabled) { 761 void DisplayManager::SetSoftwareMirroring(bool enabled) {
743 software_mirroring_enabled_ = enabled; 762 software_mirroring_enabled_ = enabled;
744 mirrored_display_ = gfx::Display(); 763 mirrored_display_ = gfx::Display();
745 } 764 }
746 765
747 int64 DisplayManager::GetDisplayIdForUIScaling() const { 766 int64 DisplayManager::GetDisplayIdForUIScaling() const {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
791 gfx::Display& DisplayManager::FindDisplayForId(int64 id) { 810 gfx::Display& DisplayManager::FindDisplayForId(int64 id) {
792 for (DisplayList::iterator iter = displays_.begin(); 811 for (DisplayList::iterator iter = displays_.begin();
793 iter != displays_.end(); ++iter) { 812 iter != displays_.end(); ++iter) {
794 if ((*iter).id() == id) 813 if ((*iter).id() == id)
795 return *iter; 814 return *iter;
796 } 815 }
797 DLOG(WARNING) << "Could not find display:" << id; 816 DLOG(WARNING) << "Could not find display:" << id;
798 return GetInvalidDisplay(); 817 return GetInvalidDisplay();
799 } 818 }
800 819
820 void DisplayManager::AddMirrorDisplayInfoIfAny(
821 std::vector<DisplayInfo>* display_info_list) {
822 if (software_mirroring_enabled_ && mirrored_display_.is_valid())
823 display_info_list->push_back(GetDisplayInfo(mirrored_display_.id()));
824 }
825
801 void DisplayManager::AddDisplayFromSpec(const std::string& spec) { 826 void DisplayManager::AddDisplayFromSpec(const std::string& spec) {
802 DisplayInfo display_info = DisplayInfo::CreateFromSpec(spec); 827 DisplayInfo display_info = DisplayInfo::CreateFromSpec(spec);
803 InsertAndUpdateDisplayInfo(display_info); 828 InsertAndUpdateDisplayInfo(display_info);
804 gfx::Display display = CreateDisplayFromDisplayInfoById(display_info.id()); 829 gfx::Display display = CreateDisplayFromDisplayInfoById(display_info.id());
805 displays_.push_back(display); 830 displays_.push_back(display);
806 } 831 }
807 832
808 void DisplayManager::InsertAndUpdateDisplayInfo(const DisplayInfo& new_info) { 833 void DisplayManager::InsertAndUpdateDisplayInfo(const DisplayInfo& new_info) {
809 std::map<int64, DisplayInfo>::iterator info = 834 std::map<int64, DisplayInfo>::iterator info =
810 display_info_.find(new_info.id()); 835 display_info_.find(new_info.id());
(...skipping 17 matching lines...) Expand all
828 // always (0,0) and the secondary display's bounds will be updated 853 // always (0,0) and the secondary display's bounds will be updated
829 // by |DisplayController::UpdateDisplayBoundsForLayout|. 854 // by |DisplayController::UpdateDisplayBoundsForLayout|.
830 new_display.SetScaleAndBounds( 855 new_display.SetScaleAndBounds(
831 display_info.device_scale_factor(), gfx::Rect(bounds_in_pixel.size())); 856 display_info.device_scale_factor(), gfx::Rect(bounds_in_pixel.size()));
832 new_display.set_rotation(display_info.rotation()); 857 new_display.set_rotation(display_info.rotation());
833 return new_display; 858 return new_display;
834 } 859 }
835 860
836 } // namespace internal 861 } // namespace internal
837 } // namespace ash 862 } // namespace ash
OLDNEW
« no previous file with comments | « ash/display/display_manager.h ('k') | ash/display/display_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698