60 lines
1.6 KiB
C++
60 lines
1.6 KiB
C++
#define MODULE "fb"
|
|
|
|
#include "render/Framebuffer.h"
|
|
#include "assert.h"
|
|
#include "bootboot.h"
|
|
#include "panic/Panic.h"
|
|
#include "string.h"
|
|
|
|
Framebuffer framebuffer0;
|
|
|
|
void Framebuffer::init(void* fb_address, int fb_type, int fb_scanline, int fb_width, int fb_height)
|
|
{
|
|
m_fb_address = fb_address;
|
|
m_fb_height = fb_height;
|
|
m_fb_width = fb_width;
|
|
m_fb_scanline = fb_scanline;
|
|
m_fb_type = fb_type;
|
|
if (m_fb_type != FB_ARGB)
|
|
{
|
|
memset(m_fb_address, 0xe4, 500); // make it visible
|
|
panic("unsupported framebuffer");
|
|
}
|
|
}
|
|
|
|
void Framebuffer::set_pixel(uint32_t x, uint32_t y, Color color)
|
|
{
|
|
*(uint32_t*)((char*)m_fb_address + m_fb_scanline * y + x * 4) = *(uint32_t*)&color;
|
|
}
|
|
|
|
Color Framebuffer::get_pixel(uint32_t x, uint32_t y)
|
|
{
|
|
return *(Color*)((char*)m_fb_address + m_fb_scanline * y + x * 4);
|
|
}
|
|
|
|
void Framebuffer::clear(Color color)
|
|
{
|
|
paint_rect(0, 0, m_fb_width, m_fb_height, color);
|
|
}
|
|
|
|
void Framebuffer::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)((char*)m_fb_address + (m_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 Framebuffer::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]); }
|
|
}
|
|
}
|