diff --git a/Config.in b/Config.in index fc3d0afd96d29aaa1278d847ac80d31046f198cb..c0d19ad5f382d3bcbdb12350ac11335a9dae741d 100644 --- a/Config.in +++ b/Config.in @@ -392,6 +392,7 @@ menu "Utils" source "$BR2_EXTERNAL_RECALBOX_PATH/package/rpi-eeprom/Config.in" source "$BR2_EXTERNAL_RECALBOX_PATH/package/rpi-utils/Config.in" source "$BR2_EXTERNAL_RECALBOX_PATH/package/nodejs-quasar/Config.in.host" + source "$BR2_EXTERNAL_RECALBOX_PATH/package/grim/Config.in" endmenu menu "Small TFT Screen" source "$BR2_EXTERNAL_RECALBOX_PATH/package/rpi-fbcp/Config.in" diff --git a/board/recalbox/fsoverlay/recalbox/scripts/recalbox-utils.sh b/board/recalbox/fsoverlay/recalbox/scripts/recalbox-utils.sh index 86b3958325e716d5384cc1baba59b6f0d2915782..3d1c0220f2b22df8a4c0efa86d770f2a9e1b3580 100644 --- a/board/recalbox/fsoverlay/recalbox/scripts/recalbox-utils.sh +++ b/board/recalbox/fsoverlay/recalbox/scripts/recalbox-utils.sh @@ -313,3 +313,22 @@ function isRecalboxRGBDUAL2ForceComposite { function isRecalboxRGBDUAL2Force50Hz { grep -q "0" /sys/devices/platform/recalboxrgbdual2/dipswitch-50hz/value } +useWayland() { + count=$(ps aux | grep dwl | grep -v grep | wc -l) + if [ "$count" -gt "0" ]; then + return 0 + else + return 1 + fi +} + +function getCurrentCrtDriDevice() { + for card in "$(ls /sys/class/drm/ | grep VGA)" "$(ls /sys/class/drm/ | grep Composite)"; do + if [ -n "$card" ] && grep -q "^connected" /sys/class/drm/"$card"/status; then + dev="/dev/$(grep DEVNAME /sys/class/drm/"$card"/device/uevent | awk -F= '{print $2}')" + echo "${dev}" + return 0 + fi + done + return 1 +} diff --git a/board/recalbox/fsoverlay/usr/bin/raspi2png b/board/recalbox/fsoverlay/usr/bin/raspi2png index a858b93fab8412e92b148c1faa2a8197ff382300..5f1ba62e0a7d644bf569d504fece83b10ae72ae2 100755 --- a/board/recalbox/fsoverlay/usr/bin/raspi2png +++ b/board/recalbox/fsoverlay/usr/bin/raspi2png @@ -1,21 +1,36 @@ #!/bin/bash - +set -x source /recalbox/scripts/recalbox-utils.sh ARCH=$(getArchName) case "$ARCH" in - rpi1|rpizero2legacy) - /usr/bin/raspi2png.real "$@" - ;; - x86|x86_64) - /usr/bin/ffmpeg -f x11grab -framerate 1 -video_size "$(DISPLAY=:0 xrandr |grep \* |awk '{print $1}')" -i :0.0 -vframes 1 -vcodec png "$2" - ;; - *) - /usr/bin/kmsgrab "$2" - if [ "$ARCH" = "odroidgo2" ] && [ $? -eq 0 ]; then + rpi1|rpizero2legacy) + /usr/bin/raspi2png.real "$@" + ;; + x86|x86_64) + /usr/bin/ffmpeg -f x11grab -framerate 1 -video_size "$(DISPLAY=:0 xrandr |grep \* |awk '{print $1}')" -i :0.0 -vframes 1 -vcodec png "$2" + ;; + odroidgo2) ffmpeg -y -i "$2" -vf transpose=1 /tmp/temp.png && mv -f /tmp/temp.png "$2" - fi - ;; + ;; + *) + if currentVideoOnCRT; then + card=$(getCurrentCrtDriDevice) + if [ "$card" = "/dev/dri/card2" ]; then + res="720×480" + else + res="320:240" + fi + /usr/bin/ffmpeg -device $card -f kmsgrab -i - -vf 'hwdownload,format=bgr0' -framerate 1 -frames:v 1 "$2" + /usr/bin/ffmpeg -i "$2" -vf scale=$res /tmp/temp.png && mv -f /tmp/temp.png "$2" + elif useWayland; then + grim "$2" + else + /usr/bin/kmsgrab "$2" + fi + if [ "$ARCH" = "odroidgo2" ] && [ $? -eq 0 ]; then + ffmpeg -y -i "$2" -vf transpose=1 /tmp/temp.png && mv -f /tmp/temp.png "$2" + fi + ;; esac - diff --git a/package/grim/Config.in b/package/grim/Config.in new file mode 100644 index 0000000000000000000000000000000000000000..0721d8f26dd071bc45c34b32823e8ed13233f696 --- /dev/null +++ b/package/grim/Config.in @@ -0,0 +1,8 @@ +config BR2_PACKAGE_GRIM + bool "grim" + select BR2_PACKAGE_WAYLAND + select BR2_PACKAGE_LIBPNG + help + Grab images from a Wayland compositor + + https://gitlab.freedesktop.org/emersion/grim diff --git a/package/grim/grim.mk b/package/grim/grim.mk new file mode 100644 index 0000000000000000000000000000000000000000..404bb4db4963e7069ddbc9adf568154d9627818d --- /dev/null +++ b/package/grim/grim.mk @@ -0,0 +1,18 @@ +################################################################################ +# +# grim +# +################################################################################ + +GRIM_VERSION = 7ba46364ab95141c79e0e18093aa66597256182c +GRIM_SITE = https://gitlab.freedesktop.org/emersion/grim/-/archive/$(GRIM_VERSION) +GRIM_LICENSE = MIT +GRIM_LICENSE_FILES = LICENSE + +GRIM_DEPENDENCIES = wayland libpng + +GRIM_CONF_OPTS = \ + -Dman-pages=disabled \ + -Djpeg=disabled + +$(eval $(meson-package)) diff --git a/package/recalbox-system/Config.in b/package/recalbox-system/Config.in index da76aa550a5a3efb4c637444f002d1ed7d71bbe0..38c95df2fa640406d9902c5c78e375fd305bb964 100644 --- a/package/recalbox-system/Config.in +++ b/package/recalbox-system/Config.in @@ -281,6 +281,7 @@ config BR2_PACKAGE_RECALBOX_VIDEO_XWAYLAND select BR2_PACKAGE_SDL2_X11 select BR2_PACKAGE_SDL2_OPENGL select BR2_PACKAGE_XLIB_LIBXI + select BR2_PACKAGE_GRIM config BR2_PACKAGE_RECALBOX_QT6 bool diff --git a/projects/configgen/configgen/generators/libretro/crtswitchres/LibretroConfigCRTSwitchres.py b/projects/configgen/configgen/generators/libretro/crtswitchres/LibretroConfigCRTSwitchres.py index c02aa20117c59a07c7526058541465d9b2adc1f1..e2a4b6433da76e369baf6797e0be6f1bba522706 100644 --- a/projects/configgen/configgen/generators/libretro/crtswitchres/LibretroConfigCRTSwitchres.py +++ b/projects/configgen/configgen/generators/libretro/crtswitchres/LibretroConfigCRTSwitchres.py @@ -78,6 +78,7 @@ class LibretroConfigCRTSwitchres: "video_message_pos_x": '"0.04"', "video_message_pos_y": '"0.05"', "quick_menu_show_crt_cali": 'true', + "video_gpu_screenshot": '"true"' } print("[CRTSwitchres]: configuration on {} with {} signal with resolution {}". @@ -235,6 +236,7 @@ class LibretroConfigCRTSwitchres: if system.CRTSuperrez in ["1920", "2560", "3840"]: config["video_font_path"] = '"/usr/share/fonts/truetype/ubuntu_condensed-4x_wide.ttf"' + config["video_gpu_screenshot"] = '"false"' else: config["video_font_path"] = '"/usr/share/fonts/truetype/ubuntu_condensed.ttf"'