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

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

Issue 1151533002: drm: Make DrmDisplayHostManager handle VGEM fd by itself. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: handle the case when vgem is absent Created 5 years, 6 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
« no previous file with comments | « ui/ozone/platform/drm/host/drm_display_host_manager.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <stdio.h> 8 #include <stdio.h>
9 #include <xf86drm.h> 9 #include <xf86drm.h>
10 10
11 #include "base/files/file_enumerator.h"
11 #include "base/logging.h" 12 #include "base/logging.h"
12 #include "base/strings/stringprintf.h" 13 #include "base/strings/stringprintf.h"
13 #include "base/thread_task_runner_handle.h" 14 #include "base/thread_task_runner_handle.h"
14 #include "base/threading/thread_restrictions.h" 15 #include "base/threading/thread_restrictions.h"
15 #include "base/threading/worker_pool.h" 16 #include "base/threading/worker_pool.h"
16 #include "ui/display/types/display_snapshot.h" 17 #include "ui/display/types/display_snapshot.h"
17 #include "ui/events/ozone/device/device_event.h" 18 #include "ui/events/ozone/device/device_event.h"
18 #include "ui/events/ozone/device/device_manager.h" 19 #include "ui/events/ozone/device/device_manager.h"
19 #include "ui/ozone/common/display_util.h" 20 #include "ui/ozone/common/display_util.h"
20 #include "ui/ozone/common/gpu/ozone_gpu_messages.h" 21 #include "ui/ozone/common/gpu/ozone_gpu_messages.h"
21 #include "ui/ozone/platform/drm/common/drm_util.h" 22 #include "ui/ozone/platform/drm/common/drm_util.h"
22 #include "ui/ozone/platform/drm/host/drm_device_handle.h" 23 #include "ui/ozone/platform/drm/host/drm_device_handle.h"
23 #include "ui/ozone/platform/drm/host/drm_display_host.h" 24 #include "ui/ozone/platform/drm/host/drm_display_host.h"
24 #include "ui/ozone/platform/drm/host/drm_gpu_platform_support_host.h" 25 #include "ui/ozone/platform/drm/host/drm_gpu_platform_support_host.h"
25 #include "ui/ozone/platform/drm/host/drm_native_display_delegate.h" 26 #include "ui/ozone/platform/drm/host/drm_native_display_delegate.h"
26 27
27 namespace ui { 28 namespace ui {
28 29
29 namespace { 30 namespace {
30 31
31 typedef base::Callback<void(const base::FilePath&, scoped_ptr<DrmDeviceHandle>)> 32 typedef base::Callback<void(const base::FilePath&, scoped_ptr<DrmDeviceHandle>)>
32 OnOpenDeviceReplyCallback; 33 OnOpenDeviceReplyCallback;
33 34
34 const char kDefaultGraphicsCardPattern[] = "/dev/dri/card%d"; 35 const char kDefaultGraphicsCardPattern[] = "/dev/dri/card%d";
36 const char kVgemDevDriCardPath[] = "/dev/dri/";
37 const char kVgemSysCardPath[] = "/sys/bus/platform/devices/vgem/drm/";
35 38
36 const char* kDisplayActionString[] = { 39 const char* kDisplayActionString[] = {
37 "ADD", 40 "ADD",
38 "REMOVE", 41 "REMOVE",
39 "CHANGE", 42 "CHANGE",
40 }; 43 };
41 44
42 void OpenDeviceOnWorkerThread( 45 void OpenDeviceOnWorkerThread(
43 const base::FilePath& path, 46 const base::FilePath& path,
44 const scoped_refptr<base::TaskRunner>& reply_runner, 47 const scoped_refptr<base::TaskRunner>& reply_runner,
(...skipping 24 matching lines...) Expand all
69 if (ret == 0 && res.count_crtcs > 0) { 72 if (ret == 0 && res.count_crtcs > 0) {
70 return base::FilePath(card_path); 73 return base::FilePath(card_path);
71 } 74 }
72 75
73 VPLOG_IF(1, ret) << "Failed to get DRM resources for '" << card_path << "'"; 76 VPLOG_IF(1, ret) << "Failed to get DRM resources for '" << card_path << "'";
74 } 77 }
75 78
76 return base::FilePath(); 79 return base::FilePath();
77 } 80 }
78 81
82 base::FilePath GetVgemCardPath() {
83 base::FileEnumerator file_iter(
84 base::FilePath::FromUTF8Unsafe(kVgemSysCardPath), false,
spang 2015/06/03 19:03:21 I don't think you need the FromUTF8Unsafe(). Does
85 base::FileEnumerator::DIRECTORIES, FILE_PATH_LITERAL("card*"));
86
87 while (!file_iter.Next().empty()) {
88 // Inspect the card%d directories in the directory and extract the filename.
89 std::string vgem_card_path =
90 kVgemDevDriCardPath +
91 file_iter.GetInfo().GetName().BaseName().MaybeAsASCII();
spang 2015/06/03 19:03:21 Use value() instead of MaybeAsASCII().
dshwang 2015/06/04 08:32:07 Done.
92 DVLOG(1) << "VGEM card path is " << vgem_card_path;
93 return base::FilePath(vgem_card_path);
94 }
95 DVLOG(1) << "Don't support VGEM";
96 return base::FilePath();
97 }
98
79 class FindDrmDisplayHostById { 99 class FindDrmDisplayHostById {
80 public: 100 public:
81 explicit FindDrmDisplayHostById(int64_t display_id) 101 explicit FindDrmDisplayHostById(int64_t display_id)
82 : display_id_(display_id) {} 102 : display_id_(display_id) {}
83 103
84 bool operator()(const DrmDisplayHost* display) const { 104 bool operator()(const DrmDisplayHost* display) const {
85 return display->snapshot()->display_id() == display_id_; 105 return display->snapshot()->display_id() == display_id_;
86 } 106 }
87 107
88 private: 108 private:
(...skipping 15 matching lines...) Expand all
104 // First device needs to be treated specially. We need to open this 124 // First device needs to be treated specially. We need to open this
105 // synchronously since the GPU process will need it to initialize the 125 // synchronously since the GPU process will need it to initialize the
106 // graphics state. 126 // graphics state.
107 base::ThreadRestrictions::ScopedAllowIO allow_io; 127 base::ThreadRestrictions::ScopedAllowIO allow_io;
108 primary_drm_device_handle_.reset(new DrmDeviceHandle()); 128 primary_drm_device_handle_.reset(new DrmDeviceHandle());
109 if (!primary_drm_device_handle_->Initialize(primary_graphics_card_path_)) { 129 if (!primary_drm_device_handle_->Initialize(primary_graphics_card_path_)) {
110 LOG(FATAL) << "Failed to open primary graphics card"; 130 LOG(FATAL) << "Failed to open primary graphics card";
111 return; 131 return;
112 } 132 }
113 drm_devices_.insert(primary_graphics_card_path_); 133 drm_devices_.insert(primary_graphics_card_path_);
134
135 vgem_card_path_ = GetVgemCardPath();
136 if (!vgem_card_path_.empty()) {
dshwang 2015/06/03 10:07:35 handle the platform which doesn't have vgem.
spang 2015/06/03 19:03:21 Can you just use open() and store it in a ScopedFD
dshwang 2015/06/04 08:32:07 Done.
137 vgem_card_device_file_ = base::File(
138 vgem_card_path_, base::File::FLAG_OPEN | base::File::FLAG_READ |
139 base::File::FLAG_WRITE);
140 }
114 } 141 }
115 142
116 device_manager_->AddObserver(this); 143 device_manager_->AddObserver(this);
117 proxy_->RegisterHandler(this); 144 proxy_->RegisterHandler(this);
118 145
119 ScopedVector<HardwareDisplayControllerInfo> display_infos = 146 ScopedVector<HardwareDisplayControllerInfo> display_infos =
120 GetAvailableDisplayControllerInfos(primary_drm_device_handle_->fd()); 147 GetAvailableDisplayControllerInfos(primary_drm_device_handle_->fd());
121 has_dummy_display_ = !display_infos.empty(); 148 has_dummy_display_ = !display_infos.empty();
122 for (size_t i = 0; i < display_infos.size(); ++i) { 149 for (size_t i = 0; i < display_infos.size(); ++i) {
123 displays_.push_back(new DrmDisplayHost( 150 displays_.push_back(new DrmDisplayHost(
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 } 207 }
181 208
182 void DrmDisplayHostManager::ProcessEvent() { 209 void DrmDisplayHostManager::ProcessEvent() {
183 while (!event_queue_.empty() && !task_pending_) { 210 while (!event_queue_.empty() && !task_pending_) {
184 DisplayEvent event = event_queue_.front(); 211 DisplayEvent event = event_queue_.front();
185 event_queue_.pop(); 212 event_queue_.pop();
186 VLOG(1) << "Got display event " << kDisplayActionString[event.action_type] 213 VLOG(1) << "Got display event " << kDisplayActionString[event.action_type]
187 << " for " << event.path.value(); 214 << " for " << event.path.value();
188 switch (event.action_type) { 215 switch (event.action_type) {
189 case DeviceEvent::ADD: 216 case DeviceEvent::ADD:
217 if (event.path == vgem_card_path_)
218 continue;
190 if (drm_devices_.find(event.path) == drm_devices_.end()) { 219 if (drm_devices_.find(event.path) == drm_devices_.end()) {
191 task_pending_ = base::WorkerPool::PostTask( 220 task_pending_ = base::WorkerPool::PostTask(
192 FROM_HERE, 221 FROM_HERE,
193 base::Bind(&OpenDeviceOnWorkerThread, event.path, 222 base::Bind(&OpenDeviceOnWorkerThread, event.path,
194 base::ThreadTaskRunnerHandle::Get(), 223 base::ThreadTaskRunnerHandle::Get(),
195 base::Bind(&DrmDisplayHostManager::OnAddGraphicsDevice, 224 base::Bind(&DrmDisplayHostManager::OnAddGraphicsDevice,
196 weak_ptr_factory_.GetWeakPtr())), 225 weak_ptr_factory_.GetWeakPtr())),
197 false /* task_is_slow */); 226 false /* task_is_slow */);
198 } 227 }
199 break; 228 break;
200 case DeviceEvent::CHANGE: 229 case DeviceEvent::CHANGE:
201 task_pending_ = base::ThreadTaskRunnerHandle::Get()->PostTask( 230 task_pending_ = base::ThreadTaskRunnerHandle::Get()->PostTask(
202 FROM_HERE, 231 FROM_HERE,
203 base::Bind(&DrmDisplayHostManager::OnUpdateGraphicsDevice, 232 base::Bind(&DrmDisplayHostManager::OnUpdateGraphicsDevice,
204 weak_ptr_factory_.GetWeakPtr())); 233 weak_ptr_factory_.GetWeakPtr()));
205 break; 234 break;
206 case DeviceEvent::REMOVE: 235 case DeviceEvent::REMOVE:
207 DCHECK(event.path != primary_graphics_card_path_) 236 DCHECK(event.path != primary_graphics_card_path_)
208 << "Removing primary graphics card"; 237 << "Removing primary graphics card";
238 DCHECK(event.path != vgem_card_path_) << "Removing VGEM device";
209 auto it = drm_devices_.find(event.path); 239 auto it = drm_devices_.find(event.path);
210 if (it != drm_devices_.end()) { 240 if (it != drm_devices_.end()) {
211 task_pending_ = base::ThreadTaskRunnerHandle::Get()->PostTask( 241 task_pending_ = base::ThreadTaskRunnerHandle::Get()->PostTask(
212 FROM_HERE, 242 FROM_HERE,
213 base::Bind(&DrmDisplayHostManager::OnRemoveGraphicsDevice, 243 base::Bind(&DrmDisplayHostManager::OnRemoveGraphicsDevice,
214 weak_ptr_factory_.GetWeakPtr(), event.path)); 244 weak_ptr_factory_.GetWeakPtr(), event.path));
215 drm_devices_.erase(it); 245 drm_devices_.erase(it);
216 } 246 }
217 break; 247 break;
218 } 248 }
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 390
361 callback.Run(snapshots); 391 callback.Run(snapshots);
362 } 392 }
363 393
364 void DrmDisplayHostManager::NotifyDisplayDelegate() const { 394 void DrmDisplayHostManager::NotifyDisplayDelegate() const {
365 if (delegate_) 395 if (delegate_)
366 delegate_->OnConfigurationChanged(); 396 delegate_->OnConfigurationChanged();
367 } 397 }
368 398
369 } // namespace ui 399 } // namespace ui
OLDNEW
« no previous file with comments | « ui/ozone/platform/drm/host/drm_display_host_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698