X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fvideo%2Fomapdss%2Fosdl_video.c;h=b2271cc1bd4a5657716a2c9c2b3dc5d605736eaa;hb=0c7caf2be89c7285aed60c5cb7a5ace9776033ab;hp=2c2226455c3005a144dd5dd86f04ddc409c768a4;hpb=455c8c43b353b60ebbb70caa09ae87be49520838;p=sdl_omap.git diff --git a/src/video/omapdss/osdl_video.c b/src/video/omapdss/osdl_video.c index 2c22264..b2271cc 100644 --- a/src/video/omapdss/osdl_video.c +++ b/src/video/omapdss/osdl_video.c @@ -1,5 +1,5 @@ /* - * (C) Gražvydas "notaz" Ignotas, 2010-2011 + * (C) Gražvydas "notaz" Ignotas, 2010-2012 * * This work is licensed under the terms of the GNU LGPL, version 2.1 or later. * See the COPYING file in the top-level directory. @@ -36,10 +36,12 @@ static const char *get_fb_device(void) return fbname; } -static int osdl_setup_omapfb(int fd, int enabled, int x, int y, int w, int h, int mem) +static int osdl_setup_omapfb(int fd, int enabled, int x, int y, int w, int h, + int mem, int *buffer_count) { struct omapfb_plane_info pi; struct omapfb_mem_info mi; + int mem_blocks = *buffer_count; int ret; memset(&pi, 0, sizeof(pi)); @@ -65,14 +67,20 @@ static int osdl_setup_omapfb(int fd, int enabled, int x, int y, int w, int h, in err_perror("SETUP_PLANE"); } - if (mi.size < mem) { - mi.size = mem; - ret = ioctl(fd, OMAPFB_SETUP_MEM, &mi); - if (ret != 0) { + if (mi.size < mem * mem_blocks) { + for (; mem_blocks > 0; mem_blocks--) { + mi.size = mem * mem_blocks; + ret = ioctl(fd, OMAPFB_SETUP_MEM, &mi); + if (ret == 0) + break; + } + if (ret != 0 || mem_blocks <= 0) { + err("failed to allocate at least %d bytes of vram:\n", mem); err_perror("SETUP_MEM"); return -1; } } + *buffer_count = mem_blocks; pi.pos_x = x; pi.pos_y = y; @@ -115,10 +123,36 @@ static int read_sysfs(const char *fname, char *buff, size_t size) return 0; } +int read_vscreeninfo(const char *fbname, int *w, int *h) +{ + struct fb_var_screeninfo fbvar; + int ret, fd; + + fd = open(fbname, O_RDWR); + if (fd == -1) { + err_perror("open %s", fbname); + return -1; + } + + ret = ioctl(fd, FBIOGET_VSCREENINFO, &fbvar); + close(fd); + + if (ret == -1) { + err_perror("ioctl %s", fbname); + return -1; + } + + if (fbvar.xres == 0 || fbvar.yres == 0) + return -1; + + *w = fbvar.xres; + *h = fbvar.yres; + return 0; +} + int osdl_video_detect_screen(struct SDL_PrivateVideoData *pdata) { int fb_id, overlay_id = -1, screen_id = -1; - struct fb_var_screeninfo fbvar; char buff[64], screen_name[64]; const char *fbname; struct stat status; @@ -201,36 +235,28 @@ int osdl_video_detect_screen(struct SDL_PrivateVideoData *pdata) skip_screen: /* attempt to extract this from FB then */ - fd = open(fbname, O_RDWR); - if (fd == -1) { - err_perror("open %s", fbname); - return -1; - } - - ret = ioctl(fd, FBIOGET_VSCREENINFO, &fbvar); - close(fd); - if (ret == -1) { - err_perror("ioctl %s", fbname); - return -1; + ret = read_vscreeninfo(fbname, &pdata->phys_w, &pdata->phys_h); + if (ret != 0 && strcmp(fbname, "/dev/fb0") != 0) { + /* last resort */ + ret = read_vscreeninfo("/dev/fb0", &pdata->phys_w, &pdata->phys_h); } - if (fbvar.xres == 0 || fbvar.yres == 0) { + if (ret != 0) { err("VSCREENINFO has nothing meaningful"); return -1; } - pdata->phys_w = fbvar.xres; - pdata->phys_h = fbvar.yres; return 0; } static int osdl_setup_omap_layer(struct SDL_PrivateVideoData *pdata, - const char *fbname, int width, int height, int bpp) + const char *fbname, int width, int height, int bpp, int *buffer_count) { int x = 0, y = 0, w = width, h = height; /* layer size and pos */ int screen_w = w, screen_h = h; int tmp_w, tmp_h; const char *tmp; + int retval = -1; int ret, fd; pdata->layer_x = pdata->layer_y = pdata->layer_w = pdata->layer_h = 0; @@ -251,18 +277,18 @@ static int osdl_setup_omap_layer(struct SDL_PrivateVideoData *pdata, struct omapfb_saved_layer *slayer; slayer = calloc(1, sizeof(*slayer)); if (slayer == NULL) - return -1; + goto out; ret = ioctl(fd, OMAPFB_QUERY_PLANE, &slayer->pi); if (ret != 0) { err_perror("QUERY_PLANE"); - return -1; + goto out; } ret = ioctl(fd, OMAPFB_QUERY_MEM, &slayer->mi); if (ret != 0) { err_perror("QUERY_MEM"); - return -1; + goto out; } pdata->saved_layer = slayer; @@ -278,35 +304,38 @@ static int osdl_setup_omap_layer(struct SDL_PrivateVideoData *pdata, err("layer size specified incorrectly, " "should be like 800x480"); } - else { - /* the layer can't be set larger than screen */ - tmp_w = w, tmp_h = h; - if (w > screen_w) - w = screen_w; - if (h > screen_h) - h = screen_h; - if (w != tmp_w || h != tmp_h) - log("layer resized %dx%d -> %dx%d to fit screen", tmp_w, tmp_h, w, h); - } + + /* the layer can't be set larger than screen */ + tmp_w = w, tmp_h = h; + if (w > screen_w) + w = screen_w; + if (h > screen_h) + h = screen_h; + if (w != tmp_w || h != tmp_h) + log("layer resized %dx%d -> %dx%d to fit screen", tmp_w, tmp_h, w, h); x = screen_w / 2 - w / 2; y = screen_h / 2 - h / 2; - ret = osdl_setup_omapfb(fd, 1, x, y, w, h, width * height * ((bpp + 7) / 8) * 2); + ret = osdl_setup_omapfb(fd, 1, x, y, w, h, + width * height * ((bpp + 7) / 8), buffer_count); if (ret == 0) { pdata->layer_x = x; pdata->layer_y = y; pdata->layer_w = w; pdata->layer_h = h; } - close(fd); - return ret; + retval = ret; +out: + close(fd); + return retval; } void *osdl_video_set_mode(struct SDL_PrivateVideoData *pdata, int border_l, int border_r, int border_t, int border_b, - int width, int height, int bpp, int doublebuf) + int width, int height, int bpp, int *doublebuf) { + int buffers_try, buffers_set; const char *fbname; void *result; int ret; @@ -318,27 +347,30 @@ void *osdl_video_set_mode(struct SDL_PrivateVideoData *pdata, pdata->fbdev = NULL; } - ret = osdl_setup_omap_layer(pdata, fbname, width, height, bpp); + buffers_try = buffers_set = 1; + if (*doublebuf) + /* actually try tripple buffering for reduced chance of tearing */ + buffers_try = buffers_set = 3; + + ret = osdl_setup_omap_layer(pdata, fbname, width, height, bpp, &buffers_set); if (ret < 0) - return NULL; + goto fail; - pdata->fbdev = vout_fbdev_init(fbname, &width, &height, bpp, doublebuf ? 2 : 1); + pdata->fbdev = vout_fbdev_init(fbname, &width, &height, bpp, buffers_set); if (pdata->fbdev == NULL) - return NULL; + goto fail; if (border_l | border_r | border_t | border_b) { width -= border_l + border_r; height -= border_t + border_b; result = vout_fbdev_resize(pdata->fbdev, width, height, bpp, - border_l, border_r, border_t, border_b, doublebuf ? 2 : 1); + border_l, border_r, border_t, border_b, buffers_set); } else { result = osdl_video_flip(pdata); } - if (result == NULL) { - osdl_video_finish(pdata); - return NULL; - } + if (result == NULL) + goto fail; if (!pdata->xenv_up) { ret = xenv_init(); @@ -346,18 +378,32 @@ void *osdl_video_set_mode(struct SDL_PrivateVideoData *pdata, pdata->xenv_up = 1; } + if (buffers_try != buffers_set) { + log("only %d/%d buffers available, expect tearing\n", + buffers_set, buffers_try); + *doublebuf = buffers_set > 1; + } + return result; + +fail: + osdl_video_finish(pdata); + return NULL; } void *osdl_video_flip(struct SDL_PrivateVideoData *pdata) { + void *ret; + if (pdata->fbdev == NULL) return NULL; + ret = vout_fbdev_flip(pdata->fbdev); + if (pdata->cfg_force_vsync) vout_fbdev_wait_vsync(pdata->fbdev); - return vout_fbdev_flip(pdata->fbdev); + return ret; } void osdl_video_finish(struct SDL_PrivateVideoData *pdata)