Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(107)

Side by Side Diff: ui/ozone/platform/drm/host/drm_display_host_manager.cc

Issue 1262043002: Implement DRM Native Pixmap using prime buffer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@new-master
Patch Set: rebase code, address spang comments, and vgem removal Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/host/drm_display_host_manager.h" 5 #include "ui/ozone/platform/drm/host/drm_display_host_manager.h"
6 6
7 #include <fcntl.h> 7 #include <fcntl.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <xf86drm.h> 9 #include <xf86drm.h>
10 #include <utility> 10 #include <utility>
11 11
12 #include "base/files/file_enumerator.h" 12 #include "base/files/file_enumerator.h"
dshwang 2016/03/23 15:52:51 It's not needed.
vignatti (out of this project) 2016/03/23 19:46:07 Done.
13 #include "base/files/file_path.h" 13 #include "base/files/file_path.h"
14 #include "base/files/file_util.h" 14 #include "base/files/file_util.h"
15 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
16 #include "base/thread_task_runner_handle.h" 16 #include "base/thread_task_runner_handle.h"
17 #include "base/threading/thread_restrictions.h" 17 #include "base/threading/thread_restrictions.h"
18 #include "base/threading/worker_pool.h" 18 #include "base/threading/worker_pool.h"
19 #include "ui/display/types/display_snapshot.h" 19 #include "ui/display/types/display_snapshot.h"
20 #include "ui/events/ozone/device/device_event.h" 20 #include "ui/events/ozone/device/device_event.h"
21 #include "ui/events/ozone/device/device_manager.h" 21 #include "ui/events/ozone/device/device_manager.h"
22 #include "ui/ozone/common/display_util.h" 22 #include "ui/ozone/common/display_util.h"
23 #include "ui/ozone/platform/drm/common/drm_util.h" 23 #include "ui/ozone/platform/drm/common/drm_util.h"
24 #include "ui/ozone/platform/drm/host/drm_device_handle.h" 24 #include "ui/ozone/platform/drm/host/drm_device_handle.h"
25 #include "ui/ozone/platform/drm/host/drm_display_host.h" 25 #include "ui/ozone/platform/drm/host/drm_display_host.h"
26 #include "ui/ozone/platform/drm/host/drm_native_display_delegate.h" 26 #include "ui/ozone/platform/drm/host/drm_native_display_delegate.h"
27 #include "ui/ozone/platform/drm/host/gpu_thread_adapter.h" 27 #include "ui/ozone/platform/drm/host/gpu_thread_adapter.h"
28 28
29 namespace ui { 29 namespace ui {
30 30
31 namespace { 31 namespace {
32 32
33 typedef base::Callback<void(const base::FilePath&, 33 typedef base::Callback<void(const base::FilePath&,
34 const base::FilePath&, 34 const base::FilePath&,
35 scoped_ptr<DrmDeviceHandle>)> 35 scoped_ptr<DrmDeviceHandle>)>
36 OnOpenDeviceReplyCallback; 36 OnOpenDeviceReplyCallback;
37 37
38 const char kDefaultGraphicsCardPattern[] = "/dev/dri/card%d"; 38 const char kDefaultGraphicsCardPattern[] = "/dev/dri/card%d";
39 const char kVgemDevDriCardPath[] = "/dev/dri/";
40 const char kVgemSysCardPath[] = "/sys/bus/platform/devices/vgem/drm/";
41 39
42 const char* kDisplayActionString[] = { 40 const char* kDisplayActionString[] = {
43 "ADD", "REMOVE", "CHANGE", 41 "ADD", "REMOVE", "CHANGE",
44 }; 42 };
45 43
46 // Find sysfs device path for the given device path. 44 // Find sysfs device path for the given device path.
47 base::FilePath MapDevPathToSysPath(const base::FilePath& device_path) { 45 base::FilePath MapDevPathToSysPath(const base::FilePath& device_path) {
48 // |device_path| looks something like /dev/dri/card0. We take the basename of 46 // |device_path| looks something like /dev/dri/card0. We take the basename of
49 // that (card0) and append it to /sys/class/drm. /sys/class/drm/card0 is a 47 // that (card0) and append it to /sys/class/drm. /sys/class/drm/card0 is a
50 // symlink that points to something like 48 // symlink that points to something like
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 return base::FilePath(card_path); 86 return base::FilePath(card_path);
89 } 87 }
90 88
91 VPLOG_IF(1, ret) << "Failed to get DRM resources for '" << card_path << "'"; 89 VPLOG_IF(1, ret) << "Failed to get DRM resources for '" << card_path << "'";
92 } 90 }
93 91
94 LOG(FATAL) << "Failed to open primary graphics device."; 92 LOG(FATAL) << "Failed to open primary graphics device.";
95 return base::FilePath(); // Not reached. 93 return base::FilePath(); // Not reached.
96 } 94 }
97 95
98 base::FilePath GetVgemCardPath() {
99 base::FileEnumerator file_iter(base::FilePath(kVgemSysCardPath), false,
100 base::FileEnumerator::DIRECTORIES,
101 FILE_PATH_LITERAL("card*"));
102
103 while (!file_iter.Next().empty()) {
104 // Inspect the card%d directories in the directory and extract the filename.
105 std::string vgem_card_path =
106 kVgemDevDriCardPath + file_iter.GetInfo().GetName().BaseName().value();
107 DVLOG(1) << "VGEM card path is " << vgem_card_path;
108 return base::FilePath(vgem_card_path);
109 }
110 DVLOG(1) << "Don't support VGEM";
111 return base::FilePath();
112 }
113
114 class FindDrmDisplayHostById { 96 class FindDrmDisplayHostById {
115 public: 97 public:
116 explicit FindDrmDisplayHostById(int64_t display_id) 98 explicit FindDrmDisplayHostById(int64_t display_id)
117 : display_id_(display_id) {} 99 : display_id_(display_id) {}
118 100
119 bool operator()(const scoped_ptr<DrmDisplayHost>& display) const { 101 bool operator()(const scoped_ptr<DrmDisplayHost>& display) const {
120 return display->snapshot()->display_id() == display_id_; 102 return display->snapshot()->display_id() == display_id_;
121 } 103 }
122 104
123 private: 105 private:
(...skipping 21 matching lines...) Expand all
145 MapDevPathToSysPath(primary_graphics_card_path_); 127 MapDevPathToSysPath(primary_graphics_card_path_);
146 128
147 primary_drm_device_handle_.reset(new DrmDeviceHandle()); 129 primary_drm_device_handle_.reset(new DrmDeviceHandle());
148 if (!primary_drm_device_handle_->Initialize( 130 if (!primary_drm_device_handle_->Initialize(
149 primary_graphics_card_path_, primary_graphics_card_path_sysfs)) { 131 primary_graphics_card_path_, primary_graphics_card_path_sysfs)) {
150 LOG(FATAL) << "Failed to open primary graphics card"; 132 LOG(FATAL) << "Failed to open primary graphics card";
151 return; 133 return;
152 } 134 }
153 drm_devices_[primary_graphics_card_path_] = 135 drm_devices_[primary_graphics_card_path_] =
154 primary_graphics_card_path_sysfs; 136 primary_graphics_card_path_sysfs;
155
156 vgem_card_path_ = GetVgemCardPath();
157 } 137 }
158 138
159 device_manager_->AddObserver(this); 139 device_manager_->AddObserver(this);
160 proxy_->RegisterHandlerForDrmDisplayHostManager(this); 140 proxy_->RegisterHandlerForDrmDisplayHostManager(this);
161 proxy_->AddGpuThreadObserver(this); 141 proxy_->AddGpuThreadObserver(this);
162 142
163 ScopedVector<HardwareDisplayControllerInfo> display_infos = 143 ScopedVector<HardwareDisplayControllerInfo> display_infos =
164 GetAvailableDisplayControllerInfos(primary_drm_device_handle_->fd()); 144 GetAvailableDisplayControllerInfos(primary_drm_device_handle_->fd());
165 has_dummy_display_ = !display_infos.empty(); 145 has_dummy_display_ = !display_infos.empty();
166 for (size_t i = 0; i < display_infos.size(); ++i) { 146 for (size_t i = 0; i < display_infos.size(); ++i) {
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 } 237 }
258 238
259 void DrmDisplayHostManager::ProcessEvent() { 239 void DrmDisplayHostManager::ProcessEvent() {
260 while (!event_queue_.empty() && !task_pending_) { 240 while (!event_queue_.empty() && !task_pending_) {
261 DisplayEvent event = event_queue_.front(); 241 DisplayEvent event = event_queue_.front();
262 event_queue_.pop(); 242 event_queue_.pop();
263 VLOG(1) << "Got display event " << kDisplayActionString[event.action_type] 243 VLOG(1) << "Got display event " << kDisplayActionString[event.action_type]
264 << " for " << event.path.value(); 244 << " for " << event.path.value();
265 switch (event.action_type) { 245 switch (event.action_type) {
266 case DeviceEvent::ADD: 246 case DeviceEvent::ADD:
267 if (event.path == vgem_card_path_)
268 continue;
269 if (drm_devices_.find(event.path) == drm_devices_.end()) { 247 if (drm_devices_.find(event.path) == drm_devices_.end()) {
270 task_pending_ = base::WorkerPool::PostTask( 248 task_pending_ = base::WorkerPool::PostTask(
271 FROM_HERE, 249 FROM_HERE,
272 base::Bind(&OpenDeviceOnWorkerThread, event.path, 250 base::Bind(&OpenDeviceOnWorkerThread, event.path,
273 base::ThreadTaskRunnerHandle::Get(), 251 base::ThreadTaskRunnerHandle::Get(),
274 base::Bind(&DrmDisplayHostManager::OnAddGraphicsDevice, 252 base::Bind(&DrmDisplayHostManager::OnAddGraphicsDevice,
275 weak_ptr_factory_.GetWeakPtr())), 253 weak_ptr_factory_.GetWeakPtr())),
276 false /* task_is_slow */); 254 false /* task_is_slow */);
277 } 255 }
278 break; 256 break;
279 case DeviceEvent::CHANGE: 257 case DeviceEvent::CHANGE:
280 task_pending_ = base::ThreadTaskRunnerHandle::Get()->PostTask( 258 task_pending_ = base::ThreadTaskRunnerHandle::Get()->PostTask(
281 FROM_HERE, 259 FROM_HERE,
282 base::Bind(&DrmDisplayHostManager::OnUpdateGraphicsDevice, 260 base::Bind(&DrmDisplayHostManager::OnUpdateGraphicsDevice,
283 weak_ptr_factory_.GetWeakPtr())); 261 weak_ptr_factory_.GetWeakPtr()));
284 break; 262 break;
285 case DeviceEvent::REMOVE: 263 case DeviceEvent::REMOVE:
286 DCHECK(event.path != primary_graphics_card_path_) 264 DCHECK(event.path != primary_graphics_card_path_)
287 << "Removing primary graphics card"; 265 << "Removing primary graphics card";
288 DCHECK(event.path != vgem_card_path_) << "Removing VGEM device";
289 auto it = drm_devices_.find(event.path); 266 auto it = drm_devices_.find(event.path);
290 if (it != drm_devices_.end()) { 267 if (it != drm_devices_.end()) {
291 task_pending_ = base::ThreadTaskRunnerHandle::Get()->PostTask( 268 task_pending_ = base::ThreadTaskRunnerHandle::Get()->PostTask(
292 FROM_HERE, 269 FROM_HERE,
293 base::Bind(&DrmDisplayHostManager::OnRemoveGraphicsDevice, 270 base::Bind(&DrmDisplayHostManager::OnRemoveGraphicsDevice,
294 weak_ptr_factory_.GetWeakPtr(), it->second)); 271 weak_ptr_factory_.GetWeakPtr(), it->second));
295 drm_devices_.erase(it); 272 drm_devices_.erase(it);
296 } 273 }
297 break; 274 break;
298 } 275 }
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 456
480 callback.Run(snapshots); 457 callback.Run(snapshots);
481 } 458 }
482 459
483 void DrmDisplayHostManager::NotifyDisplayDelegate() const { 460 void DrmDisplayHostManager::NotifyDisplayDelegate() const {
484 if (delegate_) 461 if (delegate_)
485 delegate_->OnConfigurationChanged(); 462 delegate_->OnConfigurationChanged();
486 } 463 }
487 464
488 } // namespace ui 465 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698