| 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 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 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 FOR_EACH_OBSERVER(NativeDisplayObserver, observers_, | 330 FOR_EACH_OBSERVER(NativeDisplayObserver, observers_, |
| 309 OnConfigurationChanged()); | 331 OnConfigurationChanged()); |
| 310 } | 332 } |
| 311 | 333 |
| 312 void DrmNativeDisplayDelegate::OnChannelEstablished( | 334 void DrmNativeDisplayDelegate::OnChannelEstablished( |
| 313 int host_id, | 335 int host_id, |
| 314 scoped_refptr<base::SingleThreadTaskRunner> send_runner, | 336 scoped_refptr<base::SingleThreadTaskRunner> send_runner, |
| 315 const base::Callback<void(IPC::Message*)>& send_callback) { | 337 const base::Callback<void(IPC::Message*)>& send_callback) { |
| 316 drm_devices_.clear(); | 338 drm_devices_.clear(); |
| 317 drm_devices_.insert(primary_graphics_card_path_); | 339 drm_devices_.insert(primary_graphics_card_path_); |
| 340 { |
| 341 // First device needs to be treated specially. We need to open this |
| 342 // synchronously since the GPU process will need it to initialize the |
| 343 // graphics state. |
| 344 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 345 base::File file = OpenDrmDevice(primary_graphics_card_path_); |
| 346 if (!file.IsValid()) { |
| 347 LOG(FATAL) << "Failed to open primary graphics card"; |
| 348 return; |
| 349 } |
| 350 OnAddGraphicsDevice(primary_graphics_card_path_, file.Pass()); |
| 351 } |
| 352 |
| 318 device_manager_->ScanDevices(this); | 353 device_manager_->ScanDevices(this); |
| 319 FOR_EACH_OBSERVER(NativeDisplayObserver, observers_, | 354 FOR_EACH_OBSERVER(NativeDisplayObserver, observers_, |
| 320 OnConfigurationChanged()); | 355 OnConfigurationChanged()); |
| 321 } | 356 } |
| 322 | 357 |
| 323 void DrmNativeDisplayDelegate::OnChannelDestroyed(int host_id) { | 358 void DrmNativeDisplayDelegate::OnChannelDestroyed(int host_id) { |
| 324 // If the channel got destroyed in the middle of a configuration then just | 359 // If the channel got destroyed in the middle of a configuration then just |
| 325 // respond with failure. | 360 // respond with failure. |
| 326 if (!get_displays_callback_.is_null()) { | 361 if (!get_displays_callback_.is_null()) { |
| 327 base::ThreadTaskRunnerHandle::Get()->PostTask( | 362 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 configure_callback_map_.erase(it); | 411 configure_callback_map_.erase(it); |
| 377 } | 412 } |
| 378 } | 413 } |
| 379 | 414 |
| 380 void DrmNativeDisplayDelegate::RunUpdateDisplaysCallback( | 415 void DrmNativeDisplayDelegate::RunUpdateDisplaysCallback( |
| 381 const GetDisplaysCallback& callback) const { | 416 const GetDisplaysCallback& callback) const { |
| 382 callback.Run(displays_.get()); | 417 callback.Run(displays_.get()); |
| 383 } | 418 } |
| 384 | 419 |
| 385 } // namespace ui | 420 } // namespace ui |
| OLD | NEW |