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 794 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
805 } | 805 } |
806 mirroring_controller_->SetSoftwareMirroring(enable_software_mirroring); | 806 mirroring_controller_->SetSoftwareMirroring(enable_software_mirroring); |
807 } | 807 } |
808 return success; | 808 return success; |
809 } | 809 } |
810 | 810 |
811 bool OutputConfigurator::EnterState( | 811 bool OutputConfigurator::EnterState( |
812 OutputState output_state, | 812 OutputState output_state, |
813 DisplayPowerState power_state) { | 813 DisplayPowerState power_state) { |
814 std::vector<bool> output_power; | 814 std::vector<bool> output_power; |
815 bool status; | |
Daniel Erat
2014/01/08 21:40:28
move this down to the point where you need it, and
dsodman
2014/01/09 00:26:28
Done.
| |
815 int num_on_outputs = GetOutputPower( | 816 int num_on_outputs = GetOutputPower( |
816 cached_outputs_, power_state, &output_power); | 817 cached_outputs_, power_state, &output_power); |
817 VLOG(1) << "EnterState: output=" << OutputStateToString(output_state) | 818 VLOG(1) << "EnterState: output=" << OutputStateToString(output_state) |
818 << " power=" << DisplayPowerStateToString(power_state); | 819 << " power=" << DisplayPowerStateToString(power_state); |
819 | 820 |
820 // Framebuffer dimensions. | 821 // Framebuffer dimensions. |
821 int width = 0, height = 0; | 822 int width = 0, height = 0; |
822 std::vector<OutputSnapshot> updated_outputs = cached_outputs_; | 823 std::vector<OutputSnapshot> updated_outputs = cached_outputs_; |
823 | 824 |
824 switch (output_state) { | 825 switch (output_state) { |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
934 OutputSnapshot* output = &updated_outputs[i]; | 935 OutputSnapshot* output = &updated_outputs[i]; |
935 if (output->touch_device_id) | 936 if (output->touch_device_id) |
936 output->transform = GetExtendedModeCTM(*output, width, height); | 937 output->transform = GetExtendedModeCTM(*output, width, height); |
937 } | 938 } |
938 break; | 939 break; |
939 } | 940 } |
940 } | 941 } |
941 | 942 |
942 // Finally, apply the desired changes. | 943 // Finally, apply the desired changes. |
943 DCHECK_EQ(cached_outputs_.size(), updated_outputs.size()); | 944 DCHECK_EQ(cached_outputs_.size(), updated_outputs.size()); |
945 status = true; | |
944 if (!updated_outputs.empty()) { | 946 if (!updated_outputs.empty()) { |
945 delegate_->CreateFrameBuffer(width, height, updated_outputs); | 947 delegate_->CreateFrameBuffer(width, height, updated_outputs); |
946 for (size_t i = 0; i < updated_outputs.size(); ++i) { | 948 for (size_t i = 0; i < updated_outputs.size(); ++i) { |
947 const OutputSnapshot& output = updated_outputs[i]; | 949 const OutputSnapshot& output = updated_outputs[i]; |
948 if (delegate_->ConfigureCrtc(output.crtc, output.current_mode, | 950 while (!delegate_->ConfigureCrtc(output.crtc, output.current_mode, |
949 output.output, output.x, output.y)) { | 951 output.output, output.x, output.y)) { |
950 if (output.touch_device_id) | |
951 delegate_->ConfigureCTM(output.touch_device_id, output.transform); | |
952 cached_outputs_[i] = updated_outputs[i]; | |
953 } else { | |
954 LOG(WARNING) << "Unable to configure CRTC " << output.crtc << ":" | 952 LOG(WARNING) << "Unable to configure CRTC " << output.crtc << ":" |
955 << " mode=" << output.current_mode | 953 << " mode=" << output.current_mode |
956 << " output=" << output.output | 954 << " output=" << output.output |
957 << " x=" << output.x | 955 << " x=" << output.x |
958 << " y=" << output.y; | 956 << " y=" << output.y; |
957 | |
958 // Find the mode with the next-best resolution and see if that can | |
959 // be set. | |
960 int best_mode_pixels = 0; | |
961 const ModeInfo* mode_info = GetModeInfo(output, output.current_mode); | |
962 if (!mode_info) | |
963 break; | |
964 | |
965 int current_mode_pixels = mode_info->width * mode_info->height; | |
966 for (ModeInfoMap::const_iterator it = output.mode_infos.begin(); | |
967 it != output.mode_infos.end(); it++) { | |
Daniel Erat
2014/01/08 21:40:28
nit: indent one more space
dsodman
2014/01/09 00:26:28
Done.
| |
968 int pixel_count = it->second.width * it->second.height; | |
969 if ((pixel_count < current_mode_pixels) && | |
970 (pixel_count > best_mode_pixels)) { | |
971 updated_outputs[i].current_mode = it->first; | |
972 best_mode_pixels = pixel_count; | |
973 } | |
974 } | |
975 | |
976 if (best_mode_pixels == 0) | |
977 break; | |
959 } | 978 } |
979 | |
980 // If we are trying to set mirror mode and one of the modeset's fails, | |
Daniel Erat
2014/01/08 21:40:28
nit: s/modeset's/modesets/
dsodman
2014/01/09 00:26:28
Done.
| |
981 // then the two monitors will be mis-matched. In this case, return | |
982 // false to let the observers be aware. | |
983 if (output_state == STATE_DUAL_MIRROR && | |
984 output_power[i] && | |
985 output.current_mode != output.mirror_mode) { | |
986 status = false; | |
987 } | |
988 | |
989 if (output.touch_device_id) | |
990 delegate_->ConfigureCTM(output.touch_device_id, output.transform); | |
991 cached_outputs_[i] = updated_outputs[i]; | |
Daniel Erat
2014/01/08 21:40:28
ConfigureCTM() should only be run and cached_outpu
dsodman
2014/01/09 00:26:28
To be honest, I am not entirely sure what is the i
Daniel Erat
2014/01/09 00:40:34
i'm not an expert on the touch code, but i believe
| |
960 } | 992 } |
961 } | 993 } |
962 | 994 |
963 output_state_ = output_state; | 995 output_state_ = output_state; |
964 power_state_ = power_state; | 996 power_state_ = power_state; |
965 return true; | 997 return status; |
Daniel Erat
2014/01/08 21:40:28
i'm also not sure whether output_state_ and power_
dsodman
2014/01/09 00:26:28
Done.
| |
966 } | 998 } |
967 | 999 |
968 OutputState OutputConfigurator::ChooseOutputState( | 1000 OutputState OutputConfigurator::ChooseOutputState( |
969 DisplayPowerState power_state) const { | 1001 DisplayPowerState power_state) const { |
970 int num_on_outputs = GetOutputPower(cached_outputs_, power_state, NULL); | 1002 int num_on_outputs = GetOutputPower(cached_outputs_, power_state, NULL); |
971 switch (cached_outputs_.size()) { | 1003 switch (cached_outputs_.size()) { |
972 case 0: | 1004 case 0: |
973 return STATE_HEADLESS; | 1005 return STATE_HEADLESS; |
974 case 1: | 1006 case 1: |
975 return STATE_SINGLE; | 1007 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) / | 1117 float width_ratio = static_cast<float>(mirror_mode_info->width) / |
1086 static_cast<float>(native_mode_info->width); | 1118 static_cast<float>(native_mode_info->width); |
1087 float height_ratio = static_cast<float>(mirror_mode_info->height) / | 1119 float height_ratio = static_cast<float>(mirror_mode_info->height) / |
1088 static_cast<float>(native_mode_info->height); | 1120 static_cast<float>(native_mode_info->height); |
1089 | 1121 |
1090 area_ratio = width_ratio * height_ratio; | 1122 area_ratio = width_ratio * height_ratio; |
1091 return area_ratio; | 1123 return area_ratio; |
1092 } | 1124 } |
1093 | 1125 |
1094 } // namespace chromeos | 1126 } // namespace chromeos |
OLD | NEW |