]> git.sesse.net Git - vlc/blobdiff - modules/video_output/kva.c
Plug gestures on video output
[vlc] / modules / video_output / kva.c
index 1f6be5fcbb90d6042c8d42e18c92c55dcc61c5b4..9b149dbdecfa9e1ccfb4cf4328239a45de76736d 100644 (file)
@@ -1,23 +1,23 @@
 /*****************************************************************************
  * kva.c: KVA video output plugin for vlc
  *****************************************************************************
- * Copyright (C) 2010, 2011 the VideoLAN team
+ * Copyright (C) 2010, 2011, 2012 VLC authors and VideoLAN
  *
  * Authors: KO Myung-Hun <komh@chollian.net>
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
  * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 /*****************************************************************************
@@ -57,9 +57,9 @@ static void Close( vlc_object_t * );
     "Select a proper video mode to be used by KVA." )
 
 static const char *const ppsz_kva_video_mode[] = {
-    "auto", "snap", "wo", "dive" };
+    "auto", "snap", "wo", "vman", "dive" };
 static const char *const ppsz_kva_video_mode_text[] = {
-    N_("Auto"), N_("SNAP"), N_("WarpOverlay!"), N_("DIVE") };
+    N_("Auto"), N_("SNAP"), N_("WarpOverlay!"), N_("VMAN"), N_("DIVE") };
 
 vlc_module_begin ()
     set_shortname( "KVA" )
@@ -67,8 +67,8 @@ vlc_module_begin ()
     set_subcategory( SUBCAT_VIDEO_VOUT )
     add_string( "kva-video-mode", ppsz_kva_video_mode[0], KVA_VIDEO_MODE_TEXT,
                 KVA_VIDEO_MODE_LONGTEXT, false )
-        change_string_list( ppsz_kva_video_mode, ppsz_kva_video_mode_text, 0 )
-    add_bool( "kva-fixt23", false, KVA_FIXT23_TEXT, KVA_FIXT23_LONGTEXT, true );
+        change_string_list( ppsz_kva_video_mode, ppsz_kva_video_mode_text )
+    add_bool( "kva-fixt23", false, KVA_FIXT23_TEXT, KVA_FIXT23_LONGTEXT, true )
     set_description( N_("K Video Acceleration video output") )
     set_capability( "vout display", 100 )
     add_shortcut( "kva" )
@@ -101,9 +101,9 @@ struct vout_display_sys_t
     HWND               parent;
     RECTL              parent_rect;
     picture_pool_t    *pool;
-    picture_resource_t resource;
     unsigned           button_pressed;
     bool               is_mouse_hidden;
+    bool               is_on_top;
 };
 
 struct picture_sys_t
@@ -138,7 +138,8 @@ static MRESULT EXPENTRY WndProc       ( HWND, ULONG, MPARAM, MPARAM );
 #define WM_VLC_FULLSCREEN_CHANGE    ( WM_USER + 2 )
 #define WM_VLC_SIZE_CHANGE          ( WM_USER + 3 )
 
-static const char *psz_video_mode[ 3 ] = {"DIVE", "WarpOverlay!", "SNAP"};
+static const char *psz_video_mode[ 4 ] = {"DIVE", "WarpOverlay!", "SNAP",
+                                          "VMAN"};
 
 static void PMThread( void *arg )
 {
@@ -192,13 +193,6 @@ static void PMThread( void *arg )
     {
         sys->parent = ( HWND )sys->parent_window->handle.hwnd;
 
-        /* Workaround :
-         * When an embedded window opened first, it is not positioned
-         * correctly. So reposition it here, again.
-         */
-        WinSetWindowPos( WinQueryWindow( sys->parent, QW_PARENT ),
-                         HWND_TOP, 0, 0, 0, 0, SWP_MOVE );
-
         ULONG i_style = WinQueryWindowULong( sys->parent, QWL_STYLE );
         WinSetWindowULong( sys->parent, QWL_STYLE,
                            i_style | WS_CLIPCHILDREN );
@@ -233,7 +227,7 @@ static void PMThread( void *arg )
 
     WinSetWindowPtr( sys->client, 0, vd );
 
-    if( sys->b_fixt23 )
+    if( !sys->parent_window )
     {
         WinSetWindowPtr( sys->frame, 0, vd );
         sys->p_old_frame = WinSubclassWindow( sys->frame, MyFrameWndProc );
@@ -246,6 +240,8 @@ static void PMThread( void *arg )
         i_kva_mode = KVAM_SNAP;
     else if( strcmp( psz_mode, "wo" ) == 0 )
         i_kva_mode = KVAM_WO;
+    else if( strcmp( psz_mode, "vman" ) == 0 )
+        i_kva_mode = KVAM_VMAN;
     else if( strcmp( psz_mode, "dive" ) == 0 )
         i_kva_mode = KVAM_DIVE;
 
@@ -297,9 +293,15 @@ static void PMThread( void *arg )
     sys->i_result = VLC_SUCCESS;
     DosPostEventSem( sys->ack_event );
 
+    if( !sys->parent_window )
+        WinSetVisibleRegionNotify( sys->frame, TRUE );
+
     while( WinGetMsg( sys->hab, &qm, NULLHANDLE, 0, 0 ))
         WinDispatchMsg( sys->hab, &qm );
 
+    if( !sys->parent_window )
+        WinSetVisibleRegionNotify( sys->frame, FALSE );
+
     kvaEnableScreenSaver();
 
     CloseDisplay( vd );
@@ -310,7 +312,7 @@ exit_open_display :
     kvaDone();
 
 exit_kva_init :
-    if( sys->b_fixt23 )
+    if( !sys->parent_window )
         WinSubclassWindow( sys->frame, sys->p_old_frame );
 
     WinDestroyWindow( sys->frame );
@@ -434,7 +436,8 @@ static int Control( vout_display_t *vd, int query, va_list args )
         POINTL ptl;
 
         WinQueryPointerPos( HWND_DESKTOP, &ptl );
-        if( WinWindowFromPoint( HWND_DESKTOP, &ptl, TRUE ) == sys->client )
+        if( !sys->is_mouse_hidden &&
+            WinWindowFromPoint( HWND_DESKTOP, &ptl, TRUE ) == sys->client )
         {
             WinShowPointer( HWND_DESKTOP, FALSE );
             sys->is_mouse_hidden = true;
@@ -456,6 +459,24 @@ static int Control( vout_display_t *vd, int query, va_list args )
         return VLC_SUCCESS;
     }
 
+    case VOUT_DISPLAY_CHANGE_WINDOW_STATE:
+    {
+        const unsigned state = va_arg( args, unsigned );
+        const bool is_on_top = (state & VOUT_WINDOW_STATE_ABOVE) != 0;
+
+        if( sys->parent_window )
+        {
+            if( vout_window_SetState( sys->parent_window, state ))
+                return VLC_EGENERIC;
+        }
+        else if( is_on_top )
+            WinSetWindowPos( sys->frame, HWND_TOP, 0, 0, 0, 0, SWP_ZORDER );
+
+        sys->is_on_top = is_on_top;
+
+        return VLC_SUCCESS;
+    }
+
     case VOUT_DISPLAY_CHANGE_DISPLAY_SIZE:
     {
         const vout_display_cfg_t *cfg = va_arg(args, const vout_display_cfg_t *);
@@ -467,15 +488,6 @@ static int Control( vout_display_t *vd, int query, va_list args )
             {
                 vout_window_SetSize(sys->parent_window,
                                     cfg->display.width, cfg->display.height);
-
-                /* Workaround :
-                 * If changing aspect ratio after resizing a main window,
-                 * an embedded window is misplaced. So reposition it, here.
-                 */
-                WinSetWindowPos( WinQueryWindow( sys->parent, QW_PARENT ),
-                                 HWND_TOP, 0, 1, 0, 0, SWP_MOVE );
-                WinSetWindowPos( WinQueryWindow( sys->parent, QW_PARENT ),
-                                 HWND_TOP, 0, 0, 0, 0, SWP_MOVE );
             }
             else
                 WinPostMsg( sys->client, WM_VLC_SIZE_CHANGE,
@@ -513,7 +525,6 @@ static int Control( vout_display_t *vd, int query, va_list args )
     }
 
     case VOUT_DISPLAY_RESET_PICTURES:
-    case VOUT_DISPLAY_CHANGE_WINDOW_STATE:
     case VOUT_DISPLAY_CHANGE_DISPLAY_FILLED:
     case VOUT_DISPLAY_CHANGE_ZOOM:
     case VOUT_DISPLAY_GET_OPENGL:
@@ -573,6 +584,12 @@ static int OpenDisplay( vout_display_t *vd, video_format_t *fmt )
                     i_chroma_shift = 2;
                     break;
 
+                case VLC_CODEC_RGB32:
+                    b_hw_accel = sys->kvac.ulInputFormatFlags & KVAF_BGR32;
+                    i_kva_fourcc = FOURCC_BGR4;
+                    i_chroma_shift = 0;
+                    break;
+
                 case VLC_CODEC_RGB24:
                     b_hw_accel = sys->kvac.ulInputFormatFlags & KVAF_BGR24;
                     i_kva_fourcc = FOURCC_BGR3;
@@ -639,24 +656,19 @@ static int OpenDisplay( vout_display_t *vd, video_format_t *fmt )
     }
 
     /* Create the associated picture */
-    picture_resource_t *rsc = &sys->resource;
-    rsc->p_sys = malloc( sizeof( *rsc->p_sys ));
-    if( !rsc->p_sys )
-        return VLC_EGENERIC;
-
-    rsc->p_sys->i_chroma_shift = i_chroma_shift;
+    picture_sys_t *picsys = malloc( sizeof( *picsys ) );
+    if( picsys == NULL )
+        return VLC_ENOMEM;
+    picsys->i_chroma_shift = i_chroma_shift;
 
-    for( int i = 0; i < PICTURE_PLANE_MAX; i++ )
+    picture_resource_t resource = { .p_sys = picsys };
+    picture_t *picture = picture_NewFromResource( fmt, &resource );
+    if( !picture )
     {
-        rsc->p[ i ].p_pixels = NULL;
-        rsc->p[ i ].i_pitch  = 0;
-        rsc->p[ i ].i_lines  = 0;
+        free( picsys );
+        return VLC_ENOMEM;
     }
 
-    picture_t *picture = picture_NewFromResource( fmt, rsc );
-    if( !picture )
-        goto exit_picture;
-
     /* Wrap it into a picture pool */
     picture_pool_configuration_t pool_cfg;
     memset( &pool_cfg, 0, sizeof( pool_cfg ));
@@ -669,8 +681,7 @@ static int OpenDisplay( vout_display_t *vd, video_format_t *fmt )
     if( !sys->pool )
     {
         picture_Release( picture );
-
-        goto exit_picture;
+        return VLC_ENOMEM;
     }
 
     if (vd->cfg->display.title)
@@ -708,11 +719,6 @@ static int OpenDisplay( vout_display_t *vd, video_format_t *fmt )
                      SWP_ACTIVATE );
 
     return VLC_SUCCESS;
-
-exit_picture:
-    free( rsc->p_sys );
-
-    return VLC_EGENERIC;
 }
 
 /*****************************************************************************
@@ -860,11 +866,15 @@ static MRESULT EXPENTRY MyFrameWndProc( HWND hwnd, ULONG msg, MPARAM mp1,
     {
         case WM_QUERYTRACKINFO :
         {
+            MRESULT mr;
+
+            mr = sys->p_old_frame( hwnd, msg, mp1, mp2 );
+            if( !sys->b_fixt23 )
+                return mr;
+
             PTRACKINFO pti = ( PTRACKINFO )mp2;
             RECTL      rcl;
 
-            sys->p_old_frame( hwnd, msg, mp1, mp2 );
-
             pti->rclBoundary.xLeft   = 0;
             pti->rclBoundary.yBottom = 0;
             pti->rclBoundary.xRight  = sys->i_screen_width;
@@ -892,11 +902,15 @@ static MRESULT EXPENTRY MyFrameWndProc( HWND hwnd, ULONG msg, MPARAM mp1,
 
         case WM_ADJUSTWINDOWPOS :
         {
+            if( !sys->b_fixt23 )
+                break;
+
             PSWP  pswp = ( PSWP )mp1;
-            RECTL rcl;
 
             if( pswp->fl & SWP_SIZE )
             {
+                RECTL rcl;
+
                 rcl.xLeft   = pswp->x;
                 rcl.yBottom = pswp->y;
                 rcl.xRight  = rcl.xLeft + pswp->cx;
@@ -936,6 +950,12 @@ static MRESULT EXPENTRY MyFrameWndProc( HWND hwnd, ULONG msg, MPARAM mp1,
 
             break;
         }
+
+        //case WM_VRNDISABLED :
+        case WM_VRNENABLED :
+            if( !vd->cfg->is_fullscreen && sys->is_on_top )
+                WinSetWindowPos( hwnd, HWND_TOP, 0, 0, 0, 0, SWP_ZORDER );
+            break;
     }
 
     return sys->p_old_frame( hwnd, msg, mp1, mp2 );