Chromium Code Reviews| Index: chromeos/display/output_configurator.cc |
| diff --git a/chromeos/display/output_configurator.cc b/chromeos/display/output_configurator.cc |
| index 4f0d3cdb4f6b2f4b80823dbb7bfeecdc13e6b35c..cc95bd226aba3d71ec7246e7f34728ff1de85c3b 100644 |
| --- a/chromeos/display/output_configurator.cc |
| +++ b/chromeos/display/output_configurator.cc |
| @@ -132,6 +132,7 @@ OutputConfigurator::OutputSnapshot::OutputSnapshot() |
| height_mm(0), |
| is_internal(false), |
| is_aspect_preserving_scaling(false), |
| + type(OUTPUT_TYPE_UNKNOWN), |
| touch_device_id(0), |
| display_id(0), |
| has_display_id(false), |
| @@ -227,7 +228,8 @@ OutputConfigurator::OutputConfigurator() |
| configure_display_(base::chromeos::IsRunningOnChromeOS()), |
| xrandr_event_base_(0), |
| output_state_(STATE_INVALID), |
| - power_state_(DISPLAY_POWER_ALL_ON) { |
| + power_state_(DISPLAY_POWER_ALL_ON), |
| + next_output_protection_client_id_(1) { |
| } |
| OutputConfigurator::~OutputConfigurator() {} |
| @@ -273,6 +275,121 @@ void OutputConfigurator::Start(uint32 background_color_argb) { |
| NotifyObservers(success, new_state); |
| } |
| +OutputConfigurator::OutputProtectionClientId |
| +OutputConfigurator::RegisterOutputProtectionClient() { |
| + if (!configure_display_) |
| + return 0; |
| + |
| + return next_output_protection_client_id_++; |
| +} |
| + |
| +void OutputConfigurator::UnregisterOutputProtectionClient( |
| + OutputProtectionClientId client_id) { |
| + EnableOutputProtection(client_id, OUTPUT_PROTECTION_METHOD_NONE); |
| +} |
| + |
| +bool OutputConfigurator::QueryOutputProtectionStatus( |
| + OutputProtectionClientId client_id, |
| + uint32_t* link_mask, |
| + uint32_t* protection_mask) { |
| + if (!configure_display_) |
| + return false; |
| + |
| + uint32_t enabled = 0; |
| + uint32_t unfulfilled = 0; |
| + *link_mask = 0; |
| + for (std::vector<OutputSnapshot>::const_iterator it = cached_outputs_.begin(); |
| + it != cached_outputs_.end(); ++it) { |
| + RROutput this_id = it->output; |
| + *link_mask |= it->type; |
| + switch (it->type) { |
| + case OUTPUT_TYPE_UNKNOWN: |
| + return false; |
| + // HDMI and DisplayPort both support HDCP. |
| + case OUTPUT_TYPE_HDMI: |
| + case OUTPUT_TYPE_DISPLAYPORT: { |
| + HDCPState state; |
| + if (!delegate_->GetHDCPState(this_id, &state)) |
| + return false; |
| + if (state == HDCP_STATE_ENABLED) |
| + enabled |= OUTPUT_PROTECTION_METHOD_HDCP; |
| + else |
| + unfulfilled |= OUTPUT_PROTECTION_METHOD_HDCP; |
| + break; |
| + } |
| + case OUTPUT_TYPE_INTERNAL: |
| + case OUTPUT_TYPE_VGA: |
| + case OUTPUT_TYPE_DVI: |
| + // No protections for these types. Do nothing. |
| + break; |
| + case OUTPUT_TYPE_NONE: |
| + NOTREACHED(); |
| + break; |
| + } |
| + } |
| + |
| + // Don't reveal protections requested by other clients. |
| + ProtectionRequests::iterator it = client_protection_requests_.find(client_id); |
| + if (it != client_protection_requests_.end()) { |
| + uint32_t requested_mask = it->second; |
| + *protection_mask = enabled & ~unfulfilled & requested_mask; |
| + } else { |
| + *protection_mask = 0; |
| + } |
| + return true; |
| +} |
| + |
| +bool OutputConfigurator::EnableOutputProtection( |
| + OutputProtectionClientId client_id, |
| + uint32_t desired_method_mask) { |
| + if (!configure_display_) |
| + return false; |
| + |
| + uint32_t all_desires = desired_method_mask; |
|
Daniel Erat
2013/09/23 19:31:43
nit: s/all_desires/all_desired/
kcwu
2013/09/24 13:55:06
Done.
|
| + for (ProtectionRequests::const_iterator it = |
| + client_protection_requests_.begin(); |
| + it != client_protection_requests_.end(); |
| + ++it) { |
| + if (it->first != client_id) { |
|
Daniel Erat
2013/09/23 19:31:43
nit: remove curly brackets here
kcwu
2013/09/24 13:55:06
Done.
|
| + all_desires |= it->second; |
| + } |
| + } |
| + |
| + for (std::vector<OutputSnapshot>::const_iterator it = cached_outputs_.begin(); |
| + it != cached_outputs_.end(); ++it) { |
| + RROutput this_id = it->output; |
| + switch (it->type) { |
| + case OUTPUT_TYPE_UNKNOWN: |
| + return false; |
| + // HDMI and DisplayPort both support HDCP. |
| + case OUTPUT_TYPE_HDMI: |
| + case OUTPUT_TYPE_DISPLAYPORT: { |
| + HDCPState new_desired_state = |
| + (all_desires & OUTPUT_PROTECTION_METHOD_HDCP) ? |
| + HDCP_STATE_DESIRED : HDCP_STATE_UNDESIRED; |
| + if (!delegate_->SetHDCPState(this_id, new_desired_state)) |
| + return false; |
| + break; |
| + } |
| + case OUTPUT_TYPE_INTERNAL: |
| + case OUTPUT_TYPE_VGA: |
| + case OUTPUT_TYPE_DVI: |
| + // No protections for these types. Do nothing. |
| + break; |
| + case OUTPUT_TYPE_NONE: |
| + NOTREACHED(); |
| + break; |
| + } |
| + } |
| + |
| + if (desired_method_mask == OUTPUT_PROTECTION_METHOD_NONE) |
| + client_protection_requests_.erase(client_id); |
| + else |
| + client_protection_requests_[client_id] = desired_method_mask; |
| + |
| + return true; |
| +} |
| + |
| void OutputConfigurator::Stop() { |
| configure_display_ = false; |
| } |