fb: Abstract framebuffer API

This commit is contained in:
mintsuki 2021-03-02 06:21:05 +01:00
parent 689e82dba7
commit a7a168a682
7 changed files with 45 additions and 25 deletions

View File

@ -168,7 +168,7 @@ static struct resolution fallback_resolutions[] = {
{ 640, 480, 32 }
};
bool init_vbe(struct vbe_framebuffer_info *ret,
bool init_vbe(struct fb_info *ret,
uint16_t target_width, uint16_t target_height, uint16_t target_bpp) {
print("vbe: Initialising...\n");

View File

@ -3,23 +3,9 @@
#include <stdint.h>
#include <stdbool.h>
#include <lib/fb.h>
struct vbe_framebuffer_info {
uint8_t memory_model;
uint32_t framebuffer_addr;
uint16_t framebuffer_pitch;
uint16_t framebuffer_width;
uint16_t framebuffer_height;
uint16_t framebuffer_bpp;
uint8_t red_mask_size;
uint8_t red_mask_shift;
uint8_t green_mask_size;
uint8_t green_mask_shift;
uint8_t blue_mask_size;
uint8_t blue_mask_shift;
};
bool init_vbe(struct vbe_framebuffer_info *ret,
bool init_vbe(struct fb_info *ret,
uint16_t target_width, uint16_t target_height, uint16_t target_bpp);
#endif

9
stage23/lib/fb.c Normal file
View File

@ -0,0 +1,9 @@
#include <stdint.h>
#include <stdbool.h>
#include <lib/fb.h>
#include <drivers/vbe.h>
bool fb_init(struct fb_info *ret,
uint16_t target_width, uint16_t target_height, uint16_t target_bpp) {
return init_vbe(ret, target_width, target_height, target_bpp);
}

24
stage23/lib/fb.h Normal file
View File

@ -0,0 +1,24 @@
#ifndef __LIB__FB_H__
#define __LIB__FB_H__
#include <stdint.h>
struct fb_info {
uint8_t memory_model;
uint32_t framebuffer_addr;
uint16_t framebuffer_pitch;
uint16_t framebuffer_width;
uint16_t framebuffer_height;
uint16_t framebuffer_bpp;
uint8_t red_mask_size;
uint8_t red_mask_shift;
uint8_t green_mask_size;
uint8_t green_mask_shift;
uint8_t blue_mask_size;
uint8_t blue_mask_shift;
};
bool fb_init(struct fb_info *ret,
uint16_t target_width, uint16_t target_height, uint16_t target_bpp);
#endif

View File

@ -6,6 +6,7 @@
#include <lib/config.h>
#include <lib/print.h>
#include <lib/uri.h>
#include <lib/fb.h>
#include <mm/mtrr.h>
#include <mm/pmm.h>
@ -14,7 +15,7 @@
#define VGA_FONT_GLYPHS 256
#define VGA_FONT_MAX (VGA_FONT_HEIGHT * VGA_FONT_GLYPHS)
static struct vbe_framebuffer_info fbinfo;
static struct fb_info fbinfo;
static uint32_t *gterm_framebuffer;
static uint16_t gterm_pitch;
static uint16_t gterm_width;
@ -351,7 +352,7 @@ bool gterm_init(int *_rows, int *_cols, uint32_t *_colours, int _margin, int _ma
// We force bpp to 32
req_bpp = 32;
init_vbe(&fbinfo, req_width, req_height, req_bpp);
fb_init(&fbinfo, req_width, req_height, req_bpp);
// Ensure this is xRGB8888, we only support that for the menu
if (fbinfo.red_mask_size != 8

View File

@ -12,7 +12,7 @@
#include <lib/rand.h>
#include <lib/real.h>
#include <lib/uri.h>
#include <drivers/vbe.h>
#include <lib/fb.h>
#include <lib/term.h>
#include <sys/pic.h>
#include <sys/cpu.h>
@ -172,8 +172,8 @@ void stivale_load(char *config, char *cmdline) {
if (resolution != NULL)
parse_resolution(&req_width, &req_height, &req_bpp, resolution);
struct vbe_framebuffer_info fbinfo;
if (!init_vbe(&fbinfo, req_width, req_height, req_bpp))
struct fb_info fbinfo;
if (!fb_init(&fbinfo, req_width, req_height, req_bpp))
panic("stivale: Unable to set video mode");
stivale_struct.framebuffer_addr = (uint64_t)fbinfo.framebuffer_addr;

View File

@ -15,7 +15,7 @@
#include <lib/uri.h>
#include <sys/smp.h>
#include <sys/cpu.h>
#include <drivers/vbe.h>
#include <lib/fb.h>
#include <lib/term.h>
#include <sys/pic.h>
#include <sys/lapic.h>
@ -256,8 +256,8 @@ void stivale2_load(char *config, char *cmdline, bool pxe) {
if (resolution != NULL)
parse_resolution(&req_width, &req_height, &req_bpp, resolution);
struct vbe_framebuffer_info fbinfo;
if (init_vbe(&fbinfo, req_width, req_height, req_bpp)) {
struct fb_info fbinfo;
if (fb_init(&fbinfo, req_width, req_height, req_bpp)) {
struct stivale2_struct_tag_framebuffer *tag = ext_mem_alloc(sizeof(struct stivale2_struct_tag_framebuffer));
tag->tag.identifier = STIVALE2_STRUCT_TAG_FRAMEBUFFER_ID;