OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/ozone/platform/drm/gpu/drm_device_manager.h" | 5 #include "ui/ozone/platform/drm/gpu/drm_device_manager.h" |
6 | 6 |
7 #include "base/file_descriptor_posix.h" | 7 #include "base/file_descriptor_posix.h" |
8 #include "base/single_thread_task_runner.h" | 8 #include "base/single_thread_task_runner.h" |
9 #include "ui/ozone/platform/drm/gpu/drm_device.h" | 9 #include "ui/ozone/platform/drm/gpu/drm_device.h" |
10 #include "ui/ozone/platform/drm/gpu/drm_device_generator.h" | 10 #include "ui/ozone/platform/drm/gpu/drm_device_generator.h" |
11 | 11 |
12 namespace ui { | 12 namespace ui { |
13 | 13 |
14 namespace { | 14 namespace { |
15 | 15 |
16 class FindByDevicePath { | 16 class FindByDevicePath { |
17 public: | 17 public: |
18 explicit FindByDevicePath(const base::FilePath& path) : path_(path) {} | 18 explicit FindByDevicePath(const base::FilePath& path) : path_(path) {} |
19 | 19 |
20 bool operator()(const scoped_refptr<DrmDevice>& device) { | 20 bool operator()(const scoped_refptr<DrmDeviceBase>& device) { |
21 return device->device_path() == path_; | 21 return device->device_path() == path_; |
22 } | 22 } |
23 | 23 |
24 private: | 24 private: |
25 base::FilePath path_; | 25 base::FilePath path_; |
26 }; | 26 }; |
27 | 27 |
| 28 class FindVgemDevice { |
| 29 public: |
| 30 FindVgemDevice() {} |
| 31 |
| 32 bool operator()(const scoped_refptr<DrmDeviceBase>& device) { |
| 33 return device->GetType() == DrmDeviceBase::VGEM; |
| 34 } |
| 35 }; |
| 36 |
| 37 class VgemDevice : public DrmDeviceBase { |
| 38 public: |
| 39 VgemDevice(const base::FilePath& device_path, base::File file) |
| 40 : DrmDeviceBase(device_path, file.Pass()) {} |
| 41 void InitializeTaskRunner( |
| 42 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) override { |
| 43 } |
| 44 Type GetType() const override { return VGEM; } |
| 45 |
| 46 protected: |
| 47 ~VgemDevice() override {} |
| 48 |
| 49 private: |
| 50 DISALLOW_COPY_AND_ASSIGN(VgemDevice); |
| 51 }; |
| 52 |
28 } // namespace | 53 } // namespace |
29 | 54 |
30 DrmDeviceManager::DrmDeviceManager( | 55 DrmDeviceManager::DrmDeviceManager( |
31 scoped_ptr<DrmDeviceGenerator> drm_device_generator) | 56 scoped_ptr<DrmDeviceGenerator> drm_device_generator) |
32 : drm_device_generator_(drm_device_generator.Pass()) { | 57 : drm_device_generator_(drm_device_generator.Pass()) { |
33 } | 58 } |
34 | 59 |
35 DrmDeviceManager::~DrmDeviceManager() { | 60 DrmDeviceManager::~DrmDeviceManager() { |
36 DCHECK(thread_checker_.CalledOnValidThread()); | 61 DCHECK(thread_checker_.CalledOnValidThread()); |
37 DCHECK(drm_device_map_.empty()); | 62 DCHECK(drm_device_map_.empty()); |
(...skipping 30 matching lines...) Expand all Loading... |
68 void DrmDeviceManager::RemoveDrmDevice(const base::FilePath& path) { | 93 void DrmDeviceManager::RemoveDrmDevice(const base::FilePath& path) { |
69 DCHECK(thread_checker_.CalledOnValidThread()); | 94 DCHECK(thread_checker_.CalledOnValidThread()); |
70 auto it = | 95 auto it = |
71 std::find_if(devices_.begin(), devices_.end(), FindByDevicePath(path)); | 96 std::find_if(devices_.begin(), devices_.end(), FindByDevicePath(path)); |
72 if (it == devices_.end()) { | 97 if (it == devices_.end()) { |
73 VLOG(2) << "Got request to remove non-existent device: " << path.value(); | 98 VLOG(2) << "Got request to remove non-existent device: " << path.value(); |
74 return; | 99 return; |
75 } | 100 } |
76 | 101 |
77 DCHECK_NE(primary_device_, *it); | 102 DCHECK_NE(primary_device_, *it); |
| 103 DCHECK_NE(DrmDeviceBase::VGEM, (*it)->GetType()); |
78 devices_.erase(it); | 104 devices_.erase(it); |
79 } | 105 } |
80 | 106 |
| 107 bool DrmDeviceManager::AddVgemDevice(const base::FilePath& path, |
| 108 const base::FileDescriptor& fd) { |
| 109 DCHECK(thread_checker_.CalledOnValidThread()); |
| 110 base::File file(fd.fd); |
| 111 auto it = |
| 112 std::find_if(devices_.begin(), devices_.end(), FindByDevicePath(path)); |
| 113 if (it != devices_.end()) { |
| 114 VLOG(2) << "Got request to add existing device: " << path.value(); |
| 115 return false; |
| 116 } |
| 117 devices_.push_back(new VgemDevice(path, file.Pass())); |
| 118 return true; |
| 119 } |
| 120 |
81 void DrmDeviceManager::InitializeIOTaskRunner( | 121 void DrmDeviceManager::InitializeIOTaskRunner( |
82 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) { | 122 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) { |
83 DCHECK(thread_checker_.CalledOnValidThread()); | 123 DCHECK(thread_checker_.CalledOnValidThread()); |
84 DCHECK(!io_task_runner_); | 124 DCHECK(!io_task_runner_); |
85 io_task_runner_ = task_runner; | 125 io_task_runner_ = task_runner; |
86 for (const auto& device : devices_) | 126 for (const auto& device : devices_) |
87 device->InitializeTaskRunner(io_task_runner_); | 127 device->InitializeTaskRunner(io_task_runner_); |
88 } | 128 } |
89 | 129 |
90 void DrmDeviceManager::UpdateDrmDevice(gfx::AcceleratedWidget widget, | 130 void DrmDeviceManager::UpdateDrmDevice(gfx::AcceleratedWidget widget, |
(...skipping 17 matching lines...) Expand all Loading... |
108 | 148 |
109 auto it = drm_device_map_.find(widget); | 149 auto it = drm_device_map_.find(widget); |
110 DCHECK(it != drm_device_map_.end()) | 150 DCHECK(it != drm_device_map_.end()) |
111 << "Attempting to get device for unknown widget " << widget; | 151 << "Attempting to get device for unknown widget " << widget; |
112 // If the widget isn't associated with a display (headless mode) we can | 152 // If the widget isn't associated with a display (headless mode) we can |
113 // allocate buffers from any controller since they will never be scanned out. | 153 // allocate buffers from any controller since they will never be scanned out. |
114 // Use the primary DRM device as a fallback when allocating these buffers. | 154 // Use the primary DRM device as a fallback when allocating these buffers. |
115 if (!it->second) | 155 if (!it->second) |
116 return primary_device_; | 156 return primary_device_; |
117 | 157 |
| 158 DCHECK_EQ(it->second->GetType(), DrmDeviceBase::DRM); |
118 return it->second; | 159 return it->second; |
119 } | 160 } |
120 | 161 |
121 const DrmDeviceVector& DrmDeviceManager::GetDrmDevices() const { | 162 DrmDeviceVector DrmDeviceManager::GetDrmDevices() const { |
122 DCHECK(thread_checker_.CalledOnValidThread()); | 163 DCHECK(thread_checker_.CalledOnValidThread()); |
123 return devices_; | 164 DrmDeviceVector devices; |
| 165 for (const auto& device : devices_) { |
| 166 if (device->GetType() == DrmDeviceBase::DRM) |
| 167 devices.push_back(static_cast<DrmDevice*>(device.get())); |
| 168 } |
| 169 return devices; |
| 170 } |
| 171 |
| 172 scoped_refptr<DrmDeviceBase> DrmDeviceManager::GetVgemDevice() const { |
| 173 DCHECK(thread_checker_.CalledOnValidThread()); |
| 174 auto it = std::find_if(devices_.begin(), devices_.end(), FindVgemDevice()); |
| 175 if (it == devices_.end()) { |
| 176 VLOG(2) << "Don't support VGEM."; |
| 177 return nullptr; |
| 178 } |
| 179 return *it; |
124 } | 180 } |
125 | 181 |
126 } // namespace ui | 182 } // namespace ui |
OLD | NEW |