Chromium Code Reviews| 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> | 8 #include <stdio.h> |
| 9 #include <xf86drm.h> | 9 #include <xf86drm.h> |
| 10 | 10 |
| 11 #include "base/files/file_enumerator.h" | |
| 11 #include "base/logging.h" | 12 #include "base/logging.h" |
| 12 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
| 13 #include "base/thread_task_runner_handle.h" | 14 #include "base/thread_task_runner_handle.h" |
| 14 #include "base/threading/thread_restrictions.h" | 15 #include "base/threading/thread_restrictions.h" |
| 15 #include "base/threading/worker_pool.h" | 16 #include "base/threading/worker_pool.h" |
| 16 #include "ui/events/ozone/device/device_event.h" | 17 #include "ui/events/ozone/device/device_event.h" |
| 17 #include "ui/events/ozone/device/device_manager.h" | 18 #include "ui/events/ozone/device/device_manager.h" |
| 18 #include "ui/ozone/common/display_snapshot_proxy.h" | 19 #include "ui/ozone/common/display_snapshot_proxy.h" |
| 19 #include "ui/ozone/common/display_util.h" | 20 #include "ui/ozone/common/display_util.h" |
| 20 #include "ui/ozone/common/gpu/ozone_gpu_messages.h" | 21 #include "ui/ozone/common/gpu/ozone_gpu_messages.h" |
| 21 #include "ui/ozone/platform/drm/common/drm_util.h" | 22 #include "ui/ozone/platform/drm/common/drm_util.h" |
| 22 #include "ui/ozone/platform/drm/host/drm_device_handle.h" | 23 #include "ui/ozone/platform/drm/host/drm_device_handle.h" |
| 23 #include "ui/ozone/platform/drm/host/drm_gpu_platform_support_host.h" | 24 #include "ui/ozone/platform/drm/host/drm_gpu_platform_support_host.h" |
| 24 #include "ui/ozone/platform/drm/host/drm_native_display_delegate.h" | 25 #include "ui/ozone/platform/drm/host/drm_native_display_delegate.h" |
| 25 | 26 |
| 26 namespace ui { | 27 namespace ui { |
| 27 | 28 |
| 28 namespace { | 29 namespace { |
| 29 | 30 |
| 30 typedef base::Callback<void(const base::FilePath&, scoped_ptr<DrmDeviceHandle>)> | 31 typedef base::Callback<void(const base::FilePath&, scoped_ptr<DrmDeviceHandle>)> |
| 31 OnOpenDeviceReplyCallback; | 32 OnOpenDeviceReplyCallback; |
| 32 | 33 |
| 33 const char kDefaultGraphicsCardPattern[] = "/dev/dri/card%d"; | 34 const char kDefaultGraphicsCardPattern[] = "/dev/dri/card%d"; |
| 35 const char kVgemDevDriCardPath[] = "/dev/dri/"; | |
| 36 const char kVgemSysCardPath[] = "/sys/bus/platform/devices/vgem/drm/"; | |
|
vignatti (out of this project)
2015/05/26 18:28:34
note that this only works on CrOS. In other Linux
| |
| 34 | 37 |
| 35 const char* kDisplayActionString[] = { | 38 const char* kDisplayActionString[] = { |
| 36 "ADD", | 39 "ADD", |
| 37 "REMOVE", | 40 "REMOVE", |
| 38 "CHANGE", | 41 "CHANGE", |
| 39 }; | 42 }; |
| 40 | 43 |
| 41 void OpenDeviceOnWorkerThread( | 44 void OpenDeviceOnWorkerThread( |
| 42 const base::FilePath& path, | 45 const base::FilePath& path, |
| 43 const scoped_refptr<base::TaskRunner>& reply_runner, | 46 const scoped_refptr<base::TaskRunner>& reply_runner, |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 68 if (ret == 0 && res.count_crtcs > 0) { | 71 if (ret == 0 && res.count_crtcs > 0) { |
| 69 return base::FilePath(card_path); | 72 return base::FilePath(card_path); |
| 70 } | 73 } |
| 71 | 74 |
| 72 VPLOG_IF(1, ret) << "Failed to get DRM resources for '" << card_path << "'"; | 75 VPLOG_IF(1, ret) << "Failed to get DRM resources for '" << card_path << "'"; |
| 73 } | 76 } |
| 74 | 77 |
| 75 return base::FilePath(); | 78 return base::FilePath(); |
| 76 } | 79 } |
| 77 | 80 |
| 81 base::FilePath GetVgemCardPath() { | |
| 82 base::FileEnumerator file_iter( | |
| 83 base::FilePath::FromUTF8Unsafe(kVgemSysCardPath), false, | |
| 84 base::FileEnumerator::DIRECTORIES, FILE_PATH_LITERAL("card*")); | |
| 85 | |
| 86 while (!file_iter.Next().empty()) { | |
| 87 // Inspect the card%d directories in the directory and extract the filename. | |
| 88 std::string vgem_card_path = | |
| 89 kVgemDevDriCardPath + | |
| 90 file_iter.GetInfo().GetName().BaseName().MaybeAsASCII(); | |
| 91 DVLOG(1) << "VGEM card path is " << vgem_card_path; | |
| 92 return base::FilePath(vgem_card_path); | |
| 93 } | |
| 94 DVLOG(1) << "Don't support VGEM"; | |
| 95 return base::FilePath(); | |
| 96 } | |
| 97 | |
| 78 class FindDisplaySnapshotById { | 98 class FindDisplaySnapshotById { |
| 79 public: | 99 public: |
| 80 FindDisplaySnapshotById(int64_t display_id) : display_id_(display_id) {} | 100 FindDisplaySnapshotById(int64_t display_id) : display_id_(display_id) {} |
| 81 | 101 |
| 82 bool operator()(const DisplaySnapshot* display) { | 102 bool operator()(const DisplaySnapshot* display) { |
| 83 return display->display_id() == display_id_; | 103 return display->display_id() == display_id_; |
| 84 } | 104 } |
| 85 | 105 |
| 86 private: | 106 private: |
| 87 int64_t display_id_; | 107 int64_t display_id_; |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 102 // First device needs to be treated specially. We need to open this | 122 // First device needs to be treated specially. We need to open this |
| 103 // synchronously since the GPU process will need it to initialize the | 123 // synchronously since the GPU process will need it to initialize the |
| 104 // graphics state. | 124 // graphics state. |
| 105 base::ThreadRestrictions::ScopedAllowIO allow_io; | 125 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 106 primary_drm_device_handle_.reset(new DrmDeviceHandle()); | 126 primary_drm_device_handle_.reset(new DrmDeviceHandle()); |
| 107 if (!primary_drm_device_handle_->Initialize(primary_graphics_card_path_)) { | 127 if (!primary_drm_device_handle_->Initialize(primary_graphics_card_path_)) { |
| 108 LOG(FATAL) << "Failed to open primary graphics card"; | 128 LOG(FATAL) << "Failed to open primary graphics card"; |
| 109 return; | 129 return; |
| 110 } | 130 } |
| 111 drm_devices_.insert(primary_graphics_card_path_); | 131 drm_devices_.insert(primary_graphics_card_path_); |
| 132 | |
| 133 vgem_card_path_ = GetVgemCardPath(); | |
| 134 vgem_card_device_file_ = base::File( | |
| 135 vgem_card_path_, | |
| 136 base::File::FLAG_OPEN | base::File::FLAG_READ | base::File::FLAG_WRITE); | |
| 112 } | 137 } |
| 113 | 138 |
| 114 device_manager_->AddObserver(this); | 139 device_manager_->AddObserver(this); |
| 115 proxy_->RegisterHandler(this); | 140 proxy_->RegisterHandler(this); |
| 116 | 141 |
| 117 ScopedVector<HardwareDisplayControllerInfo> display_infos = | 142 ScopedVector<HardwareDisplayControllerInfo> display_infos = |
| 118 GetAvailableDisplayControllerInfos(primary_drm_device_handle_->fd()); | 143 GetAvailableDisplayControllerInfos(primary_drm_device_handle_->fd()); |
| 119 has_dummy_display_ = !display_infos.empty(); | 144 has_dummy_display_ = !display_infos.empty(); |
| 120 for (size_t i = 0; i < display_infos.size(); ++i) { | 145 for (size_t i = 0; i < display_infos.size(); ++i) { |
| 121 displays_.push_back(new DisplaySnapshotProxy(CreateDisplaySnapshotParams( | 146 displays_.push_back(new DisplaySnapshotProxy(CreateDisplaySnapshotParams( |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 222 } | 247 } |
| 223 | 248 |
| 224 void DrmDisplayHostManager::ProcessEvent() { | 249 void DrmDisplayHostManager::ProcessEvent() { |
| 225 while (!event_queue_.empty() && !task_pending_) { | 250 while (!event_queue_.empty() && !task_pending_) { |
| 226 DisplayEvent event = event_queue_.front(); | 251 DisplayEvent event = event_queue_.front(); |
| 227 event_queue_.pop(); | 252 event_queue_.pop(); |
| 228 VLOG(1) << "Got display event " << kDisplayActionString[event.action_type] | 253 VLOG(1) << "Got display event " << kDisplayActionString[event.action_type] |
| 229 << " for " << event.path.value(); | 254 << " for " << event.path.value(); |
| 230 switch (event.action_type) { | 255 switch (event.action_type) { |
| 231 case DeviceEvent::ADD: | 256 case DeviceEvent::ADD: |
| 257 if (event.path == vgem_card_path_) | |
| 258 continue; | |
| 232 if (drm_devices_.find(event.path) == drm_devices_.end()) { | 259 if (drm_devices_.find(event.path) == drm_devices_.end()) { |
| 233 task_pending_ = base::WorkerPool::PostTask( | 260 task_pending_ = base::WorkerPool::PostTask( |
| 234 FROM_HERE, | 261 FROM_HERE, |
| 235 base::Bind(&OpenDeviceOnWorkerThread, event.path, | 262 base::Bind(&OpenDeviceOnWorkerThread, event.path, |
| 236 base::ThreadTaskRunnerHandle::Get(), | 263 base::ThreadTaskRunnerHandle::Get(), |
| 237 base::Bind(&DrmDisplayHostManager::OnAddGraphicsDevice, | 264 base::Bind(&DrmDisplayHostManager::OnAddGraphicsDevice, |
| 238 weak_ptr_factory_.GetWeakPtr())), | 265 weak_ptr_factory_.GetWeakPtr())), |
| 239 false /* task_is_slow */); | 266 false /* task_is_slow */); |
| 240 } | 267 } |
| 241 break; | 268 break; |
| 242 case DeviceEvent::CHANGE: | 269 case DeviceEvent::CHANGE: |
| 243 task_pending_ = base::ThreadTaskRunnerHandle::Get()->PostTask( | 270 task_pending_ = base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 244 FROM_HERE, | 271 FROM_HERE, |
| 245 base::Bind(&DrmDisplayHostManager::OnUpdateGraphicsDevice, | 272 base::Bind(&DrmDisplayHostManager::OnUpdateGraphicsDevice, |
| 246 weak_ptr_factory_.GetWeakPtr())); | 273 weak_ptr_factory_.GetWeakPtr())); |
| 247 break; | 274 break; |
| 248 case DeviceEvent::REMOVE: | 275 case DeviceEvent::REMOVE: |
| 249 DCHECK(event.path != primary_graphics_card_path_) | 276 DCHECK(event.path != primary_graphics_card_path_) |
| 250 << "Removing primary graphics card"; | 277 << "Removing primary graphics card"; |
| 278 DCHECK(event.path != vgem_card_path_) << "Removing VGEM device"; | |
| 251 auto it = drm_devices_.find(event.path); | 279 auto it = drm_devices_.find(event.path); |
| 252 if (it != drm_devices_.end()) { | 280 if (it != drm_devices_.end()) { |
| 253 task_pending_ = base::ThreadTaskRunnerHandle::Get()->PostTask( | 281 task_pending_ = base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 254 FROM_HERE, | 282 FROM_HERE, |
| 255 base::Bind(&DrmDisplayHostManager::OnRemoveGraphicsDevice, | 283 base::Bind(&DrmDisplayHostManager::OnRemoveGraphicsDevice, |
| 256 weak_ptr_factory_.GetWeakPtr(), event.path)); | 284 weak_ptr_factory_.GetWeakPtr(), event.path)); |
| 257 drm_devices_.erase(it); | 285 drm_devices_.erase(it); |
| 258 } | 286 } |
| 259 break; | 287 break; |
| 260 } | 288 } |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 394 const GetDisplaysCallback& callback) const { | 422 const GetDisplaysCallback& callback) const { |
| 395 callback.Run(displays_.get()); | 423 callback.Run(displays_.get()); |
| 396 } | 424 } |
| 397 | 425 |
| 398 void DrmDisplayHostManager::NotifyDisplayDelegate() const { | 426 void DrmDisplayHostManager::NotifyDisplayDelegate() const { |
| 399 if (delegate_) | 427 if (delegate_) |
| 400 delegate_->OnConfigurationChanged(); | 428 delegate_->OnConfigurationChanged(); |
| 401 } | 429 } |
| 402 | 430 |
| 403 } // namespace ui | 431 } // namespace ui |
| OLD | NEW |