| 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/thread_restrictions.h" | 12 #include "base/threading/thread_restrictions.h" |
| 12 #include "base/threading/worker_pool.h" | 13 #include "base/threading/worker_pool.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 Authenticate(int fd) { |
| 38 drm_magic_t magic = 0; |
| 39 // We need to make sure the DRM device has enough privilege. Use the DRM |
| 40 // authentication logic to figure out if the device has enough permissions. |
| 41 return !drmGetMagic(fd, &magic) && !drmAuthMagic(fd, magic); |
| 42 } |
| 43 |
| 36 base::File OpenDrmDevice(const base::FilePath& path) { | 44 base::File OpenDrmDevice(const base::FilePath& path) { |
| 37 base::File file(path, base::File::FLAG_OPEN | base::File::FLAG_READ | | 45 base::File file; |
| 38 base::File::FLAG_WRITE); | 46 bool print_warning = true; |
| 47 while (true) { |
| 48 file = base::File(path, base::File::FLAG_OPEN | base::File::FLAG_READ | |
| 49 base::File::FLAG_WRITE); |
| 39 | 50 |
| 40 base::File::Info info; | 51 base::File::Info info; |
| 41 file.GetInfo(&info); | 52 file.GetInfo(&info); |
| 42 | 53 |
| 43 CHECK(!info.is_directory); | 54 CHECK(!info.is_directory); |
| 44 CHECK(path.DirName() == base::FilePath("/dev/dri")); | 55 CHECK(path.DirName() == base::FilePath("/dev/dri")); |
| 45 | 56 |
| 46 if (!file.IsValid()) { | 57 if (!file.IsValid()) { |
| 47 LOG(ERROR) << "Failed to open " << path.value() << ": " | 58 LOG(ERROR) << "Failed to open " << path.value() << ": " |
| 48 << base::File::ErrorToString(file.error_details()); | 59 << base::File::ErrorToString(file.error_details()); |
| 60 return file.Pass(); |
| 61 } |
| 62 |
| 63 if (Authenticate(file.GetPlatformFile())) |
| 64 break; |
| 65 |
| 66 LOG_IF(WARNING, print_warning) << "Failed to authenticate " << path.value(); |
| 67 |
| 68 print_warning = false; |
| 69 usleep(100000); |
| 49 } | 70 } |
| 50 | 71 |
| 72 VLOG(1) << "Succeeded authenticating " << path.value(); |
| 51 return file.Pass(); | 73 return file.Pass(); |
| 52 } | 74 } |
| 53 | 75 |
| 54 void OpenDeviceOnWorkerThread( | 76 void OpenDeviceOnWorkerThread( |
| 55 const base::FilePath& path, | 77 const base::FilePath& path, |
| 56 const scoped_refptr<base::TaskRunner>& reply_runner, | 78 const scoped_refptr<base::TaskRunner>& reply_runner, |
| 57 const OnOpenDeviceReplyCallback& callback) { | 79 const OnOpenDeviceReplyCallback& callback) { |
| 58 base::File file = OpenDrmDevice(path); | 80 base::File file = OpenDrmDevice(path); |
| 59 reply_runner->PostTask(FROM_HERE, | 81 reply_runner->PostTask(FROM_HERE, |
| 60 base::Bind(callback, path, base::Passed(file.Pass()))); | 82 base::Bind(callback, path, base::Passed(file.Pass()))); |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 event_queue_.pop(); | 343 event_queue_.pop(); |
| 322 ProcessEvent(); | 344 ProcessEvent(); |
| 323 } | 345 } |
| 324 | 346 |
| 325 void DrmNativeDisplayDelegate::OnChannelEstablished( | 347 void DrmNativeDisplayDelegate::OnChannelEstablished( |
| 326 int host_id, | 348 int host_id, |
| 327 scoped_refptr<base::SingleThreadTaskRunner> send_runner, | 349 scoped_refptr<base::SingleThreadTaskRunner> send_runner, |
| 328 const base::Callback<void(IPC::Message*)>& send_callback) { | 350 const base::Callback<void(IPC::Message*)>& send_callback) { |
| 329 drm_devices_.clear(); | 351 drm_devices_.clear(); |
| 330 drm_devices_.insert(primary_graphics_card_path_); | 352 drm_devices_.insert(primary_graphics_card_path_); |
| 353 { |
| 354 // First device needs to be treated specially. We need to open this |
| 355 // synchronously since the GPU process will need it to initialize the |
| 356 // graphics state. |
| 357 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 358 base::File file = OpenDrmDevice(primary_graphics_card_path_); |
| 359 if (!file.IsValid()) { |
| 360 LOG(FATAL) << "Failed to open primary graphics card"; |
| 361 return; |
| 362 } |
| 363 proxy_->Send(new OzoneGpuMsg_AddGraphicsDevice( |
| 364 primary_graphics_card_path_, base::FileDescriptor(file.Pass()))); |
| 365 } |
| 366 |
| 331 device_manager_->ScanDevices(this); | 367 device_manager_->ScanDevices(this); |
| 332 FOR_EACH_OBSERVER(NativeDisplayObserver, observers_, | 368 FOR_EACH_OBSERVER(NativeDisplayObserver, observers_, |
| 333 OnConfigurationChanged()); | 369 OnConfigurationChanged()); |
| 334 } | 370 } |
| 335 | 371 |
| 336 void DrmNativeDisplayDelegate::OnChannelDestroyed(int host_id) { | 372 void DrmNativeDisplayDelegate::OnChannelDestroyed(int host_id) { |
| 337 // If the channel got destroyed in the middle of a configuration then just | 373 // If the channel got destroyed in the middle of a configuration then just |
| 338 // respond with failure. | 374 // respond with failure. |
| 339 if (!get_displays_callback_.is_null()) { | 375 if (!get_displays_callback_.is_null()) { |
| 340 base::ThreadTaskRunnerHandle::Get()->PostTask( | 376 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 set_hdcp_state_callback_map_.erase(it); | 448 set_hdcp_state_callback_map_.erase(it); |
| 413 } | 449 } |
| 414 } | 450 } |
| 415 | 451 |
| 416 void DrmNativeDisplayDelegate::RunUpdateDisplaysCallback( | 452 void DrmNativeDisplayDelegate::RunUpdateDisplaysCallback( |
| 417 const GetDisplaysCallback& callback) const { | 453 const GetDisplaysCallback& callback) const { |
| 418 callback.Run(displays_.get()); | 454 callback.Run(displays_.get()); |
| 419 } | 455 } |
| 420 | 456 |
| 421 } // namespace ui | 457 } // namespace ui |
| OLD | NEW |