]> git.sesse.net Git - vlc/blobdiff - modules/video_output/msw/common.c
Mark unreachable code on GCC even if NDEBUG
[vlc] / modules / video_output / msw / common.c
index b44ac45ed3187a415bc1270545738784d917c152..1ebe08c362794a38904e082684a8e8104824eae0 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * common.c:
+ * common.c: Windows video output common code
  *****************************************************************************
  * Copyright (C) 2001-2009 VLC authors and VideoLAN
  * $Id$
  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
-
 /*****************************************************************************
- * Preamble: This file contains the functions related to the creation of
- *             a window and the handling of its messages (events).
+ * Preamble: This file contains the functions related to the init of the vout
+ *           structure, the common display code, the screensaver, but not the
+ *           events and the Window Creation (events.c)
  *****************************************************************************/
+
 #ifdef HAVE_CONFIG_H
 # include "config.h"
 #endif
-#include <assert.h>
 
 #include <vlc_common.h>
 #include <vlc_vout_display.h>
-#include <vlc_vout_window.h>
 
 #include <windows.h>
-#include <windowsx.h>
-#include <shellapi.h>
-
-#ifdef MODULE_NAME_IS_directdraw
-#include <ddraw.h>
-#endif
-#ifdef MODULE_NAME_IS_direct3d
-#include <d3d9.h>
-#endif
-#ifdef MODULE_NAME_IS_glwin32
-#include "../opengl.h"
-#endif
-#ifdef MODULE_NAME_IS_direct2d
-#include <d2d1.h>
-#endif
+#include <assert.h>
 
 #include "common.h"
 
 #include <vlc_windows_interfaces.h>
 
 static void CommonChangeThumbnailClip(vout_display_t *, bool show);
-static int CommonControlSetFullscreen(vout_display_t *, bool is_fullscreen);
+static int  CommonControlSetFullscreen(vout_display_t *, bool is_fullscreen);
 
 static void DisableScreensaver(vout_display_t *);
 static void RestoreScreensaver(vout_display_t *);
@@ -77,8 +62,8 @@ int CommonInit(vout_display_t *vd)
     sys->is_first_display = true;
     sys->is_on_top = false;
 
-    var_Create(vd, "video-title", VLC_VAR_STRING | VLC_VAR_DOINHERIT);
     var_Create(vd, "video-deco", VLC_VAR_BOOL | VLC_VAR_DOINHERIT);
+    var_Create(vd, "disable-screensaver", VLC_VAR_BOOL | VLC_VAR_DOINHERIT);
 
     /* */
     sys->event = EventThreadCreate(vd);
@@ -87,17 +72,16 @@ int CommonInit(vout_display_t *vd)
 
     event_cfg_t cfg;
     memset(&cfg, 0, sizeof(cfg));
-#ifdef MODULE_NAME_IS_direct3d
+#ifdef MODULE_NAME_IS_direct3d9
     cfg.use_desktop = sys->use_desktop;
 #endif
 #ifdef MODULE_NAME_IS_directdraw
     cfg.use_overlay = sys->use_overlay;
 #endif
-    cfg.win.type   = VOUT_WINDOW_TYPE_HWND;
-    cfg.win.x      = var_InheritInteger(vd, "video-x");
-    cfg.win.y      = var_InheritInteger(vd, "video-y");
-    cfg.win.width  = vd->cfg->display.width;
-    cfg.win.height = vd->cfg->display.height;
+    cfg.x      = var_InheritInteger(vd, "video-x");
+    cfg.y      = var_InheritInteger(vd, "video-y");
+    cfg.width  = vd->cfg->display.width;
+    cfg.height = vd->cfg->display.height;
 
     event_hwnd_t hwnd;
     if (EventThreadStart(sys->event, &hwnd, &cfg))
@@ -114,8 +98,6 @@ int CommonInit(vout_display_t *vd)
             vout_display_SendEventFullscreen(vd, false);
     }
 
-    /* Why not with glwin32 */
-    var_Create(vd, "disable-screensaver", VLC_VAR_BOOL | VLC_VAR_DOINHERIT);
     DisableScreensaver (vd);
 
     return VLC_SUCCESS;
@@ -161,11 +143,11 @@ void CommonManage(vout_display_t *vd)
 
             /* This code deals with both resize and move
              *
-             * For most drivers(direct3d, gdi, opengl), move is never
+             * For most drivers(direct3d9, gdi, opengl), move is never
              * an issue. The surface automatically gets moved together
              * with the associated window (hvideownd)
              *
-             * For directx, it is still important to call UpdateRects
+             * For directdraw, it is still important to call UpdateRects
              * on a move of the parent window, even if no resize occurred
              */
             SetWindowPos(sys->hwnd, 0, 0, 0,
@@ -230,7 +212,7 @@ int CommonUpdatePicture(picture_t *picture, picture_t **fallback,
     /* fill in buffer info in first plane */
     picture->p->p_pixels = data;
     picture->p->i_pitch  = pitch;
-    picture->p->i_lines  = picture->format.i_height;
+    picture->p->i_lines  = picture->format.i_visible_height;
 
     /*  Fill chroma planes for planar YUV */
     if (picture->format.i_chroma == VLC_CODEC_I420 ||
@@ -243,7 +225,7 @@ int CommonUpdatePicture(picture_t *picture, picture_t **fallback,
 
             p->p_pixels = o->p_pixels + o->i_lines * o->i_pitch;
             p->i_pitch  = pitch / 2;
-            p->i_lines  = picture->format.i_height / 2;
+            p->i_lines  = picture->format.i_visible_height / 2;
         }
         /* The dx/d3d buffer is always allocated as YV12 */
         if (vlc_fourcc_AreUVPlanesSwapped(picture->format.i_chroma, VLC_CODEC_YV12)) {
@@ -346,8 +328,8 @@ void UpdateRects(vout_display_t *vd,
                                     point.x, point.y,
                                     rect.right, rect.bottom);
     if (is_resized)
-        vout_display_SendEventDisplaySize(vd, rect.right, rect.bottom, cfg->is_fullscreen);
-    if (!is_forced && !has_moved && !is_resized )
+        vout_display_SendEventDisplaySize(vd, rect.right, rect.bottom);
+    if (!is_forced && !has_moved && !is_resized)
         return;
 
     /* Update the window position and size */
@@ -366,7 +348,7 @@ void UpdateRects(vout_display_t *vd,
                      SWP_NOCOPYBITS|SWP_NOZORDER|SWP_ASYNCWINDOWPOS);
 
     /* Destination image position and dimensions */
-#if defined(MODULE_NAME_IS_direct3d) || defined(MODULE_NAME_IS_direct2d)
+#if defined(MODULE_NAME_IS_direct3d9) || defined(MODULE_NAME_IS_direct2d)
     rect_dest.left   = 0;
     rect_dest.right  = place.width;
     rect_dest.top    = 0;
@@ -420,8 +402,8 @@ void UpdateRects(vout_display_t *vd,
     /* src image dimensions */
     rect_src.left   = 0;
     rect_src.top    = 0;
-    rect_src.right  = source->i_width;
-    rect_src.bottom = source->i_height;
+    rect_src.right  = vd->fmt.i_visible_width;
+    rect_src.bottom = vd->fmt.i_visible_height;
 
     /* Clip the source image */
     rect_src_clipped.left = source->i_x_offset +
@@ -443,7 +425,7 @@ void UpdateRects(vout_display_t *vd,
     /* Apply overlay hardware constraints */
     if (sys->use_overlay)
         AlignRect(&rect_src_clipped, sys->i_align_src_boundary, sys->i_align_src_size);
-#elif defined(MODULE_NAME_IS_direct3d) || defined(MODULE_NAME_IS_direct2d)
+#elif defined(MODULE_NAME_IS_direct3d9) || defined(MODULE_NAME_IS_direct2d)
     /* Needed at least with YUV content */
     rect_src_clipped.left &= ~1;
     rect_src_clipped.right &= ~1;
@@ -483,14 +465,14 @@ static int CommonControlSetFullscreen(vout_display_t *vd, bool is_fullscreen)
 {
     vout_display_sys_t *sys = vd->sys;
 
-#ifdef MODULE_NAME_IS_direct3d
+#ifdef MODULE_NAME_IS_direct3d9
     if (sys->use_desktop && is_fullscreen)
         return VLC_EGENERIC;
 #endif
 
     /* */
     if (sys->parent_window)
-        return vout_window_SetFullScreen(sys->parent_window, is_fullscreen);
+        return VLC_EGENERIC;
 
     /* */
     HWND hwnd = sys->hparent && sys->hfswnd ? sys->hfswnd : sys->hwnd;
@@ -571,14 +553,30 @@ int CommonControl(vout_display_t *vd, int query, va_list args)
     vout_display_sys_t *sys = vd->sys;
 
     switch (query) {
-    case VOUT_DISPLAY_CHANGE_DISPLAY_SIZE:   /* const vout_display_cfg_t *p_cfg, int is_forced */
+    case VOUT_DISPLAY_CHANGE_DISPLAY_SIZE:   /* const vout_display_cfg_t *p_cfg */
+    {   /* Update dimensions */
+        const vout_display_cfg_t *cfg = va_arg(args, const vout_display_cfg_t *);
+        RECT rect_window = {
+            .top    = 0,
+            .left   = 0,
+            .right  = cfg->display.width,
+            .bottom = cfg->display.height,
+        };
+
+        AdjustWindowRect(&rect_window, EventThreadGetWindowStyle(sys->event), 0);
+        SetWindowPos(sys->hwnd, 0, 0, 0,
+                     rect_window.right - rect_window.left,
+                     rect_window.bottom - rect_window.top, SWP_NOMOVE);
+        UpdateRects(vd, cfg, &vd->source, false);
+        return VLC_SUCCESS;
+    }
     case VOUT_DISPLAY_CHANGE_DISPLAY_FILLED: /* const vout_display_cfg_t *p_cfg */
     case VOUT_DISPLAY_CHANGE_ZOOM:           /* const vout_display_cfg_t *p_cfg */
     case VOUT_DISPLAY_CHANGE_SOURCE_ASPECT:  /* const video_format_t *p_source */
     case VOUT_DISPLAY_CHANGE_SOURCE_CROP: {  /* const video_format_t *p_source */
         const vout_display_cfg_t *cfg;
         const video_format_t *source;
-        bool  is_forced = true;
+
         if (query == VOUT_DISPLAY_CHANGE_SOURCE_CROP ||
             query == VOUT_DISPLAY_CHANGE_SOURCE_ASPECT) {
             cfg    = vd->cfg;
@@ -586,56 +584,32 @@ int CommonControl(vout_display_t *vd, int query, va_list args)
         } else {
             cfg    = va_arg(args, const vout_display_cfg_t *);
             source = &vd->source;
-            if (query == VOUT_DISPLAY_CHANGE_DISPLAY_SIZE)
-                is_forced = va_arg(args, int);
         }
-        if (query == VOUT_DISPLAY_CHANGE_DISPLAY_SIZE && is_forced) {
-            /* Update dimensions */
-            if (sys->parent_window) {
-                vout_window_SetSize(sys->parent_window, cfg->display.width, cfg->display.height);
-            } else {
-                RECT rect_window;
-                rect_window.top    = 0;
-                rect_window.left   = 0;
-                rect_window.right  = cfg->display.width;
-                rect_window.bottom = cfg->display.height;
-                AdjustWindowRect(&rect_window, EventThreadGetWindowStyle(sys->event), 0);
-
-                SetWindowPos(sys->hwnd, 0, 0, 0,
-                             rect_window.right - rect_window.left,
-                             rect_window.bottom - rect_window.top, SWP_NOMOVE);
-            }
-        }
-        UpdateRects(vd, cfg, source, is_forced);
+        UpdateRects(vd, cfg, source, false);
         return VLC_SUCCESS;
     }
     case VOUT_DISPLAY_CHANGE_WINDOW_STATE: {       /* unsigned state */
         const unsigned state = va_arg(args, unsigned);
         const bool is_on_top = (state & VOUT_WINDOW_STATE_ABOVE) != 0;
-#ifdef MODULE_NAME_IS_direct3d
+#ifdef MODULE_NAME_IS_direct3d9
         if (sys->use_desktop && is_on_top)
             return VLC_EGENERIC;
 #endif
-        if (sys->parent_window) {
-            if (vout_window_SetState(sys->parent_window, state))
-                return VLC_EGENERIC;
-        } else {
-            HMENU hMenu = GetSystemMenu(sys->hwnd, FALSE);
-
-            if (is_on_top && !(GetWindowLong(sys->hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST)) {
-                CheckMenuItem(hMenu, IDM_TOGGLE_ON_TOP, MF_BYCOMMAND | MFS_CHECKED);
-                SetWindowPos(sys->hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
-            } else if (!is_on_top && (GetWindowLong(sys->hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST)) {
-                CheckMenuItem(hMenu, IDM_TOGGLE_ON_TOP, MF_BYCOMMAND | MFS_UNCHECKED);
-                SetWindowPos(sys->hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
-            }
+        HMENU hMenu = GetSystemMenu(sys->hwnd, FALSE);
+
+        if (is_on_top && !(GetWindowLong(sys->hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST)) {
+            CheckMenuItem(hMenu, IDM_TOGGLE_ON_TOP, MF_BYCOMMAND | MFS_CHECKED);
+            SetWindowPos(sys->hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
+        } else if (!is_on_top && (GetWindowLong(sys->hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST)) {
+            CheckMenuItem(hMenu, IDM_TOGGLE_ON_TOP, MF_BYCOMMAND | MFS_UNCHECKED);
+            SetWindowPos(sys->hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
         }
         sys->is_on_top = is_on_top;
         return VLC_SUCCESS;
     }
-    case VOUT_DISPLAY_CHANGE_FULLSCREEN: {   /* const vout_display_cfg_t *p_cfg */
-        const vout_display_cfg_t *cfg = va_arg(args, const vout_display_cfg_t *);
-        if (CommonControlSetFullscreen(vd, cfg->is_fullscreen))
+    case VOUT_DISPLAY_CHANGE_FULLSCREEN: {
+        bool fs = va_arg(args, int);
+        if (CommonControlSetFullscreen(vd, fs))
             return VLC_EGENERIC;
         UpdateRects(vd, NULL, NULL, false);
         return VLC_SUCCESS;
@@ -645,7 +619,7 @@ int CommonControl(vout_display_t *vd, int query, va_list args)
         EventThreadMouseHide(sys->event);
         return VLC_SUCCESS;
     case VOUT_DISPLAY_RESET_PICTURES:
-        assert(0);
+        vlc_assert_unreachable();
     default:
         return VLC_EGENERIC;
     }