Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(832)

Unified Diff: ui/ozone/platform/dri/dri_util.cc

Issue 913273006: ozone: choose a card useful for display rather than by default (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/ozone/platform/dri/dri_util.h ('k') | ui/ozone/platform/dri/ozone_platform_dri.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « ui/ozone/platform/dri/dri_util.h ('k') | ui/ozone/platform/dri/ozone_platform_dri.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698