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/drm/host/drm_display_host_manager.h" | 5 #include "ui/ozone/platform/drm/host/drm_display_host_manager.h" |
6 | 6 |
7 #include <fcntl.h> | 7 #include <fcntl.h> |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <xf86drm.h> | 9 #include <xf86drm.h> |
| 10 |
10 #include <utility> | 11 #include <utility> |
11 | 12 |
12 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
13 #include "base/files/file_util.h" | 14 #include "base/files/file_util.h" |
| 15 #include "base/memory/ptr_util.h" |
14 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
15 #include "base/thread_task_runner_handle.h" | 17 #include "base/thread_task_runner_handle.h" |
16 #include "base/threading/thread_restrictions.h" | 18 #include "base/threading/thread_restrictions.h" |
17 #include "base/threading/worker_pool.h" | 19 #include "base/threading/worker_pool.h" |
18 #include "ui/display/types/display_snapshot.h" | 20 #include "ui/display/types/display_snapshot.h" |
19 #include "ui/events/ozone/device/device_event.h" | 21 #include "ui/events/ozone/device/device_event.h" |
20 #include "ui/events/ozone/device/device_manager.h" | 22 #include "ui/events/ozone/device/device_manager.h" |
21 #include "ui/ozone/common/display_util.h" | 23 #include "ui/ozone/common/display_util.h" |
22 #include "ui/ozone/platform/drm/common/drm_util.h" | 24 #include "ui/ozone/platform/drm/common/drm_util.h" |
23 #include "ui/ozone/platform/drm/host/drm_device_handle.h" | 25 #include "ui/ozone/platform/drm/host/drm_device_handle.h" |
24 #include "ui/ozone/platform/drm/host/drm_display_host.h" | 26 #include "ui/ozone/platform/drm/host/drm_display_host.h" |
25 #include "ui/ozone/platform/drm/host/drm_native_display_delegate.h" | 27 #include "ui/ozone/platform/drm/host/drm_native_display_delegate.h" |
26 #include "ui/ozone/platform/drm/host/gpu_thread_adapter.h" | 28 #include "ui/ozone/platform/drm/host/gpu_thread_adapter.h" |
27 | 29 |
28 namespace ui { | 30 namespace ui { |
29 | 31 |
30 namespace { | 32 namespace { |
31 | 33 |
32 typedef base::Callback<void(const base::FilePath&, | 34 typedef base::Callback<void(const base::FilePath&, |
33 const base::FilePath&, | 35 const base::FilePath&, |
34 scoped_ptr<DrmDeviceHandle>)> | 36 std::unique_ptr<DrmDeviceHandle>)> |
35 OnOpenDeviceReplyCallback; | 37 OnOpenDeviceReplyCallback; |
36 | 38 |
37 const char kDefaultGraphicsCardPattern[] = "/dev/dri/card%d"; | 39 const char kDefaultGraphicsCardPattern[] = "/dev/dri/card%d"; |
38 | 40 |
39 const char* kDisplayActionString[] = { | 41 const char* kDisplayActionString[] = { |
40 "ADD", "REMOVE", "CHANGE", | 42 "ADD", "REMOVE", "CHANGE", |
41 }; | 43 }; |
42 | 44 |
43 // Find sysfs device path for the given device path. | 45 // Find sysfs device path for the given device path. |
44 base::FilePath MapDevPathToSysPath(const base::FilePath& device_path) { | 46 base::FilePath MapDevPathToSysPath(const base::FilePath& device_path) { |
45 // |device_path| looks something like /dev/dri/card0. We take the basename of | 47 // |device_path| looks something like /dev/dri/card0. We take the basename of |
46 // that (card0) and append it to /sys/class/drm. /sys/class/drm/card0 is a | 48 // that (card0) and append it to /sys/class/drm. /sys/class/drm/card0 is a |
47 // symlink that points to something like | 49 // symlink that points to something like |
48 // /sys/devices/pci0000:00/0000:00:02.0/0000:05:00.0/drm/card0, which exposes | 50 // /sys/devices/pci0000:00/0000:00:02.0/0000:05:00.0/drm/card0, which exposes |
49 // some metadata about the attached device. | 51 // some metadata about the attached device. |
50 return base::MakeAbsoluteFilePath( | 52 return base::MakeAbsoluteFilePath( |
51 base::FilePath("/sys/class/drm").Append(device_path.BaseName())); | 53 base::FilePath("/sys/class/drm").Append(device_path.BaseName())); |
52 } | 54 } |
53 | 55 |
54 void OpenDeviceOnWorkerThread( | 56 void OpenDeviceOnWorkerThread( |
55 const base::FilePath& device_path, | 57 const base::FilePath& device_path, |
56 const scoped_refptr<base::TaskRunner>& reply_runner, | 58 const scoped_refptr<base::TaskRunner>& reply_runner, |
57 const OnOpenDeviceReplyCallback& callback) { | 59 const OnOpenDeviceReplyCallback& callback) { |
58 base::FilePath sys_path = MapDevPathToSysPath(device_path); | 60 base::FilePath sys_path = MapDevPathToSysPath(device_path); |
59 | 61 |
60 scoped_ptr<DrmDeviceHandle> handle(new DrmDeviceHandle()); | 62 std::unique_ptr<DrmDeviceHandle> handle(new DrmDeviceHandle()); |
61 handle->Initialize(device_path, sys_path); | 63 handle->Initialize(device_path, sys_path); |
62 reply_runner->PostTask(FROM_HERE, | 64 reply_runner->PostTask(FROM_HERE, |
63 base::Bind(callback, device_path, sys_path, | 65 base::Bind(callback, device_path, sys_path, |
64 base::Passed(std::move(handle)))); | 66 base::Passed(std::move(handle)))); |
65 } | 67 } |
66 | 68 |
67 base::FilePath GetPrimaryDisplayCardPath() { | 69 base::FilePath GetPrimaryDisplayCardPath() { |
68 struct drm_mode_card_res res; | 70 struct drm_mode_card_res res; |
69 for (int i = 0; /* end on first card# that does not exist */; i++) { | 71 for (int i = 0; /* end on first card# that does not exist */; i++) { |
70 std::string card_path = base::StringPrintf(kDefaultGraphicsCardPattern, i); | 72 std::string card_path = base::StringPrintf(kDefaultGraphicsCardPattern, i); |
(...skipping 19 matching lines...) Expand all Loading... |
90 | 92 |
91 LOG(FATAL) << "Failed to open primary graphics device."; | 93 LOG(FATAL) << "Failed to open primary graphics device."; |
92 return base::FilePath(); // Not reached. | 94 return base::FilePath(); // Not reached. |
93 } | 95 } |
94 | 96 |
95 class FindDrmDisplayHostById { | 97 class FindDrmDisplayHostById { |
96 public: | 98 public: |
97 explicit FindDrmDisplayHostById(int64_t display_id) | 99 explicit FindDrmDisplayHostById(int64_t display_id) |
98 : display_id_(display_id) {} | 100 : display_id_(display_id) {} |
99 | 101 |
100 bool operator()(const scoped_ptr<DrmDisplayHost>& display) const { | 102 bool operator()(const std::unique_ptr<DrmDisplayHost>& display) const { |
101 return display->snapshot()->display_id() == display_id_; | 103 return display->snapshot()->display_id() == display_id_; |
102 } | 104 } |
103 | 105 |
104 private: | 106 private: |
105 int64_t display_id_; | 107 int64_t display_id_; |
106 }; | 108 }; |
107 | 109 |
108 } // namespace | 110 } // namespace |
109 | 111 |
110 DrmDisplayHostManager::DrmDisplayHostManager( | 112 DrmDisplayHostManager::DrmDisplayHostManager( |
(...skipping 25 matching lines...) Expand all Loading... |
136 } | 138 } |
137 | 139 |
138 device_manager_->AddObserver(this); | 140 device_manager_->AddObserver(this); |
139 proxy_->RegisterHandlerForDrmDisplayHostManager(this); | 141 proxy_->RegisterHandlerForDrmDisplayHostManager(this); |
140 proxy_->AddGpuThreadObserver(this); | 142 proxy_->AddGpuThreadObserver(this); |
141 | 143 |
142 ScopedVector<HardwareDisplayControllerInfo> display_infos = | 144 ScopedVector<HardwareDisplayControllerInfo> display_infos = |
143 GetAvailableDisplayControllerInfos(primary_drm_device_handle_->fd()); | 145 GetAvailableDisplayControllerInfos(primary_drm_device_handle_->fd()); |
144 has_dummy_display_ = !display_infos.empty(); | 146 has_dummy_display_ = !display_infos.empty(); |
145 for (size_t i = 0; i < display_infos.size(); ++i) { | 147 for (size_t i = 0; i < display_infos.size(); ++i) { |
146 displays_.push_back(make_scoped_ptr(new DrmDisplayHost( | 148 displays_.push_back(base::WrapUnique(new DrmDisplayHost( |
147 proxy_, CreateDisplaySnapshotParams( | 149 proxy_, CreateDisplaySnapshotParams( |
148 display_infos[i], primary_drm_device_handle_->fd(), | 150 display_infos[i], primary_drm_device_handle_->fd(), |
149 primary_drm_device_handle_->sys_path(), 0, gfx::Point()), | 151 primary_drm_device_handle_->sys_path(), 0, gfx::Point()), |
150 true /* is_dummy */))); | 152 true /* is_dummy */))); |
151 } | 153 } |
152 } | 154 } |
153 | 155 |
154 DrmDisplayHostManager::~DrmDisplayHostManager() { | 156 DrmDisplayHostManager::~DrmDisplayHostManager() { |
155 device_manager_->RemoveObserver(this); | 157 device_manager_->RemoveObserver(this); |
156 proxy_->UnRegisterHandlerForDrmDisplayHostManager(); | 158 proxy_->UnRegisterHandlerForDrmDisplayHostManager(); |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 drm_devices_.erase(it); | 273 drm_devices_.erase(it); |
272 } | 274 } |
273 break; | 275 break; |
274 } | 276 } |
275 } | 277 } |
276 } | 278 } |
277 | 279 |
278 void DrmDisplayHostManager::OnAddGraphicsDevice( | 280 void DrmDisplayHostManager::OnAddGraphicsDevice( |
279 const base::FilePath& dev_path, | 281 const base::FilePath& dev_path, |
280 const base::FilePath& sys_path, | 282 const base::FilePath& sys_path, |
281 scoped_ptr<DrmDeviceHandle> handle) { | 283 std::unique_ptr<DrmDeviceHandle> handle) { |
282 if (handle->IsValid()) { | 284 if (handle->IsValid()) { |
283 drm_devices_[dev_path] = sys_path; | 285 drm_devices_[dev_path] = sys_path; |
284 proxy_->GpuAddGraphicsDevice(sys_path, | 286 proxy_->GpuAddGraphicsDevice(sys_path, |
285 base::FileDescriptor(handle->PassFD())); | 287 base::FileDescriptor(handle->PassFD())); |
286 NotifyDisplayDelegate(); | 288 NotifyDisplayDelegate(); |
287 } | 289 } |
288 | 290 |
289 task_pending_ = false; | 291 task_pending_ = false; |
290 ProcessEvent(); | 292 ProcessEvent(); |
291 } | 293 } |
(...skipping 27 matching lines...) Expand all Loading... |
319 } | 321 } |
320 | 322 |
321 // Signal that we're taking DRM master since we're going through the | 323 // Signal that we're taking DRM master since we're going through the |
322 // initialization process again and we'll take all the available resources. | 324 // initialization process again and we'll take all the available resources. |
323 if (!take_display_control_callback_.is_null()) | 325 if (!take_display_control_callback_.is_null()) |
324 GpuTookDisplayControl(true); | 326 GpuTookDisplayControl(true); |
325 | 327 |
326 if (!relinquish_display_control_callback_.is_null()) | 328 if (!relinquish_display_control_callback_.is_null()) |
327 GpuRelinquishedDisplayControl(false); | 329 GpuRelinquishedDisplayControl(false); |
328 | 330 |
329 scoped_ptr<DrmDeviceHandle> handle = std::move(primary_drm_device_handle_); | 331 std::unique_ptr<DrmDeviceHandle> handle = |
| 332 std::move(primary_drm_device_handle_); |
330 { | 333 { |
331 base::ThreadRestrictions::ScopedAllowIO allow_io; | 334 base::ThreadRestrictions::ScopedAllowIO allow_io; |
332 | 335 |
333 drm_devices_.clear(); | 336 drm_devices_.clear(); |
334 drm_devices_[primary_graphics_card_path_] = | 337 drm_devices_[primary_graphics_card_path_] = |
335 MapDevPathToSysPath(primary_graphics_card_path_); | 338 MapDevPathToSysPath(primary_graphics_card_path_); |
336 | 339 |
337 if (!handle) { | 340 if (!handle) { |
338 handle.reset(new DrmDeviceHandle()); | 341 handle.reset(new DrmDeviceHandle()); |
339 if (!handle->Initialize(primary_graphics_card_path_, | 342 if (!handle->Initialize(primary_graphics_card_path_, |
340 drm_devices_[primary_graphics_card_path_])) | 343 drm_devices_[primary_graphics_card_path_])) |
341 LOG(FATAL) << "Failed to open primary graphics card"; | 344 LOG(FATAL) << "Failed to open primary graphics card"; |
342 } | 345 } |
343 } | 346 } |
344 | 347 |
345 // Send the primary device first since this is used to initialize graphics | 348 // Send the primary device first since this is used to initialize graphics |
346 // state. | 349 // state. |
347 proxy_->GpuAddGraphicsDevice(drm_devices_[primary_graphics_card_path_], | 350 proxy_->GpuAddGraphicsDevice(drm_devices_[primary_graphics_card_path_], |
348 base::FileDescriptor(handle->PassFD())); | 351 base::FileDescriptor(handle->PassFD())); |
349 | 352 |
350 device_manager_->ScanDevices(this); | 353 device_manager_->ScanDevices(this); |
351 NotifyDisplayDelegate(); | 354 NotifyDisplayDelegate(); |
352 } | 355 } |
353 | 356 |
354 void DrmDisplayHostManager::OnGpuThreadRetired() {} | 357 void DrmDisplayHostManager::OnGpuThreadRetired() {} |
355 | 358 |
356 void DrmDisplayHostManager::GpuHasUpdatedNativeDisplays( | 359 void DrmDisplayHostManager::GpuHasUpdatedNativeDisplays( |
357 const std::vector<DisplaySnapshot_Params>& params) { | 360 const std::vector<DisplaySnapshot_Params>& params) { |
358 std::vector<scoped_ptr<DrmDisplayHost>> old_displays; | 361 std::vector<std::unique_ptr<DrmDisplayHost>> old_displays; |
359 displays_.swap(old_displays); | 362 displays_.swap(old_displays); |
360 for (size_t i = 0; i < params.size(); ++i) { | 363 for (size_t i = 0; i < params.size(); ++i) { |
361 auto it = std::find_if(old_displays.begin(), old_displays.end(), | 364 auto it = std::find_if(old_displays.begin(), old_displays.end(), |
362 FindDrmDisplayHostById(params[i].display_id)); | 365 FindDrmDisplayHostById(params[i].display_id)); |
363 if (it == old_displays.end()) { | 366 if (it == old_displays.end()) { |
364 displays_.push_back(make_scoped_ptr( | 367 displays_.push_back(base::WrapUnique( |
365 new DrmDisplayHost(proxy_, params[i], false /* is_dummy */))); | 368 new DrmDisplayHost(proxy_, params[i], false /* is_dummy */))); |
366 } else { | 369 } else { |
367 (*it)->UpdateDisplaySnapshot(params[i]); | 370 (*it)->UpdateDisplaySnapshot(params[i]); |
368 displays_.push_back(std::move(*it)); | 371 displays_.push_back(std::move(*it)); |
369 old_displays.erase(it); | 372 old_displays.erase(it); |
370 } | 373 } |
371 } | 374 } |
372 | 375 |
373 if (!get_displays_callback_.is_null()) { | 376 if (!get_displays_callback_.is_null()) { |
374 base::ThreadTaskRunnerHandle::Get()->PostTask( | 377 base::ThreadTaskRunnerHandle::Get()->PostTask( |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
455 | 458 |
456 callback.Run(snapshots); | 459 callback.Run(snapshots); |
457 } | 460 } |
458 | 461 |
459 void DrmDisplayHostManager::NotifyDisplayDelegate() const { | 462 void DrmDisplayHostManager::NotifyDisplayDelegate() const { |
460 if (delegate_) | 463 if (delegate_) |
461 delegate_->OnConfigurationChanged(); | 464 delegate_->OnConfigurationChanged(); |
462 } | 465 } |
463 | 466 |
464 } // namespace ui | 467 } // namespace ui |
OLD | NEW |