blob: 2f251e4ad8dd82076887571c40d01254efb01d13 [file] [log] [blame]
Travis Geiselbrechte06c67c2010-05-21 22:30:10 -07001#ifndef __LIB_GFX_H
2#define __LIB_GFX_H
3
4#include <sys/types.h>
5
6// gfx library
7
8// different graphics formats
9typedef 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 */
28typedef 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
47void 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
50void 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
53void gfx_putpixel(gfx_surface *surface, uint x, uint y, uint color);
54
55// clear the entire surface with a color
56static 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
65void gfx_surface_blend(struct gfx_surface *target, struct gfx_surface *source, uint destx, uint desty);
66
67void gfx_flush(struct gfx_surface *surface);
68
69void gfx_flush_rows(struct gfx_surface *surface, uint start, uint end);
70
71// surface setup
72gfx_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
75struct display_info;
76gfx_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
80void gfx_surface_destroy(struct gfx_surface *surface);
81
82// utility routine to fill the display with a little moire pattern
83void gfx_draw_pattern(void);
84
85#endif
86