pandora: do automatic layer switching for TV
authornotaz <notasas@gmail.com>
Wed, 16 Oct 2013 23:15:33 +0000 (02:15 +0300)
committernotaz <notasas@gmail.com>
Wed, 16 Oct 2013 23:15:33 +0000 (02:15 +0300)
README.OMAP
src/video/omapdss/osdl.h
src/video/omapdss/osdl_video.c

index 96af240..e5397ce 100644 (file)
@@ -92,6 +92,9 @@ SDL_OMAP_TS_FORCE_TSLIB:
   Always use tslib to read touchscreen. Without this, use X events when they
   are available (this gives external input device support).
 
+SDL_OMAP_NO_PANDORA_TV:
+  This disables automatic framebuffer redirection to TV on pandora.
+
 
 Config file
 -----------
index 6a1789c..5421f10 100644 (file)
@@ -30,7 +30,7 @@ struct x11reuse_context;
 struct SDL_PrivateVideoData {
        struct vout_fbdev *fbdev;
        void *front_buffer;
-       void *saved_layer;
+       void *layer_state;
        /* physical screen size, should match touchscreen */
        int phys_w, phys_h;
        /* layer */
index bf42a00..9cc6252 100644 (file)
@@ -29,8 +29,48 @@ struct omapfb_state {
        struct omapfb_mem_info mi;
        struct omapfb_plane_info pi_old;
        struct omapfb_mem_info mi_old;
+       int tv_layer;
 };
 
+static int read_sysfs(const char *fname, char *buff, size_t size);
+
+static int switch_tv_layer(struct omapfb_state *ostate, int layer)
+{
+       const char *tmp;
+       struct stat st;
+       char buf[128];
+       int ret;
+
+       tmp = getenv("SDL_OMAP_NO_PANDORA_TV");
+       if (tmp != NULL && !!strtol(tmp, NULL, 0))
+               return 0;
+
+       if (stat("/proc/pandora", &st) != 0)
+               /* not pandora, don't mess with stuff */
+               return 0;
+
+       ret = read_sysfs("/sys/devices/platform/omapdss/display1/enabled",
+               buf, sizeof(buf));
+       if (ret < 0) {
+               err("couldn't check display1 state");
+               return -1;
+       }
+
+       if (strtol(buf, NULL, 0) == 0)
+               /* TV-out not enabled */
+               return 0;
+
+       snprintf(buf, sizeof(buf),
+                "sudo -n /usr/pandora/scripts/op_tvout.sh -l %d", layer);
+       ret = system(buf);
+       if (ret >= 0) {
+               ostate->tv_layer = layer;
+               ret = 0;
+       }
+
+       return ret;
+}
+
 static const char *get_fb_device(void)
 {
        const char *fbname = getenv("SDL_FBDEV");
@@ -112,6 +152,8 @@ static int osdl_setup_omapfb_enable(struct omapfb_state *ostate,
 {
        int ret;
 
+       switch_tv_layer(ostate, 1);
+
        ostate->pi.enabled = enabled;
        ret = ioctl(fd, OMAPFB_SETUP_PLANE, &ostate->pi);
        if (ret != 0)
@@ -295,7 +337,7 @@ static int osdl_setup_omap_layer(struct SDL_PrivateVideoData *pdata,
        }
 
        /* FIXME: assuming layer doesn't change here */
-       if (pdata->saved_layer == NULL) {
+       if (pdata->layer_state == NULL) {
                struct omapfb_state *slayer;
                slayer = calloc(1, sizeof(*slayer));
                if (slayer == NULL)
@@ -313,7 +355,7 @@ static int osdl_setup_omap_layer(struct SDL_PrivateVideoData *pdata,
                        goto out;
                }
 
-               pdata->saved_layer = slayer;
+               pdata->layer_state = slayer;
        }
 
        tmp = getenv("SDL_OMAP_LAYER_SIZE");
@@ -353,7 +395,7 @@ static int osdl_setup_omap_layer(struct SDL_PrivateVideoData *pdata,
 
        x = screen_w / 2 - w / 2;
        y = screen_h / 2 - h / 2;
-       ret = osdl_setup_omapfb(pdata->saved_layer, fd, 0, x, y, w, h,
+       ret = osdl_setup_omapfb(pdata->layer_state, fd, 0, x, y, w, h,
                                width * height * ((bpp + 7) / 8), buffer_count);
        if (ret == 0) {
                pdata->layer_x = x;
@@ -419,7 +461,7 @@ void *osdl_video_set_mode(struct SDL_PrivateVideoData *pdata,
                }
        }
 
-       ret = osdl_setup_omapfb_enable(pdata->saved_layer,
+       ret = osdl_setup_omapfb_enable(pdata->layer_state,
                vout_fbdev_get_fd(pdata->fbdev), 1);
        if (ret != 0) {
                err("layer enable failed");
@@ -464,7 +506,7 @@ void *osdl_video_get_active_buffer(struct SDL_PrivateVideoData *pdata)
 
 int osdl_video_pause(struct SDL_PrivateVideoData *pdata, int is_pause)
 {
-       struct omapfb_state *state = pdata->saved_layer;
+       struct omapfb_state *state = pdata->layer_state;
        struct omapfb_plane_info pi;
        struct omapfb_mem_info mi;
        int enabled;
@@ -541,10 +583,13 @@ void osdl_video_finish(struct SDL_PrivateVideoData *pdata)
        }
 
        /* restore the OMAP layer */
-       if (pdata->saved_layer != NULL) {
-               struct omapfb_state *slayer = pdata->saved_layer;
+       if (pdata->layer_state != NULL) {
+               struct omapfb_state *slayer = pdata->layer_state;
                int fd;
 
+               if (slayer->tv_layer)
+                       switch_tv_layer(slayer, 0);
+
                fd = open(fbname, O_RDWR);
                if (fd != -1) {
                        int enabled = slayer->pi_old.enabled;
@@ -560,7 +605,7 @@ void osdl_video_finish(struct SDL_PrivateVideoData *pdata)
                        close(fd);
                }
                free(slayer);
-               pdata->saved_layer = NULL;
+               pdata->layer_state = NULL;
        }
 
        if (pdata->xenv_up) {