Index: ui/ozone/platform/drm/host/drm_display_host_manager.cc |
diff --git a/ui/ozone/platform/drm/host/drm_display_host_manager.cc b/ui/ozone/platform/drm/host/drm_display_host_manager.cc |
index d22752717435b5d761cab96499d904cfab44477c..a062cef1bf4ee4ed70e6d0bf7e9abfbc13f3470e 100644 |
--- a/ui/ozone/platform/drm/host/drm_display_host_manager.cc |
+++ b/ui/ozone/platform/drm/host/drm_display_host_manager.cc |
@@ -8,6 +8,7 @@ |
#include <stdio.h> |
#include <xf86drm.h> |
+#include "base/files/file_enumerator.h" |
#include "base/logging.h" |
#include "base/strings/stringprintf.h" |
#include "base/thread_task_runner_handle.h" |
@@ -31,6 +32,8 @@ typedef base::Callback<void(const base::FilePath&, scoped_ptr<DrmDeviceHandle>)> |
OnOpenDeviceReplyCallback; |
const char kDefaultGraphicsCardPattern[] = "/dev/dri/card%d"; |
+const char kVgemDevDriCardPath[] = "/dev/dri/"; |
+const char kVgemSysCardPath[] = "/sys/bus/platform/devices/vgem/drm/"; |
const char* kDisplayActionString[] = { |
"ADD", |
@@ -40,10 +43,11 @@ const char* kDisplayActionString[] = { |
void OpenDeviceOnWorkerThread( |
const base::FilePath& path, |
+ bool is_vgem, |
const scoped_refptr<base::TaskRunner>& reply_runner, |
const OnOpenDeviceReplyCallback& callback) { |
scoped_ptr<DrmDeviceHandle> handle(new DrmDeviceHandle()); |
- handle->Initialize(path); |
+ handle->Initialize(path, is_vgem); |
reply_runner->PostTask( |
FROM_HERE, base::Bind(callback, path, base::Passed(handle.Pass()))); |
} |
@@ -75,6 +79,23 @@ base::FilePath GetPrimaryDisplayCardPath() { |
return base::FilePath(); |
} |
+base::FilePath GetVgemCardPath() { |
+ base::FileEnumerator file_iter( |
+ base::FilePath::FromUTF8Unsafe(kVgemSysCardPath), false, |
+ base::FileEnumerator::DIRECTORIES, FILE_PATH_LITERAL("card*")); |
+ |
+ while (!file_iter.Next().empty()) { |
+ // Inspect the card%d directories in the directory and extract the filename. |
+ std::string vgem_card_path = |
+ kVgemDevDriCardPath + |
+ file_iter.GetInfo().GetName().BaseName().MaybeAsASCII(); |
+ DVLOG(1) << "VGEM card path is " << vgem_card_path; |
+ return base::FilePath(vgem_card_path); |
+ } |
+ DVLOG(1) << "Don't support VGEM"; |
+ return base::FilePath(); |
+} |
+ |
class FindDisplaySnapshotById { |
public: |
FindDisplaySnapshotById(int64_t display_id) : display_id_(display_id) {} |
@@ -104,11 +125,14 @@ DrmDisplayHostManager::DrmDisplayHostManager(DrmGpuPlatformSupportHost* proxy, |
// graphics state. |
base::ThreadRestrictions::ScopedAllowIO allow_io; |
primary_drm_device_handle_.reset(new DrmDeviceHandle()); |
- if (!primary_drm_device_handle_->Initialize(primary_graphics_card_path_)) { |
+ if (!primary_drm_device_handle_->Initialize(primary_graphics_card_path_, |
+ false)) { |
LOG(FATAL) << "Failed to open primary graphics card"; |
return; |
} |
drm_devices_.insert(primary_graphics_card_path_); |
+ |
+ vgem_card_path_ = GetVgemCardPath(); |
} |
device_manager_->AddObserver(this); |
@@ -233,6 +257,7 @@ void DrmDisplayHostManager::ProcessEvent() { |
task_pending_ = base::WorkerPool::PostTask( |
FROM_HERE, |
base::Bind(&OpenDeviceOnWorkerThread, event.path, |
+ event.path == vgem_card_path_, |
base::ThreadTaskRunnerHandle::Get(), |
base::Bind(&DrmDisplayHostManager::OnAddGraphicsDevice, |
weak_ptr_factory_.GetWeakPtr())), |
@@ -248,6 +273,7 @@ void DrmDisplayHostManager::ProcessEvent() { |
case DeviceEvent::REMOVE: |
DCHECK(event.path != primary_graphics_card_path_) |
<< "Removing primary graphics card"; |
+ DCHECK(event.path != vgem_card_path_) << "Removing VGEM device"; |
auto it = drm_devices_.find(event.path); |
if (it != drm_devices_.end()) { |
task_pending_ = base::ThreadTaskRunnerHandle::Get()->PostTask( |
@@ -266,8 +292,13 @@ void DrmDisplayHostManager::OnAddGraphicsDevice( |
scoped_ptr<DrmDeviceHandle> handle) { |
if (handle->IsValid()) { |
drm_devices_.insert(path); |
- proxy_->Send(new OzoneGpuMsg_AddGraphicsDevice( |
- path, base::FileDescriptor(handle->PassFD()))); |
+ if (handle->IsVgem()) { |
+ proxy_->Send(new OzoneGpuMsg_AddVgemDevice( |
+ path, base::FileDescriptor(handle->PassFD()))); |
+ } else { |
+ proxy_->Send(new OzoneGpuMsg_AddGraphicsDevice( |
+ path, base::FileDescriptor(handle->PassFD()))); |
+ } |
NotifyDisplayDelegate(); |
} |
@@ -298,7 +329,7 @@ void DrmDisplayHostManager::OnChannelEstablished( |
if (!handle) { |
base::ThreadRestrictions::ScopedAllowIO allow_io; |
handle.reset(new DrmDeviceHandle()); |
- if (!handle->Initialize(primary_graphics_card_path_)) |
+ if (!handle->Initialize(primary_graphics_card_path_, false)) |
LOG(FATAL) << "Failed to open primary graphics card"; |
} |