OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/ozone/platform/dri/native_display_delegate_proxy.h" | 5 #include "ui/ozone/platform/dri/native_display_delegate_proxy.h" |
6 | 6 |
7 #include <stdio.h> | 7 #include <stdio.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "ui/display/types/display_snapshot.h" | 10 #include "ui/display/types/display_snapshot.h" |
(...skipping 29 matching lines...) Expand all Loading... |
40 }; | 40 }; |
41 | 41 |
42 } // namespace | 42 } // namespace |
43 | 43 |
44 NativeDisplayDelegateProxy::NativeDisplayDelegateProxy( | 44 NativeDisplayDelegateProxy::NativeDisplayDelegateProxy( |
45 DriGpuPlatformSupportHost* proxy, | 45 DriGpuPlatformSupportHost* proxy, |
46 DeviceManager* device_manager, | 46 DeviceManager* device_manager, |
47 DisplayManager* display_manager) | 47 DisplayManager* display_manager) |
48 : proxy_(proxy), | 48 : proxy_(proxy), |
49 device_manager_(device_manager), | 49 device_manager_(device_manager), |
50 display_manager_(display_manager) { | 50 display_manager_(display_manager), |
| 51 has_dummy_display_(false) { |
51 proxy_->RegisterHandler(this); | 52 proxy_->RegisterHandler(this); |
52 } | 53 } |
53 | 54 |
54 NativeDisplayDelegateProxy::~NativeDisplayDelegateProxy() { | 55 NativeDisplayDelegateProxy::~NativeDisplayDelegateProxy() { |
55 device_manager_->RemoveObserver(this); | 56 device_manager_->RemoveObserver(this); |
56 proxy_->UnregisterHandler(this); | 57 proxy_->UnregisterHandler(this); |
57 } | 58 } |
58 | 59 |
59 void NativeDisplayDelegateProxy::Initialize() { | 60 void NativeDisplayDelegateProxy::Initialize() { |
60 device_manager_->AddObserver(this); | 61 device_manager_->AddObserver(this); |
61 device_manager_->ScanDevices(this); | 62 device_manager_->ScanDevices(this); |
62 | 63 |
63 if (!displays_.empty()) | 64 if (!displays_.empty()) |
64 return; | 65 return; |
65 | 66 |
66 DisplaySnapshot_Params params = CreateSnapshotFromCommandLine(); | 67 DisplaySnapshot_Params params = CreateSnapshotFromCommandLine(); |
67 if (params.type != DISPLAY_CONNECTION_TYPE_NONE) | 68 if (params.type != DISPLAY_CONNECTION_TYPE_NONE) { |
68 displays_.push_back(new DriDisplaySnapshotProxy(params, display_manager_)); | 69 displays_.push_back(new DriDisplaySnapshotProxy(params, display_manager_)); |
| 70 has_dummy_display_ = true; |
| 71 } |
69 } | 72 } |
70 | 73 |
71 void NativeDisplayDelegateProxy::GrabServer() { | 74 void NativeDisplayDelegateProxy::GrabServer() { |
72 } | 75 } |
73 | 76 |
74 void NativeDisplayDelegateProxy::UngrabServer() { | 77 void NativeDisplayDelegateProxy::UngrabServer() { |
75 } | 78 } |
76 | 79 |
77 bool NativeDisplayDelegateProxy::TakeDisplayControl() { | 80 bool NativeDisplayDelegateProxy::TakeDisplayControl() { |
78 proxy_->Send(new OzoneGpuMsg_TakeDisplayControl()); | 81 proxy_->Send(new OzoneGpuMsg_TakeDisplayControl()); |
(...skipping 12 matching lines...) Expand all Loading... |
91 NOTIMPLEMENTED(); | 94 NOTIMPLEMENTED(); |
92 } | 95 } |
93 | 96 |
94 void NativeDisplayDelegateProxy::ForceDPMSOn() { | 97 void NativeDisplayDelegateProxy::ForceDPMSOn() { |
95 proxy_->Send(new OzoneGpuMsg_ForceDPMSOn()); | 98 proxy_->Send(new OzoneGpuMsg_ForceDPMSOn()); |
96 } | 99 } |
97 | 100 |
98 void NativeDisplayDelegateProxy::GetDisplays( | 101 void NativeDisplayDelegateProxy::GetDisplays( |
99 const GetDisplaysCallback& callback) { | 102 const GetDisplaysCallback& callback) { |
100 // GetDisplays() is supposed to force a refresh of the display list. | 103 // GetDisplays() is supposed to force a refresh of the display list. |
101 proxy_->Send(new OzoneGpuMsg_RefreshNativeDisplays( | 104 if (proxy_->Send(new OzoneGpuMsg_RefreshNativeDisplays())) |
102 std::vector<DisplaySnapshot_Params>())); | 105 get_displays_callback_ = callback; |
103 callback.Run(displays_.get()); | 106 else |
| 107 callback.Run(displays_.get()); |
104 } | 108 } |
105 | 109 |
106 void NativeDisplayDelegateProxy::AddMode(const DisplaySnapshot& output, | 110 void NativeDisplayDelegateProxy::AddMode(const DisplaySnapshot& output, |
107 const DisplayMode* mode) { | 111 const DisplayMode* mode) { |
108 } | 112 } |
109 | 113 |
110 void NativeDisplayDelegateProxy::Configure(const DisplaySnapshot& output, | 114 void NativeDisplayDelegateProxy::Configure(const DisplaySnapshot& output, |
111 const DisplayMode* mode, | 115 const DisplayMode* mode, |
112 const gfx::Point& origin, | 116 const gfx::Point& origin, |
113 const ConfigureCallback& callback) { | 117 const ConfigureCallback& callback) { |
114 // TODO(dnicoara) Should handle an asynchronous response. | 118 if (has_dummy_display_) { |
115 if (mode) | 119 callback.Run(true); |
116 proxy_->Send(new OzoneGpuMsg_ConfigureNativeDisplay( | 120 return; |
| 121 } |
| 122 |
| 123 bool status = false; |
| 124 if (mode) { |
| 125 status = proxy_->Send(new OzoneGpuMsg_ConfigureNativeDisplay( |
117 output.display_id(), GetDisplayModeParams(*mode), origin)); | 126 output.display_id(), GetDisplayModeParams(*mode), origin)); |
| 127 } else { |
| 128 status = |
| 129 proxy_->Send(new OzoneGpuMsg_DisableNativeDisplay(output.display_id())); |
| 130 } |
| 131 |
| 132 if (status) |
| 133 configure_callback_map_[output.display_id()] = callback; |
118 else | 134 else |
119 proxy_->Send(new OzoneGpuMsg_DisableNativeDisplay(output.display_id())); | 135 callback.Run(false); |
120 | |
121 callback.Run(true); | |
122 } | 136 } |
123 | 137 |
124 void NativeDisplayDelegateProxy::CreateFrameBuffer(const gfx::Size& size) { | 138 void NativeDisplayDelegateProxy::CreateFrameBuffer(const gfx::Size& size) { |
125 } | 139 } |
126 | 140 |
127 bool NativeDisplayDelegateProxy::GetHDCPState(const DisplaySnapshot& output, | 141 bool NativeDisplayDelegateProxy::GetHDCPState(const DisplaySnapshot& output, |
128 HDCPState* state) { | 142 HDCPState* state) { |
129 NOTIMPLEMENTED(); | 143 NOTIMPLEMENTED(); |
130 return false; | 144 return false; |
131 } | 145 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 if (event.device_type() != DeviceEvent::DISPLAY) | 177 if (event.device_type() != DeviceEvent::DISPLAY) |
164 return; | 178 return; |
165 | 179 |
166 switch (event.action_type()) { | 180 switch (event.action_type()) { |
167 case DeviceEvent::ADD: | 181 case DeviceEvent::ADD: |
168 VLOG(1) << "Got display added event for " << event.path().value(); | 182 VLOG(1) << "Got display added event for " << event.path().value(); |
169 proxy_->Send(new OzoneGpuMsg_AddGraphicsDevice(event.path())); | 183 proxy_->Send(new OzoneGpuMsg_AddGraphicsDevice(event.path())); |
170 break; | 184 break; |
171 case DeviceEvent::CHANGE: | 185 case DeviceEvent::CHANGE: |
172 VLOG(1) << "Got display changed event for " << event.path().value(); | 186 VLOG(1) << "Got display changed event for " << event.path().value(); |
173 proxy_->Send(new OzoneGpuMsg_RefreshNativeDisplays( | |
174 std::vector<DisplaySnapshot_Params>())); | |
175 break; | 187 break; |
176 case DeviceEvent::REMOVE: | 188 case DeviceEvent::REMOVE: |
177 VLOG(1) << "Got display removed event for " << event.path().value(); | 189 VLOG(1) << "Got display removed event for " << event.path().value(); |
178 proxy_->Send(new OzoneGpuMsg_RemoveGraphicsDevice(event.path())); | 190 proxy_->Send(new OzoneGpuMsg_RemoveGraphicsDevice(event.path())); |
179 break; | 191 break; |
180 } | 192 } |
| 193 |
| 194 FOR_EACH_OBSERVER(NativeDisplayObserver, observers_, |
| 195 OnConfigurationChanged()); |
181 } | 196 } |
182 | 197 |
183 void NativeDisplayDelegateProxy::OnChannelEstablished(int host_id, | 198 void NativeDisplayDelegateProxy::OnChannelEstablished(int host_id, |
184 IPC::Sender* sender) { | 199 IPC::Sender* sender) { |
185 std::vector<DisplaySnapshot_Params> display_params; | 200 FOR_EACH_OBSERVER(NativeDisplayObserver, observers_, |
186 for (size_t i = 0; i < displays_.size(); ++i) | 201 OnConfigurationChanged()); |
187 display_params.push_back(GetDisplaySnapshotParams(*displays_[i])); | |
188 | |
189 // Force an initial configure such that the browser process can get the actual | |
190 // state. Pass in the current display state since the GPU process may have | |
191 // crashed and we want to re-synchronize the state between processes. | |
192 proxy_->Send(new OzoneGpuMsg_RefreshNativeDisplays(display_params)); | |
193 } | 202 } |
194 | 203 |
195 void NativeDisplayDelegateProxy::OnChannelDestroyed(int host_id) { | 204 void NativeDisplayDelegateProxy::OnChannelDestroyed(int host_id) { |
| 205 // If the channel got destroyed in the middle of a configuration then just |
| 206 // respond with failure. |
| 207 if (!get_displays_callback_.is_null()) { |
| 208 get_displays_callback_.Run(std::vector<DisplaySnapshot*>()); |
| 209 get_displays_callback_.Reset(); |
| 210 } |
| 211 |
| 212 for (const auto& pair : configure_callback_map_) { |
| 213 pair.second.Run(false); |
| 214 } |
| 215 |
| 216 configure_callback_map_.clear(); |
196 } | 217 } |
197 | 218 |
198 bool NativeDisplayDelegateProxy::OnMessageReceived( | 219 bool NativeDisplayDelegateProxy::OnMessageReceived( |
199 const IPC::Message& message) { | 220 const IPC::Message& message) { |
200 bool handled = true; | 221 bool handled = true; |
201 | 222 |
202 IPC_BEGIN_MESSAGE_MAP(NativeDisplayDelegateProxy, message) | 223 IPC_BEGIN_MESSAGE_MAP(NativeDisplayDelegateProxy, message) |
203 IPC_MESSAGE_HANDLER(OzoneHostMsg_UpdateNativeDisplays, OnUpdateNativeDisplays) | 224 IPC_MESSAGE_HANDLER(OzoneHostMsg_UpdateNativeDisplays, OnUpdateNativeDisplays) |
| 225 IPC_MESSAGE_HANDLER(OzoneHostMsg_DisplayConfigured, OnDisplayConfigured) |
204 IPC_MESSAGE_UNHANDLED(handled = false) | 226 IPC_MESSAGE_UNHANDLED(handled = false) |
205 IPC_END_MESSAGE_MAP() | 227 IPC_END_MESSAGE_MAP() |
206 | 228 |
207 return handled; | 229 return handled; |
208 } | 230 } |
209 | 231 |
210 void NativeDisplayDelegateProxy::OnUpdateNativeDisplays( | 232 void NativeDisplayDelegateProxy::OnUpdateNativeDisplays( |
211 const std::vector<DisplaySnapshot_Params>& displays) { | 233 const std::vector<DisplaySnapshot_Params>& displays) { |
212 bool has_new_displays = displays.size() != displays_.size(); | 234 has_dummy_display_ = false; |
213 if (!has_new_displays) { | |
214 for (DisplaySnapshot* display : displays_) { | |
215 auto it = std::find_if(displays.begin(), displays.end(), | |
216 FindDisplayById(display->display_id())); | |
217 if (it == displays.end()) { | |
218 has_new_displays = true; | |
219 break; | |
220 } | |
221 } | |
222 } | |
223 | |
224 // If the configuration hasn't changed do not update. | |
225 if (!has_new_displays) | |
226 return; | |
227 | |
228 displays_.clear(); | 235 displays_.clear(); |
229 for (size_t i = 0; i < displays.size(); ++i) | 236 for (size_t i = 0; i < displays.size(); ++i) |
230 displays_.push_back( | 237 displays_.push_back( |
231 new DriDisplaySnapshotProxy(displays[i], display_manager_)); | 238 new DriDisplaySnapshotProxy(displays[i], display_manager_)); |
232 | 239 |
233 FOR_EACH_OBSERVER(NativeDisplayObserver, observers_, | 240 if (!get_displays_callback_.is_null()) |
234 OnConfigurationChanged()); | 241 get_displays_callback_.Run(displays_.get()); |
| 242 } |
| 243 |
| 244 void NativeDisplayDelegateProxy::OnDisplayConfigured(int64_t display_id, |
| 245 bool status) { |
| 246 auto it = configure_callback_map_.find(display_id); |
| 247 if (it != configure_callback_map_.end()) { |
| 248 it->second.Run(status); |
| 249 configure_callback_map_.erase(it); |
| 250 } |
235 } | 251 } |
236 | 252 |
237 } // namespace ui | 253 } // namespace ui |
OLD | NEW |