Add support for border removal
authornotaz <notasas@gmail.com>
Wed, 23 Nov 2011 23:29:54 +0000 (01:29 +0200)
committernotaz <notasas@gmail.com>
Wed, 23 Nov 2011 23:29:54 +0000 (01:29 +0200)
README.OMAP
src/video/omapdss/config.c
src/video/omapdss/linux/fbdev.c
src/video/omapdss/omapsdl.h
src/video/omapdss/osdl_video.c
src/video/omapdss/sdlif.c

index e1ddb06..2da9e26 100644 (file)
@@ -37,10 +37,20 @@ Other environment variables:
 
 SDL_OMAP_LAYER_SIZE:
   Output layer size. Regardless what you set with SDL_SetVideoMode(), output
-  will be scaled to this size using hardware. Valid values:
+  will be scaled to this size using hardware with zero processing cost.
+  Note: scaling amount range is limited to roughly 1/4x-8x. The exact range
+  depends on various factors like version of the driver or OMAP hardware itself.
+  Valid values:
     "WxH", for example "640x480"
     "fullscreen" to cover whole screen.
 
+SDL_OMAP_BORDER_CUT:
+  This can be used to move parts of SDL surface out of screen, in other
+  words cut borders and zoom in. Format: <left>,<right>,<top>,<bottom>
+  For example, "0,0,16,0" would hide top 16 lines offscreen, making 17th
+  (16th if you count from 0) line the first visible.
+  Note: like for layer size ranges are limited.
+
 SDL_OMAP_VSYNC:
   Enables waiting for vertical sync on SDL_Flip() calls.
   Set to "1" to enable, "0" to disable.
index a1eb5fd..d84b862 100644 (file)
@@ -115,5 +115,16 @@ void omapsdl_config_from_env(struct SDL_PrivateVideoData *pdata)
        tmp = getenv("SDL_OMAP_NO_TS_TRANSLATE");
        if (tmp != NULL)
                pdata->cfg_no_ts_translate = !!strtol(tmp, NULL, 0);
+       tmp = getenv("SDL_OMAP_BORDER_CUT");
+       if (tmp != NULL) {
+               int l, r, t, b;
+               if (sscanf(tmp, "%d,%d,%d,%d", &l, &r, &t, &b) == 4
+                   && l >= 0 && r >= 0 && t >= 0 && b >= 0) {
+                       pdata->border_l = l, pdata->border_r = r;
+                       pdata->border_t = t, pdata->border_b = b;
+               }
+               else
+                       err("border incorrectly specified, ignored");
+       }
 }
 
index 9d532a5..afd5531 100644 (file)
@@ -94,7 +94,7 @@ void *vout_fbdev_resize(struct vout_fbdev *fbdev, int w, int h, int bpp,
                fbdev->fbvar_new.bits_per_pixel = bpp;
                fbdev->fbvar_new.nonstd = 0; // can set YUV here on omapfb
                fbdev->buffer_count = buffer_cnt;
-               fbdev->buffer_write = 1;
+               fbdev->buffer_write = buffer_cnt > 1 ? 1 : 0;
 
                // seems to help a bit to avoid glitches
                vout_fbdev_wait_vsync(fbdev);
index 1f937c0..d6314d6 100644 (file)
@@ -32,6 +32,8 @@ struct SDL_PrivateVideoData {
        int phys_w, phys_h;
        /* layer */
        int layer_x, layer_y, layer_w, layer_h;
+       /* SDL surface borders to hide */
+       int border_l, border_r, border_t, border_b;
        /* phys -> layer coord multipliers (16.16) */
        int ts_xmul, ts_ymul;
        /* misc/config */
@@ -41,7 +43,8 @@ struct SDL_PrivateVideoData {
        unsigned int cfg_no_ts_translate:1;
 };
 
-int   osdl_video_set_mode(struct SDL_PrivateVideoData *pdata,
+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);
 void *osdl_video_flip(struct SDL_PrivateVideoData *pdata);
 int   osdl_video_detect_screen(struct SDL_PrivateVideoData *pdata);
index fce7eea..2c22264 100644 (file)
@@ -303,10 +303,12 @@ static int osdl_setup_omap_layer(struct SDL_PrivateVideoData *pdata,
        return ret;
 }
 
-int osdl_video_set_mode(struct SDL_PrivateVideoData *pdata,
-                       int width, int height, int bpp, int doublebuf)
+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)
 {
        const char *fbname;
+       void *result;
        int ret;
 
        fbname = get_fb_device();
@@ -318,11 +320,25 @@ int osdl_video_set_mode(struct SDL_PrivateVideoData *pdata,
 
        ret = osdl_setup_omap_layer(pdata, fbname, width, height, bpp);
        if (ret < 0)
-               return -1;
+               return NULL;
 
        pdata->fbdev = vout_fbdev_init(fbname, &width, &height, bpp, doublebuf ? 2 : 1);
        if (pdata->fbdev == NULL)
-               return -1;
+               return NULL;
+
+       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);
+       }
+       else {
+               result = osdl_video_flip(pdata);
+       }
+       if (result == NULL) {
+               osdl_video_finish(pdata);
+               return NULL;
+       }
 
        if (!pdata->xenv_up) {
                ret = xenv_init();
@@ -330,7 +346,7 @@ int osdl_video_set_mode(struct SDL_PrivateVideoData *pdata,
                        pdata->xenv_up = 1;
        }
 
-       return 0;
+       return result;
 }
 
 void *osdl_video_flip(struct SDL_PrivateVideoData *pdata)
index a4443c8..fb690d4 100644 (file)
@@ -94,7 +94,7 @@ static SDL_Surface *omap_SetVideoMode(SDL_VideoDevice *this, SDL_Surface *curren
        struct SDL_PrivateVideoData *pdata = this->hidden;
        SDL_PixelFormat *format;
        Uint32 unhandled_flags;
-       int ret;
+       void *fbmem;
 
        trace("%d, %d, %d, %08x", width, height, bpp, flags);
 
@@ -122,10 +122,23 @@ static SDL_Surface *omap_SetVideoMode(SDL_VideoDevice *this, SDL_Surface *curren
                flags |= SDL_DOUBLEBUF;
        }
 
-       ret = osdl_video_set_mode(pdata, width, height, bpp,
-               (flags & SDL_DOUBLEBUF) ? 1 : 0);
-       if (ret < 0)
+       if (pdata->border_l | pdata->border_r | pdata->border_t | pdata->border_b) {
+               if (pdata->border_l + pdata->border_r >= width
+                   || pdata->border_t + pdata->border_b >= height)
+               {
+                       err("specified border too large, ignoring");
+                       pdata->border_l = pdata->border_r = pdata->border_t = pdata->border_b = 0;
+               }
+       }
+
+       fbmem = osdl_video_set_mode(pdata,
+               pdata->border_l, pdata->border_r, pdata->border_t, pdata->border_b,
+               width, height, bpp, (flags & SDL_DOUBLEBUF) ? 1 : 0);
+       if (fbmem == NULL) {
+               log("failing on mode %dx%d@%d, doublebuf %s",
+                   width, height, bpp, (flags & SDL_DOUBLEBUF) ? "on" : "off");
                return NULL;
+       }
 
        flags |= SDL_FULLSCREEN | SDL_HWSURFACE;
        unhandled_flags = flags & ~(SDL_FULLSCREEN | SDL_HWSURFACE | SDL_DOUBLEBUF);
@@ -138,14 +151,15 @@ static SDL_Surface *omap_SetVideoMode(SDL_VideoDevice *this, SDL_Surface *curren
        current->w = width;
        current->h = height;
        current->pitch = SDL_CalculatePitch(current);
+       current->pixels = fbmem;
 
        if (pdata->layer_w != 0 && pdata->layer_h != 0) {
-               pdata->ts_xmul = (width  << 16) / pdata->layer_w;
-               pdata->ts_ymul = (height << 16) / pdata->layer_h;
+               int v_width  = width  - (pdata->border_l + pdata->border_r);
+               int v_height = height - (pdata->border_t + pdata->border_b);
+               pdata->ts_xmul = (v_width  << 16) / pdata->layer_w;
+               pdata->ts_ymul = (v_height << 16) / pdata->layer_h;
        }
 
-       current->pixels = osdl_video_flip(pdata);
-
        return current;
 }
 
@@ -227,8 +241,8 @@ static int ts_event_cb(void *cb_arg, int x, int y, unsigned int pressure)
        int xoffs;
 
        if (!pdata->cfg_no_ts_translate && pdata->layer_w != 0 && pdata->layer_h != 0) {
-               x = (x - pdata->layer_x) * pdata->ts_xmul >> 16;
-               y = (y - pdata->layer_y) * pdata->ts_ymul >> 16;
+               x = pdata->border_l + ((x - pdata->layer_x) * pdata->ts_xmul >> 16);
+               y = pdata->border_t + ((y - pdata->layer_y) * pdata->ts_ymul >> 16);
                clamp(x, 0, this->screen->w);
                clamp(y, 0, this->screen->h);
        }