diff --git a/common/contrib/qoi b/common/contrib/qoi new file mode 120000 index 0000000..16ba104 --- /dev/null +++ b/common/contrib/qoi @@ -0,0 +1 @@ +../../../contrib/qoi \ No newline at end of file diff --git a/common/generate_links.sh b/common/generate_links.sh index 3424d30..2580f2a 100755 --- a/common/generate_links.sh +++ b/common/generate_links.sh @@ -14,6 +14,7 @@ link ../../contrib/imgui_knobs contrib/imgui_knobs link ../../contrib/imgui_toggle contrib/imgui_toggle link ../../contrib/tracy contrib/tracy link ../../contrib/sdl contrib/sdl3 +link ../../contrib/qoi contrib/qoi link ./contrib/imgui_toggle/imgui_toggle.cpp ./src/widgets/imgui_toggle/imgui_toggle.cpp link ./contrib/imgui_toggle/imgui_toggle_palette.cpp ./src/widgets/imgui_toggle/imgui_toggle_palette.cpp link ./contrib/imgui_toggle/imgui_toggle_presets.cpp ./src/widgets/imgui_toggle/imgui_toggle_presets.cpp diff --git a/dhall/sourceTreeParts.dhall b/dhall/sourceTreeParts.dhall index 67bb414..e99b2ee 100644 --- a/dhall/sourceTreeParts.dhall +++ b/dhall/sourceTreeParts.dhall @@ -578,6 +578,7 @@ let skiaVideo = \(asan : Bool) -> , imgui.dir , imguiImplot.dir , render.dir + , "./contrib/qoi" ] , global = [ , "${contribDir}" diff --git a/scripts/install_3rd_party_git_repos.sh b/scripts/install_3rd_party_git_repos.sh index ce02927..a4f38a7 100755 --- a/scripts/install_3rd_party_git_repos.sh +++ b/scripts/install_3rd_party_git_repos.sh @@ -52,4 +52,5 @@ getContribRepo "https://github.com/google/flatbuffers.git" "flatbuffers" "master getContribRepo "https://github.com/google/skia" "skia" "chrome/m124" "" getContribRepo "https://github.com/wolfpld/tracy" "tracy" "master" "0d5bd53be393b590da9c7b29079d919d488412c1" getContribRepo "https://github.com/libsdl-org/SDL.git" "sdl" "main" "e049098733739664ffbeac6967568b2421a0cb2e" +getContribRepo "https://github.com/phoboslab/qoi.git" "qoi" "master" "bf7b41c2ff3f24a2031193b62aa76d35e8842b5a" getMyRepo "https://github.com/stergiotis/boxer.git" "boxer" "main" "" diff --git a/skia/CMakeLists.txt b/skia/CMakeLists.txt index f3e36ef..53c7741 100644 --- a/skia/CMakeLists.txt +++ b/skia/CMakeLists.txt @@ -134,7 +134,8 @@ SK_BUILD_FOR_UNIX) target_include_directories(skiaVideo PUBLIC "${CMAKE_CURRENT_LIST_DIR}/./skia" "${CMAKE_CURRENT_LIST_DIR}/./imgui" "${CMAKE_CURRENT_LIST_DIR}/./src/widgets/imgui_implot" -"${CMAKE_CURRENT_LIST_DIR}/./src") +"${CMAKE_CURRENT_LIST_DIR}/./src" +"${CMAKE_CURRENT_LIST_DIR}/./contrib/qoi") add_library(skiaVideo_imported OBJECT IMPORTED) set_property(TARGET skiaVideo_imported PROPERTY IMPORTED_OBJECTS "${CMAKE_CURRENT_LIST_DIR}/./contrib/skia/out/Static/obj/../libskparagraph.a" "${CMAKE_CURRENT_LIST_DIR}/./contrib/skia/out/Static/obj/../libsvg.a" diff --git a/skia/contrib/qoi b/skia/contrib/qoi new file mode 120000 index 0000000..3f3ad36 --- /dev/null +++ b/skia/contrib/qoi @@ -0,0 +1 @@ +../../common/contrib/qoi \ No newline at end of file diff --git a/skia/generate_links.sh b/skia/generate_links.sh index e3b5d54..a2d839e 100755 --- a/skia/generate_links.sh +++ b/skia/generate_links.sh @@ -20,3 +20,4 @@ link ../common/contrib/imgui_implot/implot_demo.cpp ./implot/implot_demo.cpp link ../common/contrib/imgui_ImGuiColorTextEdit/TextEditor.cpp ./imcolortextedit/TextEditor.cpp link ../common/contrib/imgui_ImGuiColorTextEdit/TextEditor.h ./imcolortextedit/TextEditor.h link ../common/contrib/sdl3 contrib/sdl3 +link ../common/contrib/qoi contrib/qoi diff --git a/skia/skia/video/app.cpp b/skia/skia/video/app.cpp index df1f707..bc0ae58 100644 --- a/skia/skia/video/app.cpp +++ b/skia/skia/video/app.cpp @@ -14,19 +14,7 @@ #include "include/encode/SkWebpEncoder.h" #include "include/gpu/GrDirectContext.h" #include "include/gpu/gl/GrGLInterface.h" -#if defined(__linux__) -#include "include/gpu/gl/glx/GrGLMakeGLXInterface.h" -#include -#include -#include -#endif - -#include "gpu/ganesh/gl/GrGLDirectContext.h" -#include "gpu/ganesh/SkSurfaceGanesh.h" -#include "gpu/ganesh/gl/GrGLBackendSurface.h" -#include "src/gpu/ganesh/gl/GrGLDefines.h" -#include "src/gpu/ganesh/gl/GrGLUtil.h" -//#include "SkBitmap.h" + #include "tracy/Tracy.hpp" @@ -36,6 +24,22 @@ #include "marshalling/receive.h" #include "marshalling/send.h" +#define QOI_IMPLEMENTATION +#define QOI_NO_STDIO +#define QOI_FREE static_assert(false && "free should never be called") +#define QOI_MALLOC(sz) qoi_malloc(sz) +static void *qoi_malloc(size_t sz) { + static void *qoiBuffer = nullptr; + static size_t lastSz = 0; + if(qoiBuffer == nullptr) { + lastSz = sz; + qoiBuffer = malloc(sz); + } + assert(lastSz == sz && "assuming constant width, height and depth of qoi images"); + return qoiBuffer; +} +#include "qoi.h" + template static inline void applyFlag(int &flag,T val,bool v) { if(v) { @@ -342,41 +346,72 @@ int App::Run(CliOptions &opts) { options.fQuality = 70.0f; } auto stream = SkFILEWStream(opts.videoRawFramesFile); + qoi_desc qd{ + static_cast(w), + static_cast(h), + 4, + QOI_SRGB + }; + char pamHeader[4096]; + snprintf(pamHeader, sizeof(pamHeader), "P7\nWIDTH %d\nHEIGHT %d\nDEPTH 4\nMAXVAL 255\nTUPLTYPE RGB_ALPHA\nENDHDR\n", w, h); + auto pamHeaderLen = strlen(pamHeader); while(!done) { ImGui::NewFrame(); ImGui::ShowMetricsWindow(); sk_sp img(rasterSurface->makeImageSnapshot(SkIRect::MakeWH(w,h))); - if(true) { - { ZoneScoped; - auto canvas = rasterSurface->getCanvas(); - canvas->clear(clearColor); - Paint(rasterSurface.get(),w,h); // will call ImGui::Render(); - } - { ZoneScoped; - SkPixmap pixmap; - if(img->peekPixels(&pixmap)) { - if (!SkWebpEncoder::Encode(static_cast(&stream), pixmap, options)) { - fprintf(stderr,"unable to encode frame as image. Skipping.\n"); + { ZoneScoped; + auto canvas = rasterSurface->getCanvas(); + canvas->clear(clearColor); + Paint(rasterSurface.get(),w,h); // will call ImGui::Render(); + } + switch(1) { + case 0: + { ZoneScoped; + SkPixmap pixmap; + if(img->peekPixels(&pixmap)) { + if (!SkWebpEncoder::Encode(static_cast(&stream), pixmap, options)) { + fprintf(stderr,"unable to encode frame as image. Skipping.\n"); + } } } - } - } else { - Paint(nullptr,w,h); // will call ImGui::Render(); - - snprintf(pathBuffer,sizeof(pathBuffer),"/tmp/video/out_%09u.flatbuffers",frame); - SkFILEWStream stream(pathBuffer); - - const ImDrawData* drawData = ImGui::GetDrawData(); - fTotalVectorCmdSerializedSize = 0; - for (int i = 0; i < drawData->CmdListsCount; ++i) { - ImDrawList* drawList = drawData->CmdLists[i]; - const uint8_t *buf; - size_t sz; - drawList->serializeFB(buf,sz); - stream.write(buf,sz); - } + break; + case 1: + { ZoneScoped; + SkPixmap pixmap; + if (img->peekPixels(&pixmap)) { + int imgLen; + auto const imgMem = qoi_encode(pixmap.addr(), &qd, &imgLen); + stream.write(imgMem, static_cast(imgLen)); + stream.flush(); + } + } + break; + case 2: + { ZoneScoped; + SkPixmap pixmap; + if (img->peekPixels(&pixmap)) { + stream.write(pamHeader, pamHeaderLen); + stream.write(pixmap.addr(),pixmap.computeByteSize()); + stream.flush(); + } + } + break; + case 3: + { ZoneScoped; + const ImDrawData* drawData = ImGui::GetDrawData(); + fTotalVectorCmdSerializedSize = 0; + for (int i = 0; i < drawData->CmdListsCount; ++i) { + ImDrawList* drawList = drawData->CmdLists[i]; + const uint8_t *buf; + size_t sz; + drawList->serializeFB(buf,sz); + stream.write(buf,sz); + } + stream.flush(); + } + break; } { diff --git a/skia/video.sh b/skia/video.sh index fa3b8e3..b431e5f 100755 --- a/skia/video.sh +++ b/skia/video.sh @@ -65,7 +65,7 @@ pid=$! #-loglevel debug \ ffmpeg -hide_banner \ -re -fflags +genpts \ - -f image2pipe -i transferRawFrames \ + -f image2pipe -vcodec qoi -i transferRawFrames \ -flags +global_header -r 30000/1001 \ -an \ -vaapi_device /dev/dri/renderD128 \ diff --git a/skia/video_null.sh b/skia/video_null.sh new file mode 100755 index 0000000..04ad2aa --- /dev/null +++ b/skia/video_null.sh @@ -0,0 +1,20 @@ +#!/bin/bash +rm -f transferRawFrames +mkfifo transferRawFrames + +resW=1920 +resH=1080 + +./imgui_skia_exe -fffiInterpreter off -ttfFilePath ./SauceCodeProNerdFontPropo-Regular.ttf -backdropFilter off -videoRawFramesFile transferRawFrames -videoResolutionWidth $resW -videoResolutionHeight $resH & +pid=$! +cat transferRawFrames | tee out.raw | \ + mpv --no-cache --untimed --no-demuxer-thread - +#ffplay -hide_banner \ +# -threads 1 -filter_threads 1 \ +# -probesize 32 -sync ext \ +# -fpsprobesize 0 -framedrop -fast -infbuf \ +# -f nut -fflags '+nobuffer' -flags2 '+fast' -i "pipe:0" \ +# -vf "drawtext=text='%{localtime\:%S-%6N}':fontsize=144:box=1:boxcolor=black:fontcolor=red:y=(main_h/2)+text_h" + +#mpv --no-cache --untimed --no-demuxer-thread --video-sync=audio \ +kill $pid