37 #include <stdatomic.h> 43 #include "liblfds711.h" 45 #define lfds720_freelist_n_element lfds711_freelist_element 46 #define lfds720_ringbuffer_n_element lfds711_ringbuffer_element 47 #define lfds720_ringbuffer_n_state lfds711_ringbuffer_state 48 #define lfds720_freelist_n_state lfds711_freelist_state 49 #define LFDS720_PAL_ATOMIC_ISOLATION_LENGTH_IN_BYTES LFDS711_PAL_ATOMIC_ISOLATION_IN_BYTES 50 #define lfds720_ringbuffer_n_init_valid_on_current_logical_core lfds711_ringbuffer_init_valid_on_current_logical_core 51 #define lfds720_freelist_n_init_valid_on_current_logical_core lfds711_freelist_init_valid_on_current_logical_core 52 #define LFDS720_FREELIST_N_SET_VALUE_IN_ELEMENT LFDS711_FREELIST_SET_VALUE_IN_ELEMENT 53 #define LFDS720_FREELIST_N_GET_VALUE_FROM_ELEMENT LFDS711_FREELIST_GET_VALUE_FROM_ELEMENT 54 #define lfds720_freelist_n_threadsafe_push lfds711_freelist_push 55 #define lfds720_freelist_n_threadsafe_pop lfds711_freelist_pop 56 #define lfds720_ringbuffer_n_cleanup lfds711_ringbuffer_cleanup 57 #define lfds720_freelist_n_cleanup lfds711_freelist_cleanup 58 #define lfds720_ringbuffer_n_read lfds711_ringbuffer_read 59 #define lfds720_ringbuffer_n_write lfds711_ringbuffer_write 60 #define lfds720_misc_flag lfds711_misc_flag 61 #define LFDS720_MISC_FLAG_RAISED LFDS711_MISC_FLAG_RAISED 62 #define LFDS720_MISC_MAKE_VALID_ON_CURRENT_LOGICAL_CORE_INITS_COMPLETED_BEFORE_NOW_ON_ANY_OTHER_PHYSICAL_CORE LFDS711_MISC_MAKE_VALID_ON_CURRENT_LOGICAL_CORE_INITS_COMPLETED_BEFORE_NOW_ON_ANY_OTHER_LOGICAL_CORE 63 #define lfds720_pal_uint_t lfds711_pal_uint_t 65 #include "liblfds720.h" 189 atomic_uint_fast16_t fps;
198 struct timeval fps_start;
200 struct timeval fps_stop;
225 unsigned int parallel_tasks;
232 struct _fbg_fragment **fragments;
235 pthread_barrier_t *sync_barrier;
245 unsigned int fragment_queue_size;
253 struct _fbg_freelist_data {
254 struct lfds720_freelist_n_element freelist_element;
256 unsigned char *buffer;
262 struct _fbg_fragment {
270 struct lfds720_ringbuffer_n_element *ringbuffer_element;
273 struct lfds720_ringbuffer_n_state *ringbuffer_state;
276 struct lfds720_freelist_n_state *freelist_state;
279 struct _fbg_freelist_data *fbg_freelist_data;
282 struct _fbg_freelist_data *tmp_fbg_freelist_data;
286 atomic_int sync_wait;
289 void *(*user_fragment_start)(
struct _fbg *fbg);
291 void (*user_fragment)(
struct _fbg *fbg,
void *user_data);
293 void (*user_fragment_stop)(
struct _fbg *fbg,
void *user_data);
317 extern struct _fbg *
fbg_customSetup(
int width,
int height,
int components,
int initialize_buffers,
int allow_resizing,
void *
user_context,
void (*
user_draw)(
struct _fbg *fbg),
void (*
user_flip)(
struct _fbg *fbg),
void (*
backend_resize)(
struct _fbg *fbg,
unsigned int new_width,
unsigned int new_height),
void (*
user_free)(
struct _fbg *fbg));
371 extern void fbg_fadeUp(
struct _fbg *fbg,
unsigned char rgb_fade_amount);
379 extern void fbg_clear(
struct _fbg *fbg,
unsigned char brightness);
389 extern void fbg_fill(
struct _fbg *fbg,
unsigned char r,
unsigned char g,
unsigned char b);
410 extern void fbg_pixel(
struct _fbg *fbg,
int x,
int y,
unsigned char r,
unsigned char g,
unsigned char b);
423 extern void fbg_pixela(
struct _fbg *fbg,
int x,
int y,
unsigned char r,
unsigned char g,
unsigned char b,
unsigned char a);
441 extern void fbg_plot(
struct _fbg *fbg,
int index,
unsigned char value);
455 extern void fbg_rect(
struct _fbg *fbg,
int x,
int y,
int w,
int h,
unsigned char r,
unsigned char g,
unsigned char b);
470 extern void fbg_recta(
struct _fbg *fbg,
int x,
int y,
int w,
int h,
unsigned char r,
unsigned char g,
unsigned char b,
unsigned char a);
481 extern void fbg_frect(
struct _fbg *fbg,
int x,
int y,
int w,
int h);
494 extern void fbg_hline(
struct _fbg *fbg,
int x,
int y,
int w,
unsigned char r,
unsigned char g,
unsigned char b);
507 extern void fbg_vline(
struct _fbg *fbg,
int x,
int y,
int h,
unsigned char r,
unsigned char g,
unsigned char b);
521 extern void fbg_line(
struct _fbg *fbg,
int x1,
int y1,
int x2,
int y2,
unsigned char r,
unsigned char g,
unsigned char b);
532 extern void fbg_polygon(
struct _fbg *fbg,
int num_vertices,
int *vertices,
unsigned char r,
unsigned char g,
unsigned char b);
571 extern void fbg_draw(
struct _fbg *fbg,
void (*user_mixing)(
struct _fbg *fbg,
unsigned char *buffer,
int task_id));
685 extern void fbg_imageEx(
struct _fbg *fbg,
struct _fbg_img *img,
int x,
int y,
float sx,
float sy,
int cx,
int cy,
int cw,
int ch);
798 extern float fbg_randf(
float min,
float max);
809 extern void fbg_createFragment(
struct _fbg *fbg,
void *(*fragment_start)(
struct _fbg *fbg),
void (*fragment)(
struct _fbg *fbg,
void *user_data),
void (*fragment_stop)(
struct _fbg *fbg,
void *user_data),
unsigned int parallel_tasks);
819 #define fbg_fade(fbg, fade_amount) fbg_fadeDown(fbg, fade_amount) 829 #define fbg_write(fbg, text, x, y) fbg_text(fbg, &fbg->current_font, text, x, y, fbg->text_color.r, fbg->text_color.g, fbg->text_color.b) 841 #define fbg_imageScale(fbg, img, x, y, sx, sy) fbg_imageEx(fbg, img, x, y, sx, sy, 0, 0, img->width, img->height) 844 #define _FBG_MAX(a,b) ((a) > (b) ? a : b) 845 #define _FBG_MIN(a,b) ((a) < (b) ? a : b) 847 #define _FBG_SGN(x) ((x<0)?-1:((x>0)?1:0)) 851 #define _FBG_DEGTORAD(angle_degree) ((angle_degree) * M_PI / 180.0) 852 #define _FBG_RADTODEG(angle_radians) ((angle_radians) * 180.0 / M_PI) 855 #define _FBG_SOURCE_OVER(a,b,c) (c * a + b * (1.f - a))
void fbg_text(struct _fbg *fbg, struct _fbg_font *fnt, char *text, int x, int y, int r, int g, int b)
draw a text
void fbg_imageClip(struct _fbg *fbg, struct _fbg_img *img, int x, int y, int cx, int cy, int cw, int ch)
draw a clipped image
struct _fbg_font * fbg_createFont(struct _fbg *fbg, struct _fbg_img *img, int glyph_width, int glyph_height, unsigned char first_char)
create a bitmap font from an image
unsigned char first_char
First ASCII character of the bitmap font file.
int text_alpha
Text background alpha value.
void fbg_setResizeCallback(struct _fbg *fbg, void(*user_resize)(struct _fbg *fbg, unsigned int new_width, unsigned int new_height))
register a user resize callback
void(* user_draw)(struct _fbg *fbg)
User-defined draw function.
int initialize_buffers
Wether to allow FBG to allocate its internal buffers.
int components
Display components amount (3 = 24 BPP / 4 = 32 BPP)
unsigned char * back_buffer
Back buffer.
void fbg_drawFramerate(struct _fbg *fbg, struct _fbg_font *fnt, int task, int x, int y, int r, int g, int b)
draw the framerate of a particular parallel task
int glyph_width
Width of a glyph.
void fbg_imageFlip(struct _fbg_img *img)
flip an image vertically
struct _fbg_img * fbg_loadImage(struct _fbg *fbg, const char *filename)
load an image (PNG or JPEG)
RGBA color data structure.
void fbg_clear(struct _fbg *fbg, unsigned char brightness)
fast grayscale background clearing
void fbg_textColorKey(struct _fbg *fbg, unsigned char v)
set the current text color key
struct _fbg_img * fbg_loadPNG(struct _fbg *fbg, const char *filename)
load a PNG image from a file (lodePNG library)
struct _fbg * fbg_customSetup(int width, int height, int components, int initialize_buffers, int allow_resizing, void *user_context, void(*user_draw)(struct _fbg *fbg), void(*user_flip)(struct _fbg *fbg), void(*backend_resize)(struct _fbg *fbg, unsigned int new_width, unsigned int new_height), void(*user_free)(struct _fbg *fbg))
initialize a FB Graphics context (typically used by a custom rendering backend)
int size
Framebuffer real data length (with BPP)
void fbg_textColor(struct _fbg *fbg, unsigned char r, unsigned char g, unsigned char b)
set the current text color
void fbg_rect(struct _fbg *fbg, int x, int y, int w, int h, unsigned char r, unsigned char g, unsigned char b)
draw a rectangle
int width
Display width in pixels.
void fbg_fpixel(struct _fbg *fbg, int x, int y)
fast pixel drawing which use the fill color set by fbg_fill()
int new_width
Requested new display width (resize event)
int new_height
Requested new display height (resize event)
void(* user_flip)(struct _fbg *fbg)
User-defined flip function.
int allow_resizing
Wether to allow context resize.
void fbg_fadeDown(struct _fbg *fbg, unsigned char rgb_fade_amount)
background fade to black with controllable factor
int line_length
Internal buffers line length.
int width_n_height
Display lenght in pixels (width * height)
void fbg_background(struct _fbg *fbg, unsigned char r, unsigned char g, unsigned char b)
clear the background with a color
int height
Display height in pixels.
void fbg_recta(struct _fbg *fbg, int x, int y, int w, int h, unsigned char r, unsigned char g, unsigned char b, unsigned char a)
draw a rectangle with alpha transparency
unsigned char * data
RGB image data (bpp depend on framebuffer settings)
void(* user_free)(struct _fbg *fbg)
User-defined free function.
unsigned char * temp_buffer
Temporary buffer.
void fbg_imageColorkey(struct _fbg *fbg, struct _fbg_img *img, int x, int y, int cr, int cg, int cb)
draw an image with colorkeying support (image colorkey value will be ignored)
void(* backend_resize)(struct _fbg *fbg, unsigned int new_width, unsigned int new_height)
Backend resize function.
void fbg_rgbToHsl(struct _fbg_hsl *color, float r, float g, float b)
convert RGB values to HSL color
void fbg_pushResize(struct _fbg *fbg, int new_width, int new_height)
void fbg_flip(struct _fbg *fbg)
flip the buffers
void fbg_close(struct _fbg *fbg)
free up the memory associated with a FB Graphics context and close the framebuffer device ...
void fbg_polygon(struct _fbg *fbg, int num_vertices, int *vertices, unsigned char r, unsigned char g, unsigned char b)
draw a polygon
void fbg_image(struct _fbg *fbg, struct _fbg_img *img, int x, int y)
draw an image
int fbg_getFramerate(struct _fbg *fbg, int task)
get the framerate of a particular task
void fbg_textFont(struct _fbg *fbg, struct _fbg_font *font)
set the current font
int * glyph_coord_y
Pre-computed Y glyphs coordinates.
void fbg_pixel(struct _fbg *fbg, int x, int y, unsigned char r, unsigned char g, unsigned char b)
draw a pixel
struct _fbg_img * bitmap
Associated font image data structure.
void fbg_draw(struct _fbg *fbg)
draw to the screen
void fbg_fadeUp(struct _fbg *fbg, unsigned char rgb_fade_amount)
background fade to white with controllable factor
void * user_context
User-defined context structure.
void fbg_freeImage(struct _fbg_img *img)
free the memory associated with an image
void(* user_resize)(struct _fbg *fbg, unsigned int new_width, unsigned int new_height)
User-defined resize function.
void fbg_fill(struct _fbg *fbg, unsigned char r, unsigned char g, unsigned char b)
set the filling color for fast drawing operations
unsigned int height
Image height in pixels.
int glyph_height
Height of a glyph.
void fbg_freeFont(struct _fbg_font *font)
free the memory associated with a font
unsigned char text_colorkey
Current text color key.
struct _fbg_img * fbg_loadJPEG(struct _fbg *fbg, const char *filename)
load a JPEG image from a file (NanoJPEG library)
void fbg_hslToRGB(struct _fbg_rgb *color, float h, float s, float l)
convert HSL values to RGB color
int comp_offset
Offset to add in case of 32 BPP.
FB Graphics context data structure.
void fbg_pixela(struct _fbg *fbg, int x, int y, unsigned char r, unsigned char g, unsigned char b, unsigned char a)
draw a pixel with alpha component (alpha blending)
void fbg_drawInto(struct _fbg *fbg, unsigned char *buffer)
set an offscreen target for all subsequent fbg context draw calls, it is important to reset back to d...
float fbg_randf(float min, float max)
pseudo random number between min / max
unsigned int width
Image width in pixels.
Bitmap font data structure.
void fbg_vline(struct _fbg *fbg, int x, int y, int h, unsigned char r, unsigned char g, unsigned char b)
draw a vertical line
void fbg_textBackground(struct _fbg *fbg, int r, int g, int b, int a)
set the current text background color (based on colorkey value!)
struct _fbg_img * fbg_createImage(struct _fbg *fbg, unsigned int width, unsigned int height)
create an empty image
HSL color data structure.
int bgr
Flag indicating a BGR framebuffer.
unsigned char * disp_buffer
Front / display buffer.
void fbg_plot(struct _fbg *fbg, int index, unsigned char value)
direct pixel access from index value
void fbg_imageEx(struct _fbg *fbg, struct _fbg_img *img, int x, int y, float sx, float sy, int cx, int cy, int cw, int ch)
draw an image with support for clipping and scaling (Nearest-neighbor algorithm)
void fbg_hline(struct _fbg *fbg, int x, int y, int w, unsigned char r, unsigned char g, unsigned char b)
draw a horizontal line
void fbg_resize(struct _fbg *fbg, int new_width, int new_height)
void fbg_getPixel(struct _fbg *fbg, int x, int y, struct _fbg_rgb *color)
get the RGB value of a pixel
void fbg_line(struct _fbg *fbg, int x1, int y1, int x2, int y2, unsigned char r, unsigned char g, unsigned char b)
draw a line from two points (Bresenham algorithm)
int compositing
Compositing method (only used with fbg_drawImage for now)
int * glyph_coord_x
Pre-computed X glyphs coordinates.
int frame
Frame counter for the current second.
void fbg_frect(struct _fbg *fbg, int x, int y, int w, int h)
fast rectangle drawing which use the fill color set by fbg_fill()