OLD | NEW |
---|---|
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/apply_content_protection_task.h" | 12 #include "ui/display/chromeos/apply_content_protection_task.h" |
13 #include "ui/display/chromeos/display_layout_manager.h" | 13 #include "ui/display/chromeos/display_layout_manager.h" |
14 #include "ui/display/chromeos/display_snapshot_virtual.h" | |
14 #include "ui/display/chromeos/display_util.h" | 15 #include "ui/display/chromeos/display_util.h" |
15 #include "ui/display/chromeos/update_display_configuration_task.h" | 16 #include "ui/display/chromeos/update_display_configuration_task.h" |
16 #include "ui/display/display_switches.h" | 17 #include "ui/display/display_switches.h" |
17 #include "ui/display/types/display_mode.h" | 18 #include "ui/display/types/display_mode.h" |
18 #include "ui/display/types/display_snapshot.h" | 19 #include "ui/display/types/display_snapshot.h" |
19 #include "ui/display/types/native_display_delegate.h" | 20 #include "ui/display/types/native_display_delegate.h" |
21 #include "ui/display/util/display_util.h" | |
22 #include "ui/gfx/display.h" | |
20 | 23 |
21 namespace ui { | 24 namespace ui { |
22 | 25 |
23 namespace { | 26 namespace { |
24 | 27 |
25 typedef std::vector<const DisplayMode*> DisplayModeList; | 28 typedef std::vector<const DisplayMode*> DisplayModeList; |
26 | 29 |
27 // The delay to perform configuration after RRNotify. See the comment for | 30 // The delay to perform configuration after RRNotify. See the comment for |
28 // |configure_timer_|. | 31 // |configure_timer_|. |
29 const int kConfigureDelayMs = 500; | 32 const int kConfigureDelayMs = 500; |
30 | 33 |
31 // The delay spent before reading the display configuration after coming out of | 34 // The delay spent before reading the display configuration after coming out of |
32 // suspend. While coming out of suspend the display state may be updating. This | 35 // suspend. While coming out of suspend the display state may be updating. This |
33 // is used to wait until the hardware had a chance to update the display state | 36 // is used to wait until the hardware had a chance to update the display state |
34 // such that we read an up to date state. | 37 // such that we read an up to date state. |
35 const int kResumeDelayMs = 500; | 38 const int kResumeDelayMs = 500; |
36 | 39 |
40 // The EDID specification marks the top bit of the manufacturer id as reserved. | |
41 const int16_t kReservedManufacturerID = 1 << 15; | |
42 | |
37 struct DisplayState { | 43 struct DisplayState { |
38 DisplaySnapshot* display = nullptr; // Not owned. | 44 DisplaySnapshot* display = nullptr; // Not owned. |
39 | 45 |
40 // User-selected mode for the display. | 46 // User-selected mode for the display. |
41 const DisplayMode* selected_mode = nullptr; | 47 const DisplayMode* selected_mode = nullptr; |
42 | 48 |
43 // Mode used when displaying the same desktop on multiple displays. | 49 // Mode used when displaying the same desktop on multiple displays. |
44 const DisplayMode* mirror_mode = nullptr; | 50 const DisplayMode* mirror_mode = nullptr; |
45 }; | 51 }; |
46 | 52 |
(...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
654 enable_protection_callbacks_.pop(); | 660 enable_protection_callbacks_.pop(); |
655 | 661 |
656 if (!content_protection_tasks_.empty()) | 662 if (!content_protection_tasks_.empty()) |
657 content_protection_tasks_.front().Run(); | 663 content_protection_tasks_.front().Run(); |
658 } | 664 } |
659 | 665 |
660 void DisplayConfigurator::QueryContentProtectionStatus( | 666 void DisplayConfigurator::QueryContentProtectionStatus( |
661 ContentProtectionClientId client_id, | 667 ContentProtectionClientId client_id, |
662 int64_t display_id, | 668 int64_t display_id, |
663 const QueryProtectionCallback& callback) { | 669 const QueryProtectionCallback& callback) { |
670 // Exclude virtual displays so that protected content will not be recaptured | |
671 // through the cast stream. | |
672 for (const DisplaySnapshot* display : cached_displays_) { | |
673 if (display->display_id() == display_id && | |
674 !IsPhysicalDisplayType(display->type())) { | |
675 callback.Run(QueryProtectionResponse()); | |
676 return; | |
677 } | |
678 } | |
679 | |
664 if (!configure_display_ || display_externally_controlled_) { | 680 if (!configure_display_ || display_externally_controlled_) { |
665 callback.Run(QueryProtectionResponse()); | 681 callback.Run(QueryProtectionResponse()); |
666 return; | 682 return; |
667 } | 683 } |
668 | 684 |
669 query_protection_callbacks_.push(callback); | 685 query_protection_callbacks_.push(callback); |
670 QueryContentProtectionTask* task = new QueryContentProtectionTask( | 686 QueryContentProtectionTask* task = new QueryContentProtectionTask( |
671 layout_manager_.get(), native_display_delegate_.get(), display_id, | 687 layout_manager_.get(), native_display_delegate_.get(), display_id, |
672 base::Bind(&DisplayConfigurator::OnContentProtectionQueried, | 688 base::Bind(&DisplayConfigurator::OnContentProtectionQueried, |
673 weak_ptr_factory_.GetWeakPtr(), client_id, display_id)); | 689 weak_ptr_factory_.GetWeakPtr(), client_id, display_id)); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
772 callback.Run(true); | 788 callback.Run(true); |
773 if (!content_protection_tasks_.empty()) | 789 if (!content_protection_tasks_.empty()) |
774 content_protection_tasks_.front().Run(); | 790 content_protection_tasks_.front().Run(); |
775 } | 791 } |
776 | 792 |
777 std::vector<ui::ColorCalibrationProfile> | 793 std::vector<ui::ColorCalibrationProfile> |
778 DisplayConfigurator::GetAvailableColorCalibrationProfiles(int64_t display_id) { | 794 DisplayConfigurator::GetAvailableColorCalibrationProfiles(int64_t display_id) { |
779 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | 795 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
780 switches::kDisableDisplayColorCalibration)) { | 796 switches::kDisableDisplayColorCalibration)) { |
781 for (const DisplaySnapshot* display : cached_displays_) { | 797 for (const DisplaySnapshot* display : cached_displays_) { |
782 if (display->display_id() == display_id) { | 798 if (display->display_id() == display_id && |
799 IsPhysicalDisplayType(display->type())) { | |
783 return native_display_delegate_->GetAvailableColorCalibrationProfiles( | 800 return native_display_delegate_->GetAvailableColorCalibrationProfiles( |
784 *display); | 801 *display); |
785 } | 802 } |
786 } | 803 } |
787 } | 804 } |
788 | 805 |
789 return std::vector<ui::ColorCalibrationProfile>(); | 806 return std::vector<ui::ColorCalibrationProfile>(); |
790 } | 807 } |
791 | 808 |
792 bool DisplayConfigurator::SetColorCalibrationProfile( | 809 bool DisplayConfigurator::SetColorCalibrationProfile( |
793 int64_t display_id, | 810 int64_t display_id, |
794 ui::ColorCalibrationProfile new_profile) { | 811 ui::ColorCalibrationProfile new_profile) { |
795 for (const DisplaySnapshot* display : cached_displays_) { | 812 for (const DisplaySnapshot* display : cached_displays_) { |
796 if (display->display_id() == display_id) { | 813 if (display->display_id() == display_id && |
814 IsPhysicalDisplayType(display->type())) { | |
797 return native_display_delegate_->SetColorCalibrationProfile(*display, | 815 return native_display_delegate_->SetColorCalibrationProfile(*display, |
798 new_profile); | 816 new_profile); |
799 } | 817 } |
800 } | 818 } |
801 | 819 |
802 return false; | 820 return false; |
803 } | 821 } |
804 | 822 |
805 bool DisplayConfigurator::SetGammaRamp( | 823 bool DisplayConfigurator::SetGammaRamp( |
806 int64_t display_id, | 824 int64_t display_id, |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
957 " requested"; | 975 " requested"; |
958 CallAndClearQueuedCallbacks(true); | 976 CallAndClearQueuedCallbacks(true); |
959 return; | 977 return; |
960 } | 978 } |
961 | 979 |
962 configuration_task_.reset(new UpdateDisplayConfigurationTask( | 980 configuration_task_.reset(new UpdateDisplayConfigurationTask( |
963 native_display_delegate_.get(), layout_manager_.get(), | 981 native_display_delegate_.get(), layout_manager_.get(), |
964 requested_display_state_, requested_power_state_, requested_power_flags_, | 982 requested_display_state_, requested_power_state_, requested_power_flags_, |
965 0, force_configure_, base::Bind(&DisplayConfigurator::OnConfigured, | 983 0, force_configure_, base::Bind(&DisplayConfigurator::OnConfigured, |
966 weak_ptr_factory_.GetWeakPtr()))); | 984 weak_ptr_factory_.GetWeakPtr()))); |
985 configuration_task_->set_virtual_display_snapshots( | |
986 virtual_display_snapshots_.get()); | |
967 | 987 |
968 // Reset the flags before running the task; otherwise it may end up scheduling | 988 // Reset the flags before running the task; otherwise it may end up scheduling |
969 // another configuration. | 989 // another configuration. |
970 force_configure_ = false; | 990 force_configure_ = false; |
971 requested_power_flags_ = kSetDisplayPowerNoFlags; | 991 requested_power_flags_ = kSetDisplayPowerNoFlags; |
972 requested_power_state_change_ = false; | 992 requested_power_state_change_ = false; |
973 requested_display_state_ = MULTIPLE_DISPLAY_STATE_INVALID; | 993 requested_display_state_ = MULTIPLE_DISPLAY_STATE_INVALID; |
974 | 994 |
975 DCHECK(in_progress_configuration_callbacks_.empty()); | 995 DCHECK(in_progress_configuration_callbacks_.empty()); |
976 in_progress_configuration_callbacks_.swap(queued_configuration_callbacks_); | 996 in_progress_configuration_callbacks_.swap(queued_configuration_callbacks_); |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1072 if (success) { | 1092 if (success) { |
1073 FOR_EACH_OBSERVER( | 1093 FOR_EACH_OBSERVER( |
1074 Observer, observers_, OnDisplayModeChanged(cached_displays_)); | 1094 Observer, observers_, OnDisplayModeChanged(cached_displays_)); |
1075 } else { | 1095 } else { |
1076 FOR_EACH_OBSERVER( | 1096 FOR_EACH_OBSERVER( |
1077 Observer, observers_, OnDisplayModeChangeFailed(cached_displays_, | 1097 Observer, observers_, OnDisplayModeChangeFailed(cached_displays_, |
1078 attempted_state)); | 1098 attempted_state)); |
1079 } | 1099 } |
1080 } | 1100 } |
1081 | 1101 |
1102 int64_t DisplayConfigurator::AddVirtualDisplay(gfx::Size display_size) { | |
1103 if (last_virtual_display_id_ == 0xff) { | |
1104 LOG(WARNING) << "Exceeded virtual display id limit"; | |
1105 return gfx::Display::kInvalidDisplayID; | |
1106 } | |
1107 | |
1108 DisplaySnapshotVirtual* virtual_snapshot = | |
1109 new DisplaySnapshotVirtual(GenerateDisplayID(kReservedManufacturerID, 0x0, | |
1110 ++last_virtual_display_id_), | |
1111 display_size); | |
1112 virtual_display_snapshots_.push_back(virtual_snapshot); | |
1113 ConfigureDisplays(); | |
1114 | |
1115 return virtual_snapshot->display_id(); | |
1116 } | |
1117 | |
1118 bool DisplayConfigurator::RemoveVirtualDisplay(int64_t display_id) { | |
1119 bool display_found = false; | |
1120 for (auto it = virtual_display_snapshots_.begin(); | |
1121 it != virtual_display_snapshots_.end(); ++it) { | |
1122 if ((*it)->display_id() == display_id) { | |
1123 virtual_display_snapshots_.erase(it); | |
1124 ConfigureDisplays(); | |
1125 display_found = true; | |
1126 break; | |
1127 } | |
1128 } | |
1129 | |
1130 if (!display_found) | |
1131 return false; | |
1132 | |
1133 int64_t highest_virtual_display_id = 0; | |
1134 for (const auto& display : virtual_display_snapshots_) { | |
1135 if (display->display_id() > highest_virtual_display_id) | |
1136 highest_virtual_display_id = display->display_id(); | |
oshima
2015/12/03 18:54:07
optional: std::max if it fits in the single line (
| |
1137 } | |
1138 last_virtual_display_id_ = highest_virtual_display_id & 0xff; | |
1139 | |
1140 return true; | |
1141 } | |
1142 | |
1082 } // namespace ui | 1143 } // namespace ui |
OLD | NEW |