mirror of
https://github.com/X11Libre/xf86-video-intel.git
synced 2026-03-24 01:24:12 +00:00
tools: Add rudimentary dri3info
A simple tool just to check if the target Xserver offers dri3. Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
This commit is contained in:
3
tools/.gitignore
vendored
3
tools/.gitignore
vendored
@@ -1,3 +1,4 @@
|
||||
dri3info
|
||||
intel-virtual-output
|
||||
xf86-video-intel-backlight-helper
|
||||
org.x.xf86-video-intel.backlight-helper.policy
|
||||
xf86-video-intel-backlight-helper
|
||||
|
||||
@@ -31,6 +31,12 @@ bin_PROGRAMS = intel-virtual-output
|
||||
driverman_DATA = intel-virtual-output.$(DRIVER_MAN_SUFFIX)
|
||||
endif
|
||||
|
||||
if X11_DRI3
|
||||
noinst_PROGRAMS = dri3info
|
||||
dri3info_SOURCES = dri3info.c
|
||||
dri3info_LDADD = $(X11_DRI3_LIBS)
|
||||
endif
|
||||
|
||||
if BUILD_BACKLIGHT_HELPER
|
||||
libexec_PROGRAMS = xf86-video-intel-backlight-helper
|
||||
nodist_policy_DATA = org.x.xf86-video-intel.backlight-helper.policy
|
||||
|
||||
115
tools/dri3info.c
Normal file
115
tools/dri3info.c
Normal file
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
* Copyright (c) 2015 Intel Corporation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xlib-xcb.h>
|
||||
#include <xcb/xcb.h>
|
||||
#include <xcb/dri3.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
static int dri3_open(Display *dpy)
|
||||
{
|
||||
xcb_connection_t *c = XGetXCBConnection(dpy);
|
||||
xcb_dri3_open_cookie_t cookie;
|
||||
xcb_dri3_open_reply_t *reply;
|
||||
|
||||
cookie = xcb_dri3_open(c, RootWindow(dpy, DefaultScreen(dpy)), None);
|
||||
reply = xcb_dri3_open_reply(c, cookie, NULL);
|
||||
|
||||
if (!reply)
|
||||
return -1;
|
||||
|
||||
if (reply->nfd != 1)
|
||||
return -1;
|
||||
|
||||
return xcb_dri3_open_reply_fds(c, reply)[0];
|
||||
}
|
||||
|
||||
static void match_device(int fd, char *buf, int len)
|
||||
{
|
||||
struct stat remote, local;
|
||||
int i;
|
||||
|
||||
if (fstat(fd, &remote))
|
||||
goto out;
|
||||
|
||||
for (i = 0; i < 64; i++) {
|
||||
snprintf(buf, len, "/dev/dri/card%d", i);
|
||||
if (stat(buf, &local))
|
||||
continue;
|
||||
|
||||
if (local.st_mode == remote.st_mode &&
|
||||
local.st_rdev == remote.st_rdev)
|
||||
return;
|
||||
}
|
||||
|
||||
out:
|
||||
strncpy(buf, "unknown card", len);
|
||||
}
|
||||
|
||||
static void info(const char *dpyname)
|
||||
{
|
||||
Display *dpy;
|
||||
int device;
|
||||
char device_name[1024];
|
||||
|
||||
dpy = XOpenDisplay(dpyname);
|
||||
if (dpy == NULL) {
|
||||
printf("Unable to connect to display '%s'\n",
|
||||
dpyname ?: getenv("DISPLAY") ?: "unset");
|
||||
return;
|
||||
}
|
||||
|
||||
device = dri3_open(dpy);
|
||||
if (device < 0) {
|
||||
printf("Unable to connect to DRI3 on display '%s'\n",
|
||||
DisplayString(dpy));
|
||||
return;
|
||||
}
|
||||
|
||||
match_device(device, device_name, sizeof(device_name));
|
||||
|
||||
printf("Connected to DRI3 on display '%s', using fd %d: matches %s\n",
|
||||
DisplayString(dpy), device, device_name);
|
||||
|
||||
XCloseDisplay(dpy);
|
||||
close(device);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (argc > 1) {
|
||||
for (i = 1; i < argc; i++)
|
||||
info(argv[i]);
|
||||
} else
|
||||
info(NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user