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

Unified Diff: ui/ozone/platform/drm/gpu/drm_device_manager.cc

Issue 1100973002: [2/4]Allow hotplugging of primary DRM device (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@fix-hotplug
Patch Set: unittests Created 5 years, 8 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
« no previous file with comments | « ui/ozone/platform/drm/gpu/drm_device_manager.h ('k') | ui/ozone/platform/drm/gpu/drm_gpu_display_manager.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/ozone/platform/drm/gpu/drm_device_manager.cc
diff --git a/ui/ozone/platform/drm/gpu/drm_device_manager.cc b/ui/ozone/platform/drm/gpu/drm_device_manager.cc
index c974276fed4672d6fdcd7be7f9a97e4cda903142..b01664abb706586b1332aee3d22d82fa6f87a5f0 100644
--- a/ui/ozone/platform/drm/gpu/drm_device_manager.cc
+++ b/ui/ozone/platform/drm/gpu/drm_device_manager.cc
@@ -4,19 +4,89 @@
#include "ui/ozone/platform/drm/gpu/drm_device_manager.h"
+#include "base/file_descriptor_posix.h"
+#include "base/single_thread_task_runner.h"
#include "ui/ozone/platform/drm/gpu/drm_device.h"
+#include "ui/ozone/platform/drm/gpu/drm_device_generator.h"
namespace ui {
+namespace {
+
+class FindByDevicePath {
+ public:
+ explicit FindByDevicePath(const base::FilePath& path) : path_(path) {}
+
+ bool operator()(const scoped_refptr<DrmDevice>& device) {
+ return device->device_path() == path_;
+ }
+
+ private:
+ base::FilePath path_;
+};
+
+} // namespace
+
DrmDeviceManager::DrmDeviceManager(
- const scoped_refptr<DrmDevice>& primary_device)
- : primary_device_(primary_device) {
+ scoped_ptr<DrmDeviceGenerator> drm_device_generator)
+ : drm_device_generator_(drm_device_generator.Pass()) {
}
DrmDeviceManager::~DrmDeviceManager() {
+ DCHECK(thread_checker_.CalledOnValidThread());
DCHECK(drm_device_map_.empty());
}
+bool DrmDeviceManager::AddDrmDevice(const base::FilePath& path,
+ const base::FileDescriptor& fd) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ base::File file(fd.fd);
+ auto it =
+ std::find_if(devices_.begin(), devices_.end(), FindByDevicePath(path));
+ if (it != devices_.end()) {
+ VLOG(2) << "Got request to add existing device: " << path.value();
+ return false;
+ }
+
+ scoped_refptr<DrmDevice> device =
+ drm_device_generator_->CreateDevice(path, file.Pass());
+ if (!device) {
+ LOG(ERROR) << "Could not initialize DRM device for " << path.value();
+ return false;
+ }
+
+ if (io_task_runner_)
+ device->InitializeTaskRunner(io_task_runner_);
+
+ if (!primary_device_)
+ primary_device_ = device;
+
+ devices_.push_back(device);
+ return true;
+}
+
+void DrmDeviceManager::RemoveDrmDevice(const base::FilePath& path) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ auto it =
+ std::find_if(devices_.begin(), devices_.end(), FindByDevicePath(path));
+ if (it == devices_.end()) {
+ VLOG(2) << "Got request to remove non-existent device: " << path.value();
+ return;
+ }
+
+ DCHECK_NE(primary_device_, *it);
+ devices_.erase(it);
+}
+
+void DrmDeviceManager::InitializeIOTaskRunner(
+ const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK(!io_task_runner_);
+ io_task_runner_ = task_runner;
+ for (const auto& device : devices_)
+ device->InitializeTaskRunner(io_task_runner_);
+}
+
void DrmDeviceManager::UpdateDrmDevice(gfx::AcceleratedWidget widget,
const scoped_refptr<DrmDevice>& device) {
base::AutoLock lock(lock_);
@@ -48,4 +118,9 @@ scoped_refptr<DrmDevice> DrmDeviceManager::GetDrmDevice(
return it->second;
}
+const DrmDeviceVector& DrmDeviceManager::GetDrmDevices() const {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ return devices_;
+}
+
} // namespace ui
« no previous file with comments | « ui/ozone/platform/drm/gpu/drm_device_manager.h ('k') | ui/ozone/platform/drm/gpu/drm_gpu_display_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698