Skip to content

Commit 8e6f856

Browse files
committed
feat: better cli options, software rasterer, buildinfo cleanups
1 parent 892c706 commit 8e6f856

File tree

10 files changed

+75
-106
lines changed

10 files changed

+75
-106
lines changed

skia/CMakeLists.txt

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ project(imgui_skia_exe)
44
set(CMAKE_CXX_STANDARD 20)
55
set(CMAKE_CXX_COMPILER clang++)
66

7-
add_compile_definitions(TRACY_ENABLE)
7+
add_compile_definitions()
88
include_directories("${CMAKE_CURRENT_LIST_DIR}/./imgui"
99
"${CMAKE_CURRENT_LIST_DIR}/./src/arena/simple"
1010
"${CMAKE_CURRENT_LIST_DIR}/./contrib/skia"
@@ -19,19 +19,11 @@ include_directories("${CMAKE_CURRENT_LIST_DIR}/./imgui"
1919
"${CMAKE_CURRENT_LIST_DIR}/./contrib/skia/modules/svg/include"
2020
"${CMAKE_CURRENT_LIST_DIR}/./contrib/skia/include"
2121
"${CMAKE_CURRENT_LIST_DIR}/./contrib/skia/include/core"
22-
"${CMAKE_CURRENT_LIST_DIR}/./contrib/tracy/public"
23-
"${CMAKE_CURRENT_LIST_DIR}/./contrib/flatbuffers")
22+
"${CMAKE_CURRENT_LIST_DIR}/./contrib/flatbuffers"
23+
"${CMAKE_CURRENT_LIST_DIR}/./contrib/tracy/public")
2424
set(COMPILE_OPTIONS -std=c++20
25-
-g
26-
-gdwarf-4
27-
-Wall
28-
-Wformat
29-
-Wextra
30-
-O1
31-
-fsanitize=address
32-
-fno-omit-frame-pointer
33-
-DIMZERO_DEBUG_BUILD)
34-
link_libraries(-fsanitize=address
25+
-O3)
26+
link_libraries(-DNDEBUG
3527
-ldl
3628
-lpthread
3729
-lfreetype
@@ -224,8 +216,8 @@ set_property(TARGET skia_imported PROPERTY IMPORTED_OBJECTS "${CMAKE_CURRENT_LIS
224216
"${CMAKE_CURRENT_LIST_DIR}/./contrib/skia/out/Static/libpiex.a"
225217
"${CMAKE_CURRENT_LIST_DIR}/./contrib/skia/out/Static/libpng.a")
226218

227-
add_library(tracyEnabled OBJECT "${CMAKE_CURRENT_LIST_DIR}/./contrib/tracy/public/TracyClient.cpp")
228219

220+
add_library(tracyDisabled OBJECT "${CMAKE_CURRENT_LIST_DIR}/./contrib/tracy/public/TracyClient.cpp")
229221
add_executable(imgui_skia_exe $<TARGET_OBJECTS:imguiWithSkia>
230222
$<TARGET_OBJECTS:render>
231223
$<TARGET_OBJECTS:marshalling>
@@ -239,5 +231,5 @@ $<TARGET_OBJECTS:imguiFlamegraph>
239231
$<TARGET_OBJECTS:imguiTextedit>
240232
$<TARGET_OBJECTS:skia>
241233
$<TARGET_OBJECTS:skia_imported>
242-
$<TARGET_OBJECTS:tracyEnabled>)
234+
$<TARGET_OBJECTS:tracyDisabled>)
243235

skia/build_cpp.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,19 @@ flatc="../../contrib/flatbuffers/flatc"
77

88
./cmakelists.dhall
99

10+
generate_buildinfo() {
11+
echo -en "#pragma once\nnamespace buildinfo {\n static const char *gitCommit=\""
12+
git log -1 --pretty=format:"%H" | tr -d "\n"
13+
echo -en "\";\n static const bool gitDirty="
14+
if [[ $(git diff --stat) != '' ]]; then
15+
echo -n "true"
16+
else
17+
echo -n "false"
18+
fi
19+
echo -en ";\n}\n"
20+
}
21+
generate_buildinfo > src/buildinfo.gen.h
22+
1023
mkdir -p build
1124
cd build
1225
cmake ../CMakeLists.txt

skia/build_flatbuffers.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
here=$(dirname "$(readlink -f "$BASH_SOURCE")")
33
set -ev
44
cd ../../contrib/flatbuffers
5-
cmake -G "Unix Makefiles"
5+
cmake -G "Unix Makefiles" .
66
make -j

skia/common.dhall

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
let lib = ../dhall/lib.dhall
2+
let debug = False
13
let sourceTreePartsRepo = ../dhall/sourceTreeParts.dhall
24
let sourceTreeParts = [
35
, sourceTreePartsRepo.imguiWithSkia
@@ -13,9 +15,8 @@ let sourceTreeParts = [
1315
, sourceTreePartsRepo.imguiTextedit
1416
, sourceTreePartsRepo.binding
1517
, sourceTreePartsRepo.skia
16-
, sourceTreePartsRepo.tracyEnabled
1718
, sourceTreePartsRepo.flatbuffers
18-
]
19+
] # (if debug then [ , sourceTreePartsRepo.tracyEnabled ] else [ ,sourceTreePartsRepo.tracyDisabled ] : List lib.sourceTreePart.Type )
1920
let cxx = "clang++"
2021
let cppstd = 20
2122
let cxxflagsDebug = [
@@ -37,7 +38,6 @@ let ldflagsDebug = ["-fsanitize=address"] : List Text
3738
let ldflagsRelease = ["-DNDEBUG"] : List Text
3839
--let stdlibFlags = ["-stdlib=libc++"] : List Text
3940
let stdlibFlags = [] : List Text
40-
let debug = False
4141
in {
4242
, sourceTreeParts
4343
, cxx

skia/run.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@
22
set -ev
33
here=$(dirname "$(readlink -f "$BASH_SOURCE")")
44
cd "$here"
5-
make -j
65
./build_go.sh
76
./main_go --logFormat console --httpServerAddress localhost:8888 demo --imGuiBinary ./imgui_exe --mainFontTTF ./SauceCodeProNerdFontMono-Regular.ttf --mainFontSizeInPixels 18

skia/run_pipe.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ rm -f transfer
44
mkfifo transfer
55
font="./martian/MartianMono-StdRg.ttf"
66
font="./SauceCodeProNerdFontMono-Regular.ttf"
7-
./main_go --logFormat console demo --mainFontTTF "$font" --mainFontSizeInPixels 13 "$@" < transfer | ./imgui_exe -ttfFilePath "$font" > transfer
7+
./main_go --logFormat console demo --mainFontTTF "$font" --mainFontSizeInPixels 13 "$@" < transfer | ./imgui_exe -ttfFilePath "$font" -fffiInterpreter on -skiaBackendType gl -vsync on -backdropFilter on > transfer
88
rm -f transfer

skia/skia/modified/ImGuiLayer.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ static void build_ImFontAtlas(ImFontAtlas& atlas, SkPaint& fontPaint) {
4242
atlas.TexID = &fontPaint;
4343
}
4444

45-
ImGuiLayer::ImGuiLayer(bool standalone) : fWindow(nullptr), fSvgBytesWritten(0), fSkpBytesWritten(0), fPngBytesWritten(0), fStandalone(standalone), fTotalVectorCmdSerializedSize(0) {
45+
ImGuiLayer::ImGuiLayer(const CliOptions *opts) : fWindow(nullptr), fSvgBytesWritten(0), fSkpBytesWritten(0), fPngBytesWritten(0), ffffiInterpreter(opts->fffiInterpreter), fTotalVectorCmdSerializedSize(0) {
4646
// ImGui initialization:
4747
ImGui::CreateContext();
4848
ImGuiIO& io = ImGui::GetIO();
@@ -70,7 +70,7 @@ ImGuiLayer::ImGuiLayer(bool standalone) : fWindow(nullptr), fSvgBytesWritten(0),
7070
io.KeyMap[ImGuiKey_Y] = (int)skui::Key::kY;
7171
io.KeyMap[ImGuiKey_Z] = (int)skui::Key::kZ;
7272

73-
if(!fStandalone) {
73+
if(ffffiInterpreter) {
7474
render_init();
7575
}
7676

@@ -79,12 +79,20 @@ ImGuiLayer::ImGuiLayer(bool standalone) : fWindow(nullptr), fSvgBytesWritten(0),
7979

8080
fVectorCmdSkiaRenderer.setVertexDrawPaint(&fFontPaint);
8181
fVectorCmdSkiaRenderer.setParagraphHandler(ImGui::paragraph);
82+
RenderModeE mode = 0;
83+
if(opts->backdropFilter) {
84+
mode |= RenderModeE_BackdropBlur;
85+
}
86+
if(opts->sketchFilter) {
87+
mode |= RenderModeE_Sketch;
88+
}
89+
fVectorCmdSkiaRenderer.changeRenderMode(mode);
8290

8391
fSkiaBackendActive = true;
8492
}
8593

8694
ImGuiLayer::~ImGuiLayer() {
87-
if(!fStandalone) {
95+
if(ffffiInterpreter) {
8896
render_cleanup();
8997
}
9098
ImGui::DestroyContext();
@@ -272,14 +280,15 @@ void ImGuiLayer::onPaint(SkSurface* surface) { ZoneScoped;
272280
auto renderMode = fVectorCmdSkiaRenderer.getRenderMode();
273281
resetReceiveStat();
274282
resetSendStat();
275-
if(fStandalone) { ZoneScopedN("demo window");
276-
ImGui::ShowDemoWindow();
277-
} else { ZoneScopedN("render fffi commands");
283+
if(ffffiInterpreter) { ZoneScopedN("render fffi commands");
278284
render_render();
285+
} else { ZoneScopedN("demo window");
286+
ImGui::ShowDemoWindow();
279287
}
280288

281289
SaveFormatE saveFormat = SaveFormatE_None;
282290
if(ImGui::Begin("ImZeroSkia Settings")) { ZoneScoped;
291+
ImGui::Text("gitCommit=\"%s\",dirty=%s",buildinfo::gitCommit,buildinfo::gitDirty ? "yes" : "no");
283292
fImZeroSkiaSetupUi.render(saveFormat, fVectorCmdSkiaRenderer, fSkiaBackendActive,
284293
fTotalVectorCmdSerializedSize, totalSentBytes+totalReceivedBytes,
285294
fSkpBytesWritten,fSvgBytesWritten, fPngBytesWritten,

skia/skia/modified/ImGuiLayer.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
#include "../vectorCmdSkiaRenderer.h"
2929
#include "../setupUI.h"
30+
#include "cliOptions.h"
3031

3132
class SkCanvas;
3233
class SkSurface;
@@ -39,7 +40,7 @@ enum class ModifierKey;
3940

4041
class ImGuiLayer : public sk_app::Window::Layer {
4142
public:
42-
ImGuiLayer(bool standalone);
43+
ImGuiLayer(const CliOptions *opts);
4344
~ImGuiLayer() override;
4445

4546
void setScaleFactor(float scaleFactor);
@@ -66,7 +67,7 @@ class ImGuiLayer : public sk_app::Window::Layer {
6667
size_t fSvgBytesWritten;
6768
size_t fPngBytesWritten;
6869
ImZeroSkiaSetupUI fImZeroSkiaSetupUi;
69-
bool fStandalone;
70+
bool ffffiInterpreter;
7071

7172
void drawImDrawData(SkCanvas &canvas);
7273
void drawImGuiVectorCmdsFB(SkCanvas &canvas);

skia/skia/modified/app.cpp

Lines changed: 31 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -58,74 +58,36 @@ void operator delete(void* ptr) noexcept {
5858
#endif
5959
#endif
6060

61-
static bool hasFlag(int argc, char **argv,const char *flag) {
62-
for(int i=0;i<argc;i++) {
63-
if(strcmp(argv[i],flag) == 0) {
64-
return true;
65-
}
66-
}
67-
return false;
68-
}
69-
static const char *findFlagValueDefault(int argc, char **argv,const char *flag,const char *defaultValue) {
70-
for(int i=0;i<argc;i++) {
71-
if(strcmp(argv[i],flag) == 0) {
72-
if(i == argc) {
73-
return defaultValue;
74-
} else {
75-
return argv[i+1];
76-
}
77-
}
78-
}
79-
return defaultValue;
80-
}
81-
static void showUsage(const char *name, FILE *file) {
82-
fprintf(stderr, "%s -ttfFilePath <file.ttf> -fontDyFudge <float> -fffiInFile <fffiIn> -fffiOutFile <fffiOut> -disableVsync -disableFffi\n", name);
83-
}
61+
CliOptions opts;
8462

8563
Application* Application::Create(int argc, char** argv, void* platformData) {
8664
#ifdef TRACY_ENABLE
8765
ImGui::SetAllocatorFunctions(imZeroMemAlloc,imZeroMemFree,nullptr);
8866
#endif
8967

90-
auto const ttfFilePath = findFlagValueDefault(argc,argv,"-ttfFilePath","./SauceCodeProNerdFontPropo-Regular.ttf");
91-
auto const fffiInFile = findFlagValueDefault(argc, argv, "-fffiInFile", nullptr);
92-
auto const fffiOutFile = findFlagValueDefault(argc, argv, "-fffiOutFile", nullptr);
93-
auto const fontDyFudge = findFlagValueDefault(argc, argv, "-fontDyFudge", "0.0");
94-
95-
{
96-
auto const fontDyFudgeNum = strtof(fontDyFudge, nullptr);
97-
if(!isnanf(fontDyFudgeNum) && fontDyFudgeNum >= -10000.0f && fontDyFudgeNum <= 10000.0f) {
98-
fprintf(stderr,"using font dy fudge value %f px to modify font baseline\n", fontDyFudgeNum);
99-
ImGui::skiaFontDyFudge = fontDyFudgeNum;
100-
}
101-
}
102-
103-
if(hasFlag(argc,argv,"-help")) {
104-
showUsage(argv[0],stderr);
105-
exit(0);
106-
}
68+
opts.parse(argc,argv);
69+
ImGui::skiaFontDyFudge = opts.fontDyFudge;
10770

108-
const auto standalone = hasFlag(argc, argv, "-disableFffi");
109-
if(!standalone) {
110-
if(fffiInFile != nullptr) {
111-
fdIn = fopen(fffiInFile, "r");
71+
if(opts.fffiInterpreter) {
72+
if(opts.fffiInFile != nullptr) {
73+
fdIn = fopen(opts.fffiInFile, "r");
11274
if(fdIn == nullptr) {
113-
fprintf(stderr, "unable to open fffInFile %s: %s", fffiInFile, strerror(errno));
75+
fprintf(stderr, "unable to open fffInFile %s: %s", opts.fffiInFile, strerror(errno));
11476
exit(1);
11577
}
11678
setvbuf(fdIn, nullptr,_IONBF,0);
11779
}
118-
if(fffiOutFile != nullptr) {
119-
fdOut = fopen(fffiOutFile, "w");
80+
if(opts.fffiOutFile != nullptr) {
81+
fdOut = fopen(opts.fffiOutFile, "w");
12082
if(fdOut == nullptr) {
121-
fprintf(stderr, "unable to open fffOutFile %s: %s", fffiOutFile, strerror(errno));
83+
fprintf(stderr, "unable to open fffOutFile %s: %s", opts.fffiOutFile, strerror(errno));
12284
exit(1);
12385
}
12486
setvbuf(fdOut, nullptr,_IONBF,0);
12587
}
12688
}
12789

128-
auto ttfData = SkData::MakeFromFileName(ttfFilePath);
90+
auto ttfData = SkData::MakeFromFileName(opts.ttfFilePath);
12991
auto fontMgr = SkFontMgr_New_Custom_Data(SkSpan<sk_sp<SkData>>(&ttfData,1));
13092

13193
const auto typeface = fontMgr->makeFromData(ttfData);
@@ -140,30 +102,37 @@ Application* Application::Create(int argc, char** argv, void* platformData) {
140102
return new ImZeroSkiaClient(argc, argv, platformData);
141103
}
142104

143-
ImZeroSkiaClient::ImZeroSkiaClient(int argc, char** argv, void* platformData)
105+
ImZeroSkiaClient::ImZeroSkiaClient(int argc, char** argv, void* platformData) : fBackendType(Window::kRaster_BackendType) {
106+
if(strcmp(opts.skiaBackendType,"gl") == 0) {
144107
#if defined(SK_GL)
145-
: fBackendType(Window::kNativeGL_BackendType)
146-
#elif defined(SK_VULKAN)
147-
: fBackendType(Window::kVulkan_BackendType)
108+
fBackendType=Window::kNativeGL_BackendType;
109+
#else
110+
fprintf(stderr,"gl backend is not supported (SK_GL not defined)\n");
111+
exit(1);
112+
#endif
113+
}
114+
if(strcmp(opts.skiaBackendType,"vulkan") == 0) {
115+
#if defined(SK_VULKAN)
116+
fBackendType=Window::kVulkan_BackendType;
148117
#else
149-
: fBackendType(Window::kRaster_BackendType)
118+
fprintf(stderr,"vulkan backend is not supported (SK_VULKAN not defined)\n");
119+
exit(1);
150120
#endif
151-
{
152-
const auto standalone = hasFlag(argc, argv, "-disableFffi");
121+
}
122+
if(strcmp(opts.skiaBackendType,"raster") == 0) {
123+
fBackendType=Window::kRaster_BackendType;
124+
}
153125

154126
SkGraphics::Init();
155127

156128
fWindow = Window::CreateNativeWindow(platformData);
157129
{
158130
auto params = DisplayParams();
159-
160-
if(hasFlag(argc,argv,"-disableVsync")) {
161-
params.fDisableVsync = true;
162-
}
131+
params.fDisableVsync = !opts.vsync;
163132
fWindow->setRequestedDisplayParams(params);
164133
}
165134

166-
fImGuiLayer = std::make_unique<ImGuiLayer>(standalone);
135+
fImGuiLayer = std::make_unique<ImGuiLayer>(&opts);
167136
fImGuiLayer->setScaleFactor(fWindow->scaleFactor());
168137

169138
// register callbacks
@@ -183,22 +152,7 @@ void ImZeroSkiaClient::updateTitle() {
183152
return;
184153
}
185154

186-
SkString title("ImZeroSkiaClient ");
187-
if (Window::kRaster_BackendType == fBackendType) {
188-
title.append("Raster");
189-
} else {
190-
#if defined(SK_GL)
191-
title.append("GL");
192-
#elif defined(SK_VULKAN)
193-
title.append("Vulkan");
194-
#elif defined(SK_DAWN)
195-
title.append("Dawn");
196-
#else
197-
title.append("Unknown GPU backend");
198-
#endif
199-
}
200-
201-
fWindow->setTitle(title.c_str());
155+
fWindow->setTitle(opts.appTitle);
202156
}
203157

204158
void ImZeroSkiaClient::onBackendCreated() {

skia/skia/modified/app.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "tools/skui/ModifierKey.h"
1616

1717
#include "ImGuiLayer.h"
18+
#include "cliOptions.h"
1819

1920
class SkSurface;
2021

0 commit comments

Comments
 (0)