[feat] Desktop render color

This commit is contained in:
2026-05-31 19:58:14 +08:00
Unverified
parent 746786a059
commit 175eba1889
27 changed files with 66 additions and 39 deletions
+8 -2
View File
@@ -21,7 +21,8 @@ KERNEL_CPP = kernel/entry.cpp kernel/main.cpp kernel/serial.cpp kernel/fs.cpp \
kernel/interrupt/gdt.cpp kernel/interrupt/idt.cpp \ kernel/interrupt/gdt.cpp kernel/interrupt/idt.cpp \
kernel/interrupt/pic.cpp kernel/interrupt/pit.cpp \ kernel/interrupt/pic.cpp kernel/interrupt/pit.cpp \
graphics/context.cpp graphics/draw.cpp \ graphics/context.cpp graphics/draw.cpp \
fonts/pixel_font.cpp fonts/pixel_font.cpp \
desktop/prepare.cpp
KERNEL_ASM = kernel/scheduler/context_switch.S kernel/interrupt/isr.S kernel/interrupt/idt_helpers.S KERNEL_ASM = kernel/scheduler/context_switch.S kernel/interrupt/isr.S kernel/interrupt/idt_helpers.S
KERNEL_OBJ = $(KERNEL_CPP:%.cpp=build/%.o) $(KERNEL_ASM:%.S=build/%.o) KERNEL_OBJ = $(KERNEL_CPP:%.cpp=build/%.o) $(KERNEL_ASM:%.S=build/%.o)
@@ -47,7 +48,8 @@ all: _bd $(EFI_OBJ) $(BOOT_OBJ) $(KERNEL_OBJ)
@echo "Done." @echo "Done."
_bd: _bd:
@mkdir -p build/graphics build/kernel build/fonts build/kernel/memory \ @mkdir -p build/graphics build/kernel build/fonts build/desktop \
build/kernel/memory \
build/kernel/scheduler build/kernel/interrupt \ build/kernel/scheduler build/kernel/interrupt \
build/efi/lib build/efi/lib/x86_64 build/efi/lib/runtime build/efi/gnuefi build/efi/lib build/efi/lib/x86_64 build/efi/lib/runtime build/efi/gnuefi
@@ -117,6 +119,10 @@ build/fonts/%.o: fonts/%.cpp | _bd
@echo "Compile CPP $<" @echo "Compile CPP $<"
@g++ $(KERNEL_CXXFLAGS) -c $< -o $@ @g++ $(KERNEL_CXXFLAGS) -c $< -o $@
build/desktop/%.o: desktop/%.cpp | _bd
@echo "Compile CPP $<"
@g++ $(KERNEL_CXXFLAGS) -c $< -o $@
vdir: all vdir: all
@mkdir -p vdir/EFI/BOOT @mkdir -p vdir/EFI/BOOT
@cp build/BOOTX64.EFI vdir/EFI/BOOT @cp build/BOOTX64.EFI vdir/EFI/BOOT
+9
View File
@@ -0,0 +1,9 @@
#include <graphics/draw.h>
void prepare(UINT32 width, UINT32 height, COLOR_RGB color) {
for (UINT32 i = 0; i < height; i++) {
for (UINT32 j = 0; j < width; j++) {
draw_pixel(i, j, color);
}
}
}
+2 -2
View File
@@ -12,7 +12,7 @@ void pf_reset_position(void) {
pf_y = 1; pf_y = 1;
} }
void pf_print_char(char c, unsigned int basex, unsigned int basey, EFI_GRAPHICS_OUTPUT_BLT_PIXEL color) { void pf_print_char(char c, unsigned int basex, unsigned int basey, COLOR_RGB color) {
for (unsigned int y = 0; y < 16; y++) { for (unsigned int y = 0; y < 16; y++) {
unsigned char data = hankaku_pixels[c][y]; unsigned char data = hankaku_pixels[c][y];
for (int x = 7; x >= 0; x--) { for (int x = 7; x >= 0; x--) {
@@ -31,7 +31,7 @@ void pf_print_char(char c, unsigned int basex, unsigned int basey, EFI_GRAPHICS_
} }
} }
void pf_print(const char* text, EFI_GRAPHICS_OUTPUT_BLT_PIXEL color) { void pf_print(const char* text, COLOR_RGB color) {
for (unsigned int i = 0; i < strlen(text); i++) { for (unsigned int i = 0; i < strlen(text); i++) {
char c = text[i]; char c = text[i];
if (c == '\n') { if (c == '\n') {
+3 -2
View File
@@ -1,4 +1,5 @@
#include <graphics/context.h> #include <graphics/context.h>
#include <graphics/draw.h>
gfx_context g_gfx; gfx_context g_gfx;
@@ -6,10 +7,10 @@ void gfx_init(EFI_GRAPHICS_OUTPUT_PROTOCOL *GOP) {
g_gfx.GOP = GOP; g_gfx.GOP = GOP;
g_gfx.hr = GOP->Mode->Info->HorizontalResolution; g_gfx.hr = GOP->Mode->Info->HorizontalResolution;
g_gfx.vr = GOP->Mode->Info->VerticalResolution; g_gfx.vr = GOP->Mode->Info->VerticalResolution;
g_gfx.base = (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *) GOP->Mode->FrameBufferBase; g_gfx.base = (COLOR_RGB *) GOP->Mode->FrameBufferBase;
} }
void gfx_clear(void) { void gfx_clear(void) {
EFI_GRAPHICS_OUTPUT_BLT_PIXEL black = {0, 0, 0, 0}; COLOR_RGB black = {0, 0, 0, 0};
g_gfx.GOP->Blt(g_gfx.GOP, &black, EfiBltVideoFill, 0, 0, 0, 0, g_gfx.hr, g_gfx.vr, 0); g_gfx.GOP->Blt(g_gfx.GOP, &black, EfiBltVideoFill, 0, 0, 0, 0, g_gfx.hr, g_gfx.vr, 0);
} }
+2 -2
View File
@@ -1,7 +1,7 @@
#include <graphics/draw.h> #include <graphics/draw.h>
void draw_pixel(unsigned int x, unsigned int y, EFI_GRAPHICS_OUTPUT_BLT_PIXEL color) { void draw_pixel(unsigned int x, unsigned int y, COLOR_RGB color) {
EFI_GRAPHICS_OUTPUT_BLT_PIXEL *p = g_gfx.base + (g_gfx.hr * y) + x; COLOR_RGB *p = g_gfx.base + (g_gfx.hr * y) + x;
p->Blue = color.Blue; p->Blue = color.Blue;
p->Green = color.Green; p->Green = color.Green;
+1
View File
@@ -1,6 +1,7 @@
#pragma once #pragma once
#define ASM asm volatile #define ASM asm volatile
#define COLOR_RGB EFI_GRAPHICS_OUTPUT_BLT_PIXEL
static unsigned int strlen(const char* arr) { // 获取string长度 static unsigned int strlen(const char* arr) { // 获取string长度
int i = 0; int i = 0;
+3
View File
@@ -0,0 +1,3 @@
#pragma once
void prepare(UINT32 width, UINT32 height, COLOR_RGB color = {144, 238, 145});
+4 -3
View File
@@ -1,8 +1,9 @@
#pragma once #pragma once
#include <graphics/context.h> #include <graphics/context.h>
#include <graphics/draw.h>
void pf_print_char(char c, unsigned int basex, unsigned int basey, void pf_print_char(char c, unsigned int basex, unsigned int basey,
EFI_GRAPHICS_OUTPUT_BLT_PIXEL color = {255, 255, 255, 255}); // Pixel Font 打印字符 COLOR_RGB color = {255, 255, 255, 255}); // Pixel Font 打印字符
void pf_print(const char* text, EFI_GRAPHICS_OUTPUT_BLT_PIXEL color = {255, 255, 255, 255}); // Pixel Font 打印string void pf_print(const char* text, COLOR_RGB color = {255, 255, 255, 255}); // Pixel Font 打印string
void pf_reset_position(void); // 重设Pixel Font Cursor位置 void pf_reset_position(void); // 重设Pixel Font Cursor位置
+2 -1
View File
@@ -3,12 +3,13 @@
// 这个文件存在的目的是让graphics的draw功能不用每次传 GOP hr vr base // 这个文件存在的目的是让graphics的draw功能不用每次传 GOP hr vr base
#include <efi.h> #include <efi.h>
#include <common.h>
struct gfx_context { struct gfx_context {
EFI_GRAPHICS_OUTPUT_PROTOCOL *GOP; EFI_GRAPHICS_OUTPUT_PROTOCOL *GOP;
unsigned int hr; unsigned int hr;
unsigned int vr; unsigned int vr;
EFI_GRAPHICS_OUTPUT_BLT_PIXEL *base; COLOR_RGB *base;
}; };
extern gfx_context g_gfx; extern gfx_context g_gfx;
+3 -1
View File
@@ -3,4 +3,6 @@
#include <efi.h> #include <efi.h>
#include <graphics/context.h> #include <graphics/context.h>
void draw_pixel(unsigned int x, unsigned int y, EFI_GRAPHICS_OUTPUT_BLT_PIXEL color); // 画像素 #define COLOR_RGB EFI_GRAPHICS_OUTPUT_BLT_PIXEL
void draw_pixel(unsigned int x, unsigned int y, COLOR_RGB color); // 画像素
+2 -2
View File
@@ -1,5 +1,5 @@
#include <fs.h> #include <kernel/fs.h>
#include <serial.h> #include <kernel/serial.h>
#include <memory/heap.h> #include <memory/heap.h>
#include <common.h> #include <common.h>
+2 -2
View File
@@ -1,6 +1,6 @@
#include <gdt.h> #include <kernel/gdt.h>
#include <common.h> #include <common.h>
#include <serial.h> #include <kernel/serial.h>
static gdt_entry g_gdt[7]; // 5 segments + TSS (2 entries) static gdt_entry g_gdt[7]; // 5 segments + TSS (2 entries)
static gdt_ptr g_gdt_ptr; static gdt_ptr g_gdt_ptr;
+3 -3
View File
@@ -1,7 +1,7 @@
#include <idt.h> #include <kernel/idt.h>
#include <common.h> #include <common.h>
#include <pic.h> #include <kernel/pic.h>
#include <serial.h> #include <kernel/serial.h>
// Defined in isr.S — 256 ISR stubs // Defined in isr.S — 256 ISR stubs
extern "C" void* isr_stub_table[256]; extern "C" void* isr_stub_table[256];
+2 -2
View File
@@ -1,6 +1,6 @@
#include <pic.h> #include <kernel/pic.h>
#include <common.h> #include <common.h>
#include <serial.h> #include <kernel/serial.h>
static inline void outb(UINT16 port, UINT8 val) { static inline void outb(UINT16 port, UINT8 val) {
ASM("outb %0, %1" : : "a"(val), "Nd"(port)); ASM("outb %0, %1" : : "a"(val), "Nd"(port));
+3 -3
View File
@@ -1,7 +1,7 @@
#include <pit.h> #include <kernel/pit.h>
#include <common.h> #include <common.h>
#include <pic.h> #include <kernel/pic.h>
#include <serial.h> #include <kernel/serial.h>
static inline void outb(UINT16 port, UINT8 val) { static inline void outb(UINT16 port, UINT8 val) {
ASM("outb %0, %1" : : "a"(val), "Nd"(port)); ASM("outb %0, %1" : : "a"(val), "Nd"(port));
+10 -7
View File
@@ -2,16 +2,17 @@
#include <graphics/context.h> #include <graphics/context.h>
#include <graphics/draw.h> #include <graphics/draw.h>
#include <fonts/pixel_font.h> #include <fonts/pixel_font.h>
#include <serial.h> #include <kernel/serial.h>
#include <common.h> #include <common.h>
#include <memory/pmm.h> #include <memory/pmm.h>
#include <memory/heap.h> #include <memory/heap.h>
#include <scheduler.h> #include <kernel/scheduler.h>
#include <fs.h> #include <kernel/fs.h>
#include <gdt.h> #include <kernel/gdt.h>
#include <idt.h> #include <kernel/idt.h>
#include <pic.h> #include <kernel/pic.h>
#include <pit.h> #include <kernel/pit.h>
#include <desktop/prepare.h>
extern EFI_SYSTEM_TABLE *ST; extern EFI_SYSTEM_TABLE *ST;
@@ -131,6 +132,8 @@ extern "C" void kernel_main() {
pf_print("Welcome to Sylva OS!\n"); pf_print("Welcome to Sylva OS!\n");
serial_write(" Kernel prepared well.\n"); serial_write(" Kernel prepared well.\n");
prepare((UINT32) g_gfx.vr, (UINT32) g_gfx.hr);
// --- Interrupt infrastructure --- // --- Interrupt infrastructure ---
serial_write("Sylva: init GDT...\n"); serial_write("Sylva: init GDT...\n");
gdt_init(); gdt_init();
+1 -1
View File
@@ -1,6 +1,6 @@
#include <memory/heap.h> #include <memory/heap.h>
#include <memory/pmm.h> #include <memory/pmm.h>
#include <serial.h> #include <kernel/serial.h>
struct heap_block { struct heap_block {
UINTN size; // includes header; bit 0 = 1 used, 0 free UINTN size; // includes header; bit 0 = 1 used, 0 free
+1 -1
View File
@@ -1,5 +1,5 @@
#include <memory/pmm.h> #include <memory/pmm.h>
#include <serial.h> #include <kernel/serial.h>
extern EFI_SYSTEM_TABLE *ST; extern EFI_SYSTEM_TABLE *ST;
+4 -4
View File
@@ -1,10 +1,10 @@
#include <scheduler.h> #include <kernel/scheduler.h>
#include <idt.h> #include <kernel/idt.h>
#include <pic.h> #include <kernel/pic.h>
#include <memory/heap.h> #include <memory/heap.h>
#include <memory/pmm.h> #include <memory/pmm.h>
#include <common.h> #include <common.h>
#include <serial.h> #include <kernel/serial.h>
// Assembly: context_switch(UINT64* old_rsp, UINT64 new_rsp) // Assembly: context_switch(UINT64* old_rsp, UINT64 new_rsp)
extern "C" void context_switch(UINT64* old_rsp, UINT64 new_rsp); extern "C" void context_switch(UINT64* old_rsp, UINT64 new_rsp);
+1 -1
View File
@@ -1,4 +1,4 @@
#include <serial.h> #include <kernel/serial.h>
extern EFI_SYSTEM_TABLE *ST; extern EFI_SYSTEM_TABLE *ST;