ioctl(fbdev->fd, FBIO_WAITFORVSYNC, &arg);
}
-int vout_fbdev_resize(struct vout_fbdev *fbdev, int w, int h, int bpp,
+/* 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;
fbdev->fbvar_new.xres_virtual = w_total;
fbdev->fbvar_new.yres_virtual = h_total;
fbdev->fbvar_new.xoffset = left_border;
+ 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 = buffer_cnt;
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");
}
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 = 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)
{
struct vout_fbdev *fbdev;
int req_w, req_h;
+ void *pret;
int ret;
fbdev = calloc(1, sizeof(*fbdev));
if (*h != 0)
req_h = *h;
- ret = vout_fbdev_resize(fbdev, req_w, req_h, bpp, 0, 0, 0, 0, buffer_cnt);
- 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,
struct vout_fbdev *vout_fbdev_init(const char *fbdev_name, int *w, int *h, int bpp, int buffer_count);
void *vout_fbdev_flip(struct vout_fbdev *fbdev);
void vout_fbdev_wait_vsync(struct vout_fbdev *fbdev);
-int vout_fbdev_resize(struct vout_fbdev *fbdev, int w, int h, int bpp,
+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_count);
void vout_fbdev_clear(struct vout_fbdev *fbdev);
int pl_fbdev_set_mode(int w, int h, int bpp)
{
- int ret;
+ void *ret;
pl_fbdev_w = w;
- printf("set mode %dx%d@%d\n", w, h, bpp);
+
+ vout_fbdev_clear(layer_fb);
ret = vout_fbdev_resize(layer_fb, w, h, bpp, 0, 0, 0, 0, 3);
- if (ret)
+ if (ret == NULL)
fprintf(stderr, "failed to set mode\n");
- return ret;
+ else
+ pl_fbdev_buf = ret;
+
+ return (ret != NULL) ? 0 : -1;
}
void *pl_fbdev_flip(void)
{
extern void bgr555_to_rgb565(void *dst, void *src, int bytes);
extern void bgr888_to_rgb888(void *dst, void *src, int bytes);
- int x = PSXDisplay.DisplayPosition.x;
+ int x = PSXDisplay.DisplayPosition.x & ~3; // XXX: align needed by bgr*_to_...
int y = PSXDisplay.DisplayPosition.y;
int w = PreviousPSXDisplay.Range.x1;
int h = PreviousPSXDisplay.DisplayMode.y;
if (PSXDisplay.DisplayMode.x == 0 || PSXDisplay.DisplayMode.y == 0)
return;
+ /* careful if rearranging this code, we try to set mode and flip
+ * to get the hardware apply both changes at the same time */
if (PSXDisplay.DisplayMode.x != fbw || PSXDisplay.DisplayMode.y != fbh
|| PSXDisplay.RGB24 != fb24bpp) {
fbw = PSXDisplay.DisplayMode.x;