| 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 <cstdarg> | 7 #include <cstdarg> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 | 107 |
| 108 // Returns a comma-separated string describing the actions that were | 108 // Returns a comma-separated string describing the actions that were |
| 109 // requested since the previous call to GetActionsAndClear() (i.e. | 109 // requested since the previous call to GetActionsAndClear() (i.e. |
| 110 // results are non-repeatable). | 110 // results are non-repeatable). |
| 111 std::string GetActionsAndClear() { | 111 std::string GetActionsAndClear() { |
| 112 std::string actions = actions_; | 112 std::string actions = actions_; |
| 113 actions_.clear(); | 113 actions_.clear(); |
| 114 return actions; | 114 return actions; |
| 115 } | 115 } |
| 116 | 116 |
| 117 // Adds a mode to be returned by GetModeDetails(). | |
| 118 void AddMode(RRMode mode, int width, int height, bool interlaced) { | |
| 119 modes_[mode] = ModeDetails(width, height, interlaced); | |
| 120 } | |
| 121 | |
| 122 // OutputConfigurator::Delegate overrides: | 117 // OutputConfigurator::Delegate overrides: |
| 123 virtual void SetPanelFittingEnabled(bool enabled) OVERRIDE {} | 118 virtual void SetPanelFittingEnabled(bool enabled) OVERRIDE {} |
| 124 virtual void InitXRandRExtension(int* event_base) OVERRIDE { | 119 virtual void InitXRandRExtension(int* event_base) OVERRIDE { |
| 125 AppendAction(kInitXRandR); | 120 AppendAction(kInitXRandR); |
| 126 *event_base = kXRandREventBase; | 121 *event_base = kXRandREventBase; |
| 127 } | 122 } |
| 128 virtual void UpdateXRandRConfiguration( | 123 virtual void UpdateXRandRConfiguration( |
| 129 const base::NativeEvent& event) OVERRIDE { AppendAction(kUpdateXRandR); } | 124 const base::NativeEvent& event) OVERRIDE { AppendAction(kUpdateXRandR); } |
| 130 virtual void GrabServer() OVERRIDE { AppendAction(kGrab); } | 125 virtual void GrabServer() OVERRIDE { AppendAction(kGrab); } |
| 131 virtual void UngrabServer() OVERRIDE { AppendAction(kUngrab); } | 126 virtual void UngrabServer() OVERRIDE { AppendAction(kUngrab); } |
| 132 virtual void SyncWithServer() OVERRIDE { AppendAction(kSync); } | 127 virtual void SyncWithServer() OVERRIDE { AppendAction(kSync); } |
| 133 virtual void SetBackgroundColor(uint32 color_argb) OVERRIDE { | 128 virtual void SetBackgroundColor(uint32 color_argb) OVERRIDE { |
| 134 AppendAction(GetBackgroundAction(color_argb)); | 129 AppendAction(GetBackgroundAction(color_argb)); |
| 135 } | 130 } |
| 136 virtual void ForceDPMSOn() OVERRIDE { AppendAction(kForceDPMS); } | 131 virtual void ForceDPMSOn() OVERRIDE { AppendAction(kForceDPMS); } |
| 137 virtual std::vector<OutputConfigurator::OutputSnapshot> GetOutputs( | 132 virtual std::vector<OutputConfigurator::OutputSnapshot> GetOutputs( |
| 138 const OutputConfigurator::StateController* controller) OVERRIDE { | 133 const OutputConfigurator::StateController* controller) OVERRIDE { |
| 139 return outputs_; | 134 return outputs_; |
| 140 } | 135 } |
| 141 virtual bool GetModeDetails( | |
| 142 RRMode mode, | |
| 143 int* width, | |
| 144 int* height, | |
| 145 bool* interlaced) OVERRIDE { | |
| 146 std::map<RRMode, ModeDetails>::const_iterator it = modes_.find(mode); | |
| 147 if (it == modes_.end()) | |
| 148 return false; | |
| 149 | |
| 150 if (width) | |
| 151 *width = it->second.width; | |
| 152 if (height) | |
| 153 *height = it->second.height; | |
| 154 if (interlaced) | |
| 155 *interlaced = it->second.interlaced; | |
| 156 return true; | |
| 157 } | |
| 158 virtual bool ConfigureCrtc(RRCrtc crtc, | 136 virtual bool ConfigureCrtc(RRCrtc crtc, |
| 159 RRMode mode, | 137 RRMode mode, |
| 160 RROutput output, | 138 RROutput output, |
| 161 int x, | 139 int x, |
| 162 int y) OVERRIDE { | 140 int y) OVERRIDE { |
| 163 AppendAction(GetCrtcAction(crtc, x, y, mode, output)); | 141 AppendAction(GetCrtcAction(crtc, x, y, mode, output)); |
| 164 return configure_crtc_result_; | 142 return configure_crtc_result_; |
| 165 } | 143 } |
| 166 virtual void CreateFrameBuffer( | 144 virtual void CreateFrameBuffer( |
| 167 int width, | 145 int width, |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 : test_api_(&configurator_, TestDelegate::kXRandREventBase) {} | 241 : test_api_(&configurator_, TestDelegate::kXRandREventBase) {} |
| 264 virtual ~OutputConfiguratorTest() {} | 242 virtual ~OutputConfiguratorTest() {} |
| 265 | 243 |
| 266 virtual void SetUp() OVERRIDE { | 244 virtual void SetUp() OVERRIDE { |
| 267 delegate_ = new TestDelegate(); | 245 delegate_ = new TestDelegate(); |
| 268 configurator_.SetDelegateForTesting( | 246 configurator_.SetDelegateForTesting( |
| 269 scoped_ptr<OutputConfigurator::Delegate>(delegate_)); | 247 scoped_ptr<OutputConfigurator::Delegate>(delegate_)); |
| 270 configurator_.set_state_controller(&state_controller_); | 248 configurator_.set_state_controller(&state_controller_); |
| 271 configurator_.set_mirroring_controller(&mirroring_controller_); | 249 configurator_.set_mirroring_controller(&mirroring_controller_); |
| 272 | 250 |
| 251 OutputConfigurator::ModeInfo small_mode_info; |
| 252 small_mode_info.width = kSmallModeWidth; |
| 253 small_mode_info.height = kSmallModeHeight; |
| 254 |
| 255 OutputConfigurator::ModeInfo big_mode_info; |
| 256 big_mode_info.width = kBigModeWidth; |
| 257 big_mode_info.height = kBigModeHeight; |
| 258 |
| 273 OutputConfigurator::OutputSnapshot* o = &outputs_[0]; | 259 OutputConfigurator::OutputSnapshot* o = &outputs_[0]; |
| 274 o->output = 1; | 260 o->output = 1; |
| 275 o->crtc = 10; | 261 o->crtc = 10; |
| 276 o->current_mode = kSmallModeId; | 262 o->current_mode = kSmallModeId; |
| 277 o->native_mode = kSmallModeId; | 263 o->native_mode = kSmallModeId; |
| 278 o->selected_mode = kSmallModeId; | 264 o->selected_mode = kSmallModeId; |
| 279 o->mirror_mode = kSmallModeId; | 265 o->mirror_mode = kSmallModeId; |
| 280 o->x = 0; | 266 o->x = 0; |
| 281 o->y = 0; | 267 o->y = 0; |
| 282 o->is_internal = true; | 268 o->is_internal = true; |
| 283 o->is_aspect_preserving_scaling = true; | 269 o->is_aspect_preserving_scaling = true; |
| 270 o->mode_infos[kSmallModeId] = small_mode_info; |
| 284 o->touch_device_id = 0; | 271 o->touch_device_id = 0; |
| 285 o->has_display_id = true; | 272 o->has_display_id = true; |
| 286 | 273 |
| 287 o = &outputs_[1]; | 274 o = &outputs_[1]; |
| 288 o->output = 2; | 275 o->output = 2; |
| 289 o->crtc = 11; | 276 o->crtc = 11; |
| 290 o->current_mode = kBigModeId; | 277 o->current_mode = kBigModeId; |
| 291 o->native_mode = kBigModeId; | 278 o->native_mode = kBigModeId; |
| 292 o->selected_mode = kBigModeId; | 279 o->selected_mode = kBigModeId; |
| 293 o->mirror_mode = kSmallModeId; | 280 o->mirror_mode = kSmallModeId; |
| 294 o->x = 0; | 281 o->x = 0; |
| 295 o->y = 0; | 282 o->y = 0; |
| 296 o->is_internal = false; | 283 o->is_internal = false; |
| 297 o->is_aspect_preserving_scaling = true; | 284 o->is_aspect_preserving_scaling = true; |
| 285 o->mode_infos[kSmallModeId] = small_mode_info; |
| 286 o->mode_infos[kBigModeId] = big_mode_info; |
| 298 o->touch_device_id = 0; | 287 o->touch_device_id = 0; |
| 299 o->has_display_id = true; | 288 o->has_display_id = true; |
| 300 | 289 |
| 301 UpdateOutputs(2, false); | 290 UpdateOutputs(2, false); |
| 302 delegate_->AddMode(kSmallModeId, kSmallModeWidth, kSmallModeHeight, false); | |
| 303 delegate_->AddMode(kBigModeId, kBigModeWidth, kBigModeHeight, false); | |
| 304 } | 291 } |
| 305 | 292 |
| 306 void DisableNativeMirroring() { | 293 void DisableNativeMirroring() { |
| 307 outputs_[0].mirror_mode = outputs_[1].mirror_mode = 0L; | 294 outputs_[0].mirror_mode = outputs_[1].mirror_mode = 0L; |
| 308 } | 295 } |
| 309 | 296 |
| 310 protected: | 297 protected: |
| 311 // Predefined modes that can be used by outputs. | 298 // Predefined modes that can be used by outputs. |
| 312 static const int kSmallModeId = 20; | 299 static const int kSmallModeId = 20; |
| 313 static const int kSmallModeWidth = 1366; | 300 static const int kSmallModeWidth = 1366; |
| (...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 697 // no displays are connected. | 684 // no displays are connected. |
| 698 configurator_.SetDisplayPower(DISPLAY_POWER_ALL_OFF, | 685 configurator_.SetDisplayPower(DISPLAY_POWER_ALL_OFF, |
| 699 OutputConfigurator::kSetDisplayPowerNoFlags); | 686 OutputConfigurator::kSetDisplayPowerNoFlags); |
| 700 EXPECT_EQ(JoinActions(kGrab, kUngrab, NULL), delegate_->GetActionsAndClear()); | 687 EXPECT_EQ(JoinActions(kGrab, kUngrab, NULL), delegate_->GetActionsAndClear()); |
| 701 configurator_.SetDisplayPower(DISPLAY_POWER_ALL_ON, | 688 configurator_.SetDisplayPower(DISPLAY_POWER_ALL_ON, |
| 702 OutputConfigurator::kSetDisplayPowerNoFlags); | 689 OutputConfigurator::kSetDisplayPowerNoFlags); |
| 703 EXPECT_EQ(JoinActions(kGrab, kForceDPMS, kUngrab, NULL), | 690 EXPECT_EQ(JoinActions(kGrab, kForceDPMS, kUngrab, NULL), |
| 704 delegate_->GetActionsAndClear()); | 691 delegate_->GetActionsAndClear()); |
| 705 | 692 |
| 706 // Connect an external display and check that it's configured correctly. | 693 // Connect an external display and check that it's configured correctly. |
| 707 outputs_[0].is_internal = false; | 694 outputs_[0] = outputs_[1]; |
| 708 outputs_[0].native_mode = kBigModeId; | |
| 709 outputs_[0].selected_mode = kBigModeId; | |
| 710 UpdateOutputs(1, true); | 695 UpdateOutputs(1, true); |
| 711 EXPECT_EQ(JoinActions(kUpdateXRandR, kGrab, | 696 EXPECT_EQ(JoinActions(kUpdateXRandR, kGrab, |
| 712 GetFramebufferAction(kBigModeWidth, kBigModeHeight, | 697 GetFramebufferAction(kBigModeWidth, kBigModeHeight, |
| 713 outputs_[0].crtc, 0).c_str(), | 698 outputs_[0].crtc, 0).c_str(), |
| 714 GetCrtcAction(outputs_[0].crtc, 0, 0, kBigModeId, | 699 GetCrtcAction(outputs_[0].crtc, 0, 0, kBigModeId, |
| 715 outputs_[0].output).c_str(), | 700 outputs_[0].output).c_str(), |
| 716 kUngrab, kProjectingOff, NULL), | 701 kUngrab, kProjectingOff, NULL), |
| 717 delegate_->GetActionsAndClear()); | 702 delegate_->GetActionsAndClear()); |
| 718 } | 703 } |
| 719 | 704 |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 868 outputs_[0].crtc, outputs_[1].crtc).c_str(), | 853 outputs_[0].crtc, outputs_[1].crtc).c_str(), |
| 869 GetCrtcAction(outputs_[0].crtc, 0, 0, kSmallModeId, | 854 GetCrtcAction(outputs_[0].crtc, 0, 0, kSmallModeId, |
| 870 outputs_[0].output).c_str(), | 855 outputs_[0].output).c_str(), |
| 871 GetCrtcAction(outputs_[1].crtc, 0, 0, kSmallModeId, | 856 GetCrtcAction(outputs_[1].crtc, 0, 0, kSmallModeId, |
| 872 outputs_[1].output).c_str(), | 857 outputs_[1].output).c_str(), |
| 873 kUngrab, kProjectingOn, NULL), | 858 kUngrab, kProjectingOn, NULL), |
| 874 delegate_->GetActionsAndClear()); | 859 delegate_->GetActionsAndClear()); |
| 875 } | 860 } |
| 876 | 861 |
| 877 } // namespace chromeos | 862 } // namespace chromeos |
| OLD | NEW |