]> git.sesse.net Git - vlc/blobdiff - modules/access/screen/win32.c
Remove IS_WINNT macro
[vlc] / modules / access / screen / win32.c
index 358a62f50b3085980a01a6c3a87c32044400d68c..6ffa9f792d2f0320a996cfb77334707848537784 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * win32.c: Screen capture module.
  *****************************************************************************
- * Copyright (C) 2004 the VideoLAN team
+ * Copyright (C) 2004-2008 the VideoLAN team
  * $Id$
  *
  * Authors: Gildas Bazin <gbazin@videolan.org>
  *
  * 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., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#include <stdlib.h>
 
-#include <vlc/vlc.h>
-#include <vlc/input.h>
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
 
 #include "screen.h"
 
@@ -52,9 +54,11 @@ int screen_InitCapture( demux_t *p_demux )
     demux_sys_t *p_sys = p_demux->p_sys;
     screen_data_t *p_data;
     int i_chroma, i_bits_per_pixel;
-    vlc_value_t val;
 
     p_sys->p_data = p_data = malloc( sizeof( screen_data_t ) );
+    if( !p_data )
+        return VLC_ENOMEM;
+    memset( p_data, 0, sizeof( screen_data_t ) );
 
     /* Get the device context for the whole screen */
     p_data->hdc_src = CreateDC( "DISPLAY", NULL, NULL, NULL );
@@ -78,9 +82,8 @@ int screen_InitCapture( demux_t *p_demux )
     case 8: /* FIXME: set the palette */
         i_chroma = VLC_FOURCC('R','G','B','2'); break;
     case 15:
+    case 16:    /* Yes it is really 15 bits (when using BI_RGB) */
         i_chroma = VLC_FOURCC('R','V','1','5'); break;
-    case 16:
-        i_chroma = VLC_FOURCC('R','V','1','6'); break;
     case 24:
         i_chroma = VLC_FOURCC('R','V','2','4'); break;
     case 32:
@@ -93,49 +96,36 @@ int screen_InitCapture( demux_t *p_demux )
         return VLC_EGENERIC;
     }
 
-#if 1 /* For now we force RV24 because of chroma inversion in the other cases*/
-    i_chroma = VLC_FOURCC('R','V','2','4');
-    i_bits_per_pixel = 24;
-#endif
-
     es_format_Init( &p_sys->fmt, VIDEO_ES, i_chroma );
+    p_sys->fmt.video.i_visible_width =
     p_sys->fmt.video.i_width  = GetDeviceCaps( p_data->hdc_src, HORZRES );
+    p_sys->fmt.video.i_visible_height =
     p_sys->fmt.video.i_height = GetDeviceCaps( p_data->hdc_src, VERTRES );
     p_sys->fmt.video.i_bits_per_pixel = i_bits_per_pixel;
+    p_sys->fmt.video.i_chroma = i_chroma;
 
-    /* Create the bitmap info header */
-    p_data->bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
-    p_data->bmi.bmiHeader.biWidth = p_sys->fmt.video.i_width;
-    p_data->bmi.bmiHeader.biHeight = - p_sys->fmt.video.i_height;
-    p_data->bmi.bmiHeader.biPlanes = 1;
-    p_data->bmi.bmiHeader.biBitCount = p_sys->fmt.video.i_bits_per_pixel;
-    p_data->bmi.bmiHeader.biCompression = BI_RGB;
-    p_data->bmi.bmiHeader.biSizeImage = 0;
-    p_data->bmi.bmiHeader.biXPelsPerMeter =
-        p_data->bmi.bmiHeader.biYPelsPerMeter = 0;
-    p_data->bmi.bmiHeader.biClrUsed = 0;
-    p_data->bmi.bmiHeader.biClrImportant = 0;
-
-    if( i_chroma == VLC_FOURCC('R','V','2','4') )
+    switch( i_chroma )
     {
-        /* This is in BGR format */
-        p_sys->fmt.video.i_bmask = 0x00ff0000;
+    case VLC_FOURCC('R','V','1','5'):
+        p_sys->fmt.video.i_rmask = 0x7c00;
+        p_sys->fmt.video.i_gmask = 0x03e0;
+        p_sys->fmt.video.i_bmask = 0x001f;
+        break;
+    case VLC_FOURCC('R','V','2','4'):
+        p_sys->fmt.video.i_rmask = 0x00ff0000;
+        p_sys->fmt.video.i_gmask = 0x0000ff00;
+        p_sys->fmt.video.i_bmask = 0x000000ff;
+        break;
+    case VLC_FOURCC('R','V','3','2'):
+        p_sys->fmt.video.i_rmask = 0x00ff0000;
         p_sys->fmt.video.i_gmask = 0x0000ff00;
-        p_sys->fmt.video.i_rmask = 0x000000ff;
+        p_sys->fmt.video.i_bmask = 0x000000ff;
+        break;
+    default:
+        msg_Warn( p_demux, "Unknown RGB masks" );
+        break;
     }
 
-    var_Create( p_demux, "screen-fragment-size",
-                VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
-    var_Get( p_demux, "screen-fragment-size", &val );
-    p_data->i_fragment_size =
-        val.i_int > 0 ? val.i_int : p_sys->fmt.video.i_height;
-    p_data->i_fragment_size =
-        val.i_int > p_sys->fmt.video.i_height ? p_sys->fmt.video.i_height :
-        p_data->i_fragment_size;
-    p_sys->f_fps *= (p_sys->fmt.video.i_height/p_data->i_fragment_size);
-    p_sys->i_incr = 1000000 / p_sys->f_fps;
-    p_data->i_fragment = 0;
-    p_data->p_block = 0;
 
     return VLC_SUCCESS;
 }
@@ -159,12 +149,13 @@ int screen_CloseCapture( demux_t *p_demux )
 
 struct block_sys_t
 {
+    block_t self;
     HBITMAP hbmp;
 };
 
 static void CaptureBlockRelease( block_t *p_block )
 {
-    DeleteObject( p_block->p_sys->hbmp );
+    DeleteObject( ((block_sys_t *)p_block)->hbmp );
     free( p_block );
 }
 
@@ -172,11 +163,42 @@ static block_t *CaptureBlockNew( demux_t *p_demux )
 {
     demux_sys_t *p_sys = p_demux->p_sys;
     screen_data_t *p_data = p_sys->p_data;
-    block_t *p_block;
+    block_sys_t *p_block;
     void *p_buffer;
     int i_buffer;
     HBITMAP hbmp;
 
+    if( p_data->bmi.bmiHeader.biSize == 0 )
+    {
+        vlc_value_t val;
+        /* Create the bitmap info header */
+        p_data->bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
+        p_data->bmi.bmiHeader.biWidth = p_sys->fmt.video.i_width;
+        p_data->bmi.bmiHeader.biHeight = - p_sys->fmt.video.i_height;
+        p_data->bmi.bmiHeader.biPlanes = 1;
+        p_data->bmi.bmiHeader.biBitCount = p_sys->fmt.video.i_bits_per_pixel;
+        p_data->bmi.bmiHeader.biCompression = BI_RGB;
+        p_data->bmi.bmiHeader.biSizeImage = 0;
+        p_data->bmi.bmiHeader.biXPelsPerMeter =
+            p_data->bmi.bmiHeader.biYPelsPerMeter = 0;
+        p_data->bmi.bmiHeader.biClrUsed = 0;
+        p_data->bmi.bmiHeader.biClrImportant = 0;
+
+        var_Create( p_demux, "screen-fragment-size",
+                    VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
+        var_Get( p_demux, "screen-fragment-size", &val );
+        p_data->i_fragment_size =
+            val.i_int > 0 ? val.i_int : p_sys->fmt.video.i_height;
+        p_data->i_fragment_size =
+            val.i_int > p_sys->fmt.video.i_height ? p_sys->fmt.video.i_height :
+            p_data->i_fragment_size;
+        p_sys->f_fps *= (p_sys->fmt.video.i_height/p_data->i_fragment_size);
+        p_sys->i_incr = 1000000 / p_sys->f_fps;
+        p_data->i_fragment = 0;
+        p_data->p_block = 0;
+    }
+
+
     /* Create the bitmap storage space */
     hbmp = CreateDIBSection( p_data->hdc_dst, &p_data->bmi, DIB_RGB_COLORS,
                              &p_buffer, NULL, 0 );
@@ -206,20 +228,14 @@ static block_t *CaptureBlockNew( demux_t *p_demux )
         DeleteObject( hbmp );
         return NULL;
     }
-    memset( p_block, 0, sizeof( block_t ) );
-    p_block->p_sys = (block_sys_t *)( (uint8_t *)p_block + sizeof( block_t ) );
-
     /* Fill all fields */
     i_buffer = (p_sys->fmt.video.i_bits_per_pixel + 7) / 8 *
         p_sys->fmt.video.i_width * p_sys->fmt.video.i_height;
-    p_block->p_next         = NULL;
-    p_block->i_buffer       = i_buffer;
-    p_block->p_buffer       = p_buffer;
-    p_block->pf_release     = CaptureBlockRelease;
-    p_block->p_manager      = VLC_OBJECT( p_demux->p_vlc );
-    p_block->p_sys->hbmp    = hbmp;
-
-    return p_block;
+    block_Init( &p_block->self, p_buffer, i_buffer );
+    p_block->self.pf_release = CaptureBlockRelease;
+    p_block->hbmp            = hbmp;
+
+    return &p_block->self;
 }
 
 block_t *screen_Capture( demux_t *p_demux )
@@ -236,12 +252,19 @@ block_t *screen_Capture( demux_t *p_demux )
         }
     }
 
-    if( !BitBlt( p_data->hdc_dst, 0, p_data->i_fragment *
-                 p_data->i_fragment_size,
+    if( p_sys->b_follow_mouse )
+    {
+        POINT pos;
+        GetCursorPos( &pos );
+        FollowMouse( p_sys, pos.x, pos.y );
+    }
+
+    if( !BitBlt( p_data->hdc_dst, 0,
+                 p_data->i_fragment * p_data->i_fragment_size,
                  p_sys->fmt.video.i_width, p_data->i_fragment_size,
-                 p_data->hdc_src, 0, p_data->i_fragment *
-                 p_data->i_fragment_size,
-                 IS_WINNT ? SRCCOPY | CAPTUREBLT : SRCCOPY ) )
+                 p_data->hdc_src, p_sys->i_left, p_sys->i_top +
+                 p_data->i_fragment * p_data->i_fragment_size,
+                 SRCCOPY | CAPTUREBLT ) )
     {
         msg_Err( p_demux, "error during BitBlt()" );
         return NULL;
@@ -255,6 +278,15 @@ block_t *screen_Capture( demux_t *p_demux )
         block_t *p_block = p_data->p_block;
         p_data->i_fragment = 0;
         p_data->p_block = 0;
+
+        if( p_sys->p_mouse )
+        {
+            POINT pos;
+            GetCursorPos( &pos );
+            RenderCursor( p_demux, pos.x, pos.y,
+                          p_block->p_buffer );
+        }
+
         return p_block;
     }