UEFIStarter
a simple UEFI framework
graphics.h
Go to the documentation of this file.
1 
11 #ifndef __GRAPHICS_H
12 #define __GRAPHICS_H
13 
14 #include <Uefi.h>
15 #include <Protocol/GraphicsOutput.h>
16 #include "core/cmdline.h"
17 #include "core/files.h"
18 #include "core/logger.h"
19 
20 #define COLOR EFI_GRAPHICS_OUTPUT_BLT_PIXEL
21 #define SPRITE EFI_GRAPHICS_OUTPUT_BLT_PIXEL *
22 #define GFX_BUFFER EFI_GRAPHICS_OUTPUT_BLT_PIXEL *
25 extern EFI_GRAPHICS_OUTPUT_PROTOCOL *graphics_protocol;
26 extern EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *graphics_info;
29 extern UINTN graphics_fs_pages;
30 extern UINTN graphics_fs_pixel_count;
31 
32 #define ARG_MODE graphics_argument_list[0].value.uint64
33 #define ARG_VSYNC graphics_argument_list[1].value.uint64
34 #define ARG_FPS graphics_argument_list[2].value.uint64
35 #define ARG_DISPLAY graphics_argument_list[3].value.uint64
36 extern cmdline_argument_t graphics_argument_list[];
38 
39 
40 /**********
41  * General
42  */
43 
44 EFI_STATUS init_graphics();
45 void shutdown_graphics();
46 
48 void free_graphics_fs_buffer(void *addr);
49 EFI_STATUS graphics_fs_blt(GFX_BUFFER buffer);
50 
51 EFI_GRAPHICS_OUTPUT_PROTOCOL *get_graphics_protocol(); //move to init and make field static?
52 EFI_STATUS draw_filled_rect(EFI_GRAPHICS_OUTPUT_PROTOCOL *gop, UINTN x, UINTN y, UINTN width, UINTN height, COLOR *color);
53 void print_graphics_modes(EFI_GRAPHICS_OUTPUT_PROTOCOL *gop);
54 EFI_STATUS set_graphics_mode(EFI_GRAPHICS_OUTPUT_PROTOCOL *gop, int mode);
55 EFI_STATUS query_current_mode(EFI_GRAPHICS_OUTPUT_PROTOCOL *gop, EFI_GRAPHICS_OUTPUT_MODE_INFORMATION **info);
56 void wait_vsync();
57 BOOLEAN limit_framerate(UINT64 *previous, UINT64 minimum_frame_ticks);
58 
59 typedef double trig_func(double);
62 
63 
64 /*********
65  * Images
66  */
67 
69 typedef struct
70 {
71  UINTN memory_pages;
72  UINT32 width;
73  UINT32 height;
74  EFI_GRAPHICS_OUTPUT_BLT_PIXEL data[];
75 } image_t;
76 
78 typedef struct
79 {
81  CHAR16 *filename;
83 
84 
88 
89 image_t *load_ppm_file(CHAR16 *filename);
90 image_t *load_pgm_file(CHAR16 *filename);
91 image_t *load_pbm_file(CHAR16 *filename);
92 image_t *load_netpbm_file(CHAR16 *filename);
93 image_t *create_image(INTN width, INTN height);
94 void free_image(image_t *image);
95 void load_image_assets(UINTN count, image_asset_t *assets);
96 void free_image_assets(UINTN count, image_asset_t *assets);
97 
98 COLOR interpolate_2px(COLOR *colors, float ratio);
99 COLOR interpolate_4px(COLOR *corners, UINTN row_width, float x, float y);
100 void rotate_image(SPRITE original, SPRITE rotated, INTN radius, float theta);
101 
102 
103 /********
104  * Fonts
105  */
106 
108 typedef struct
109 {
110  CHAR16 chr;
111  UINT8 data[8*15];
112 } glyph_t;
113 
115 typedef struct
116 {
117  UINT32 memory_pages;
118  UINT16 glyph_count;
119  glyph_t glyphs[];
120 } glyph_list_t;
121 
122 glyph_list_t *parse_glyphs(image_t *image, CHAR16 *text);
124 void draw_text(SPRITE buffer, UINTN buffer_width, glyph_list_t *glyphs, UINT32 x, UINT32 y, COLOR color, CHAR16 *text);
125 void draw_glyph(SPRITE start, UINTN buffer_width, glyph_t *glyph, COLOR color);
126 void free_glyphs(glyph_list_t *glyphs);
127 
128 
129 #endif
UINTN graphics_fs_height
screen height, in pixels
Definition: graphics.c:26
COLOR interpolate_2px(COLOR *colors, float ratio)
Performs linear interpolation of a pixel value between 2 pixels.
Definition: graphics.c:359
EFI_STATUS query_current_mode(EFI_GRAPHICS_OUTPUT_PROTOCOL *gop, EFI_GRAPHICS_OUTPUT_MODE_INFORMATION **info)
Fetches information about the current graphics mode.
Definition: graphics.c:659
void rotate_image(SPRITE original, SPRITE rotated, INTN radius, float theta)
Rotates an image by an arbitrary angle.
Definition: graphics.c:376
void print_graphics_modes(EFI_GRAPHICS_OUTPUT_PROTOCOL *gop)
Prints the list of available graphics modes.
Definition: graphics.c:562
EFI_STATUS graphics_fs_blt(GFX_BUFFER buffer)
Outputs a full-screen graphics buffer to the graphics display.
Definition: graphics.c:952
void draw_text(SPRITE buffer, UINTN buffer_width, glyph_list_t *glyphs, UINT32 x, UINT32 y, COLOR color, CHAR16 *text)
Draws text to a sprite or output buffer.
Definition: graphics.c:804
EFI_STATUS init_graphics()
Initializes the graphics output.
Definition: graphics.c:963
UINTN graphics_fs_pixel_count
number of pixels in output buffer
Definition: graphics.c:29
UINT32 width
the image&#39;s width, in pixels
Definition: graphics.h:72
BOOLEAN limit_framerate(UINT64 *previous, UINT64 minimum_frame_ticks)
Limits graphics animation framerates.
Definition: graphics.c:904
#define GFX_BUFFER
shortcut macro: indicates pixel data is intended to be used as a screen buffer
Definition: graphics.h:22
EFI_GRAPHICS_OUTPUT_MODE_INFORMATION * graphics_info
UEFI&#39;s graphics info.
Definition: graphics.c:24
void free_image(image_t *image)
Frees an image resource.
Definition: graphics.c:513
data type for list of glyphs, size is dynamic
Definition: graphics.h:115
image_t * load_netpbm_file(CHAR16 *filename)
Reads a netpbm file, determines the image format by the file&#39;s extension.
Definition: graphics.c:481
UINT32 memory_pages
the number of allocated memory pages
Definition: graphics.h:117
glyph_list_t * load_font()
Parses the font file.
Definition: graphics.c:739
image_t * load_pbm_file(CHAR16 *filename)
Reads a netpbm PBM (black/white bitmap) file.
Definition: graphics.c:470
void free_glyphs(glyph_list_t *glyphs)
Frees a previously allocated list of glyphs.
Definition: graphics.c:850
EFI_GRAPHICS_OUTPUT_PROTOCOL * get_graphics_protocol()
Fetches the UEFI graphics output protocol handle.
Definition: graphics.c:607
void free_graphics_fs_buffer(void *addr)
Frees a full-screen graphics buffer.
Definition: graphics.c:940
cmdline_argument_group_t graphics_arguments
group for graphics-related arguments
Definition: graphics.c:90
UINTN memory_pages
the number of memory pages allocated
Definition: graphics.h:71
Data structure for file contents.
Definition: files.h:22
image_t * load_ppm_file(CHAR16 *filename)
Reads a netpbm PPM (color) file.
Definition: graphics.c:448
image_t * parse_pgm_image_data(file_contents_t *contents)
Parses a PGM (grayscale) image.
Definition: graphics.c:280
UINT32 height
the image&#39;s height, in pixels
Definition: graphics.h:73
void draw_glyph(SPRITE start, UINTN buffer_width, glyph_t *glyph, COLOR color)
Draws a single glyph to a sprite or output buffer.
Definition: graphics.c:774
CHAR16 chr
the character the glyph is for
Definition: graphics.h:110
void wait_vsync()
Waits for the graphics card&#39;s vertical synchronisation event.
Definition: graphics.c:866
data type for image data, size is dynamic
Definition: graphics.h:69
glyph_list_t * parse_glyphs(image_t *image, CHAR16 *text)
Parses a font sprite sheet.
Definition: graphics.c:699
image_t * load_pgm_file(CHAR16 *filename)
Reads a netpbm PGM (grayscale) file.
Definition: graphics.c:459
image_t * create_image(INTN width, INTN height)
Allocates and initializes an image.
Definition: graphics.c:184
#define COLOR
shortcut macro: indicates pixel data is intended to be used as paint color
Definition: graphics.h:20
EFI_STATUS set_graphics_mode(EFI_GRAPHICS_OUTPUT_PROTOCOL *gop, int mode)
Sets the graphics mode.
Definition: graphics.c:640
void load_image_assets(UINTN count, image_asset_t *assets)
Loads a list of image assets.
Definition: graphics.c:530
Logging facility, supports verbosity levels.
UINT16 glyph_count
the number of glyphs in this list
Definition: graphics.h:118
GFX_BUFFER create_graphics_fs_buffer()
Creates a full-screen graphics buffer.
Definition: graphics.c:926
UINTN graphics_fs_pages
number of pages for output buffer
Definition: graphics.c:28
void set_graphics_cos_func(trig_func *f)
Sets the cos() function pointer to use in graphics operations.
Definition: graphics.c:50
EFI_STATUS draw_filled_rect(EFI_GRAPHICS_OUTPUT_PROTOCOL *gop, UINTN x, UINTN y, UINTN width, UINTN height, COLOR *color)
Draws an unbuffered rectangle to the screen.
Definition: graphics.c:594
image_t ** image
the asset&#39;s content
Definition: graphics.h:80
void free_image_assets(UINTN count, image_asset_t *assets)
Frees a list of image assets.
Definition: graphics.c:544
UINTN graphics_fs_width
screen width, in pixels
Definition: graphics.c:25
COLOR interpolate_4px(COLOR *corners, UINTN row_width, float x, float y)
Performs bilinear interpolation of a pixel value within a square of 4 surrounding pixels...
Definition: graphics.c:326
File handling functions.
GFX_BUFFER graphics_fs_buffer
full-screen output buffer
Definition: graphics.c:27
void set_graphics_sin_func(trig_func *f)
Sets the sin() function pointer to use in graphics operations.
Definition: graphics.c:40
model for group of command line arguments
Definition: cmdline.h:50
Command line parameter parser.
void shutdown_graphics()
Shuts down the graphics features.
Definition: graphics.c:1002
double trig_func(double)
data type for trigonometry function pointers
Definition: graphics.h:59
#define SPRITE
shortcut macro: indicates pixel data is intended to be as a drawable image
Definition: graphics.h:21
data type for individual 8x15 font glyphs
Definition: graphics.h:108
image_t * parse_pbm_image_data(file_contents_t *contents)
Parses a PBM (black/white bitmap) image.
Definition: graphics.c:291
data type for image assets
Definition: graphics.h:78
CHAR16 * filename
the asset&#39;s filename
Definition: graphics.h:81
image_t * parse_ppm_image_data(file_contents_t *contents)
Parses a PPM (color) image.
Definition: graphics.c:269