OLD | NEW |
---|---|
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_native_display_delegate.h" | 5 #include "ui/ozone/platform/drm/host/drm_native_display_delegate.h" |
6 | 6 |
7 #include <stdio.h> | 7 #include <stdio.h> |
8 #include <xf86drm.h> | |
8 | 9 |
9 #include "base/logging.h" | 10 #include "base/logging.h" |
10 #include "base/thread_task_runner_handle.h" | 11 #include "base/thread_task_runner_handle.h" |
11 #include "base/threading/sequenced_worker_pool.h" | 12 #include "base/threading/sequenced_worker_pool.h" |
12 #include "base/threading/thread_restrictions.h" | 13 #include "base/threading/thread_restrictions.h" |
13 #include "ui/display/types/display_snapshot.h" | 14 #include "ui/display/types/display_snapshot.h" |
14 #include "ui/display/types/native_display_observer.h" | 15 #include "ui/display/types/native_display_observer.h" |
15 #include "ui/events/ozone/device/device_event.h" | 16 #include "ui/events/ozone/device/device_event.h" |
16 #include "ui/events/ozone/device/device_manager.h" | 17 #include "ui/events/ozone/device/device_manager.h" |
17 #include "ui/ozone/common/display_snapshot_proxy.h" | 18 #include "ui/ozone/common/display_snapshot_proxy.h" |
18 #include "ui/ozone/common/display_util.h" | 19 #include "ui/ozone/common/display_util.h" |
19 #include "ui/ozone/common/gpu/ozone_gpu_messages.h" | 20 #include "ui/ozone/common/gpu/ozone_gpu_messages.h" |
20 #include "ui/ozone/platform/drm/host/display_manager.h" | 21 #include "ui/ozone/platform/drm/host/display_manager.h" |
21 #include "ui/ozone/platform/drm/host/drm_gpu_platform_support_host.h" | 22 #include "ui/ozone/platform/drm/host/drm_gpu_platform_support_host.h" |
22 | 23 |
23 namespace ui { | 24 namespace ui { |
24 | 25 |
25 namespace { | 26 namespace { |
26 | 27 |
27 typedef base::Callback<void(const base::FilePath&, base::File)> | 28 typedef base::Callback<void(const base::FilePath&, base::File)> |
28 OnOpenDeviceReplyCallback; | 29 OnOpenDeviceReplyCallback; |
29 | 30 |
30 const char* kDisplayActionString[] = { | 31 const char* kDisplayActionString[] = { |
31 "ADD", | 32 "ADD", |
32 "REMOVE", | 33 "REMOVE", |
33 "CHANGE", | 34 "CHANGE", |
34 }; | 35 }; |
35 | 36 |
37 bool IsAuthenticated(int fd) { | |
spang
2015/04/22 18:50:58
A function called IsBlah() should not have side ef
dnicoara
2015/04/22 19:10:01
Done.
| |
38 drm_magic_t magic; | |
39 memset(&magic, 0, sizeof(magic)); | |
spang
2015/04/22 18:50:58
Seems like you can do "= 0;" instead of memset..
dnicoara
2015/04/22 19:10:01
Done.
| |
40 // We need to make sure the DRM device has enough privilege. Use the DRM | |
41 // authentication logic to figure out if the device has enough permissions. | |
42 return !drmGetMagic(fd, &magic) && !drmAuthMagic(fd, magic); | |
43 } | |
44 | |
36 base::File OpenDrmDevice(const base::FilePath& path) { | 45 base::File OpenDrmDevice(const base::FilePath& path) { |
37 base::File file(path, base::File::FLAG_OPEN | base::File::FLAG_READ | | 46 base::File file; |
38 base::File::FLAG_WRITE); | 47 bool print_warning = true; |
48 while (true) { | |
49 file = base::File(path, base::File::FLAG_OPEN | base::File::FLAG_READ | | |
50 base::File::FLAG_WRITE); | |
39 | 51 |
40 base::File::Info info; | 52 base::File::Info info; |
41 file.GetInfo(&info); | 53 file.GetInfo(&info); |
42 | 54 |
43 CHECK(!info.is_directory); | 55 CHECK(!info.is_directory); |
44 CHECK(path.DirName() == base::FilePath("/dev/dri")); | 56 CHECK(path.DirName() == base::FilePath("/dev/dri")); |
45 | 57 |
46 if (!file.IsValid()) { | 58 if (!file.IsValid()) { |
47 LOG(ERROR) << "Failed to open " << path.value() << ": " | 59 LOG(ERROR) << "Failed to open " << path.value() << ": " |
48 << base::File::ErrorToString(file.error_details()); | 60 << base::File::ErrorToString(file.error_details()); |
61 return file.Pass(); | |
62 } | |
63 | |
64 break; | |
spang
2015/04/22 18:50:58
??
dnicoara
2015/04/22 19:10:01
Oops, removed.
| |
65 if (IsAuthenticated(file.GetPlatformFile())) | |
66 break; | |
67 | |
68 LOG_IF(WARNING, print_warning) << "Failed to authenticate " << path.value(); | |
69 | |
70 print_warning = false; | |
71 usleep(100000); | |
49 } | 72 } |
50 | 73 |
74 VLOG(1) << "Succeeded authenticating " << path.value(); | |
51 return file.Pass(); | 75 return file.Pass(); |
52 } | 76 } |
53 | 77 |
54 void OpenDeviceOnWorkerThread( | 78 void OpenDeviceOnWorkerThread( |
55 const base::FilePath& path, | 79 const base::FilePath& path, |
56 const scoped_refptr<base::TaskRunner>& reply_runner, | 80 const scoped_refptr<base::TaskRunner>& reply_runner, |
57 const OnOpenDeviceReplyCallback& callback) { | 81 const OnOpenDeviceReplyCallback& callback) { |
58 base::File file = OpenDrmDevice(path); | 82 base::File file = OpenDrmDevice(path); |
59 reply_runner->PostTask(FROM_HERE, | 83 reply_runner->PostTask(FROM_HERE, |
60 base::Bind(callback, path, base::Passed(file.Pass()))); | 84 base::Bind(callback, path, base::Passed(file.Pass()))); |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
308 FOR_EACH_OBSERVER(NativeDisplayObserver, observers_, | 332 FOR_EACH_OBSERVER(NativeDisplayObserver, observers_, |
309 OnConfigurationChanged()); | 333 OnConfigurationChanged()); |
310 } | 334 } |
311 | 335 |
312 void DrmNativeDisplayDelegate::OnChannelEstablished( | 336 void DrmNativeDisplayDelegate::OnChannelEstablished( |
313 int host_id, | 337 int host_id, |
314 scoped_refptr<base::SingleThreadTaskRunner> send_runner, | 338 scoped_refptr<base::SingleThreadTaskRunner> send_runner, |
315 const base::Callback<void(IPC::Message*)>& send_callback) { | 339 const base::Callback<void(IPC::Message*)>& send_callback) { |
316 drm_devices_.clear(); | 340 drm_devices_.clear(); |
317 drm_devices_.insert(primary_graphics_card_path_); | 341 drm_devices_.insert(primary_graphics_card_path_); |
342 { | |
343 // First device needs to be treated specially. We need to open this | |
344 // synchronously since the GPU process will need it to initialize the | |
345 // graphics state. | |
spang
2015/04/22 18:50:58
How does sync open in the browser help the GPU pro
dnicoara
2015/04/22 19:10:01
The UI thread creates a window right away which cr
| |
346 base::ThreadRestrictions::ScopedAllowIO allow_io; | |
347 base::File file = OpenDrmDevice(primary_graphics_card_path_); | |
348 if (!file.IsValid()) { | |
349 LOG(FATAL) << "Failed to open primary graphics card"; | |
350 return; | |
351 } | |
352 OnAddGraphicsDevice(primary_graphics_card_path_, file.Pass()); | |
353 } | |
354 | |
318 device_manager_->ScanDevices(this); | 355 device_manager_->ScanDevices(this); |
319 FOR_EACH_OBSERVER(NativeDisplayObserver, observers_, | 356 FOR_EACH_OBSERVER(NativeDisplayObserver, observers_, |
320 OnConfigurationChanged()); | 357 OnConfigurationChanged()); |
321 } | 358 } |
322 | 359 |
323 void DrmNativeDisplayDelegate::OnChannelDestroyed(int host_id) { | 360 void DrmNativeDisplayDelegate::OnChannelDestroyed(int host_id) { |
324 // If the channel got destroyed in the middle of a configuration then just | 361 // If the channel got destroyed in the middle of a configuration then just |
325 // respond with failure. | 362 // respond with failure. |
326 if (!get_displays_callback_.is_null()) { | 363 if (!get_displays_callback_.is_null()) { |
327 base::ThreadTaskRunnerHandle::Get()->PostTask( | 364 base::ThreadTaskRunnerHandle::Get()->PostTask( |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
376 configure_callback_map_.erase(it); | 413 configure_callback_map_.erase(it); |
377 } | 414 } |
378 } | 415 } |
379 | 416 |
380 void DrmNativeDisplayDelegate::RunUpdateDisplaysCallback( | 417 void DrmNativeDisplayDelegate::RunUpdateDisplaysCallback( |
381 const GetDisplaysCallback& callback) const { | 418 const GetDisplaysCallback& callback) const { |
382 callback.Run(displays_.get()); | 419 callback.Run(displays_.get()); |
383 } | 420 } |
384 | 421 |
385 } // namespace ui | 422 } // namespace ui |
OLD | NEW |