From: John Tsiombikas Date: Fri, 19 Aug 2016 04:01:33 +0000 (+0300) Subject: initial commit X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=fbgfx;a=commitdiff_plain;h=7e9af893a6d14c0136a89648a2fdebab614a662f initial commit --- 7e9af893a6d14c0136a89648a2fdebab614a662f diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..7882958 --- /dev/null +++ b/Makefile @@ -0,0 +1,12 @@ +src = $(wildcard src/*.c) +obj = $(src:.c=.o) +bin = fbgfx + +CFLAGS = -pedantic -Wall -g + +$(bin): $(obj) + $(CC) -o $@ $(obj) $(LDFLAGS) + +.PHONY: clean +clean: + rm -f $(obj) $(bin) diff --git a/src/fbgfx.c b/src/fbgfx.c new file mode 100644 index 0000000..4b96eeb --- /dev/null +++ b/src/fbgfx.c @@ -0,0 +1,70 @@ +#include +#include +#include +#include +#include +#include +#include +#include "fbgfx.h" + +static void cleanup(void); + +static int fd = -1; +static void *vmem; +static int vmem_size; +static struct fb_fix_screeninfo finfo; +static struct fb_var_screeninfo vinfo; + +static int init(void) +{ + if(fd >= 0) return 0; + + if((fd = open("/dev/fb0", O_RDWR)) == -1) { + fprintf(stderr, "failed to open framebuffer device\n"); + return -1; + } + + ioctl(fd, FBIOGET_FSCREENINFO, &finfo); + + atexit(cleanup); + return 0; +} + +static void cleanup(void) +{ + if(vmem) { + munmap(vmem, vmem_size); + } + if(fd != -1) { + close(fd); + } +} + +void *fbgfx_set_video_mode(int x, int y, int depth) +{ + if(init() == -1) { + return 0; + } + return 0; +} + +void *fbgfx_get_video_mode(int *xptr, int *yptr, int *depthptr) +{ + if(init() == -1) { + return 0; + } + if(vmem) return vmem; + + ioctl(fd, FBIOGET_VSCREENINFO, &vinfo); + vmem_size = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8; + + if((vmem = mmap(0, vmem_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)) == (void*)-1) { + fprintf(stderr, "failed to map video memory\n"); + vmem = 0; + return 0; + } + *xptr = vinfo.xres; + *yptr = vinfo.yres; + *depthptr = vinfo.bits_per_pixel; + return vmem; +} diff --git a/src/fbgfx.h b/src/fbgfx.h new file mode 100644 index 0000000..6c18d7f --- /dev/null +++ b/src/fbgfx.h @@ -0,0 +1,8 @@ +#ifndef FBGFX_H_ +#define FBGFX_H_ + +void *fbgfx_set_video_mode(int x, int y, int depth); +void *fbgfx_get_video_mode(int *xptr, int *yptr, int *depthptr); + + +#endif /* FBGFX_H_ */ diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..9d73367 --- /dev/null +++ b/src/main.c @@ -0,0 +1,19 @@ +#include +#include +#include +#include "fbgfx.h" + +static unsigned char *vmem; +static int xsz, ysz, depth; + +int main(void) +{ + if(!(vmem = fbgfx_get_video_mode(&xsz, &ysz, &depth))) { + return 1; + } + printf("current video mode: %dx%d %dbpp\n", xsz, ysz, depth); + + /*memset(vmem, 0xff, xsz * ysz * depth / 8);*/ + + return 0; +}