Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / ui / ozone / platform / drm / host / drm_display_host.cc
blob9491e4ef2c45853a0a9aa89aaa2247c76db8b022
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"
13 namespace ui {
15 DrmDisplayHost::DrmDisplayHost(DrmGpuPlatformSupportHost* sender,
16 const DisplaySnapshot_Params& params,
17 bool is_dummy)
18 : sender_(sender),
19 snapshot_(new DisplaySnapshotProxy(params)),
20 is_dummy_(is_dummy) {
21 sender_->AddChannelObserver(this);
24 DrmDisplayHost::~DrmDisplayHost() {
25 sender_->RemoveChannelObserver(this);
26 ClearCallbacks();
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) {
37 if (is_dummy_) {
38 callback.Run(true);
39 return;
42 configure_callback_ = callback;
43 bool status = false;
44 if (mode) {
45 status = sender_->Send(new OzoneGpuMsg_ConfigureNativeDisplay(
46 snapshot_->display_id(), GetDisplayModeParams(*mode), origin));
47 } else {
48 status = sender_->Send(
49 new OzoneGpuMsg_DisableNativeDisplay(snapshot_->display_id()));
52 if (!status)
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));
60 } else {
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));
78 } else {
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;
89 if (!sender_->Send(
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));
98 } else {
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() {
111 is_dummy_ = false;
113 // Note: These responses are done here since the OnChannelDestroyed() is
114 // called after OnChannelEstablished().
115 ClearCallbacks();
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);
130 } // namespace ui