Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/real_output_configurator_delegate.h" | 5 #include "chromeos/display/real_output_configurator_delegate.h" |
| 6 | 6 |
| 7 #include <X11/Xatom.h> | 7 #include <X11/Xatom.h> |
| 8 #include <X11/Xlib.h> | 8 #include <X11/Xlib.h> |
| 9 #include <X11/extensions/dpms.h> | 9 #include <X11/extensions/dpms.h> |
| 10 #include <X11/extensions/XInput.h> | 10 #include <X11/extensions/XInput.h> |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 23 | 23 |
| 24 namespace chromeos { | 24 namespace chromeos { |
| 25 | 25 |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| 28 // DPI measurements. | 28 // DPI measurements. |
| 29 const float kMmInInch = 25.4; | 29 const float kMmInInch = 25.4; |
| 30 const float kDpi96 = 96.0; | 30 const float kDpi96 = 96.0; |
| 31 const float kPixelsToMmScale = kMmInInch / kDpi96; | 31 const float kPixelsToMmScale = kMmInInch / kDpi96; |
| 32 | 32 |
| 33 // Prefixes of output name | |
| 34 const char kOutputPortName_VGA[] = "VGA"; | |
| 35 const char kOutputPortName_HDMI[] = "HDMI"; | |
| 36 const char kOutputPortName_DVI[] = "DVI"; | |
| 37 const char kOutputPortName_DisplayPort[] = "DP"; | |
| 38 | |
| 33 bool IsInternalOutput(const XRROutputInfo* output_info) { | 39 bool IsInternalOutput(const XRROutputInfo* output_info) { |
| 34 return IsInternalOutputName(std::string(output_info->name)); | 40 return IsInternalOutputName(std::string(output_info->name)); |
| 35 } | 41 } |
| 36 | 42 |
| 37 RRMode GetOutputNativeMode(const XRROutputInfo* output_info) { | 43 RRMode GetOutputNativeMode(const XRROutputInfo* output_info) { |
| 38 return output_info->nmode > 0 ? output_info->modes[0] : None; | 44 return output_info->nmode > 0 ? output_info->modes[0] : None; |
| 39 } | 45 } |
| 40 | 46 |
| 41 } // namespace | 47 } // namespace |
| 42 | 48 |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 363 &mode_info.interlaced)) { | 369 &mode_info.interlaced)) { |
| 364 output.mode_infos.insert(std::make_pair(mode, mode_info)); | 370 output.mode_infos.insert(std::make_pair(mode, mode_info)); |
| 365 } else { | 371 } else { |
| 366 LOG(WARNING) << "Unable to find XRRModeInfo for mode " << mode; | 372 LOG(WARNING) << "Unable to find XRRModeInfo for mode " << mode; |
| 367 } | 373 } |
| 368 } | 374 } |
| 369 | 375 |
| 370 return output; | 376 return output; |
| 371 } | 377 } |
| 372 | 378 |
| 379 bool RealOutputConfiguratorDelegate::GetHDCPState(RROutput id, | |
| 380 HDCPState* state) { | |
| 381 CHECK(screen_) << "Server not grabbed"; | |
| 382 unsigned char* values = NULL; | |
| 383 int actual_format = 0; | |
| 384 unsigned long nitems = 0; | |
| 385 unsigned long bytes_after = 0; | |
| 386 Atom actual_type = None; | |
| 387 int success = 0; | |
| 388 Atom prop = XInternAtom(display_, "Content Protection", False); | |
| 389 | |
| 390 bool ok = true; | |
| 391 success = XRRGetOutputProperty(display_, id, prop, 0, 100, False, | |
| 392 False, AnyPropertyType, &actual_type, | |
| 393 &actual_format, &nitems, &bytes_after, | |
| 394 &values); | |
| 395 if (actual_type == None) { | |
| 396 LOG(ERROR) << "Property 'Content Protection' does not exist"; | |
| 397 ok = false; | |
| 398 } else if (success == Success && actual_type == XA_ATOM && | |
| 399 actual_format == 32 && nitems == 1) { | |
| 400 Atom value = reinterpret_cast<Atom*>(values)[0]; | |
| 401 if (value == XInternAtom(display_, "Undesired", False)) { | |
| 402 *state = HDCP_State_Undesired; | |
| 403 } else if (value == XInternAtom(display_, "Desired", False)) { | |
| 404 *state = HDCP_State_Desired; | |
| 405 } else if (value == XInternAtom(display_, "Enabled", False)) { | |
| 406 *state = HDCP_State_Enabled; | |
| 407 } else { | |
| 408 LOG(ERROR) << "Unknown property value: " << value; | |
| 409 ok = false; | |
| 410 } | |
| 411 } else { | |
| 412 LOG(ERROR) << "XRRGetOutputProperty failed"; | |
| 413 ok = false; | |
| 414 } | |
| 415 if (values) | |
| 416 XFree(values); | |
| 417 | |
| 418 VLOG(3) << "HDCP state: " << ok << "," << *state; | |
| 419 return ok; | |
| 420 } | |
| 421 | |
| 422 bool RealOutputConfiguratorDelegate::SetHDCPState(RROutput id, | |
| 423 HDCPState state) { | |
| 424 CHECK(screen_) << "Server not grabbed"; | |
| 425 Atom name = XInternAtom(display_, "Content Protection", False); | |
| 426 Atom value; | |
| 427 switch (state) { | |
| 428 case HDCP_State_Undesired: | |
| 429 value = XInternAtom(display_, "Undesired", False); | |
| 430 break; | |
| 431 case HDCP_State_Desired: | |
| 432 value = XInternAtom(display_, "Desired", False); | |
| 433 break; | |
| 434 default: | |
| 435 DCHECK(0) << "Invalid HDCP state: " << state; | |
|
DaleCurtis
2013/09/13 22:08:33
NOTREACHED() << "blah blah"
kcwu
2013/09/16 11:57:37
Done.
| |
| 436 NOTREACHED(); | |
| 437 return false; | |
| 438 } | |
| 439 unsigned char *data = reinterpret_cast<unsigned char*>(&value); | |
| 440 XRRChangeOutputProperty(display_, id, name, XA_ATOM, 32, | |
| 441 PropModeReplace, data, 1); | |
| 442 return true; | |
| 443 } | |
| 444 | |
| 445 bool RealOutputConfiguratorDelegate::QueryOutputProtectionLinkType( | |
| 446 RROutput id, | |
| 447 PP_OutputProtectionLinkType_Private *link_type) { | |
| 448 XRROutputInfo* output_info = XRRGetOutputInfo(display_, screen_, id); | |
| 449 if (output_info == NULL) { | |
|
DaleCurtis
2013/09/13 22:08:33
!output_info
kcwu
2013/09/16 11:57:37
Done.
| |
| 450 return false; | |
| 451 } | |
| 452 | |
| 453 bool ok = true; | |
| 454 if (output_info->connection == RR_Connected) { | |
| 455 std::string name(output_info->name); | |
| 456 if (IsInternalOutput(output_info)) { | |
| 457 *link_type = PP_OUTPUT_PROTECTION_LINK_TYPE_PRIVATE_INTERNAL; | |
| 458 } else if (name.find(kOutputPortName_VGA) == 0) { | |
| 459 *link_type = PP_OUTPUT_PROTECTION_LINK_TYPE_PRIVATE_VGA; | |
| 460 } else if (name.find(kOutputPortName_HDMI) == 0) { | |
| 461 *link_type = PP_OUTPUT_PROTECTION_LINK_TYPE_PRIVATE_HDMI; | |
| 462 } else if (name.find(kOutputPortName_DisplayPort) == 0) { | |
| 463 *link_type = PP_OUTPUT_PROTECTION_LINK_TYPE_PRIVATE_DISPLAYPORT; | |
| 464 } else { | |
| 465 DCHECK(0) << "Unknown link type: " << name; | |
|
DaleCurtis
2013/09/13 22:08:33
NOTREACHED() << "blah blah"
kcwu
2013/09/16 11:57:37
No, this may be reached when new link type is inve
| |
| 466 ok = false; | |
| 467 } | |
| 468 } else { | |
| 469 *link_type = PP_OUTPUT_PROTECTION_LINK_TYPE_PRIVATE_NONE; | |
| 470 } | |
| 471 XRRFreeOutputInfo(output_info); | |
| 472 return ok; | |
| 473 } | |
| 474 | |
| 475 bool RealOutputConfiguratorDelegate::EnableOutputProtection( | |
| 476 const void* client, | |
| 477 uint32_t desired_method_mask) { | |
| 478 if (desired_method_mask == PP_OUTPUT_PROTECTION_METHOD_PRIVATE_NONE) | |
| 479 client_protection_requests_.erase(client); | |
| 480 else | |
| 481 client_protection_requests_[client] = desired_method_mask; | |
| 482 | |
| 483 uint32_t all_desires = 0; | |
| 484 for (ProtectionRequests::const_iterator it = | |
| 485 client_protection_requests_.begin(); | |
| 486 it != client_protection_requests_.end(); | |
| 487 ++it) { | |
| 488 all_desires |= it->second; | |
| 489 } | |
| 490 | |
| 491 for (int i = 0; i < screen_->noutput; ++i) { | |
| 492 RROutput this_id = screen_->outputs[i]; | |
| 493 PP_OutputProtectionLinkType_Private type; | |
| 494 if (!QueryOutputProtectionLinkType(this_id, &type)) | |
| 495 return false; | |
| 496 | |
| 497 if ((type & PP_OUTPUT_PROTECTION_LINK_TYPE_PRIVATE_HDMI) || | |
| 498 (type & PP_OUTPUT_PROTECTION_LINK_TYPE_PRIVATE_DISPLAYPORT)) { | |
| 499 HDCPState new_desired_state; | |
| 500 if (all_desires & PP_OUTPUT_PROTECTION_METHOD_PRIVATE_HDCP) { | |
| 501 new_desired_state = HDCP_State_Desired; | |
| 502 } else { | |
| 503 new_desired_state = HDCP_State_Undesired; | |
| 504 } | |
| 505 if (!SetHDCPState(this_id, new_desired_state)) | |
| 506 return false; | |
| 507 } | |
| 508 } | |
| 509 return true; | |
| 510 } | |
| 511 | |
| 512 bool RealOutputConfiguratorDelegate::QueryOutputProtectionStatus( | |
| 513 const void* client, | |
| 514 uint32_t* link_mask, | |
| 515 uint32_t* protection_mask) { | |
| 516 uint32_t enabled = 0; | |
| 517 uint32_t unfulfiled = 0; | |
|
DaleCurtis
2013/09/13 22:08:33
unfulfilled.
kcwu
2013/09/16 11:57:37
Done.
| |
| 518 | |
| 519 *link_mask = 0; | |
| 520 for (int i = 0; i < screen_->noutput; ++i) { | |
| 521 RROutput this_id = screen_->outputs[i]; | |
| 522 PP_OutputProtectionLinkType_Private type; | |
| 523 if (!QueryOutputProtectionLinkType(this_id, &type)) | |
| 524 return false; | |
| 525 *link_mask |= type; | |
| 526 | |
| 527 if ((type & PP_OUTPUT_PROTECTION_LINK_TYPE_PRIVATE_HDMI) || | |
| 528 (type & PP_OUTPUT_PROTECTION_LINK_TYPE_PRIVATE_DISPLAYPORT)) { | |
| 529 HDCPState state; | |
| 530 RROutput this_id = screen_->outputs[i]; | |
| 531 if (!GetHDCPState(this_id, &state)) | |
| 532 return false; | |
| 533 if (state == HDCP_State_Enabled) | |
| 534 enabled |= PP_OUTPUT_PROTECTION_METHOD_PRIVATE_HDCP; | |
| 535 else | |
| 536 unfulfiled |= PP_OUTPUT_PROTECTION_METHOD_PRIVATE_HDCP; | |
| 537 } | |
| 538 } | |
| 539 | |
| 540 // Don't reveal protections requested by other clients. | |
| 541 ProtectionRequests::iterator it = client_protection_requests_.find(client); | |
| 542 if (it != client_protection_requests_.end()) { | |
| 543 uint32_t requested_mask = it->second; | |
| 544 *protection_mask = enabled & ~unfulfiled & requested_mask; | |
| 545 } else { | |
| 546 *protection_mask = 0; | |
| 547 } | |
| 548 return true; | |
| 549 } | |
| 550 | |
| 373 void RealOutputConfiguratorDelegate::DestroyUnusedCrtcs( | 551 void RealOutputConfiguratorDelegate::DestroyUnusedCrtcs( |
| 374 const std::vector<OutputConfigurator::OutputSnapshot>& outputs) { | 552 const std::vector<OutputConfigurator::OutputSnapshot>& outputs) { |
| 375 CHECK(screen_) << "Server not grabbed"; | 553 CHECK(screen_) << "Server not grabbed"; |
| 376 // Setting the screen size will fail if any CRTC doesn't fit afterwards. | 554 // Setting the screen size will fail if any CRTC doesn't fit afterwards. |
| 377 // At the same time, turning CRTCs off and back on uses up a lot of time. | 555 // At the same time, turning CRTCs off and back on uses up a lot of time. |
| 378 // This function tries to be smart to avoid too many off/on cycles: | 556 // This function tries to be smart to avoid too many off/on cycles: |
| 379 // - We disable all the CRTCs we won't need after the FB resize. | 557 // - We disable all the CRTCs we won't need after the FB resize. |
| 380 // - We set the new modes on CRTCs, if they fit in both the old and new | 558 // - We set the new modes on CRTCs, if they fit in both the old and new |
| 381 // FBs, and park them at (0,0) | 559 // FBs, and park them at (0,0) |
| 382 // - We disable the CRTCs we will need but don't fit in the old FB. Those | 560 // - We disable the CRTCs we will need but don't fit in the old FB. Those |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 638 << (*outputs)[i].touch_device_id << " to output #" << i; | 816 << (*outputs)[i].touch_device_id << " to output #" << i; |
| 639 break; | 817 break; |
| 640 } | 818 } |
| 641 } | 819 } |
| 642 } | 820 } |
| 643 | 821 |
| 644 XIFreeDeviceInfo(info); | 822 XIFreeDeviceInfo(info); |
| 645 } | 823 } |
| 646 | 824 |
| 647 } // namespace chromeos | 825 } // namespace chromeos |
| OLD | NEW |