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 93d43e2467de430ae2cec6ce1655f6eb33dd403d..874912b7e6347ffe1b0ec13aa1a5168094972b1a 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 kVgemSysCardPath[] = "/sys/bus/platform/devices/vgem/drm/"; |
+base::LazyInstance<std::string> kVgemCardPath; |
spang
2015/05/12 17:20:38
Please don't add state to the global scope. Instea
dshwang
2015/05/12 17:48:02
I see. I move this to member of this class.
dshwang
2015/05/13 13:09:00
Done.
|
const char* kDisplayActionString[] = { |
"ADD", |
@@ -38,12 +41,42 @@ const char* kDisplayActionString[] = { |
"CHANGE", |
}; |
+// VGEM fd is a /dev/dri device but we cannot know in advance which one, for |
+// that we inspect the /sys/.../vgem/.../cardX, if we find one such card, then |
+// VGEM is present in the system and we can reuse the index. |
+std::string GetVgemCardPath() { |
+ if (!kVgemCardPath.Get().empty()) |
+ return kVgemCardPath.Get(); |
+ |
+ 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 index. |
+ std::string name(file_iter.GetInfo().GetName().BaseName().MaybeAsASCII()); |
+ base::TrimString(name, "card", &name); |
dnicoara
2015/05/12 15:41:22
Rather than extracting the interger, why not just
dshwang
2015/05/12 16:18:57
good point. I'll update.
dshwang
2015/05/13 13:09:00
Done.
|
+ errno = 0; |
+ const int device_index = strtol(name.c_str(), nullptr, 10); |
+ DLOG_IF(ERROR, errno != 0) << "Error extracting integer from " << name; |
+ if (errno != 0) |
+ return std::string(); |
+ |
+ kVgemCardPath.Get() = |
+ base::StringPrintf(kDefaultGraphicsCardPattern, device_index); |
+ DVLOG(1) << "VGEM card path is " << kVgemCardPath.Get(); |
+ break; |
+ } |
+ return kVgemCardPath.Get(); |
+} |
+ |
void OpenDeviceOnWorkerThread( |
const base::FilePath& path, |
const scoped_refptr<base::TaskRunner>& reply_runner, |
const OnOpenDeviceReplyCallback& callback) { |
+ bool is_vgem = path.MaybeAsASCII() == GetVgemCardPath(); |
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()))); |
} |
@@ -112,7 +145,7 @@ DrmDisplayHostManager::DrmDisplayHostManager(DrmGpuPlatformSupportHost* proxy, |
// graphics state. |
base::ThreadRestrictions::ScopedAllowIO allow_io; |
scoped_ptr<DrmDeviceHandle> handle(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"; |
return; |
} |
@@ -303,9 +336,10 @@ void DrmDisplayHostManager::OnAddGraphicsDevice( |
scoped_ptr<DrmDeviceHandle> handle) { |
if (handle->IsValid()) { |
base::ScopedFD file = handle->Duplicate(); |
+ bool is_vgem = handle->IsVgem(); |
drm_devices_.add(path, handle.Pass()); |
proxy_->Send(new OzoneGpuMsg_AddGraphicsDevice( |
- path, base::FileDescriptor(file.Pass()))); |
+ path, base::FileDescriptor(file.Pass()), is_vgem)); |
NotifyDisplayDelegate(); |
} |
@@ -335,12 +369,14 @@ void DrmDisplayHostManager::OnChannelEstablished( |
// Send the primary device first since this is used to initialize graphics |
// state. |
proxy_->Send(new OzoneGpuMsg_AddGraphicsDevice( |
- it->first, base::FileDescriptor(it->second->Duplicate()))); |
+ it->first, base::FileDescriptor(it->second->Duplicate()), |
+ it->second->IsVgem())); |
for (auto pair : drm_devices_) { |
if (pair.second->IsValid() && pair.first != primary_graphics_card_path_) { |
proxy_->Send(new OzoneGpuMsg_AddGraphicsDevice( |
- pair.first, base::FileDescriptor(pair.second->Duplicate()))); |
+ pair.first, base::FileDescriptor(pair.second->Duplicate()), |
+ it->second->IsVgem())); |
} |
} |