2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

framebufferへの描画

Last updated at Posted at 2020-03-10

FreeBSDのframebufferへの描画について、以下のページに情報がありました。

下のベージにあるgonzoさんのメールのコードを試してみました。

写真(2020-03-10 13.50).jpg

WARNINGのことも書かれていますが、理解できてません。

cairoでも書いてみました。

/*
 * original code is fbutils.c
 *
 * Utility routines for framebuffer interaction
 *
 * Copyright 2002 Russell King and Doug Lowder
 *
 * This file is placed under the GPL.  Please see the
 * file COPYING for details.
 *
 */

# include <stdio.h>
# include <stdlib.h>
# include <string.h>
# include <unistd.h>
# include <sys/fcntl.h>
# include <sys/ioctl.h>
# include <sys/mman.h>
# include <sys/time.h>

# include <sys/consio.h>
# include <sys/fbio.h>

# include <cairo/cairo.h>

static int fbsize;
static unsigned char *fbuffer;
static unsigned char **line_addr;
static int fb_fd=0;
uint32_t xres, yres;
int line_length;

static char *defaultfbdevice = "/dev/fb0";

int open_framebuffer(void)
{
	int y;
	unsigned addr;
	struct fbtype fb;

	fb_fd = open(defaultfbdevice, O_RDWR);
	if (fb_fd == -1) {
		perror("open fbdevice");
		return -1;
	}


	if (ioctl(fb_fd, FBIOGTYPE, &fb) != 0) {
		perror("ioctl(FBIOGTYPE)");
		return -1;
	}

	if (ioctl(fb_fd, FBIO_GETLINEWIDTH, &line_length) != 0) {
		perror("ioctl(FBIO_GETLINEWIDTH)");
		return -1;
	}

	xres = fb.fb_width;
	yres = fb.fb_height;

	int pagemask = getpagesize() - 1;
	fbsize = ((int) line_length*yres + pagemask) & ~pagemask;

	fbuffer = (unsigned char *)mmap(0, fbsize, PROT_READ | PROT_WRITE,
	    MAP_SHARED, fb_fd, 0);
	if (fbuffer == (unsigned char *)-1) {
		perror("mmap framebuffer");
		close(fb_fd);
		return -1;
	}

	return 0;
}

void close_framebuffer(void *device)
{
	munmap(fbuffer, fbsize);
	close(fb_fd);
}

int main()
{
	cairo_t* cr;
	cairo_surface_t *surface;

	open_framebuffer();

	surface = cairo_image_surface_create_for_data (fbuffer,
	    CAIRO_FORMAT_ARGB32, xres, yres, line_length); 

	cairo_surface_set_user_data(surface, NULL, NULL,
	    &close_framebuffer);

	cr = cairo_create (surface);
	cairo_set_line_width(cr, 3);
	cairo_set_source_rgb(cr, 1.0, 0, 0);
	cairo_move_to (cr, 500, 500);
	cairo_line_to (cr, 600, 600);
	cairo_stroke (cr);

	cairo_destroy(cr);
	cairo_surface_destroy(surface);


	return 0;
}

写真(2020-03-11 8.27) #2.jpg

mruby_cairoにもサポート入れてみました。

c = Cairo.new
c.set_source_rgb(1, 0, 0)
c.move_to(0, 0)
c.line_to(100, 100)
c.stroke()

写真(2020-03-11 10.56).jpg

framebufferにコンソールのログが出ないようにするには以下のようにする。

# conscontrol delete ttyv0
Configured: ttyu0
 Available: ttyu0,ttyv0
    Muting: off

起動時のものは消せないが、起動後のものは出なくなる。

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?