Chromium Code Reviews| Index: ui/ozone/platform/drm/host/drm_device_handle.cc |
| diff --git a/ui/ozone/platform/drm/host/drm_device_handle.cc b/ui/ozone/platform/drm/host/drm_device_handle.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..15a4908d4b96bb320965bdd755ceea9855521c2d |
| --- /dev/null |
| +++ b/ui/ozone/platform/drm/host/drm_device_handle.cc |
| @@ -0,0 +1,75 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "ui/ozone/platform/drm/host/drm_device_handle.h" |
| + |
| +#include <xf86drm.h> |
| +#include <xf86drmMode.h> |
| + |
| +#include "base/files/file_path.h" |
| + |
| +namespace ui { |
| + |
| +namespace { |
| + |
| +bool Authenticate(int fd) { |
| + drm_magic_t magic; |
| + memset(&magic, 0, sizeof(magic)); |
| + // We need to make sure the DRM device has enough privilege. Use the DRM |
| + // authentication logic to figure out if the device has enough permissions. |
| + return !drmGetMagic(fd, &magic) && !drmAuthMagic(fd, magic); |
| +} |
| + |
| +} // namespace |
| + |
| +DrmDeviceHandle::DrmDeviceHandle() { |
| +} |
| + |
| +DrmDeviceHandle::~DrmDeviceHandle() { |
| +} |
| + |
| +bool DrmDeviceHandle::Initialize(const base::FilePath& path) { |
| + bool print_warning = true; |
| + while (true) { |
| + 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.
|
| + base::File::FLAG_WRITE); |
| + |
| + base::File::Info info; |
| + file_.GetInfo(&info); |
| + |
| + CHECK(!info.is_directory); |
| + CHECK(path.DirName() == base::FilePath("/dev/dri")); |
| + |
| + if (!file_.IsValid()) { |
| + LOG(ERROR) << "Failed to open " << path.value() << ": " |
| + << base::File::ErrorToString(file_.error_details()); |
| + return false; |
| + } |
| + |
| + if (Authenticate(file_.GetPlatformFile())) |
| + break; |
| + |
| + LOG_IF(WARNING, print_warning) << "Failed to authenticate " << path.value(); |
| + print_warning = false; |
| + usleep(100000); |
| + } |
| + |
| + VLOG(1) << "Succeeded authenticating " << path.value(); |
| + return true; |
| +} |
| + |
| +void DrmDeviceHandle::Shutdown() { |
| + file_.Close(); |
| +} |
| + |
| +bool DrmDeviceHandle::IsValid() const { |
| + return file_.IsValid(); |
| +} |
| + |
| +base::File DrmDeviceHandle::DuplicateFile() { |
| + DCHECK(file_.IsValid()); |
| + return file_.Duplicate(); |
| +} |
| + |
| +} // namespace ui |