adjust default layer size to fit screen
[sdl_omap.git] / src / video / omapdss / osdl_video.c
index 6cd7b31..d00b6b9 100644 (file)
@@ -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,7 +20,7 @@
 #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;
@@ -62,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;
@@ -78,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;
        }
 
@@ -221,6 +224,7 @@ static int osdl_setup_omap_layer(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 tmp_w, tmp_h;
        const char *tmp;
        int ret, fd;
 
@@ -259,31 +263,39 @@ static int osdl_setup_omap_layer(struct SDL_PrivateVideoData *pdata,
 
        tmp = getenv("SDL_OMAP_LAYER_SIZE");
        if (tmp != NULL) {
-               int w_, h_;
                if (strcasecmp(tmp, "fullscreen") == 0)
                        w = screen_w, h = screen_h;
-               else if (sscanf(tmp, "%dx%d", &w_, &h_) == 2)
-                       w = w_, h = h_;
+               else if (sscanf(tmp, "%dx%d", &tmp_w, &tmp_h) == 2)
+                       w = tmp_w, h = tmp_h;
                else
                        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);
+       }
 
        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;
 }
 
-int osdl_video_set_mode(struct SDL_PrivateVideoData *pdata, int width, int height, int bpp)
+int osdl_video_set_mode(struct SDL_PrivateVideoData *pdata,
+                       int width, int height, int bpp, int doublebuf)
 {
        const char *fbname;
        int ret;
 
-       bpp = 16; // FIXME
-
        fbname = get_fb_device();
 
        if (pdata->fbdev != NULL) {
@@ -291,19 +303,18 @@ int osdl_video_set_mode(struct SDL_PrivateVideoData *pdata, int width, int heigh
                pdata->fbdev = NULL;
        }
 
-       omapsdl_config_from_env();
-
        ret = osdl_setup_omap_layer(pdata, fbname, width, height, bpp);
        if (ret < 0)
                return -1;
 
-       pdata->fbdev = vout_fbdev_init(fbname, &width, &height, 0);
+       pdata->fbdev = vout_fbdev_init(fbname, &width, &height, bpp, doublebuf ? 2 : 1);
        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;
@@ -353,9 +364,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;
        }
 }