From a4b246095a82fdef5a12ccdfdf862579fe32cb51 Mon Sep 17 00:00:00 2001 From: Eric-Paul I Date: Thu, 9 Mar 2023 18:04:47 +0100 Subject: [PATCH] Made first major changes; missing integration and optimization --- kernel/inc/drivers/gfx/command_queue.h | 12 +++++ .../inc/drivers/gfx/default_implementation.h | 12 +++++ kernel/inc/drivers/gfx/graphics_driver.h | 35 +++++++++++++ kernel/inc/drivers/gfx/pixelbuffer.h | 51 ++++++++++++++++++ kernel/inc/drivers/gfx/stringify.h | 12 +++++ kernel/inc/drivers/gfx/utility.h | 19 +++++++ kernel/src/drivers/gfx/command_queue.c | 2 + .../src/drivers/gfx/default_implementation.c | 2 + kernel/src/drivers/gfx/graphics_driver.c | 52 +++++++++++++++++++ kernel/src/drivers/gfx/pixelbuffer.c | 44 ++++++++++++++++ kernel/src/drivers/gfx/stringify.c | 2 + 11 files changed, 243 insertions(+) create mode 100644 kernel/inc/drivers/gfx/command_queue.h create mode 100644 kernel/inc/drivers/gfx/default_implementation.h create mode 100644 kernel/inc/drivers/gfx/graphics_driver.h create mode 100644 kernel/inc/drivers/gfx/pixelbuffer.h create mode 100644 kernel/inc/drivers/gfx/stringify.h create mode 100644 kernel/inc/drivers/gfx/utility.h create mode 100644 kernel/src/drivers/gfx/command_queue.c create mode 100644 kernel/src/drivers/gfx/default_implementation.c create mode 100644 kernel/src/drivers/gfx/graphics_driver.c create mode 100644 kernel/src/drivers/gfx/pixelbuffer.c create mode 100644 kernel/src/drivers/gfx/stringify.c diff --git a/kernel/inc/drivers/gfx/command_queue.h b/kernel/inc/drivers/gfx/command_queue.h new file mode 100644 index 0000000..548d62d --- /dev/null +++ b/kernel/inc/drivers/gfx/command_queue.h @@ -0,0 +1,12 @@ + +#ifndef NOX_GRAPHICS_COMMAND_QUEUE_H +#define NOX_GRAPHICS_COMMAND_QUEUE_H + +#include +#include +#include + +// TODO + +#endif + diff --git a/kernel/inc/drivers/gfx/default_implementation.h b/kernel/inc/drivers/gfx/default_implementation.h new file mode 100644 index 0000000..d2ce706 --- /dev/null +++ b/kernel/inc/drivers/gfx/default_implementation.h @@ -0,0 +1,12 @@ + +#ifndef NOX_GRAPHICS_DEFAULT_IMPLEMENTATION_H +#define NOX_GRAPHICS_DEFAULT_IMPLEMENTATION_H + +#include +#include +#include + +// TODO + +#endif + diff --git a/kernel/inc/drivers/gfx/graphics_driver.h b/kernel/inc/drivers/gfx/graphics_driver.h new file mode 100644 index 0000000..4a7b369 --- /dev/null +++ b/kernel/inc/drivers/gfx/graphics_driver.h @@ -0,0 +1,35 @@ + +#ifndef NOX_GRAPHICS_DRIVER_H +#define NOX_GRAPHICS_DRIVER_H + +#include + +#include +#include +#include + +#include + +typedef struct framebuffer_t { + + uint32_t pixel_width; + uint32_t pixel_height; + uint8_t pixel_stride; + + void *memory_mapping; + pixelbuffer_T *root_pixelbuffer; + +} framebuffer_T; + +typedef struct graphics_driver_t { + + uint32_t num_framebuffers; + framebuffer_T *framebuffers; + +} graphics_driver_T; + +graphics_driver_T * create_graphics_driver_from_boot_info(boot_info_T *boot_info); +void delete_graphics_driver(graphics_driver_T *driver); + +#endif + diff --git a/kernel/inc/drivers/gfx/pixelbuffer.h b/kernel/inc/drivers/gfx/pixelbuffer.h new file mode 100644 index 0000000..9d1cc9f --- /dev/null +++ b/kernel/inc/drivers/gfx/pixelbuffer.h @@ -0,0 +1,51 @@ + +#ifndef NOX_PIXELBUFFER_H +#define NOX_PIXELBUFFER_H + +#include +#include +#include +#include + +typedef struct pixelbuffer_t pixelbuffer_T; + +struct pixelbuffer_t { + + // + // Other relevant state + // + + pixelbuffer_T *parent; + // root_pixelbuffer: The first pixelbuffer for a screen, it represents the whole screen + // from a drawing perspective. In the root pixelbuffers themselves, this is NULL. + pixelbuffer_T *root_pixelbuffer; + + // + // Dimensions of the pixelbuffers' area + // + + uint32_t relative_start_x; + uint32_t relative_start_y; + uint32_t absolute_start_x; + uint32_t absolute_start_y; + uint32_t pixel_width; + uint32_t pixel_height; + + // + // Information necessary for drawing + // + + // pixel_stride: The distance between pixels in 'mapped_region', in bytes. + uint8_t pixel_stride; + void *memory_mapping; + +}; + +pixelbuffer_T * create_pixelbuffer (pixelbuffer_T *parent); +void delete_pixelbuffer (pixelbuffer_T *pixelbuffer); + +void graphics_set_pixel (pixelbuffer_T *pixelbuffer, + uint32_t relative_x, uint32_t relative_y, pixel_T pixel); + +#endif + diff --git a/kernel/inc/drivers/gfx/stringify.h b/kernel/inc/drivers/gfx/stringify.h new file mode 100644 index 0000000..31d56eb --- /dev/null +++ b/kernel/inc/drivers/gfx/stringify.h @@ -0,0 +1,12 @@ + +#ifndef NOX_GRAPHICS_STRINGIFY_ENUMS_H +#define NOX_GRAPHICS_STRINGIFY_ENUMS_H + +#include +#include +#include + +// TODO + +#endif + diff --git a/kernel/inc/drivers/gfx/utility.h b/kernel/inc/drivers/gfx/utility.h new file mode 100644 index 0000000..2749d7c --- /dev/null +++ b/kernel/inc/drivers/gfx/utility.h @@ -0,0 +1,19 @@ + +#ifndef NOX_GRAPHICS_UTILITY_H +#define NOX_GRAPHICS_UTILITY_H + +#include +#include +#include + +typedef struct +{ + uint16_t red; + uint16_t green; + uint16_t blue; + uint16_t alpha; + +} pixel_T; + +#endif + diff --git a/kernel/src/drivers/gfx/command_queue.c b/kernel/src/drivers/gfx/command_queue.c new file mode 100644 index 0000000..b2a6be2 --- /dev/null +++ b/kernel/src/drivers/gfx/command_queue.c @@ -0,0 +1,2 @@ +// TODO + diff --git a/kernel/src/drivers/gfx/default_implementation.c b/kernel/src/drivers/gfx/default_implementation.c new file mode 100644 index 0000000..b2a6be2 --- /dev/null +++ b/kernel/src/drivers/gfx/default_implementation.c @@ -0,0 +1,2 @@ +// TODO + diff --git a/kernel/src/drivers/gfx/graphics_driver.c b/kernel/src/drivers/gfx/graphics_driver.c new file mode 100644 index 0000000..c344242 --- /dev/null +++ b/kernel/src/drivers/gfx/graphics_driver.c @@ -0,0 +1,52 @@ +#include + +pixelbuffer_T * create_root_pixelbuffer(graphics_driver_T *driver, framebuffer_T *framebuffer) { + + pixelbuffer_T *pixelbuffer = memory_allocate(sizeof(pixelbuffer_T)); + pixelbuffer->parent = NULL; + pixelbuffer->root_pixelbuffer = NULL; + pixelbuffer->relative_start_x = 0; + pixelbuffer->relative_start_y = 0; + pixelbuffer->absolute_start_x = 0; + pixelbuffer->absolute_start_y = 0; + pixelbuffer->pixel_width = framebuffer->pixel_width; + pixelbuffer->pixel_height = framebuffer->pixel_height; + pixelbuffer->pixel_stride = framebuffer->pixel_stride; + pixelbuffer->memory_mapping = framebuffer->memory_mapping; + + return pixelbuffer; +} + +framebuffer_T convert_limine_framebuffer_to_noxos_framebuffer(graphics_driver_T *driver, struct limine_framebuffer *limine_framebuffer) { + + framebuffer_T noxos_framebuffer; + noxos_framebuffer.pixel_width = limine_framebuffer->width; + noxos_framebuffer.pixel_height = limine_framebuffer->height; + noxos_framebuffer.pixel_stride = limine_framebuffer->bpp / 8; // TODO: Check: Is this right? + noxos_framebuffer.memory_mapping = limine_framebuffer->address; + noxos_framebuffer.root_pixelbuffer = create_root_pixelbuffer(driver, &noxos_framebuffer); + + return noxos_framebuffer; +} + +graphics_driver_T * create_graphics_driver_from_boot_info(boot_info_T *boot_info) { + + graphics_driver_T *driver = memory_allocate(sizeof(graphics_driver_T)); + driver->num_framebuffers = boot_info->framebuffer->framebuffer_count; + driver->framebuffers = memory_allocate(sizeof(framebuffer_T) * driver->num_framebuffers); + + uint32_t framebuffer_index = 0; + while(framebuffer_index > boot_info->framebuffer->framebuffer_count) + { + driver->framebuffers[framebuffer_index] = convert_limine_framebuffer_to_noxos_framebuffer( + driver, &boot_info->framebuffer->framebuffers[framebuffer_index]); + ++framebuffer_index; + } + return driver; +} + +void delete_graphics_driver(graphics_driver_T *driver) { + + // TODO +} + diff --git a/kernel/src/drivers/gfx/pixelbuffer.c b/kernel/src/drivers/gfx/pixelbuffer.c new file mode 100644 index 0000000..ca9c9fe --- /dev/null +++ b/kernel/src/drivers/gfx/pixelbuffer.c @@ -0,0 +1,44 @@ +#include + +pixelbuffer_T * find_root_pixelbuffer(pixelbuffer_T *current) { + if(current->parent == NULL) return current; + return find_root_pixelbuffer(current->parent); +} + +pixelbuffer_T * create_pixelbuffer(pixelbuffer_T *parent) { + + pixelbuffer_T *pixelbuffer = memory_allocate(sizeof(pixelbuffer_T)); + pixelbuffer->parent = parent; + pixelbuffer->root_pixelbuffer = find_root_pixelbuffer(parent); + pixelbuffer->memory_mapping = parent->memory_mapping; + pixelbuffer->absolute_start_x = parent->absolute_start_x; + pixelbuffer->absolute_start_y = parent->absolute_start_y; + pixelbuffer->relative_start_x = 0; + pixelbuffer->relative_start_y = 0; + pixelbuffer->pixel_width = 1; + pixelbuffer->pixel_height = 1; + pixelbuffer->pixel_stride = pixelbuffer->root_pixelbuffer->pixel_stride; + + return pixelbuffer; +} + +void delete_pixelbuffer(pixelbuffer_T *pixelbuffer) { + + // TODO + +} + + + +void graphics_set_pixel(pixelbuffer_T *pixelbuffer, + uint32_t relative_x, uint32_t relative_y, pixel_T pixel) +{ + // TODO: Check if these values are inside the pixelbuffers' range! + + uint8_t *output_address = pixelbuffer->memory_mapping + + ((relative_y * pixelbuffer->pixel_width + relative_x) + pixelbuffer->pixel_stride); + output_address[0] = pixel.red; + output_address[1] = pixel.green; + output_address[2] = pixel.blue; +} + diff --git a/kernel/src/drivers/gfx/stringify.c b/kernel/src/drivers/gfx/stringify.c new file mode 100644 index 0000000..b2a6be2 --- /dev/null +++ b/kernel/src/drivers/gfx/stringify.c @@ -0,0 +1,2 @@ +// TODO +