X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fvideo%2Fomapdss%2Fosdl_video.c;h=108ef8af24303ac6bbba97dfcf8b90e050a9fda9;hb=f9b3f440374c61339a12046b226066658e313065;hp=450176e2d1e887268dac89eb9298147f4b419127;hpb=7b66578c38502c173e310eb68f0cddc2e7b5031e;p=sdl_omap.git diff --git a/src/video/omapdss/osdl_video.c b/src/video/omapdss/osdl_video.c index 450176e..108ef8a 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 + * (C) Gražvydas "notaz" Ignotas, 2010-2011 * * 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. @@ -20,13 +20,22 @@ #include "omapsdl.h" #include "omapfb.h" #include "linux/fbdev.h" -#include "linux/oshide.h" +#include "linux/xenv.h" struct omapfb_saved_layer { struct omapfb_plane_info pi; struct omapfb_mem_info mi; }; +static const char *get_fb_device(void) +{ + const char *fbname = getenv("SDL_FBDEV"); + if (fbname == NULL) + fbname = "/dev/fb1"; + + return fbname; +} + static int osdl_setup_omapfb(int fd, int enabled, int x, int y, int w, int h, int mem) { struct omapfb_plane_info pi; @@ -53,11 +62,13 @@ static int osdl_setup_omapfb(int fd, int enabled, int x, int y, int w, int h, in err_perror("SETUP_PLANE"); } - mi.size = mem; - ret = ioctl(fd, OMAPFB_SETUP_MEM, &mi); - if (ret != 0) { - err_perror("SETUP_MEM"); - return -1; + if (mi.size < mem) { + mi.size = mem; + ret = ioctl(fd, OMAPFB_SETUP_MEM, &mi); + if (ret != 0) { + err_perror("SETUP_MEM"); + return -1; + } } pi.pos_x = x; @@ -69,6 +80,7 @@ static int osdl_setup_omapfb(int fd, int enabled, int x, int y, int w, int h, in ret = ioctl(fd, OMAPFB_SETUP_PLANE, &pi); if (ret != 0) { err_perror("SETUP_PLANE"); + err("(%d %d %d %d)\n", x, y, w, h); return -1; } @@ -100,52 +112,26 @@ static int read_sysfs(const char *fname, char *buff, size_t size) return 0; } -static int osdl_setup_omap_layer(struct SDL_PrivateVideoData *pdata, - const char *fbname, int width, int height, int bpp) +int osdl_video_detect_screen(struct SDL_PrivateVideoData *pdata) { - int x = 0, y = 0, w = width, h = height; /* layer size and pos */ - int screen_w = w, screen_h = h; 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; - const char *tmp; - int i, ret, fd; + int fd, i, ret; + int w, h; FILE *f; - fd = open(fbname, O_RDWR); - if (fd == -1) { - err_perror("open %s", fbname); - return -1; - } + fbname = get_fb_device(); - /* FIXME: assuming layer doesn't change here */ - if (pdata->saved_layer == NULL) { - struct omapfb_saved_layer *slayer; - slayer = calloc(1, sizeof(*slayer)); - if (slayer == NULL) - return -1; - - ret = ioctl(fd, OMAPFB_QUERY_PLANE, &slayer->pi); - if (ret != 0) { - err_perror("QUERY_PLANE"); - return -1; - } - - ret = ioctl(fd, OMAPFB_QUERY_MEM, &slayer->mi); - if (ret != 0) { - err_perror("QUERY_MEM"); - return -1; - } - - pdata->saved_layer = slayer; - } - - /* Figure out screen resolution, we will want to center if scaling is not enabled. + /* Figure out screen resolution, we need to know default resolution + * to report to SDL and for centering stuff. * The only way to achieve this seems to be walking some sysfs files.. */ ret = stat(fbname, &status); if (ret != 0) { err_perror("can't stat %s", fbname); - return -1; + goto skip_screen; } fb_id = minor(status.st_rdev); @@ -194,7 +180,7 @@ static int osdl_setup_omap_layer(struct SDL_PrivateVideoData *pdata, goto skip_screen; } - ret = fscanf(f, "%*d,%d/%*d/%*d/%*d,%d/%*d/%*d/%*d", &screen_w, &screen_h); + ret = fscanf(f, "%*d,%d/%*d/%*d/%*d,%d/%*d/%*d/%*d", &w, &h); fclose(f); if (ret != 2) { err("can't parse %s (%d), skip screen detection", buff, ret); @@ -202,9 +188,78 @@ static int osdl_setup_omap_layer(struct SDL_PrivateVideoData *pdata, } log("detected %dx%d '%s' (%d) screen attached to fb %d and overlay %d", - screen_w, screen_h, screen_name, screen_id, fb_id, overlay_id); + w, h, screen_name, screen_id, fb_id, overlay_id); + + pdata->screen_w = w; + pdata->screen_h = h; + return 0; 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; + } + + if (fbvar.xres == 0 || fbvar.yres == 0) { + err("VSCREENINFO has nothing meaningful"); + return -1; + } + + pdata->screen_w = fbvar.xres; + pdata->screen_h = fbvar.yres; + return 0; +} + +static int osdl_setup_omap_layer(struct SDL_PrivateVideoData *pdata, + const char *fbname, int width, int height, int bpp) +{ + int x = 0, y = 0, w = width, h = height; /* layer size and pos */ + int screen_w = w, screen_h = h; + const char *tmp; + int ret, fd; + + if (pdata->screen_w != 0) + screen_w = pdata->screen_w; + if (pdata->screen_h != 0) + screen_h = pdata->screen_h; + + fd = open(fbname, O_RDWR); + if (fd == -1) { + err_perror("open %s", fbname); + return -1; + } + + /* FIXME: assuming layer doesn't change here */ + if (pdata->saved_layer == NULL) { + struct omapfb_saved_layer *slayer; + slayer = calloc(1, sizeof(*slayer)); + if (slayer == NULL) + return -1; + + ret = ioctl(fd, OMAPFB_QUERY_PLANE, &slayer->pi); + if (ret != 0) { + err_perror("QUERY_PLANE"); + return -1; + } + + ret = ioctl(fd, OMAPFB_QUERY_MEM, &slayer->mi); + if (ret != 0) { + err_perror("QUERY_MEM"); + return -1; + } + + pdata->saved_layer = slayer; + } + tmp = getenv("SDL_OMAP_LAYER_SIZE"); if (tmp != NULL) { int w_, h_; @@ -219,7 +274,7 @@ skip_screen: 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) * 3); + ret = osdl_setup_omapfb(fd, 1, x, y, w, h, width * height * ((bpp + 7) / 8) * 2); close(fd); return ret; @@ -230,11 +285,7 @@ int osdl_video_set_mode(struct SDL_PrivateVideoData *pdata, int width, int heigh const char *fbname; int ret; - bpp = 16; // FIXME - - fbname = getenv("SDL_FBDEV"); - if (fbname == NULL) - fbname = "/dev/fb1"; + fbname = get_fb_device(); if (pdata->fbdev != NULL) { vout_fbdev_finish(pdata->fbdev); @@ -247,13 +298,14 @@ int osdl_video_set_mode(struct SDL_PrivateVideoData *pdata, int width, int heigh if (ret < 0) return -1; - pdata->fbdev = vout_fbdev_init(fbname, &width, &height, 0); + pdata->fbdev = vout_fbdev_init(fbname, &width, &height, bpp, 2); if (pdata->fbdev == NULL) return -1; - if (!pdata->oshide_done) { - oshide_init(); - pdata->oshide_done = 1; + if (!pdata->xenv_up) { + ret = xenv_init(); + if (ret == 0) + pdata->xenv_up = 1; } return 0; @@ -274,10 +326,7 @@ void osdl_video_finish(struct SDL_PrivateVideoData *pdata) { static const char *fbname; - fbname = getenv("SDL_FBDEV"); - if (fbname == NULL) - fbname = "/dev/fb1"; - + fbname = get_fb_device(); if (pdata->fbdev != NULL) { vout_fbdev_finish(pdata->fbdev); pdata->fbdev = NULL; @@ -306,9 +355,9 @@ void osdl_video_finish(struct SDL_PrivateVideoData *pdata) pdata->saved_layer = NULL; } - if (pdata->oshide_done) { - oshide_finish(); - pdata->oshide_done = 0; + if (pdata->xenv_up) { + xenv_finish(); + pdata->xenv_up = 0; } }