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 "base/thread_task_runner_handle.h" |
10 #include "base/threading/thread_restrictions.h" | 11 #include "base/threading/thread_restrictions.h" |
| 12 #include "base/threading/worker_pool.h" |
11 #include "ui/display/types/display_snapshot.h" | 13 #include "ui/display/types/display_snapshot.h" |
12 #include "ui/display/types/native_display_observer.h" | 14 #include "ui/display/types/native_display_observer.h" |
13 #include "ui/events/ozone/device/device_event.h" | 15 #include "ui/events/ozone/device/device_event.h" |
14 #include "ui/events/ozone/device/device_manager.h" | 16 #include "ui/events/ozone/device/device_manager.h" |
15 #include "ui/ozone/common/display_snapshot_proxy.h" | 17 #include "ui/ozone/common/display_snapshot_proxy.h" |
16 #include "ui/ozone/common/display_util.h" | 18 #include "ui/ozone/common/display_util.h" |
17 #include "ui/ozone/common/gpu/ozone_gpu_messages.h" | 19 #include "ui/ozone/common/gpu/ozone_gpu_messages.h" |
18 #include "ui/ozone/platform/dri/display_manager.h" | 20 #include "ui/ozone/platform/dri/display_manager.h" |
19 #include "ui/ozone/platform/dri/dri_gpu_platform_support_host.h" | 21 #include "ui/ozone/platform/dri/dri_gpu_platform_support_host.h" |
20 | 22 |
21 namespace ui { | 23 namespace ui { |
22 | 24 |
23 namespace { | 25 namespace { |
24 | 26 |
| 27 const char kDefaultGraphicsCardPath[] = "/dev/dri/card0"; |
| 28 |
| 29 typedef base::Callback<void(const base::FilePath&, base::File)> |
| 30 OnOpenDeviceReplyCallback; |
| 31 |
| 32 void OpenDeviceOnWorkerThread( |
| 33 const base::FilePath& path, |
| 34 const scoped_refptr<base::TaskRunner>& reply_runner, |
| 35 const OnOpenDeviceReplyCallback& callback) { |
| 36 base::File file(path, base::File::FLAG_OPEN | base::File::FLAG_READ | |
| 37 base::File::FLAG_WRITE); |
| 38 |
| 39 base::File::Info info; |
| 40 file.GetInfo(&info); |
| 41 |
| 42 CHECK(!info.is_directory); |
| 43 CHECK(path.DirName() == base::FilePath("/dev/dri")); |
| 44 |
| 45 if (file.IsValid()) { |
| 46 reply_runner->PostTask( |
| 47 FROM_HERE, base::Bind(callback, path, base::Passed(file.Pass()))); |
| 48 } |
| 49 } |
| 50 |
25 class DriDisplaySnapshotProxy : public DisplaySnapshotProxy { | 51 class DriDisplaySnapshotProxy : public DisplaySnapshotProxy { |
26 public: | 52 public: |
27 DriDisplaySnapshotProxy(const DisplaySnapshot_Params& params, | 53 DriDisplaySnapshotProxy(const DisplaySnapshot_Params& params, |
28 DisplayManager* display_manager) | 54 DisplayManager* display_manager) |
29 : DisplaySnapshotProxy(params), display_manager_(display_manager) { | 55 : DisplaySnapshotProxy(params), display_manager_(display_manager) { |
30 display_manager_->RegisterDisplay(this); | 56 display_manager_->RegisterDisplay(this); |
31 } | 57 } |
32 | 58 |
33 ~DriDisplaySnapshotProxy() override { | 59 ~DriDisplaySnapshotProxy() override { |
34 display_manager_->UnregisterDisplay(this); | 60 display_manager_->UnregisterDisplay(this); |
35 } | 61 } |
36 | 62 |
37 private: | 63 private: |
38 DisplayManager* display_manager_; // Not owned. | 64 DisplayManager* display_manager_; // Not owned. |
39 | 65 |
40 DISALLOW_COPY_AND_ASSIGN(DriDisplaySnapshotProxy); | 66 DISALLOW_COPY_AND_ASSIGN(DriDisplaySnapshotProxy); |
41 }; | 67 }; |
42 | 68 |
43 } // namespace | 69 } // namespace |
44 | 70 |
45 NativeDisplayDelegateProxy::NativeDisplayDelegateProxy( | 71 NativeDisplayDelegateProxy::NativeDisplayDelegateProxy( |
46 DriGpuPlatformSupportHost* proxy, | 72 DriGpuPlatformSupportHost* proxy, |
47 DeviceManager* device_manager, | 73 DeviceManager* device_manager, |
48 DisplayManager* display_manager) | 74 DisplayManager* display_manager) |
49 : proxy_(proxy), | 75 : proxy_(proxy), |
50 device_manager_(device_manager), | 76 device_manager_(device_manager), |
51 display_manager_(display_manager), | 77 display_manager_(display_manager), |
52 has_dummy_display_(false) { | 78 has_dummy_display_(false), |
| 79 weak_ptr_factory_(this) { |
53 proxy_->RegisterHandler(this); | 80 proxy_->RegisterHandler(this); |
54 } | 81 } |
55 | 82 |
56 NativeDisplayDelegateProxy::~NativeDisplayDelegateProxy() { | 83 NativeDisplayDelegateProxy::~NativeDisplayDelegateProxy() { |
57 device_manager_->RemoveObserver(this); | 84 device_manager_->RemoveObserver(this); |
58 proxy_->UnregisterHandler(this); | 85 proxy_->UnregisterHandler(this); |
59 } | 86 } |
60 | 87 |
61 void NativeDisplayDelegateProxy::Initialize() { | 88 void NativeDisplayDelegateProxy::Initialize() { |
62 device_manager_->AddObserver(this); | 89 device_manager_->AddObserver(this); |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 observers_.RemoveObserver(observer); | 215 observers_.RemoveObserver(observer); |
189 } | 216 } |
190 | 217 |
191 void NativeDisplayDelegateProxy::OnDeviceEvent(const DeviceEvent& event) { | 218 void NativeDisplayDelegateProxy::OnDeviceEvent(const DeviceEvent& event) { |
192 if (event.device_type() != DeviceEvent::DISPLAY) | 219 if (event.device_type() != DeviceEvent::DISPLAY) |
193 return; | 220 return; |
194 | 221 |
195 switch (event.action_type()) { | 222 switch (event.action_type()) { |
196 case DeviceEvent::ADD: | 223 case DeviceEvent::ADD: |
197 VLOG(1) << "Got display added event for " << event.path().value(); | 224 VLOG(1) << "Got display added event for " << event.path().value(); |
198 proxy_->Send(new OzoneGpuMsg_AddGraphicsDevice(event.path())); | 225 // The default card is a special case since it needs to be opened early on |
199 break; | 226 // the GPU process in order to initialize EGL. If it is opened here as |
| 227 // well, it will cause a race with opening it in the GPU process and the |
| 228 // GPU process may fail initialization. |
| 229 // TODO(dnicoara) Remove this when EGL_DEFAULT_DISPLAY is the only native |
| 230 // display we return in GbmSurfaceFactory. |
| 231 if (event.path().value() == kDefaultGraphicsCardPath) |
| 232 return; |
| 233 |
| 234 base::WorkerPool::PostTask( |
| 235 FROM_HERE, |
| 236 base::Bind( |
| 237 &OpenDeviceOnWorkerThread, event.path(), |
| 238 base::ThreadTaskRunnerHandle::Get(), |
| 239 base::Bind(&NativeDisplayDelegateProxy::OnNewGraphicsDevice, |
| 240 weak_ptr_factory_.GetWeakPtr())), |
| 241 false /* task_is_slow */); |
| 242 return; |
200 case DeviceEvent::CHANGE: | 243 case DeviceEvent::CHANGE: |
201 VLOG(1) << "Got display changed event for " << event.path().value(); | 244 VLOG(1) << "Got display changed event for " << event.path().value(); |
202 break; | 245 break; |
203 case DeviceEvent::REMOVE: | 246 case DeviceEvent::REMOVE: |
204 VLOG(1) << "Got display removed event for " << event.path().value(); | 247 VLOG(1) << "Got display removed event for " << event.path().value(); |
| 248 // It shouldn't be possible to remove this device. |
| 249 DCHECK_NE(kDefaultGraphicsCardPath, event.path().value()); |
205 proxy_->Send(new OzoneGpuMsg_RemoveGraphicsDevice(event.path())); | 250 proxy_->Send(new OzoneGpuMsg_RemoveGraphicsDevice(event.path())); |
206 break; | 251 break; |
207 } | 252 } |
208 | 253 |
209 FOR_EACH_OBSERVER(NativeDisplayObserver, observers_, | 254 FOR_EACH_OBSERVER(NativeDisplayObserver, observers_, |
210 OnConfigurationChanged()); | 255 OnConfigurationChanged()); |
211 } | 256 } |
212 | 257 |
| 258 void NativeDisplayDelegateProxy::OnNewGraphicsDevice(const base::FilePath& path, |
| 259 base::File file) { |
| 260 DCHECK(file.IsValid()); |
| 261 proxy_->Send(new OzoneGpuMsg_AddGraphicsDevice( |
| 262 path, base::FileDescriptor(file.Pass()))); |
| 263 |
| 264 FOR_EACH_OBSERVER(NativeDisplayObserver, observers_, |
| 265 OnConfigurationChanged()); |
| 266 } |
| 267 |
213 void NativeDisplayDelegateProxy::OnChannelEstablished( | 268 void NativeDisplayDelegateProxy::OnChannelEstablished( |
214 int host_id, | 269 int host_id, |
215 scoped_refptr<base::SingleThreadTaskRunner> send_runner, | 270 scoped_refptr<base::SingleThreadTaskRunner> send_runner, |
216 const base::Callback<void(IPC::Message*)>& send_callback) { | 271 const base::Callback<void(IPC::Message*)>& send_callback) { |
| 272 device_manager_->ScanDevices(this); |
217 FOR_EACH_OBSERVER(NativeDisplayObserver, observers_, | 273 FOR_EACH_OBSERVER(NativeDisplayObserver, observers_, |
218 OnConfigurationChanged()); | 274 OnConfigurationChanged()); |
219 } | 275 } |
220 | 276 |
221 void NativeDisplayDelegateProxy::OnChannelDestroyed(int host_id) { | 277 void NativeDisplayDelegateProxy::OnChannelDestroyed(int host_id) { |
222 // If the channel got destroyed in the middle of a configuration then just | 278 // If the channel got destroyed in the middle of a configuration then just |
223 // respond with failure. | 279 // respond with failure. |
224 if (!get_displays_callback_.is_null()) { | 280 if (!get_displays_callback_.is_null()) { |
225 get_displays_callback_.Run(std::vector<DisplaySnapshot*>()); | 281 get_displays_callback_.Run(std::vector<DisplaySnapshot*>()); |
226 get_displays_callback_.Reset(); | 282 get_displays_callback_.Reset(); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 void NativeDisplayDelegateProxy::OnDisplayConfigured(int64_t display_id, | 319 void NativeDisplayDelegateProxy::OnDisplayConfigured(int64_t display_id, |
264 bool status) { | 320 bool status) { |
265 auto it = configure_callback_map_.find(display_id); | 321 auto it = configure_callback_map_.find(display_id); |
266 if (it != configure_callback_map_.end()) { | 322 if (it != configure_callback_map_.end()) { |
267 it->second.Run(status); | 323 it->second.Run(status); |
268 configure_callback_map_.erase(it); | 324 configure_callback_map_.erase(it); |
269 } | 325 } |
270 } | 326 } |
271 | 327 |
272 } // namespace ui | 328 } // namespace ui |
OLD | NEW |