Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / ui / ozone / platform / dri / chromeos / native_display_delegate_proxy.cc
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.
4
5 #include "ui/ozone/platform/dri/chromeos/native_display_delegate_proxy.h"
6
7 #include "base/logging.h"
8 #include "ui/display/types/chromeos/display_snapshot.h"
9 #include "ui/display/types/chromeos/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"
16
17 namespace ui {
18
19 NativeDisplayDelegateProxy::NativeDisplayDelegateProxy(
20     GpuPlatformSupportHostGbm* proxy,
21     DeviceManager* device_manager)
22     : proxy_(proxy),
23       device_manager_(device_manager) {
24   proxy_->RegisterHandler(this);
25 }
26
27 NativeDisplayDelegateProxy::~NativeDisplayDelegateProxy() {
28   if (device_manager_)
29     device_manager_->RemoveObserver(this);
30
31   proxy_->UnregisterHandler(this);
32 }
33
34 void NativeDisplayDelegateProxy::Initialize() {
35   if (device_manager_)
36     device_manager_->AddObserver(this);
37 }
38
39 void NativeDisplayDelegateProxy::GrabServer() {}
40
41 void NativeDisplayDelegateProxy::UngrabServer() {}
42
43 void NativeDisplayDelegateProxy::SyncWithServer() {}
44
45 void NativeDisplayDelegateProxy::SetBackgroundColor(uint32_t color_argb) {
46   NOTIMPLEMENTED();
47 }
48
49 void NativeDisplayDelegateProxy::ForceDPMSOn() {
50   proxy_->Send(new OzoneGpuMsg_ForceDPMSOn());
51 }
52
53 std::vector<DisplaySnapshot*> NativeDisplayDelegateProxy::GetDisplays() {
54   return displays_.get();
55 }
56
57 void NativeDisplayDelegateProxy::AddMode(const DisplaySnapshot& output,
58                                          const DisplayMode* mode) {}
59
60 bool NativeDisplayDelegateProxy::Configure(const DisplaySnapshot& output,
61                                            const DisplayMode* mode,
62                                            const gfx::Point& origin) {
63   // TODO(dnicoara) Should handle an asynchronous response.
64   if (mode)
65     proxy_->Send(new OzoneGpuMsg_ConfigureNativeDisplay(
66         output.display_id(), GetDisplayModeParams(*mode), origin));
67   else
68     proxy_->Send(new OzoneGpuMsg_DisableNativeDisplay(output.display_id()));
69
70   return true;
71 }
72
73 void NativeDisplayDelegateProxy::CreateFrameBuffer(const gfx::Size& size) {}
74
75 bool NativeDisplayDelegateProxy::GetHDCPState(const DisplaySnapshot& output,
76                                               HDCPState* state) {
77   NOTIMPLEMENTED();
78   return false;
79 }
80
81 bool NativeDisplayDelegateProxy::SetHDCPState(const DisplaySnapshot& output,
82                                               HDCPState state) {
83   NOTIMPLEMENTED();
84   return false;
85 }
86
87 std::vector<ColorCalibrationProfile>
88 NativeDisplayDelegateProxy::GetAvailableColorCalibrationProfiles(
89     const DisplaySnapshot& output) {
90   NOTIMPLEMENTED();
91   return std::vector<ColorCalibrationProfile>();
92 }
93
94 bool NativeDisplayDelegateProxy::SetColorCalibrationProfile(
95     const DisplaySnapshot& output,
96     ColorCalibrationProfile new_profile) {
97   NOTIMPLEMENTED();
98   return false;
99 }
100
101 void NativeDisplayDelegateProxy::AddObserver(NativeDisplayObserver* observer) {
102   observers_.AddObserver(observer);
103 }
104
105 void NativeDisplayDelegateProxy::RemoveObserver(
106     NativeDisplayObserver* observer) {
107   observers_.RemoveObserver(observer);
108 }
109
110 void NativeDisplayDelegateProxy::OnDeviceEvent(const DeviceEvent& event) {
111   if (event.device_type() != DeviceEvent::DISPLAY)
112     return;
113
114   if (event.action_type() == DeviceEvent::CHANGE) {
115     VLOG(1) << "Got display changed event";
116     proxy_->Send(new OzoneGpuMsg_RefreshNativeDisplays());
117   }
118 }
119
120 void NativeDisplayDelegateProxy::OnChannelEstablished(
121     int host_id, IPC::Sender* sender) {
122   // Force an initial configure such that the browser process can get the actual
123   // state.
124   proxy_->Send(new OzoneGpuMsg_RefreshNativeDisplays());
125 }
126
127 void NativeDisplayDelegateProxy::OnChannelDestroyed(int host_id) {
128 }
129
130 bool NativeDisplayDelegateProxy::OnMessageReceived(
131     const IPC::Message& message) {
132   bool handled = true;
133
134   IPC_BEGIN_MESSAGE_MAP(NativeDisplayDelegateProxy, message)
135   IPC_MESSAGE_HANDLER(OzoneHostMsg_UpdateNativeDisplays,
136                       OnUpdateNativeDisplays)
137   IPC_MESSAGE_UNHANDLED(handled = false)
138   IPC_END_MESSAGE_MAP()
139
140   return handled;
141 }
142
143 void NativeDisplayDelegateProxy::OnUpdateNativeDisplays(
144     const std::vector<DisplaySnapshot_Params>& displays) {
145   displays_.clear();
146   for (size_t i = 0; i < displays.size(); ++i)
147     displays_.push_back(new DisplaySnapshotProxy(displays[i]));
148
149   FOR_EACH_OBSERVER(
150       NativeDisplayObserver, observers_, OnConfigurationChanged());
151 }
152
153 }  // namespace ui