| 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 <cmath> | 7 #include <cmath> |
| 8 | 8 |
| 9 #include <X11/Xatom.h> | 9 #include <X11/Xatom.h> |
| 10 #include <X11/Xlib.h> | 10 #include <X11/Xlib.h> |
| (...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 } | 389 } |
| 390 } | 390 } |
| 391 break; | 391 break; |
| 392 } | 392 } |
| 393 default: | 393 default: |
| 394 CHECK(false); | 394 CHECK(false); |
| 395 } | 395 } |
| 396 return state; | 396 return state; |
| 397 } | 397 } |
| 398 | 398 |
| 399 OutputState GetNextState(Display* display, | |
| 400 XRRScreenResources* screen, | |
| 401 OutputState current_state, | |
| 402 const std::vector<OutputSnapshot>& outputs) { | |
| 403 TRACE_EVENT0("chromeos", "OutputConfigurator::GetNextState"); | |
| 404 OutputState state = STATE_INVALID; | |
| 405 | |
| 406 switch (outputs.size()) { | |
| 407 case 0: | |
| 408 state = STATE_HEADLESS; | |
| 409 break; | |
| 410 case 1: | |
| 411 state = STATE_SINGLE; | |
| 412 break; | |
| 413 case 2: { | |
| 414 bool mirror_supported = (0 != outputs[0].mirror_mode) && | |
| 415 (0 != outputs[1].mirror_mode); | |
| 416 switch (current_state) { | |
| 417 case STATE_DUAL_EXTENDED: | |
| 418 state = | |
| 419 mirror_supported ? STATE_DUAL_MIRROR : STATE_DUAL_EXTENDED; | |
| 420 break; | |
| 421 case STATE_DUAL_MIRROR: | |
| 422 state = STATE_DUAL_EXTENDED; | |
| 423 break; | |
| 424 default: | |
| 425 // Default to extended mode. | |
| 426 state = STATE_DUAL_EXTENDED; | |
| 427 } | |
| 428 break; | |
| 429 } | |
| 430 default: | |
| 431 CHECK(false); | |
| 432 } | |
| 433 return state; | |
| 434 } | |
| 435 | |
| 436 RRCrtc GetNextCrtcAfter(Display* display, | 399 RRCrtc GetNextCrtcAfter(Display* display, |
| 437 XRRScreenResources* screen, | 400 XRRScreenResources* screen, |
| 438 RROutput output, | 401 RROutput output, |
| 439 RRCrtc previous) { | 402 RRCrtc previous) { |
| 440 RRCrtc crtc = None; | 403 RRCrtc crtc = None; |
| 441 XRROutputInfo* output_info = XRRGetOutputInfo(display, screen, output); | 404 XRROutputInfo* output_info = XRRGetOutputInfo(display, screen, output); |
| 442 | 405 |
| 443 for (int i = 0; (i < output_info->ncrtc) && (crtc == None); ++i) { | 406 for (int i = 0; (i < output_info->ncrtc) && (crtc == None); ++i) { |
| 444 RRCrtc this_crtc = output_info->crtcs[i]; | 407 RRCrtc this_crtc = output_info->crtcs[i]; |
| 445 | 408 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 526 XFree(props); | 489 XFree(props); |
| 527 | 490 |
| 528 return ret; | 491 return ret; |
| 529 } | 492 } |
| 530 | 493 |
| 531 } // namespace | 494 } // namespace |
| 532 | 495 |
| 533 OutputConfigurator::OutputConfigurator() | 496 OutputConfigurator::OutputConfigurator() |
| 534 // If we aren't running on ChromeOS (like linux desktop), | 497 // If we aren't running on ChromeOS (like linux desktop), |
| 535 // don't try to configure display. | 498 // don't try to configure display. |
| 536 : configure_display_(base::chromeos::IsRunningOnChromeOS()), | 499 : delegate_(NULL), |
| 500 configure_display_(base::chromeos::IsRunningOnChromeOS()), |
| 537 is_panel_fitting_enabled_(false), | 501 is_panel_fitting_enabled_(false), |
| 538 connected_output_count_(0), | 502 connected_output_count_(0), |
| 539 xrandr_event_base_(0), | 503 xrandr_event_base_(0), |
| 540 output_state_(STATE_INVALID), | 504 output_state_(STATE_INVALID), |
| 541 power_state_(DISPLAY_POWER_ALL_ON), | 505 power_state_(DISPLAY_POWER_ALL_ON), |
| 542 mirror_mode_will_preserve_aspect_(false), | 506 mirror_mode_will_preserve_aspect_(false), |
| 543 mirror_mode_preserved_aspect_(false), | 507 mirror_mode_preserved_aspect_(false), |
| 544 last_enter_state_time_() { | 508 last_enter_state_time_() { |
| 545 } | 509 } |
| 546 | 510 |
| (...skipping 748 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1295 duration); | 1259 duration); |
| 1296 break; | 1260 break; |
| 1297 default: | 1261 default: |
| 1298 break; | 1262 break; |
| 1299 } | 1263 } |
| 1300 | 1264 |
| 1301 mirror_mode_preserved_aspect_ = mirror_mode_will_preserve_aspect_; | 1265 mirror_mode_preserved_aspect_ = mirror_mode_will_preserve_aspect_; |
| 1302 last_enter_state_time_ = base::TimeTicks::Now(); | 1266 last_enter_state_time_ = base::TimeTicks::Now(); |
| 1303 } | 1267 } |
| 1304 | 1268 |
| 1269 OutputState OutputConfigurator::GetNextState( |
| 1270 Display* display, |
| 1271 XRRScreenResources* screen, |
| 1272 OutputState current_state, |
| 1273 const std::vector<OutputSnapshot>& output_snapshots) const { |
| 1274 TRACE_EVENT0("chromeos", "OutputConfigurator::GetNextState"); |
| 1275 OutputState state = STATE_INVALID; |
| 1276 |
| 1277 switch (output_snapshots.size()) { |
| 1278 case 0: |
| 1279 state = STATE_HEADLESS; |
| 1280 break; |
| 1281 case 1: |
| 1282 state = STATE_SINGLE; |
| 1283 break; |
| 1284 case 2: { |
| 1285 bool mirror_supported = (0 != output_snapshots[0].mirror_mode) && |
| 1286 (0 != output_snapshots[1].mirror_mode); |
| 1287 switch (current_state) { |
| 1288 case STATE_DUAL_EXTENDED: |
| 1289 state = |
| 1290 mirror_supported ? STATE_DUAL_MIRROR : STATE_DUAL_EXTENDED; |
| 1291 break; |
| 1292 case STATE_DUAL_MIRROR: |
| 1293 state = STATE_DUAL_EXTENDED; |
| 1294 break; |
| 1295 case STATE_INVALID: { |
| 1296 std::vector<RROutput> outputs; |
| 1297 for (size_t i = 0; i < output_snapshots.size(); ++i) |
| 1298 outputs.push_back(output_snapshots[i].output); |
| 1299 state = delegate_->GetStateForOutputs(outputs); |
| 1300 break; |
| 1301 } |
| 1302 default: |
| 1303 state = STATE_DUAL_EXTENDED; |
| 1304 } |
| 1305 break; |
| 1306 } |
| 1307 default: |
| 1308 CHECK(false); |
| 1309 } |
| 1310 return state; |
| 1311 } |
| 1312 |
| 1305 // static | 1313 // static |
| 1306 bool OutputConfigurator::IsInternalOutput(const XRROutputInfo* output_info) { | 1314 bool OutputConfigurator::IsInternalOutput(const XRROutputInfo* output_info) { |
| 1307 return IsInternalOutputName(std::string(output_info->name)); | 1315 return IsInternalOutputName(std::string(output_info->name)); |
| 1308 } | 1316 } |
| 1309 | 1317 |
| 1310 // static | 1318 // static |
| 1311 RRMode OutputConfigurator::GetOutputNativeMode( | 1319 RRMode OutputConfigurator::GetOutputNativeMode( |
| 1312 const XRROutputInfo* output_info) { | 1320 const XRROutputInfo* output_info) { |
| 1313 if (output_info->nmode <= 0) | 1321 if (output_info->nmode <= 0) |
| 1314 return None; | 1322 return None; |
| 1315 | 1323 |
| 1316 return output_info->modes[0]; | 1324 return output_info->modes[0]; |
| 1317 } | 1325 } |
| 1318 | 1326 |
| 1319 } // namespace chromeos | 1327 } // namespace chromeos |
| OLD | NEW |