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

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: remove drm header 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"
13 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
14 #include "base/files/file_util.h" 13 #include "base/files/file_util.h"
15 #include "base/strings/stringprintf.h" 14 #include "base/strings/stringprintf.h"
16 #include "base/thread_task_runner_handle.h" 15 #include "base/thread_task_runner_handle.h"
17 #include "base/threading/thread_restrictions.h" 16 #include "base/threading/thread_restrictions.h"
18 #include "base/threading/worker_pool.h" 17 #include "base/threading/worker_pool.h"
19 #include "ui/display/types/display_snapshot.h" 18 #include "ui/display/types/display_snapshot.h"
20 #include "ui/events/ozone/device/device_event.h" 19 #include "ui/events/ozone/device/device_event.h"
21 #include "ui/events/ozone/device/device_manager.h" 20 #include "ui/events/ozone/device/device_manager.h"
22 #include "ui/ozone/common/display_util.h" 21 #include "ui/ozone/common/display_util.h"
23 #include "ui/ozone/platform/drm/common/drm_util.h" 22 #include "ui/ozone/platform/drm/common/drm_util.h"
24 #include "ui/ozone/platform/drm/host/drm_device_handle.h" 23 #include "ui/ozone/platform/drm/host/drm_device_handle.h"
25 #include "ui/ozone/platform/drm/host/drm_display_host.h" 24 #include "ui/ozone/platform/drm/host/drm_display_host.h"
26 #include "ui/ozone/platform/drm/host/drm_native_display_delegate.h" 25 #include "ui/ozone/platform/drm/host/drm_native_display_delegate.h"
27 #include "ui/ozone/platform/drm/host/gpu_thread_adapter.h" 26 #include "ui/ozone/platform/drm/host/gpu_thread_adapter.h"
28 27
29 namespace ui { 28 namespace ui {
30 29
31 namespace { 30 namespace {
32 31
33 typedef base::Callback<void(const base::FilePath&, 32 typedef base::Callback<void(const base::FilePath&,
34 const base::FilePath&, 33 const base::FilePath&,
35 scoped_ptr<DrmDeviceHandle>)> 34 scoped_ptr<DrmDeviceHandle>)>
36 OnOpenDeviceReplyCallback; 35 OnOpenDeviceReplyCallback;
37 36
38 const char kDefaultGraphicsCardPattern[] = "/dev/dri/card%d"; 37 const char kDefaultGraphicsCardPattern[] = "/dev/dri/card%d";
39 const char kVgemDevDriCardPath[] = "/dev/dri/";
40 const char kVgemSysCardPath[] = "/sys/bus/platform/devices/vgem/drm/";
41 38
42 const char* kDisplayActionString[] = { 39 const char* kDisplayActionString[] = {
43 "ADD", "REMOVE", "CHANGE", 40 "ADD", "REMOVE", "CHANGE",
44 }; 41 };
45 42
46 // Find sysfs device path for the given device path. 43 // Find sysfs device path for the given device path.
47 base::FilePath MapDevPathToSysPath(const base::FilePath& device_path) { 44 base::FilePath MapDevPathToSysPath(const base::FilePath& device_path) {
48 // |device_path| looks something like /dev/dri/card0. We take the basename of 45 // |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 46 // that (card0) and append it to /sys/class/drm. /sys/class/drm/card0 is a
50 // symlink that points to something like 47 // symlink that points to something like
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 return base::FilePath(card_path); 85 return base::FilePath(card_path);
89 } 86 }
90 87
91 VPLOG_IF(1, ret) << "Failed to get DRM resources for '" << card_path << "'"; 88 VPLOG_IF(1, ret) << "Failed to get DRM resources for '" << card_path << "'";
92 } 89 }
93 90
94 LOG(FATAL) << "Failed to open primary graphics device."; 91 LOG(FATAL) << "Failed to open primary graphics device.";
95 return base::FilePath(); // Not reached. 92 return base::FilePath(); // Not reached.
96 } 93 }
97 94
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 { 95 class FindDrmDisplayHostById {
115 public: 96 public:
116 explicit FindDrmDisplayHostById(int64_t display_id) 97 explicit FindDrmDisplayHostById(int64_t display_id)
117 : display_id_(display_id) {} 98 : display_id_(display_id) {}
118 99
119 bool operator()(const scoped_ptr<DrmDisplayHost>& display) const { 100 bool operator()(const scoped_ptr<DrmDisplayHost>& display) const {
120 return display->snapshot()->display_id() == display_id_; 101 return display->snapshot()->display_id() == display_id_;
121 } 102 }
122 103
123 private: 104 private:
(...skipping 21 matching lines...) Expand all
145 MapDevPathToSysPath(primary_graphics_card_path_); 126 MapDevPathToSysPath(primary_graphics_card_path_);
146 127
147 primary_drm_device_handle_.reset(new DrmDeviceHandle()); 128 primary_drm_device_handle_.reset(new DrmDeviceHandle());
148 if (!primary_drm_device_handle_->Initialize( 129 if (!primary_drm_device_handle_->Initialize(
149 primary_graphics_card_path_, primary_graphics_card_path_sysfs)) { 130 primary_graphics_card_path_, primary_graphics_card_path_sysfs)) {
150 LOG(FATAL) << "Failed to open primary graphics card"; 131 LOG(FATAL) << "Failed to open primary graphics card";
151 return; 132 return;
152 } 133 }
153 drm_devices_[primary_graphics_card_path_] = 134 drm_devices_[primary_graphics_card_path_] =
154 primary_graphics_card_path_sysfs; 135 primary_graphics_card_path_sysfs;
155
156 vgem_card_path_ = GetVgemCardPath();
157 } 136 }
158 137
159 device_manager_->AddObserver(this); 138 device_manager_->AddObserver(this);
160 proxy_->RegisterHandlerForDrmDisplayHostManager(this); 139 proxy_->RegisterHandlerForDrmDisplayHostManager(this);
161 proxy_->AddGpuThreadObserver(this); 140 proxy_->AddGpuThreadObserver(this);
162 141
163 ScopedVector<HardwareDisplayControllerInfo> display_infos = 142 ScopedVector<HardwareDisplayControllerInfo> display_infos =
164 GetAvailableDisplayControllerInfos(primary_drm_device_handle_->fd()); 143 GetAvailableDisplayControllerInfos(primary_drm_device_handle_->fd());
165 has_dummy_display_ = !display_infos.empty(); 144 has_dummy_display_ = !display_infos.empty();
166 for (size_t i = 0; i < display_infos.size(); ++i) { 145 for (size_t i = 0; i < display_infos.size(); ++i) {
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 } 236 }
258 237
259 void DrmDisplayHostManager::ProcessEvent() { 238 void DrmDisplayHostManager::ProcessEvent() {
260 while (!event_queue_.empty() && !task_pending_) { 239 while (!event_queue_.empty() && !task_pending_) {
261 DisplayEvent event = event_queue_.front(); 240 DisplayEvent event = event_queue_.front();
262 event_queue_.pop(); 241 event_queue_.pop();
263 VLOG(1) << "Got display event " << kDisplayActionString[event.action_type] 242 VLOG(1) << "Got display event " << kDisplayActionString[event.action_type]
264 << " for " << event.path.value(); 243 << " for " << event.path.value();
265 switch (event.action_type) { 244 switch (event.action_type) {
266 case DeviceEvent::ADD: 245 case DeviceEvent::ADD:
267 if (event.path == vgem_card_path_)
268 continue;
269 if (drm_devices_.find(event.path) == drm_devices_.end()) { 246 if (drm_devices_.find(event.path) == drm_devices_.end()) {
270 task_pending_ = base::WorkerPool::PostTask( 247 task_pending_ = base::WorkerPool::PostTask(
271 FROM_HERE, 248 FROM_HERE,
272 base::Bind(&OpenDeviceOnWorkerThread, event.path, 249 base::Bind(&OpenDeviceOnWorkerThread, event.path,
273 base::ThreadTaskRunnerHandle::Get(), 250 base::ThreadTaskRunnerHandle::Get(),
274 base::Bind(&DrmDisplayHostManager::OnAddGraphicsDevice, 251 base::Bind(&DrmDisplayHostManager::OnAddGraphicsDevice,
275 weak_ptr_factory_.GetWeakPtr())), 252 weak_ptr_factory_.GetWeakPtr())),
276 false /* task_is_slow */); 253 false /* task_is_slow */);
277 } 254 }
278 break; 255 break;
279 case DeviceEvent::CHANGE: 256 case DeviceEvent::CHANGE:
280 task_pending_ = base::ThreadTaskRunnerHandle::Get()->PostTask( 257 task_pending_ = base::ThreadTaskRunnerHandle::Get()->PostTask(
281 FROM_HERE, 258 FROM_HERE,
282 base::Bind(&DrmDisplayHostManager::OnUpdateGraphicsDevice, 259 base::Bind(&DrmDisplayHostManager::OnUpdateGraphicsDevice,
283 weak_ptr_factory_.GetWeakPtr())); 260 weak_ptr_factory_.GetWeakPtr()));
284 break; 261 break;
285 case DeviceEvent::REMOVE: 262 case DeviceEvent::REMOVE:
286 DCHECK(event.path != primary_graphics_card_path_) 263 DCHECK(event.path != primary_graphics_card_path_)
287 << "Removing primary graphics card"; 264 << "Removing primary graphics card";
288 DCHECK(event.path != vgem_card_path_) << "Removing VGEM device";
289 auto it = drm_devices_.find(event.path); 265 auto it = drm_devices_.find(event.path);
290 if (it != drm_devices_.end()) { 266 if (it != drm_devices_.end()) {
291 task_pending_ = base::ThreadTaskRunnerHandle::Get()->PostTask( 267 task_pending_ = base::ThreadTaskRunnerHandle::Get()->PostTask(
292 FROM_HERE, 268 FROM_HERE,
293 base::Bind(&DrmDisplayHostManager::OnRemoveGraphicsDevice, 269 base::Bind(&DrmDisplayHostManager::OnRemoveGraphicsDevice,
294 weak_ptr_factory_.GetWeakPtr(), it->second)); 270 weak_ptr_factory_.GetWeakPtr(), it->second));
295 drm_devices_.erase(it); 271 drm_devices_.erase(it);
296 } 272 }
297 break; 273 break;
298 } 274 }
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 455
480 callback.Run(snapshots); 456 callback.Run(snapshots);
481 } 457 }
482 458
483 void DrmDisplayHostManager::NotifyDisplayDelegate() const { 459 void DrmDisplayHostManager::NotifyDisplayDelegate() const {
484 if (delegate_) 460 if (delegate_)
485 delegate_->OnConfigurationChanged(); 461 delegate_->OnConfigurationChanged();
486 } 462 }
487 463
488 } // namespace ui 464 } // namespace ui
OLDNEW
« no previous file with comments | « ui/ozone/platform/drm/host/drm_display_host_manager.h ('k') | ui/ozone/platform/drm/ozone_platform_gbm.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698