hagl icon indicating copy to clipboard operation
hagl copied to clipboard

Add surface and backend concepts

Open tuupola opened this issue 2 years ago • 6 comments

tuupola avatar May 31 '22 07:05 tuupola

Notes:

https://gist.github.com/rianhunter/0be8dc116b120ad5fdd4 https://cseweb.ucsd.edu/~calder/papers/POPL-94.pdf https://hbfs.wordpress.com/2008/12/30/the-true-cost-of-calls/ https://www.avrfreaks.net/forum/static-inline-void-function

tuupola avatar May 31 '22 07:05 tuupola

I'm a little confused on the concept, correct me:

  • Backend - it's clear what it is. It is needed to provide low-level functions that interact directly with the device. Allows you to have multiple physical devices in one project.
  • Bitmap - also clear. We can draw on it, we can use it as sprites, etc.
  • The surface - here it is not clear. What functionality does it implement? Allows you to use multiple physical devices as one screen?

UncleRus avatar May 31 '22 08:05 UncleRus

And I also want to say that I really like the way in which hagl develops.

UncleRus avatar May 31 '22 08:05 UncleRus

Surface is supposed to be same as an interface in object oriented world. Meaning you can pass any object which implements surface interface to all the drawing functions. Both backend and bitmap implement the surface interface.

However, I am bit stuck here. C is not OOP and I am not quite sure what is the best way to implement this.

One way convert backend and bitmap structs to a surface struct (which I do now). Then again this is an extra step which is not necessarily needed. Other option is to make the drawing functions accept both backend and bitmap structs by using void pointer for function parameter. Something like:

void hagl_put_pixel(void *surface, int16_t x0, int16_t y0, color_t color);

In any case the goal is that you can draw to both directly to a backend and also to a bitmap, which you can then blit to the backend (or another bitmap) later.

hagl_put_pixel(backend, 100, 150, black);
hagl_put_pixel(bitmap, 100, 150, black);

tuupola avatar May 31 '22 12:05 tuupola

How about this option (sorry if it sounds stupid): the backend always provides a single bitmap. In this case, the surface becomes unnecessary - we can draw both on the backend bitmap and on the custom one. The disadvantage is obvious - this may lead to additional buffering, which can be harmful on large full-color displays (bitmaps of their backends will take up a lot of RAM). However, this minus can be dealt with by merging the logic of bitmap and the surface - you can provide a flag inside the bitmap structure that will determine whether this bitmap is "real" or just a proxy to the backend.

UncleRus avatar Jun 05 '22 08:06 UncleRus

And I would like one more thing: right now I have a project in which I would really like to use hagl, but I can’t, because this project uses two different displays at the same time (sd1306 and sd1322), while it also assumes the possibility of changing their connection (selection of GPIO) at runtime. I think the backend concept is a great step in that direction.

UncleRus avatar Jun 05 '22 08:06 UncleRus