From 91e117fdc3bd4d8916a93c4d40736d90c106e34a Mon Sep 17 00:00:00 2001 From: Pierre Fenoll Date: Tue, 2 Nov 2021 10:40:15 +0000 Subject: [PATCH] xvfb.sh (#114) --- .dockerignore | 4 ++- .github/workflows/workflow.yml | 11 +++++- .gitignore | 1 + Dockerfile | 31 ++++++++++++++-- snap/snapcraft.yaml | 2 +- voidstar/managers/glfw3.cc | 7 ++-- voidstar/managers/manager.h | 9 +++-- xvfb.sh | 64 ++++++++++++++++++++++++++++++++++ 8 files changed, 117 insertions(+), 12 deletions(-) create mode 100755 xvfb.sh diff --git a/.dockerignore b/.dockerignore index ec54e85..a8f14c8 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,8 +1,10 @@ * !/.bazelrc !/BUILD +!/data/ !/resolved.bzl -!/variables.bzl !/third_party +!/variables.bzl !/voidstar !/WORKSPACE +!/xvfb.sh diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index f86f938..cebc936 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -29,6 +29,11 @@ jobs: - uses: actions/checkout@v2 - run: DOCKER_BUILDKIT=1 docker build -o=./bin/ --target=voidstar . --progress=plain - run: ./bin/voidstar --help + - uses: Wandalen/wretry.action@v1.0.11 + with: + command: DOCKER_BUILDKIT=1 docker build -o=. --target=video-gcc . --progress=plain + attempt_limit: 20 + attempt_delay: 1000 build_on_ubuntu_with_clang: name: Build on ubuntu with Clang @@ -41,7 +46,11 @@ jobs: - uses: actions/checkout@v2 - run: DOCKER_BUILDKIT=1 docker build -o=./bin/ --target=voidstar-clang . --progress=plain - run: ./bin/voidstar --help - + - uses: Wandalen/wretry.action@v1.0.11 + with: + command: DOCKER_BUILDKIT=1 docker build -o=. --target=video-clang . --progress=plain + attempt_limit: 20 + attempt_delay: 1000 build_on_macos: name: Build on macos diff --git a/.gitignore b/.gitignore index 68203ec..32fbf48 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ /bazelisk /bin/* +/video.webm diff --git a/Dockerfile b/Dockerfile index 89d7d30..b7f8f2b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,6 +18,7 @@ RUN \ ca-certificates \ clang \ curl \ + ffmpeg \ git \ gzip \ libgl1-mesa-dev \ @@ -25,7 +26,9 @@ RUN \ software-properties-common \ tar \ unzip \ + xauth \ xorg-dev \ + xvfb \ && update-alternatives --install /usr/bin/python python /usr/bin/python3 1 RUN \ --mount=type=cache,target=/var/cache/apt \ @@ -77,8 +80,6 @@ RUN \ && bazel build --repo_env=CC=clang voidstar \ # Necessary as COPY --from does not follow symlinks && cp /app/bazel-bin/voidstar/voidstar / -FROM scratch AS voidstar-clang -COPY --from=builder-clang /voidstar / # voidstar GCC FROM base AS builder-gcc @@ -88,5 +89,31 @@ RUN \ && bazel build voidstar \ # Necessary as COPY --from does not follow symlinks && cp /app/bazel-bin/voidstar/voidstar / + + +# xvfb GCC +FROM builder-gcc AS xvfb-gcc +ARG WxHxD=800x600x24 +ARG BIN=/voidstar +ARG FILE=./data/BigPictureBG.tga +ARG OUT=video.webm +RUN ./xvfb.sh +FROM scratch AS video-gcc +COPY --from=xvfb-gcc /app/video.webm / + +# xvfb Clang +FROM builder-clang AS xvfb-clang +ARG WxHxD=800x600x24 +ARG BIN=/voidstar +ARG FILE=./data/BigPictureBG.tga +ARG OUT=video.webm +RUN ./xvfb.sh +FROM scratch AS video-clang +COPY --from=xvfb-clang /app/video.webm / + + +FROM scratch AS voidstar-clang +COPY --from=builder-clang /voidstar / + FROM scratch AS voidstar COPY --from=builder-gcc /voidstar / diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 7d7a791..9532dd7 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -1,5 +1,5 @@ name: voidstar -version: v1.34.1 # FIXME: 'git' +version: v1.35.0 # FIXME: 'git' summary: void* casts files onto 2D/3D colored spaces for your mind blowing needs # 79 char long summary description: | Usage: diff --git a/voidstar/managers/glfw3.cc b/voidstar/managers/glfw3.cc index 9d793b8..03dd528 100644 --- a/voidstar/managers/glfw3.cc +++ b/voidstar/managers/glfw3.cc @@ -229,8 +229,11 @@ bool GLFW3Manager::updateFirst(float deltaTime, glm::mat4* MVP) { // User loaded a different file file_changed || false) { if (args_->move_window) slide_window_right(); - bool slid = slide_window(scene_->selected(), scene_->indices()); - if (!slid && args_->move_window) args_->move_window = false; + auto slid = slide_window(scene_->selected(), scene_->indices()); + if (previously_slid_ != slid) + std::cout << "#selected: " << slid << std::endl; + previously_slid_ = slid; + if (slid < 1 && args_->move_window) args_->move_window = false; } return true; diff --git a/voidstar/managers/manager.h b/voidstar/managers/manager.h index 7c9ef81..705f0cb 100644 --- a/voidstar/managers/manager.h +++ b/voidstar/managers/manager.h @@ -7,7 +7,6 @@ #include "voidstar/managers/events.h" #include "voidstar/registrar.h" #include "voidstar/scenes/scene.h" -#include "voidstar/size2str.h" class Manager { public: @@ -62,7 +61,8 @@ class Manager { : args_->sliding_window_length; } - bool slide_window(VertIndices& selected, const VertIndices& indices) { + size_t previously_slid_ = 0; + size_t slide_window(VertIndices& selected, const VertIndices& indices) { using offset_t = VertIndices::const_iterator::difference_type; const offset_t woffset = static_cast(sliding_window_offset_); const offset_t wlength = static_cast(sliding_window_length_); @@ -75,10 +75,9 @@ class Manager { selected.assign(left, right); sliding_window_left_ = &left[0]; sliding_window_right_ = &right[0]; - std::cout << "#selected: " << size2str(selected.size()) << std::endl; - return true; + return selected.size(); } - return false; + return 0; } protected: diff --git a/xvfb.sh b/xvfb.sh new file mode 100755 index 0000000..c4e3870 --- /dev/null +++ b/xvfb.sh @@ -0,0 +1,64 @@ +#!/bin/bash -eux +set -o pipefail + +_kill_procs() { + kill -TERM $companion + wait $companion + kill -TERM $xvfb +} +trap _kill_procs SIGTERM + +display=99 + +wxhxd=${WxHxD:-800x600x24} +bin=${BIN:-./bin/voidstar} +file=${FILE:-"$bin"} +out=${OUT:-video.webm} + +case "$file" in + http://*|https://*) + curl -fsSLo /file "$file" + file=/file + # ls -lh "$file"; exit 42 +;;*) ;; +esac + +rm -rf /tmp/xvfb-run.* + +xvfb-run \ + --server-num="$display" \ + --error-file=/dev/stdout \ + -s "-screen 0 $wxhxd" \ + "$bin" \ + --move \ + --exit-at-fin \ + "$file" & +xvfb=$! + +touch ~/.Xauthority +xauth generate :0 . trusted || true +xauth list + +ls /tmp/xvfb*/Xauthority >/dev/null + +XAUTHORITY=$(echo /tmp/xvfb*/Xauthority) \ + ffmpeg \ + -r 30 \ + -f x11grab \ + -draw_mouse 0 \ + -s "$(cut -dx -f1-2 <<<"$wxhxd")" \ + -i :"$display" \ + -c:v libvpx \ + -quality realtime \ + -cpu-used 0 \ + -b:v 384k \ + -qmin 10 \ + -qmax 42 \ + -maxrate 384k \ + -bufsize 1000k \ + -an "$out" & +companion=$! + +wait $xvfb +kill -TERM $companion +wait $companion || true