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

Side by Side Diff: ui/ozone/platform/dri/native_display_delegate_proxy.cc

Issue 905873003: [8/8][Ozone-Dri] Pass DRM FD to GPU process on hotplug event (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@udl2.9-allow-ndd-to-handle-multiple-drm-devices
Patch Set: Rebased Created 5 years, 10 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/dri/native_display_delegate_proxy.h" 5 #include "ui/ozone/platform/dri/native_display_delegate_proxy.h"
6 6
7 #include <stdio.h> 7 #include <stdio.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/thread_task_runner_handle.h"
10 #include "base/threading/thread_restrictions.h" 11 #include "base/threading/thread_restrictions.h"
12 #include "base/threading/worker_pool.h"
11 #include "ui/display/types/display_snapshot.h" 13 #include "ui/display/types/display_snapshot.h"
12 #include "ui/display/types/native_display_observer.h" 14 #include "ui/display/types/native_display_observer.h"
13 #include "ui/events/ozone/device/device_event.h" 15 #include "ui/events/ozone/device/device_event.h"
14 #include "ui/events/ozone/device/device_manager.h" 16 #include "ui/events/ozone/device/device_manager.h"
15 #include "ui/ozone/common/display_snapshot_proxy.h" 17 #include "ui/ozone/common/display_snapshot_proxy.h"
16 #include "ui/ozone/common/display_util.h" 18 #include "ui/ozone/common/display_util.h"
17 #include "ui/ozone/common/gpu/ozone_gpu_messages.h" 19 #include "ui/ozone/common/gpu/ozone_gpu_messages.h"
18 #include "ui/ozone/platform/dri/display_manager.h" 20 #include "ui/ozone/platform/dri/display_manager.h"
19 #include "ui/ozone/platform/dri/dri_gpu_platform_support_host.h" 21 #include "ui/ozone/platform/dri/dri_gpu_platform_support_host.h"
20 22
21 namespace ui { 23 namespace ui {
22 24
23 namespace { 25 namespace {
24 26
27 const char kDefaultGraphicsCardPath[] = "/dev/dri/card0";
spang 2015/02/11 21:13:21 When do we get to remove this?
dnicoara 2015/02/11 22:21:14 I left a comment in NDDProxy::OnDeviceEvent() on t
28
29 typedef base::Callback<void(const base::FilePath&, base::File)>
30 OnOpenDeviceReplyCallback;
31
32 void OpenDeviceOnWorkerThread(
33 const base::FilePath& path,
34 const scoped_refptr<base::TaskRunner>& reply_runner,
35 const OnOpenDeviceReplyCallback& callback) {
36 base::File file(path, base::File::FLAG_OPEN | base::File::FLAG_READ |
37 base::File::FLAG_WRITE);
38
39 if (file.IsValid()) {
40 reply_runner->PostTask(
41 FROM_HERE, base::Bind(callback, path, base::Passed(file.Pass())));
42 }
43 }
44
25 class DriDisplaySnapshotProxy : public DisplaySnapshotProxy { 45 class DriDisplaySnapshotProxy : public DisplaySnapshotProxy {
26 public: 46 public:
27 DriDisplaySnapshotProxy(const DisplaySnapshot_Params& params, 47 DriDisplaySnapshotProxy(const DisplaySnapshot_Params& params,
28 DisplayManager* display_manager) 48 DisplayManager* display_manager)
29 : DisplaySnapshotProxy(params), display_manager_(display_manager) { 49 : DisplaySnapshotProxy(params), display_manager_(display_manager) {
30 display_manager_->RegisterDisplay(this); 50 display_manager_->RegisterDisplay(this);
31 } 51 }
32 52
33 ~DriDisplaySnapshotProxy() override { 53 ~DriDisplaySnapshotProxy() override {
34 display_manager_->UnregisterDisplay(this); 54 display_manager_->UnregisterDisplay(this);
35 } 55 }
36 56
37 private: 57 private:
38 DisplayManager* display_manager_; // Not owned. 58 DisplayManager* display_manager_; // Not owned.
39 59
40 DISALLOW_COPY_AND_ASSIGN(DriDisplaySnapshotProxy); 60 DISALLOW_COPY_AND_ASSIGN(DriDisplaySnapshotProxy);
41 }; 61 };
42 62
43 } // namespace 63 } // namespace
44 64
45 NativeDisplayDelegateProxy::NativeDisplayDelegateProxy( 65 NativeDisplayDelegateProxy::NativeDisplayDelegateProxy(
46 DriGpuPlatformSupportHost* proxy, 66 DriGpuPlatformSupportHost* proxy,
47 DeviceManager* device_manager, 67 DeviceManager* device_manager,
48 DisplayManager* display_manager) 68 DisplayManager* display_manager)
49 : proxy_(proxy), 69 : proxy_(proxy),
50 device_manager_(device_manager), 70 device_manager_(device_manager),
51 display_manager_(display_manager), 71 display_manager_(display_manager),
52 has_dummy_display_(false) { 72 has_dummy_display_(false),
73 weak_ptr_factory_(this) {
53 proxy_->RegisterHandler(this); 74 proxy_->RegisterHandler(this);
54 } 75 }
55 76
56 NativeDisplayDelegateProxy::~NativeDisplayDelegateProxy() { 77 NativeDisplayDelegateProxy::~NativeDisplayDelegateProxy() {
57 device_manager_->RemoveObserver(this); 78 device_manager_->RemoveObserver(this);
58 proxy_->UnregisterHandler(this); 79 proxy_->UnregisterHandler(this);
59 } 80 }
60 81
61 void NativeDisplayDelegateProxy::Initialize() { 82 void NativeDisplayDelegateProxy::Initialize() {
62 device_manager_->AddObserver(this); 83 device_manager_->AddObserver(this);
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 observers_.RemoveObserver(observer); 209 observers_.RemoveObserver(observer);
189 } 210 }
190 211
191 void NativeDisplayDelegateProxy::OnDeviceEvent(const DeviceEvent& event) { 212 void NativeDisplayDelegateProxy::OnDeviceEvent(const DeviceEvent& event) {
192 if (event.device_type() != DeviceEvent::DISPLAY) 213 if (event.device_type() != DeviceEvent::DISPLAY)
193 return; 214 return;
194 215
195 switch (event.action_type()) { 216 switch (event.action_type()) {
196 case DeviceEvent::ADD: 217 case DeviceEvent::ADD:
197 VLOG(1) << "Got display added event for " << event.path().value(); 218 VLOG(1) << "Got display added event for " << event.path().value();
198 proxy_->Send(new OzoneGpuMsg_AddGraphicsDevice(event.path())); 219 // The default card is a special case since it needs to be opened early on
199 break; 220 // the GPU process in order to initialize EGL. If it is opened here as
221 // well, it will cause a race with opening it in the GPU process and the
222 // GPU process may fail initialization.
223 // TODO(dnicoara) Remove this when EGL_DEFAULT_DISPLAY is the only native
224 // display we return in GbmSurfaceFactory.
225 if (event.path().value() == kDefaultGraphicsCardPath)
226 return;
227
228 base::WorkerPool::PostTask(
229 FROM_HERE,
230 base::Bind(
231 &OpenDeviceOnWorkerThread, event.path(),
232 base::ThreadTaskRunnerHandle::Get(),
233 base::Bind(&NativeDisplayDelegateProxy::OnNewGraphicsDevice,
234 weak_ptr_factory_.GetWeakPtr())),
235 true /* task_is_slow */);
spang 2015/02/11 21:13:21 Apparently task_is_slow = false should be used unl
dnicoara 2015/02/11 22:21:14 Done.
236 return;
200 case DeviceEvent::CHANGE: 237 case DeviceEvent::CHANGE:
201 VLOG(1) << "Got display changed event for " << event.path().value(); 238 VLOG(1) << "Got display changed event for " << event.path().value();
202 break; 239 break;
203 case DeviceEvent::REMOVE: 240 case DeviceEvent::REMOVE:
204 VLOG(1) << "Got display removed event for " << event.path().value(); 241 VLOG(1) << "Got display removed event for " << event.path().value();
242 // It shouldn't be possible to remove this device.
243 DCHECK_NE(kDefaultGraphicsCardPath, event.path().value());
205 proxy_->Send(new OzoneGpuMsg_RemoveGraphicsDevice(event.path())); 244 proxy_->Send(new OzoneGpuMsg_RemoveGraphicsDevice(event.path()));
206 break; 245 break;
207 } 246 }
208 247
209 FOR_EACH_OBSERVER(NativeDisplayObserver, observers_, 248 FOR_EACH_OBSERVER(NativeDisplayObserver, observers_,
210 OnConfigurationChanged()); 249 OnConfigurationChanged());
211 } 250 }
212 251
252 void NativeDisplayDelegateProxy::OnNewGraphicsDevice(const base::FilePath& path,
253 base::File file) {
254 DCHECK(file.IsValid());
255 proxy_->Send(new OzoneGpuMsg_AddGraphicsDevice(
256 path, base::FileDescriptor(file.Pass())));
257
258 FOR_EACH_OBSERVER(NativeDisplayObserver, observers_,
259 OnConfigurationChanged());
260 }
261
213 void NativeDisplayDelegateProxy::OnChannelEstablished( 262 void NativeDisplayDelegateProxy::OnChannelEstablished(
214 int host_id, 263 int host_id,
215 scoped_refptr<base::SingleThreadTaskRunner> send_runner, 264 scoped_refptr<base::SingleThreadTaskRunner> send_runner,
216 const base::Callback<void(IPC::Message*)>& send_callback) { 265 const base::Callback<void(IPC::Message*)>& send_callback) {
266 device_manager_->ScanDevices(this);
217 FOR_EACH_OBSERVER(NativeDisplayObserver, observers_, 267 FOR_EACH_OBSERVER(NativeDisplayObserver, observers_,
218 OnConfigurationChanged()); 268 OnConfigurationChanged());
219 } 269 }
220 270
221 void NativeDisplayDelegateProxy::OnChannelDestroyed(int host_id) { 271 void NativeDisplayDelegateProxy::OnChannelDestroyed(int host_id) {
222 // If the channel got destroyed in the middle of a configuration then just 272 // If the channel got destroyed in the middle of a configuration then just
223 // respond with failure. 273 // respond with failure.
224 if (!get_displays_callback_.is_null()) { 274 if (!get_displays_callback_.is_null()) {
225 get_displays_callback_.Run(std::vector<DisplaySnapshot*>()); 275 get_displays_callback_.Run(std::vector<DisplaySnapshot*>());
226 get_displays_callback_.Reset(); 276 get_displays_callback_.Reset();
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 void NativeDisplayDelegateProxy::OnDisplayConfigured(int64_t display_id, 313 void NativeDisplayDelegateProxy::OnDisplayConfigured(int64_t display_id,
264 bool status) { 314 bool status) {
265 auto it = configure_callback_map_.find(display_id); 315 auto it = configure_callback_map_.find(display_id);
266 if (it != configure_callback_map_.end()) { 316 if (it != configure_callback_map_.end()) {
267 it->second.Run(status); 317 it->second.Run(status);
268 configure_callback_map_.erase(it); 318 configure_callback_map_.erase(it);
269 } 319 }
270 } 320 }
271 321
272 } // namespace ui 322 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698