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

Side by Side Diff: ui/display/chromeos/display_configurator.cc

Issue 615133002: Add support for a virtual display on ChromeOS (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase on ToT Created 5 years, 10 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "ui/display/chromeos/display_configurator.h" 5 #include "ui/display/chromeos/display_configurator.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/sys_info.h" 10 #include "base/sys_info.h"
11 #include "base/time/time.h" 11 #include "base/time/time.h"
12 #include "ui/display/chromeos/display_snapshot_virtual.h"
12 #include "ui/display/chromeos/display_util.h" 13 #include "ui/display/chromeos/display_util.h"
13 #include "ui/display/chromeos/update_display_configuration_task.h" 14 #include "ui/display/chromeos/update_display_configuration_task.h"
14 #include "ui/display/display_switches.h" 15 #include "ui/display/display_switches.h"
15 #include "ui/display/types/display_mode.h" 16 #include "ui/display/types/display_mode.h"
16 #include "ui/display/types/display_snapshot.h" 17 #include "ui/display/types/display_snapshot.h"
17 #include "ui/display/types/native_display_delegate.h" 18 #include "ui/display/types/native_display_delegate.h"
19 #include "ui/gfx/display.h"
18 20
19 namespace ui { 21 namespace ui {
20 22
21 namespace { 23 namespace {
22 24
23 typedef std::vector<const DisplayMode*> DisplayModeList; 25 typedef std::vector<const DisplayMode*> DisplayModeList;
24 26
25 // The delay to perform configuration after RRNotify. See the comment for 27 // The delay to perform configuration after RRNotify. See the comment for
26 // |configure_timer_|. 28 // |configure_timer_|.
27 const int kConfigureDelayMs = 500; 29 const int kConfigureDelayMs = 500;
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 std::vector<DisplayConfigurator::DisplayState> 137 std::vector<DisplayConfigurator::DisplayState>
136 DisplayConfigurator::DisplayLayoutManagerImpl::ParseDisplays( 138 DisplayConfigurator::DisplayLayoutManagerImpl::ParseDisplays(
137 const std::vector<DisplaySnapshot*>& snapshots) const { 139 const std::vector<DisplaySnapshot*>& snapshots) const {
138 std::vector<DisplayState> cached_displays; 140 std::vector<DisplayState> cached_displays;
139 for (auto snapshot : snapshots) { 141 for (auto snapshot : snapshots) {
140 DisplayState display_state; 142 DisplayState display_state;
141 display_state.display = snapshot; 143 display_state.display = snapshot;
142 cached_displays.push_back(display_state); 144 cached_displays.push_back(display_state);
143 } 145 }
144 146
147 // Add virtual display if activated
148 if (configurator_->virtual_display_mode_.get()) {
achuithb 2015/02/11 23:41:44 if (IsVirtualDisplayEnabled()) easier to read?
149 DisplayState display_state;
150 display_state.display = new DisplaySnapshotVirtual(
151 snapshots.size(), configurator_->virtual_display_mode_.get());
152 cached_displays.push_back(display_state);
153 }
154
145 // Set |selected_mode| fields. 155 // Set |selected_mode| fields.
146 for (size_t i = 0; i < cached_displays.size(); ++i) { 156 for (size_t i = 0; i < cached_displays.size(); ++i) {
147 DisplayState* display_state = &cached_displays[i]; 157 DisplayState* display_state = &cached_displays[i];
148 gfx::Size size; 158 gfx::Size size;
149 if (GetStateController() && 159 if (GetStateController() &&
150 GetStateController()->GetResolutionForDisplayId( 160 GetStateController()->GetResolutionForDisplayId(
151 display_state->display->display_id(), &size)) { 161 display_state->display->display_id(), &size)) {
152 display_state->selected_mode = 162 display_state->selected_mode =
153 FindDisplayModeMatchingSize(*display_state->display, size); 163 FindDisplayModeMatchingSize(*display_state->display, size);
154 } 164 }
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after
587 HDCPState new_state = 597 HDCPState new_state =
588 new_desired ? HDCP_STATE_DESIRED : HDCP_STATE_UNDESIRED; 598 new_desired ? HDCP_STATE_DESIRED : HDCP_STATE_UNDESIRED;
589 if (!native_display_delegate_->SetHDCPState(*it->display, new_state)) 599 if (!native_display_delegate_->SetHDCPState(*it->display, new_state))
590 return false; 600 return false;
591 } 601 }
592 break; 602 break;
593 } 603 }
594 case DISPLAY_CONNECTION_TYPE_INTERNAL: 604 case DISPLAY_CONNECTION_TYPE_INTERNAL:
595 case DISPLAY_CONNECTION_TYPE_VGA: 605 case DISPLAY_CONNECTION_TYPE_VGA:
596 case DISPLAY_CONNECTION_TYPE_NETWORK: 606 case DISPLAY_CONNECTION_TYPE_NETWORK:
607 case DISPLAY_CONNECTION_TYPE_VIRTUAL:
597 // No protections for these types. Do nothing. 608 // No protections for these types. Do nothing.
598 break; 609 break;
599 case DISPLAY_CONNECTION_TYPE_NONE: 610 case DISPLAY_CONNECTION_TYPE_NONE:
600 NOTREACHED(); 611 NOTREACHED();
601 break; 612 break;
602 } 613 }
603 } 614 }
604 615
605 return true; 616 return true;
606 } 617 }
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
663 return false; 674 return false;
664 if (state == HDCP_STATE_ENABLED) 675 if (state == HDCP_STATE_ENABLED)
665 enabled |= CONTENT_PROTECTION_METHOD_HDCP; 676 enabled |= CONTENT_PROTECTION_METHOD_HDCP;
666 else 677 else
667 unfulfilled |= CONTENT_PROTECTION_METHOD_HDCP; 678 unfulfilled |= CONTENT_PROTECTION_METHOD_HDCP;
668 break; 679 break;
669 } 680 }
670 case DISPLAY_CONNECTION_TYPE_INTERNAL: 681 case DISPLAY_CONNECTION_TYPE_INTERNAL:
671 case DISPLAY_CONNECTION_TYPE_VGA: 682 case DISPLAY_CONNECTION_TYPE_VGA:
672 case DISPLAY_CONNECTION_TYPE_NETWORK: 683 case DISPLAY_CONNECTION_TYPE_NETWORK:
684 case DISPLAY_CONNECTION_TYPE_VIRTUAL:
673 // No protections for these types. Do nothing. 685 // No protections for these types. Do nothing.
674 break; 686 break;
675 case DISPLAY_CONNECTION_TYPE_NONE: 687 case DISPLAY_CONNECTION_TYPE_NONE:
676 NOTREACHED(); 688 NOTREACHED();
677 break; 689 break;
678 } 690 }
679 } 691 }
680 692
681 // Don't reveal protections requested by other clients. 693 // Don't reveal protections requested by other clients.
682 ProtectionRequests::iterator it = client_protection_requests_.find(client_id); 694 ProtectionRequests::iterator it = client_protection_requests_.find(client_id);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
729 741
730 return true; 742 return true;
731 } 743 }
732 744
733 std::vector<ui::ColorCalibrationProfile> 745 std::vector<ui::ColorCalibrationProfile>
734 DisplayConfigurator::GetAvailableColorCalibrationProfiles(int64_t display_id) { 746 DisplayConfigurator::GetAvailableColorCalibrationProfiles(int64_t display_id) {
735 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( 747 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
736 switches::kDisableDisplayColorCalibration)) { 748 switches::kDisableDisplayColorCalibration)) {
737 for (size_t i = 0; i < cached_displays_.size(); ++i) { 749 for (size_t i = 0; i < cached_displays_.size(); ++i) {
738 if (cached_displays_[i].display && 750 if (cached_displays_[i].display &&
739 cached_displays_[i].display->display_id() == display_id) { 751 cached_displays_[i].display->display_id() == display_id &&
752 IsNativeDisplay(cached_displays_[i].display->type())) {
740 return native_display_delegate_->GetAvailableColorCalibrationProfiles( 753 return native_display_delegate_->GetAvailableColorCalibrationProfiles(
741 *cached_displays_[i].display); 754 *cached_displays_[i].display);
742 } 755 }
743 } 756 }
744 } 757 }
745 758
746 return std::vector<ui::ColorCalibrationProfile>(); 759 return std::vector<ui::ColorCalibrationProfile>();
747 } 760 }
748 761
749 bool DisplayConfigurator::SetColorCalibrationProfile( 762 bool DisplayConfigurator::SetColorCalibrationProfile(
750 int64_t display_id, 763 int64_t display_id,
751 ui::ColorCalibrationProfile new_profile) { 764 ui::ColorCalibrationProfile new_profile) {
752 for (size_t i = 0; i < cached_displays_.size(); ++i) { 765 for (size_t i = 0; i < cached_displays_.size(); ++i) {
753 if (cached_displays_[i].display && 766 if (cached_displays_[i].display &&
754 cached_displays_[i].display->display_id() == display_id) { 767 cached_displays_[i].display->display_id() == display_id &&
768 IsNativeDisplay(cached_displays_[i].display->type())) {
755 return native_display_delegate_->SetColorCalibrationProfile( 769 return native_display_delegate_->SetColorCalibrationProfile(
756 *cached_displays_[i].display, new_profile); 770 *cached_displays_[i].display, new_profile);
757 } 771 }
758 } 772 }
759 773
760 return false; 774 return false;
761 } 775 }
762 776
763 void DisplayConfigurator::PrepareForExit() { 777 void DisplayConfigurator::PrepareForExit() {
764 configure_display_ = false; 778 configure_display_ = false;
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
1001 MultipleDisplayState attempted_state) { 1015 MultipleDisplayState attempted_state) {
1002 if (success) { 1016 if (success) {
1003 FOR_EACH_OBSERVER( 1017 FOR_EACH_OBSERVER(
1004 Observer, observers_, OnDisplayModeChanged(cached_displays_)); 1018 Observer, observers_, OnDisplayModeChanged(cached_displays_));
1005 } else { 1019 } else {
1006 FOR_EACH_OBSERVER( 1020 FOR_EACH_OBSERVER(
1007 Observer, observers_, OnDisplayModeChangeFailed(attempted_state)); 1021 Observer, observers_, OnDisplayModeChangeFailed(attempted_state));
1008 } 1022 }
1009 } 1023 }
1010 1024
1025 void DisplayConfigurator::EnableVirtualDisplay(
1026 scoped_ptr<DisplayMode> display_mode) {
1027 if (!virtual_display_enabled()) {
1028 virtual_display_mode_ = display_mode.Pass();
1029 ConfigureDisplays();
1030 } else {
1031 LOG(WARNING)
achuithb 2015/02/11 23:41:44 NOTREACHED may be better here
1032 << "Attempt to enable virtual display when it is already configured";
1033 }
1034 }
1035
1036 void DisplayConfigurator::DisableVirtualDisplay() {
1037 if (virtual_display_enabled()) {
1038 virtual_display_mode_.reset();
1039 ConfigureDisplays();
1040 } else {
1041 LOG(WARNING) << "Attempt to disable virtual display when it is not enabled";
achuithb 2015/02/11 23:41:44 NOTREACHED might be better here
1042 }
1043 }
1044
1045 int64 DisplayConfigurator::GetVirtualDisplayId(void) {
achuithb 2015/02/11 23:41:44 don't need void
1046 for (size_t i = 0; i < cached_displays_.size(); i++) {
achuithb 2015/02/11 23:41:44 ++i
1047 if (cached_displays_[i].display->type() == DISPLAY_CONNECTION_TYPE_VIRTUAL)
1048 return cached_displays_[i].display->display_id();
1049 }
1050 return gfx::Display::kInvalidDisplayID;
1051 }
1011 } // namespace ui 1052 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698