Commit a385d68d authored by dnicoara's avatar dnicoara Committed by Commit bot

[Ozone-Dri] Adding initial content protection support

BUG=403322
NOTRY=true

Review URL: https://codereview.chromium.org/471433007

Cr-Commit-Position: refs/heads/master@{#291923}
parent 0a51daeb
......@@ -19,7 +19,39 @@
namespace ui {
namespace {
const size_t kMaxDisplayCount = 2;
const char kContentProtection[] = "Content Protection";
struct ContentProtectionMapping {
const char* name;
HDCPState state;
};
const ContentProtectionMapping kContentProtectionStates[] = {
{"Undesired", HDCP_STATE_UNDESIRED},
{"Desired", HDCP_STATE_DESIRED},
{"Enabled", HDCP_STATE_ENABLED}};
uint32_t GetContentProtectionValue(drmModePropertyRes* property,
HDCPState state) {
std::string name;
for (size_t i = 0; i < arraysize(kContentProtectionStates); ++i) {
if (kContentProtectionStates[i].state == state) {
name = kContentProtectionStates[i].name;
break;
}
}
for (int i = 0; i < property->count_enums; ++i)
if (name == property->enums[i].name)
return i;
NOTREACHED();
return 0;
}
} // namespace
NativeDisplayDelegateDri::NativeDisplayDelegateDri(
......@@ -162,14 +194,61 @@ void NativeDisplayDelegateDri::CreateFrameBuffer(const gfx::Size& size) {}
bool NativeDisplayDelegateDri::GetHDCPState(const DisplaySnapshot& output,
HDCPState* state) {
NOTIMPLEMENTED();
const DisplaySnapshotDri& dri_output =
static_cast<const DisplaySnapshotDri&>(output);
ScopedDrmConnectorPtr connector(dri_->GetConnector(dri_output.connector()));
if (!connector) {
LOG(ERROR) << "Failed to get connector " << dri_output.connector();
return false;
}
ScopedDrmPropertyPtr hdcp_property(
dri_->GetProperty(connector.get(), kContentProtection));
if (!hdcp_property) {
LOG(ERROR) << "'" << kContentProtection << "' property doesn't exist.";
return false;
}
DCHECK_LT(static_cast<int>(hdcp_property->prop_id), connector->count_props);
int hdcp_state_idx = connector->prop_values[hdcp_property->prop_id];
DCHECK_LT(hdcp_state_idx, hdcp_property->count_enums);
std::string name(hdcp_property->enums[hdcp_state_idx].name);
for (size_t i = 0; i < arraysize(kContentProtectionStates); ++i) {
if (name == kContentProtectionStates[i].name) {
*state = kContentProtectionStates[i].state;
VLOG(3) << "HDCP state: " << *state << " (" << name << ")";
return true;
}
}
LOG(ERROR) << "Unknown content protection value '" << name << "'";
return false;
}
bool NativeDisplayDelegateDri::SetHDCPState(const DisplaySnapshot& output,
HDCPState state) {
NOTIMPLEMENTED();
return false;
const DisplaySnapshotDri& dri_output =
static_cast<const DisplaySnapshotDri&>(output);
ScopedDrmConnectorPtr connector(dri_->GetConnector(dri_output.connector()));
if (!connector) {
LOG(ERROR) << "Failed to get connector " << dri_output.connector();
return false;
}
ScopedDrmPropertyPtr hdcp_property(
dri_->GetProperty(connector.get(), kContentProtection));
if (!hdcp_property) {
LOG(ERROR) << "'" << kContentProtection << "' property doesn't exist.";
return false;
}
return dri_->SetProperty(
dri_output.connector(),
hdcp_property->prop_id,
GetContentProtectionValue(hdcp_property.get(), state));
}
std::vector<ui::ColorCalibrationProfile>
......
......@@ -121,6 +121,12 @@ bool DriWrapper::DisableCrtc(uint32_t crtc_id) {
return !drmModeSetCrtc(fd_, crtc_id, 0, 0, 0, NULL, 0, NULL);
}
ScopedDrmConnectorPtr DriWrapper::GetConnector(uint32_t connector_id) {
DCHECK(fd_ >= 0);
TRACE_EVENT1("dri", "DriWrapper::GetConnector", "connector", connector_id);
return ScopedDrmConnectorPtr(drmModeGetConnector(fd_, connector_id));
}
bool DriWrapper::AddFramebuffer(uint32_t width,
uint32_t height,
uint8_t depth,
......
......@@ -51,6 +51,9 @@ class DriWrapper {
virtual bool DisableCrtc(uint32_t crtc_id);
// Returns the connector properties for |connector_id|.
virtual ScopedDrmConnectorPtr GetConnector(uint32_t connector_id);
// Register a buffer with the CRTC. On successful registration, the CRTC will
// assign a framebuffer ID to |framebuffer|.
virtual bool AddFramebuffer(uint32_t width,
......
......@@ -61,6 +61,10 @@ bool MockDriWrapper::SetCrtc(drmModeCrtc* crtc,
return true;
}
ScopedDrmConnectorPtr MockDriWrapper::GetConnector(uint32_t connector_id) {
return ScopedDrmConnectorPtr(DrmAllocator<drmModeConnector>());
}
bool MockDriWrapper::AddFramebuffer(uint32_t width,
uint32_t height,
uint8_t depth,
......
......@@ -57,6 +57,7 @@ class MockDriWrapper : public ui::DriWrapper {
drmModeModeInfo* mode) OVERRIDE;
virtual bool SetCrtc(drmModeCrtc* crtc,
std::vector<uint32_t> connectors) OVERRIDE;
virtual ScopedDrmConnectorPtr GetConnector(uint32_t connector_id) OVERRIDE;
virtual bool AddFramebuffer(uint32_t width,
uint32_t height,
uint8_t depth,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment