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 15 matching lines...) Expand all Loading... |
26 }; | 26 }; |
27 | 27 |
28 } // namespace | 28 } // namespace |
29 | 29 |
30 DrmDeviceManager::DrmDeviceManager( | 30 DrmDeviceManager::DrmDeviceManager( |
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()); | |
37 DCHECK(drm_device_map_.empty()); | 36 DCHECK(drm_device_map_.empty()); |
38 } | 37 } |
39 | 38 |
40 bool DrmDeviceManager::AddDrmDevice(const base::FilePath& path, | 39 bool DrmDeviceManager::AddDrmDevice(const base::FilePath& path, |
41 const base::FileDescriptor& fd) { | 40 const base::FileDescriptor& fd) { |
42 DCHECK(thread_checker_.CalledOnValidThread()); | |
43 base::File file(fd.fd); | 41 base::File file(fd.fd); |
44 auto it = | 42 auto it = |
45 std::find_if(devices_.begin(), devices_.end(), FindByDevicePath(path)); | 43 std::find_if(devices_.begin(), devices_.end(), FindByDevicePath(path)); |
46 if (it != devices_.end()) { | 44 if (it != devices_.end()) { |
47 VLOG(2) << "Got request to add existing device: " << path.value(); | 45 VLOG(2) << "Got request to add existing device: " << path.value(); |
48 return false; | 46 return false; |
49 } | 47 } |
50 | 48 |
51 scoped_refptr<DrmDevice> device = | 49 scoped_refptr<DrmDevice> device = |
52 drm_device_generator_->CreateDevice(path, file.Pass(), !primary_device_); | 50 drm_device_generator_->CreateDevice(path, file.Pass(), !primary_device_); |
53 if (!device) { | 51 if (!device) { |
54 LOG(ERROR) << "Could not initialize DRM device for " << path.value(); | 52 LOG(ERROR) << "Could not initialize DRM device for " << path.value(); |
55 return false; | 53 return false; |
56 } | 54 } |
57 | 55 |
58 if (io_task_runner_) | |
59 device->InitializeTaskRunner(io_task_runner_); | |
60 | |
61 if (!primary_device_) | 56 if (!primary_device_) |
62 primary_device_ = device; | 57 primary_device_ = device; |
63 | 58 |
64 devices_.push_back(device); | 59 devices_.push_back(device); |
65 return true; | 60 return true; |
66 } | 61 } |
67 | 62 |
68 void DrmDeviceManager::RemoveDrmDevice(const base::FilePath& path) { | 63 void DrmDeviceManager::RemoveDrmDevice(const base::FilePath& path) { |
69 DCHECK(thread_checker_.CalledOnValidThread()); | |
70 auto it = | 64 auto it = |
71 std::find_if(devices_.begin(), devices_.end(), FindByDevicePath(path)); | 65 std::find_if(devices_.begin(), devices_.end(), FindByDevicePath(path)); |
72 if (it == devices_.end()) { | 66 if (it == devices_.end()) { |
73 VLOG(2) << "Got request to remove non-existent device: " << path.value(); | 67 VLOG(2) << "Got request to remove non-existent device: " << path.value(); |
74 return; | 68 return; |
75 } | 69 } |
76 | 70 |
77 DCHECK_NE(primary_device_, *it); | 71 DCHECK_NE(primary_device_, *it); |
78 devices_.erase(it); | 72 devices_.erase(it); |
79 } | 73 } |
80 | 74 |
81 void DrmDeviceManager::InitializeIOTaskRunner( | |
82 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) { | |
83 DCHECK(thread_checker_.CalledOnValidThread()); | |
84 DCHECK(!io_task_runner_); | |
85 io_task_runner_ = task_runner; | |
86 for (const auto& device : devices_) | |
87 device->InitializeTaskRunner(io_task_runner_); | |
88 } | |
89 | |
90 void DrmDeviceManager::UpdateDrmDevice(gfx::AcceleratedWidget widget, | 75 void DrmDeviceManager::UpdateDrmDevice(gfx::AcceleratedWidget widget, |
91 const scoped_refptr<DrmDevice>& device) { | 76 const scoped_refptr<DrmDevice>& device) { |
92 base::AutoLock lock(lock_); | |
93 drm_device_map_[widget] = device; | 77 drm_device_map_[widget] = device; |
94 } | 78 } |
95 | 79 |
96 void DrmDeviceManager::RemoveDrmDevice(gfx::AcceleratedWidget widget) { | 80 void DrmDeviceManager::RemoveDrmDevice(gfx::AcceleratedWidget widget) { |
97 base::AutoLock lock(lock_); | |
98 auto it = drm_device_map_.find(widget); | 81 auto it = drm_device_map_.find(widget); |
99 if (it != drm_device_map_.end()) | 82 if (it != drm_device_map_.end()) |
100 drm_device_map_.erase(it); | 83 drm_device_map_.erase(it); |
101 } | 84 } |
102 | 85 |
103 scoped_refptr<DrmDevice> DrmDeviceManager::GetDrmDevice( | 86 scoped_refptr<DrmDevice> DrmDeviceManager::GetDrmDevice( |
104 gfx::AcceleratedWidget widget) { | 87 gfx::AcceleratedWidget widget) { |
105 base::AutoLock lock(lock_); | |
106 if (widget == gfx::kNullAcceleratedWidget) | 88 if (widget == gfx::kNullAcceleratedWidget) |
107 return primary_device_; | 89 return primary_device_; |
108 | 90 |
109 auto it = drm_device_map_.find(widget); | 91 auto it = drm_device_map_.find(widget); |
110 DCHECK(it != drm_device_map_.end()) | 92 DCHECK(it != drm_device_map_.end()) |
111 << "Attempting to get device for unknown widget " << widget; | 93 << "Attempting to get device for unknown widget " << widget; |
112 // If the widget isn't associated with a display (headless mode) we can | 94 // 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. | 95 // 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. | 96 // Use the primary DRM device as a fallback when allocating these buffers. |
115 if (!it->second) | 97 if (!it->second) |
116 return primary_device_; | 98 return primary_device_; |
117 | 99 |
118 return it->second; | 100 return it->second; |
119 } | 101 } |
120 | 102 |
121 const DrmDeviceVector& DrmDeviceManager::GetDrmDevices() const { | 103 const DrmDeviceVector& DrmDeviceManager::GetDrmDevices() const { |
122 DCHECK(thread_checker_.CalledOnValidThread()); | |
123 return devices_; | 104 return devices_; |
124 } | 105 } |
125 | 106 |
126 } // namespace ui | 107 } // namespace ui |
OLD | NEW |