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 <stdio.h> | |
9 #include <xf86drm.h> | 8 #include <xf86drm.h> |
10 | 9 |
11 #include "base/logging.h" | 10 #include "base/files/file_enumerator.h" |
12 #include "base/strings/stringprintf.h" | 11 #include "base/posix/eintr_wrapper.h" |
13 #include "base/thread_task_runner_handle.h" | 12 #include "base/thread_task_runner_handle.h" |
14 #include "base/threading/thread_restrictions.h" | 13 #include "base/threading/thread_restrictions.h" |
15 #include "base/threading/worker_pool.h" | 14 #include "base/threading/worker_pool.h" |
16 #include "ui/display/types/display_snapshot.h" | 15 #include "ui/display/types/display_snapshot.h" |
17 #include "ui/events/ozone/device/device_event.h" | 16 #include "ui/events/ozone/device/device_event.h" |
18 #include "ui/events/ozone/device/device_manager.h" | 17 #include "ui/events/ozone/device/device_manager.h" |
19 #include "ui/ozone/common/display_util.h" | 18 #include "ui/ozone/common/display_util.h" |
20 #include "ui/ozone/common/gpu/ozone_gpu_messages.h" | 19 #include "ui/ozone/common/gpu/ozone_gpu_messages.h" |
21 #include "ui/ozone/platform/drm/common/drm_util.h" | 20 #include "ui/ozone/platform/drm/common/drm_util.h" |
22 #include "ui/ozone/platform/drm/host/drm_device_handle.h" | 21 #include "ui/ozone/platform/drm/host/drm_device_handle.h" |
23 #include "ui/ozone/platform/drm/host/drm_display_host.h" | 22 #include "ui/ozone/platform/drm/host/drm_display_host.h" |
24 #include "ui/ozone/platform/drm/host/drm_gpu_platform_support_host.h" | 23 #include "ui/ozone/platform/drm/host/drm_gpu_platform_support_host.h" |
25 #include "ui/ozone/platform/drm/host/drm_native_display_delegate.h" | 24 #include "ui/ozone/platform/drm/host/drm_native_display_delegate.h" |
26 | 25 |
27 namespace ui { | 26 namespace ui { |
28 | 27 |
29 namespace { | 28 namespace { |
30 | 29 |
31 typedef base::Callback<void(const base::FilePath&, scoped_ptr<DrmDeviceHandle>)> | 30 typedef base::Callback<void(const base::FilePath&, scoped_ptr<DrmDeviceHandle>)> |
32 OnOpenDeviceReplyCallback; | 31 OnOpenDeviceReplyCallback; |
33 | 32 |
34 const char kDefaultGraphicsCardPattern[] = "/dev/dri/card%d"; | 33 const char kDefaultGraphicsCardPattern[] = "/dev/dri/card%d"; |
| 34 const char kVgemDevDriCardPath[] = "/dev/dri/"; |
| 35 const char kVgemSysCardPath[] = "/sys/bus/platform/devices/vgem/drm/"; |
35 | 36 |
36 const char* kDisplayActionString[] = { | 37 const char* kDisplayActionString[] = { |
37 "ADD", | 38 "ADD", |
38 "REMOVE", | 39 "REMOVE", |
39 "CHANGE", | 40 "CHANGE", |
40 }; | 41 }; |
41 | 42 |
42 void OpenDeviceOnWorkerThread( | 43 void OpenDeviceOnWorkerThread( |
43 const base::FilePath& path, | 44 const base::FilePath& path, |
44 const scoped_refptr<base::TaskRunner>& reply_runner, | 45 const scoped_refptr<base::TaskRunner>& reply_runner, |
(...skipping 24 matching lines...) Expand all Loading... |
69 if (ret == 0 && res.count_crtcs > 0) { | 70 if (ret == 0 && res.count_crtcs > 0) { |
70 return base::FilePath(card_path); | 71 return base::FilePath(card_path); |
71 } | 72 } |
72 | 73 |
73 VPLOG_IF(1, ret) << "Failed to get DRM resources for '" << card_path << "'"; | 74 VPLOG_IF(1, ret) << "Failed to get DRM resources for '" << card_path << "'"; |
74 } | 75 } |
75 | 76 |
76 return base::FilePath(); | 77 return base::FilePath(); |
77 } | 78 } |
78 | 79 |
| 80 base::FilePath GetVgemCardPath() { |
| 81 base::FileEnumerator file_iter(base::FilePath(kVgemSysCardPath), false, |
| 82 base::FileEnumerator::DIRECTORIES, |
| 83 FILE_PATH_LITERAL("card*")); |
| 84 |
| 85 while (!file_iter.Next().empty()) { |
| 86 // Inspect the card%d directories in the directory and extract the filename. |
| 87 std::string vgem_card_path = |
| 88 kVgemDevDriCardPath + file_iter.GetInfo().GetName().BaseName().value(); |
| 89 DVLOG(1) << "VGEM card path is " << vgem_card_path; |
| 90 return base::FilePath(vgem_card_path); |
| 91 } |
| 92 DVLOG(1) << "Don't support VGEM"; |
| 93 return base::FilePath(); |
| 94 } |
| 95 |
79 class FindDrmDisplayHostById { | 96 class FindDrmDisplayHostById { |
80 public: | 97 public: |
81 explicit FindDrmDisplayHostById(int64_t display_id) | 98 explicit FindDrmDisplayHostById(int64_t display_id) |
82 : display_id_(display_id) {} | 99 : display_id_(display_id) {} |
83 | 100 |
84 bool operator()(const DrmDisplayHost* display) const { | 101 bool operator()(const DrmDisplayHost* display) const { |
85 return display->snapshot()->display_id() == display_id_; | 102 return display->snapshot()->display_id() == display_id_; |
86 } | 103 } |
87 | 104 |
88 private: | 105 private: |
(...skipping 15 matching lines...) Expand all Loading... |
104 // First device needs to be treated specially. We need to open this | 121 // First device needs to be treated specially. We need to open this |
105 // synchronously since the GPU process will need it to initialize the | 122 // synchronously since the GPU process will need it to initialize the |
106 // graphics state. | 123 // graphics state. |
107 base::ThreadRestrictions::ScopedAllowIO allow_io; | 124 base::ThreadRestrictions::ScopedAllowIO allow_io; |
108 primary_drm_device_handle_.reset(new DrmDeviceHandle()); | 125 primary_drm_device_handle_.reset(new DrmDeviceHandle()); |
109 if (!primary_drm_device_handle_->Initialize(primary_graphics_card_path_)) { | 126 if (!primary_drm_device_handle_->Initialize(primary_graphics_card_path_)) { |
110 LOG(FATAL) << "Failed to open primary graphics card"; | 127 LOG(FATAL) << "Failed to open primary graphics card"; |
111 return; | 128 return; |
112 } | 129 } |
113 drm_devices_.insert(primary_graphics_card_path_); | 130 drm_devices_.insert(primary_graphics_card_path_); |
| 131 |
| 132 vgem_card_path_ = GetVgemCardPath(); |
| 133 if (!vgem_card_path_.empty()) { |
| 134 int fd = HANDLE_EINTR( |
| 135 open(vgem_card_path_.value().c_str(), O_RDWR | O_CLOEXEC)); |
| 136 if (fd < 0) { |
| 137 PLOG(ERROR) << "Failed to open vgem: " << vgem_card_path_.value(); |
| 138 } |
| 139 vgem_card_device_file_.reset(fd); |
| 140 } |
114 } | 141 } |
115 | 142 |
116 device_manager_->AddObserver(this); | 143 device_manager_->AddObserver(this); |
117 proxy_->RegisterHandler(this); | 144 proxy_->RegisterHandler(this); |
118 | 145 |
119 ScopedVector<HardwareDisplayControllerInfo> display_infos = | 146 ScopedVector<HardwareDisplayControllerInfo> display_infos = |
120 GetAvailableDisplayControllerInfos(primary_drm_device_handle_->fd()); | 147 GetAvailableDisplayControllerInfos(primary_drm_device_handle_->fd()); |
121 has_dummy_display_ = !display_infos.empty(); | 148 has_dummy_display_ = !display_infos.empty(); |
122 for (size_t i = 0; i < display_infos.size(); ++i) { | 149 for (size_t i = 0; i < display_infos.size(); ++i) { |
123 displays_.push_back(new DrmDisplayHost( | 150 displays_.push_back(new DrmDisplayHost( |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 } | 207 } |
181 | 208 |
182 void DrmDisplayHostManager::ProcessEvent() { | 209 void DrmDisplayHostManager::ProcessEvent() { |
183 while (!event_queue_.empty() && !task_pending_) { | 210 while (!event_queue_.empty() && !task_pending_) { |
184 DisplayEvent event = event_queue_.front(); | 211 DisplayEvent event = event_queue_.front(); |
185 event_queue_.pop(); | 212 event_queue_.pop(); |
186 VLOG(1) << "Got display event " << kDisplayActionString[event.action_type] | 213 VLOG(1) << "Got display event " << kDisplayActionString[event.action_type] |
187 << " for " << event.path.value(); | 214 << " for " << event.path.value(); |
188 switch (event.action_type) { | 215 switch (event.action_type) { |
189 case DeviceEvent::ADD: | 216 case DeviceEvent::ADD: |
| 217 if (event.path == vgem_card_path_) |
| 218 continue; |
190 if (drm_devices_.find(event.path) == drm_devices_.end()) { | 219 if (drm_devices_.find(event.path) == drm_devices_.end()) { |
191 task_pending_ = base::WorkerPool::PostTask( | 220 task_pending_ = base::WorkerPool::PostTask( |
192 FROM_HERE, | 221 FROM_HERE, |
193 base::Bind(&OpenDeviceOnWorkerThread, event.path, | 222 base::Bind(&OpenDeviceOnWorkerThread, event.path, |
194 base::ThreadTaskRunnerHandle::Get(), | 223 base::ThreadTaskRunnerHandle::Get(), |
195 base::Bind(&DrmDisplayHostManager::OnAddGraphicsDevice, | 224 base::Bind(&DrmDisplayHostManager::OnAddGraphicsDevice, |
196 weak_ptr_factory_.GetWeakPtr())), | 225 weak_ptr_factory_.GetWeakPtr())), |
197 false /* task_is_slow */); | 226 false /* task_is_slow */); |
198 } | 227 } |
199 break; | 228 break; |
200 case DeviceEvent::CHANGE: | 229 case DeviceEvent::CHANGE: |
201 task_pending_ = base::ThreadTaskRunnerHandle::Get()->PostTask( | 230 task_pending_ = base::ThreadTaskRunnerHandle::Get()->PostTask( |
202 FROM_HERE, | 231 FROM_HERE, |
203 base::Bind(&DrmDisplayHostManager::OnUpdateGraphicsDevice, | 232 base::Bind(&DrmDisplayHostManager::OnUpdateGraphicsDevice, |
204 weak_ptr_factory_.GetWeakPtr())); | 233 weak_ptr_factory_.GetWeakPtr())); |
205 break; | 234 break; |
206 case DeviceEvent::REMOVE: | 235 case DeviceEvent::REMOVE: |
207 DCHECK(event.path != primary_graphics_card_path_) | 236 DCHECK(event.path != primary_graphics_card_path_) |
208 << "Removing primary graphics card"; | 237 << "Removing primary graphics card"; |
| 238 DCHECK(event.path != vgem_card_path_) << "Removing VGEM device"; |
209 auto it = drm_devices_.find(event.path); | 239 auto it = drm_devices_.find(event.path); |
210 if (it != drm_devices_.end()) { | 240 if (it != drm_devices_.end()) { |
211 task_pending_ = base::ThreadTaskRunnerHandle::Get()->PostTask( | 241 task_pending_ = base::ThreadTaskRunnerHandle::Get()->PostTask( |
212 FROM_HERE, | 242 FROM_HERE, |
213 base::Bind(&DrmDisplayHostManager::OnRemoveGraphicsDevice, | 243 base::Bind(&DrmDisplayHostManager::OnRemoveGraphicsDevice, |
214 weak_ptr_factory_.GetWeakPtr(), event.path)); | 244 weak_ptr_factory_.GetWeakPtr(), event.path)); |
215 drm_devices_.erase(it); | 245 drm_devices_.erase(it); |
216 } | 246 } |
217 break; | 247 break; |
218 } | 248 } |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 | 390 |
361 callback.Run(snapshots); | 391 callback.Run(snapshots); |
362 } | 392 } |
363 | 393 |
364 void DrmDisplayHostManager::NotifyDisplayDelegate() const { | 394 void DrmDisplayHostManager::NotifyDisplayDelegate() const { |
365 if (delegate_) | 395 if (delegate_) |
366 delegate_->OnConfigurationChanged(); | 396 delegate_->OnConfigurationChanged(); |
367 } | 397 } |
368 | 398 |
369 } // namespace ui | 399 } // namespace ui |
OLD | NEW |