Altered and added definitions in the graphics driver

This commit is contained in:
Eric-Paul I 2023-03-09 06:39:14 +01:00
parent ddcb64daea
commit 3ac01ad142
3 changed files with 337 additions and 45 deletions

View File

@ -42,14 +42,14 @@ typedef enum {
} color_palette_E;
typedef struct {
uint8_t alpha;
uint8_t red;
uint8_t green;
uint8_t blue;
} color_argb_T;
uint8_t alpha;
} color_rgba_T;
extern color_argb_T g_color_palette[COLOR_PAL_ENUM_END];
extern color_rgba_T g_color_palette[COLOR_PAL_ENUM_END];
color_argb_T color_argb_blend_alpha(color_argb_T background, color_argb_T foreground);
color_rgba_T color_rgba_blend_alpha(color_rgba_T background, color_rgba_T foreground);
#endif //NOX_COLOR_H

View File

@ -0,0 +1,312 @@
//
// Copyright (c) 2023 by The NOXOS Authors
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the “Software”), to deal in
// the Software without restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
// Software, and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//
#include <utils/math.h>
#include <utils/stdtypes.h>
typedef struct graphics_data_buffer graphics_data_buffer_T;
typedef struct graphics_command graphics_command_T;
typedef struct graphics_command_queue graphics_command_queue_T;
// graphics_draw_pixel_T: A pixel struct that is meant to be for drawing on the screen
// through one of the functions. This could have more functionality, but not yet.
typedef struct {
// The position is relative to the start point *of the pixel buffer*,
math_vector_2i_T position;
// color: The actual layout of this depends on the state at the time of drawing.
uint64_t color;
} graphics_draw_pixel_T;
typedef struct {
math_vector_2i_T start;
math_vector_2i_T end;
uint64_t color;
} graphics_draw_line_T;
typedef struct {
math_vector_2i_T start;
math_vector_2i_T size;
uint64_t color;
} graphics_draw_rectangle_T;
typedef enum {
GRAPHICS_COLOR_FORMAT_RGB = 0x0101,
GRAPHICS_COLOR_FORMAT_RGBA = 0x0102
} graphics_color_order_E;
typedef enum {
// Buffer Functions
GRAPHICS_COMMAND_NEW_DATA_BUFFER = 0x0111,
GRAPHICS_COMMAND_FILL_BUFFER_DATA = 0x0112,
GRAPHICS_COMMAND_CLEAR_BUFFER_DATA = 0x0112,
GRAPHICS_COMMAND_MAP_BUFFER_DATA_MAPPING = 0x0113,
GRAPHICS_COMMAND_SYNC_BUFFER_DATA = 0x0114,
GRAPHICS_COMMAND_NEW_PIXEL_BUFFER = 0x0121,
GRAPHICS_COMMAND_CLEAR_PIXEL_BUFFER = 0x0122,
GRAPHICS_COMMAND_MAP_PIXEL_BUFFER = 0x0123,
GRAPHICS_COMMAND_SYNC_PIXEL_BUFFER_MAPPING = 0x0124,
GRAPHICS_COMMAND_SHOW_PIXEL_BUFFER = 0x0125,
// Basic Draws/Fills & Retrieves
GRAPHICS_COMMAND_DRAW_PIXELS = 0x0211,
GRAPHICS_COMMAND_DRAW_LINES = 0x0212,
GRAPHICS_COMMAND_DRAW_PIXEL_BUFFER = 0x0213, // TODO
GRAPHICS_COMMAND_OUTLINE_RECTANGLES = 0x0221,
GRAPHICS_COMMAND_FILL_RECTANGLES = 0x0222,
GRAPHICS_COMMAND_RETRIEVE_PIXEL = 0x0231,
GRAPHICS_COMMAND_RETRIEVE_AREA = 0x0232,
// Text Features
GRAPHICS_COMMAND_DRAW_RUNE = 0x0311,
GRAPHICS_COMMAND_DRAW_TEXT = 0x0312,
// Implementation-relative
GRAPHICS_COMMAND_SWITCH_IMPLEMENTATION = 0x0411,
GRAPHICS_COMMAND_GET_IMPLEMENTATION_INFO = 0x0412,
GRAPHICS_COMMAND_SET_IMPLEMENTATION_INFO = 0x0413,
GRAPHICS_COMMAND_GET_SPECIFIC_FUNCTION = 0x0414
} graphics_command_E;
union graphics_command_data {
struct graphics_command_new_data_buffer {
uint32_t related_state_id;
uint32_t wanted_buffer_id;
} new_data_buffer;
struct graphics_command_fill_data_buffer {
uint32_t related_state_id;
uint32_t buffer_id;
uint32_t len_new_data;
void *new_data;
} fill_data_buffer;
struct graphics_command_clear_data_buffer {
uint32_t related_state_id;
uint32_t buffer_id;
uint32_t first_output;
uint32_t num_bytes;
uint32_t len_value;
void *value;
} clear_data_buffer;
struct graphics_command_map_data_buffer {
uint32_t related_state_id;
uint32_t buffer_id;
uint32_t wanted_mapping_id;
uint32_t len_buffer_area;
uint32_t first_buffer_byte;
void *virtual_map_address;
} map_data_buffer;
struct graphics_command_sync_data_buffer_mapping {
uint32_t related_state_id;
uint32_t buffer_id;
uint32_t mapping_id;
uint32_t len_sync_area;
uint32_t first_sync_byte;
} sync_data_buffer_mapping;
struct graphics_command_new_pixel_buffer {
uint32_t related_state_id;
uint32_t wanted_buffer_id;
uint32_t start_x;
uint32_t start_y;
uint32_t width;
uint32_t height;
graphics_color_order_E color_format;
// The number of bits for depth can be 16 at most!
uint8_t red_bits;
uint8_t green_bits;
uint8_t blue_bits;
uint8_t alpha_bits;
} new_pixel_buffer;
struct graphics_command_clear_pixel_buffer {
uint32_t related_state_id;
uint32_t buffer_id;
uint32_t first_output;
uint32_t num_bytes;
uint32_t len_value;
void *value;
} clear_pixel_buffer;
struct graphics_command_map_pixel_buffer {
uint32_t related_state_id;
uint32_t buffer_id;
uint32_t wanted_mapping_id;
uint32_t len_buffer_area;
uint32_t first_buffer_byte;
void *virtual_map_address;
} map_pixel_buffer;
struct graphics_command_sync_pixel_buffer_mapping {
uint32_t related_state_id;
uint32_t buffer_id;
uint32_t mapping_id;
uint32_t len_sync_area;
uint32_t first_sync_byte;
} sync_pixel_buffer;
struct graphics_command_draw_pixels {
uint32_t related_state_id;
uint32_t used_pixel_buffer;
uint32_t num_pixels;
graphics_draw_pixel_T *pixels;
} draw_pixels;
struct graphics_command_draw_lines {
uint32_t related_state_id;
uint32_t used_pixel_buffer;
uint32_t num_pixels;
graphics_draw_pixel_T *pixels;
} draw_lines;
struct graphics_command_draw_pixel_buffer {
// TODO
} draw_pixel_buffer;
struct graphics_command_outline_rectangles {
uint32_t related_state_id;
uint32_t used_pixel_buffer;
uint32_t num_pixels;
graphics_draw_rectangle_T *pixels;
} outline_rectangles;
struct graphics_command_fill_rectangles {
uint32_t related_state_id;
uint32_t used_pixel_buffer;
uint32_t num_pixels;
graphics_draw_rectangle_T *pixels;
} fill_rectangles;
struct graphics_command_draw_rune {
uint32_t related_state_id;
uint32_t used_pixel_buffer;
uint32_t rune;
uint16_t height;
// If the width is 0, it is calculated from the aspect
// ratio defined in the font and the given height.
uint16_t width;
uint64_t color;
} draw_rune;
struct graphics_command_draw_text {
uint32_t len_text;
// text: This should be encoded in UTF-8.
char *text;
uint32_t rune;
uint16_t height;
// TODO: Width as bias from the defined one and maximum rendered length.
uint64_t color;
} draw_text;
};
struct graphics_command {
graphics_command_T *next;
graphics_command_T *previous;
graphics_command_E type;
};
struct graphics_command_queue {
uint64_t command_cap;
uint64_t num_commands;
graphics_command_T *command_pool;
bool is_busy;
};

View File

@ -32,51 +32,31 @@
#include "drivers/graphics/framebuffer.h"
#include "boot/boot_info.h"
typedef enum {
GRAPHICS_BUFFER_STANDARD,
GRAPHICS_BUFFER_OVERLAY,
// TODO: Descriptions
typedef struct graphics_pixel_buffer graphics_pixel_buffer_T;
typedef struct graphics_implementation graphics_implementation_T;
typedef struct graphics_renderer graphics_renderer_T;
typedef void (*graphics_fn_handle_command)
(graphics_driver *driver, graphics_command command);
struct graphics_pixel_buffer {
GRAPHICS_BUFFER_ENUM_MAX
} graphics_buffer_layer_E;
typedef struct graphics_buffer_T graphics_buffer_T;
struct graphics_buffer_T {
color_argb_T* buffer;
uint32_t width;
uint32_t height;
uint32_t pos_x;
uint32_t pos_y;
bool blocked;
bool render;
graphics_buffer_layer_E layer;
graphics_buffer_T* prev;
graphics_buffer_T* next;
};
typedef struct {
framebuffer_T framebuffer;
uint32_t* back_buffer;
uint64_t buffer_size;
graphics_buffer_T** graphics_buffer_layers;
font_T font;
bool initialized;
bool blocked;
} graphics_renderer_T;
struct graphics_implementation {
graphics_buffer_T* graphics_buffer_request (uint32_t pos_x, uint32_t pos_y, uint32_t width, uint32_t height, graphics_buffer_layer_E layer);
void graphics_buffer_show (graphics_buffer_T* graphics_buffer);
void graphics_buffer_hide (graphics_buffer_T* graphics_buffer);
void graphics_buffer_destruct (graphics_buffer_T* graphics_buffer);
void graphics_buffer_shift_up (graphics_buffer_T* graphics_buffer, uint16_t shift);
void graphics_buffer_set_pixel (graphics_buffer_T* graphics_buffer, uint32_t x, uint32_t y, color_argb_T color);
color_argb_T graphics_buffer_get_pixel (graphics_buffer_T* graphics_buffer, uint32_t x, uint32_t y);
void graphics_buffer_draw_char (graphics_buffer_T* graphics_buffer, uint32_t x, uint32_t y, color_argb_T color, char chr);
position_T graphics_buffer_draw_string (graphics_buffer_T* graphics_buffer, uint32_t x, uint32_t y, color_argb_T color, string_t string);
void graphics_renderer_init (boot_info_T* boot_info);
void graphics_renderer_update ();
graphics_buffer_T* graphics_renderer_get_top_buffer (graphics_buffer_layer_E layer);
uint32_t graphics_renderer_get_width ();
uint32_t graphics_renderer_get_height ();
}
struct graphics_renderer {
}
#endif //NOX_RENDERER_H