From ed28f845fc827621f267c7a2784d66a31f8454d3 Mon Sep 17 00:00:00 2001 From: dnicoara Date: Thu, 23 Apr 2015 11:31:23 -0700 Subject: [PATCH] [Ozone-Drm] Add support for async content protection Forward requests from the UI thread to the GPU process where the DRM devices are opened. The GPU side of the platform will query the DRM device and will respond. BUG=442317 Review URL: https://codereview.chromium.org/1022673012 Cr-Commit-Position: refs/heads/master@{#326587} --- ui/display/types/display_constants.h | 9 ++++- ui/ozone/common/gpu/ozone_gpu_messages.h | 20 +++++++++++ .../platform/drm/gpu/drm_gpu_display_manager.cc | 34 ++++++++++++------- .../platform/drm/gpu/drm_gpu_display_manager.h | 6 ++-- .../platform/drm/gpu/drm_gpu_platform_support.cc | 14 ++++++++ .../platform/drm/gpu/drm_gpu_platform_support.h | 3 ++ .../drm/host/drm_native_display_delegate.cc | 39 ++++++++++++++++++---- .../drm/host/drm_native_display_delegate.h | 7 ++++ 8 files changed, 109 insertions(+), 23 deletions(-) diff --git a/ui/display/types/display_constants.h b/ui/display/types/display_constants.h index f2361b383ea8..aedb04bc9eab 100644 --- a/ui/display/types/display_constants.h +++ b/ui/display/types/display_constants.h @@ -40,7 +40,14 @@ enum ContentProtectionMethod { }; // HDCP protection state. -enum HDCPState { HDCP_STATE_UNDESIRED, HDCP_STATE_DESIRED, HDCP_STATE_ENABLED }; +enum HDCPState { + HDCP_STATE_UNDESIRED, + HDCP_STATE_DESIRED, + HDCP_STATE_ENABLED, + + // Update this when adding a new type. + HDCP_STATE_LAST = HDCP_STATE_ENABLED +}; // Color calibration profiles. Don't change the order, and edit // tools/metrics/histograms/histograms.xml when a new item is added. diff --git a/ui/ozone/common/gpu/ozone_gpu_messages.h b/ui/ozone/common/gpu/ozone_gpu_messages.h index 14d2a10761e1..bc9a465d4353 100644 --- a/ui/ozone/common/gpu/ozone_gpu_messages.h +++ b/ui/ozone/common/gpu/ozone_gpu_messages.h @@ -10,6 +10,7 @@ #include "base/file_descriptor_posix.h" #include "ipc/ipc_message_macros.h" #include "third_party/skia/include/core/SkBitmap.h" +#include "ui/display/types/display_constants.h" #include "ui/gfx/geometry/point.h" #include "ui/gfx/geometry/rect.h" #include "ui/gfx/ipc/gfx_param_traits.h" @@ -25,6 +26,8 @@ IPC_ENUM_TRAITS_MAX_VALUE(ui::DisplayConnectionType, ui::DISPLAY_CONNECTION_TYPE_LAST) +IPC_ENUM_TRAITS_MAX_VALUE(ui::HDCPState, ui::HDCP_STATE_LAST) + IPC_STRUCT_TRAITS_BEGIN(ui::DisplayMode_Params) IPC_STRUCT_TRAITS_MEMBER(size) IPC_STRUCT_TRAITS_MEMBER(is_interlaced) @@ -102,6 +105,12 @@ IPC_MESSAGE_CONTROL0(OzoneGpuMsg_TakeDisplayControl) // Let other entity control the display IPC_MESSAGE_CONTROL0(OzoneGpuMsg_RelinquishDisplayControl) +IPC_MESSAGE_CONTROL1(OzoneGpuMsg_GetHDCPState, int64_t /* display_id */) + +IPC_MESSAGE_CONTROL2(OzoneGpuMsg_SetHDCPState, + int64_t /* display_id */, + ui::HDCPState /* state */) + //------------------------------------------------------------------------------ // Browser Messages // These messages are from the GPU to the browser process. @@ -113,3 +122,14 @@ IPC_MESSAGE_CONTROL1(OzoneHostMsg_UpdateNativeDisplays, IPC_MESSAGE_CONTROL2(OzoneHostMsg_DisplayConfigured, int64_t /* display_id */, bool /* status */) + +// Response for OzoneGpuMsg_GetHDCPState. +IPC_MESSAGE_CONTROL3(OzoneHostMsg_HDCPStateReceived, + int64_t /* display_id */, + bool /* success */, + ui::HDCPState /* state */) + +// Response for OzoneGpuMsg_SetHDCPState. +IPC_MESSAGE_CONTROL2(OzoneHostMsg_HDCPStateUpdated, + int64_t /* display_id */, + bool /* success */) diff --git a/ui/ozone/platform/drm/gpu/drm_gpu_display_manager.cc b/ui/ozone/platform/drm/gpu/drm_gpu_display_manager.cc index 477ae7a0f9a8..526b200513f1 100644 --- a/ui/ozone/platform/drm/gpu/drm_gpu_display_manager.cc +++ b/ui/ozone/platform/drm/gpu/drm_gpu_display_manager.cc @@ -336,17 +336,22 @@ bool DrmGpuDisplayManager::Configure(const DrmDisplaySnapshot& output, return true; } -bool DrmGpuDisplayManager::GetHDCPState(const DrmDisplaySnapshot& output, - HDCPState* state) { +bool DrmGpuDisplayManager::GetHDCPState(int64_t display_id, HDCPState* state) { + DrmDisplaySnapshot* output = FindDisplaySnapshot(display_id); + if (!output) { + LOG(ERROR) << "There is no display with ID " << display_id; + return false; + } + ScopedDrmConnectorPtr connector( - output.drm()->GetConnector(output.connector())); + output->drm()->GetConnector(output->connector())); if (!connector) { - PLOG(ERROR) << "Failed to get connector " << output.connector(); + PLOG(ERROR) << "Failed to get connector " << output->connector(); return false; } ScopedDrmPropertyPtr hdcp_property( - output.drm()->GetProperty(connector.get(), kContentProtection)); + output->drm()->GetProperty(connector.get(), kContentProtection)); if (!hdcp_property) { PLOG(ERROR) << "'" << kContentProtection << "' property doesn't exist."; return false; @@ -366,24 +371,29 @@ bool DrmGpuDisplayManager::GetHDCPState(const DrmDisplaySnapshot& output, return false; } -bool DrmGpuDisplayManager::SetHDCPState(const DrmDisplaySnapshot& output, - HDCPState state) { +bool DrmGpuDisplayManager::SetHDCPState(int64_t display_id, HDCPState state) { + DrmDisplaySnapshot* output = FindDisplaySnapshot(display_id); + if (!output) { + LOG(ERROR) << "There is no display with ID " << display_id; + return false; + } + ScopedDrmConnectorPtr connector( - output.drm()->GetConnector(output.connector())); + output->drm()->GetConnector(output->connector())); if (!connector) { - PLOG(ERROR) << "Failed to get connector " << output.connector(); + PLOG(ERROR) << "Failed to get connector " << output->connector(); return false; } ScopedDrmPropertyPtr hdcp_property( - output.drm()->GetProperty(connector.get(), kContentProtection)); + output->drm()->GetProperty(connector.get(), kContentProtection)); if (!hdcp_property) { PLOG(ERROR) << "'" << kContentProtection << "' property doesn't exist."; return false; } - return output.drm()->SetProperty( - output.connector(), hdcp_property->prop_id, + return output->drm()->SetProperty( + output->connector(), hdcp_property->prop_id, GetContentProtectionValue(hdcp_property.get(), state)); } diff --git a/ui/ozone/platform/drm/gpu/drm_gpu_display_manager.h b/ui/ozone/platform/drm/gpu/drm_gpu_display_manager.h index bbfa50834d5b..5267b6f63709 100644 --- a/ui/ozone/platform/drm/gpu/drm_gpu_display_manager.h +++ b/ui/ozone/platform/drm/gpu/drm_gpu_display_manager.h @@ -54,6 +54,9 @@ class DrmGpuDisplayManager { const base::FileDescriptor& fd); void RemoveGraphicsDevice(const base::FilePath& path); + bool GetHDCPState(int64_t display_id, HDCPState* state); + bool SetHDCPState(int64_t display_id, HDCPState state); + private: DrmDisplaySnapshot* FindDisplaySnapshot(int64_t id); const DrmDisplayMode* FindDisplayMode(const gfx::Size& size, @@ -65,9 +68,6 @@ class DrmGpuDisplayManager { const DrmDisplayMode* mode, const gfx::Point& origin); - bool GetHDCPState(const DrmDisplaySnapshot& output, HDCPState* state); - bool SetHDCPState(const DrmDisplaySnapshot& output, HDCPState state); - // Notify ScreenManager of all the displays that were present before the // update but are gone after the update. void NotifyScreenManager( diff --git a/ui/ozone/platform/drm/gpu/drm_gpu_platform_support.cc b/ui/ozone/platform/drm/gpu/drm_gpu_platform_support.cc index 495307f85e4a..fdf9980f9aba 100644 --- a/ui/ozone/platform/drm/gpu/drm_gpu_platform_support.cc +++ b/ui/ozone/platform/drm/gpu/drm_gpu_platform_support.cc @@ -213,6 +213,8 @@ bool DrmGpuPlatformSupport::OnMessageReceived(const IPC::Message& message) { OnRelinquishDisplayControl) IPC_MESSAGE_HANDLER(OzoneGpuMsg_AddGraphicsDevice, OnAddGraphicsDevice) IPC_MESSAGE_HANDLER(OzoneGpuMsg_RemoveGraphicsDevice, OnRemoveGraphicsDevice) + IPC_MESSAGE_HANDLER(OzoneGpuMsg_GetHDCPState, OnGetHDCPState) + IPC_MESSAGE_HANDLER(OzoneGpuMsg_SetHDCPState, OnSetHDCPState) IPC_MESSAGE_UNHANDLED(handled = false); IPC_END_MESSAGE_MAP() @@ -296,6 +298,18 @@ void DrmGpuPlatformSupport::RelinquishGpuResources( callback.Run(); } +void DrmGpuPlatformSupport::OnGetHDCPState(int64_t display_id) { + HDCPState state = HDCP_STATE_UNDESIRED; + bool success = ndd_->GetHDCPState(display_id, &state); + sender_->Send(new OzoneHostMsg_HDCPStateReceived(display_id, success, state)); +} + +void DrmGpuPlatformSupport::OnSetHDCPState(int64_t display_id, + HDCPState state) { + sender_->Send(new OzoneHostMsg_HDCPStateUpdated( + display_id, ndd_->SetHDCPState(display_id, state))); +} + void DrmGpuPlatformSupport::SetIOTaskRunner( const scoped_refptr& io_task_runner) { ndd_->InitializeIOTaskRunner(io_task_runner); diff --git a/ui/ozone/platform/drm/gpu/drm_gpu_platform_support.h b/ui/ozone/platform/drm/gpu/drm_gpu_platform_support.h index 2c844dbe432d..abd697828f1d 100644 --- a/ui/ozone/platform/drm/gpu/drm_gpu_platform_support.h +++ b/ui/ozone/platform/drm/gpu/drm_gpu_platform_support.h @@ -9,6 +9,7 @@ #include "base/memory/scoped_ptr.h" #include "base/memory/scoped_vector.h" #include "ipc/message_filter.h" +#include "ui/display/types/display_constants.h" #include "ui/gfx/native_widget_types.h" #include "ui/ozone/public/gpu_platform_support.h" @@ -75,6 +76,8 @@ class DrmGpuPlatformSupport : public GpuPlatformSupport { void OnAddGraphicsDevice(const base::FilePath& path, const base::FileDescriptor& fd); void OnRemoveGraphicsDevice(const base::FilePath& path); + void OnGetHDCPState(int64_t display_id); + void OnSetHDCPState(int64_t display_id, HDCPState state); void SetIOTaskRunner( const scoped_refptr& io_task_runner); diff --git a/ui/ozone/platform/drm/host/drm_native_display_delegate.cc b/ui/ozone/platform/drm/host/drm_native_display_delegate.cc index 0a2a4c2e16cc..9eb76e03ffa9 100644 --- a/ui/ozone/platform/drm/host/drm_native_display_delegate.cc +++ b/ui/ozone/platform/drm/host/drm_native_display_delegate.cc @@ -197,18 +197,20 @@ bool DrmNativeDisplayDelegate::SetHDCPState(const DisplaySnapshot& output, } void DrmNativeDisplayDelegate::GetHDCPState( - const ui::DisplaySnapshot& output, + const DisplaySnapshot& output, const GetHDCPStateCallback& callback) { - NOTIMPLEMENTED(); - callback.Run(false, HDCP_STATE_UNDESIRED); + get_hdcp_state_callback_map_[output.display_id()] = callback; + if (!proxy_->Send(new OzoneGpuMsg_GetHDCPState(output.display_id()))) + OnHDCPStateReceived(output.display_id(), false, HDCP_STATE_UNDESIRED); } void DrmNativeDisplayDelegate::SetHDCPState( - const ui::DisplaySnapshot& output, - ui::HDCPState state, + const DisplaySnapshot& output, + HDCPState state, const SetHDCPStateCallback& callback) { - NOTIMPLEMENTED(); - callback.Run(false); + set_hdcp_state_callback_map_[output.display_id()] = callback; + if (!proxy_->Send(new OzoneGpuMsg_SetHDCPState(output.display_id(), state))) + OnHDCPStateUpdated(output.display_id(), false); } std::vector @@ -316,6 +318,8 @@ bool DrmNativeDisplayDelegate::OnMessageReceived(const IPC::Message& message) { IPC_BEGIN_MESSAGE_MAP(DrmNativeDisplayDelegate, message) IPC_MESSAGE_HANDLER(OzoneHostMsg_UpdateNativeDisplays, OnUpdateNativeDisplays) IPC_MESSAGE_HANDLER(OzoneHostMsg_DisplayConfigured, OnDisplayConfigured) + IPC_MESSAGE_HANDLER(OzoneHostMsg_HDCPStateReceived, OnHDCPStateReceived) + IPC_MESSAGE_HANDLER(OzoneHostMsg_HDCPStateUpdated, OnHDCPStateUpdated) IPC_MESSAGE_UNHANDLED(handled = false) IPC_END_MESSAGE_MAP() @@ -349,6 +353,27 @@ void DrmNativeDisplayDelegate::OnDisplayConfigured(int64_t display_id, } } +void DrmNativeDisplayDelegate::OnHDCPStateReceived(int64_t display_id, + bool status, + HDCPState state) { + auto it = get_hdcp_state_callback_map_.find(display_id); + if (it != get_hdcp_state_callback_map_.end()) { + base::ThreadTaskRunnerHandle::Get()->PostTask( + FROM_HERE, base::Bind(it->second, status, state)); + get_hdcp_state_callback_map_.erase(it); + } +} + +void DrmNativeDisplayDelegate::OnHDCPStateUpdated(int64_t display_id, + bool status) { + auto it = set_hdcp_state_callback_map_.find(display_id); + if (it != set_hdcp_state_callback_map_.end()) { + base::ThreadTaskRunnerHandle::Get()->PostTask( + FROM_HERE, base::Bind(it->second, status)); + set_hdcp_state_callback_map_.erase(it); + } +} + void DrmNativeDisplayDelegate::RunUpdateDisplaysCallback( const GetDisplaysCallback& callback) const { callback.Run(displays_.get()); diff --git a/ui/ozone/platform/drm/host/drm_native_display_delegate.h b/ui/ozone/platform/drm/host/drm_native_display_delegate.h index 986f28af950b..b6d6063a8ab0 100644 --- a/ui/ozone/platform/drm/host/drm_native_display_delegate.h +++ b/ui/ozone/platform/drm/host/drm_native_display_delegate.h @@ -84,6 +84,9 @@ class DrmNativeDisplayDelegate : public NativeDisplayDelegate, void OnNewGraphicsDevice(const base::FilePath& path, base::File file); + void OnHDCPStateReceived(int64_t display_id, bool status, HDCPState state); + void OnHDCPStateUpdated(int64_t display_id, bool status); + void RunUpdateDisplaysCallback(const GetDisplaysCallback& callback) const; DrmGpuPlatformSupportHost* proxy_; // Not owned. @@ -107,6 +110,10 @@ class DrmNativeDisplayDelegate : public NativeDisplayDelegate, // Map between display_id and the configuration callback. std::map configure_callback_map_; + std::map get_hdcp_state_callback_map_; + + std::map set_hdcp_state_callback_map_; + base::WeakPtrFactory weak_ptr_factory_; DISALLOW_COPY_AND_ASSIGN(DrmNativeDisplayDelegate); -- 2.11.4.GIT