Chromium Code Reviews| Index: ui/ozone/platform/dri/dri_util.cc |
| diff --git a/ui/ozone/platform/dri/dri_util.cc b/ui/ozone/platform/dri/dri_util.cc |
| index 5305f6d0b48f891031a158f9ea9814fca9ec5356..77230e561506e3c62b85d3971cdbd25c3b55204a 100644 |
| --- a/ui/ozone/platform/dri/dri_util.cc |
| +++ b/ui/ozone/platform/dri/dri_util.cc |
| @@ -2,9 +2,11 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| +#include "base/strings/stringprintf.h" |
| #include "ui/ozone/platform/dri/dri_util.h" |
| #include <errno.h> |
| +#include <fcntl.h> |
| #include <stdint.h> |
| #include <stdlib.h> |
| #include <sys/mman.h> |
| @@ -15,6 +17,8 @@ namespace ui { |
| namespace { |
| +const char kDefaultGraphicsCardPattern[] = "/dev/dri/card%d"; |
| + |
| bool IsCrtcInUse(uint32_t crtc, |
| const ScopedVector<HardwareDisplayControllerInfo>& displays) { |
| for (size_t i = 0; i < displays.size(); ++i) { |
| @@ -135,4 +139,28 @@ bool MapDumbBuffer(int fd, |
| return true; |
| } |
| +int OpenFirstDisplayCard() { |
| + struct drm_mode_card_res res; |
| + for (int i = 0; /* end on first card# that does not exist */; i++) { |
| + std::string card_path = base::StringPrintf(kDefaultGraphicsCardPattern, i); |
| + |
| + if (access(card_path.c_str(), F_OK) != 0) |
| + break; |
| + |
| + int fd = open(card_path.c_str(), O_RDWR | O_CLOEXEC); |
| + if (fd < 0) |
| + continue; |
| + |
| + memset(&res, 0, sizeof(struct drm_mode_card_res)); |
| + int ret = drmIoctl(fd, DRM_IOCTL_MODE_GETRESOURCES, &res); |
|
marcheu
2015/02/13 04:34:42
I'm going to nitpick. In some cases, we can have a
Zach Reizner
2015/02/13 18:45:15
I agree.
|
| + if (ret == 0) { |
| + return fd; |
| + } |
| + |
| + close(fd); |
| + } |
| + |
| + return -1; |
| +} |
| + |
| } // namespace ui |