Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(139)

Unified Diff: chromeos/display/real_output_configurator_delegate.cc

Issue 24039002: Pepper API implementation for output protection. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: modify pepper host as message filter. rewrite methods in real_output_configurator_delegate. Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..779fbe87d38f6f93e8014aa32d86d9aa44e51c26 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";
+const char kOutputPortName_HDMI[] = "HDMI";
+const char kOutputPortName_DVI[] = "DVI";
+const char kOutputPortName_DisplayPort[] = "DP";
+
bool IsInternalOutput(const XRROutputInfo* output_info) {
return IsInternalOutputName(std::string(output_info->name));
}
@@ -370,6 +376,178 @@ 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,
+ 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:
+ DCHECK(0) << "Invalid HDCP state: " << state;
DaleCurtis 2013/09/13 22:08:33 NOTREACHED() << "blah blah"
kcwu 2013/09/16 11:57:37 Done.
+ NOTREACHED();
+ return false;
+ }
+ unsigned char *data = reinterpret_cast<unsigned char*>(&value);
+ XRRChangeOutputProperty(display_, id, name, XA_ATOM, 32,
+ PropModeReplace, data, 1);
+ return true;
+}
+
+bool RealOutputConfiguratorDelegate::QueryOutputProtectionLinkType(
+ RROutput id,
+ PP_OutputProtectionLinkType_Private *link_type) {
+ XRROutputInfo* output_info = XRRGetOutputInfo(display_, screen_, id);
+ if (output_info == NULL) {
DaleCurtis 2013/09/13 22:08:33 !output_info
kcwu 2013/09/16 11:57:37 Done.
+ return false;
+ }
+
+ bool ok = true;
+ if (output_info->connection == RR_Connected) {
+ std::string name(output_info->name);
+ if (IsInternalOutput(output_info)) {
+ *link_type = PP_OUTPUT_PROTECTION_LINK_TYPE_PRIVATE_INTERNAL;
+ } else if (name.find(kOutputPortName_VGA) == 0) {
+ *link_type = PP_OUTPUT_PROTECTION_LINK_TYPE_PRIVATE_VGA;
+ } else if (name.find(kOutputPortName_HDMI) == 0) {
+ *link_type = PP_OUTPUT_PROTECTION_LINK_TYPE_PRIVATE_HDMI;
+ } else if (name.find(kOutputPortName_DisplayPort) == 0) {
+ *link_type = PP_OUTPUT_PROTECTION_LINK_TYPE_PRIVATE_DISPLAYPORT;
+ } else {
+ 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
+ ok = false;
+ }
+ } else {
+ *link_type = PP_OUTPUT_PROTECTION_LINK_TYPE_PRIVATE_NONE;
+ }
+ XRRFreeOutputInfo(output_info);
+ return ok;
+}
+
+bool RealOutputConfiguratorDelegate::EnableOutputProtection(
+ const void* client,
+ uint32_t desired_method_mask) {
+ if (desired_method_mask == PP_OUTPUT_PROTECTION_METHOD_PRIVATE_NONE)
+ client_protection_requests_.erase(client);
+ else
+ client_protection_requests_[client] = 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];
+ PP_OutputProtectionLinkType_Private type;
+ if (!QueryOutputProtectionLinkType(this_id, &type))
+ return false;
+
+ if ((type & PP_OUTPUT_PROTECTION_LINK_TYPE_PRIVATE_HDMI) ||
+ (type & PP_OUTPUT_PROTECTION_LINK_TYPE_PRIVATE_DISPLAYPORT)) {
+ HDCPState new_desired_state;
+ if (all_desires & PP_OUTPUT_PROTECTION_METHOD_PRIVATE_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(
+ const void* client,
+ uint32_t* link_mask,
+ uint32_t* protection_mask) {
+ uint32_t enabled = 0;
+ uint32_t unfulfiled = 0;
DaleCurtis 2013/09/13 22:08:33 unfulfilled.
kcwu 2013/09/16 11:57:37 Done.
+
+ *link_mask = 0;
+ for (int i = 0; i < screen_->noutput; ++i) {
+ RROutput this_id = screen_->outputs[i];
+ PP_OutputProtectionLinkType_Private type;
+ if (!QueryOutputProtectionLinkType(this_id, &type))
+ return false;
+ *link_mask |= type;
+
+ if ((type & PP_OUTPUT_PROTECTION_LINK_TYPE_PRIVATE_HDMI) ||
+ (type & PP_OUTPUT_PROTECTION_LINK_TYPE_PRIVATE_DISPLAYPORT)) {
+ HDCPState state;
+ RROutput this_id = screen_->outputs[i];
+ if (!GetHDCPState(this_id, &state))
+ return false;
+ if (state == HDCP_State_Enabled)
+ enabled |= PP_OUTPUT_PROTECTION_METHOD_PRIVATE_HDCP;
+ else
+ unfulfiled |= PP_OUTPUT_PROTECTION_METHOD_PRIVATE_HDCP;
+ }
+ }
+
+ // Don't reveal protections requested by other clients.
+ ProtectionRequests::iterator it = client_protection_requests_.find(client);
+ if (it != client_protection_requests_.end()) {
+ uint32_t requested_mask = it->second;
+ *protection_mask = enabled & ~unfulfiled & requested_mask;
+ } else {
+ *protection_mask = 0;
+ }
+ return true;
+}
+
void RealOutputConfiguratorDelegate::DestroyUnusedCrtcs(
const std::vector<OutputConfigurator::OutputSnapshot>& outputs) {
CHECK(screen_) << "Server not grabbed";

Powered by Google App Engine
This is Rietveld 408576698