diff options
author | Gerd Hoffmann <kraxel@redhat.com> | 2019-02-25 09:00:49 +0100 |
---|---|---|
committer | Gerd Hoffmann <kraxel@redhat.com> | 2019-02-25 09:00:49 +0100 |
commit | ce94df99dba97a671335d350d6bb617f068097cc (patch) | |
tree | 11f0ea5fd2065c3800663d1bcc069fdd2d0ef3f0 | |
parent | d33dd8cd0355f60f07649d8c1b2750ddd98649b4 (diff) | |
download | drminfo-ce94df99dba97a671335d350d6bb617f068097cc.tar.gz |
fbinfo, pixman mode, misc
-rw-r--r-- | drminfo.spec | 2 | ||||
-rw-r--r-- | drmtest.c | 73 | ||||
-rw-r--r-- | fbinfo.c | 65 | ||||
-rw-r--r-- | fbtools.c | 19 | ||||
-rw-r--r-- | fbtools.h | 1 | ||||
-rw-r--r-- | meson.build | 6 |
6 files changed, 150 insertions, 16 deletions
diff --git a/drminfo.spec b/drminfo.spec index ecef075..e3b9fe7 100644 --- a/drminfo.spec +++ b/drminfo.spec @@ -38,5 +38,5 @@ ninja-build -C build-rpm install %{_bindir}/drm* %{_bindir}/prime %{_bindir}/virtiotest -%{_bindir}/fbtest +%{_bindir}/fb* %{_mandir}/man1/drm*.1* @@ -33,8 +33,10 @@ static struct drm_mode_create_dumb creq; static const struct fbformat *fmt = NULL; static uint8_t *fbmem; -/* cairo */ +/* cairo + pixman */ static cairo_surface_t *cs; +static pixman_image_t *pxcs; +static pixman_image_t *pxfb; /* user options */ static cairo_surface_t *image; @@ -52,8 +54,9 @@ static void drm_draw(void) version->version_patchlevel, version->desc); drm_conn_name(conn, name, sizeof(name)); - snprintf(info2, sizeof(info2), "%dx%d, output %s", - mode->hdisplay, mode->vdisplay, name); + snprintf(info2, sizeof(info2), "%dx%d, output %.10s, %.10s mode", + mode->hdisplay, mode->vdisplay, name, + pxcs && pxfb ? "pixman" : "cairo"); if (fmt->fourcc) { snprintf(info3, sizeof(info3), @@ -76,11 +79,19 @@ static void drm_draw(void) render_test(cr, mode->hdisplay, mode->vdisplay, info1, info2, info3); } cairo_destroy(cr); + + if (pxcs && pxfb) { + pixman_image_composite(PIXMAN_OP_SRC, pxcs, NULL, pxfb, + 0, 0, + 0, 0, + 0, 0, + mode->hdisplay, mode->vdisplay); + } } /* ------------------------------------------------------------------ */ -static void drm_init_dumb_fb(void) +static void drm_init_dumb_fb(bool use_pixman) { struct drm_mode_map_dumb mreq; uint32_t zero = 0; @@ -133,11 +144,28 @@ static void drm_init_dumb_fb(void) exit(1); } - cs = cairo_image_surface_create_for_data(fbmem, - fmt->cairo, - creq.width, - creq.height, - creq.pitch); + if (use_pixman) { + pxfb = pixman_image_create_bits(fmt->pixman, + creq.width, + creq.height, + (void*)fbmem, + creq.pitch); + pxcs = pixman_image_create_bits(PIXMAN_x2r10g10b10, + creq.width, + creq.height, + NULL, 0); + cs = cairo_image_surface_create_for_data((void*)pixman_image_get_data(pxcs), + CAIRO_FORMAT_RGB30, + creq.width, + creq.height, + pixman_image_get_stride(pxcs)); + } else { + cs = cairo_image_surface_create_for_data(fbmem, + fmt->cairo, + creq.width, + creq.height, + creq.pitch); + } } static void drm_draw_dumb_fb(void) @@ -156,6 +184,7 @@ static void usage(FILE *fp) "\n" "options:\n" " -h print this\n" + " -p pixman mode\n" " -c <nr> pick card\n" " -o <name> pick output\n" " -s <secs> set sleep time\n" @@ -173,13 +202,17 @@ int main(int argc, char **argv) char *format = NULL; char *modename = NULL; char buf[32]; + bool pixman = false; int c,i; for (;;) { - c = getopt(argc, argv, "hc:s:o:i:f:m:"); + c = getopt(argc, argv, "hpc:s:o:i:f:m:"); if (c == -1) break; switch (c) { + case 'p': + pixman = true; + break; case 'c': card = atoi(optarg); break; @@ -216,8 +249,13 @@ int main(int argc, char **argv) if (!fmt) { fprintf(stderr, "unknown format %s, valid choices are:\n", format); for (i = 0; i < fmtcnt; i++) { - if (fmts[i].cairo == CAIRO_FORMAT_INVALID) - continue; + if (pixman) { + if (fmts[i].pixman == 0) + continue; + } else { + if (fmts[i].cairo == CAIRO_FORMAT_INVALID) + continue; + } drm_print_format(stderr, &fmts[i], 4, false); } exit(1); @@ -229,8 +267,13 @@ int main(int argc, char **argv) if (!fmt) { /* find first supported in list */ for (i = 0; i < fmtcnt; i++) { - if (fmts[i].cairo == CAIRO_FORMAT_INVALID) - continue; + if (pixman) { + if (fmts[i].pixman == 0) + continue; + } else { + if (fmts[i].cairo == CAIRO_FORMAT_INVALID) + continue; + } if (!drm_probe_format(fd, &fmts[i])) continue; fmt = &fmts[i]; @@ -243,7 +286,7 @@ int main(int argc, char **argv) } } - drm_init_dumb_fb(); + drm_init_dumb_fb(pixman); drm_draw_dumb_fb(); drm_show_fb(); diff --git a/fbinfo.c b/fbinfo.c new file mode 100644 index 0000000..a2b4fb3 --- /dev/null +++ b/fbinfo.c @@ -0,0 +1,65 @@ +#include <stdio.h> +#include <stdlib.h> +#include <stdbool.h> +#include <unistd.h> +#include <errno.h> +#include <string.h> +#include <inttypes.h> +#include <getopt.h> + +#include <sys/ioctl.h> +#include <sys/mman.h> + +#include <cairo.h> + +#include "fbtools.h" + +/* ------------------------------------------------------------------ */ + +static void usage(FILE *fp) +{ + fprintf(fp, + "\n" + "usage: fbtest [ options ]\n" + "\n" + "options:\n" + " -h print this\n" + " -f <nr> pick framebuffer\n" + "\n"); +} + +int main(int argc, char **argv) +{ + int framebuffer = 0; + int c; + + for (;;) { + c = getopt(argc, argv, "hf:"); + if (c == -1) + break; + switch (c) { + case 'f': + framebuffer = atoi(optarg); + break; + case 'h': + usage(stdout); + exit(0); + default: + usage(stderr); + exit(1); + } + } + + fb_query(framebuffer); + + fprintf(stderr, "fb%d: %s, %dx%d, %d bpp, r/g/b/a %d/%d/%d/%d\n", + framebuffer, + fb_fix.id, + fb_var.xres, fb_var.yres, + fb_var.bits_per_pixel, + fb_var.red.length, + fb_var.green.length, + fb_var.blue.length, + fb_var.transp.length); + return 0; +} @@ -135,6 +135,25 @@ void fb_fini(void) /* -------------------------------------------------------------------- */ +void fb_query(int cardno) +{ + char device[64]; + + snprintf(device, sizeof(device), "/dev/fb%d", cardno); + if (-1 == (fb = open(device,O_RDWR | O_CLOEXEC))) { + fprintf(stderr,"open %s: %s\n",device,strerror(errno)); + exit(1); + } + if (-1 == ioctl(fb,FBIOGET_FSCREENINFO,&fb_fix)) { + perror("ioctl FBIOGET_FSCREENINFO"); + exit(1); + } + if (-1 == ioctl(fb,FBIOGET_VSCREENINFO,&fb_var)) { + perror("ioctl FBIOGET_VSCREENINFO"); + exit(1); + } +} + void fb_init(int cardno) { unsigned long page_mask; @@ -6,5 +6,6 @@ extern unsigned char *fb_mem; extern int fb_mem_offset; extern cairo_format_t fb_format; +void fb_query(int devnr); void fb_init(int devnr); void fb_fini(void); diff --git a/meson.build b/meson.build index 02ad834..18b2633 100644 --- a/meson.build +++ b/meson.build @@ -17,6 +17,7 @@ jpeg_dep = declare_dependency(link_args : '-ljpeg') drminfo_srcs = [ 'drminfo.c', 'drmtools.c' ] drmtest_srcs = [ 'drmtest.c', 'drmtools.c', 'ttytools.c', 'render.c', 'image.c' ] +fbinfo_srcs = [ 'fbinfo.c', 'fbtools.c' ] fbtest_srcs = [ 'fbtest.c', 'fbtools.c', 'ttytools.c', 'render.c', 'image.c' ] prime_srcs = [ 'prime.c' ] viotest_srcs = [ 'virtiotest.c', 'drmtools.c', 'ttytools.c', 'render.c' ] @@ -25,6 +26,7 @@ gtktest_srcs = [ 'gtktest.c', 'render.c', 'image.c' ] drminfo_deps = [ libdrm_dep, cairo_dep, pixman_dep ] drmtest_deps = [ libdrm_dep, gbm_dep, epoxy_dep, cairo_dep, pixman_dep, jpeg_dep ] +fbinfo_deps = [ cairo_dep ] fbtest_deps = [ cairo_dep, pixman_dep, jpeg_dep ] prime_deps = [ libdrm_dep, gbm_dep ] viotest_deps = [ libdrm_dep, gbm_dep, epoxy_dep, @@ -40,6 +42,10 @@ executable('drmtest', sources : drmtest_srcs, dependencies : drmtest_deps, install : true) +executable('fbinfo', + sources : fbinfo_srcs, + dependencies : fbinfo_deps, + install : true) executable('fbtest', sources : fbtest_srcs, dependencies : fbtest_deps, |