Chromium Code Reviews| 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..70a9f34140325fbeb0e217b45f380ba408b94179 100644 |
| --- a/ui/ozone/platform/drm/gpu/drm_device_manager.cc |
| +++ b/ui/ozone/platform/drm/gpu/drm_device_manager.cc |
| @@ -4,19 +4,87 @@ |
| #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(drm_device_map_.empty()); |
| } |
| +bool DrmDeviceManager::AddDrmDevice(const base::FilePath& path, |
| + const base::FileDescriptor& fd) { |
| + base::AutoLock lock(lock_); |
| + 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) { |
| + VLOG(2) << "Could not initialize DRM device for " << path.value(); |
|
spang
2015/04/22 18:50:58
LOG(ERROR)
dnicoara
2015/04/22 19:10:00
Done.
|
| + return false; |
| + } |
| + |
| + if (io_task_runner_) |
| + device->InitializeTaskRunner(io_task_runner_); |
| + |
| + if (!primary_device_) |
|
alexst (slow to review)
2015/04/22 18:27:56
Document this please, so we know that primary is t
dnicoara
2015/04/22 18:41:30
Done; added to the header file.
|
| + primary_device_ = device; |
| + |
| + devices_.push_back(device); |
| + return true; |
| +} |
| + |
| +void DrmDeviceManager::RemoveDrmDevice(const base::FilePath& path) { |
| + base::AutoLock lock(lock_); |
| + 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(!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_); |
| @@ -26,6 +94,9 @@ void DrmDeviceManager::UpdateDrmDevice(gfx::AcceleratedWidget widget, |
| void DrmDeviceManager::RemoveDrmDevice(gfx::AcceleratedWidget widget) { |
| base::AutoLock lock(lock_); |
| auto it = drm_device_map_.find(widget); |
| + // It shouldn't be possible to remove the primary device. |
| + DCHECK_NE(it->second, primary_device_); |
| + |
| if (it != drm_device_map_.end()) |
| drm_device_map_.erase(it); |
| } |
| @@ -48,4 +119,9 @@ scoped_refptr<DrmDevice> DrmDeviceManager::GetDrmDevice( |
| return it->second; |
| } |
| +std::vector<scoped_refptr<DrmDevice>> DrmDeviceManager::GetDrmDevices() { |
| + base::AutoLock lock(lock_); |
| + return devices_; |
| +} |
| + |
| } // namespace ui |