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 b01664abb706586b1332aee3d22d82fa6f87a5f0..1a1dc6ecce1b836fe33531019961e7f7230a236f 100644 |
--- a/ui/ozone/platform/drm/gpu/drm_device_manager.cc |
+++ b/ui/ozone/platform/drm/gpu/drm_device_manager.cc |
@@ -17,7 +17,7 @@ class FindByDevicePath { |
public: |
explicit FindByDevicePath(const base::FilePath& path) : path_(path) {} |
- bool operator()(const scoped_refptr<DrmDevice>& device) { |
+ bool operator()(const scoped_refptr<DrmDeviceBase>& device) { |
return device->device_path() == path_; |
} |
@@ -25,6 +25,31 @@ class FindByDevicePath { |
base::FilePath path_; |
}; |
+class FindVgemDevice { |
+ public: |
+ FindVgemDevice() {} |
+ |
+ bool operator()(const scoped_refptr<DrmDeviceBase>& device) { |
+ return device->GetType() == DrmDeviceBase::VGEM; |
+ } |
+}; |
+ |
+class VgemDevice : public DrmDeviceBase { |
+ public: |
+ VgemDevice(const base::FilePath& device_path, base::File file) |
+ : DrmDeviceBase(device_path, file.Pass()) {} |
+ void InitializeTaskRunner( |
+ const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) override { |
+ } |
+ Type GetType() const override { return VGEM; } |
+ |
+ protected: |
+ ~VgemDevice() override {} |
+ |
+ private: |
+ DISALLOW_COPY_AND_ASSIGN(VgemDevice); |
+}; |
+ |
} // namespace |
DrmDeviceManager::DrmDeviceManager( |
@@ -75,9 +100,24 @@ void DrmDeviceManager::RemoveDrmDevice(const base::FilePath& path) { |
} |
DCHECK_NE(primary_device_, *it); |
+ DCHECK_NE(DrmDeviceBase::VGEM, (*it)->GetType()); |
devices_.erase(it); |
} |
+bool DrmDeviceManager::AddVgemDevice(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; |
+ } |
+ devices_.push_back(new VgemDevice(path, file.Pass())); |
+ return true; |
+} |
+ |
void DrmDeviceManager::InitializeIOTaskRunner( |
const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) { |
DCHECK(thread_checker_.CalledOnValidThread()); |
@@ -115,12 +155,28 @@ scoped_refptr<DrmDevice> DrmDeviceManager::GetDrmDevice( |
if (!it->second) |
return primary_device_; |
+ DCHECK_EQ(it->second->GetType(), DrmDeviceBase::DRM); |
return it->second; |
} |
-const DrmDeviceVector& DrmDeviceManager::GetDrmDevices() const { |
+DrmDeviceVector DrmDeviceManager::GetDrmDevices() const { |
DCHECK(thread_checker_.CalledOnValidThread()); |
- return devices_; |
+ DrmDeviceVector devices; |
+ for (const auto& device : devices_) { |
+ if (device->GetType() == DrmDeviceBase::DRM) |
+ devices.push_back(static_cast<DrmDevice*>(device.get())); |
+ } |
+ return devices; |
+} |
+ |
+scoped_refptr<DrmDeviceBase> DrmDeviceManager::GetVgemDevice() const { |
+ DCHECK(thread_checker_.CalledOnValidThread()); |
+ auto it = std::find_if(devices_.begin(), devices_.end(), FindVgemDevice()); |
+ if (it == devices_.end()) { |
+ VLOG(2) << "Don't support VGEM."; |
+ return nullptr; |
+ } |
+ return *it; |
} |
} // namespace ui |