Upstream version 11.40.271.0
[platform/framework/web/crosswalk.git] / src / ui / ozone / platform / dri / 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/native_display_delegate_proxy.h"
6
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"
16
17 namespace ui {
18
19 NativeDisplayDelegateProxy::NativeDisplayDelegateProxy(
20     DriGpuPlatformSupportHost* proxy,
21     DeviceManager* device_manager)
22     : proxy_(proxy), device_manager_(device_manager) {
23   proxy_->RegisterHandler(this);
24 }
25
26 NativeDisplayDelegateProxy::~NativeDisplayDelegateProxy() {
27   if (device_manager_)
28     device_manager_->RemoveObserver(this);
29
30   proxy_->UnregisterHandler(this);
31 }
32
33 void NativeDisplayDelegateProxy::Initialize() {
34   if (device_manager_)
35     device_manager_->AddObserver(this);
36 }
37
38 void NativeDisplayDelegateProxy::GrabServer() {
39 }
40
41 void NativeDisplayDelegateProxy::UngrabServer() {
42 }
43
44 bool NativeDisplayDelegateProxy::TakeDisplayControl() {
45   proxy_->Send(new OzoneGpuMsg_TakeDisplayControl());
46   return true;
47 }
48
49 bool NativeDisplayDelegateProxy::RelinquishDisplayControl() {
50   proxy_->Send(new OzoneGpuMsg_RelinquishDisplayControl());
51   return true;
52 }
53
54 void NativeDisplayDelegateProxy::SyncWithServer() {
55 }
56
57 void NativeDisplayDelegateProxy::SetBackgroundColor(uint32_t color_argb) {
58   NOTIMPLEMENTED();
59 }
60
61 void NativeDisplayDelegateProxy::ForceDPMSOn() {
62   proxy_->Send(new OzoneGpuMsg_ForceDPMSOn());
63 }
64
65 std::vector<DisplaySnapshot*> NativeDisplayDelegateProxy::GetDisplays() {
66   return displays_.get();
67 }
68
69 void NativeDisplayDelegateProxy::AddMode(const DisplaySnapshot& output,
70                                          const DisplayMode* mode) {
71 }
72
73 bool NativeDisplayDelegateProxy::Configure(const DisplaySnapshot& output,
74                                            const DisplayMode* mode,
75                                            const gfx::Point& origin) {
76   // TODO(dnicoara) Should handle an asynchronous response.
77   if (mode)
78     proxy_->Send(new OzoneGpuMsg_ConfigureNativeDisplay(
79         output.display_id(), GetDisplayModeParams(*mode), origin));
80   else
81     proxy_->Send(new OzoneGpuMsg_DisableNativeDisplay(output.display_id()));
82
83   return true;
84 }
85
86 void NativeDisplayDelegateProxy::CreateFrameBuffer(const gfx::Size& size) {
87 }
88
89 bool NativeDisplayDelegateProxy::GetHDCPState(const DisplaySnapshot& output,
90                                               HDCPState* state) {
91   NOTIMPLEMENTED();
92   return false;
93 }
94
95 bool NativeDisplayDelegateProxy::SetHDCPState(const DisplaySnapshot& output,
96                                               HDCPState state) {
97   NOTIMPLEMENTED();
98   return false;
99 }
100
101 std::vector<ColorCalibrationProfile>
102 NativeDisplayDelegateProxy::GetAvailableColorCalibrationProfiles(
103     const DisplaySnapshot& output) {
104   NOTIMPLEMENTED();
105   return std::vector<ColorCalibrationProfile>();
106 }
107
108 bool NativeDisplayDelegateProxy::SetColorCalibrationProfile(
109     const DisplaySnapshot& output,
110     ColorCalibrationProfile new_profile) {
111   NOTIMPLEMENTED();
112   return false;
113 }
114
115 void NativeDisplayDelegateProxy::AddObserver(NativeDisplayObserver* observer) {
116   observers_.AddObserver(observer);
117 }
118
119 void NativeDisplayDelegateProxy::RemoveObserver(
120     NativeDisplayObserver* observer) {
121   observers_.RemoveObserver(observer);
122 }
123
124 void NativeDisplayDelegateProxy::OnDeviceEvent(const DeviceEvent& event) {
125   if (event.device_type() != DeviceEvent::DISPLAY)
126     return;
127
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>()));
132   }
133 }
134
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]));
140
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));
145 }
146
147 void NativeDisplayDelegateProxy::OnChannelDestroyed(int host_id) {
148 }
149
150 bool NativeDisplayDelegateProxy::OnMessageReceived(
151     const IPC::Message& message) {
152   bool handled = true;
153
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()
158
159   return handled;
160 }
161
162 void NativeDisplayDelegateProxy::OnUpdateNativeDisplays(
163     const std::vector<DisplaySnapshot_Params>& displays) {
164   displays_.clear();
165   for (size_t i = 0; i < displays.size(); ++i)
166     displays_.push_back(new DisplaySnapshotProxy(displays[i]));
167
168   FOR_EACH_OBSERVER(NativeDisplayObserver, observers_,
169                     OnConfigurationChanged());
170 }
171
172 }  // namespace ui