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" |
(...skipping 20 matching lines...) Expand all Loading... | |
31 scoped_ptr<DrmDeviceGenerator> drm_device_generator) | 31 scoped_ptr<DrmDeviceGenerator> drm_device_generator) |
32 : drm_device_generator_(drm_device_generator.Pass()) { | 32 : drm_device_generator_(drm_device_generator.Pass()) { |
33 } | 33 } |
34 | 34 |
35 DrmDeviceManager::~DrmDeviceManager() { | 35 DrmDeviceManager::~DrmDeviceManager() { |
36 DCHECK(thread_checker_.CalledOnValidThread()); | 36 DCHECK(thread_checker_.CalledOnValidThread()); |
37 DCHECK(drm_device_map_.empty()); | 37 DCHECK(drm_device_map_.empty()); |
38 } | 38 } |
39 | 39 |
40 bool DrmDeviceManager::AddDrmDevice(const base::FilePath& path, | 40 bool DrmDeviceManager::AddDrmDevice(const base::FilePath& path, |
41 const base::FileDescriptor& fd) { | 41 const base::FileDescriptor& fd, |
42 bool is_vgem) { | |
42 DCHECK(thread_checker_.CalledOnValidThread()); | 43 DCHECK(thread_checker_.CalledOnValidThread()); |
44 DCHECK(fd.auto_close); | |
reveman
2015/05/12 13:47:01
this check seems inappropriate. why should this no
dshwang
2015/05/12 14:11:42
DrmDeviceManager implementation always close the g
reveman
2015/05/12 17:19:00
yes
dshwang
2015/05/13 13:09:00
Done.
| |
45 | |
46 if (is_vgem) { | |
reveman
2015/05/12 13:47:01
why is the code below not relevant in this case? C
dshwang
2015/05/12 14:11:42
That's good question. The answer is directly relat
reveman
2015/05/12 15:49:24
So should DrmDevice be doing something different i
dshwang
2015/05/12 16:18:57
Yes, vgem fd must be handled differently. I just a
reveman
2015/05/12 17:19:00
If vgem is supported, are all devices not vgem?
I
dshwang
2015/05/12 17:48:02
How about creating DriDevice pure virtual class? D
zachr
2015/05/12 18:24:37
All of these things wrap the same type of object:
dshwang
2015/05/12 18:36:20
Thank you for answering. I'll handle vgem in DrmDe
dshwang
2015/05/13 13:09:00
Done.
| |
47 vgem_device_.reset(fd.fd); | |
48 vgem_path_ = path; | |
reveman
2015/05/12 17:19:00
what happens if 2 vgem devices are added?
dshwang
2015/05/12 17:48:02
I don't think vgem can be 2. zachr, could you conf
zachr
2015/05/12 18:24:37
card numbers are arbitrary and it is a mistake to
dshwang
2015/05/12 18:36:20
Great answer. I did ask that can device have 2 dif
dshwang
2015/05/13 13:09:00
Done. handle multiple add and remove in same way t
| |
49 return true; | |
50 } | |
51 | |
43 base::File file(fd.fd); | 52 base::File file(fd.fd); |
44 auto it = | 53 auto it = |
45 std::find_if(devices_.begin(), devices_.end(), FindByDevicePath(path)); | 54 std::find_if(devices_.begin(), devices_.end(), FindByDevicePath(path)); |
46 if (it != devices_.end()) { | 55 if (it != devices_.end()) { |
47 VLOG(2) << "Got request to add existing device: " << path.value(); | 56 VLOG(2) << "Got request to add existing device: " << path.value(); |
48 return false; | 57 return false; |
49 } | 58 } |
50 | 59 |
51 scoped_refptr<DrmDevice> device = | 60 scoped_refptr<DrmDevice> device = |
52 drm_device_generator_->CreateDevice(path, file.Pass()); | 61 drm_device_generator_->CreateDevice(path, file.Pass()); |
53 if (!device) { | 62 if (!device) { |
54 LOG(ERROR) << "Could not initialize DRM device for " << path.value(); | 63 LOG(ERROR) << "Could not initialize DRM device for " << path.value(); |
55 return false; | 64 return false; |
56 } | 65 } |
57 | 66 |
58 if (io_task_runner_) | 67 if (io_task_runner_) |
59 device->InitializeTaskRunner(io_task_runner_); | 68 device->InitializeTaskRunner(io_task_runner_); |
60 | 69 |
61 if (!primary_device_) | 70 if (!primary_device_) |
62 primary_device_ = device; | 71 primary_device_ = device; |
63 | 72 |
64 devices_.push_back(device); | 73 devices_.push_back(device); |
65 return true; | 74 return true; |
66 } | 75 } |
67 | 76 |
68 void DrmDeviceManager::RemoveDrmDevice(const base::FilePath& path) { | 77 void DrmDeviceManager::RemoveDrmDevice(const base::FilePath& path) { |
69 DCHECK(thread_checker_.CalledOnValidThread()); | 78 DCHECK(thread_checker_.CalledOnValidThread()); |
79 if (vgem_path_ == path) { | |
80 vgem_device_.reset(); | |
81 vgem_path_ = base::FilePath(); | |
82 return; | |
83 } | |
84 | |
70 auto it = | 85 auto it = |
71 std::find_if(devices_.begin(), devices_.end(), FindByDevicePath(path)); | 86 std::find_if(devices_.begin(), devices_.end(), FindByDevicePath(path)); |
72 if (it == devices_.end()) { | 87 if (it == devices_.end()) { |
73 VLOG(2) << "Got request to remove non-existent device: " << path.value(); | 88 VLOG(2) << "Got request to remove non-existent device: " << path.value(); |
74 return; | 89 return; |
75 } | 90 } |
76 | 91 |
77 DCHECK_NE(primary_device_, *it); | 92 DCHECK_NE(primary_device_, *it); |
78 devices_.erase(it); | 93 devices_.erase(it); |
79 } | 94 } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
116 return primary_device_; | 131 return primary_device_; |
117 | 132 |
118 return it->second; | 133 return it->second; |
119 } | 134 } |
120 | 135 |
121 const DrmDeviceVector& DrmDeviceManager::GetDrmDevices() const { | 136 const DrmDeviceVector& DrmDeviceManager::GetDrmDevices() const { |
122 DCHECK(thread_checker_.CalledOnValidThread()); | 137 DCHECK(thread_checker_.CalledOnValidThread()); |
123 return devices_; | 138 return devices_; |
124 } | 139 } |
125 | 140 |
141 int DrmDeviceManager::GetVgemDevice() const { | |
142 DCHECK(thread_checker_.CalledOnValidThread()); | |
143 return vgem_device_.get(); | |
144 } | |
145 | |
126 } // namespace ui | 146 } // namespace ui |
OLD | NEW |