Skip to content

Commit c82509a

Browse files
committed
fix: proper initialization sequence
1 parent 789906b commit c82509a

File tree

9 files changed

+33
-26
lines changed

9 files changed

+33
-26
lines changed

skia/main/sdl3/app.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -999,7 +999,7 @@ int App::Run(CliOptions &opts) {
999999
createContext(clearColor, dm->w, dm->h);
10001000
}
10011001

1002-
build_ImFontAtlas(*io.Fonts, fFontPaint);
1002+
//build_ImFontAtlas(*io.Fonts, fFontPaint);
10031003

10041004
if(headless) {
10051005
return mainLoopHeadless(opts, clearColor);

skia2/imzero_client_skia_sdl3_impl/imzero_client_skia_sdl3_app.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -622,13 +622,17 @@ static void printColorMode(FILE *fd) {
622622
}
623623

624624
void ImZeroClient::App::setup(ImZeroCliOptions &opts) {
625+
fApp.setup(opts.fBaseOptions); // will set up imgui, needed in render_init
626+
625627
printColorMode(stderr);
626628
// prevent SIGPIPE when writing frames or reading user interaction events
627629
//signal(SIGPIPE, SIG_IGN);
628630

629631
sk_sp<SkTypeface> typeface = nullptr;
630632
sk_sp<SkData> ttfData = nullptr;
631633
{
634+
fFffiInFile = stdin;
635+
fFffiOutFile = stdout;
632636
// setup skia/imgui shared objects
633637
if (opts.fFffiInterpreter) {
634638
if (opts.fFffiInFile != nullptr) {
@@ -650,25 +654,25 @@ void ImZeroClient::App::setup(ImZeroCliOptions &opts) {
650654
}
651655
}
652656
fFffiInterpreter = opts.fFffiInterpreter;
657+
}
658+
void ImZeroClient::App::completeFontSetup() {
653659
if (fFffiInterpreter) {
654-
//render_init(fffiInFile, fffiOutFile);
660+
render_init(fFffiInFile, fFffiOutFile);
661+
// this assumes that the font setup commands will be sent in the first batch before (not evaluated in a frame context)
662+
interpretCommands();
655663
}
656-
fApp.setup(opts.fBaseOptions);
664+
fApp.completeFontSetup();
657665
}
666+
658667
SkSurface* ImZeroClient::App::preRender(bool& done, int& width, int& height) {
659668
return fApp.preRender(done, width, height);
660669
}
661670
void ImZeroClient::App::postRender(ImGuiSkia::FrameExportFormatE frameExportFormat, SkSurface* surface, int width, int height) {
662671
return fApp.postRender(frameExportFormat, surface, width, height);
663672
}
664673
ImGuiSkia::FrameExportFormatE ImZeroClient::App::render(SkSurface* surface, int width, int height) {
665-
static bool first = true;
666674
auto const r = fApp.render(surface, width, height);
667675
if (fFffiInterpreter) {
668-
if (first) {
669-
first = false;
670-
render_init(fFffiInFile, fFffiOutFile);
671-
}
672676
render_render();
673677
}
674678
return r;

skia2/imzero_client_skia_sdl3_impl/imzero_client_skia_sdl3_app.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ namespace ImZeroClient
4141
void postPaint(SkSurface* surface, ImGuiSkia::FrameExportFormatE frameExportFormat, int width, int height);
4242

4343
void setup(ImZeroCliOptions &opts);
44+
void completeFontSetup();
4445
int mainLoop();
4546
void cleanup();
4647
private:

skia2/imzero_client_skia_sdl3_impl/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ int main(const int argc, const char** argv) {
6060

6161
ImZeroClient::App app{};
6262
app.setup(opts);
63+
app.completeFontSetup();
6364

6465
const int r = app.mainLoop();
6566
app.cleanup();

skia2/stacktrace.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ here=$(dirname "$(readlink -f "$BASH_SOURCE")")
44
cd "$here"
55
rm -f core
66
coredumpctl -1 dump --output core
7-
gdb ./imgui_skia_exe core
7+
gdb ./bin/imgui_skia_exe core

skia_minimal/example_sdl3/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ int main(int argc, const char** argv) {
1212

1313
ImGuiSkia::Driver::App app{};
1414
app.setup(opts);
15+
app.completeFontSetup();
1516
const int r = app.mainLoop();
1617
app.cleanup();
1718
return r;

skia_minimal/imgui_skia_driver_impl/imgui_skia_app_sdl3.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -218,20 +218,6 @@ void ImGuiSkia::Driver::App::postPaint(SkSurface *surface, FrameExportFormatE fr
218218

219219
FrameMark;
220220
}
221-
static void build_ImFontAtlas(ImFontAtlas& atlas, SkPaint& fontPaint) {
222-
int w, h;
223-
unsigned char* pixels;
224-
atlas.GetTexDataAsAlpha8(&pixels, &w, &h);
225-
SkImageInfo info = SkImageInfo::MakeA8(w, h);
226-
const SkPixmap pmap(info, pixels, info.minRowBytes());
227-
const SkMatrix localMatrix = SkMatrix::Scale(1.0f / static_cast<float>(w), 1.0f / static_cast<float>(h));
228-
const auto fontImage = SkImages::RasterFromPixmap(pmap, nullptr, nullptr);
229-
const auto fontShader = fontImage->makeShader(SkSamplingOptions(SkFilterMode::kLinear), localMatrix);
230-
fontPaint.setShader(fontShader);
231-
fontPaint.setColor(SK_ColorWHITE);
232-
const ImTextureID texId = reinterpret_cast<intptr_t>(&fontPaint);
233-
atlas.TexID = texId;
234-
}
235221

236222
void ImGuiSkia::Driver::App::setup(CliOptions &opts) {
237223
// prevent SIGPIPE when writing frames or reading user interaction events
@@ -443,10 +429,24 @@ void ImGuiSkia::Driver::App::setup(CliOptions &opts) {
443429
}
444430
}
445431

446-
447432
createContext(initialWindowWidth, initialWindowHeight);
448-
build_ImFontAtlas(*((ImGui::GetIO()).Fonts), fFontPaint);
449433
}
434+
void ImGuiSkia::Driver::App::completeFontSetup() {
435+
ImFontAtlas &atlas = *((ImGui::GetIO()).Fonts);
436+
int w, h;
437+
unsigned char* pixels;
438+
atlas.GetTexDataAsAlpha8(&pixels, &w, &h);
439+
const SkImageInfo info = SkImageInfo::MakeA8(w, h);
440+
const SkPixmap pmap(info, pixels, info.minRowBytes());
441+
const SkMatrix localMatrix = SkMatrix::Scale(1.0f / static_cast<float>(w), 1.0f / static_cast<float>(h));
442+
const auto fontImage = SkImages::RasterFromPixmap(pmap, nullptr, nullptr);
443+
const auto fontShader = fontImage->makeShader(SkSamplingOptions(SkFilterMode::kLinear), localMatrix);
444+
fFontPaint.setShader(fontShader);
445+
fFontPaint.setColor(SK_ColorWHITE);
446+
const ImTextureID texId = reinterpret_cast<intptr_t>(&fFontPaint);
447+
atlas.TexID = texId;
448+
}
449+
450450
SkSurface * ImGuiSkia::Driver::App::preRender(bool &done, int &width, int &height) {
451451
const ImGuiIO &io = ImGui::GetIO();
452452
width = static_cast<int>(io.DisplaySize.x);

skia_minimal/imgui_skia_driver_impl/imgui_skia_app_sdl3.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ namespace ImGuiSkia::Driver {
2020
void postPaint(SkSurface* surface, FrameExportFormatE frameExportFormat, int width, int height);
2121

2222
void setup(CliOptions &opts);
23+
void completeFontSetup();
2324
int mainLoop();
2425
void cleanup();
2526

skia_minimal/imgui_skia_impl/imgui_skia_hooks_impl.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#pragma once
22

33
#include "imgui_skia_config.h"
4-
#include "include/core/SkFont.h"
54
#include "imgui_skia_paragraph.h"
65

76
// NOTE: part of ImDrawChannel as std::vector and FlatBufferBuilder are not trivially default constructible

0 commit comments

Comments
 (0)