Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1668)

Unified Diff: ui/ozone/platform/drm/host/drm_display_host_manager.cc

Issue 1124063003: drm: GPU process manages VGEM fd. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: io code is moved to io thread Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..e04f33bc2fd3eb0db944d8cd340a7da50038592a 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,7 @@ 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/";
const char* kDisplayActionString[] = {
"ADD",
@@ -38,12 +40,45 @@ 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() {
+ static std::string vgem_card_path;
+ static base::ThreadChecker checker;
+ DCHECK(checker.CalledOnValidThread());
+ 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
+ return vgem_card_path;
+
+ 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);
+ 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();
+
+ vgem_card_path =
+ base::StringPrintf(kDefaultGraphicsCardPattern, device_index);
+ DVLOG(1) << "VGEM card path is " << vgem_card_path;
+ break;
+ }
+ return vgem_card_path;
+}
+
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 +147,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 +338,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 +371,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()));
}
}

Powered by Google App Engine
This is Rietveld 408576698