X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?p=pcsx_rearmed.git;a=blobdiff_plain;f=frontend%2Flinux%2Ffbdev.c;h=224f42d8458ca7413d0c309e40fae169ee4b5eb7;hp=6ae0c7714240025066c33be8c1e6cc97875fd2f6;hb=2cb4655298083c0c05f68941fa7e4f37b6b51ebd;hpb=b60f2812208aa36dc8b9e8e90f02b608dafd0c00 diff --git a/frontend/linux/fbdev.c b/frontend/linux/fbdev.c index 6ae0c771..224f42d8 100644 --- a/frontend/linux/fbdev.c +++ b/frontend/linux/fbdev.c @@ -1,7 +1,10 @@ /* * (C) Gražvydas "notaz" Ignotas, 2009-2010 * - * This work is licensed under the terms of the GNU LGPL, version 2.1 or later. + * This work is licensed under the terms of any of these licenses + * (at your option): + * - GNU GPL, version 2 or later. + * - GNU LGPL, version 2.1 or later. * See the COPYING file in the top-level directory. */ @@ -19,8 +22,6 @@ #include "fbdev.h" -#define FBDEV_MAX_BUFFERS 3 - struct vout_fbdev { int fd; void *mem; @@ -60,8 +61,9 @@ void vout_fbdev_wait_vsync(struct vout_fbdev *fbdev) ioctl(fbdev->fd, FBIO_WAITFORVSYNC, &arg); } -int vout_fbdev_resize(struct vout_fbdev *fbdev, int w, int h, - int left_border, int right_border, int top_border, int bottom_border, int no_dblbuf) +/* it is recommended to call vout_fbdev_clear() before this */ +void *vout_fbdev_resize(struct vout_fbdev *fbdev, int w, int h, int bpp, + int left_border, int right_border, int top_border, int bottom_border, int buffer_cnt) { int w_total = left_border + w + right_border; int h_total = top_border + h + bottom_border; @@ -71,7 +73,7 @@ int vout_fbdev_resize(struct vout_fbdev *fbdev, int w, int h, // unblank to be sure the mode is really accepted ioctl(fbdev->fd, FBIOBLANK, FB_BLANK_UNBLANK); - if (fbdev->fbvar_new.bits_per_pixel != 16 || + if (fbdev->fbvar_new.bits_per_pixel != bpp || w != fbdev->fbvar_new.xres || h != fbdev->fbvar_new.yres || w_total != fbdev->fbvar_new.xres_virtual || @@ -82,44 +84,51 @@ int vout_fbdev_resize(struct vout_fbdev *fbdev, int w, int h, fbdev->fbvar_new.xres_virtual = w_total; fbdev->fbvar_new.yres_virtual = h_total; fbdev->fbvar_new.xoffset = left_border; - fbdev->fbvar_new.bits_per_pixel = 16; - printf(" switching to %dx%d@16\n", w, h); + fbdev->fbvar_new.yoffset = top_border; + fbdev->fbvar_new.bits_per_pixel = bpp; + printf(" switching to %dx%d@%d\n", w, h, bpp); + + // seems to help a bit to avoid glitches + vout_fbdev_wait_vsync(fbdev); + ret = ioctl(fbdev->fd, FBIOPUT_VSCREENINFO, &fbdev->fbvar_new); if (ret == -1) { perror("FBIOPUT_VSCREENINFO ioctl"); - return -1; + return NULL; } + + fbdev->buffer_write = 1; } - fbdev->buffer_count = FBDEV_MAX_BUFFERS; // be optimistic - if (no_dblbuf) - fbdev->buffer_count = 1; + fbdev->buffer_count = buffer_cnt; if (fbdev->fbvar_new.yres_virtual < h_total * fbdev->buffer_count) { fbdev->fbvar_new.yres_virtual = h_total * fbdev->buffer_count; ret = ioctl(fbdev->fd, FBIOPUT_VSCREENINFO, &fbdev->fbvar_new); if (ret == -1) { fbdev->buffer_count = 1; + fbdev->buffer_write = 0; fprintf(stderr, "Warning: failed to increase virtual resolution, " "doublebuffering disabled\n"); } } - fbdev->fb_size = w_total * h_total * 2; + fbdev->fb_size = w_total * h_total * bpp / 8; fbdev->top_border = top_border; fbdev->bottom_border = bottom_border; mem_size = fbdev->fb_size * fbdev->buffer_count; if (fbdev->mem_size >= mem_size) - return 0; + goto out; if (fbdev->mem != NULL) munmap(fbdev->mem, fbdev->mem_size); fbdev->mem = mmap(0, mem_size, PROT_WRITE|PROT_READ, MAP_SHARED, fbdev->fd, 0); if (fbdev->mem == MAP_FAILED && fbdev->buffer_count > 1) { - fprintf(stderr, "Warning: can't map %zd bytes, doublebuffering disabled\n", fbdev->mem_size); + fprintf(stderr, "Warning: can't map %zd bytes, doublebuffering disabled\n", mem_size); fbdev->buffer_count = 1; + fbdev->buffer_write = 0; mem_size = fbdev->fb_size; fbdev->mem = mmap(0, mem_size, PROT_WRITE|PROT_READ, MAP_SHARED, fbdev->fd, 0); } @@ -127,11 +136,13 @@ int vout_fbdev_resize(struct vout_fbdev *fbdev, int w, int h, fbdev->mem = NULL; fbdev->mem_size = 0; perror("mmap framebuffer"); - return -1; + return NULL; } fbdev->mem_size = mem_size; - return 0; + +out: + return (char *)fbdev->mem + fbdev->fb_size * fbdev->buffer_write; } void vout_fbdev_clear(struct vout_fbdev *fbdev) @@ -157,10 +168,11 @@ int vout_fbdev_get_fd(struct vout_fbdev *fbdev) return fbdev->fd; } -struct vout_fbdev *vout_fbdev_init(const char *fbdev_name, int *w, int *h, int no_dblbuf) +struct vout_fbdev *vout_fbdev_init(const char *fbdev_name, int *w, int *h, int bpp, int buffer_cnt) { struct vout_fbdev *fbdev; int req_w, req_h; + void *pret; int ret; fbdev = calloc(1, sizeof(*fbdev)); @@ -189,8 +201,8 @@ struct vout_fbdev *vout_fbdev_init(const char *fbdev_name, int *w, int *h, int n if (*h != 0) req_h = *h; - ret = vout_fbdev_resize(fbdev, req_w, req_h, 0, 0, 0, 0, no_dblbuf); - if (ret != 0) + pret = vout_fbdev_resize(fbdev, req_w, req_h, bpp, 0, 0, 0, 0, buffer_cnt); + if (pret == NULL) goto fail; printf("%s: %ix%i@%d\n", fbdev_name, fbdev->fbvar_new.xres, fbdev->fbvar_new.yres,