]> git.sesse.net Git - vlc/blobdiff - modules/video_output/sdl.c
New video output driver: "vmem", for direct memory access.
[vlc] / modules / video_output / sdl.c
index 86a9144ed5036883fc93c63b5436b84eece33baf..3ed1de7168dc37347e0deb763a40d4461d8b0032 100644 (file)
  *****************************************************************************/
 #include <errno.h>                                                 /* ENOMEM */
 
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
 #include <vlc/vlc.h>
 #include <vlc_interface.h>
 #include <vlc_playlist.h>
@@ -59,8 +63,10 @@ struct vout_sys_t
     int i_width;
     int i_height;
 
+#if SDL_VERSION_ATLEAST(1,2,10)
     unsigned int i_desktop_width;
     unsigned int i_desktop_height;
+#endif
 
     /* For YUV output */
     SDL_Overlay * p_overlay;   /* An overlay we keep to grab the XVideo port */
@@ -72,8 +78,6 @@ struct vout_sys_t
     vlc_bool_t  b_cursor_autohidden;
     mtime_t     i_lastmoved;
     mtime_t     i_lastpressed;                        /* to track dbl-clicks */
-
-    vlc_mutex_t lock;
 };
 
 /*****************************************************************************
@@ -156,8 +160,6 @@ static int Open ( vlc_object_t *p_this )
         return VLC_ENOMEM;
     }
 
-    vlc_mutex_init( p_vout, &p_vout->p_sys->lock );
-
     /* Check if SDL video module has been initialized */
     if( SDL_WasInit( SDL_INIT_VIDEO ) != 0 )
     {
@@ -196,7 +198,7 @@ static int Open ( vlc_object_t *p_this )
     /* Win32 SDL implementation doesn't support SDL_INIT_EVENTTHREAD yet*/
                 | SDL_INIT_EVENTTHREAD
 #endif
-#ifdef DEBUG
+#ifndef NDEBUG
     /* In debug mode you may want vlc to dump a core instead of staying
      * stuck */
                 | SDL_INIT_NOPARACHUTE
@@ -215,8 +217,11 @@ static int Open ( vlc_object_t *p_this )
     SDL_EnableUNICODE(1);
 
     /* Get the desktop resolution */
+#if SDL_VERSION_ATLEAST(1,2,10)
+    /* FIXME: SDL has a problem with virtual desktop */
     p_vout->p_sys->i_desktop_width = SDL_GetVideoInfo()->current_w;
     p_vout->p_sys->i_desktop_height = SDL_GetVideoInfo()->current_h;
+#endif
 
     /* Create the cursor */
     p_vout->p_sys->b_cursor = 1;
@@ -339,8 +344,6 @@ static void Close ( vlc_object_t *p_this )
     CloseDisplay( p_vout );
     SDL_QuitSubSystem( SDL_INIT_VIDEO );
 
-    vlc_mutex_destroy( &p_vout->p_sys->lock );
-
     free( p_vout->p_sys );
 }
 
@@ -356,8 +359,6 @@ static int Manage( vout_thread_t *p_vout )
     vlc_value_t val;
     unsigned int i_width, i_height, i_x, i_y;
 
-    vlc_mutex_lock( &p_vout->p_sys->lock );
-
     /* Process events */
     while( SDL_PollEvent( &event ) )
     {
@@ -376,11 +377,30 @@ static int Manage( vout_thread_t *p_vout )
                                p_vout->p_sys->i_height,
                                &i_x, &i_y, &i_width, &i_height );
 
-            val.i_int = ( event.motion.x - i_x )
-                         * p_vout->render.i_width / i_width;
+            /* Compute the x coordinate and check if the value is
+               in [0,p_vout->fmt_in.i_visible_width] */
+            val.i_int = ( event.motion.x - i_x ) *
+                        p_vout->fmt_in.i_visible_width / i_width +
+                        p_vout->fmt_in.i_x_offset;
+
+            if( (int)(event.motion.x - i_x) < 0 )
+                val.i_int = 0;
+            else if( (unsigned int)val.i_int > p_vout->fmt_in.i_visible_width )
+                val.i_int = p_vout->fmt_in.i_visible_width;
+
             var_Set( p_vout, "mouse-x", val );
-            val.i_int = ( event.motion.y - i_y )
-                         * p_vout->render.i_height / i_height;
+
+            /* compute the y coordinate and check if the value is
+               in [0,p_vout->fmt_in.i_visible_height] */
+            val.i_int = ( event.motion.y - i_y ) *
+                        p_vout->fmt_in.i_visible_height / i_height +
+                        p_vout->fmt_in.i_y_offset;
+
+            if( (int)(event.motion.y - i_y) < 0 )
+                val.i_int = 0;
+            else if( (unsigned int)val.i_int > p_vout->fmt_in.i_visible_height )
+                val.i_int = p_vout->fmt_in.i_visible_height;
+
             var_Set( p_vout, "mouse-y", val );
 
             val.b_bool = VLC_TRUE;
@@ -612,8 +632,6 @@ static int Manage( vout_thread_t *p_vout )
         SDL_ShowCursor( 0 );
     }
 
-    vlc_mutex_unlock( &p_vout->p_sys->lock );
-
     return VLC_SUCCESS;
 }
 
@@ -693,8 +711,6 @@ static void Display( vout_thread_t *p_vout, picture_t *p_pic )
     unsigned int x, y, w, h;
     SDL_Rect disp;
 
-    vlc_mutex_lock( &p_vout->p_sys->lock );
-
     vout_PlacePicture( p_vout, p_vout->p_sys->i_width, p_vout->p_sys->i_height,
                        &x, &y, &w, &h );
     disp.x = x;
@@ -714,8 +730,6 @@ static void Display( vout_thread_t *p_vout, picture_t *p_pic )
         SDL_DisplayYUVOverlay( p_pic->p_sys->p_overlay , &disp );
         SDL_LockYUVOverlay( p_pic->p_sys->p_overlay);
     }
-
-    vlc_mutex_unlock( &p_vout->p_sys->lock );
 }
 
 /* following functions are local */
@@ -737,10 +751,17 @@ static int OpenDisplay( vout_thread_t *p_vout )
     uint32_t i_chroma = 0;
 
     /* Set main window's size */
+#if SDL_VERSION_ATLEAST(1,2,10)
     p_vout->p_sys->i_width = p_vout->b_fullscreen ? p_vout->p_sys->i_desktop_width :
                                                     p_vout->i_window_width;
     p_vout->p_sys->i_height = p_vout->b_fullscreen ? p_vout->p_sys->i_desktop_height :
                                                      p_vout->i_window_height;
+#else
+    p_vout->p_sys->i_width = p_vout->b_fullscreen ? p_vout->output.i_width :
+                                                    p_vout->i_window_width;
+    p_vout->p_sys->i_height = p_vout->b_fullscreen ? p_vout->output.i_height :
+                                                     p_vout->i_window_height;
+#endif
 
     /* Initialize flags and cursor */
     i_flags = SDL_ANYFORMAT | SDL_HWPALETTE | SDL_HWSURFACE | SDL_DOUBLEBUF;