Chromium Code Reviews| Index: chromeos/display/real_output_configurator_delegate.cc |
| diff --git a/chromeos/display/real_output_configurator_delegate.cc b/chromeos/display/real_output_configurator_delegate.cc |
| index 6d0c78254112c5e678f0149aefc181cb6ebd448e..5985c792e8c9035c4c0308b0b8412c5bdf35186e 100644 |
| --- a/chromeos/display/real_output_configurator_delegate.cc |
| +++ b/chromeos/display/real_output_configurator_delegate.cc |
| @@ -30,6 +30,12 @@ const float kMmInInch = 25.4; |
| const float kDpi96 = 96.0; |
| const float kPixelsToMmScale = kMmInInch / kDpi96; |
| +// Prefixes of output name |
| +const char kOutputPortName_VGA[] = "VGA"; |
|
Daniel Erat
2013/09/18 22:39:16
nit: remove underscores from constant identifiers
kcwu
2013/09/20 03:03:47
This naming style follows kInternal_* as marcheu m
|
| +const char kOutputPortName_HDMI[] = "HDMI"; |
| +const char kOutputPortName_DVI[] = "DVI"; |
| +const char kOutputPortName_DisplayPort[] = "DP"; |
|
marcheu
2013/09/18 23:21:35
I think just "OutputName_*" is fine, the "OutputPo
kcwu
2013/09/20 03:03:47
Done. I changed they as kOutputName_*.
These names
|
| + |
| bool IsInternalOutput(const XRROutputInfo* output_info) { |
| return IsInternalOutputName(std::string(output_info->name)); |
| } |
| @@ -44,7 +50,8 @@ RealOutputConfiguratorDelegate::RealOutputConfiguratorDelegate() |
| : display_(base::MessagePumpAuraX11::GetDefaultXDisplay()), |
| window_(DefaultRootWindow(display_)), |
| screen_(NULL), |
| - is_panel_fitting_enabled_(false) { |
| + is_panel_fitting_enabled_(false), |
| + next_client_id_(1) { |
| } |
| RealOutputConfiguratorDelegate::~RealOutputConfiguratorDelegate() { |
| @@ -370,6 +377,188 @@ RealOutputConfiguratorDelegate::InitOutputSnapshot( |
| return output; |
| } |
| +bool RealOutputConfiguratorDelegate::GetHDCPState(RROutput id, |
| + HDCPState* state) { |
| + CHECK(screen_) << "Server not grabbed"; |
| + unsigned char* values = NULL; |
| + int actual_format = 0; |
| + unsigned long nitems = 0; |
| + unsigned long bytes_after = 0; |
| + Atom actual_type = None; |
| + int success = 0; |
| + Atom prop = XInternAtom(display_, "Content Protection", False); |
| + |
| + bool ok = true; |
| + success = XRRGetOutputProperty(display_, id, prop, 0, 100, False, |
|
Daniel Erat
2013/09/18 22:39:16
please add a TODO to move this to x11_util (simila
kcwu
2013/09/20 03:03:47
Done.
|
| + False, AnyPropertyType, &actual_type, |
| + &actual_format, &nitems, &bytes_after, |
| + &values); |
| + if (actual_type == None) { |
| + LOG(ERROR) << "Property 'Content Protection' does not exist"; |
| + ok = false; |
| + } else if (success == Success && actual_type == XA_ATOM && |
| + actual_format == 32 && nitems == 1) { |
| + Atom value = reinterpret_cast<Atom*>(values)[0]; |
| + if (value == XInternAtom(display_, "Undesired", False)) { |
| + *state = HDCP_State_Undesired; |
| + } else if (value == XInternAtom(display_, "Desired", False)) { |
| + *state = HDCP_State_Desired; |
| + } else if (value == XInternAtom(display_, "Enabled", False)) { |
| + *state = HDCP_State_Enabled; |
| + } else { |
| + LOG(ERROR) << "Unknown property value: " << value; |
| + ok = false; |
| + } |
| + } else { |
| + LOG(ERROR) << "XRRGetOutputProperty failed"; |
| + ok = false; |
| + } |
| + if (values) |
| + XFree(values); |
| + |
| + VLOG(3) << "HDCP state: " << ok << "," << *state; |
| + return ok; |
| +} |
| + |
| +bool RealOutputConfiguratorDelegate::SetHDCPState(RROutput id, |
| + HDCPState state) { |
| + CHECK(screen_) << "Server not grabbed"; |
| + Atom name = XInternAtom(display_, "Content Protection", False); |
| + Atom value; |
| + switch (state) { |
| + case HDCP_State_Undesired: |
| + value = XInternAtom(display_, "Undesired", False); |
| + break; |
| + case HDCP_State_Desired: |
| + value = XInternAtom(display_, "Desired", False); |
| + break; |
| + default: |
| + NOTREACHED() << "Invalid HDCP state: " << state; |
| + return false; |
| + } |
| + unsigned char *data = reinterpret_cast<unsigned char*>(&value); |
| + XRRChangeOutputProperty(display_, id, name, XA_ATOM, 32, |
| + PropModeReplace, data, 1); |
|
marcheu
2013/09/18 23:21:35
Hmm, we probably shouldn't return true here withou
kcwu
2013/09/20 03:03:47
Done.
|
| + return true; |
| +} |
| + |
| +uint64_t RealOutputConfiguratorDelegate::RegisterOutputProtectionClient() { |
| + return next_client_id_++; |
| +} |
| + |
| +void RealOutputConfiguratorDelegate::UnregisterOutputProtectionClient( |
| + uint64_t client_id) { |
| + EnableOutputProtection(client_id, OUTPUT_PROTECTION_METHOD_NONE); |
| +} |
| + |
| +bool RealOutputConfiguratorDelegate::QueryOutputProtectionLinkType( |
| + RROutput id, |
| + OutputLinkType *link_type) { |
| + XRROutputInfo* output_info = XRRGetOutputInfo(display_, screen_, id); |
| + if (!output_info) { |
| + return false; |
| + } |
| + |
| + bool ok = true; |
| + if (output_info->connection == RR_Connected) { |
| + std::string name(output_info->name); |
| + if (IsInternalOutput(output_info)) { |
| + *link_type = OUTPUT_LINK_TYPE_INTERNAL; |
| + } else if (name.find(kOutputPortName_VGA) == 0) { |
| + *link_type = OUTPUT_LINK_TYPE_VGA; |
| + } else if (name.find(kOutputPortName_HDMI) == 0) { |
| + *link_type = OUTPUT_LINK_TYPE_HDMI; |
| + } else if (name.find(kOutputPortName_DVI) == 0) { |
| + *link_type = OUTPUT_LINK_TYPE_DVI; |
| + } else if (name.find(kOutputPortName_DisplayPort) == 0) { |
| + *link_type = OUTPUT_LINK_TYPE_DISPLAYPORT; |
| + } else { |
| + DCHECK(0) << "Unknown link type: " << name; |
| + ok = false; |
| + } |
| + } else { |
| + *link_type = OUTPUT_LINK_TYPE_NONE; |
| + } |
| + XRRFreeOutputInfo(output_info); |
| + return ok; |
| +} |
| + |
| +bool RealOutputConfiguratorDelegate::EnableOutputProtection( |
| + uint64_t client_id, |
| + uint32_t desired_method_mask) { |
| + if (desired_method_mask == OUTPUT_PROTECTION_METHOD_NONE) |
| + client_protection_requests_.erase(client_id); |
| + else |
| + client_protection_requests_[client_id] = desired_method_mask; |
| + |
| + uint32_t all_desires = 0; |
| + for (ProtectionRequests::const_iterator it = |
| + client_protection_requests_.begin(); |
| + it != client_protection_requests_.end(); |
| + ++it) { |
| + all_desires |= it->second; |
| + } |
| + |
| + for (int i = 0; i < screen_->noutput; ++i) { |
| + RROutput this_id = screen_->outputs[i]; |
| + OutputLinkType type; |
| + if (!QueryOutputProtectionLinkType(this_id, &type)) |
| + return false; |
| + |
| + if ((type & OUTPUT_LINK_TYPE_HDMI) || |
| + (type & OUTPUT_LINK_TYPE_DISPLAYPORT)) { |
| + HDCPState new_desired_state; |
| + if (all_desires & OUTPUT_PROTECTION_METHOD_HDCP) { |
| + new_desired_state = HDCP_State_Desired; |
| + } else { |
| + new_desired_state = HDCP_State_Undesired; |
| + } |
| + if (!SetHDCPState(this_id, new_desired_state)) |
| + return false; |
| + } |
| + } |
| + return true; |
| +} |
| + |
| +bool RealOutputConfiguratorDelegate::QueryOutputProtectionStatus( |
| + uint64_t client_id, |
| + uint32_t* link_mask, |
| + uint32_t* protection_mask) { |
| + uint32_t enabled = 0; |
| + uint32_t unfulfilled = 0; |
| + |
| + *link_mask = 0; |
| + for (int i = 0; i < screen_->noutput; ++i) { |
| + RROutput this_id = screen_->outputs[i]; |
| + OutputLinkType type; |
| + if (!QueryOutputProtectionLinkType(this_id, &type)) |
| + return false; |
| + *link_mask |= type; |
| + |
| + if ((type & OUTPUT_LINK_TYPE_HDMI) || |
| + (type & OUTPUT_LINK_TYPE_DISPLAYPORT)) { |
| + HDCPState state; |
| + RROutput this_id = screen_->outputs[i]; |
| + if (!GetHDCPState(this_id, &state)) |
| + return false; |
| + if (state == HDCP_State_Enabled) |
| + enabled |= OUTPUT_PROTECTION_METHOD_HDCP; |
| + else |
| + unfulfilled |= OUTPUT_PROTECTION_METHOD_HDCP; |
| + } |
| + } |
| + |
| + // 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; |
| +} |
| + |
| void RealOutputConfiguratorDelegate::DestroyUnusedCrtcs( |
| const std::vector<OutputConfigurator::OutputSnapshot>& outputs) { |
| CHECK(screen_) << "Server not grabbed"; |