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

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: 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
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
443 // works while mirrored.
James Cook 2013/05/29 12:22:43 nit: "scaling to work". Also, this comment seems w
oshima 2013/05/29 15:39:49 Done.
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 //
James Cook 2013/05/29 12:22:43 remove blank comment
oshima 2013/05/29 15:39:49 Done.
453 DisplayInfo info = *new_info_iter;
454 info.SetOverscanInsets(true, gfx::Insets());
455 InsertAndUpdateDisplayInfo(info);
456
445 mirrored_display_ = CreateDisplayFromDisplayInfoById(new_info_iter->id()); 457 mirrored_display_ = CreateDisplayFromDisplayInfoById(new_info_iter->id());
446 mirror_window_updater.reset( 458 mirror_window_updater.reset(
447 new MirrorWindowCreator(display_info_[new_info_iter->id()])); 459 new MirrorWindowCreator(display_info_[new_info_iter->id()]));
448 ++new_info_iter; 460 ++new_info_iter;
449 // Remove existing external dispaly if it is going to be mirrored. 461 // Remove existing external dispaly if it is going to be mirrored.
450 if (curr_iter != displays_.end() && 462 if (curr_iter != displays_.end() &&
451 curr_iter->id() == mirrored_display_id) { 463 curr_iter->id() == mirrored_display_id) {
452 removed_displays.push_back(*curr_iter); 464 removed_displays.push_back(*curr_iter);
453 ++curr_iter; 465 ++curr_iter;
454 } 466 }
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 displays_.pop_back(); 562 displays_.pop_back();
551 } 563 }
552 for (std::vector<size_t>::iterator iter = added_display_indices.begin(); 564 for (std::vector<size_t>::iterator iter = added_display_indices.begin();
553 iter != added_display_indices.end(); ++iter) { 565 iter != added_display_indices.end(); ++iter) {
554 Shell::GetInstance()->screen()->NotifyDisplayAdded(displays_[*iter]); 566 Shell::GetInstance()->screen()->NotifyDisplayAdded(displays_[*iter]);
555 } 567 }
556 for (std::vector<size_t>::iterator iter = changed_display_indices.begin(); 568 for (std::vector<size_t>::iterator iter = changed_display_indices.begin();
557 iter != changed_display_indices.end(); ++iter) { 569 iter != changed_display_indices.end(); ++iter) {
558 Shell::GetInstance()->screen()->NotifyBoundsChanged(displays_[*iter]); 570 Shell::GetInstance()->screen()->NotifyBoundsChanged(displays_[*iter]);
559 } 571 }
572 mirror_window_updater.reset();
560 display_controller->NotifyDisplayConfigurationChanged(); 573 display_controller->NotifyDisplayConfigurationChanged();
561 if (update_mouse_location) 574 if (update_mouse_location)
562 display_controller->EnsurePointerInDisplays(); 575 display_controller->EnsurePointerInDisplays();
563 else 576 else
564 display_controller->UpdateMouseCursor(mouse_location_in_native); 577 display_controller->UpdateMouseCursor(mouse_location_in_native);
565 578
566 #if defined(USE_X11) && defined(OS_CHROMEOS) 579 #if defined(USE_X11) && defined(OS_CHROMEOS)
567 if (!changed_display_indices.empty() && base::chromeos::IsRunningOnChromeOS()) 580 if (!changed_display_indices.empty() && base::chromeos::IsRunningOnChromeOS())
568 ui::ClearX11DefaultRootWindow(); 581 ui::ClearX11DefaultRootWindow();
569 #endif 582 #endif
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 matching = &(*iter); 654 matching = &(*iter);
642 } 655 }
643 } 656 }
644 // Fallback to the primary display if there is no matching display. 657 // Fallback to the primary display if there is no matching display.
645 return matching ? *matching : DisplayController::GetPrimaryDisplay(); 658 return matching ? *matching : DisplayController::GetPrimaryDisplay();
646 } 659 }
647 660
648 const DisplayInfo& DisplayManager::GetDisplayInfo(int64 display_id) const { 661 const DisplayInfo& DisplayManager::GetDisplayInfo(int64 display_id) const {
649 std::map<int64, DisplayInfo>::const_iterator iter = 662 std::map<int64, DisplayInfo>::const_iterator iter =
650 display_info_.find(display_id); 663 display_info_.find(display_id);
651 CHECK(iter != display_info_.end()); 664 CHECK(iter != display_info_.end()) << display_id;
652 return iter->second; 665 return iter->second;
653 } 666 }
654 667
655 std::string DisplayManager::GetDisplayNameForId(int64 id) { 668 std::string DisplayManager::GetDisplayNameForId(int64 id) {
656 if (id == gfx::Display::kInvalidDisplayID) 669 if (id == gfx::Display::kInvalidDisplayID)
657 return l10n_util::GetStringUTF8(IDS_ASH_STATUS_TRAY_UNKNOWN_DISPLAY_NAME); 670 return l10n_util::GetStringUTF8(IDS_ASH_STATUS_TRAY_UNKNOWN_DISPLAY_NAME);
658 671
659 std::map<int64, DisplayInfo>::const_iterator iter = display_info_.find(id); 672 std::map<int64, DisplayInfo>::const_iterator iter = display_info_.find(id);
660 if (iter != display_info_.end() && !iter->second.name().empty()) 673 if (iter != display_info_.end() && !iter->second.name().empty())
661 return iter->second.name(); 674 return iter->second.name();
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
701 if (num_connected_displays() == 1) { 714 if (num_connected_displays() == 1) {
702 // Layout the 2nd display below the primary as with the real device. 715 // Layout the 2nd display below the primary as with the real device.
703 aura::RootWindow* primary = Shell::GetPrimaryRootWindow(); 716 aura::RootWindow* primary = Shell::GetPrimaryRootWindow();
704 gfx::Rect host_bounds = 717 gfx::Rect host_bounds =
705 gfx::Rect(primary->GetHostOrigin(), primary->GetHostSize()); 718 gfx::Rect(primary->GetHostOrigin(), primary->GetHostSize());
706 new_display_info_list.push_back(DisplayInfo::CreateFromSpec( 719 new_display_info_list.push_back(DisplayInfo::CreateFromSpec(
707 base::StringPrintf( 720 base::StringPrintf(
708 "%d+%d-500x400", host_bounds.x(), host_bounds.bottom()))); 721 "%d+%d-500x400", host_bounds.x(), host_bounds.bottom())));
709 } 722 }
710 num_connected_displays_ = new_display_info_list.size(); 723 num_connected_displays_ = new_display_info_list.size();
724 mirrored_display_ = gfx::Display();
711 UpdateDisplays(new_display_info_list); 725 UpdateDisplays(new_display_info_list);
712 } 726 }
713 727
714 void DisplayManager::ToggleDisplayScaleFactor() { 728 void DisplayManager::ToggleDisplayScaleFactor() {
715 DCHECK(!displays_.empty()); 729 DCHECK(!displays_.empty());
716 std::vector<DisplayInfo> new_display_info_list; 730 std::vector<DisplayInfo> new_display_info_list;
717 for (DisplayList::const_iterator iter = displays_.begin(); 731 for (DisplayList::const_iterator iter = displays_.begin();
718 iter != displays_.end(); ++iter) { 732 iter != displays_.end(); ++iter) {
719 DisplayInfo display_info = GetDisplayInfo(iter->id()); 733 DisplayInfo display_info = GetDisplayInfo(iter->id());
720 display_info.set_device_scale_factor( 734 display_info.set_device_scale_factor(
721 display_info.device_scale_factor() == 1.0f ? 2.0f : 1.0f); 735 display_info.device_scale_factor() == 1.0f ? 2.0f : 1.0f);
722 new_display_info_list.push_back(display_info); 736 new_display_info_list.push_back(display_info);
723 } 737 }
738 AddMirrorDisplayInfoIfAny(&new_display_info_list);
724 UpdateDisplays(new_display_info_list); 739 UpdateDisplays(new_display_info_list);
725 } 740 }
726 741
727 void DisplayManager::OnRootWindowResized(const aura::RootWindow* root, 742 void DisplayManager::OnRootWindowResized(const aura::RootWindow* root,
728 const gfx::Size& old_size) { 743 const gfx::Size& old_size) {
729 if (change_display_upon_host_resize_) { 744 if (change_display_upon_host_resize_) {
730 gfx::Display& display = FindDisplayForRootWindow(root); 745 gfx::Display& display = FindDisplayForRootWindow(root);
731 gfx::Size old_display_size_in_pixel = display.GetSizeInPixel(); 746 gfx::Size old_display_size_in_pixel = display.GetSizeInPixel();
732 display_info_[display.id()].SetBounds( 747 display_info_[display.id()].SetBounds(
733 gfx::Rect(root->GetHostOrigin(), root->GetHostSize())); 748 gfx::Rect(root->GetHostOrigin(), root->GetHostSize()));
734 const gfx::Size& new_root_size = root->bounds().size(); 749 const gfx::Size& new_root_size = root->bounds().size();
750 // It's tricky to support resizing mirror window on desktop.
751 if (software_mirroring_enabled_ && mirrored_display_.id() == display.id())
752 return;
735 if (old_size != new_root_size) { 753 if (old_size != new_root_size) {
736 display.SetSize(display_info_[display.id()].size_in_pixel()); 754 display.SetSize(display_info_[display.id()].size_in_pixel());
737 Shell::GetInstance()->screen()->NotifyBoundsChanged(display); 755 Shell::GetInstance()->screen()->NotifyBoundsChanged(display);
756 Shell::GetInstance()->mirror_window_controller()->
757 UpdateWindow();
738 } 758 }
739 } 759 }
740 } 760 }
741 761
742 void DisplayManager::SetSoftwareMirroring(bool enabled) { 762 void DisplayManager::SetSoftwareMirroring(bool enabled) {
743 software_mirroring_enabled_ = enabled; 763 software_mirroring_enabled_ = enabled;
744 mirrored_display_ = gfx::Display(); 764 mirrored_display_ = gfx::Display();
745 } 765 }
746 766
747 int64 DisplayManager::GetDisplayIdForUIScaling() const { 767 int64 DisplayManager::GetDisplayIdForUIScaling() const {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
791 gfx::Display& DisplayManager::FindDisplayForId(int64 id) { 811 gfx::Display& DisplayManager::FindDisplayForId(int64 id) {
792 for (DisplayList::iterator iter = displays_.begin(); 812 for (DisplayList::iterator iter = displays_.begin();
793 iter != displays_.end(); ++iter) { 813 iter != displays_.end(); ++iter) {
794 if ((*iter).id() == id) 814 if ((*iter).id() == id)
795 return *iter; 815 return *iter;
796 } 816 }
797 DLOG(WARNING) << "Could not find display:" << id; 817 DLOG(WARNING) << "Could not find display:" << id;
798 return GetInvalidDisplay(); 818 return GetInvalidDisplay();
799 } 819 }
800 820
821 void DisplayManager::AddMirrorDisplayInfoIfAny(
822 std::vector<DisplayInfo>* display_info_list) {
823 if (software_mirroring_enabled_ && mirrored_display_.is_valid())
824 display_info_list->push_back(GetDisplayInfo(mirrored_display_.id()));
825 }
826
801 void DisplayManager::AddDisplayFromSpec(const std::string& spec) { 827 void DisplayManager::AddDisplayFromSpec(const std::string& spec) {
802 DisplayInfo display_info = DisplayInfo::CreateFromSpec(spec); 828 DisplayInfo display_info = DisplayInfo::CreateFromSpec(spec);
803 InsertAndUpdateDisplayInfo(display_info); 829 InsertAndUpdateDisplayInfo(display_info);
804 gfx::Display display = CreateDisplayFromDisplayInfoById(display_info.id()); 830 gfx::Display display = CreateDisplayFromDisplayInfoById(display_info.id());
805 displays_.push_back(display); 831 displays_.push_back(display);
806 } 832 }
807 833
808 void DisplayManager::InsertAndUpdateDisplayInfo(const DisplayInfo& new_info) { 834 void DisplayManager::InsertAndUpdateDisplayInfo(const DisplayInfo& new_info) {
809 std::map<int64, DisplayInfo>::iterator info = 835 std::map<int64, DisplayInfo>::iterator info =
810 display_info_.find(new_info.id()); 836 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 854 // always (0,0) and the secondary display's bounds will be updated
829 // by |DisplayController::UpdateDisplayBoundsForLayout|. 855 // by |DisplayController::UpdateDisplayBoundsForLayout|.
830 new_display.SetScaleAndBounds( 856 new_display.SetScaleAndBounds(
831 display_info.device_scale_factor(), gfx::Rect(bounds_in_pixel.size())); 857 display_info.device_scale_factor(), gfx::Rect(bounds_in_pixel.size()));
832 new_display.set_rotation(display_info.rotation()); 858 new_display.set_rotation(display_info.rotation());
833 return new_display; 859 return new_display;
834 } 860 }
835 861
836 } // namespace internal 862 } // namespace internal
837 } // namespace ash 863 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698