1 // Copyright 2014 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/dri/native_display_delegate_proxy.h"
7 #include "base/logging.h"
8 #include "ui/display/types/display_snapshot.h"
9 #include "ui/display/types/native_display_observer.h"
10 #include "ui/events/ozone/device/device_event.h"
11 #include "ui/events/ozone/device/device_manager.h"
12 #include "ui/ozone/common/display_snapshot_proxy.h"
13 #include "ui/ozone/common/display_util.h"
14 #include "ui/ozone/common/gpu/ozone_gpu_messages.h"
15 #include "ui/ozone/platform/dri/dri_gpu_platform_support_host.h"
19 NativeDisplayDelegateProxy::NativeDisplayDelegateProxy(
20 DriGpuPlatformSupportHost* proxy,
21 DeviceManager* device_manager)
22 : proxy_(proxy), device_manager_(device_manager) {
23 proxy_->RegisterHandler(this);
26 NativeDisplayDelegateProxy::~NativeDisplayDelegateProxy() {
28 device_manager_->RemoveObserver(this);
30 proxy_->UnregisterHandler(this);
33 void NativeDisplayDelegateProxy::Initialize() {
35 device_manager_->AddObserver(this);
38 void NativeDisplayDelegateProxy::GrabServer() {
41 void NativeDisplayDelegateProxy::UngrabServer() {
44 bool NativeDisplayDelegateProxy::TakeDisplayControl() {
45 proxy_->Send(new OzoneGpuMsg_TakeDisplayControl());
49 bool NativeDisplayDelegateProxy::RelinquishDisplayControl() {
50 proxy_->Send(new OzoneGpuMsg_RelinquishDisplayControl());
54 void NativeDisplayDelegateProxy::SyncWithServer() {
57 void NativeDisplayDelegateProxy::SetBackgroundColor(uint32_t color_argb) {
61 void NativeDisplayDelegateProxy::ForceDPMSOn() {
62 proxy_->Send(new OzoneGpuMsg_ForceDPMSOn());
65 std::vector<DisplaySnapshot*> NativeDisplayDelegateProxy::GetDisplays() {
66 return displays_.get();
69 void NativeDisplayDelegateProxy::AddMode(const DisplaySnapshot& output,
70 const DisplayMode* mode) {
73 bool NativeDisplayDelegateProxy::Configure(const DisplaySnapshot& output,
74 const DisplayMode* mode,
75 const gfx::Point& origin) {
76 // TODO(dnicoara) Should handle an asynchronous response.
78 proxy_->Send(new OzoneGpuMsg_ConfigureNativeDisplay(
79 output.display_id(), GetDisplayModeParams(*mode), origin));
81 proxy_->Send(new OzoneGpuMsg_DisableNativeDisplay(output.display_id()));
86 void NativeDisplayDelegateProxy::CreateFrameBuffer(const gfx::Size& size) {
89 bool NativeDisplayDelegateProxy::GetHDCPState(const DisplaySnapshot& output,
95 bool NativeDisplayDelegateProxy::SetHDCPState(const DisplaySnapshot& output,
101 std::vector<ColorCalibrationProfile>
102 NativeDisplayDelegateProxy::GetAvailableColorCalibrationProfiles(
103 const DisplaySnapshot& output) {
105 return std::vector<ColorCalibrationProfile>();
108 bool NativeDisplayDelegateProxy::SetColorCalibrationProfile(
109 const DisplaySnapshot& output,
110 ColorCalibrationProfile new_profile) {
115 void NativeDisplayDelegateProxy::AddObserver(NativeDisplayObserver* observer) {
116 observers_.AddObserver(observer);
119 void NativeDisplayDelegateProxy::RemoveObserver(
120 NativeDisplayObserver* observer) {
121 observers_.RemoveObserver(observer);
124 void NativeDisplayDelegateProxy::OnDeviceEvent(const DeviceEvent& event) {
125 if (event.device_type() != DeviceEvent::DISPLAY)
128 if (event.action_type() == DeviceEvent::CHANGE) {
129 VLOG(1) << "Got display changed event";
130 proxy_->Send(new OzoneGpuMsg_RefreshNativeDisplays(
131 std::vector<DisplaySnapshot_Params>()));
135 void NativeDisplayDelegateProxy::OnChannelEstablished(int host_id,
136 IPC::Sender* sender) {
137 std::vector<DisplaySnapshot_Params> display_params;
138 for (size_t i = 0; i < displays_.size(); ++i)
139 display_params.push_back(GetDisplaySnapshotParams(*displays_[i]));
141 // Force an initial configure such that the browser process can get the actual
142 // state. Pass in the current display state since the GPU process may have
143 // crashed and we want to re-synchronize the state between processes.
144 proxy_->Send(new OzoneGpuMsg_RefreshNativeDisplays(display_params));
147 void NativeDisplayDelegateProxy::OnChannelDestroyed(int host_id) {
150 bool NativeDisplayDelegateProxy::OnMessageReceived(
151 const IPC::Message& message) {
154 IPC_BEGIN_MESSAGE_MAP(NativeDisplayDelegateProxy, message)
155 IPC_MESSAGE_HANDLER(OzoneHostMsg_UpdateNativeDisplays, OnUpdateNativeDisplays)
156 IPC_MESSAGE_UNHANDLED(handled = false)
157 IPC_END_MESSAGE_MAP()
162 void NativeDisplayDelegateProxy::OnUpdateNativeDisplays(
163 const std::vector<DisplaySnapshot_Params>& displays) {
165 for (size_t i = 0; i < displays.size(); ++i)
166 displays_.push_back(new DisplaySnapshotProxy(displays[i]));
168 FOR_EACH_OBSERVER(NativeDisplayObserver, observers_,
169 OnConfigurationChanged());