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