tuupola / hagl

Hardware Agnostic Graphics Library for embedded
https://www.appelsiini.net/tags/hagl/
MIT License
303 stars 49 forks source link

Variable display size #48

Open amb5l opened 3 years ago

amb5l commented 3 years ago

Do not initialize clip_window if display width and height may be changed at runtime - rely on HAL to initialize instead.

amb5l commented 3 years ago

Thank you for this excellent project which I am using to prove an embedded graphics controller in an FPGA. My hardware supports multiple display resolutions so the initialization of clip_window needs to change for my application.

tuupola commented 3 years ago

What can be gained by leaving the window_t clip_window empty? It forces an initial call to hagl_set_clip_window()which you probably want to do anyway after changing the resolution.

amb5l commented 3 years ago

My framebuffer driver maintains the current display size as

uint16_t fb_width;
uint16_t fb_height;

So in my hagl_hal.h I have

#define DISPLAY_WIDTH fb_width
#define DISPLAY_HEIGHT fb_height

This results in an error when compiling hagl.c: initializer element is not constant

tuupola commented 3 years ago

Yes the C preprocessor does not allow you to do that. Are you changing resolution runtime or do you configure the resolution when compiling? If the latter then you can use those configuration values as DISPLAY_WIDTH and DISPLAY_HEIGHT.

If you change resolution runtime you will run into other problems since code currently relies on DISPLAY_WIDTH and DISPLAY_HEIGHT to be defined on other places. Changing resolution runtime has not really been taken into account.

This could to be another reason why changing the API to include the surface in the API calls (see #43). Then one could do something like:

#include <hagl_hal.h>
#include <hagl.h>

surface_t s = hagl_init();

hagl_load_image(s, 0, 0, "/sdcard/foo.jpg");
hagl_hal_change_resolution(s, 320, 240);
hagl_set_clip_window(s, 0, 40, s.width, s.height - 40);
hagl_load_image(s, 0, 0, "/sdcard/bar.jpg");

hagl_close(s);

One thing to consider though is how often you have an embedded project where you to change display resolution on runtime.

amb5l commented 3 years ago

I am changing the resolution at runtime. My CPU is testing my frame buffer hardware in various resolutions. My simple tests are running OK with the change to clip_window initialization, so this is not a high priority. Let me get a more complete test working which I can show you, and which may suggest a better way forward, or perhaps that my application is an edge case not worth considering.

tuupola commented 3 years ago

Sounds good!

amb5l commented 3 years ago

My FPGA hardware and test software is working well. The repo is here and documentation for the graphics design is here. I don't think you need to take account of my application - I've forked hagl and my project links to that fork. Thanks again for a great piece of work.