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

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: Remove ash/ dep from content Created 5 years, 9 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_->IsVirtualDisplayEnabled()) {
149 DisplayState display_state;
150 configurator_->virtual_display_snapshot_->set_display_id(snapshots.size());
151 display_state.display = configurator_->virtual_display_snapshot_.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 IsPhysicalDisplayType(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 IsPhysicalDisplayType(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 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
1006 if (success) { 1020 if (success) {
1007 FOR_EACH_OBSERVER( 1021 FOR_EACH_OBSERVER(
1008 Observer, observers_, OnDisplayModeChanged(cached_displays_)); 1022 Observer, observers_, OnDisplayModeChanged(cached_displays_));
1009 } else { 1023 } else {
1010 FOR_EACH_OBSERVER( 1024 FOR_EACH_OBSERVER(
1011 Observer, observers_, OnDisplayModeChangeFailed(cached_displays_, 1025 Observer, observers_, OnDisplayModeChangeFailed(cached_displays_,
1012 attempted_state)); 1026 attempted_state));
1013 } 1027 }
1014 } 1028 }
1015 1029
1030 void DisplayConfigurator::EnableVirtualDisplay(gfx::Size display_size) {
1031 DCHECK(!IsVirtualDisplayEnabled()) << "virtual display already enabled";
1032 // The display_id will be updated after the real displays are enumerated.
1033 virtual_display_snapshot_.reset(new DisplaySnapshotVirtual(
1034 gfx::Display::kInvalidDisplayID, display_size));
1035 ConfigureDisplays();
1036 }
1037
1038 void DisplayConfigurator::DisableVirtualDisplay() {
1039 DCHECK(IsVirtualDisplayEnabled()) << "virtual display not enabled";
1040 virtual_display_snapshot_.reset();
1041 ConfigureDisplays();
1042 }
1043
1044 bool DisplayConfigurator::IsVirtualDisplayEnabled() const {
1045 return virtual_display_snapshot_.get();
1046 }
1047
1048 int64_t DisplayConfigurator::GetVirtualDisplayId() {
1049 for (const auto& display : cached_displays_) {
1050 if (display.display->type() == DISPLAY_CONNECTION_TYPE_VIRTUAL)
1051 return display.display->display_id();
1052 }
1053 return gfx::Display::kInvalidDisplayID;
1054 }
1055
1016 // static 1056 // static
1017 DisplayConfigurator* DisplayConfigurator::GetInstance() { 1057 DisplayConfigurator* DisplayConfigurator::GetInstance() {
1018 return Singleton<DisplayConfigurator>::get(); 1058 return Singleton<DisplayConfigurator>::get();
1019 } 1059 }
1020 1060
1021 } // namespace ui 1061 } // namespace ui
OLDNEW
« no previous file with comments | « ui/display/chromeos/display_configurator.h ('k') | ui/display/chromeos/display_configurator_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698