Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ui/ozone/platform/drm/host/drm_device_handle.h" | |
| 6 | |
| 7 #include <xf86drm.h> | |
| 8 #include <xf86drmMode.h> | |
| 9 | |
| 10 #include "base/files/file_path.h" | |
| 11 | |
| 12 namespace ui { | |
| 13 | |
| 14 namespace { | |
| 15 | |
| 16 bool Authenticate(int fd) { | |
| 17 drm_magic_t magic; | |
| 18 memset(&magic, 0, sizeof(magic)); | |
| 19 // We need to make sure the DRM device has enough privilege. Use the DRM | |
| 20 // authentication logic to figure out if the device has enough permissions. | |
| 21 return !drmGetMagic(fd, &magic) && !drmAuthMagic(fd, magic); | |
| 22 } | |
| 23 | |
| 24 } // namespace | |
| 25 | |
| 26 DrmDeviceHandle::DrmDeviceHandle() { | |
| 27 } | |
| 28 | |
| 29 DrmDeviceHandle::~DrmDeviceHandle() { | |
| 30 } | |
| 31 | |
| 32 bool DrmDeviceHandle::Initialize(const base::FilePath& path) { | |
| 33 bool print_warning = true; | |
| 34 while (true) { | |
| 35 file_ = base::File(path, base::File::FLAG_OPEN | base::File::FLAG_READ | | |
|
spang
2015/04/27 22:23:15
The base::File abstraction provides little to no b
dnicoara
2015/04/28 16:26:15
Done.
| |
| 36 base::File::FLAG_WRITE); | |
| 37 | |
| 38 base::File::Info info; | |
| 39 file_.GetInfo(&info); | |
| 40 | |
| 41 CHECK(!info.is_directory); | |
| 42 CHECK(path.DirName() == base::FilePath("/dev/dri")); | |
| 43 | |
| 44 if (!file_.IsValid()) { | |
| 45 LOG(ERROR) << "Failed to open " << path.value() << ": " | |
| 46 << base::File::ErrorToString(file_.error_details()); | |
| 47 return false; | |
| 48 } | |
| 49 | |
| 50 if (Authenticate(file_.GetPlatformFile())) | |
| 51 break; | |
| 52 | |
| 53 LOG_IF(WARNING, print_warning) << "Failed to authenticate " << path.value(); | |
| 54 print_warning = false; | |
| 55 usleep(100000); | |
| 56 } | |
| 57 | |
| 58 VLOG(1) << "Succeeded authenticating " << path.value(); | |
| 59 return true; | |
| 60 } | |
| 61 | |
| 62 void DrmDeviceHandle::Shutdown() { | |
| 63 file_.Close(); | |
| 64 } | |
| 65 | |
| 66 bool DrmDeviceHandle::IsValid() const { | |
| 67 return file_.IsValid(); | |
| 68 } | |
| 69 | |
| 70 base::File DrmDeviceHandle::DuplicateFile() { | |
| 71 DCHECK(file_.IsValid()); | |
| 72 return file_.Duplicate(); | |
| 73 } | |
| 74 | |
| 75 } // namespace ui | |
| OLD | NEW |