From 6bc532b54c8745fd1b1382122988b0ee4668ca10 Mon Sep 17 00:00:00 2001 From: grz0zrg Date: Tue, 26 Sep 2023 20:01:35 +0200 Subject: [PATCH] fix special cases resize when parallelism is in use --- examples/Makefile | 2 +- examples/tiny.c | 39 +++++++++++++++++++++++++++++++++++++++ src/fbgraphics.c | 12 ++++++++---- 3 files changed, 48 insertions(+), 5 deletions(-) create mode 100644 examples/tiny.c diff --git a/examples/Makefile b/examples/Makefile index fe4da77..0783d4a 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -38,7 +38,7 @@ all: $(CC) $(SRC7) $(INCS) $(STANDARD_FLAGS) $(DEFP) $(RELEASE_FLAGS) $(LIBS2) -o $(OUT7) tiny: - $(CC) ../custom_backend/fbdev/fbg_fbdev.c ../src/fbgraphics.c simple_parallel_example.c $(INCS) $(STANDARD_FLAGS) $(DEFP) -fdata-sections -ffunction-sections -flto -DFBG_LIGHT -Os -lpthread -o $(OUT2) -Wl,--gc-sections,-flto + $(CC) ../custom_backend/fbdev/fbg_fbdev.c ../src/fbgraphics.c tiny.c $(INCS) $(STANDARD_FLAGS) -fdata-sections -ffunction-sections -flto -DWITHOUT_STB_IMAGE -DWITHOUT_JPEG -DWITHOUT_PNG -Os -o tiny -Wl,--gc-sections,-flto debug: $(CC) $(SRC1) $(INCS) $(STANDARD_FLAGS) $(DEBUG_FLAGS) $(LIBS1) -o $(OUT1) diff --git a/examples/tiny.c b/examples/tiny.c new file mode 100644 index 0000000..945af8e --- /dev/null +++ b/examples/tiny.c @@ -0,0 +1,39 @@ +#include +#include + +#include "fbgraphics.h" +#include "fbg_fbdev.h" // insert any backends from ../custom_backend/backend_name folder + +int keep_running = 1; + +void int_handler(int dummy) { + keep_running = 0; +} + +int main(int argc, char* argv[]) { + signal(SIGINT, int_handler); + + // open "/dev/fb0" by default, use fbg_fbdevSetup("/dev/fb1", 0) if you want to use another framebuffer + // note : fbg_fbdevInit is the linux framebuffer backend, you can use a different backend easily by including the proper header and compiling with the appropriate backend file found in ../custom_backend/backend_name + struct _fbg *fbg = fbg_fbdevInit(); + if (fbg == NULL) { + return 0; + } + + do { + fbg_clear(fbg, 0); // can also be replaced by fbg_background(fbg, 0, 0, 0); + + fbg_draw(fbg); + + fbg_rect(fbg, fbg->width / 2 - 8, fbg->height / 2 - 8, 16, 16, 0, 255, 0); + + fbg_pixel(fbg, fbg->width / 2, fbg->height / 2, 255, 0, 0); + + fbg_flip(fbg); + + } while (keep_running); + + fbg_close(fbg); + + return 0; +} diff --git a/src/fbgraphics.c b/src/fbgraphics.c index 2f6254c..5cf4aa1 100644 --- a/src/fbgraphics.c +++ b/src/fbgraphics.c @@ -225,6 +225,10 @@ void fbg_resize(struct _fbg *fbg, int new_width, int new_height) { fbg->size = new_size; + if (fbg->user_resize) { + fbg->user_resize(fbg, new_width, new_height); + } + #ifdef FBG_PARALLEL if (fbg->tasks || create_fragments) { if (!user_fragment_start) { @@ -242,10 +246,10 @@ void fbg_resize(struct _fbg *fbg, int new_width, int new_height) { fbg_createFragment(fbg, user_fragment_start, user_fragment, user_fragment_stop, parallel_tasks); } #endif - } - - if (fbg->user_resize) { - fbg->user_resize(fbg, new_width, new_height); + } else { + if (fbg->user_resize) { + fbg->user_resize(fbg, new_width, new_height); + } } }