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 39c1501e2e75caa40116951eb0d9dbea1f647946..dee846117c4b8ec5b5169fe522370064b4a192bc 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> |
@@ -18,6 +20,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) { |
@@ -161,4 +165,27 @@ void ForceInitializationOfPrimaryDisplay(const scoped_refptr<DriWrapper>& drm, |
} |
} |
+base::FilePath GetFirstDisplayCardPath() { |
+ 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); |
+ close(fd); |
+ if (ret == 0 && res.count_crtcs > 0) { |
+ return base::FilePath(card_path); |
+ } |
+ } |
+ |
+ return base::FilePath(); |
+} |
+ |
} // namespace ui |