[Teton] Draw a green square into the framebuffer.
This commit is contained in:
parent
28719ac726
commit
fb458e6fd4
|
@ -1,4 +1,5 @@
|
|||
add_executable(teton
|
||||
framebuffer/framebuffer.cpp
|
||||
teton.cpp
|
||||
)
|
||||
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
#include "framebuffer/framebuffer.h"
|
||||
|
||||
#include <mammoth/memory_region.h>
|
||||
|
||||
Framebuffer::Framebuffer(const FramebufferInfo& info) : fb_info_(info) {
|
||||
uint64_t buff_size_bytes = fb_info_.height() * fb_info_.pitch();
|
||||
MappedMemoryRegion region = MappedMemoryRegion::DirectPhysical(
|
||||
fb_info_.address_phys(), buff_size_bytes);
|
||||
fb_ = reinterpret_cast<uint32_t*>(region.vaddr());
|
||||
}
|
||||
|
||||
void Framebuffer::DrawPixel(uint32_t row, uint32_t col, uint32_t pixel) {
|
||||
// Div by 4 because pitch is in bytes and fb_ is a 32bit array.
|
||||
fb_[(row * fb_info_.pitch() / 4) + col] = pixel;
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
#pragma once
|
||||
|
||||
#include <yellowstone/yellowstone.yunq.h>
|
||||
|
||||
class Framebuffer {
|
||||
public:
|
||||
Framebuffer(const FramebufferInfo& info);
|
||||
|
||||
void DrawPixel(uint32_t row, uint32_t col, uint32_t pixel);
|
||||
|
||||
private:
|
||||
// FIXME: Implement Yunq copy or move so we
|
||||
// don't have to store a reference here.
|
||||
const FramebufferInfo& fb_info_;
|
||||
uint32_t* fb_;
|
||||
};
|
|
@ -2,6 +2,8 @@
|
|||
#include <mammoth/init.h>
|
||||
#include <yellowstone/yellowstone.yunq.client.h>
|
||||
|
||||
#include "framebuffer/framebuffer.h"
|
||||
|
||||
uint64_t main(uint64_t init_port) {
|
||||
ParseInitPort(init_port);
|
||||
|
||||
|
@ -12,8 +14,17 @@ uint64_t main(uint64_t init_port) {
|
|||
|
||||
FramebufferInfo framebuffer;
|
||||
RET_ERR(client.GetFramebufferInfo({}, framebuffer));
|
||||
dbgln("FB addr {x}, width {} , height {}", framebuffer.address_phys(),
|
||||
framebuffer.width(), framebuffer.height());
|
||||
dbgln("FB addr {x}, bpp {}, width {} , height {}, pitch {}",
|
||||
framebuffer.address_phys(), framebuffer.bpp(), framebuffer.width(),
|
||||
framebuffer.height(), framebuffer.pitch());
|
||||
|
||||
Framebuffer fbuf(framebuffer);
|
||||
|
||||
for (uint64_t r = 0; r < 20; r++) {
|
||||
for (uint64_t c = 0; c < 20; c++) {
|
||||
fbuf.DrawPixel(r, c, 0x0000FF00);
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Parse a font file.
|
||||
|
||||
|
|
Loading…
Reference in New Issue