documentation/kernel/drivers/graphics/renderer.h.md

89 lines
5.5 KiB
Markdown
Raw Normal View History

2023-05-28 17:16:43 +00:00
# renderer.h
The renderer is maybe a bit over-engineered and slow.
The renderer has a stack of buffers, which act like canvases.
You can create, move, hide and show buffers.
#### `graphics_buffer_layer_E` - enum
- **Standard** - The layer, where almost everything should be on
- **Overlay** - This layer should be used for stuff like a mouse cursor, that should always be visible
#### `graphics_buffer_T` - struct
| Name | Type | Description |
|---------|--------------------------|------------------------------------------------------------------------------|
| buffer | g_color_palette* | The buffer, where all the pixels are stored |
| width | uint32_t | The width of the buffer |
| height | uint32_t | The height of the buffer |
| pos_x | uint32_t | The buffers x offset (from the top-left corner) in the renderers main buffer |
| pos_y | uint32_t | The buffers y offset (from the top-left corner) in the renderers main buffer |
| blocked | bool | Thread safety block variable |
| render | bool | Controls, if the buffer will be rendered or not |
| layer | graphics_buffer_layer_E | The layer, on which the buffer will be rendered |
| prev | graphics_buffer_layer_E* | The previous buffer in the rendering queue |
| next | graphics_buffer_T* | The next buffer in the rendering queue |
#### `graphics_renderer_T` - struct
| Name | Type | Description |
|------------------------|---------------------|------------------------------------------------------------------------------------------|
| framebuffer | framebuffer_T | The systems framebuffer (requested from bootloader) |
| back_buffer | uint32_t* | The buffer, where the final image is calculated, before sending it to the framebuffer |
| buffer_size | uint64_t | The size of `back_buffer` (in bytes) |
| graphics_buffer_layers | graphics_buffer_T** | List of pointers to the first graphics_buffer_T of every layer |
| font | font_T | The font, all graphics buffers use to draw chars (could be moved to `graphics_buffer_T`) |
| initialized | bool | Indicates whether the renderer is initialized or not |
| blocked | bool | Blocking variable that is used for thread safety in graphics_renderer_update() |
#### `graphics_buffer_request(pos_x, pos_y, width, height, layer)` - function (graphics_buffer_T*)
Allocates a graphics buffer and pushes it on top of the rendering queue of **_layer_**.
#### `graphics_buffer_show(graphics_buffer)` - function (void)
Enables rendering for this buffer.
Every created buffer will be rendered by default.
#### `graphics_buffer_hide(graphics_buffer)` - function (void)
Disables rendering for this buffer.
#### `graphics_buffer_destruct(graphics_buffer)` - function (void)
Removes **_graphics_buffer_** from the rendering queue and frees its memory allocations.
#### `graphics_buffer_shift_up(graphics_buffer, shift)` - function (void)
Shifts **_graphics_buffer_**'s content **_shift_** rows up.
#### `graphics_buffer_set_pixel(graphics_buffer, x, y, color)` - function (void)
Sets a pixel with the given **_color_** at position(**_x_** | **_y_**) in **_graphics_buffer_**.
**_x_** and **_y_** are graphics buffer relative.
#### `graphics_buffer_get_pixel(graphics_buffer, x, y)` - function (color_argb_T)
Returns the color of the pixel at position(**_x_** | **_y_**) in **_graphics_buffer_**.
#### `graphics_buffer_draw_char(graphics_buffer, x, y, color, chr)` - function (void)
Draws a character (**_chr_**) at position(**_x_** | **_y_**) in **_graphics_buffer_**.
The position is the top-left corner of the char.
#### `graphics_buffer_draw_string(graphics_buffer, x, y, color, string)` - function (position_T)
Draws **_string_** at position(**_x_** | **_y_**) in **_graphics_buffer_**.
The position is the top-left corner of the string.
Returns the position after the last char of the string.
#### `graphics_renderer_init(boot_info)` - function (void)
Initializes the global graphics renderer.
Needs a pointer to `boot_info` to extract information about the framebuffer.
#### `graphics_renderer_update()` - function (void)
Updates the renderers back_buffer and swaps it into the framebuffer.
To update the back_buffer, it iterates over the rendering queue and copies every buffer to the back_buffer.
If there are overlapping graphics_buffers, it alpha-blends them.
#### `graphics_renderer_get_top_buffer(layer)` - function (graphics_buffer_T*)
Returns a pointer to the graphics_buffer, that is on top of the rendering queue of **_layer_**.
#### `graphics_renderer_get_width()` - function (uint32_t)
Returns the width of the framebuffer.
#### `graphics_renderer_get_height()` - function (uint32_t)
Returns the height of the framebuffer.