apio
140910763e
All checks were successful
Build and test / build (push) Successful in 1m56s
Why are command-line utilities stored in "apps"? And why are apps like "editor" or "terminal" top-level directories? Command-line utilities now go in "utils". GUI stuff now goes in "gui". This includes: libui -> gui/libui, wind -> gui/wind, GUI apps -> gui/apps, editor&terminal -> gui/apps... System services go in "system".
37 lines
755 B
C++
37 lines
755 B
C++
#include "Screen.h"
|
|
#include <errno.h>
|
|
#include <fcntl.h>
|
|
#include <sys/ioctl.h>
|
|
#include <sys/mman.h>
|
|
#include <unistd.h>
|
|
|
|
Screen Screen::s_the;
|
|
|
|
Result<void> Screen::open()
|
|
{
|
|
int fd = ::open("/dev/fb0", O_RDWR);
|
|
if (fd < 0) return err(errno);
|
|
|
|
int width = ioctl(fd, FB_GET_WIDTH);
|
|
int height = ioctl(fd, FB_GET_HEIGHT);
|
|
|
|
void* p = mmap(nullptr, width * height * BYTES_PER_PIXEL, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
|
close(fd);
|
|
|
|
if (p == MAP_FAILED) { return err(errno); }
|
|
|
|
Screen screen;
|
|
|
|
screen.m_canvas = ui::Canvas::create((u8*)p, width, height);
|
|
screen.m_size = width * height * BYTES_PER_PIXEL;
|
|
|
|
s_the = screen;
|
|
|
|
return {};
|
|
}
|
|
|
|
void Screen::sync()
|
|
{
|
|
msync(m_canvas.ptr, size(), MS_SYNC);
|
|
}
|