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/chromeos/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/chromeos/display_snapshot_proxy.h"
13 #include "ui/ozone/common/chromeos/display_util.h"
14 #include "ui/ozone/common/gpu/ozone_gpu_messages.h"
15 #include "ui/ozone/platform/dri/gpu_platform_support_host_gbm.h"
19 NativeDisplayDelegateProxy::NativeDisplayDelegateProxy(
20 GpuPlatformSupportHostGbm* proxy,
21 DeviceManager* device_manager)
23 device_manager_(device_manager) {
24 proxy_->RegisterHandler(this);
27 NativeDisplayDelegateProxy::~NativeDisplayDelegateProxy() {
29 device_manager_->RemoveObserver(this);
31 proxy_->UnregisterHandler(this);
34 void NativeDisplayDelegateProxy::Initialize() {
36 device_manager_->AddObserver(this);
39 void NativeDisplayDelegateProxy::GrabServer() {}
41 void NativeDisplayDelegateProxy::UngrabServer() {}
43 void NativeDisplayDelegateProxy::SyncWithServer() {}
45 void NativeDisplayDelegateProxy::SetBackgroundColor(uint32_t color_argb) {
49 void NativeDisplayDelegateProxy::ForceDPMSOn() {
50 proxy_->Send(new OzoneGpuMsg_ForceDPMSOn());
53 std::vector<DisplaySnapshot*> NativeDisplayDelegateProxy::GetDisplays() {
54 return displays_.get();
57 void NativeDisplayDelegateProxy::AddMode(const DisplaySnapshot& output,
58 const DisplayMode* mode) {}
60 bool NativeDisplayDelegateProxy::Configure(const DisplaySnapshot& output,
61 const DisplayMode* mode,
62 const gfx::Point& origin) {
63 // TODO(dnicoara) Should handle an asynchronous response.
65 proxy_->Send(new OzoneGpuMsg_ConfigureNativeDisplay(
66 output.display_id(), GetDisplayModeParams(*mode), origin));
68 proxy_->Send(new OzoneGpuMsg_DisableNativeDisplay(output.display_id()));
73 void NativeDisplayDelegateProxy::CreateFrameBuffer(const gfx::Size& size) {}
75 bool NativeDisplayDelegateProxy::GetHDCPState(const DisplaySnapshot& output,
81 bool NativeDisplayDelegateProxy::SetHDCPState(const DisplaySnapshot& output,
87 std::vector<ColorCalibrationProfile>
88 NativeDisplayDelegateProxy::GetAvailableColorCalibrationProfiles(
89 const DisplaySnapshot& output) {
91 return std::vector<ColorCalibrationProfile>();
94 bool NativeDisplayDelegateProxy::SetColorCalibrationProfile(
95 const DisplaySnapshot& output,
96 ColorCalibrationProfile new_profile) {
101 void NativeDisplayDelegateProxy::AddObserver(NativeDisplayObserver* observer) {
102 observers_.AddObserver(observer);
105 void NativeDisplayDelegateProxy::RemoveObserver(
106 NativeDisplayObserver* observer) {
107 observers_.RemoveObserver(observer);
110 void NativeDisplayDelegateProxy::OnDeviceEvent(const DeviceEvent& event) {
111 if (event.device_type() != DeviceEvent::DISPLAY)
114 if (event.action_type() == DeviceEvent::CHANGE) {
115 VLOG(1) << "Got display changed event";
116 proxy_->Send(new OzoneGpuMsg_RefreshNativeDisplays(
117 std::vector<DisplaySnapshot_Params>()));
121 void NativeDisplayDelegateProxy::OnChannelEstablished(
122 int host_id, IPC::Sender* sender) {
123 std::vector<DisplaySnapshot_Params> display_params;
124 for (size_t i = 0; i < displays_.size(); ++i)
125 display_params.push_back(GetDisplaySnapshotParams(*displays_[i]));
127 // Force an initial configure such that the browser process can get the actual
128 // state. Pass in the current display state since the GPU process may have
129 // crashed and we want to re-synchronize the state between processes.
130 proxy_->Send(new OzoneGpuMsg_RefreshNativeDisplays(display_params));
133 void NativeDisplayDelegateProxy::OnChannelDestroyed(int host_id) {
136 bool NativeDisplayDelegateProxy::OnMessageReceived(
137 const IPC::Message& message) {
140 IPC_BEGIN_MESSAGE_MAP(NativeDisplayDelegateProxy, message)
141 IPC_MESSAGE_HANDLER(OzoneHostMsg_UpdateNativeDisplays,
142 OnUpdateNativeDisplays)
143 IPC_MESSAGE_UNHANDLED(handled = false)
144 IPC_END_MESSAGE_MAP()
149 void NativeDisplayDelegateProxy::OnUpdateNativeDisplays(
150 const std::vector<DisplaySnapshot_Params>& displays) {
152 for (size_t i = 0; i < displays.size(); ++i)
153 displays_.push_back(new DisplaySnapshotProxy(displays[i]));
156 NativeDisplayObserver, observers_, OnConfigurationChanged());