From 5eca5526070b01e1661a818b2de05ef6d41dcb52 Mon Sep 17 00:00:00 2001 From: totaam Date: Mon, 12 Sep 2022 18:32:04 +0700 Subject: [PATCH] #3390 add drm query tool --- .gitignore | 1 + setup.py | 7 ++- xpra/codecs/evdi/drm.pyx | 96 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 102 insertions(+), 2 deletions(-) create mode 100644 xpra/codecs/evdi/drm.pyx diff --git a/.gitignore b/.gitignore index 95201345b3..bc8a4ca86b 100644 --- a/.gitignore +++ b/.gitignore @@ -132,6 +132,7 @@ tests/unittests/test-file* /xpra/codecs/nvjpeg/decoder.c /xpra/codecs/nvjpeg/common.c /xpra/codecs/evdi/capture.cpp +/xpra/codecs/evdi/drm.c /xpra/gtk_common/gdk_atoms.c /xpra/gtk_common/gtk3/gdk_atoms.c /xpra/gtk_common/gtk3/gdk_bindings.c diff --git a/setup.py b/setup.py index 5218d1c9df..baf3f11ab3 100755 --- a/setup.py +++ b/setup.py @@ -213,7 +213,8 @@ def has_header_file(name, isdir=False): notifications_ENABLED = DEFAULT keyboard_ENABLED = DEFAULT v4l2_ENABLED = DEFAULT and (not WIN32 and not OSX and not FREEBSD and not OPENBSD) -evdi_ENABLED = DEFAULT and POSIX and pkg_config_version("1.10", "evdi") +evdi_ENABLED = DEFAULT and LINUX and pkg_config_version("1.12", "evdi") +evdi_drm_ENABLED = DEFAULT and LINUX and pkg_config_version("2.4", "drm") #ffmpeg 3.1 or later is required dec_avcodec2_ENABLED = DEFAULT and BITS==64 and pkg_config_version("57", "libavcodec") csc_swscale_ENABLED = DEFAULT and BITS==64 and pkg_config_ok("--exists", "libswscale") @@ -248,7 +249,7 @@ def has_header_file(name, isdir=False): "spng_decoder", "spng_encoder", "jpeg_encoder", "jpeg_decoder", "nvjpeg", "avif", "argb", - "v4l2", "evdi", + "v4l2", "evdi", "evdi_drm", "dec_avcodec2", "csc_swscale", "csc_cython", "csc_libyuv", ] @@ -1053,6 +1054,7 @@ def clean(): "xpra/codecs/v4l2/pusher.c", "xpra/codecs/v4l2/constants.pxi", "xpra/codecs/evdi/capture.cpp", + "xpra/codecs/evdi/drm.c", "xpra/codecs/libav_common/av_log.c", "xpra/codecs/webp/encoder.c", "xpra/codecs/webp/decoder.c", @@ -2177,6 +2179,7 @@ def nvcc_compile(cmd): tace(argb_ENABLED, "xpra.codecs.argb.argb", optimize=3) toggle_packages(evdi_ENABLED, "xpra.codecs.evdi") tace(evdi_ENABLED, "xpra.codecs.evdi.capture", "evdi", language="c++") +tace(evdi_drm_ENABLED, "xpra.codecs.evdi.drm", "libdrm") toggle_packages(enc_x264_ENABLED, "xpra.codecs.enc_x264") tace(enc_x264_ENABLED, "xpra.codecs.enc_x264.encoder", "x264") toggle_packages(enc_x265_ENABLED, "xpra.codecs.enc_x265") diff --git a/xpra/codecs/evdi/drm.pyx b/xpra/codecs/evdi/drm.pyx new file mode 100644 index 0000000000..e1e1d396cb --- /dev/null +++ b/xpra/codecs/evdi/drm.pyx @@ -0,0 +1,96 @@ +# This file is part of Xpra. +# Copyright (C) 2022 Antoine Martin +# Xpra is released under the terms of the GNU GPL v2, or, at your option, any +# later version. See the file COPYING for details. + +#cython: wraparound=False + +from xpra.os_util import bytestostr + +from xpra.log import Logger +log = Logger("encoder", "evdi") + +cdef extern from "drm/drm.h": + ctypedef unsigned int __kernel_size_t + ctypedef struct drm_version: + int version_major + int version_minor + int version_patchlevel + __kernel_size_t name_len + char *name + __kernel_size_t date_len + char *date + __kernel_size_t desc_len + char *desc + ctypedef drm_version* drmVersionPtr + +cdef extern from "xf86drm.h": + int DRM_NODE_PRIMARY + ctypedef struct drmDevice: + char **nodes #DRM_NODE_MAX sized array + int available_nodes #DRM_NODE_* bitmask + int bustype + #union { + #drmPciBusInfoPtr pci + #drmUsbBusInfoPtr usb + #drmPlatformBusInfoPtr platform + #drmHost1xBusInfoPtr host1x + #} businfo; + #union { + #drmPciDeviceInfoPtr pci + #drmUsbDeviceInfoPtr usb + #drmPlatformDeviceInfoPtr platform + #drmHost1xDeviceInfoPtr host1x + #} deviceinfo; + ctypedef drmDevice* drmDevicePtr + + drmVersionPtr drmGetVersion(int fd) + void drmFreeVersion(drmVersionPtr ver) + + int drmGetDevices(drmDevicePtr devices[], int max_devices) + void drmFreeDevices(drmDevicePtr devices[], int count) + +cdef extern from "xf86drmMode.h": + #drmModeResPtr drmModeGetResources(int fd) + int drmIsKMS(int fd) + +def query(): + info = {} + cdef int count = drmGetDevices(NULL, 16) + if count<0: + log.error(f"Error querying drm devices: {count}") + return info + if count==0: + log.warn("Warning: no drm devices found") + return info + cdef drmDevicePtr[16] devices + count = drmGetDevices(devices, 16) + assert 0