gfx.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #ifndef __LIB_GFX_H
  2. #define __LIB_GFX_H
  3. #include <sys/types.h>
  4. // gfx library
  5. // different graphics formats
  6. typedef enum {
  7. GFX_FORMAT_RGB_565,
  8. GFX_FORMAT_ARGB_8888,
  9. GFX_FORMAT_RGB_x888,
  10. GFX_FORMAT_MAX
  11. } gfx_format;
  12. #define MAX_ALPHA 255
  13. /**
  14. * @brief Describe a graphics drawing surface
  15. *
  16. * The gfx_surface object represents a framebuffer that can be rendered
  17. * to. Elements include a pointer to the actual pixel memory, its size, its
  18. * layout, and pointers to basic drawing functions.
  19. *
  20. * @ingroup graphics
  21. */
  22. typedef struct gfx_surface {
  23. void *ptr;
  24. bool free_on_destroy;
  25. gfx_format format;
  26. uint width;
  27. uint height;
  28. uint stride;
  29. uint pixelsize;
  30. size_t len;
  31. uint alpha;
  32. // function pointers
  33. void (*copyrect)(struct gfx_surface *, uint x, uint y, uint width, uint height, uint x2, uint y2);
  34. void (*fillrect)(struct gfx_surface *, uint x, uint y, uint width, uint height, uint color);
  35. void (*putpixel)(struct gfx_surface *, uint x, uint y, uint color);
  36. void (*flush)(uint starty, uint endy);
  37. } gfx_surface;
  38. // copy a rect from x,y with width x height to x2, y2
  39. void gfx_copyrect(gfx_surface *surface, uint x, uint y, uint width, uint height, uint x2, uint y2);
  40. // fill a rect within the surface with a color
  41. void gfx_fillrect(gfx_surface *surface, uint x, uint y, uint width, uint height, uint color);
  42. // draw a pixel at x, y in the surface
  43. void gfx_putpixel(gfx_surface *surface, uint x, uint y, uint color);
  44. // clear the entire surface with a color
  45. static inline void gfx_clear(gfx_surface *surface, uint color)
  46. {
  47. surface->fillrect(surface, 0, 0, surface->width, surface->height, color);
  48. if (surface->flush)
  49. surface->flush(0, surface->height-1);
  50. }
  51. // blend between two surfaces
  52. void gfx_surface_blend(struct gfx_surface *target, struct gfx_surface *source, uint destx, uint desty);
  53. void gfx_flush(struct gfx_surface *surface);
  54. void gfx_flush_rows(struct gfx_surface *surface, uint start, uint end);
  55. // surface setup
  56. gfx_surface *gfx_create_surface(void *ptr, uint width, uint height, uint stride, gfx_format format);
  57. // utility routine to make a surface out of a display info
  58. struct display_info;
  59. gfx_surface *gfx_create_surface_from_display(struct display_info *);
  60. // free the surface
  61. // optionally frees the buffer if the free bit is set
  62. void gfx_surface_destroy(struct gfx_surface *surface);
  63. // utility routine to fill the display with a little moire pattern
  64. void gfx_draw_pattern(void);
  65. #endif