Luna/kernel/src/render/BBRenderer.cpp
2022-09-05 16:13:51 +02:00

48 lines
1.2 KiB
C++

#include "render/BBRenderer.h"
#include "assert.h"
#include "bootboot.h"
extern BOOTBOOT bootboot;
extern uint8_t fb[4];
bool BBRenderer::init()
{
// FIXME: Support more framebuffer types
return bootboot.fb_type == FB_ARGB;
}
void BBRenderer::set_pixel(uint32_t x, uint32_t y, Color color)
{
*(uint32_t*)(fb + bootboot.fb_scanline * y + x * 4) = *(uint32_t*)&color;
}
Color BBRenderer::get_pixel(uint32_t x, uint32_t y)
{
return *(Color*)(fb + bootboot.fb_scanline * y + x * 4);
}
void BBRenderer::clear(Color color)
{
paint_rect(0, 0, bootboot.fb_width, bootboot.fb_height, color);
}
void BBRenderer::paint_rect(uint32_t x, uint32_t y, uint32_t w, uint32_t h, Color color)
{
for (uint32_t i = y; i < (y + h); i++)
{
uint64_t addr = (uint64_t)(fb + (bootboot.fb_scanline * i) + (x * 4));
for (uint64_t addr_current = addr; addr_current < (addr + w * 4); addr_current += 4)
{
*(uint32_t*)addr_current = *(uint32_t*)&color;
}
}
}
void BBRenderer::paint_rect(uint32_t x, uint32_t y, uint32_t w, uint32_t h, Color* colors)
{
uint32_t j;
for (uint32_t l = j = 0; l < h; l++)
{
for (uint32_t i = 0; i < w; i++, j++) { set_pixel(x + i, y + l, colors[j]); }
}
}