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/display/types/display_snapshot.h" | 17 #include "ui/display/types/display_snapshot.h" |
| 17 #include "ui/events/ozone/device/device_event.h" | 18 #include "ui/events/ozone/device/device_event.h" |
| 18 #include "ui/events/ozone/device/device_manager.h" | 19 #include "ui/events/ozone/device/device_manager.h" |
| 19 #include "ui/ozone/common/display_snapshot_proxy.h" | 20 #include "ui/ozone/common/display_snapshot_proxy.h" |
| 20 #include "ui/ozone/common/display_util.h" | 21 #include "ui/ozone/common/display_util.h" |
| 21 #include "ui/ozone/common/gpu/ozone_gpu_messages.h" | 22 #include "ui/ozone/common/gpu/ozone_gpu_messages.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 kVgemSysCardPath[] = "/sys/bus/platform/devices/vgem/drm/"; | |
| 34 | 36 |
| 35 const char* kDisplayActionString[] = { | 37 const char* kDisplayActionString[] = { |
| 36 "ADD", | 38 "ADD", |
| 37 "REMOVE", | 39 "REMOVE", |
| 38 "CHANGE", | 40 "CHANGE", |
| 39 }; | 41 }; |
| 40 | 42 |
| 43 // VGEM fd is a /dev/dri device but we cannot know in advance which one, for | |
| 44 // that we inspect the /sys/.../vgem/.../cardX, if we find one such card, then | |
| 45 // VGEM is present in the system and we can reuse the index. | |
| 46 std::string GetVgemCardPath() { | |
| 47 static std::string vgem_card_path; | |
| 48 static base::ThreadChecker checker; | |
| 49 DCHECK(checker.CalledOnValidThread()); | |
| 50 if (!vgem_card_path.empty()) | |
|
reveman
2015/05/12 13:47:01
Is this VgemCardPath really supposed to be a singl
dshwang
2015/05/12 14:11:42
I believe it's singleton. +zachr
However, this co
| |
| 51 return vgem_card_path; | |
| 52 | |
| 53 base::FileEnumerator file_iter( | |
| 54 base::FilePath::FromUTF8Unsafe(kVgemSysCardPath), false, | |
| 55 base::FileEnumerator::DIRECTORIES, FILE_PATH_LITERAL("card*")); | |
| 56 | |
| 57 while (!file_iter.Next().empty()) { | |
| 58 // Inspect the card%d directories in the directory and extract the index. | |
| 59 std::string name(file_iter.GetInfo().GetName().BaseName().MaybeAsASCII()); | |
| 60 base::TrimString(name, "card", &name); | |
| 61 errno = 0; | |
| 62 const int device_index = strtol(name.c_str(), nullptr, 10); | |
| 63 DLOG_IF(ERROR, errno != 0) << "Error extracting integer from " << name; | |
| 64 if (errno != 0) | |
| 65 return std::string(); | |
| 66 | |
| 67 vgem_card_path = | |
| 68 base::StringPrintf(kDefaultGraphicsCardPattern, device_index); | |
| 69 DVLOG(1) << "VGEM card path is " << vgem_card_path; | |
| 70 break; | |
| 71 } | |
| 72 return vgem_card_path; | |
| 73 } | |
| 74 | |
| 41 void OpenDeviceOnWorkerThread( | 75 void OpenDeviceOnWorkerThread( |
| 42 const base::FilePath& path, | 76 const base::FilePath& path, |
| 43 const scoped_refptr<base::TaskRunner>& reply_runner, | 77 const scoped_refptr<base::TaskRunner>& reply_runner, |
| 44 const OnOpenDeviceReplyCallback& callback) { | 78 const OnOpenDeviceReplyCallback& callback) { |
| 79 bool is_vgem = path.MaybeAsASCII() == GetVgemCardPath(); | |
| 45 scoped_ptr<DrmDeviceHandle> handle(new DrmDeviceHandle()); | 80 scoped_ptr<DrmDeviceHandle> handle(new DrmDeviceHandle()); |
| 46 handle->Initialize(path); | 81 handle->Initialize(path, is_vgem); |
| 47 reply_runner->PostTask( | 82 reply_runner->PostTask( |
| 48 FROM_HERE, base::Bind(callback, path, base::Passed(handle.Pass()))); | 83 FROM_HERE, base::Bind(callback, path, base::Passed(handle.Pass()))); |
| 49 } | 84 } |
| 50 | 85 |
| 51 void CloseDeviceOnWorkerThread( | 86 void CloseDeviceOnWorkerThread( |
| 52 scoped_ptr<DrmDeviceHandle> handle, | 87 scoped_ptr<DrmDeviceHandle> handle, |
| 53 const scoped_refptr<base::TaskRunner>& reply_runner, | 88 const scoped_refptr<base::TaskRunner>& reply_runner, |
| 54 const base::Closure& callback) { | 89 const base::Closure& callback) { |
| 55 handle.reset(); | 90 handle.reset(); |
| 56 reply_runner->PostTask(FROM_HERE, callback); | 91 reply_runner->PostTask(FROM_HERE, callback); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 105 primary_graphics_card_path_(GetPrimaryDisplayCardPath()), | 140 primary_graphics_card_path_(GetPrimaryDisplayCardPath()), |
| 106 has_dummy_display_(false), | 141 has_dummy_display_(false), |
| 107 task_pending_(false), | 142 task_pending_(false), |
| 108 weak_ptr_factory_(this) { | 143 weak_ptr_factory_(this) { |
| 109 { | 144 { |
| 110 // First device needs to be treated specially. We need to open this | 145 // First device needs to be treated specially. We need to open this |
| 111 // synchronously since the GPU process will need it to initialize the | 146 // synchronously since the GPU process will need it to initialize the |
| 112 // graphics state. | 147 // graphics state. |
| 113 base::ThreadRestrictions::ScopedAllowIO allow_io; | 148 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 114 scoped_ptr<DrmDeviceHandle> handle(new DrmDeviceHandle()); | 149 scoped_ptr<DrmDeviceHandle> handle(new DrmDeviceHandle()); |
| 115 if (!handle->Initialize(primary_graphics_card_path_)) { | 150 if (!handle->Initialize(primary_graphics_card_path_, false)) { |
| 116 LOG(FATAL) << "Failed to open primary graphics card"; | 151 LOG(FATAL) << "Failed to open primary graphics card"; |
| 117 return; | 152 return; |
| 118 } | 153 } |
| 119 drm_devices_.add(primary_graphics_card_path_, handle.Pass()); | 154 drm_devices_.add(primary_graphics_card_path_, handle.Pass()); |
| 120 } | 155 } |
| 121 | 156 |
| 122 device_manager_->AddObserver(this); | 157 device_manager_->AddObserver(this); |
| 123 proxy_->RegisterHandler(this); | 158 proxy_->RegisterHandler(this); |
| 124 | 159 |
| 125 DisplaySnapshot_Params params; | 160 DisplaySnapshot_Params params; |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 296 break; | 331 break; |
| 297 } | 332 } |
| 298 } | 333 } |
| 299 } | 334 } |
| 300 | 335 |
| 301 void DrmDisplayHostManager::OnAddGraphicsDevice( | 336 void DrmDisplayHostManager::OnAddGraphicsDevice( |
| 302 const base::FilePath& path, | 337 const base::FilePath& path, |
| 303 scoped_ptr<DrmDeviceHandle> handle) { | 338 scoped_ptr<DrmDeviceHandle> handle) { |
| 304 if (handle->IsValid()) { | 339 if (handle->IsValid()) { |
| 305 base::ScopedFD file = handle->Duplicate(); | 340 base::ScopedFD file = handle->Duplicate(); |
| 341 bool is_vgem = handle->IsVgem(); | |
| 306 drm_devices_.add(path, handle.Pass()); | 342 drm_devices_.add(path, handle.Pass()); |
| 307 proxy_->Send(new OzoneGpuMsg_AddGraphicsDevice( | 343 proxy_->Send(new OzoneGpuMsg_AddGraphicsDevice( |
| 308 path, base::FileDescriptor(file.Pass()))); | 344 path, base::FileDescriptor(file.Pass()), is_vgem)); |
| 309 NotifyDisplayDelegate(); | 345 NotifyDisplayDelegate(); |
| 310 } | 346 } |
| 311 | 347 |
| 312 task_pending_ = false; | 348 task_pending_ = false; |
| 313 ProcessEvent(); | 349 ProcessEvent(); |
| 314 } | 350 } |
| 315 | 351 |
| 316 void DrmDisplayHostManager::OnUpdateGraphicsDevice() { | 352 void DrmDisplayHostManager::OnUpdateGraphicsDevice() { |
| 317 NotifyDisplayDelegate(); | 353 NotifyDisplayDelegate(); |
| 318 task_pending_ = false; | 354 task_pending_ = false; |
| 319 ProcessEvent(); | 355 ProcessEvent(); |
| 320 } | 356 } |
| 321 | 357 |
| 322 void DrmDisplayHostManager::OnRemoveGraphicsDevice(const base::FilePath& path) { | 358 void DrmDisplayHostManager::OnRemoveGraphicsDevice(const base::FilePath& path) { |
| 323 proxy_->Send(new OzoneGpuMsg_RemoveGraphicsDevice(path)); | 359 proxy_->Send(new OzoneGpuMsg_RemoveGraphicsDevice(path)); |
| 324 NotifyDisplayDelegate(); | 360 NotifyDisplayDelegate(); |
| 325 task_pending_ = false; | 361 task_pending_ = false; |
| 326 ProcessEvent(); | 362 ProcessEvent(); |
| 327 } | 363 } |
| 328 | 364 |
| 329 void DrmDisplayHostManager::OnChannelEstablished( | 365 void DrmDisplayHostManager::OnChannelEstablished( |
| 330 int host_id, | 366 int host_id, |
| 331 scoped_refptr<base::SingleThreadTaskRunner> send_runner, | 367 scoped_refptr<base::SingleThreadTaskRunner> send_runner, |
| 332 const base::Callback<void(IPC::Message*)>& send_callback) { | 368 const base::Callback<void(IPC::Message*)>& send_callback) { |
| 333 auto it = drm_devices_.find(primary_graphics_card_path_); | 369 auto it = drm_devices_.find(primary_graphics_card_path_); |
| 334 DCHECK(it != drm_devices_.end()); | 370 DCHECK(it != drm_devices_.end()); |
| 335 // Send the primary device first since this is used to initialize graphics | 371 // Send the primary device first since this is used to initialize graphics |
| 336 // state. | 372 // state. |
| 337 proxy_->Send(new OzoneGpuMsg_AddGraphicsDevice( | 373 proxy_->Send(new OzoneGpuMsg_AddGraphicsDevice( |
| 338 it->first, base::FileDescriptor(it->second->Duplicate()))); | 374 it->first, base::FileDescriptor(it->second->Duplicate()), |
| 375 it->second->IsVgem())); | |
| 339 | 376 |
| 340 for (auto pair : drm_devices_) { | 377 for (auto pair : drm_devices_) { |
| 341 if (pair.second->IsValid() && pair.first != primary_graphics_card_path_) { | 378 if (pair.second->IsValid() && pair.first != primary_graphics_card_path_) { |
| 342 proxy_->Send(new OzoneGpuMsg_AddGraphicsDevice( | 379 proxy_->Send(new OzoneGpuMsg_AddGraphicsDevice( |
| 343 pair.first, base::FileDescriptor(pair.second->Duplicate()))); | 380 pair.first, base::FileDescriptor(pair.second->Duplicate()), |
| 381 it->second->IsVgem())); | |
| 344 } | 382 } |
| 345 } | 383 } |
| 346 | 384 |
| 347 device_manager_->ScanDevices(this); | 385 device_manager_->ScanDevices(this); |
| 348 NotifyDisplayDelegate(); | 386 NotifyDisplayDelegate(); |
| 349 } | 387 } |
| 350 | 388 |
| 351 void DrmDisplayHostManager::OnChannelDestroyed(int host_id) { | 389 void DrmDisplayHostManager::OnChannelDestroyed(int host_id) { |
| 352 // If the channel got destroyed in the middle of a configuration then just | 390 // If the channel got destroyed in the middle of a configuration then just |
| 353 // respond with failure. | 391 // respond with failure. |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 431 const GetDisplaysCallback& callback) const { | 469 const GetDisplaysCallback& callback) const { |
| 432 callback.Run(displays_.get()); | 470 callback.Run(displays_.get()); |
| 433 } | 471 } |
| 434 | 472 |
| 435 void DrmDisplayHostManager::NotifyDisplayDelegate() const { | 473 void DrmDisplayHostManager::NotifyDisplayDelegate() const { |
| 436 if (delegate_) | 474 if (delegate_) |
| 437 delegate_->OnConfigurationChanged(); | 475 delegate_->OnConfigurationChanged(); |
| 438 } | 476 } |
| 439 | 477 |
| 440 } // namespace ui | 478 } // namespace ui |
| OLD | NEW |