Skip to content

Commit f531487

Browse files
committed
wip: reintroduce interpreter
1 parent 3daee11 commit f531487

File tree

7 files changed

+110
-26
lines changed

7 files changed

+110
-26
lines changed

common/src/render.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,11 @@ void render_init(FILE *fdInput,FILE *fdOutput) {
127127
sendInit();
128128
receiveInit();
129129

130-
interpretCommands();
131-
fprintf(stderr,"end of render_init\n");
130+
//interpretCommands();
132131
}
133132

134-
135133
void render_render() {
136134
interpretCommands();
137-
//EmitDrawList(stdout);
138135
}
139136

140137
void render_cleanup() {

skia2/common.dhall

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ let common =
77
let sourceTreePartsImGuiSkia = ../skia_minimal/dhall/sourceTreeParts.dhall
88
let target = {os = sourceTreePartsImGuiSkia.TargetOs.linux}
99
let librarySourceTreeParts = [
10-
, sourceTreePartsImGuiSkia.systemFlags target
10+
, sourceTreePartsImGuiSkia.systemFlags target
1111
, sourceTreePartsImGuiSkia.flatbuffers
1212
, sourceTreePartsImGuiSkia.imguiWithHooks1919Wip sourceTreePartsImGuiSkia.ImGuiAppHelper.SDL3
1313
, sourceTreePartsImGuiSkia.imguiSkiaImpl

skia2/imzero_client_skia_sdl3_impl/imzero_client_skia_sdl3_app.cpp

Lines changed: 53 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
#define QOI_NO_STDIO
5959
#define QOI_FREE static_assert(false && "free should never be called")
6060
#define QOI_MALLOC(sz) qoiMalloc(sz)
61-
static void *qoiMalloc(size_t sz) {
61+
static void *qoiMalloc(const size_t sz) {
6262
static void *qoiBuffer = nullptr;
6363
static size_t lastSz = 0;
6464
if(qoiBuffer == nullptr) {
@@ -75,7 +75,7 @@ static void applyFlag(int &flag,T val,bool v) {
7575
if(v) {
7676
flag |= val;
7777
} else {
78-
flag &= ~(val);
78+
flag &= ~val;
7979
}
8080
}
8181
constexpr int msaaSampleCount = 0; //4;
@@ -621,40 +621,80 @@ static void printColorMode(FILE *fd) {
621621
#endif
622622
}
623623

624-
int ImZeroClient::App::Run(ImZeroCliOptions &opts) {
624+
void ImZeroClient::App::setup(ImZeroCliOptions &opts) {
625625
printColorMode(stderr);
626626
// prevent SIGPIPE when writing frames or reading user interaction events
627627
//signal(SIGPIPE, SIG_IGN);
628628

629629
sk_sp<SkTypeface> typeface = nullptr;
630630
sk_sp<SkData> ttfData = nullptr;
631-
FILE *fffiInFile = stdin;
632-
FILE *fffiOutFile = stdout;
633631
{
634632
// setup skia/imgui shared objects
635633
if (opts.fFffiInterpreter) {
636634
if (opts.fFffiInFile != nullptr) {
637-
fffiInFile = fopen(opts.fFffiInFile, "rw");
638-
if (fffiInFile == nullptr) {
635+
fFffiInFile = fopen(opts.fFffiInFile, "rw");
636+
if (fFffiInFile == nullptr) {
639637
fprintf(stderr, "unable to open fffInFile %s: %s", opts.fFffiInFile, strerror(errno));
640638
exit(1);
641639
}
642-
setvbuf(fffiInFile, nullptr, _IONBF, 0);
640+
setvbuf(fFffiInFile, nullptr, _IONBF, 0);
643641
}
644642
if (opts.fFffiOutFile != nullptr) {
645-
fffiOutFile = fopen(opts.fFffiOutFile, "w");
646-
if (fffiOutFile == nullptr) {
643+
fFffiOutFile = fopen(opts.fFffiOutFile, "w");
644+
if (fFffiOutFile == nullptr) {
647645
fprintf(stderr, "unable to open fffOutFile %s: %s", opts.fFffiOutFile, strerror(errno));
648646
exit(1);
649647
}
650-
setvbuf(fffiOutFile, nullptr, _IONBF, 0);
648+
setvbuf(fFffiOutFile, nullptr, _IONBF, 0);
651649
}
652650
}
653651
}
652+
fFffiInterpreter = opts.fFffiInterpreter;
653+
if (fFffiInterpreter) {
654+
//render_init(fffiInFile, fffiOutFile);
655+
}
656+
fApp.setup(opts.fBaseOptions);
657+
}
658+
SkSurface* ImZeroClient::App::preRender(bool& done, int& width, int& height) {
659+
return fApp.preRender(done, width, height);
660+
}
661+
void ImZeroClient::App::postRender(ImGuiSkia::FrameExportFormatE frameExportFormat, SkSurface* surface, int width, int height) {
662+
return fApp.postRender(frameExportFormat, surface, width, height);
663+
}
664+
ImGuiSkia::FrameExportFormatE ImZeroClient::App::render(SkSurface* surface, int width, int height) {
665+
static bool first = true;
666+
auto const r = fApp.render(surface, width, height);
667+
if (fFffiInterpreter) {
668+
if (first) {
669+
first = false;
670+
render_init(fFffiInFile, fFffiOutFile);
671+
}
672+
render_render();
673+
}
674+
return r;
675+
}
676+
void ImZeroClient::App::postPaint(SkSurface* surface, ImGuiSkia::FrameExportFormatE frameExportFormat, int width, int height) {
677+
return fApp.postPaint(surface, frameExportFormat, width, height);
678+
}
679+
void ImZeroClient::App::cleanup() {
680+
if (fFffiInterpreter) {
681+
render_cleanup();
682+
}
683+
fApp.cleanup();
684+
}
654685

655-
if (opts.fFffiInterpreter) {
656-
render_init(fffiInFile, fffiOutFile);
686+
int ImZeroClient::App::mainLoop() {
687+
bool done = false;
688+
int width;
689+
int height;
690+
while(!done) {
691+
auto const surface = preRender(done,width,height);
692+
if (surface != nullptr) {
693+
const auto frameExportFormat = render(surface,width,height);
694+
postRender(frameExportFormat, surface, width,height);
695+
}
657696
}
697+
658698
return 0;
659699
}
660700
int ImZeroClient::App::mainLoopHeadless(const ImZeroCliOptions &opts, ImVec4 const &clearColor) {

skia2/imzero_client_skia_sdl3_impl/imzero_client_skia_sdl3_app.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,16 @@ namespace ImZeroClient
3333
public:
3434
App();
3535
~App();
36-
int Run(ImZeroCliOptions &opts);
36+
37+
void postRender(ImGuiSkia::FrameExportFormatE frameExportFormat, SkSurface* surface, int width, int height);
38+
void prePaint(const SkSurface* surface, int width, int height);
39+
SkSurface* preRender(bool& done, int& width, int& height);
40+
ImGuiSkia::FrameExportFormatE render(SkSurface* surface, int width, int height);
41+
void postPaint(SkSurface* surface, ImGuiSkia::FrameExportFormatE frameExportFormat, int width, int height);
42+
43+
void setup(ImZeroCliOptions &opts);
44+
int mainLoop();
45+
void cleanup();
3746
private:
3847
sk_sp<SkSurface> getSurfaceRaster(int w, int h);
3948
bool fFffiInterpreter = false;
@@ -70,5 +79,7 @@ namespace ImZeroClient
7079

7180
ImGuiSkia::Driver::App fApp{};
7281
sk_sp<SkSurface> fSurface{nullptr};
82+
FILE *fFffiInFile = nullptr;
83+
FILE *fFffiOutFile = nullptr;
7384
};
7485
}

skia2/imzero_client_skia_sdl3_impl/main.cpp

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,43 @@
11
#include "imzero_client_skia_sdl3_app.h"
22
#include "imzero_client_skia_sdl3_cli_options.h"
3-
#include "imgui_skia_cli_options.h"
43

54
#include <sys/prctl.h>
5+
#ifdef TRACY_ENABLE
6+
#include <cstdlib>
7+
#include "tracy/Tracy.hpp"
8+
static const char *tracyMemPoolNameImgui = "imgui";
9+
static void *imZeroMemAlloc(size_t sz,void *user_data) noexcept { ZoneScoped;
10+
11+
auto ptr = malloc(sz);
12+
#ifdef IMZERO_DEBUG_BUILD
13+
TracyAllocNS(ptr, sz, 6, tracyMemPoolNameImgui);
14+
#else
15+
TracyAllocN(ptr, sz, tracyMemPoolNameImgui);
16+
#endif
17+
return ptr;
18+
}
19+
static void imZeroMemFree(void *ptr,void *user_data) noexcept { ZoneScoped;
20+
#ifdef IMZERO_DEBUG_BUILD
21+
TracyFreeNS(ptr, 6, tracyMemPoolNameImgui);
22+
#else
23+
TracyFreeN(ptr, tracyMemPoolNameImgui);
24+
#endif
25+
free(ptr);
26+
}
27+
#if 0
28+
// NOTE: not compatible with address sanitizier asan
29+
static const char *tracyMemPoolNameOperators = "operator new/delete";
30+
void* operator new(std::size_t count) {
31+
auto ptr = malloc(count);
32+
TracyAllocN(ptr, count, tracyMemPoolNameOperators);
33+
return ptr;
34+
}
35+
void operator delete(void* ptr) noexcept {
36+
free(ptr);
37+
TracyFreeN(ptr, tracyMemPoolNameOperators);
38+
}
39+
#endif
40+
#endif
641

742
int main(const int argc, const char** argv) {
843
#ifdef TRACY_ENABLE
@@ -23,8 +58,9 @@ int main(const int argc, const char** argv) {
2358
return 1;
2459
}
2560

26-
ImGuiSkia::Driver::App app{};
27-
app.setup(opts.fBaseOptions);
61+
ImZeroClient::App app{};
62+
app.setup(opts);
63+
2864
const int r = app.mainLoop();
2965
app.cleanup();
3066
return r;

skia_minimal/build.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ cd "$here"
55
export IMGUI_SKIA_CPP_ROOT="$(realpath "$here")/.."
66
./copy_libs.sh
77
./build_cpp.sh
8-
rm -rf bin
9-
mkdir -p bin
10-
mv imgui_skia_exe bin
8+
#rm -rf bin
9+
#mkdir -p bin
10+
#mv imgui_skia_exe bin

skia_minimal/imgui_skia_driver_impl/imgui_skia_app_sdl3.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ namespace ImGuiSkia::Driver {
1212
class App {
1313
public:
1414
App();
15-
void postRender(FrameExportFormatE frameExportFormat, SkSurface* surface, int width, int height);
1615
~App();
16+
void postRender(FrameExportFormatE frameExportFormat, SkSurface* surface, int width, int height);
1717
void prePaint(const SkSurface* surface, int width, int height);
1818
SkSurface* preRender(bool& done, int& width, int& height);
1919
FrameExportFormatE render(SkSurface* surface, int width, int height);

0 commit comments

Comments
 (0)