1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ui/ozone/platform/drm/host/drm_display_host.h"
7 #include "base/thread_task_runner_handle.h"
8 #include "ui/ozone/common/display_snapshot_proxy.h"
9 #include "ui/ozone/common/display_util.h"
10 #include "ui/ozone/common/gpu/ozone_gpu_messages.h"
11 #include "ui/ozone/platform/drm/host/drm_gpu_platform_support_host.h"
15 DrmDisplayHost::DrmDisplayHost(DrmGpuPlatformSupportHost
* sender
,
16 const DisplaySnapshot_Params
& params
,
19 snapshot_(new DisplaySnapshotProxy(params
)),
21 sender_
->AddChannelObserver(this);
24 DrmDisplayHost::~DrmDisplayHost() {
25 sender_
->RemoveChannelObserver(this);
29 void DrmDisplayHost::UpdateDisplaySnapshot(
30 const DisplaySnapshot_Params
& params
) {
31 snapshot_
= make_scoped_ptr(new DisplaySnapshotProxy(params
));
34 void DrmDisplayHost::Configure(const DisplayMode
* mode
,
35 const gfx::Point
& origin
,
36 const ConfigureCallback
& callback
) {
42 configure_callback_
= callback
;
45 status
= sender_
->Send(new OzoneGpuMsg_ConfigureNativeDisplay(
46 snapshot_
->display_id(), GetDisplayModeParams(*mode
), origin
));
48 status
= sender_
->Send(
49 new OzoneGpuMsg_DisableNativeDisplay(snapshot_
->display_id()));
53 OnDisplayConfigured(false);
56 void DrmDisplayHost::OnDisplayConfigured(bool status
) {
57 if (!configure_callback_
.is_null()) {
58 base::ThreadTaskRunnerHandle::Get()->PostTask(
59 FROM_HERE
, base::Bind(configure_callback_
, status
));
61 LOG(ERROR
) << "Got unexpected event for display "
62 << snapshot_
->display_id();
65 configure_callback_
.Reset();
68 void DrmDisplayHost::GetHDCPState(const GetHDCPStateCallback
& callback
) {
69 get_hdcp_callback_
= callback
;
70 if (!sender_
->Send(new OzoneGpuMsg_GetHDCPState(snapshot_
->display_id())))
71 OnHDCPStateReceived(false, HDCP_STATE_UNDESIRED
);
74 void DrmDisplayHost::OnHDCPStateReceived(bool status
, HDCPState state
) {
75 if (!get_hdcp_callback_
.is_null()) {
76 base::ThreadTaskRunnerHandle::Get()->PostTask(
77 FROM_HERE
, base::Bind(get_hdcp_callback_
, status
, state
));
79 LOG(ERROR
) << "Got unexpected event for display "
80 << snapshot_
->display_id();
83 get_hdcp_callback_
.Reset();
86 void DrmDisplayHost::SetHDCPState(HDCPState state
,
87 const SetHDCPStateCallback
& callback
) {
88 set_hdcp_callback_
= callback
;
90 new OzoneGpuMsg_SetHDCPState(snapshot_
->display_id(), state
)))
91 OnHDCPStateUpdated(false);
94 void DrmDisplayHost::OnHDCPStateUpdated(bool status
) {
95 if (!set_hdcp_callback_
.is_null()) {
96 base::ThreadTaskRunnerHandle::Get()->PostTask(
97 FROM_HERE
, base::Bind(set_hdcp_callback_
, status
));
99 LOG(ERROR
) << "Got unexpected event for display "
100 << snapshot_
->display_id();
103 set_hdcp_callback_
.Reset();
106 void DrmDisplayHost::SetGammaRamp(const std::vector
<GammaRampRGBEntry
>& lut
) {
107 sender_
->Send(new OzoneGpuMsg_SetGammaRamp(snapshot_
->display_id(), lut
));
110 void DrmDisplayHost::OnChannelEstablished() {
113 // Note: These responses are done here since the OnChannelDestroyed() is
114 // called after OnChannelEstablished().
118 void DrmDisplayHost::OnChannelDestroyed() {
121 void DrmDisplayHost::ClearCallbacks() {
122 if (!configure_callback_
.is_null())
123 OnDisplayConfigured(false);
124 if (!get_hdcp_callback_
.is_null())
125 OnHDCPStateReceived(false, HDCP_STATE_UNDESIRED
);
126 if (!set_hdcp_callback_
.is_null())
127 OnHDCPStateUpdated(false);