[cairo-commit] cairo-demo/fbdev Makefile, NONE, 1.1 cairo-fb.c, NONE, 1.1

Amaury Jacquot commit at pdx.freedesktop.org
Thu Sep 30 13:02:18 PDT 2004


Committed by: sxpert

Update of /cvs/cairo/cairo-demo/fbdev
In directory gabe:/tmp/cvs-serv1595

Added Files:
	Makefile cairo-fb.c 
Log Message:

first version of the frame buffer demo


--- NEW FILE: Makefile ---


fbtest : fbtest.o
	gcc `pkg-config --libs cairo` -o fbtest fbtest.o

fbtest.o: fbtest.c
	gcc `pkg-config --cflags cairo` -c fbtest.c

clean:
	rm *.o fbtest

--- NEW FILE: cairo-fb.c ---
/*************************************************************************
 * Cairo Frame Buffer demo
 * (c) 2004 Amaury Jacquot <sxpert at esitcom.org>
 * This program is licensed under the GNU GPL version 2 or later license
 ************************************************************************/

#include <unistd.h>
#include <stdio.h>
#include <fcntl.h>
#include <linux/fb.h>
#include <sys/mman.h>
#include <cairo.h>

int main(){
	int fbfd = 0;
	struct fb_var_screeninfo vinfo;
	struct fb_fix_screeninfo finfo;
	long int screensize = 0;
	char* fbp = 0;
	cairo_t* cr;

	// open the frame buffer file for reading & writing
	fbfd = open ( "/dev/fb0", O_RDWR );
	if (!fbfd) {
		printf ("Error: can't open framebuffer device.\n");
		exit (1);
	}
	printf ("The framebuffer device was opened successfully\n");

	if (ioctl (fbfd, FBIOGET_FSCREENINFO, &finfo)) {
		printf ("Error reading fixed information\n");
		close (fbfd);
		exit (2);
	}

	if (ioctl (fbfd, FBIOGET_VSCREENINFO, &vinfo)) {
		printf ("Error reading variable information\n");
		close (fbfd);
		exit (3);
	}

	// print info about the buffer
	printf ("%dx%d, %dbpp\n", vinfo.xres, vinfo.yres, vinfo.bits_per_pixel);

	// calculates size
	screensize = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8;

	// map the device to memory 
	fbp = (char*) mmap (0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED, fbfd, 0);

	if ((int)fbp == -1) {
		printf ("Error: failed to map framebuffer device to memory\n");
		close (fbfd);
		exit (4);
	}

	printf ("The framebuffer device was successfully mapped to memory\n");

	cr = cairo_create ();
	cairo_set_target_image (cr, fbp, CAIRO_FORMAT_ARGB32, 
		vinfo.xres, vinfo.yres, finfo.line_length); 
	cairo_move_to (cr, 100, 100);
	cairo_line_to (cr, 300, 300);
	cairo_stroke (cr);
	
	munmap (fbp, screensize);
	close (fbfd);
	return 0;
}




More information about the cairo-commit mailing list