simplify linux version
This commit is contained in:
1 parent
3f7054fe40
commit
bc27c72034
5 files changed
+560
-501
No files matched your search
+6
-10
@@ -9,25 +9,21 @@ BUILD_DIR = build
|
||||
|
||||
CFLAGS += $(LOTUS_INC)
|
||||
|
||||
all: $(LOTUS_LIB) $(BUILD_DIR)/inbe-$(ARCH) $(BUILD_DIR)/inbefb-$(ARCH) $(BUILD_DIR)/inbe-linux.tar.gz
|
||||
all: $(LOTUS_LIB) $(BUILD_DIR)/inbe-$(ARCH) $(BUILD_DIR)/inbe-linux.tar.gz
|
||||
|
||||
$(BUILD_DIR)/inbefb-$(ARCH): $(SRC_DIR)/native.c $(SRC_DIR)/graphics.c $(SRC_DIR)/common.c $(SRC_DIR)/graphics.h $(SRC_DIR)/common.h $(LOTUS_LIB)
|
||||
$(BUILD_DIR)/inbe-$(ARCH): $(SRC_DIR)/main.c $(SRC_DIR)/graphics.c $(SRC_DIR)/common.c $(SRC_DIR)/graphics.h $(SRC_DIR)/common.h $(LOTUS_LIB)
|
||||
mkdir -p $(BUILD_DIR)
|
||||
$(CC) $(CFLAGS) -o $@ $(SRC_DIR)/native.c $(SRC_DIR)/graphics.c $(SRC_DIR)/common.c $(LOTUS_LIB)
|
||||
$(CC) $(CFLAGS) -o $@ $(SRC_DIR)/main.c $(SRC_DIR)/graphics.c $(SRC_DIR)/common.c $(LOTUS_LIB) -lX11
|
||||
|
||||
$(BUILD_DIR)/inbe-$(ARCH): $(SRC_DIR)/emulator.c $(SRC_DIR)/graphics.c $(SRC_DIR)/common.c $(SRC_DIR)/graphics.h $(SRC_DIR)/common.h $(LOTUS_LIB)
|
||||
mkdir -p $(BUILD_DIR)
|
||||
$(CC) $(CFLAGS) -o $@ $(SRC_DIR)/emulator.c $(SRC_DIR)/graphics.c $(SRC_DIR)/common.c $(LOTUS_LIB) -lX11
|
||||
|
||||
$(BUILD_DIR)/inbe-linux.tar.gz: $(BUILD_DIR)/inbe-$(ARCH) $(BUILD_DIR)/inbefb-$(ARCH)
|
||||
$(BUILD_DIR)/inbe-linux.tar.gz: $(BUILD_DIR)/inbe-$(ARCH)
|
||||
find $(BUILD_DIR) -maxdepth 1 -type f \( -name 'inbe-*' -o -name 'inbefb-*' \) ! -name '*.tar.gz' -exec chmod 755 {} +
|
||||
cd $(BUILD_DIR) && tar -czf inbe-linux.tar.gz $$(find . -maxdepth 1 -type f \( -name 'inbe-*' -o -name 'inbefb-*' \) ! -name '*.tar.gz' -printf '%f\n' | sort)
|
||||
cd $(BUILD_DIR) && tar -czf inbe-linux.tar.gz $$(find . -maxdepth 1 -type f \( -name 'inbe-*' \) ! -name '*.tar.gz' -printf '%f\n' | sort)
|
||||
|
||||
$(LOTUS_LIB):
|
||||
$(MAKE) -C $(LOTUS_DIR)
|
||||
|
||||
clean:
|
||||
rm -f $(BUILD_DIR)/inbe $(BUILD_DIR)/inbefb $(BUILD_DIR)/inbe_* $(BUILD_DIR)/inbefb_* $(BUILD_DIR)/inbe-* $(BUILD_DIR)/inbefb-*
|
||||
rm -f $(BUILD_DIR)/inbe $(BUILD_DIR)/inbe_* $(BUILD_DIR)/inbe-*
|
||||
$(MAKE) -C $(LOTUS_DIR) clean
|
||||
|
||||
.PHONY: all clean
|
||||
@@ -1,236 +0,0 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xutil.h>
|
||||
#include <X11/keysym.h>
|
||||
#include <stdint.h>
|
||||
#include <linux/fb.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include "graphics.h"
|
||||
#include "common.h"
|
||||
#include "../liblotus/lotus.h"
|
||||
|
||||
static uint64_t
|
||||
get_time_ns(void)
|
||||
{
|
||||
struct timespec now;
|
||||
clock_gettime(CLOCK_MONOTONIC, &now);
|
||||
return (uint64_t)now.tv_sec * 1000000000ULL + (uint64_t)now.tv_nsec;
|
||||
}
|
||||
|
||||
static Cursor
|
||||
create_hidden_cursor(Display *display)
|
||||
{
|
||||
static unsigned char cursor_data[1] = { 0 };
|
||||
Cursor cursor;
|
||||
Pixmap data;
|
||||
XColor color;
|
||||
|
||||
data = XCreateBitmapFromData(display, DefaultRootWindow(display), (char*)cursor_data, 1, 1);
|
||||
|
||||
color.pixel = BlackPixel(display, DefaultScreen(display));
|
||||
color.red = color.green = color.blue = 0;
|
||||
color.flags = DoRed | DoGreen | DoBlue;
|
||||
|
||||
cursor = XCreatePixmapCursor(display, data, data, &color, &color, 0, 0);
|
||||
|
||||
XFreePixmap(display, data);
|
||||
|
||||
return cursor;
|
||||
}
|
||||
|
||||
static int
|
||||
quiet_x_io_error(Display *display)
|
||||
{
|
||||
(void)display;
|
||||
_exit(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
put_changed_pixels(Display *display, Window window, GC gc, XImage *x_image,
|
||||
uint8_t *frame, uint8_t *prev,
|
||||
struct fb_var_screeninfo *vinfo,
|
||||
struct fb_fix_screeninfo *finfo, int first_frame)
|
||||
{
|
||||
int bytes_per_pixel = vinfo->bits_per_pixel / 8;
|
||||
size_t row_bytes = (size_t)vinfo->xres * (size_t)bytes_per_pixel;
|
||||
|
||||
if(bytes_per_pixel <= 0)
|
||||
return;
|
||||
|
||||
for(int y = 0; y < (int)vinfo->yres; y++){
|
||||
size_t row = (size_t)y * (size_t)finfo->line_length;
|
||||
|
||||
if(first_frame || memcmp(frame + row, prev + row, row_bytes) != 0){
|
||||
int x = 0;
|
||||
|
||||
while(x < (int)vinfo->xres){
|
||||
size_t pixel = row + (size_t)x * (size_t)bytes_per_pixel;
|
||||
|
||||
if(!first_frame && memcmp(frame + pixel, prev + pixel, bytes_per_pixel) == 0){
|
||||
x++;
|
||||
continue;
|
||||
}
|
||||
|
||||
int start = x;
|
||||
|
||||
while(x < (int)vinfo->xres){
|
||||
pixel = row + (size_t)x * (size_t)bytes_per_pixel;
|
||||
if(!first_frame && memcmp(frame + pixel, prev + pixel, bytes_per_pixel) == 0)
|
||||
break;
|
||||
x++;
|
||||
}
|
||||
|
||||
size_t offset = row + (size_t)start * (size_t)bytes_per_pixel;
|
||||
int width = x - start;
|
||||
|
||||
XPutImage(display, window, gc, x_image, start, y, start, y, (unsigned int)width, 1);
|
||||
memcpy(prev + offset, frame + offset, (size_t)width * (size_t)bytes_per_pixel);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
XSetIOErrorHandler(quiet_x_io_error);
|
||||
|
||||
struct fb_var_screeninfo vinfo = {
|
||||
.xres = 800,
|
||||
.yres = 600,
|
||||
.xoffset = 0,
|
||||
.yoffset = 0,
|
||||
.bits_per_pixel = 32
|
||||
};
|
||||
struct fb_fix_screeninfo finfo = {
|
||||
.line_length = 800 * 4
|
||||
};
|
||||
finfo.smem_len = finfo.line_length * vinfo.yres;
|
||||
|
||||
uint8_t *fb = malloc(finfo.smem_len);
|
||||
if (!fb) return 1;
|
||||
|
||||
uint8_t *prev = malloc(finfo.smem_len);
|
||||
if (!prev) {
|
||||
free(fb);
|
||||
return 1;
|
||||
}
|
||||
memset(prev, 0, finfo.smem_len);
|
||||
|
||||
Display *display = XOpenDisplay(NULL);
|
||||
if (!display) {
|
||||
free(prev);
|
||||
free(fb);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int screen = DefaultScreen(display);
|
||||
Window window = XCreateSimpleWindow(
|
||||
display,
|
||||
RootWindow(display, screen),
|
||||
10, 10,
|
||||
vinfo.xres,
|
||||
vinfo.yres,
|
||||
1,
|
||||
BlackPixel(display, screen),
|
||||
WhitePixel(display, screen)
|
||||
);
|
||||
|
||||
XStoreName(display, window, "Inner Breeze");
|
||||
XSelectInput(display, window, ExposureMask | KeyPressMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask);
|
||||
|
||||
Cursor cursor = create_hidden_cursor(display);
|
||||
XDefineCursor(display, window, cursor);
|
||||
XMapWindow(display, window);
|
||||
|
||||
XImage *x_image = XCreateImage(
|
||||
display,
|
||||
DefaultVisual(display, screen),
|
||||
24,
|
||||
ZPixmap,
|
||||
0,
|
||||
(char *)fb,
|
||||
vinfo.xres,
|
||||
vinfo.yres,
|
||||
32,
|
||||
finfo.line_length
|
||||
);
|
||||
|
||||
GC gc = DefaultGC(display, screen);
|
||||
XEvent event;
|
||||
|
||||
Lotus lotus;
|
||||
lotusinit(&lotus);
|
||||
lotus.speed = 1;
|
||||
lotus.breathtickmax = 2;
|
||||
lotus.screen = LotusScreenStart;
|
||||
|
||||
int mx = vinfo.xres / 2;
|
||||
int my = vinfo.yres / 2;
|
||||
|
||||
const uint64_t target_ns = 16666666ULL;
|
||||
int need_redraw = 1;
|
||||
int first_frame = 1;
|
||||
|
||||
while (1) {
|
||||
uint64_t frame_start = get_time_ns();
|
||||
|
||||
int click = 0;
|
||||
while (XPending(display) > 0) {
|
||||
XNextEvent(display, &event);
|
||||
|
||||
if (event.type == Expose) {
|
||||
need_redraw = 1;
|
||||
}
|
||||
|
||||
if (event.type == KeyPress) {
|
||||
KeySym key = XLookupKeysym(&event.xkey, 0);
|
||||
if (key == XK_q || key == XK_Q) {
|
||||
goto cleanup;
|
||||
}
|
||||
if (key == XK_space || key == XK_Return) {
|
||||
click = 1;
|
||||
need_redraw = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (event.type == ButtonPress) {
|
||||
if (event.xbutton.button == Button1) {
|
||||
click = 1;
|
||||
need_redraw = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (event.type == MotionNotify) {
|
||||
mx = event.xmotion.x;
|
||||
my = event.xmotion.y;
|
||||
need_redraw = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (need_redraw || lotus.screen == LotusScreenSession) {
|
||||
render(fb, &vinfo, &finfo, &lotus, mx, my, &click);
|
||||
draw_cursor(fb, &vinfo, &finfo, mx, my);
|
||||
put_changed_pixels(display, window, gc, x_image, fb, prev,
|
||||
&vinfo, &finfo, first_frame);
|
||||
first_frame = 0;
|
||||
need_redraw = 0;
|
||||
}
|
||||
|
||||
uint64_t frame_time = get_time_ns() - frame_start;
|
||||
if (frame_time < target_ns) {
|
||||
usleep((useconds_t)((target_ns - frame_time) / 1000));
|
||||
}
|
||||
}
|
||||
|
||||
cleanup:
|
||||
XDestroyImage(x_image);
|
||||
XFreeCursor(display, cursor);
|
||||
XCloseDisplay(display);
|
||||
free(prev);
|
||||
return 0;
|
||||
}
|
||||
+149
-28
@@ -65,26 +65,74 @@ draw_circle(uint8_t *fb, struct fb_var_screeninfo *vinfo, struct fb_fix_screenin
|
||||
void
|
||||
clear_screen(uint8_t *fb, struct fb_var_screeninfo *vinfo, struct fb_fix_screeninfo *finfo, uint32_t color)
|
||||
{
|
||||
for(int y = 0; y < (int)vinfo->yres; y++)
|
||||
for(int x = 0; x < (int)vinfo->xres; x++)
|
||||
put_pixel(fb, vinfo, finfo, x, y, color);
|
||||
int bytes_per_pixel = vinfo->bits_per_pixel / 8;
|
||||
long total_pixels = (long)vinfo->xres * (long)vinfo->yres;
|
||||
|
||||
if(bytes_per_pixel == 4){
|
||||
uint32_t *fb32 = (uint32_t *)fb;
|
||||
for(long i = 0; i < total_pixels; i++)
|
||||
fb32[i] = color;
|
||||
}else if(bytes_per_pixel == 2){
|
||||
uint8_t r = (color >> 16) & 0xff;
|
||||
uint8_t g = (color >> 8) & 0xff;
|
||||
uint8_t b = color & 0xff;
|
||||
uint16_t rgb565 = ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | (b >> 3);
|
||||
uint16_t *fb16 = (uint16_t *)fb;
|
||||
for(long i = 0; i < total_pixels; i++)
|
||||
fb16[i] = rgb565;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
draw_char(uint8_t *fb, struct fb_var_screeninfo *vinfo, struct fb_fix_screeninfo *finfo, char c, int x, int y, int scale, uint32_t color)
|
||||
{
|
||||
const uint8_t *glyph = font_8x8[(unsigned char)c];
|
||||
int bytes_per_pixel = vinfo->bits_per_pixel / 8;
|
||||
|
||||
for(int row = 0; row < 8; row++){
|
||||
uint8_t rowbits = glyph[row];
|
||||
for(int col = 0; col < 8; col++){
|
||||
if(rowbits & (1 << (7 - col))){
|
||||
for(int sy = 0; sy < scale; sy++){
|
||||
for(int sx = 0; sx < scale; sx++){
|
||||
int px = x + col * scale + sx;
|
||||
int py = y + row * scale + sy;
|
||||
if(px >= 0 && px < (int)vinfo->xres && py >= 0 && py < (int)vinfo->yres)
|
||||
put_pixel(fb, vinfo, finfo, px, py, color);
|
||||
if(bytes_per_pixel == 4){
|
||||
for(int row = 0; row < 8; row++){
|
||||
uint8_t rowbits = glyph[row];
|
||||
for(int col = 0; col < 8; col++){
|
||||
if(rowbits & (1 << (7 - col))){
|
||||
int px = x + col * scale;
|
||||
int py = y + row * scale;
|
||||
for(int sy = 0; sy < scale && py + sy < (int)vinfo->yres; sy++){
|
||||
if(py + sy < 0) continue;
|
||||
int clip_x = px < 0 ? 0 : px;
|
||||
int clip_w = scale;
|
||||
if(px < 0) clip_w += px;
|
||||
if(px + scale > (int)vinfo->xres) clip_w = vinfo->xres - px;
|
||||
if(clip_w > 0){
|
||||
uint32_t *dst = (uint32_t *)(fb + (py + sy) * finfo->line_length + clip_x * 4);
|
||||
for(int sx = 0; sx < clip_w; sx++)
|
||||
dst[sx] = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}else if(bytes_per_pixel == 2){
|
||||
uint8_t r = (color >> 16) & 0xff;
|
||||
uint8_t g = (color >> 8) & 0xff;
|
||||
uint8_t b = color & 0xff;
|
||||
uint16_t rgb565 = ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | (b >> 3);
|
||||
for(int row = 0; row < 8; row++){
|
||||
uint8_t rowbits = glyph[row];
|
||||
for(int col = 0; col < 8; col++){
|
||||
if(rowbits & (1 << (7 - col))){
|
||||
int px = x + col * scale;
|
||||
int py = y + row * scale;
|
||||
for(int sy = 0; sy < scale && py + sy < (int)vinfo->yres; sy++){
|
||||
if(py + sy < 0) continue;
|
||||
int clip_x = px < 0 ? 0 : px;
|
||||
int clip_w = scale;
|
||||
if(px < 0) clip_w += px;
|
||||
if(px + scale > (int)vinfo->xres) clip_w = vinfo->xres - px;
|
||||
if(clip_w > 0){
|
||||
uint16_t *dst = (uint16_t *)(fb + (py + sy) * finfo->line_length + clip_x * 2);
|
||||
for(int sx = 0; sx < clip_w; sx++)
|
||||
dst[sx] = rgb565;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -115,10 +163,39 @@ draw_string(uint8_t *fb, struct fb_var_screeninfo *vinfo, struct fb_fix_screenin
|
||||
static void
|
||||
draw_rect(uint8_t *fb, struct fb_var_screeninfo *vinfo, struct fb_fix_screeninfo *finfo, int x, int y, int w, int h, uint32_t color)
|
||||
{
|
||||
for(int yy = y; yy < y + h; yy++){
|
||||
for(int xx = x; xx < x + w; xx++){
|
||||
if(xx >= 0 && xx < (int)vinfo->xres && yy >= 0 && yy < (int)vinfo->yres)
|
||||
put_pixel(fb, vinfo, finfo, xx, yy, color);
|
||||
int bytes_per_pixel = vinfo->bits_per_pixel / 8;
|
||||
|
||||
if(bytes_per_pixel == 4){
|
||||
for(int yy = y; yy < y + h; yy++){
|
||||
if(yy >= 0 && yy < (int)vinfo->yres){
|
||||
int clip_x = x < 0 ? 0 : x;
|
||||
int clip_w = w;
|
||||
if(x < 0) clip_w += x;
|
||||
if(x + w > (int)vinfo->xres) clip_w = vinfo->xres - x;
|
||||
if(clip_w > 0){
|
||||
uint32_t *dst = (uint32_t *)(fb + yy * finfo->line_length + clip_x * 4);
|
||||
for(int xx = 0; xx < clip_w; xx++)
|
||||
dst[xx] = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
}else if(bytes_per_pixel == 2){
|
||||
uint8_t r = (color >> 16) & 0xff;
|
||||
uint8_t g = (color >> 8) & 0xff;
|
||||
uint8_t b = color & 0xff;
|
||||
uint16_t rgb565 = ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | (b >> 3);
|
||||
for(int yy = y; yy < y + h; yy++){
|
||||
if(yy >= 0 && yy < (int)vinfo->yres){
|
||||
int clip_x = x < 0 ? 0 : x;
|
||||
int clip_w = w;
|
||||
if(x < 0) clip_w += x;
|
||||
if(x + w > (int)vinfo->xres) clip_w = vinfo->xres - x;
|
||||
if(clip_w > 0){
|
||||
uint16_t *dst = (uint16_t *)(fb + yy * finfo->line_length + clip_x * 2);
|
||||
for(int xx = 0; xx < clip_w; xx++)
|
||||
dst[xx] = rgb565;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -159,28 +236,72 @@ draw_cursor(uint8_t *fb, struct fb_var_screeninfo *vinfo, struct fb_fix_screenin
|
||||
".......X...."
|
||||
};
|
||||
int rows = (int)(sizeof(shape) / sizeof(shape[0]));
|
||||
int bytes_per_pixel = vinfo->bits_per_pixel / 8;
|
||||
|
||||
/* Precompute edge pixels */
|
||||
char edge[17][14] = {0};
|
||||
for(int yy = -1; yy <= rows; yy++){
|
||||
for(int xx = -1; xx <= 12; xx++){
|
||||
int edge = 0;
|
||||
|
||||
for(int oy = -1; oy <= 1; oy++){
|
||||
for(int ox = -1; ox <= 1; ox++){
|
||||
int sy = yy + oy;
|
||||
int sx = xx + ox;
|
||||
|
||||
if(sy >= 0 && sy < rows && sx >= 0 && sx < 12 && shape[sy][sx] == 'X')
|
||||
edge = 1;
|
||||
edge[yy + 1][xx + 1] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if(edge)
|
||||
put_pixel(fb, vinfo, finfo, x + xx, y + yy, COLOR_WHITE);
|
||||
}
|
||||
}
|
||||
|
||||
for(int yy = 0; yy < rows; yy++)
|
||||
for(int xx = 0; xx < 12; xx++)
|
||||
if(shape[yy][xx] == 'X')
|
||||
put_pixel(fb, vinfo, finfo, x + xx, y + yy, COLOR_TEXT);
|
||||
if(bytes_per_pixel == 4){
|
||||
/* Draw white edge */
|
||||
for(int yy = 0; yy < rows + 2; yy++){
|
||||
for(int xx = 0; xx < 14; xx++){
|
||||
if(edge[yy][xx] && !(yy > 0 && yy <= rows && xx > 0 && xx <= 12 && shape[yy-1][xx-1] == 'X')){
|
||||
int px = x + xx - 1;
|
||||
int py = y + yy - 1;
|
||||
if(px >= 0 && px < (int)vinfo->xres && py >= 0 && py < (int)vinfo->yres)
|
||||
*(uint32_t *)(fb + py * finfo->line_length + px * 4) = COLOR_WHITE;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Draw main cursor */
|
||||
for(int yy = 0; yy < rows; yy++){
|
||||
for(int xx = 0; xx < 12; xx++){
|
||||
if(shape[yy][xx] == 'X'){
|
||||
int px = x + xx;
|
||||
int py = y + yy;
|
||||
if(px >= 0 && px < (int)vinfo->xres && py >= 0 && py < (int)vinfo->yres)
|
||||
*(uint32_t *)(fb + py * finfo->line_length + px * 4) = COLOR_TEXT;
|
||||
}
|
||||
}
|
||||
}
|
||||
}else if(bytes_per_pixel == 2){
|
||||
uint16_t white565 = ((0xff & 0xf8) << 8) | ((0xff & 0xfc) << 3) | (0xff >> 3);
|
||||
uint8_t tr = (COLOR_TEXT >> 16) & 0xff;
|
||||
uint8_t tg = (COLOR_TEXT >> 8) & 0xff;
|
||||
uint8_t tb = COLOR_TEXT & 0xff;
|
||||
uint16_t text565 = ((tr & 0xf8) << 8) | ((tg & 0xfc) << 3) | (tb >> 3);
|
||||
|
||||
for(int yy = 0; yy < rows + 2; yy++){
|
||||
for(int xx = 0; xx < 14; xx++){
|
||||
if(edge[yy][xx] && !(yy > 0 && yy <= rows && xx > 0 && xx <= 12 && shape[yy-1][xx-1] == 'X')){
|
||||
int px = x + xx - 1;
|
||||
int py = y + yy - 1;
|
||||
if(px >= 0 && px < (int)vinfo->xres && py >= 0 && py < (int)vinfo->yres)
|
||||
*(uint16_t *)(fb + py * finfo->line_length + px * 2) = white565;
|
||||
}
|
||||
}
|
||||
}
|
||||
for(int yy = 0; yy < rows; yy++){
|
||||
for(int xx = 0; xx < 12; xx++){
|
||||
if(shape[yy][xx] == 'X'){
|
||||
int px = x + xx;
|
||||
int py = y + yy;
|
||||
if(px >= 0 && px < (int)vinfo->xres && py >= 0 && py < (int)vinfo->yres)
|
||||
*(uint16_t *)(fb + py * finfo->line_length + px * 2) = text565;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,405 @@
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/mman.h>
|
||||
#include <signal.h>
|
||||
#include <stdint.h>
|
||||
#include <time.h>
|
||||
#include <linux/fb.h>
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xutil.h>
|
||||
#include <X11/keysym.h>
|
||||
#include <linux/kd.h>
|
||||
#include <termios.h>
|
||||
|
||||
#include "graphics.h"
|
||||
#include "common.h"
|
||||
#include "../liblotus/lotus.h"
|
||||
|
||||
static uint64_t
|
||||
get_time_ns(void)
|
||||
{
|
||||
struct timespec now;
|
||||
clock_gettime(CLOCK_MONOTONIC, &now);
|
||||
return (uint64_t)now.tv_sec * 1000000000ULL + (uint64_t)now.tv_nsec;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
int (*init)(struct fb_var_screeninfo *vinfo, struct fb_fix_screeninfo *finfo);
|
||||
void (*flip)(uint8_t *frame, size_t screen_size);
|
||||
int (*poll_input)(int *mx, int *my, int *click, int *need_redraw);
|
||||
void (*cleanup)(void);
|
||||
} Backend;
|
||||
|
||||
/* ================= X11 Backend ================= */
|
||||
static Display *x11_display;
|
||||
static Window x11_window;
|
||||
static GC x11_gc;
|
||||
static XImage *x11_image;
|
||||
static uint8_t *x11_framebuffer;
|
||||
static uint8_t *x11_prev;
|
||||
static int x11_mx, x11_my;
|
||||
|
||||
static int
|
||||
x11_init(struct fb_var_screeninfo *vinfo, struct fb_fix_screeninfo *finfo)
|
||||
{
|
||||
x11_display = XOpenDisplay(NULL);
|
||||
if(!x11_display)
|
||||
return -1;
|
||||
|
||||
int screen = DefaultScreen(x11_display);
|
||||
|
||||
vinfo->xres = 800;
|
||||
vinfo->yres = 600;
|
||||
vinfo->xoffset = 0;
|
||||
vinfo->yoffset = 0;
|
||||
vinfo->bits_per_pixel = 32;
|
||||
|
||||
finfo->line_length = 800 * 4;
|
||||
finfo->smem_len = finfo->line_length * vinfo->yres;
|
||||
|
||||
x11_framebuffer = malloc(finfo->smem_len);
|
||||
x11_prev = malloc(finfo->smem_len);
|
||||
if(!x11_framebuffer || !x11_prev) {
|
||||
free(x11_framebuffer);
|
||||
free(x11_prev);
|
||||
XCloseDisplay(x11_display);
|
||||
return -1;
|
||||
}
|
||||
memset(x11_prev, 0, finfo->smem_len);
|
||||
|
||||
x11_window = XCreateSimpleWindow(
|
||||
x11_display,
|
||||
RootWindow(x11_display, screen),
|
||||
10, 10,
|
||||
vinfo->xres,
|
||||
vinfo->yres,
|
||||
1,
|
||||
BlackPixel(x11_display, screen),
|
||||
WhitePixel(x11_display, screen)
|
||||
);
|
||||
|
||||
XStoreName(x11_display, x11_window, "Inner Breeze");
|
||||
XSelectInput(x11_display, x11_window,
|
||||
ExposureMask | KeyPressMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask);
|
||||
|
||||
/* Hide cursor */
|
||||
static unsigned char cursor_data[1] = { 0 };
|
||||
Pixmap data = XCreateBitmapFromData(x11_display, DefaultRootWindow(x11_display),
|
||||
(char*)cursor_data, 1, 1);
|
||||
XColor color = { .pixel = BlackPixel(x11_display, screen), .red = 0, .green = 0, .blue = 0,
|
||||
.flags = DoRed | DoGreen | DoBlue };
|
||||
Cursor cursor = XCreatePixmapCursor(x11_display, data, data, &color, &color, 0, 0);
|
||||
XDefineCursor(x11_display, x11_window, cursor);
|
||||
XFreePixmap(x11_display, data);
|
||||
|
||||
XMapWindow(x11_display, x11_window);
|
||||
|
||||
x11_image = XCreateImage(
|
||||
x11_display,
|
||||
DefaultVisual(x11_display, screen),
|
||||
24,
|
||||
ZPixmap,
|
||||
0,
|
||||
(char *)x11_framebuffer,
|
||||
vinfo->xres,
|
||||
vinfo->yres,
|
||||
32,
|
||||
finfo->line_length
|
||||
);
|
||||
|
||||
x11_gc = DefaultGC(x11_display, screen);
|
||||
x11_mx = vinfo->xres / 2;
|
||||
x11_my = vinfo->yres / 2;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
x11_flip(uint8_t *frame, size_t screen_size)
|
||||
{
|
||||
(void)screen_size;
|
||||
/* Copy entire frame at once */
|
||||
memcpy(x11_framebuffer, frame, screen_size);
|
||||
XPutImage(x11_display, x11_window, x11_gc, x11_image,
|
||||
0, 0, 0, 0, x11_image->width, x11_image->height);
|
||||
memcpy(x11_prev, x11_framebuffer, screen_size);
|
||||
}
|
||||
|
||||
static int
|
||||
x11_poll_input(int *mx, int *my, int *click, int *need_redraw)
|
||||
{
|
||||
XEvent event;
|
||||
|
||||
while(XPending(x11_display) > 0) {
|
||||
XNextEvent(x11_display, &event);
|
||||
|
||||
if(event.type == Expose) {
|
||||
*need_redraw = 1;
|
||||
}
|
||||
|
||||
if(event.type == KeyPress) {
|
||||
KeySym key = XLookupKeysym(&event.xkey, 0);
|
||||
if(key == XK_q || key == XK_Q)
|
||||
return -1; /* quit */
|
||||
if(key == XK_space || key == XK_Return) {
|
||||
*click = 1;
|
||||
*need_redraw = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if(event.type == ButtonPress) {
|
||||
if(event.xbutton.button == Button1) {
|
||||
*click = 1;
|
||||
*need_redraw = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if(event.type == MotionNotify) {
|
||||
*mx = event.xmotion.x;
|
||||
*my = event.xmotion.y;
|
||||
*need_redraw = 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
x11_cleanup(void)
|
||||
{
|
||||
if(x11_image) XDestroyImage(x11_image);
|
||||
if(x11_display) XCloseDisplay(x11_display);
|
||||
if(x11_framebuffer) free(x11_framebuffer);
|
||||
if(x11_prev) free(x11_prev);
|
||||
}
|
||||
|
||||
/* ================= Framebuffer Backend ================= */
|
||||
static int fb_tty_fd = -1;
|
||||
static int fb_mouse_fd = -1;
|
||||
static int fb_fd = -1;
|
||||
static uint8_t *fb_mem;
|
||||
static uint8_t *fb_frame;
|
||||
static struct termios fb_orig_termios;
|
||||
static struct fb_var_screeninfo fb_vinfo;
|
||||
static struct fb_fix_screeninfo fb_finfo;
|
||||
|
||||
static void fb_signal_cleanup(int sig);
|
||||
|
||||
static int
|
||||
fb_init(struct fb_var_screeninfo *vinfo, struct fb_fix_screeninfo *finfo)
|
||||
{
|
||||
signal(SIGINT, fb_signal_cleanup);
|
||||
signal(SIGTERM, fb_signal_cleanup);
|
||||
|
||||
fb_tty_fd = open("/dev/tty0", O_RDWR | O_NONBLOCK);
|
||||
if(fb_tty_fd < 0)
|
||||
fb_tty_fd = open("/dev/tty", O_RDWR | O_NONBLOCK);
|
||||
|
||||
if(fb_tty_fd >= 0){
|
||||
ioctl(fb_tty_fd, KDSETMODE, KD_GRAPHICS);
|
||||
tcgetattr(fb_tty_fd, &fb_orig_termios);
|
||||
struct termios raw = fb_orig_termios;
|
||||
raw.c_lflag &= ~(ICANON | ECHO);
|
||||
tcsetattr(fb_tty_fd, TCSANOW, &raw);
|
||||
}
|
||||
|
||||
fb_mouse_fd = open("/dev/input/mice", O_RDONLY | O_NONBLOCK);
|
||||
|
||||
fb_fd = open("/dev/fb0", O_RDWR);
|
||||
if(fb_fd < 0)
|
||||
return -1;
|
||||
|
||||
if(ioctl(fb_fd, FBIOGET_FSCREENINFO, &fb_finfo) == -1 ||
|
||||
ioctl(fb_fd, FBIOGET_VSCREENINFO, &fb_vinfo) == -1) {
|
||||
close(fb_fd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
long screen_size = fb_finfo.smem_len;
|
||||
fb_mem = mmap(0, screen_size, PROT_READ | PROT_WRITE, MAP_SHARED, fb_fd, 0);
|
||||
if(fb_mem == MAP_FAILED) {
|
||||
close(fb_fd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
fb_frame = malloc((size_t)screen_size);
|
||||
if(!fb_frame) {
|
||||
munmap(fb_mem, screen_size);
|
||||
close(fb_fd);
|
||||
return -1;
|
||||
}
|
||||
memset(fb_frame, 0, (size_t)screen_size);
|
||||
|
||||
*vinfo = fb_vinfo;
|
||||
*finfo = fb_finfo;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
fb_flip(uint8_t *frame, size_t screen_size)
|
||||
{
|
||||
memcpy(fb_mem, frame, screen_size);
|
||||
}
|
||||
|
||||
static int
|
||||
fb_poll_input(int *mx, int *my, int *click, int *need_redraw)
|
||||
{
|
||||
char buf;
|
||||
char mouse_buf[3];
|
||||
static int mouse_down = 0;
|
||||
|
||||
if(read(fb_tty_fd, &buf, 1) > 0){
|
||||
if(buf == 'q' || buf == 'Q')
|
||||
return -1;
|
||||
if(buf == ' ' || buf == '\n'){
|
||||
*click = 1;
|
||||
*need_redraw = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if(fb_mouse_fd >= 0){
|
||||
while(read(fb_mouse_fd, mouse_buf, 3) == 3){
|
||||
signed char dx = mouse_buf[1];
|
||||
signed char dy = -mouse_buf[2];
|
||||
int new_buttons = mouse_buf[0] & 0x07;
|
||||
|
||||
*mx += dx;
|
||||
*my += dy;
|
||||
|
||||
if(*mx < 0) *mx = 0;
|
||||
if(*mx >= (int)fb_vinfo.xres) *mx = fb_vinfo.xres - 1;
|
||||
if(*my < 0) *my = 0;
|
||||
if(*my >= (int)fb_vinfo.yres) *my = fb_vinfo.yres - 1;
|
||||
|
||||
if(dx != 0 || dy != 0)
|
||||
*need_redraw = 1;
|
||||
|
||||
if((new_buttons & 0x01) && !(mouse_down & 0x01)){
|
||||
*click = 1;
|
||||
*need_redraw = 1;
|
||||
}
|
||||
|
||||
mouse_down = new_buttons;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
fb_signal_cleanup(int sig)
|
||||
{
|
||||
(void)sig;
|
||||
if(fb_tty_fd >= 0){
|
||||
ioctl(fb_tty_fd, KDSETMODE, KD_TEXT);
|
||||
tcsetattr(fb_tty_fd, TCSANOW, &fb_orig_termios);
|
||||
close(fb_tty_fd);
|
||||
}
|
||||
if(fb_mouse_fd >= 0)
|
||||
close(fb_mouse_fd);
|
||||
_exit(0);
|
||||
}
|
||||
|
||||
static void
|
||||
fb_cleanup(void)
|
||||
{
|
||||
if(fb_tty_fd >= 0){
|
||||
ioctl(fb_tty_fd, KDSETMODE, KD_TEXT);
|
||||
tcsetattr(fb_tty_fd, TCSANOW, &fb_orig_termios);
|
||||
close(fb_tty_fd);
|
||||
}
|
||||
if(fb_mouse_fd >= 0)
|
||||
close(fb_mouse_fd);
|
||||
if(fb_frame) free(fb_frame);
|
||||
if(fb_mem) munmap(fb_mem, fb_finfo.smem_len);
|
||||
if(fb_fd >= 0) close(fb_fd);
|
||||
}
|
||||
|
||||
/* ================= Main ================= */
|
||||
static Backend x11_backend = {
|
||||
.init = x11_init,
|
||||
.flip = x11_flip,
|
||||
.poll_input = x11_poll_input,
|
||||
.cleanup = x11_cleanup
|
||||
};
|
||||
|
||||
static Backend fb_backend = {
|
||||
.init = fb_init,
|
||||
.flip = fb_flip,
|
||||
.poll_input = fb_poll_input,
|
||||
.cleanup = fb_cleanup
|
||||
};
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
Backend *backend;
|
||||
struct fb_var_screeninfo vinfo;
|
||||
struct fb_fix_screeninfo finfo;
|
||||
uint8_t *frame;
|
||||
int mx, my, click, need_redraw;
|
||||
Lotus lotus;
|
||||
const uint64_t target_ns = 16666666ULL;
|
||||
|
||||
/* Detect backend */
|
||||
if(getenv("DISPLAY")) {
|
||||
backend = &x11_backend;
|
||||
} else {
|
||||
backend = &fb_backend;
|
||||
}
|
||||
|
||||
/* Initialize backend */
|
||||
if(backend->init(&vinfo, &finfo) < 0)
|
||||
return 1;
|
||||
|
||||
/* Allocate frame buffer */
|
||||
frame = calloc(1, finfo.smem_len);
|
||||
if(!frame) {
|
||||
backend->cleanup();
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Initialize game state */
|
||||
lotusinit(&lotus);
|
||||
lotus.speed = 1;
|
||||
lotus.breathtickmax = 2;
|
||||
lotus.screen = LotusScreenStart;
|
||||
|
||||
mx = vinfo.xres / 2;
|
||||
my = vinfo.yres / 2;
|
||||
click = 0;
|
||||
need_redraw = 1;
|
||||
|
||||
/* Main loop */
|
||||
while(1){
|
||||
uint64_t frame_start = get_time_ns();
|
||||
|
||||
/* Poll input */
|
||||
int input_result = backend->poll_input(&mx, &my, &click, &need_redraw);
|
||||
if(input_result < 0)
|
||||
break;
|
||||
|
||||
/* Render */
|
||||
if(need_redraw || lotus.screen == LotusScreenSession){
|
||||
render(frame, &vinfo, &finfo, &lotus, mx, my, &click);
|
||||
draw_cursor(frame, &vinfo, &finfo, mx, my);
|
||||
backend->flip(frame, finfo.smem_len);
|
||||
need_redraw = 0;
|
||||
}
|
||||
|
||||
/* Frame rate limiting */
|
||||
uint64_t frame_time = get_time_ns() - frame_start;
|
||||
if(frame_time < target_ns)
|
||||
usleep((useconds_t)((target_ns - frame_time) / 1000));
|
||||
}
|
||||
|
||||
/* Cleanup */
|
||||
free(frame);
|
||||
backend->cleanup();
|
||||
return 0;
|
||||
}
|
||||
@@ -1,227 +0,0 @@
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/mman.h>
|
||||
#include <linux/kd.h>
|
||||
#include <signal.h>
|
||||
#include <stdint.h>
|
||||
#include <linux/fb.h>
|
||||
#include <termios.h>
|
||||
#include <time.h>
|
||||
#include "graphics.h"
|
||||
#include "common.h"
|
||||
#include "../liblotus/lotus.h"
|
||||
|
||||
static int tty_fd = -1;
|
||||
static int mouse_fd = -1;
|
||||
static struct termios orig_termios;
|
||||
|
||||
static void
|
||||
cleanup(int sig)
|
||||
{
|
||||
(void)sig;
|
||||
if(tty_fd >= 0){
|
||||
ioctl(tty_fd, KDSETMODE, KD_TEXT);
|
||||
tcsetattr(tty_fd, TCSANOW, &orig_termios);
|
||||
close(tty_fd);
|
||||
}
|
||||
if(mouse_fd >= 0)
|
||||
close(mouse_fd);
|
||||
_exit(0);
|
||||
}
|
||||
|
||||
static uint64_t
|
||||
get_time_ns(void)
|
||||
{
|
||||
struct timespec now;
|
||||
clock_gettime(CLOCK_MONOTONIC, &now);
|
||||
return (uint64_t)now.tv_sec * 1000000000ULL + (uint64_t)now.tv_nsec;
|
||||
}
|
||||
|
||||
static void
|
||||
flush_changed_pixels(uint8_t *fb, uint8_t *frame, uint8_t *prev,
|
||||
struct fb_var_screeninfo *vinfo,
|
||||
struct fb_fix_screeninfo *finfo, size_t screen_size,
|
||||
int first_frame)
|
||||
{
|
||||
int bytes_per_pixel = vinfo->bits_per_pixel / 8;
|
||||
size_t row_bytes = (size_t)vinfo->xres * (size_t)bytes_per_pixel;
|
||||
|
||||
if(bytes_per_pixel <= 0)
|
||||
return;
|
||||
|
||||
for(int y = 0; y < (int)vinfo->yres; y++){
|
||||
size_t row = ((size_t)y + vinfo->yoffset) * finfo->line_length +
|
||||
(size_t)vinfo->xoffset * (size_t)bytes_per_pixel;
|
||||
|
||||
if(row + row_bytes > screen_size)
|
||||
continue;
|
||||
|
||||
if(first_frame || memcmp(frame + row, prev + row, row_bytes) != 0){
|
||||
int x = 0;
|
||||
|
||||
while(x < (int)vinfo->xres){
|
||||
size_t pixel = row + (size_t)x * (size_t)bytes_per_pixel;
|
||||
|
||||
if(!first_frame && memcmp(frame + pixel, prev + pixel, bytes_per_pixel) == 0){
|
||||
x++;
|
||||
continue;
|
||||
}
|
||||
|
||||
int start = x;
|
||||
|
||||
while(x < (int)vinfo->xres){
|
||||
pixel = row + (size_t)x * (size_t)bytes_per_pixel;
|
||||
if(!first_frame && memcmp(frame + pixel, prev + pixel, bytes_per_pixel) == 0)
|
||||
break;
|
||||
x++;
|
||||
}
|
||||
|
||||
size_t offset = row + (size_t)start * (size_t)bytes_per_pixel;
|
||||
size_t bytes = (size_t)(x - start) * (size_t)bytes_per_pixel;
|
||||
|
||||
memcpy(fb + offset, frame + offset, bytes);
|
||||
memcpy(prev + offset, frame + offset, bytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
signal(SIGINT, cleanup);
|
||||
signal(SIGTERM, cleanup);
|
||||
|
||||
tty_fd = open("/dev/tty0", O_RDWR | O_NONBLOCK);
|
||||
if(tty_fd < 0)
|
||||
tty_fd = open("/dev/tty", O_RDWR | O_NONBLOCK);
|
||||
|
||||
if(tty_fd >= 0){
|
||||
ioctl(tty_fd, KDSETMODE, KD_GRAPHICS);
|
||||
tcgetattr(tty_fd, &orig_termios);
|
||||
struct termios raw = orig_termios;
|
||||
raw.c_lflag &= ~(ICANON | ECHO);
|
||||
tcsetattr(tty_fd, TCSANOW, &raw);
|
||||
}
|
||||
|
||||
mouse_fd = open("/dev/input/mice", O_RDONLY | O_NONBLOCK);
|
||||
|
||||
int fb_fd = open("/dev/fb0", O_RDWR);
|
||||
if(fb_fd < 0){
|
||||
cleanup(0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
struct fb_var_screeninfo vinfo;
|
||||
struct fb_fix_screeninfo finfo;
|
||||
|
||||
if(ioctl(fb_fd, FBIOGET_FSCREENINFO, &finfo) == -1 ||
|
||||
ioctl(fb_fd, FBIOGET_VSCREENINFO, &vinfo) == -1){
|
||||
close(fb_fd);
|
||||
cleanup(0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
long screen_size = finfo.smem_len;
|
||||
uint8_t *fb = mmap(0, screen_size, PROT_READ | PROT_WRITE, MAP_SHARED, fb_fd, 0);
|
||||
|
||||
if(fb == MAP_FAILED){
|
||||
close(fb_fd);
|
||||
cleanup(0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
uint8_t *frame = malloc((size_t)screen_size);
|
||||
uint8_t *prev = malloc((size_t)screen_size);
|
||||
|
||||
if(!frame || !prev){
|
||||
free(frame);
|
||||
free(prev);
|
||||
munmap(fb, screen_size);
|
||||
close(fb_fd);
|
||||
cleanup(0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
memset(frame, 0, (size_t)screen_size);
|
||||
memset(prev, 0, (size_t)screen_size);
|
||||
|
||||
Lotus lotus;
|
||||
lotusinit(&lotus);
|
||||
lotus.speed = 1;
|
||||
lotus.breathtickmax = 2;
|
||||
lotus.screen = LotusScreenStart;
|
||||
|
||||
const uint64_t target_ns = 16666666ULL;
|
||||
int mx = vinfo.xres / 2;
|
||||
int my = vinfo.yres / 2;
|
||||
char buf;
|
||||
char mouse_buf[3];
|
||||
int mouse_down = 0;
|
||||
int need_redraw = 1;
|
||||
int first_frame = 1;
|
||||
|
||||
while(1){
|
||||
uint64_t frame_start = get_time_ns();
|
||||
|
||||
int click = 0;
|
||||
|
||||
if(read(tty_fd, &buf, 1) > 0){
|
||||
if(buf == 'q' || buf == 'Q')
|
||||
break;
|
||||
if(buf == ' ' || buf == '\n'){
|
||||
click = 1;
|
||||
need_redraw = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if(mouse_fd >= 0){
|
||||
while(read(mouse_fd, mouse_buf, 3) == 3){
|
||||
signed char dx = mouse_buf[1];
|
||||
signed char dy = -mouse_buf[2];
|
||||
int new_buttons = mouse_buf[0] & 0x07;
|
||||
|
||||
mx += dx;
|
||||
my += dy;
|
||||
|
||||
if(mx < 0) mx = 0;
|
||||
if(mx >= (int)vinfo.xres) mx = vinfo.xres - 1;
|
||||
if(my < 0) my = 0;
|
||||
if(my >= (int)vinfo.yres) my = vinfo.yres - 1;
|
||||
|
||||
if(dx != 0 || dy != 0)
|
||||
need_redraw = 1;
|
||||
|
||||
if((new_buttons & 0x01) && !(mouse_down & 0x01)){
|
||||
click = 1;
|
||||
need_redraw = 1;
|
||||
}
|
||||
|
||||
mouse_down = new_buttons;
|
||||
}
|
||||
}
|
||||
|
||||
if(need_redraw || lotus.screen == LotusScreenSession){
|
||||
render(frame, &vinfo, &finfo, &lotus, mx, my, &click);
|
||||
draw_cursor(frame, &vinfo, &finfo, mx, my);
|
||||
flush_changed_pixels(fb, frame, prev, &vinfo, &finfo,
|
||||
(size_t)screen_size, first_frame);
|
||||
first_frame = 0;
|
||||
need_redraw = 0;
|
||||
}
|
||||
|
||||
uint64_t frame_time = get_time_ns() - frame_start;
|
||||
if(frame_time < target_ns)
|
||||
usleep((useconds_t)((target_ns - frame_time) / 1000));
|
||||
}
|
||||
|
||||
free(frame);
|
||||
free(prev);
|
||||
munmap(fb, screen_size);
|
||||
close(fb_fd);
|
||||
cleanup(0);
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user