OLD | NEW |
---|---|
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 "chromeos/display/output_configurator.h" | 5 #include "chromeos/display/output_configurator.h" |
6 | 6 |
7 #include <X11/Xlib.h> | 7 #include <X11/Xlib.h> |
8 #include <X11/extensions/Xrandr.h> | 8 #include <X11/extensions/Xrandr.h> |
9 #include <X11/extensions/XInput2.h> | 9 #include <X11/extensions/XInput2.h> |
10 | 10 |
(...skipping 923 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
934 OutputSnapshot* output = &updated_outputs[i]; | 934 OutputSnapshot* output = &updated_outputs[i]; |
935 if (output->touch_device_id) | 935 if (output->touch_device_id) |
936 output->transform = GetExtendedModeCTM(*output, width, height); | 936 output->transform = GetExtendedModeCTM(*output, width, height); |
937 } | 937 } |
938 break; | 938 break; |
939 } | 939 } |
940 } | 940 } |
941 | 941 |
942 // Finally, apply the desired changes. | 942 // Finally, apply the desired changes. |
943 DCHECK_EQ(cached_outputs_.size(), updated_outputs.size()); | 943 DCHECK_EQ(cached_outputs_.size(), updated_outputs.size()); |
944 bool all_succeeded = true; | |
944 if (!updated_outputs.empty()) { | 945 if (!updated_outputs.empty()) { |
945 delegate_->CreateFrameBuffer(width, height, updated_outputs); | 946 delegate_->CreateFrameBuffer(width, height, updated_outputs); |
946 for (size_t i = 0; i < updated_outputs.size(); ++i) { | 947 for (size_t i = 0; i < updated_outputs.size(); ++i) { |
947 const OutputSnapshot& output = updated_outputs[i]; | 948 const OutputSnapshot& output = updated_outputs[i]; |
948 if (delegate_->ConfigureCrtc(output.crtc, output.current_mode, | 949 bool configure_succeeded; |
949 output.output, output.x, output.y)) { | 950 |
950 if (output.touch_device_id) | 951 while (true) { |
951 delegate_->ConfigureCTM(output.touch_device_id, output.transform); | 952 configure_succeeded = false; |
Daniel Erat
2014/01/09 00:40:34
nit: just initialize the variable to false where i
| |
952 cached_outputs_[i] = updated_outputs[i]; | 953 if (delegate_->ConfigureCrtc(output.crtc, output.current_mode, |
953 } else { | 954 output.output, output.x, output.y)) { |
955 configure_succeeded = true; | |
956 break; | |
957 } | |
958 | |
954 LOG(WARNING) << "Unable to configure CRTC " << output.crtc << ":" | 959 LOG(WARNING) << "Unable to configure CRTC " << output.crtc << ":" |
955 << " mode=" << output.current_mode | 960 << " mode=" << output.current_mode |
956 << " output=" << output.output | 961 << " output=" << output.output |
957 << " x=" << output.x | 962 << " x=" << output.x |
958 << " y=" << output.y; | 963 << " y=" << output.y; |
964 | |
965 const ModeInfo* mode_info = GetModeInfo(output, output.current_mode); | |
966 if (!mode_info) | |
967 break; | |
968 | |
969 // Find the mode with the next-best resolution and see if that can | |
970 // be set. | |
971 int best_mode_pixels = 0; | |
972 | |
973 int current_mode_pixels = mode_info->width * mode_info->height; | |
974 for (ModeInfoMap::const_iterator it = output.mode_infos.begin(); | |
975 it != output.mode_infos.end(); it++) { | |
976 int pixel_count = it->second.width * it->second.height; | |
977 if ((pixel_count < current_mode_pixels) && | |
978 (pixel_count > best_mode_pixels)) { | |
979 updated_outputs[i].current_mode = it->first; | |
980 best_mode_pixels = pixel_count; | |
981 } | |
982 } | |
983 | |
984 if (best_mode_pixels == 0) | |
985 break; | |
959 } | 986 } |
987 | |
988 if (configure_succeeded) { | |
989 if (output.touch_device_id) | |
990 delegate_->ConfigureCTM(output.touch_device_id, output.transform); | |
991 cached_outputs_[i] = updated_outputs[i]; | |
992 } else { | |
993 all_succeeded = false; | |
994 } | |
995 | |
996 // If we are trying to set mirror mode and one of the modesets fails, | |
997 // then the two monitors will be mis-matched. In this case, return | |
998 // false to let the observers be aware. | |
999 if (output_state == STATE_DUAL_MIRROR && | |
1000 output_power[i] && | |
1001 output.current_mode != output.mirror_mode) | |
1002 all_succeeded = false; | |
1003 | |
960 } | 1004 } |
961 } | 1005 } |
962 | 1006 |
963 output_state_ = output_state; | 1007 if (all_succeeded) { |
964 power_state_ = power_state; | 1008 output_state_ = output_state; |
965 return true; | 1009 power_state_ = power_state; |
1010 } | |
1011 return all_succeeded; | |
966 } | 1012 } |
967 | 1013 |
968 OutputState OutputConfigurator::ChooseOutputState( | 1014 OutputState OutputConfigurator::ChooseOutputState( |
969 DisplayPowerState power_state) const { | 1015 DisplayPowerState power_state) const { |
970 int num_on_outputs = GetOutputPower(cached_outputs_, power_state, NULL); | 1016 int num_on_outputs = GetOutputPower(cached_outputs_, power_state, NULL); |
971 switch (cached_outputs_.size()) { | 1017 switch (cached_outputs_.size()) { |
972 case 0: | 1018 case 0: |
973 return STATE_HEADLESS; | 1019 return STATE_HEADLESS; |
974 case 1: | 1020 case 1: |
975 return STATE_SINGLE; | 1021 return STATE_SINGLE; |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1085 float width_ratio = static_cast<float>(mirror_mode_info->width) / | 1131 float width_ratio = static_cast<float>(mirror_mode_info->width) / |
1086 static_cast<float>(native_mode_info->width); | 1132 static_cast<float>(native_mode_info->width); |
1087 float height_ratio = static_cast<float>(mirror_mode_info->height) / | 1133 float height_ratio = static_cast<float>(mirror_mode_info->height) / |
1088 static_cast<float>(native_mode_info->height); | 1134 static_cast<float>(native_mode_info->height); |
1089 | 1135 |
1090 area_ratio = width_ratio * height_ratio; | 1136 area_ratio = width_ratio * height_ratio; |
1091 return area_ratio; | 1137 return area_ratio; |
1092 } | 1138 } |
1093 | 1139 |
1094 } // namespace chromeos | 1140 } // namespace chromeos |
OLD | NEW |