| 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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 // on/off state of each corresponding entry in |outputs|. | 87 // on/off state of each corresponding entry in |outputs|. |
| 88 int GetOutputPower( | 88 int GetOutputPower( |
| 89 const std::vector<OutputConfigurator::OutputSnapshot>& outputs, | 89 const std::vector<OutputConfigurator::OutputSnapshot>& outputs, |
| 90 DisplayPowerState state, | 90 DisplayPowerState state, |
| 91 std::vector<bool>* output_power) { | 91 std::vector<bool>* output_power) { |
| 92 int num_on_outputs = 0; | 92 int num_on_outputs = 0; |
| 93 if (output_power) | 93 if (output_power) |
| 94 output_power->resize(outputs.size()); | 94 output_power->resize(outputs.size()); |
| 95 | 95 |
| 96 for (size_t i = 0; i < outputs.size(); ++i) { | 96 for (size_t i = 0; i < outputs.size(); ++i) { |
| 97 bool internal = outputs[i].is_internal; | 97 bool internal = outputs[i].type == OUTPUT_TYPE_INTERNAL; |
| 98 bool on = state == DISPLAY_POWER_ALL_ON || | 98 bool on = state == DISPLAY_POWER_ALL_ON || |
| 99 (state == DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON && !internal) || | 99 (state == DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON && !internal) || |
| 100 (state == DISPLAY_POWER_INTERNAL_ON_EXTERNAL_OFF && internal); | 100 (state == DISPLAY_POWER_INTERNAL_ON_EXTERNAL_OFF && internal); |
| 101 if (output_power) | 101 if (output_power) |
| 102 (*output_power)[i] = on; | 102 (*output_power)[i] = on; |
| 103 if (on) | 103 if (on) |
| 104 num_on_outputs++; | 104 num_on_outputs++; |
| 105 } | 105 } |
| 106 return num_on_outputs; | 106 return num_on_outputs; |
| 107 } | 107 } |
| 108 | 108 |
| 109 // Determine if there is an "internal" output and how many outputs are | 109 // Determine if there is an "internal" output and how many outputs are |
| 110 // connected. | 110 // connected. |
| 111 bool IsProjecting( | 111 bool IsProjecting( |
| 112 const std::vector<OutputConfigurator::OutputSnapshot>& outputs) { | 112 const std::vector<OutputConfigurator::OutputSnapshot>& outputs) { |
| 113 bool has_internal_output = false; | 113 bool has_internal_output = false; |
| 114 int connected_output_count = outputs.size(); | 114 int connected_output_count = outputs.size(); |
| 115 for (size_t i = 0; i < outputs.size(); ++i) | 115 for (size_t i = 0; i < outputs.size(); ++i) |
| 116 has_internal_output |= outputs[i].is_internal; | 116 has_internal_output |= outputs[i].type == OUTPUT_TYPE_INTERNAL; |
| 117 | 117 |
| 118 // "Projecting" is defined as having more than 1 output connected while at | 118 // "Projecting" is defined as having more than 1 output connected while at |
| 119 // least one of them is an internal output. | 119 // least one of them is an internal output. |
| 120 return has_internal_output && (connected_output_count > 1); | 120 return has_internal_output && (connected_output_count > 1); |
| 121 } | 121 } |
| 122 | 122 |
| 123 } // namespace | 123 } // namespace |
| 124 | 124 |
| 125 OutputConfigurator::ModeInfo::ModeInfo() | 125 OutputConfigurator::ModeInfo::ModeInfo() |
| 126 : width(0), | 126 : width(0), |
| (...skipping 20 matching lines...) Expand all Loading... |
| 147 : output(None), | 147 : output(None), |
| 148 crtc(None), | 148 crtc(None), |
| 149 current_mode(None), | 149 current_mode(None), |
| 150 native_mode(None), | 150 native_mode(None), |
| 151 mirror_mode(None), | 151 mirror_mode(None), |
| 152 selected_mode(None), | 152 selected_mode(None), |
| 153 x(0), | 153 x(0), |
| 154 y(0), | 154 y(0), |
| 155 width_mm(0), | 155 width_mm(0), |
| 156 height_mm(0), | 156 height_mm(0), |
| 157 is_internal(false), | |
| 158 is_aspect_preserving_scaling(false), | 157 is_aspect_preserving_scaling(false), |
| 159 type(OUTPUT_TYPE_UNKNOWN), | 158 type(OUTPUT_TYPE_UNKNOWN), |
| 160 touch_device_id(0), | 159 touch_device_id(0), |
| 161 display_id(0), | 160 display_id(0), |
| 162 has_display_id(false), | 161 has_display_id(false), |
| 163 index(0) {} | 162 index(0) {} |
| 164 | 163 |
| 165 OutputConfigurator::OutputSnapshot::~OutputSnapshot() {} | 164 OutputConfigurator::OutputSnapshot::~OutputSnapshot() {} |
| 166 | 165 |
| 167 void OutputConfigurator::TestApi::SendScreenChangeEvent() { | 166 void OutputConfigurator::TestApi::SendScreenChangeEvent() { |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 477 delegate_->GrabServer(); | 476 delegate_->GrabServer(); |
| 478 UpdateCachedOutputs(); | 477 UpdateCachedOutputs(); |
| 479 | 478 |
| 480 const OutputState new_state = ChooseOutputState(power_state); | 479 const OutputState new_state = ChooseOutputState(power_state); |
| 481 bool attempted_change = false; | 480 bool attempted_change = false; |
| 482 bool success = false; | 481 bool success = false; |
| 483 | 482 |
| 484 bool only_if_single_internal_display = | 483 bool only_if_single_internal_display = |
| 485 flags & kSetDisplayPowerOnlyIfSingleInternalDisplay; | 484 flags & kSetDisplayPowerOnlyIfSingleInternalDisplay; |
| 486 bool single_internal_display = | 485 bool single_internal_display = |
| 487 cached_outputs_.size() == 1 && cached_outputs_[0].is_internal; | 486 cached_outputs_.size() == 1 && |
| 487 cached_outputs_[0].type == OUTPUT_TYPE_INTERNAL; |
| 488 if (single_internal_display || !only_if_single_internal_display) { | 488 if (single_internal_display || !only_if_single_internal_display) { |
| 489 success = EnterStateOrFallBackToSoftwareMirroring(new_state, power_state); | 489 success = EnterStateOrFallBackToSoftwareMirroring(new_state, power_state); |
| 490 attempted_change = true; | 490 attempted_change = true; |
| 491 | 491 |
| 492 // Force the DPMS on since the driver doesn't always detect that it | 492 // Force the DPMS on since the driver doesn't always detect that it |
| 493 // should turn on. This is needed when coming back from idle suspend. | 493 // should turn on. This is needed when coming back from idle suspend. |
| 494 if (success && power_state != DISPLAY_POWER_ALL_OFF) | 494 if (success && power_state != DISPLAY_POWER_ALL_OFF) |
| 495 delegate_->ForceDPMSOn(); | 495 delegate_->ForceDPMSOn(); |
| 496 } | 496 } |
| 497 | 497 |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 658 FindOutputModeMatchingSize(*output, width, height); | 658 FindOutputModeMatchingSize(*output, width, height); |
| 659 } | 659 } |
| 660 } | 660 } |
| 661 // Fall back to native mode. | 661 // Fall back to native mode. |
| 662 if (output->selected_mode == None) | 662 if (output->selected_mode == None) |
| 663 output->selected_mode = output->native_mode; | 663 output->selected_mode = output->native_mode; |
| 664 } | 664 } |
| 665 | 665 |
| 666 // Set |mirror_mode| fields. | 666 // Set |mirror_mode| fields. |
| 667 if (cached_outputs_.size() == 2) { | 667 if (cached_outputs_.size() == 2) { |
| 668 bool one_is_internal = cached_outputs_[0].is_internal; | 668 bool one_is_internal = cached_outputs_[0].type == OUTPUT_TYPE_INTERNAL; |
| 669 bool two_is_internal = cached_outputs_[1].is_internal; | 669 bool two_is_internal = cached_outputs_[1].type == OUTPUT_TYPE_INTERNAL; |
| 670 int internal_outputs = (one_is_internal ? 1 : 0) + | 670 int internal_outputs = (one_is_internal ? 1 : 0) + |
| 671 (two_is_internal ? 1 : 0); | 671 (two_is_internal ? 1 : 0); |
| 672 DCHECK_LT(internal_outputs, 2); | 672 DCHECK_LT(internal_outputs, 2); |
| 673 LOG_IF(WARNING, internal_outputs == 2) | 673 LOG_IF(WARNING, internal_outputs == 2) |
| 674 << "Two internal outputs detected."; | 674 << "Two internal outputs detected."; |
| 675 | 675 |
| 676 bool can_mirror = false; | 676 bool can_mirror = false; |
| 677 for (int attempt = 0; !can_mirror && attempt < 2; ++attempt) { | 677 for (int attempt = 0; !can_mirror && attempt < 2; ++attempt) { |
| 678 // Try preserving external output's aspect ratio on the first attempt. | 678 // Try preserving external output's aspect ratio on the first attempt. |
| 679 // If that fails, fall back to the highest matching resolution. | 679 // If that fails, fall back to the highest matching resolution. |
| (...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1130 float width_ratio = static_cast<float>(mirror_mode_info->width) / | 1130 float width_ratio = static_cast<float>(mirror_mode_info->width) / |
| 1131 static_cast<float>(native_mode_info->width); | 1131 static_cast<float>(native_mode_info->width); |
| 1132 float height_ratio = static_cast<float>(mirror_mode_info->height) / | 1132 float height_ratio = static_cast<float>(mirror_mode_info->height) / |
| 1133 static_cast<float>(native_mode_info->height); | 1133 static_cast<float>(native_mode_info->height); |
| 1134 | 1134 |
| 1135 area_ratio = width_ratio * height_ratio; | 1135 area_ratio = width_ratio * height_ratio; |
| 1136 return area_ratio; | 1136 return area_ratio; |
| 1137 } | 1137 } |
| 1138 | 1138 |
| 1139 } // namespace chromeos | 1139 } // namespace chromeos |
| OLD | NEW |