video_output: msw -> win32 for Windows
authorJean-Baptiste Kempf <jb@videolan.org>
Sun, 17 Apr 2016 18:46:46 +0000 (20:46 +0200)
committerJean-Baptiste Kempf <jb@videolan.org>
Sun, 17 Apr 2016 19:50:58 +0000 (21:50 +0200)
28 files changed:
modules/video_output/Makefile.am
modules/video_output/msw/builtin_shaders.h [deleted file]
modules/video_output/msw/common.c [deleted file]
modules/video_output/msw/common.h [deleted file]
modules/video_output/msw/direct2d.c [deleted file]
modules/video_output/msw/direct3d11.c [deleted file]
modules/video_output/msw/direct3d9.c [deleted file]
modules/video_output/msw/directdraw.c [deleted file]
modules/video_output/msw/events.c [deleted file]
modules/video_output/msw/events.h [deleted file]
modules/video_output/msw/glwin32.c [deleted file]
modules/video_output/msw/win32touch.c [deleted file]
modules/video_output/msw/win32touch.h [deleted file]
modules/video_output/msw/wingdi.c [deleted file]
modules/video_output/win32/builtin_shaders.h [new file with mode: 0644]
modules/video_output/win32/common.c [new file with mode: 0644]
modules/video_output/win32/common.h [new file with mode: 0644]
modules/video_output/win32/direct2d.c [new file with mode: 0644]
modules/video_output/win32/direct3d11.c [new file with mode: 0644]
modules/video_output/win32/direct3d9.c [new file with mode: 0644]
modules/video_output/win32/directdraw.c [new file with mode: 0644]
modules/video_output/win32/events.c [new file with mode: 0644]
modules/video_output/win32/events.h [new file with mode: 0644]
modules/video_output/win32/glwin32.c [new file with mode: 0644]
modules/video_output/win32/win32touch.c [new file with mode: 0644]
modules/video_output/win32/win32touch.h [new file with mode: 0644]
modules/video_output/win32/wingdi.c [new file with mode: 0644]
po/POTFILES.in

index 83a26e1..9f4a761 100644 (file)
@@ -157,10 +157,10 @@ endif
 
 
 ### Win32 ###
-libdirect2d_plugin_la_SOURCES = video_output/msw/direct2d.c \
-       video_output/msw/common.c video_output/msw/common.h \
-       video_output/msw/events.c video_output/msw/events.h \
-       video_output/msw/win32touch.c video_output/msw/win32touch.h
+libdirect2d_plugin_la_SOURCES = video_output/win32/direct2d.c \
+       video_output/win32/common.c video_output/win32/common.h \
+       video_output/win32/events.c video_output/win32/events.h \
+       video_output/win32/win32touch.c video_output/win32/win32touch.h
 libdirect2d_plugin_la_CPPFLAGS = $(AM_CPPFLAGS) \
        -DMODULE_NAME_IS_direct2d
 libdirect2d_plugin_la_LIBADD = -lgdi32 -lole32 -luuid
@@ -168,11 +168,11 @@ libdirect2d_plugin_la_LDFLAGS = $(AM_LDFLAGS) -rpath '$(voutdir)'
 vout_LTLIBRARIES += $(LTLIBdirect2d)
 EXTRA_LTLIBRARIES += libdirect2d_plugin.la
 
-libdirect3d9_plugin_la_SOURCES = video_output/msw/direct3d9.c \
-       video_output/msw/common.c video_output/msw/common.h \
-       video_output/msw/events.c video_output/msw/events.h \
-       video_output/msw/builtin_shaders.h \
-       video_output/msw/win32touch.c video_output/msw/win32touch.h
+libdirect3d9_plugin_la_SOURCES = video_output/win32/direct3d9.c \
+       video_output/win32/common.c video_output/win32/common.h \
+       video_output/win32/events.c video_output/win32/events.h \
+       video_output/win32/builtin_shaders.h \
+       video_output/win32/win32touch.c video_output/win32/win32touch.h
 libdirect3d9_plugin_la_CPPFLAGS = $(AM_CPPFLAGS) \
        -DMODULE_NAME_IS_direct3d9
 libdirect3d9_plugin_la_LIBADD = -lgdi32 -lole32 -luuid
@@ -180,15 +180,15 @@ libdirect3d9_plugin_la_LDFLAGS = $(AM_LDFLAGS) -rpath '$(voutdir)'
 vout_LTLIBRARIES += $(LTLIBdirect3d9)
 EXTRA_LTLIBRARIES += libdirect3d9_plugin.la
 
-libdirect3d11_plugin_la_SOURCES = video_output/msw/direct3d11.c \
+libdirect3d11_plugin_la_SOURCES = video_output/win32/direct3d11.c \
  video_chroma/dxgi_fmt.c video_chroma/dxgi_fmt.h \
- video_output/msw/common.c video_output/msw/common.h
+ video_output/win32/common.c video_output/win32/common.h
 libdirect3d11_plugin_la_CPPFLAGS = $(AM_CPPFLAGS) \
  -DMODULE_NAME_IS_direct3d11
 if !HAVE_WINSTORE
-libdirect3d11_plugin_la_SOURCES += video_output/msw/events.c \
- video_output/msw/events.h \
- video_output/msw/win32touch.c video_output/msw/win32touch.h
+libdirect3d11_plugin_la_SOURCES += video_output/win32/events.c \
+ video_output/win32/events.h \
+ video_output/win32/win32touch.c video_output/win32/win32touch.h
 libdirect3d11_plugin_la_LIBADD = -lgdi32 -lole32 -luuid
 else
 libdirect3d11_plugin_la_LIBADD = -ld3dcompiler -lole32 -luuid
@@ -197,10 +197,10 @@ libdirect3d11_plugin_la_LDFLAGS = $(AM_LDFLAGS) -rpath '$(voutdir)'
 vout_LTLIBRARIES += $(LTLIBdirect3d11)
 EXTRA_LTLIBRARIES += libdirect3d11_plugin.la
 
-libdirectdraw_plugin_la_SOURCES = video_output/msw/directdraw.c \
-       video_output/msw/common.c video_output/msw/common.h \
-       video_output/msw/events.c video_output/msw/events.h \
-       video_output/msw/win32touch.c video_output/msw/win32touch.h
+libdirectdraw_plugin_la_SOURCES = video_output/win32/directdraw.c \
+       video_output/win32/common.c video_output/win32/common.h \
+       video_output/win32/events.c video_output/win32/events.h \
+       video_output/win32/win32touch.c video_output/win32/win32touch.h
 libdirectdraw_plugin_la_CPPFLAGS = $(AM_CPPFLAGS) \
        -DMODULE_NAME_IS_directdraw
 libdirectdraw_plugin_la_LIBADD = -luser32 -lgdi32 -lole32 -luuid
@@ -208,11 +208,11 @@ if HAVE_DIRECTX
 vout_LTLIBRARIES += libdirectdraw_plugin.la
 endif
 
-libglwin32_plugin_la_SOURCES = video_output/msw/glwin32.c \
+libglwin32_plugin_la_SOURCES = video_output/win32/glwin32.c \
        video_output/opengl.c video_output/opengl.h \
-       video_output/msw/common.c video_output/msw/common.h \
-       video_output/msw/events.c video_output/msw/events.h \
-       video_output/msw/win32touch.c video_output/msw/win32touch.h
+       video_output/win32/common.c video_output/win32/common.h \
+       video_output/win32/events.c video_output/win32/events.h \
+       video_output/win32/win32touch.c video_output/win32/win32touch.h
 libglwin32_plugin_la_CPPFLAGS = $(AM_CPPFLAGS) \
        -DMODULE_NAME_IS_glwin32
 libglwin32_plugin_la_LIBADD = -lopengl32 -lgdi32 -lole32 -luuid
@@ -220,10 +220,10 @@ libglwin32_plugin_la_LDFLAGS = $(AM_LDFLAGS) -rpath '$(voutdir)'
 vout_LTLIBRARIES += $(LTLIBglwin32)
 EXTRA_LTLIBRARIES += libglwin32_plugin.la
 
-libwingdi_plugin_la_SOURCES = video_output/msw/wingdi.c \
-       video_output/msw/common.c video_output/msw/common.h \
-       video_output/msw/events.c video_output/msw/events.h \
-       video_output/msw/win32touch.c video_output/msw/win32touch.h
+libwingdi_plugin_la_SOURCES = video_output/win32/wingdi.c \
+       video_output/win32/common.c video_output/win32/common.h \
+       video_output/win32/events.c video_output/win32/events.h \
+       video_output/win32/win32touch.c video_output/win32/win32touch.h
 libwingdi_plugin_la_CPPFLAGS = $(AM_CPPFLAGS) \
        -DMODULE_NAME_IS_wingdi
 libwingdi_plugin_la_LIBADD = -lgdi32 -lole32 -luuid
diff --git a/modules/video_output/msw/builtin_shaders.h b/modules/video_output/msw/builtin_shaders.h
deleted file mode 100644 (file)
index 3a87ce2..0000000
+++ /dev/null
@@ -1,150 +0,0 @@
-/*****************************************************************************
- * builtin_shaders.h: Builtin HLSL shader functions.
- *****************************************************************************
- * Copyright (C) 2014 the VideoLAN team
- *
- * Authors: Sasha Koruga <skoruga@gmail.com>,
- *          Felix Abecassis <felix.abecassis@gmail.com>
- * 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 Lesser General Public License for more details.
- *
- * 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.
- *****************************************************************************/
-
-static const char shader_disabled_source[] =
-    "sampler2D screen;\n"
-    "float4 main(float2 screenCoords : TEXCOORD0) : COLOR\n"
-    "{\n"
-    "    return saturate(tex2D(screen, screenCoords.xy));\n"
-    "}\n";
-
-static const char shader_invert_source[] =
-    "sampler2D screen;\n"
-    "float4 main(float2 screenCoords : TEXCOORD0) : COLOR\n"
-    "{\n"
-    "    float4 color = tex2D(screen, screenCoords.xy);\n"
-    "    color.r = 1.0 - color.r;\n"
-    "    color.g = 1.0 - color.g;\n"
-    "    color.b = 1.0 - color.b;\n"
-    "    return color;\n"
-    "}\n";
-
-static const char shader_grayscale_source[] =
-    "sampler2D screen;\n"
-    "float4 main(float2 screenCoords : TEXCOORD0) : COLOR0\n"
-    "{\n"
-    "    float4 color = tex2D(screen, screenCoords.xy);\n"
-    "    float gray = 0.2989 * color.r + 0.5870 * color.g + 0.1140 * color.b;\n"
-    "    color.r = color.g = color.b = gray;\n"
-    "    return color;\n"
-    "}\n";
-
-static const char shader_convert601to709_source[] =
-    "sampler2D screen;\n"
-    "float4 rgb_to_yuv601(float4 RGB)\n"
-    "{\n"
-    "    float Kr = 0.299;\n"
-    "    float Kg = 0.587;\n"
-    "    float Kb = 0.114;\n"
-    "    float Y = Kr*RGB.r + Kg*RGB.g + Kb*RGB.b;\n"
-    "    float V = (RGB.r-Y)/(1-Kr);\n"
-    "    float U = (RGB.b-Y)/(1-Kb);\n"
-    "    return float4(Y,U,V,1);\n"
-    "}\n"
-
-    "float4 yuv709_to_rgb(float4 YUV)\n"
-    "{\n"
-    "    float Kr = 0.2125;\n"
-    "    float Kg = 0.7154;\n"
-    "    float Kb = 0.0721;\n"
-    "    float Y = YUV.x;\n"
-    "    float U = YUV.y;\n"
-    "    float V = YUV.z;\n"
-    "    float R = Y + V*(1-Kr);\n"
-    "    float G = Y - U*(1-Kb)*Kb/Kg - V*(1-Kr)*Kr/Kg;\n"
-    "    float B = Y + U*(1-Kb);\n"
-    "    return float4(R,G,B,1);\n"
-    "}\n"
-
-    "float4 main(float2 screenCoords : TEXCOORD0) : COLOR0\n"
-    "{\n"
-    "    float4 color = tex2D(screen, screenCoords.xy);\n"
-    "    return yuv709_to_rgb(rgb_to_yuv601(color));\n"
-    "}\n";
-
-static const char shader_gammacorrection18_source[] =
-    "sampler2D screen;\n"
-    "float4 main(float2 screenCoords : TEXCOORD0) : COLOR0\n"
-    "{\n"
-    "    float4 color = tex2D( screen, screenCoords.xy);\n"
-    "    color = pow(color,1.0/1.8);\n"
-    "    return color;\n"
-    "}\n";
-
-static const char shader_gammacorrection22_source[] =
-    "sampler2D screen;\n"
-    "float4 main(float2 screenCoords : TEXCOORD0) : COLOR0\n"
-    "{\n"
-    "    float4 color = tex2D( screen, screenCoords.xy);\n"
-    "    color = pow(color,1.0/2.2);\n"
-    "    return color;\n"
-    "}\n";
-
-static const char shader_gammacorrectionbt709_source[] =
-    "sampler2D screen;\n"
-    "float4 main(float2 screenCoords : TEXCOORD0) : COLOR0\n"
-    "{\n"
-    "    float4 color = tex2D(screen, screenCoords.xy);\n"
-    "    if(color.r > 0.018)\n"
-    "        color.r = 1.099 * pow(color.r,0.45) - 0.099;\n"
-    "    else\n"
-    "        color.r = 4.5138 * color.r;\n"
-    "    if(color.g > 0.018)\n"
-    "        color.g = 1.099 * pow(color.g,0.45) - 0.099;\n"
-    "    else\n"
-    "        color.g = 4.5138 * color.g;\n"
-    "    if(color.b > 0.018)\n"
-    "        color.b = 1.099 * pow(color.b,0.45) - 0.099;\n"
-    "    else\n"
-    "        color.b = 4.5138 * color.b;\n"
-    "    return color;\n"
-    "}\n";
-
-static const char shader_widencolorspace_source[] =
-    "sampler2D screen;\n"
-    "float4 main(float2 screenCoords : TEXCOORD0) : COLOR0\n"
-    "{\n"
-    "    float4 color = tex2D(screen, screenCoords.xy);\n"
-    "    color.r = max(color.r - 0.0627450980392157,0) * 1.164383561643836;\n"
-    "    color.g = max(color.g - 0.0627450980392157,0) * 1.164383561643836;\n"
-    "    color.b = max(color.b - 0.0627450980392157,0) * 1.164383561643836;\n"
-    "    return saturate(color);\n"
-    "}\n";
-
-typedef struct
-{
-    const char *name;
-    const char *code;
-} builtin_shader_t;
-
-static const builtin_shader_t builtin_shaders[] =
-{
-    { "Disabled", shader_disabled_source },
-    { "Invert", shader_invert_source },
-    { "Grayscale", shader_grayscale_source },
-    { "Convert601to709", shader_convert601to709_source },
-    { "GammaCorrection18", shader_gammacorrection18_source },
-    { "GammaCorrection22", shader_gammacorrection22_source },
-    { "GammaCorrectionBT709", shader_gammacorrectionbt709_source },
-    { "WidenColorSpace", shader_widencolorspace_source },
-};
-#define BUILTIN_SHADERS_COUNT (sizeof(builtin_shaders)/sizeof(builtin_shaders[0]))
diff --git a/modules/video_output/msw/common.c b/modules/video_output/msw/common.c
deleted file mode 100644 (file)
index 4c880fa..0000000
+++ /dev/null
@@ -1,757 +0,0 @@
-/*****************************************************************************
- * common.c: Windows video output common code
- *****************************************************************************
- * Copyright (C) 2001-2009 VLC authors and VideoLAN
- * $Id$
- *
- * Authors: Gildas Bazin <gbazin@videolan.org>
- *          Martell Malone <martellmalone@gmail.com>
- *
- * 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 Lesser General Public License for more details.
- *
- * 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.
- *****************************************************************************/
-
-/*****************************************************************************
- * 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 <vlc_common.h>
-#include <vlc_vout_display.h>
-
-#include <windows.h>
-#include <assert.h>
-
-#define COBJMACROS
-#include <shobjidl.h>
-
-#include "common.h"
-
-static void CommonChangeThumbnailClip(vout_display_t *, bool show);
-#if !VLC_WINSTORE_APP
-static int  CommonControlSetFullscreen(vout_display_t *, bool is_fullscreen);
-
-static void DisableScreensaver(vout_display_t *);
-static void RestoreScreensaver(vout_display_t *);
-#endif
-
-/* */
-int CommonInit(vout_display_t *vd)
-{
-    vout_display_sys_t *sys = vd->sys;
-
-    sys->hwnd      = NULL;
-    sys->hvideownd = NULL;
-    sys->hparent   = NULL;
-    sys->hfswnd    = NULL;
-    sys->changes   = 0;
-    sys->is_first_display = true;
-    sys->is_on_top        = false;
-
-#if !VLC_WINSTORE_APP
-    SetRectEmpty(&sys->rect_display);
-    SetRectEmpty(&sys->rect_parent);
-
-    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);
-    if (!sys->event)
-        return VLC_EGENERIC;
-#endif
-
-    event_cfg_t cfg;
-    memset(&cfg, 0, sizeof(cfg));
-#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.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;
-
-#if !VLC_WINSTORE_APP
-    event_hwnd_t hwnd;
-    if (EventThreadStart(sys->event, &hwnd, &cfg))
-        return VLC_EGENERIC;
-
-    sys->parent_window = hwnd.parent_window;
-    sys->hparent       = hwnd.hparent;
-    sys->hwnd          = hwnd.hwnd;
-    sys->hvideownd     = hwnd.hvideownd;
-    sys->hfswnd        = hwnd.hfswnd;
-
-    if (vd->cfg->is_fullscreen) {
-        if (CommonControlSetFullscreen(vd, true))
-            vout_display_SendEventFullscreen(vd, false);
-    }
-
-    DisableScreensaver (vd);
-#endif
-
-    return VLC_SUCCESS;
-}
-
-/* */
-picture_pool_t *CommonPool(vout_display_t *vd, unsigned count)
-{
-    VLC_UNUSED(count);
-    return vd->sys->pool;
-}
-
-/*****************************************************************************
-* UpdateRects: update clipping rectangles
-*****************************************************************************
-* This function is called when the window position or size are changed, and
-* its job is to update the source and destination RECTs used to display the
-* picture.
-*****************************************************************************/
-void UpdateRects(vout_display_t *vd,
-    const vout_display_cfg_t *cfg,
-    const video_format_t *source,
-    bool is_forced)
-{
-    vout_display_sys_t *sys = vd->sys;
-#define rect_src sys->rect_src
-#define rect_src_clipped sys->rect_src_clipped
-#define rect_dest sys->rect_dest
-#define rect_dest_clipped sys->rect_dest_clipped
-
-    RECT  rect;
-    POINT point;
-
-    /* */
-    if (!cfg)
-        cfg = vd->cfg;
-    if (!source)
-        source = &vd->source;
-
-    /* Retrieve the window size */
-#if VLC_WINSTORE_APP && MODULE_NAME_IS_direct3d11
-    rect.left   = 0;
-    rect.top    = 0;
-    uint32_t i_width;
-    uint32_t i_height;
-    UINT dataSize = sizeof(i_width);
-    HRESULT hr = IDXGISwapChain_GetPrivateData(sys->dxgiswapChain, &GUID_SWAPCHAIN_WIDTH, &dataSize, &i_width);
-    if (FAILED(hr)) {
-        msg_Err(vd, "Can't get swapchain width, size %d. (hr=0x%lX)", hr, dataSize);
-        return;
-    }
-    dataSize = sizeof(i_height);
-    hr = IDXGISwapChain_GetPrivateData(sys->dxgiswapChain, &GUID_SWAPCHAIN_HEIGHT, &dataSize, &i_height);
-    if (FAILED(hr)) {
-        msg_Err(vd, "Can't get swapchain height, size %d. (hr=0x%lX)", hr, dataSize);
-        return;
-    }
-    rect.right  = i_width;
-    rect.bottom = i_height;
-#else
-    GetClientRect(sys->hwnd, &rect);
-#endif
-
-    /* Retrieve the window position */
-    point.x = point.y = 0;
-#if !VLC_WINSTORE_APP
-    ClientToScreen(sys->hwnd, &point);
-#endif
-
-    /* If nothing changed, we can return */
-    bool has_moved;
-    bool is_resized;
-#if VLC_WINSTORE_APP
-    has_moved = false;
-    is_resized = rect.right != (sys->rect_display.right - sys->rect_display.left) ||
-        rect.bottom != (sys->rect_display.bottom - sys->rect_display.top);
-    sys->rect_display = rect;
-#else
-    EventThreadUpdateWindowPosition(sys->event, &has_moved, &is_resized,
-        point.x, point.y,
-        rect.right, rect.bottom);
-#endif
-    if (is_resized)
-        vout_display_SendEventDisplaySize(vd, rect.right, rect.bottom);
-    if (!is_forced && !has_moved && !is_resized)
-        return;
-
-    /* Update the window position and size */
-    vout_display_cfg_t place_cfg = *cfg;
-    place_cfg.display.width = rect.right;
-    place_cfg.display.height = rect.bottom;
-
-    vout_display_place_t place;
-    vout_display_PlacePicture(&place, source, &place_cfg, false);
-
-#if !VLC_WINSTORE_APP
-    EventThreadUpdateSourceAndPlace(sys->event, source, &place);
-
-    if (sys->hvideownd)
-        SetWindowPos(sys->hvideownd, 0,
-            place.x, place.y, place.width, place.height,
-            SWP_NOCOPYBITS | SWP_NOZORDER | SWP_ASYNCWINDOWPOS);
-#endif
-
-    /* Destination image position and dimensions */
-#if (defined(MODULE_NAME_IS_direct3d9) || defined(MODULE_NAME_IS_direct3d11) || defined(MODULE_NAME_IS_direct2d)) && !VLC_WINSTORE_APP
-    rect_dest.left = 0;
-    rect_dest.right = place.width;
-    rect_dest.top = 0;
-    rect_dest.bottom = place.height;
-#else
-    rect_dest.left = point.x + place.x;
-    rect_dest.right = rect_dest.left + place.width;
-    rect_dest.top = point.y + place.y;
-    rect_dest.bottom = rect_dest.top + place.height;
-
-#ifdef MODULE_NAME_IS_directdraw
-    /* Apply overlay hardware constraints */
-    if (sys->use_overlay)
-        AlignRect(&rect_dest, sys->i_align_dest_boundary, sys->i_align_dest_size);
-#endif
-
-#endif
-
-#if defined(MODULE_NAME_IS_directdraw)
-    /* UpdateOverlay directdraw function doesn't automatically clip to the
-    * display size so we need to do it otherwise it will fail */
-
-    /* Clip the destination window */
-    if (!IntersectRect(&rect_dest_clipped, &rect_dest,
-        &sys->rect_display)) {
-        SetRectEmpty(&rect_src_clipped);
-        goto exit;
-    }
-
-#ifndef NDEBUG
-    msg_Dbg(vd, "DirectXUpdateRects image_dst_clipped coords:"
-        " %li,%li,%li,%li",
-        rect_dest_clipped.left, rect_dest_clipped.top,
-        rect_dest_clipped.right, rect_dest_clipped.bottom);
-#endif
-
-#else
-
-    /* AFAIK, there are no clipping constraints in Direct3D, OpenGL and GDI */
-    rect_dest_clipped = rect_dest;
-
-#endif
-
-    /* the 2 following lines are to fix a bug when clicking on the desktop */
-    if ((rect_dest_clipped.right - rect_dest_clipped.left) == 0 ||
-        (rect_dest_clipped.bottom - rect_dest_clipped.top) == 0) {
-#if !VLC_WINSTORE_APP
-        SetRectEmpty(&rect_src_clipped);
-#endif
-        goto exit;
-    }
-
-    /* src image dimensions */
-    rect_src.left = 0;
-    rect_src.top = 0;
-    rect_src.right = vd->fmt.i_width;
-    rect_src.bottom = vd->fmt.i_height;
-
-    /* Clip the source image */
-    rect_src_clipped.left = source->i_x_offset +
-        (rect_dest_clipped.left - rect_dest.left) *
-        source->i_visible_width / (rect_dest.right - rect_dest.left);
-    rect_src_clipped.right = source->i_x_offset +
-        source->i_visible_width -
-        (rect_dest.right - rect_dest_clipped.right) *
-        source->i_visible_width / (rect_dest.right - rect_dest.left);
-    rect_src_clipped.top = source->i_y_offset +
-        (rect_dest_clipped.top - rect_dest.top) *
-        source->i_visible_height / (rect_dest.bottom - rect_dest.top);
-    rect_src_clipped.bottom = source->i_y_offset +
-        source->i_visible_height -
-        (rect_dest.bottom - rect_dest_clipped.bottom) *
-        source->i_visible_height / (rect_dest.bottom - rect_dest.top);
-
-#ifdef MODULE_NAME_IS_directdraw
-    /* 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_direct3d9) || defined(MODULE_NAME_IS_direct3d11) || defined(MODULE_NAME_IS_direct2d)
-    /* Needed at least with YUV content */
-    rect_src_clipped.left &= ~1;
-    rect_src_clipped.right &= ~1;
-    rect_src_clipped.top &= ~1;
-    rect_src_clipped.bottom &= ~1;
-#endif
-
-#ifndef NDEBUG
-    msg_Dbg(vd, "DirectXUpdateRects souce"
-        " offset: %i,%i visible: %ix%i",
-        source->i_x_offset, source->i_y_offset,
-        source->i_visible_width, source->i_visible_height);
-    msg_Dbg(vd, "DirectXUpdateRects image_src"
-        " coords: %li,%li,%li,%li",
-        rect_src.left, rect_src.top,
-        rect_src.right, rect_src.bottom);
-    msg_Dbg(vd, "DirectXUpdateRects image_src_clipped"
-        " coords: %li,%li,%li,%li",
-        rect_src_clipped.left, rect_src_clipped.top,
-        rect_src_clipped.right, rect_src_clipped.bottom);
-    msg_Dbg(vd, "DirectXUpdateRects image_dst"
-        " coords: %li,%li,%li,%li",
-        rect_dest.left, rect_dest.top,
-        rect_dest.right, rect_dest.bottom);
-    msg_Dbg(vd, "DirectXUpdateRects image_dst_clipped"
-        " coords: %li,%li,%li,%li",
-        rect_dest_clipped.left, rect_dest_clipped.top,
-        rect_dest_clipped.right, rect_dest_clipped.bottom);
-#endif
-
-#ifdef MODULE_NAME_IS_directdraw
-    /* The destination coordinates need to be relative to the current
-    * directdraw primary surface (display) */
-    rect_dest_clipped.left -= sys->rect_display.left;
-    rect_dest_clipped.right -= sys->rect_display.left;
-    rect_dest_clipped.top -= sys->rect_display.top;
-    rect_dest_clipped.bottom -= sys->rect_display.top;
-#endif
-
-    CommonChangeThumbnailClip(vd, true);
-
-exit:
-    /* Signal the change in size/position */
-    sys->changes |= DX_POSITION_CHANGE;
-
-#undef rect_src
-#undef rect_src_clipped
-#undef rect_dest
-#undef rect_dest_clipped
-}
-
-#if !VLC_WINSTORE_APP
-/* */
-void CommonClean(vout_display_t *vd)
-{
-    vout_display_sys_t *sys = vd->sys;
-    if (sys->event) {
-        CommonChangeThumbnailClip(vd, false);
-        EventThreadStop(sys->event);
-        EventThreadDestroy(sys->event);
-    }
-
-    RestoreScreensaver(vd);
-}
-
-void CommonManage(vout_display_t *vd)
-{
-    vout_display_sys_t *sys = vd->sys;
-
-    /* We used to call the Win32 PeekMessage function here to read the window
-     * messages. But since window can stay blocked into this function for a
-     * long time (for example when you move your window on the screen), I
-     * decided to isolate PeekMessage in another thread. */
-    /* If we do not control our window, we check for geometry changes
-     * ourselves because the parent might not send us its events. */
-    if (sys->hparent) {
-        RECT rect_parent;
-        POINT point;
-
-        /* Check if the parent window has resized or moved */
-        GetClientRect(sys->hparent, &rect_parent);
-        point.x = point.y = 0;
-        ClientToScreen(sys->hparent, &point);
-        OffsetRect(&rect_parent, point.x, point.y);
-
-        if (!EqualRect(&rect_parent, &sys->rect_parent)) {
-            sys->rect_parent = rect_parent;
-
-            /* This code deals with both resize and move
-             *
-             * For most drivers(direct3d9, gdi, opengl), move is never
-             * an issue. The surface automatically gets moved together
-             * with the associated window (hvideownd)
-             *
-             * 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,
-                         rect_parent.right - rect_parent.left,
-                         rect_parent.bottom - rect_parent.top,
-                         SWP_NOZORDER);
-
-            UpdateRects(vd, NULL, NULL, true);
-        }
-    }
-
-    /* HasMoved means here resize or move */
-    if (EventThreadGetAndResetHasMoved(sys->event))
-        UpdateRects(vd, NULL, NULL, false);
-}
-
-/**
- * It ensures that the video window is shown after the first picture
- * is displayed.
- */
-void CommonDisplay(vout_display_t *vd)
-{
-    vout_display_sys_t *sys = vd->sys;
-    if (!sys->is_first_display)
-        return;
-
-    /* Video window is initially hidden, show it now since we got a
-     * picture to show.
-     */
-    SetWindowPos(sys->hvideownd, 0, 0, 0, 0, 0,
-                 SWP_ASYNCWINDOWPOS|
-                 SWP_FRAMECHANGED|
-                 SWP_SHOWWINDOW|
-                 SWP_NOMOVE|
-                 SWP_NOSIZE|
-                 SWP_NOZORDER);
-    sys->is_first_display = false;
-}
-#endif
-
-/**
- * It updates a picture data/pitches.
- */
-int CommonUpdatePicture(picture_t *picture, picture_t **fallback,
-                        uint8_t *data, unsigned pitch)
-{
-    if (fallback) {
-        if (*fallback == NULL) {
-            *fallback = picture_NewFromFormat(&picture->format);
-            if (*fallback == NULL)
-                return VLC_EGENERIC;
-        }
-        for (int n = 0; n < picture->i_planes; n++) {
-            const plane_t *src = &(*fallback)->p[n];
-            plane_t       *dst = &picture->p[n];
-            dst->p_pixels = src->p_pixels;
-            dst->i_pitch  = src->i_pitch;
-            dst->i_lines  = src->i_lines;
-        }
-        return VLC_SUCCESS;
-    }
-    /* 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;
-
-    /*  Fill chroma planes for biplanar YUV */
-    if (picture->format.i_chroma == VLC_CODEC_NV12 ||
-        picture->format.i_chroma == VLC_CODEC_NV21) {
-
-        for (int n = 1; n < picture->i_planes; n++) {
-            const plane_t *o = &picture->p[n-1];
-            plane_t *p = &picture->p[n];
-
-            p->p_pixels = o->p_pixels + o->i_lines * o->i_pitch;
-            p->i_pitch  = pitch;
-            p->i_lines  = picture->format.i_height;
-        }
-        /* The dx/d3d buffer is always allocated as NV12 */
-        if (vlc_fourcc_AreUVPlanesSwapped(picture->format.i_chroma, VLC_CODEC_NV12)) {
-            /* TODO : Swap NV21 UV planes to match NV12 */
-            return VLC_EGENERIC;
-        }
-    }
-
-    /*  Fill chroma planes for planar YUV */
-    if (picture->format.i_chroma == VLC_CODEC_I420 ||
-        picture->format.i_chroma == VLC_CODEC_J420 ||
-        picture->format.i_chroma == VLC_CODEC_YV12) {
-
-        for (int n = 1; n < picture->i_planes; n++) {
-            const plane_t *o = &picture->p[n-1];
-            plane_t *p = &picture->p[n];
-
-            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;
-        }
-        /* The dx/d3d buffer is always allocated as YV12 */
-        if (vlc_fourcc_AreUVPlanesSwapped(picture->format.i_chroma, VLC_CODEC_YV12)) {
-            uint8_t *p_tmp = picture->p[1].p_pixels;
-            picture->p[1].p_pixels = picture->p[2].p_pixels;
-            picture->p[2].p_pixels = p_tmp;
-        }
-    }
-    return VLC_SUCCESS;
-}
-
-void AlignRect(RECT *r, int align_boundary, int align_size)
-{
-    if (align_boundary)
-        r->left = (r->left + align_boundary/2) & ~align_boundary;
-    if (align_size)
-        r->right = ((r->right - r->left + align_size/2) & ~align_size) + r->left;
-}
-
-#if !VLC_WINSTORE_APP
-/* */
-static void CommonChangeThumbnailClip(vout_display_t *vd, bool show)
-{
-    vout_display_sys_t *sys = vd->sys;
-
-    /* Windows 7 taskbar thumbnail code */
-    OSVERSIONINFO winVer;
-    winVer.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
-    if (!GetVersionEx(&winVer) || winVer.dwMajorVersion <= 5)
-        return;
-
-    if( FAILED(CoInitializeEx(NULL, COINIT_MULTITHREADED)) )
-        vlc_assert_unreachable();
-
-    void *ptr;
-    if (S_OK == CoCreateInstance(&CLSID_TaskbarList,
-                                 NULL, CLSCTX_INPROC_SERVER,
-                                 &IID_ITaskbarList3,
-                                 &ptr)) {
-        ITaskbarList3 *taskbl = ptr;
-        taskbl->lpVtbl->HrInit(taskbl);
-
-        HWND hroot = GetAncestor(sys->hwnd,GA_ROOT);
-        RECT relative;
-        if (show) {
-            RECT video, parent;
-            GetWindowRect(sys->hvideownd, &video);
-            GetWindowRect(hroot, &parent);
-            relative.left   = video.left   - parent.left - 8;
-            relative.top    = video.top    - parent.top - 10;
-
-            relative.right  = video.right  - video.left + relative.left;
-            relative.bottom = video.bottom - video.top  + relative.top - 25;
-        }
-        if (S_OK != taskbl->lpVtbl->SetThumbnailClip(taskbl, hroot,
-                                                 show ? &relative : NULL))
-            msg_Err(vd, "SetThumbNailClip failed");
-
-        taskbl->lpVtbl->Release(taskbl);
-    }
-    CoUninitialize();
-}
-
-static int CommonControlSetFullscreen(vout_display_t *vd, bool is_fullscreen)
-{
-    vout_display_sys_t *sys = vd->sys;
-
-#ifdef MODULE_NAME_IS_direct3d9
-    if (sys->use_desktop && is_fullscreen)
-        return VLC_EGENERIC;
-#endif
-
-    /* */
-    if (sys->parent_window)
-        return VLC_EGENERIC;
-
-    /* */
-    HWND hwnd = sys->hparent && sys->hfswnd ? sys->hfswnd : sys->hwnd;
-
-    /* Save the current windows placement/placement to restore
-       when fullscreen is over */
-    WINDOWPLACEMENT window_placement;
-    window_placement.length = sizeof(WINDOWPLACEMENT);
-    GetWindowPlacement(hwnd, &window_placement);
-
-    if (is_fullscreen) {
-        msg_Dbg(vd, "entering fullscreen mode");
-
-        /* Change window style, no borders and no title bar */
-        SetWindowLong(hwnd, GWL_STYLE, WS_CLIPCHILDREN | WS_VISIBLE);
-
-        if (sys->hparent) {
-            /* Retrieve current window position so fullscreen will happen
-            *on the right screen */
-            HMONITOR hmon = MonitorFromWindow(sys->hparent,
-                                              MONITOR_DEFAULTTONEAREST);
-            MONITORINFO mi;
-            mi.cbSize = sizeof(MONITORINFO);
-            if (GetMonitorInfo(hmon, &mi))
-                SetWindowPos(hwnd, 0,
-                             mi.rcMonitor.left,
-                             mi.rcMonitor.top,
-                             mi.rcMonitor.right - mi.rcMonitor.left,
-                             mi.rcMonitor.bottom - mi.rcMonitor.top,
-                             SWP_NOZORDER|SWP_FRAMECHANGED);
-        } else {
-            /* Maximize non embedded window */
-            ShowWindow(hwnd, SW_SHOWMAXIMIZED);
-        }
-
-        if (sys->hparent) {
-            /* Hide the previous window */
-            RECT rect;
-            GetClientRect(hwnd, &rect);
-            SetParent(sys->hwnd, hwnd);
-            SetWindowPos(sys->hwnd, 0, 0, 0,
-                         rect.right, rect.bottom,
-                         SWP_NOZORDER|SWP_FRAMECHANGED);
-
-            HWND topLevelParent = GetAncestor(sys->hparent, GA_ROOT);
-            ShowWindow(topLevelParent, SW_HIDE);
-        }
-        SetForegroundWindow(hwnd);
-    } else {
-        msg_Dbg(vd, "leaving fullscreen mode");
-
-        /* Change window style, no borders and no title bar */
-        SetWindowLong(hwnd, GWL_STYLE, EventThreadGetWindowStyle(sys->event));
-
-        if (sys->hparent) {
-            RECT rect;
-            GetClientRect(sys->hparent, &rect);
-            SetParent(sys->hwnd, sys->hparent);
-            SetWindowPos(sys->hwnd, 0, 0, 0,
-                         rect.right, rect.bottom,
-                         SWP_NOZORDER|SWP_FRAMECHANGED);
-
-            HWND topLevelParent = GetAncestor(sys->hparent, GA_ROOT);
-            ShowWindow(topLevelParent, SW_SHOW);
-            SetForegroundWindow(sys->hparent);
-            ShowWindow(hwnd, SW_HIDE);
-        } else {
-            /* return to normal window for non embedded vout */
-            SetWindowPlacement(hwnd, &window_placement);
-            ShowWindow(hwnd, SW_SHOWNORMAL);
-        }
-    }
-    return VLC_SUCCESS;
-}
-
-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 */
-    {   /* 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;
-
-        if (query == VOUT_DISPLAY_CHANGE_SOURCE_CROP ||
-            query == VOUT_DISPLAY_CHANGE_SOURCE_ASPECT) {
-            const video_format_t *source = va_arg(args, const video_format_t *);
-            cfg    = vd->cfg;
-            UpdateRects(vd, cfg, source, true);
-        } else {
-            cfg    = va_arg(args, const vout_display_cfg_t *);
-            UpdateRects(vd, cfg, NULL, 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_direct3d9
-        if (sys->use_desktop && is_on_top)
-            return VLC_EGENERIC;
-#endif
-        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: {
-        bool fs = va_arg(args, int);
-        if (CommonControlSetFullscreen(vd, fs))
-            return VLC_EGENERIC;
-        UpdateRects(vd, NULL, NULL, false);
-        return VLC_SUCCESS;
-    }
-
-    case VOUT_DISPLAY_HIDE_MOUSE:
-        EventThreadMouseHide(sys->event);
-        return VLC_SUCCESS;
-    case VOUT_DISPLAY_RESET_PICTURES:
-        vlc_assert_unreachable();
-    default:
-        return VLC_EGENERIC;
-    }
-}
-
-static void DisableScreensaver(vout_display_t *vd)
-{
-    vout_display_sys_t *sys = vd->sys;
-
-    /* disable screensaver by temporarily changing system settings */
-    sys->i_spi_screensaveactive = 0;
-    if (var_GetBool(vd, "disable-screensaver")) {
-        msg_Dbg(vd, "disabling screen saver");
-        SystemParametersInfo(SPI_GETSCREENSAVEACTIVE, 0,
-                             &sys->i_spi_screensaveactive, 0);
-
-        if (FALSE != sys->i_spi_screensaveactive) {
-            SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, 0, NULL, 0);
-        }
-    }
-}
-
-static void RestoreScreensaver(vout_display_t *vd)
-{
-    vout_display_sys_t *sys = vd->sys;
-
-    /* restore screensaver system settings */
-    if (0 != sys->i_spi_screensaveactive) {
-        SystemParametersInfo(SPI_SETSCREENSAVEACTIVE,
-                             sys->i_spi_screensaveactive, NULL, 0);
-    }
-}
-
-#else
-
-int CommonControl(vout_display_t *vd, int query, va_list args)
-{
-    switch (query) {
-    default:
-        return VLC_EGENERIC;
-    }
-}
-
-void CommonManage(vout_display_t *vd) {
-    UpdateRects(vd, NULL, NULL, false);
-}
-void CommonClean(vout_display_t *vd) {}
-void CommonDisplay(vout_display_t *vd) {}
-void CommonChangeThumbnailClip(vout_display_t *vd, bool show) {}
-#endif
diff --git a/modules/video_output/msw/common.h b/modules/video_output/msw/common.h
deleted file mode 100644 (file)
index 09408a8..0000000
+++ /dev/null
@@ -1,280 +0,0 @@
-/*****************************************************************************
- * common.h: Windows video output header file
- *****************************************************************************
- * Copyright (C) 2001-2009 VLC authors and VideoLAN
- * $Id$
- *
- * Authors: Gildas Bazin <gbazin@videolan.org>
- *          Damien Fouilleul <damienf@videolan.org>
- *          Martell Malone <martellmalone@gmail.com>
- *
- * 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 Lesser General Public License for more details.
- *
- * 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.
- *****************************************************************************/
-
-#ifdef MODULE_NAME_IS_directdraw
-# include <ddraw.h>
-#endif
-#ifdef MODULE_NAME_IS_direct3d11
-# include <d3d11.h>
-# include <dxgi1_2.h>
-# include <d3dcompiler.h>
-#endif
-#ifdef MODULE_NAME_IS_direct3d9
-# include <d3d9.h>
-# include <d3dx9effect.h>
-#endif
-#ifdef MODULE_NAME_IS_glwin32
-# include "../opengl.h"
-#endif
-#ifdef MODULE_NAME_IS_direct2d
-# include <d2d1.h>
-#endif
-
-/*****************************************************************************
- * event_thread_t: event thread
- *****************************************************************************/
-#include "events.h"
-
-#ifdef MODULE_NAME_IS_direct3d11
-typedef struct
-{
-    DXGI_FORMAT   textureFormat;
-    DXGI_FORMAT   resourceFormatYRGB;
-    DXGI_FORMAT   resourceFormatUV;
-} d3d_quad_cfg_t;
-
-typedef struct
-{
-    ID3D11Buffer              *pVertexBuffer;
-    ID3D11Texture2D           *pTexture;
-    ID3D11ShaderResourceView  *d3dresViewY;
-    ID3D11ShaderResourceView  *d3dresViewUV;
-    ID3D11PixelShader         *d3dpixelShader;
-    D3D11_VIEWPORT            cropViewport;
-} d3d_quad_t;
-#endif
-
-#if VLC_WINSTORE_APP
-extern const GUID GUID_SWAPCHAIN_WIDTH;
-extern const GUID GUID_SWAPCHAIN_HEIGHT;
-#endif
-
-/*****************************************************************************
- * vout_sys_t: video output method descriptor
- *****************************************************************************
- * This structure is part of the video output thread descriptor.
- * It describes the module specific properties of an output thread.
- *****************************************************************************/
-struct vout_display_sys_t
-{
-    /* */
-    event_thread_t *event;
-
-    /* */
-    HWND                 hwnd;                  /* Handle of the main window */
-    HWND                 hvideownd;        /* Handle of the video sub-window */
-    struct vout_window_t *parent_window;         /* Parent window VLC object */
-    HWND                 hparent;             /* Handle of the parent window */
-    HWND                 hfswnd;          /* Handle of the fullscreen window */
-
-    /* size of the display */
-    RECT         rect_display;
-
-    /* size of the overall window (including black bands) */
-    RECT         rect_parent;
-
-    unsigned changes;        /* changes made to the video display */
-
-    /* Misc */
-    bool is_first_display;
-    bool is_on_top;
-
-    /* screensaver system settings to be restored when vout is closed */
-    UINT i_spi_screensaveactive;
-
-    /* Coordinates of src and dest images (used when blitting to display) */
-    RECT         rect_src;
-    RECT         rect_src_clipped;
-    RECT         rect_dest;
-    RECT         rect_dest_clipped;
-
-    picture_pool_t *pool;
-
-#ifdef MODULE_NAME_IS_directdraw
-    /* Multi-monitor support */
-    HMONITOR             hmonitor;          /* handle of the current monitor */
-    GUID                 *display_driver;
-
-    /* Overlay alignment restrictions */
-    int          i_align_src_boundary;
-    int          i_align_src_size;
-    int          i_align_dest_boundary;
-    int          i_align_dest_size;
-
-    bool   use_wallpaper;   /* show as desktop wallpaper ? */
-
-    bool   use_overlay;     /* Are we using an overlay surface */
-    bool   restore_overlay;
-
-    /* DDraw capabilities */
-    bool            can_blit_fourcc;
-
-    uint32_t        i_rgb_colorkey;      /* colorkey in RGB used by the overlay */
-    uint32_t        i_colorkey;                 /* colorkey used by the overlay */
-
-    COLORREF        color_bkg;
-    COLORREF        color_bkgtxt;
-
-    LPDIRECTDRAW2        ddobject;                    /* DirectDraw object */
-    LPDIRECTDRAWSURFACE2 display;                        /* Display device */
-    LPDIRECTDRAWCLIPPER  clipper;             /* clipper used for blitting */
-    HINSTANCE            hddraw_dll;       /* handle of the opened ddraw dll */
-
-    picture_sys_t        *picsys;
-
-    /* It protects the following variables */
-    vlc_mutex_t    lock;
-    bool           ch_wallpaper;
-    bool           wallpaper_requested;
-#endif
-
-#ifdef MODULE_NAME_IS_glwin32
-    HDC                   hGLDC;
-    HGLRC                 hGLRC;
-    vlc_gl_t              gl;
-    vout_display_opengl_t *vgl;
-    HDC                   affinityHDC; // DC for the selected GPU
-#endif
-
-#ifdef MODULE_NAME_IS_direct2d
-    HINSTANCE              d2_dll;            /* handle of the opened d2d1 dll */
-    ID2D1Factory           *d2_factory;                         /* D2D factory */
-    ID2D1HwndRenderTarget  *d2_render_target;          /* D2D rendering target */
-    ID2D1Bitmap            *d2_bitmap;                            /* D2 bitmap */
-#endif
-
-#ifdef MODULE_NAME_IS_direct3d11
-#if !VLC_WINSTORE_APP
-    HINSTANCE                hdxgi_dll;        /* handle of the opened dxgi dll */
-    HINSTANCE                hd3d11_dll;       /* handle of the opened d3d11 dll */
-    HINSTANCE                hd3dcompiler_dll; /* handle of the opened d3dcompiler dll */
-    IDXGIFactory2            *dxgifactory;     /* DXGI 1.2 factory */
-    /* We should find a better way to store this or atleast a shorter name */
-    PFN_D3D11_CREATE_DEVICE_AND_SWAP_CHAIN OurD3D11CreateDeviceAndSwapChain;
-    PFN_D3D11_CREATE_DEVICE                OurD3D11CreateDevice;
-    pD3DCompile                            OurD3DCompile;
-#endif
-    IDXGISwapChain1          *dxgiswapChain;   /* DXGI 1.1 swap chain */
-    ID3D11Device             *d3ddevice;       /* D3D device */
-    ID3D11DeviceContext      *d3dcontext;      /* D3D context */
-    d3d_quad_t               picQuad;
-    d3d_quad_cfg_t           picQuadConfig;
-    ID3D11RenderTargetView   *d3drenderTargetView;
-    ID3D11DepthStencilView   *d3ddepthStencilView;
-    const char               *d3dPxShader;
-
-    // SPU
-    vlc_fourcc_t             pSubpictureChromas[2];
-    const char               *psz_rgbaPxShader;
-    ID3D11PixelShader        *pSPUPixelShader;
-    DXGI_FORMAT              d3dregion_format;
-    int                      d3dregion_count;
-    picture_t                **d3dregions;
-#endif
-
-#ifdef MODULE_NAME_IS_direct3d9
-    bool allow_hw_yuv;    /* Should we use hardware YUV->RGB conversions */
-    /* show video on desktop window ? */
-    bool use_desktop;
-    struct {
-        bool is_fullscreen;
-        bool is_on_top;
-        RECT win;
-    } desktop_save;
-    vout_display_cfg_t cfg_saved; /* configuration used before going into desktop mode */
-
-    // core objects
-    HINSTANCE               hd3d9_dll;       /* handle of the opened d3d9 dll */
-    HINSTANCE               hd3d9x_dll;      /* handle of the opened d3d9x dll */
-    IDirect3DPixelShader9*  d3dx_shader;
-    LPDIRECT3D9             d3dobj;
-    D3DCAPS9                d3dcaps;
-    LPDIRECT3DDEVICE9       d3ddev;
-    D3DPRESENT_PARAMETERS   d3dpp;
-    bool                    use_d3d9ex;
-
-    // scene objects
-    LPDIRECT3DTEXTURE9      d3dtex;
-    LPDIRECT3DVERTEXBUFFER9 d3dvtc;
-    D3DFORMAT               d3dregion_format;
-    int                     d3dregion_count;
-    struct d3d_region_t     *d3dregion;
-
-    picture_sys_t           *picsys;
-
-    /* */
-    bool                    reset_device;
-    bool                    reopen_device;
-    bool                    lost_not_ready;
-    bool                    clear_scene;
-
-    /* It protects the following variables */
-    vlc_mutex_t    lock;
-    bool           ch_desktop;
-    bool           desktop_requested;
-#endif
-
-#if defined(MODULE_NAME_IS_wingdi)
-    int  i_depth;
-
-    /* Our offscreen bitmap and its framebuffer */
-    HDC        off_dc;
-    HBITMAP    off_bitmap;
-
-    struct
-    {
-        BITMAPINFO bitmapinfo;
-        RGBQUAD    red;
-        RGBQUAD    green;
-        RGBQUAD    blue;
-    };
-#endif
-};
-
-/*****************************************************************************
- * Prototypes from common.c
- *****************************************************************************/
-int  CommonInit(vout_display_t *);
-void CommonClean(vout_display_t *);
-void CommonManage(vout_display_t *);
-int  CommonControl(vout_display_t *, int , va_list );
-void CommonDisplay(vout_display_t *);
-int  CommonUpdatePicture(picture_t *, picture_t **, uint8_t *, unsigned);
-
-void UpdateRects (vout_display_t *,
-                  const vout_display_cfg_t *,
-                  const video_format_t *,
-                  bool is_forced);
-void AlignRect(RECT *, int align_boundary, int align_size);
-
-picture_pool_t *CommonPool(vout_display_t *, unsigned);
-
-/*****************************************************************************
- * Constants
- *****************************************************************************/
-#define IDM_TOGGLE_ON_TOP WM_USER + 1
-#define DX_POSITION_CHANGE 0x1000
-#define DX_WALLPAPER_CHANGE 0x2000
-#define DX_DESKTOP_CHANGE 0x4000
diff --git a/modules/video_output/msw/direct2d.c b/modules/video_output/msw/direct2d.c
deleted file mode 100644 (file)
index 277ce36..0000000
+++ /dev/null
@@ -1,419 +0,0 @@
-/*****************************************************************************
- * direct2d.c : Direct2D video output plugin for vlc (Win7/Vista SP2 PF Update)
- *****************************************************************************
- * Copyright (C) 2010 VideoLAN and AUTHORS
- * $Id$
- *
- * Author: David Kaplan <david@2of1.org>
- *
- * 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 Lesser General Public License for more details.
- *
- * 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.
- *****************************************************************************/
-
-/*****************************************************************************
- * Preamble
- *****************************************************************************/
-
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-#include <assert.h>
-
-#include <vlc_common.h>
-#include <vlc_plugin.h>
-#include <vlc_vout_display.h>
-
-#include <windows.h>
-#include <commctrl.h>
-#include <initguid.h>
-#include <d2d1.h>
-
-#include "common.h"
-
-
-/*****************************************************************************
- * Module descriptor
- *****************************************************************************/
-static int  Open (vlc_object_t *);
-static void Close(vlc_object_t *);
-
-#define D2D_HELP N_("Video output for Windows 7/Windows Vista with Platform update")
-
-vlc_module_begin ()
-    set_category(CAT_VIDEO)
-    set_subcategory(SUBCAT_VIDEO_VOUT)
-    set_help(D2D_HELP)
-    set_shortname("Direct2D")
-    set_description(N_("Direct2D video output"))
-    set_capability("vout display", 180)
-    add_shortcut("direct2d")
-    set_callbacks(Open, Close)
-vlc_module_end ()
-
-
-/*****************************************************************************
- * Local prototypes
- *****************************************************************************/
-static picture_pool_t *Pool  (vout_display_t *, unsigned);
-static void           Prepare(vout_display_t *, picture_t *, subpicture_t *);
-static void           Display(vout_display_t *, picture_t *, subpicture_t *);
-static int            Control(vout_display_t *, int, va_list);
-static void           Manage (vout_display_t *);
-
-static int      D2D_CreateRenderTarget(vout_display_t *vd);
-static void     D2D_ResizeRenderTarget(vout_display_t *vd);
-static void     D2D_DestroyRenderTarget(vout_display_t *vd);
-
-/**
- * Initialises Direct2D vout module
- */
-static int Open(vlc_object_t *object)
-{
-    vout_display_t *vd = (vout_display_t *)object;
-    vout_display_sys_t *sys;
-
-    vd->sys = sys = calloc(1, sizeof(*sys));
-    if (!sys)
-        return VLC_ENOMEM;
-
-    sys->d2_render_target = NULL;
-
-    sys->d2_dll = LoadLibrary(TEXT("D2D1.DLL"));
-    if (!sys->d2_dll) {
-        if (object->b_force)
-            msg_Err(vd, "Cannot load D2D1.DLL, aborting");
-        goto error;
-    }
-
-    D2D1_FACTORY_OPTIONS fo = {
-        D2D1_DEBUG_LEVEL_NONE
-    };
-
-    HRESULT (WINAPI *D2D1CreateFactory)(D2D1_FACTORY_TYPE, REFIID,
-                                        const D2D1_FACTORY_OPTIONS *,
-                                        void **);
-
-    D2D1CreateFactory = (void *)GetProcAddress(sys->d2_dll,
-                                               "D2D1CreateFactory");
-    if (!D2D1CreateFactory) {
-        msg_Err(vd,
-                "Cannot locate reference to a D2D1CreateFactory ABI in D2D1.DLL");
-        goto error;
-    }
-
-#ifndef NDEBUG
-    msg_Dbg(vd, "D2D1.DLL loaded");
-#endif
-
-    HRESULT hr = D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED,
-                                   (REFIID)&IID_ID2D1Factory,
-                                   &fo,
-                                   (void **)&sys->d2_factory);
-    if (hr != S_OK) {
-        msg_Err(vd, "Cannot create Direct2D factory (hr = 0x%x)!",
-                (unsigned)hr);
-        goto error;
-    }
-
-    if (CommonInit(vd))
-        goto error;
-
-    if (D2D_CreateRenderTarget(vd) != VLC_SUCCESS)
-        goto error;
-
-    vout_display_info_t info = vd->info;
-    info.is_slow              = false;
-    info.has_double_click     = true;
-    info.has_hide_mouse       = false;
-    info.has_pictures_invalid = false;
-    vd->info = info;
-
-    vd->fmt.i_chroma = VLC_CODEC_RGB32; /* masks change this to BGR32 for ID2D1Bitmap */
-    vd->fmt.i_rmask  = 0x0000ff00;
-    vd->fmt.i_gmask  = 0x00ff0000;
-    vd->fmt.i_bmask  = 0xff000000;
-
-    vd->pool    = Pool;
-    vd->prepare = Prepare;
-    vd->display = Display;
-    vd->manage  = Manage;
-    vd->control = Control;
-
-    EventThreadUpdateTitle(sys->event, VOUT_TITLE " (Direct2D output)");
-
-#ifndef NDEBUG
-    msg_Dbg(vd, "Ready");
-#endif
-
-    return VLC_SUCCESS;
-
-error:
-    Close(VLC_OBJECT(vd));
-    return VLC_EGENERIC;
-}
-
-/**
- * Close Direct2D vout
- */
-static void Close(vlc_object_t *object)
-{
-    vout_display_t *vd = (vout_display_t *)object;
-
-    D2D_DestroyRenderTarget(vd);
-
-    if (vd->sys->pool)
-        picture_pool_Release(vd->sys->pool);
-
-    CommonClean(vd);
-
-    if (vd->sys->d2_factory)
-        ID2D1Factory_Release(vd->sys->d2_factory);
-    if (vd->sys->d2_dll)
-        FreeLibrary(vd->sys->d2_dll);
-
-    free(vd->sys);
-}
-
-/**
- * Handles pool allocations for bitmaps
- */
-static picture_pool_t *Pool(vout_display_t *vd, unsigned count)
-{
-    vout_display_sys_t *sys = vd->sys;
-
-    if (!sys->pool) {
-        sys->pool = picture_pool_NewFromFormat(&vd->fmt, count);
-#ifndef NDEBUG
-        msg_Dbg(vd, "New picture pool created");
-#endif
-    }
-
-    return sys->pool;
-}
-
-/**
- * Performs set up of ID2D1Bitmap memory ready for blitting
- */
-static void Prepare(vout_display_t *vd, picture_t *picture, subpicture_t *subpicture)
-{
-    vout_display_sys_t *sys = vd->sys;
-
-    if (sys->d2_render_target && sys->d2_bitmap) {
-
-        HRESULT hr = ID2D1Bitmap_CopyFromMemory(sys->d2_bitmap,
-                                                NULL /*&r_src*/,
-                                                picture->p[0].p_pixels,
-                                                picture->p[0].i_pitch);
-        if (hr != S_OK)
-            msg_Err(vd, "Failed to copy bitmap memory (hr = 0x%x)!",
-                    (unsigned)hr);
-
-#ifndef NDEBUG
-        /*msg_Dbg(vd, "Bitmap dbg: target = %p, pitch = %d, bitmap = %p",
-                (void *)sys->d2_render_target, pitch, (void *)sys->d2_bitmap);*/
-#endif
-    }
-    VLC_UNUSED(subpicture);
-}
-
-/**
- * Blits a scaled picture_t to the render target
- */
-static void Display(vout_display_t *vd, picture_t *picture, subpicture_t *subpicture)
-{
-    vout_display_sys_t *sys = vd->sys;
-
-    D2D1_RECT_F r_dest = {
-        sys->rect_dest.left,
-        sys->rect_dest.top,
-        sys->rect_dest.right,
-        sys->rect_dest.bottom
-    };
-
-    if (sys->d2_render_target && sys->d2_bitmap) {
-        ID2D1HwndRenderTarget_BeginDraw(sys->d2_render_target);
-
-        ID2D1HwndRenderTarget_DrawBitmap(sys->d2_render_target,
-                                         sys->d2_bitmap,
-                                         &r_dest,
-                                         1.0f,
-                                         D2D1_BITMAP_INTERPOLATION_MODE_LINEAR,
-                                         NULL);
-
-        HRESULT hr = ID2D1HwndRenderTarget_EndDraw(sys->d2_render_target,
-                                                   NULL,
-                                                   NULL);
-        if (hr == D2DERR_RECREATE_TARGET) {
-            D2D_DestroyRenderTarget(vd);
-            D2D_CreateRenderTarget(vd);
-        }
-    }
-
-    picture_Release(picture);
-    VLC_UNUSED(subpicture);
-
-    CommonDisplay(vd);
-}
-
- /**
-  * Control event handler
-  */
-static int Control(vout_display_t *vd, int query, va_list args)
-{
-    return CommonControl(vd, query, args);
-}
-
-/**
- * Handles surface management
- * ID2D1RenderTargets cannot be resized and must be recreated
- */
-static void Manage(vout_display_t *vd)
-{
-    vout_display_sys_t *sys = vd->sys;
-
-    CommonManage(vd);
-
-    if (sys->changes & DX_POSITION_CHANGE) {
-        D2D_ResizeRenderTarget(vd);
-        sys->changes &= ~DX_POSITION_CHANGE;
-    }
-}
-
-/**
- * Creates a ID2D1HwndRenderTarget and associated ID2D1Bitmap
- */
-static int D2D_CreateRenderTarget(vout_display_t *vd)
-{
-    vout_display_sys_t *sys = vd->sys;
-
-    sys->d2_render_target = NULL;
-
-    D2D1_PIXEL_FORMAT pf = {
-        DXGI_FORMAT_B8G8R8A8_UNORM,
-        D2D1_ALPHA_MODE_IGNORE
-    };
-
-    D2D1_RENDER_TARGET_PROPERTIES rtp = {
-        D2D1_RENDER_TARGET_TYPE_DEFAULT,
-        pf,
-        0,
-        0,
-        D2D1_RENDER_TARGET_USAGE_NONE,
-        D2D1_FEATURE_LEVEL_DEFAULT
-    };
-
-    D2D1_SIZE_U size = {
-        sys->rect_dest.right - sys->rect_dest.left,
-        sys->rect_dest.bottom - sys->rect_dest.top
-    };
-
-    D2D1_HWND_RENDER_TARGET_PROPERTIES hrtp = {
-        sys->hvideownd,
-        size,
-        D2D1_PRESENT_OPTIONS_IMMEDIATELY /* this might need fiddling */
-    };
-
-    HRESULT hr  = ID2D1Factory_CreateHwndRenderTarget(sys->d2_factory,
-                                                      &rtp,
-                                                      &hrtp,
-                                                      &sys->d2_render_target);
-    if (hr != S_OK) {
-        msg_Err(vd, "Cannot create render target (hvideownd = 0x%x, width = %d, height = %d, pf.format = %d, hr = 0x%x)!",
-                (unsigned)hrtp.hwnd, hrtp.pixelSize.width,
-                hrtp.pixelSize.height, pf.format, (unsigned)hr);
-
-        sys->d2_render_target = NULL;
-
-        return VLC_EGENERIC;
-    }
-
-    FLOAT dpi_x, dpi_y;
-
-    ID2D1Factory_GetDesktopDpi(sys->d2_factory,
-                               &dpi_x,
-                               &dpi_y);
-
-    D2D1_BITMAP_PROPERTIES bp = {
-        pf,
-        dpi_x,
-        dpi_y
-    };
-
-    D2D1_SIZE_U bitmap_size = {
-        vd->fmt.i_visible_width,
-        vd->fmt.i_visible_height
-    };
-
-    hr = ID2D1HwndRenderTarget_CreateBitmap(sys->d2_render_target,
-                                            bitmap_size,
-                                            NULL,
-                                            0,
-                                            &bp,
-                                            &sys->d2_bitmap);
-    if (hr != S_OK) {
-        msg_Err(vd, "Failed to create bitmap (hr = 0x%x)!", (unsigned)hr);
-
-        sys->d2_bitmap = NULL;
-        D2D_DestroyRenderTarget(vd);
-
-        return VLC_EGENERIC;
-    }
-
-#ifndef NDEBUG
-    msg_Dbg(vd, "Render trgt dbg: dpi = %f, render_target = %p, bitmap = %p",
-            dpi_x, (void *)sys->d2_render_target, (void *)sys->d2_bitmap);
-#endif
-
-    return VLC_SUCCESS;
-}
-
-/**
- * Resizes a ID2D1HWndRenderTarget
- */
-static void D2D_ResizeRenderTarget(vout_display_t *vd)
-{
-    vout_display_sys_t *sys = vd->sys;
-
-    D2D1_SIZE_U size = {
-        sys->rect_dest.right - sys->rect_dest.left,
-        sys->rect_dest.bottom - sys->rect_dest.top
-    };
-
-    HRESULT hr  = ID2D1HwndRenderTarget_Resize(sys->d2_render_target, &size);
-    if (hr != S_OK)
-        msg_Err(vd, "Cannot resize render target (width = %d, height = %d, hr = 0x%x)!",
-                size.width, size.height, (unsigned)hr);
-}
-
-/**
- * Cleans up ID2D1HwndRenderTarget and ID2D1Bitmap
- */
-static void D2D_DestroyRenderTarget(vout_display_t *vd)
-{
-    vout_display_sys_t *sys = vd->sys;
-
-    if (sys->d2_render_target) {
-        ID2D1HwndRenderTarget_Release(sys->d2_render_target);
-        sys->d2_render_target = NULL;
-    }
-
-    if (sys->d2_bitmap) {
-        ID2D1Bitmap_Release(sys->d2_bitmap);
-        sys->d2_bitmap = NULL;
-    }
-
-#ifndef NDEBUG
-    msg_Dbg(vd, "Destroyed");
-#endif
-}
diff --git a/modules/video_output/msw/direct3d11.c b/modules/video_output/msw/direct3d11.c
deleted file mode 100644 (file)
index 417f4b8..0000000
+++ /dev/null
@@ -1,1768 +0,0 @@
-/*****************************************************************************
- * direct3d11.c: Windows Direct3D11 video output module
- *****************************************************************************
- * Copyright (C) 2014-2015 VLC authors and VideoLAN
- *
- * Authors: Martell Malone <martellmalone@gmail.com>
- *          Steve Lhomme <robux4@gmail.com>
- *
- * 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 Lesser General Public License for more details.
- *
- * 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.
- *****************************************************************************/
-
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#include <vlc_common.h>
-#include <vlc_plugin.h>
-#include <vlc_vout_display.h>
-
-#include <assert.h>
-
-#define COBJMACROS
-#define INITGUID
-#include <d3d11.h>
-
-/* avoided until we can pass ISwapchainPanel without c++/cx mode
-# include <windows.ui.xaml.media.dxinterop.h> */
-
-#include "common.h"
-
-#include "../../video_chroma/dxgi_fmt.h"
-
-#if !VLC_WINSTORE_APP
-# if USE_DXGI
-#  define D3D11CreateDeviceAndSwapChain(args...) sys->OurD3D11CreateDeviceAndSwapChain(args)
-# else
-#  define D3D11CreateDevice(args...)             sys->OurD3D11CreateDevice(args)
-# endif
-# define D3DCompile(args...)                    sys->OurD3DCompile(args)
-#endif
-
-DEFINE_GUID(GUID_SWAPCHAIN_WIDTH,  0xf1b59347, 0x1643, 0x411a, 0xad, 0x6b, 0xc7, 0x80, 0x17, 0x7a, 0x06, 0xb6);
-DEFINE_GUID(GUID_SWAPCHAIN_HEIGHT, 0x6ea976a0, 0x9d60, 0x4bb7, 0xa5, 0xa9, 0x7d, 0xd1, 0x18, 0x7f, 0xc9, 0xbd);
-
-static int  Open(vlc_object_t *);
-static void Close(vlc_object_t *);
-
-#define D3D11_HELP N_("Recommended video output for Windows 8 and later versions")
-#define HW_BLENDING_TEXT N_("Use hardware blending support")
-#define HW_BLENDING_LONGTEXT N_(\
-    "Try to use hardware acceleration for subtitle/OSD blending.")
-
-vlc_module_begin ()
-    set_shortname("Direct3D11")
-    set_description(N_("Direct3D11 video output"))
-    set_help(D3D11_HELP)
-    set_category(CAT_VIDEO)
-    set_subcategory(SUBCAT_VIDEO_VOUT)
-
-    add_bool("direct3d11-hw-blending", true, HW_BLENDING_TEXT, HW_BLENDING_LONGTEXT, true)
-
-#if VLC_WINSTORE_APP
-    add_integer("winrt-d3ddevice",     0x0, NULL, NULL, true); /* ID3D11Device*        */
-    add_integer("winrt-d3dcontext",    0x0, NULL, NULL, true); /* ID3D11DeviceContext* */
-    add_integer("winrt-swapchain",     0x0, NULL, NULL, true); /* IDXGISwapChain1*     */
-#endif
-
-    set_capability("vout display", 240)
-    add_shortcut("direct3d11")
-    set_callbacks(Open, Close)
-vlc_module_end ()
-
-#ifdef HAVE_ID3D11VIDEODECODER 
-/* VLC_CODEC_D3D11_OPAQUE */
-struct picture_sys_t
-{
-    ID3D11VideoDecoderOutputView  *decoder; /* may be NULL for pictures from the pool */
-    ID3D11Texture2D               *texture;
-    ID3D11DeviceContext           *context;
-};
-#endif
-
-/* internal picture_t pool  */
-typedef struct
-{
-    ID3D11Texture2D               *texture;
-    vout_display_t                *vd;
-} picture_sys_pool_t;
-
-/* matches the D3D11_INPUT_ELEMENT_DESC we setup */
-typedef struct d3d_vertex_t {
-    struct {
-        FLOAT x;
-        FLOAT y;
-        FLOAT z;
-    } position;
-    struct {
-        FLOAT x;
-        FLOAT y;
-    } texture;
-    FLOAT       opacity;
-} d3d_vertex_t;
-
-#define RECTWidth(r)   (int)((r).right - (r).left)
-#define RECTHeight(r)  (int)((r).bottom - (r).top)
-
-static picture_pool_t *Pool(vout_display_t *vd, unsigned count);
-
-static void Prepare(vout_display_t *, picture_t *, subpicture_t *subpicture);
-static void Display(vout_display_t *, picture_t *, subpicture_t *subpicture);
-
-static HINSTANCE Direct3D11LoadShaderLibrary(void);
-static void Direct3D11Destroy(vout_display_t *);
-
-static int  Direct3D11Open (vout_display_t *, video_format_t *);
-static void Direct3D11Close(vout_display_t *);
-
-static int  Direct3D11CreateResources (vout_display_t *, video_format_t *);
-static void Direct3D11DestroyResources(vout_display_t *);
-
-static int  Direct3D11CreatePool (vout_display_t *, video_format_t *);
-static void Direct3D11DestroyPool(vout_display_t *);
-
-static void DestroyDisplayPicture(picture_t *);
-static void DestroyDisplayPoolPicture(picture_t *);
-static int  Direct3D11MapTexture(picture_t *);
-static int  Direct3D11UnmapTexture(picture_t *);
-static void Direct3D11DeleteRegions(int, picture_t **);
-static int Direct3D11MapSubpicture(vout_display_t *, int *, picture_t ***, subpicture_t *);
-
-static int AllocQuad(vout_display_t *, const video_format_t *, d3d_quad_t *,
-                     d3d_quad_cfg_t *, ID3D11PixelShader *);
-static void ReleaseQuad(d3d_quad_t *);
-static void UpdatePicQuadPosition(vout_display_t *);
-static void UpdateQuadOpacity(vout_display_t *, const d3d_quad_t *, float);
-
-static void Manage(vout_display_t *vd);
-
-/* All the #if USE_DXGI contain an alternative method to setup dx11
-   They both need to be benchmarked to see which performs better */
-#if USE_DXGI
-/* I have no idea why MS decided dxgi headers do not define this
-   As they do have prototypes for d3d11 functions */
-typedef HRESULT(WINAPI *PFN_CREATE_DXGI_FACTORY)(REFIID riid, void **ppFactory);
-#endif
-
-/* TODO: Move to a direct3d11_shaders header */
-static const char* globVertexShaderDefault = "\
-  struct VS_INPUT\
-  {\
-    float4 Position   : POSITION;\
-    float2 Texture    : TEXCOORD0;\
-    float  Opacity    : OPACITY;\
-  };\
-  \
-  struct VS_OUTPUT\
-  {\
-    float4 Position   : SV_POSITION;\
-    float2 Texture    : TEXCOORD0;\
-    float  Opacity    : OPACITY;\
-  };\
-  \
-  VS_OUTPUT VS( VS_INPUT In )\
-  {\
-    VS_OUTPUT Output;\
-    Output.Position = float4(In.Position.xy, 0.0f, 1.0f);\
-    Output.Texture = In.Texture;\
-    Output.Opacity = In.Opacity;\
-    return Output;\
-  }\
-";
-
-static const char* globPixelShaderDefault = "\
-  Texture2D shaderTexture;\
-  SamplerState SampleType;\
-  \
-  struct PS_INPUT\
-  {\
-    float4 Position   : SV_POSITION;\
-    float2 Texture    : TEXCOORD0;\
-    float  Opacity    : OPACITY;\
-  };\
-  \
-  float4 PS( PS_INPUT In ) : SV_TARGET\
-  {\
-    float4 rgba; \
-    \
-    rgba = shaderTexture.Sample(SampleType, In.Texture);\
-    rgba.a = rgba.a * In.Opacity;\
-    return rgba; \
-  }\
-";
-
-static const char *globPixelShaderBiplanarI420_BT601_2RGB = "\
-  Texture2D shaderTextureY;\
-  Texture2D shaderTextureUV;\
-  SamplerState SampleType;\
-  \
-  struct PS_INPUT\
-  {\
-    float4 Position   : SV_POSITION;\
-    float2 Texture    : TEXCOORD0;\
-    float  Opacity    : OPACITY;\
-  };\
-  \
-  float4 PS( PS_INPUT In ) : SV_TARGET\
-  {\
-    float Y;\
-    float UCb;\
-    float VCr;\
-    float2 UCbPos;\
-    float2 VCrPos;\
-    float4 rgba;\
-    \
-    Y  = shaderTextureY.Sample(SampleType, In.Texture).x;\
-    \
-    VCrPos = In.Texture / 2;\
-    VCr = shaderTextureUV.Sample(SampleType, VCrPos).x;\
-    \
-    UCbPos = In.Texture / 2;\
-    UCbPos.y = UCbPos.y + 0.5;\
-    UCb = shaderTextureUV.Sample(SampleType, UCbPos).x;\
-    \
-    Y = 1.164383561643836 * (Y - 0.0625);\
-    UCb = UCb - 0.5;\
-    VCr = VCr - 0.5;\
-    \
-    rgba.x = saturate(Y + 1.596026785714286 * VCr);\
-    rgba.y = saturate(Y - 0.812967647237771 * VCr - 0.391762290094914 * UCb);\
-    rgba.z = saturate(Y + 2.017232142857142 * UCb);\
-    rgba.a = In.Opacity;\
-    return rgba;\
-  }\
-";
-
-static const char *globPixelShaderBiplanarI420_BT709_2RGB = "\
-  Texture2D shaderTextureY;\
-  Texture2D shaderTextureUV;\
-  SamplerState SampleType;\
-  \
-  struct PS_INPUT\
-  {\
-    float4 Position   : SV_POSITION;\
-    float2 Texture    : TEXCOORD0;\
-    float  Opacity    : OPACITY;\
-  };\
-  \
-  float4 PS( PS_INPUT In ) : SV_TARGET\
-  {\
-    float Y;\
-    float UCb;\
-    float VCr;\
-    float2 UCbPos;\
-    float2 VCrPos;\
-    float4 rgba;\
-    \
-    Y  = shaderTextureY.Sample(SampleType, In.Texture).x;\
-    \
-    VCrPos = In.Texture / 2;\
-    VCr = shaderTextureUV.Sample(SampleType, VCrPos).x;\
-    \
-    UCbPos = In.Texture / 2;\
-    UCbPos.y = UCbPos.y + 0.5;\
-    UCb = shaderTextureUV.Sample(SampleType, UCbPos).x;\
-    \
-    Y = 1.164383561643836 * (Y - 0.0625);\
-    UCb = UCb - 0.5;\
-    VCr = VCr - 0.5;\
-    \
-    rgba.x = saturate(Y + 1.792741071428571 * VCr);\
-    rgba.y = saturate(Y - 0.532909328559444 * VCr - 0.21324861427373 * UCb);\
-    rgba.z = saturate(Y + 2.112401785714286 * UCb);\
-    rgba.a = In.Opacity;\
-    return rgba;\
-  }\
-";
-
-static const char *globPixelShaderBiplanarYUV_BT601_2RGB = "\
-  Texture2D shaderTextureY;\
-  Texture2D shaderTextureUV;\
-  SamplerState SampleType;\
-  \
-  struct PS_INPUT\
-  {\
-    float4 Position   : SV_POSITION;\
-    float2 Texture    : TEXCOORD0;\
-    float  Opacity    : OPACITY;\
-  };\
-  \
-  float4 PS( PS_INPUT In ) : SV_TARGET\
-  {\
-    float3 yuv;\
-    float4 rgba;\
-    yuv.x  = shaderTextureY.Sample(SampleType, In.Texture).x;\
-    yuv.yz = shaderTextureUV.Sample(SampleType, In.Texture).xy;\
-    yuv.x  = 1.164383561643836 * (yuv.x-0.0625);\
-    yuv.y  = yuv.y - 0.5;\
-    yuv.z  = yuv.z - 0.5;\
-    rgba.x = saturate(yuv.x + 1.596026785714286 * yuv.z);\
-    rgba.y = saturate(yuv.x - 0.812967647237771 * yuv.z - 0.391762290094914 * yuv.y);\
-    rgba.z = saturate(yuv.x + 2.017232142857142 * yuv.y);\
-    rgba.a = In.Opacity;\
-    return rgba;\
-  }\
-";
-
-static const char *globPixelShaderBiplanarYUV_BT709_2RGB = "\
-  Texture2D shaderTextureY;\
-  Texture2D shaderTextureUV;\
-  SamplerState SampleType;\
-  \
-  struct PS_INPUT\
-  {\
-    float4 Position   : SV_POSITION;\
-    float2 Texture    : TEXCOORD0;\
-    float  Opacity    : OPACITY;\
-  };\
-  \
-  float4 PS( PS_INPUT In ) : SV_TARGET\
-  {\
-    float3 yuv;\
-    float4 rgba;\
-    yuv.x  = shaderTextureY.Sample(SampleType, In.Texture).x;\
-    yuv.yz = shaderTextureUV.Sample(SampleType, In.Texture).xy;\
-    yuv.x  = 1.164383561643836 * (yuv.x-0.0625);\
-    yuv.y  = yuv.y - 0.5;\
-    yuv.z  = yuv.z - 0.5;\
-    rgba.x = saturate(yuv.x + 1.792741071428571 * yuv.z);\
-    rgba.y = saturate(yuv.x - 0.532909328559444 * yuv.z - 0.21324861427373 * yuv.y);\
-    rgba.z = saturate(yuv.x + 2.112401785714286 * yuv.y);\
-    rgba.a = In.Opacity;\
-    return rgba;\
-  }\
-";
-
-static int Open(vlc_object_t *object)
-{
-    vout_display_t *vd = (vout_display_t *)object;
-
-#if !VLC_WINSTORE_APP
-    HINSTANCE hd3d11_dll = LoadLibrary(TEXT("D3D11.DLL"));
-    if (!hd3d11_dll) {
-        msg_Warn(vd, "cannot load d3d11.dll, aborting");
-        return VLC_EGENERIC;
-    }
-
-    HINSTANCE hd3dcompiler_dll = Direct3D11LoadShaderLibrary();
-    if (!hd3dcompiler_dll) {
-        msg_Err(vd, "cannot load d3dcompiler.dll, aborting");
-        FreeLibrary(hd3d11_dll);
-        return VLC_EGENERIC;
-    }
-
-# if USE_DXGI
-    HINSTANCE hdxgi_dll = LoadLibrary(TEXT("DXGI.DLL"));
-    if (!hdxgi_dll) {
-        msg_Warn(vd, "cannot load dxgi.dll, aborting");
-        return VLC_EGENERIC;
-    }
-# endif
-
-#else
-    IDXGISwapChain1* dxgiswapChain  = var_InheritInteger(vd, "winrt-swapchain");
-    if (!dxgiswapChain)
-        return VLC_EGENERIC;
-    ID3D11Device* d3ddevice         = var_InheritInteger(vd, "winrt-d3ddevice");
-    if (!d3ddevice)
-        return VLC_EGENERIC;
-    ID3D11DeviceContext* d3dcontext = var_InheritInteger(vd, "winrt-d3dcontext");
-    if (!d3dcontext)
-        return VLC_EGENERIC;
-#endif
-
-    vout_display_sys_t *sys = vd->sys = calloc(1, sizeof(vout_display_sys_t));
-    if (!sys)
-        return VLC_ENOMEM;
-
-#if !VLC_WINSTORE_APP
-    sys->hd3d11_dll       = hd3d11_dll;
-    sys->hd3dcompiler_dll = hd3dcompiler_dll;
-
-    sys->OurD3DCompile = (void *)GetProcAddress(sys->hd3dcompiler_dll, "D3DCompile");
-    if (!sys->OurD3DCompile) {
-        msg_Err(vd, "Cannot locate reference to D3DCompile in d3dcompiler DLL");
-        Direct3D11Destroy(vd);
-        return VLC_EGENERIC;
-    }
-
-# if USE_DXGI
-    sys->hdxgi_dll = hdxgi_dll;
-
-    /* TODO : enable all dxgi versions from 1.3 -> 1.1 */
-    PFN_CREATE_DXGI_FACTORY OurCreateDXGIFactory =
-        (void *)GetProcAddress(sys->hdxgi_dll, "CreateDXGIFactory");
-    if (!OurCreateDXGIFactory) {
-        msg_Err(vd, "Cannot locate reference to CreateDXGIFactory in dxgi DLL");
-        Direct3D11Destroy(vd);
-        return VLC_EGENERIC;
-    }
-
-    UINT i_factory_flags = 0;
-#ifndef NDEBUG
-    i_factory_flags |= DXGI_CREATE_FACTORY_DEBUG;
-#endif
-
-    /* TODO : detect the directx version supported and use IID_IDXGIFactory3 or 2 */
-    HRESULT hr = OurCreateDXGIFactory(&IID_IDXGIFactory2, (void **)&sys->dxgifactory);
-    if (FAILED(hr)) {
-        msg_Err(vd, "Could not create dxgi factory. (hr=0x%lX)", hr);
-        Direct3D11Destroy(vd);
-        return VLC_EGENERIC;
-    }
-
-    sys->OurD3D11CreateDeviceAndSwapChain =
-        (void *)GetProcAddress(sys->hd3d11_dll, "D3D11CreateDeviceAndSwapChain");
-    if (!sys->OurD3D11CreateDeviceAndSwapChain) {
-        msg_Err(vd, "Cannot locate reference to D3D11CreateDeviceAndSwapChain in d3d11 DLL");
-        Direct3D11Destroy(vd);
-        return VLC_EGENERIC;
-    }
-
-# else
-    sys->OurD3D11CreateDevice =
-        (void *)GetProcAddress(sys->hd3d11_dll, "D3D11CreateDevice");
-    if (!sys->OurD3D11CreateDevice) {
-        msg_Err(vd, "Cannot locate reference to D3D11CreateDevice in d3d11 DLL");
-        Direct3D11Destroy(vd);
-        return VLC_EGENERIC;
-    }
-# endif
-
-#else
-    sys->dxgiswapChain = dxgiswapChain;
-    sys->d3ddevice     = d3ddevice;
-    sys->d3dcontext    = d3dcontext;
-    IDXGISwapChain_AddRef     (sys->dxgiswapChain);
-    ID3D11Device_AddRef       (sys->d3ddevice);
-    ID3D11DeviceContext_AddRef(sys->d3dcontext);
-#endif
-
-    if (CommonInit(vd))
-        goto error;
-
-    video_format_t fmt;
-    if (Direct3D11Open(vd, &fmt)) {
-        msg_Err(vd, "Direct3D11 could not be opened");
-        goto error;
-    }
-
-    vout_display_info_t info  = vd->info;
-    info.is_slow              = fmt.i_chroma != VLC_CODEC_D3D11_OPAQUE;
-    info.has_double_click     = true;
-    info.has_hide_mouse       = false;
-    info.has_event_thread     = true;
-    info.has_pictures_invalid = fmt.i_chroma != VLC_CODEC_D3D11_OPAQUE;
-
-    if (var_InheritBool(vd, "direct3d11-hw-blending") &&
-        sys->d3dregion_format != DXGI_FORMAT_UNKNOWN)
-        info.subpicture_chromas = sys->pSubpictureChromas;
-    else
-        info.subpicture_chromas = NULL;
-
-    video_format_Clean(&vd->fmt);
-    video_format_Copy(&vd->fmt, &fmt);
-    vd->info = info;
-
-    vd->pool    = Pool;
-    vd->prepare = Prepare;
-    vd->display = Display;
-    vd->control = CommonControl;
-    vd->manage  = Manage;
-
-    msg_Dbg(vd, "Direct3D11 Open Succeeded");
-
-    return VLC_SUCCESS;
-error:
-    Direct3D11Close(vd);
-    CommonClean(vd);
-    Direct3D11Destroy(vd);
-    free(vd->sys);
-    return VLC_EGENERIC;
-}
-
-static void Close(vlc_object_t *object)
-{
-    vout_display_t * vd = (vout_display_t *)object;
-
-    Direct3D11Close(vd);
-    CommonClean(vd);
-    Direct3D11Destroy(vd);
-    free(vd->sys);
-}
-
-static picture_pool_t *Pool(vout_display_t *vd, unsigned pool_size)
-{
-    if ( vd->sys->pool != NULL )
-        return vd->sys->pool;
-
-#ifdef HAVE_ID3D11VIDEODECODER 
-    picture_t**       pictures = NULL;
-    unsigned          picture_count = 0;
-    HRESULT           hr;
-
-    ID3D10Multithread *pMultithread;
-    hr = ID3D11Device_QueryInterface( vd->sys->d3ddevice, &IID_ID3D10Multithread, (void **)&pMultithread);
-    if (SUCCEEDED(hr)) {
-        ID3D10Multithread_SetMultithreadProtected(pMultithread, TRUE);
-        ID3D10Multithread_Release(pMultithread);
-    }
-
-    pictures = calloc(pool_size, sizeof(*pictures));
-    if (!pictures)
-        goto error;
-
-    D3D11_TEXTURE2D_DESC texDesc;
-    ZeroMemory(&texDesc, sizeof(texDesc));
-    texDesc.Width = vd->fmt.i_width;
-    texDesc.Height = vd->fmt.i_height;
-    texDesc.MipLevels = 1;
-    texDesc.Format = vd->sys->picQuadConfig.textureFormat;
-    texDesc.SampleDesc.Count = 1;
-    texDesc.MiscFlags = 0; //D3D11_RESOURCE_MISC_SHARED;
-    texDesc.ArraySize = 1;
-    texDesc.Usage = D3D11_USAGE_DYNAMIC;
-    texDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
-    texDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
-
-    for (picture_count = 0; picture_count < pool_size; picture_count++) {
-        picture_sys_t *picsys = calloc(1, sizeof(*picsys));
-        if (unlikely(picsys == NULL))
-            goto error;
-
-        hr = ID3D11Device_CreateTexture2D( vd->sys->d3ddevice, &texDesc, NULL, &picsys->texture );
-        if (FAILED(hr)) {
-            msg_Err(vd, "CreateTexture2D %d failed on picture %d of the pool. (hr=0x%0lx)", pool_size, picture_count, hr);
-            goto error;
-        }
-
-        picsys->context = vd->sys->d3dcontext;
-
-        picture_resource_t resource = {
-            .p_sys = picsys,
-            .pf_destroy = DestroyDisplayPoolPicture,
-        };
-
-        picture_t *picture = picture_NewFromResource(&vd->fmt, &resource);
-        if (unlikely(picture == NULL)) {
-            free(picsys);
-            msg_Err( vd, "Failed to create picture %d in the pool.", picture_count );
-            goto error;
-        }
-
-        pictures[picture_count] = picture;
-        /* each picture_t holds a ref to the context and release it on Destroy */
-        ID3D11DeviceContext_AddRef(picsys->context);
-    }
-    msg_Dbg(vd, "ID3D11VideoDecoderOutputView succeed with %d surfaces (%dx%d)",
-            pool_size, vd->fmt.i_width, vd->fmt.i_height);
-
-    picture_pool_configuration_t pool_cfg;
-    memset(&pool_cfg, 0, sizeof(pool_cfg));
-    pool_cfg.picture_count = pool_size;
-    pool_cfg.picture       = pictures;
-
-    vd->sys->pool = picture_pool_NewExtended( &pool_cfg );
-
-error:
-    if (vd->sys->pool ==NULL && pictures) {
-        msg_Dbg(vd, "Failed to create the picture d3d11 pool");
-        for (unsigned i=0;i<picture_count; ++i)
-            DestroyDisplayPoolPicture(pictures[i]);
-        free(pictures);
-
-        /* create an empty pool to avoid crashing */
-        picture_pool_configuration_t pool_cfg;
-        memset( &pool_cfg, 0, sizeof( pool_cfg ) );
-        pool_cfg.picture_count = 0;
-
-        vd->sys->pool = picture_pool_NewExtended( &pool_cfg );
-    }
-#endif
-    return vd->sys->pool;
-}
-
-#ifdef HAVE_ID3D11VIDEODECODER 
-static void DestroyDisplayPoolPicture(picture_t *picture)
-{
-    picture_sys_t *p_sys = (picture_sys_t*) picture->p_sys;
-
-    if (p_sys->texture)
-        ID3D11Texture2D_Release(p_sys->texture);
-
-    free(p_sys);
-    free(picture);
-}
-#endif
-
-static void DestroyDisplayPicture(picture_t *picture)
-{
-    picture_sys_pool_t *p_sys = (picture_sys_pool_t*) picture->p_sys;
-
-    if (p_sys->texture)
-        ID3D11Texture2D_Release(p_sys->texture);
-
-    free(p_sys);
-    free(picture);
-}
-
-static HRESULT UpdateBackBuffer(vout_display_t *vd)
-{
-    vout_display_sys_t *sys = vd->sys;
-    HRESULT hr;
-    ID3D11Texture2D* pDepthStencil;
-    ID3D11Texture2D* pBackBuffer;
-    uint32_t i_width  = RECTWidth(sys->rect_dest_clipped);
-    uint32_t i_height = RECTHeight(sys->rect_dest_clipped);
-#if VLC_WINSTORE_APP
-    UINT dataSize = sizeof(i_width);
-    hr = IDXGISwapChain_GetPrivateData(sys->dxgiswapChain, &GUID_SWAPCHAIN_WIDTH, &dataSize, &i_width);
-    if (FAILED(hr)) {
-        msg_Err(vd, "Can't get swapchain width, size %d. (hr=0x%lX)", hr, dataSize);
-        return hr;
-    }
-    dataSize = sizeof(i_height);
-    hr = IDXGISwapChain_GetPrivateData(sys->dxgiswapChain, &GUID_SWAPCHAIN_HEIGHT, &dataSize, &i_height);
-    if (FAILED(hr)) {
-        msg_Err(vd, "Can't get swapchain height, size %d. (hr=0x%lX)", hr, dataSize);
-        return hr;
-    }
-#endif
-
-    if (sys->d3drenderTargetView) {
-        ID3D11RenderTargetView_Release(sys->d3drenderTargetView);
-        sys->d3drenderTargetView = NULL;
-    }
-    if (sys->d3ddepthStencilView) {
-        ID3D11DepthStencilView_Release(sys->d3ddepthStencilView);
-        sys->d3ddepthStencilView = NULL;
-    }
-
-    hr = IDXGISwapChain_ResizeBuffers(sys->dxgiswapChain, 0, i_width, i_height,
-        DXGI_FORMAT_UNKNOWN, 0);
-    if (FAILED(hr)) {
-       msg_Err(vd, "Failed to resize the backbuffer. (hr=0x%lX)", hr);
-       return hr;
-    }
-
-    hr = IDXGISwapChain_GetBuffer(sys->dxgiswapChain, 0, &IID_ID3D11Texture2D, (LPVOID *)&pBackBuffer);
-    if (FAILED(hr)) {
-       msg_Err(vd, "Could not get the backbuffer for the Swapchain. (hr=0x%lX)", hr);
-       return hr;
-    }
-
-    hr = ID3D11Device_CreateRenderTargetView(sys->d3ddevice, (ID3D11Resource *)pBackBuffer, NULL, &sys->d3drenderTargetView);
-    ID3D11Texture2D_Release(pBackBuffer);
-    if (FAILED(hr)) {
-        msg_Err(vd, "Failed to create the target view. (hr=0x%lX)", hr);
-        return hr;
-    }
-
-    D3D11_TEXTURE2D_DESC deptTexDesc;
-    memset(&deptTexDesc, 0,sizeof(deptTexDesc));
-    deptTexDesc.ArraySize = 1;
-    deptTexDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
-    deptTexDesc.CPUAccessFlags = 0;
-    deptTexDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
-    deptTexDesc.Width = i_width;
-    deptTexDesc.Height = i_height;
-    deptTexDesc.MipLevels = 1;
-    deptTexDesc.MiscFlags = 0;
-    deptTexDesc.SampleDesc.Count = 1;
-    deptTexDesc.SampleDesc.Quality = 0;
-    deptTexDesc.Usage = D3D11_USAGE_DEFAULT;
-
-    hr = ID3D11Device_CreateTexture2D(sys->d3ddevice, &deptTexDesc, NULL, &pDepthStencil);
-    if (FAILED(hr)) {
-       msg_Err(vd, "Could not create the depth stencil texture. (hr=0x%lX)", hr);
-       return hr;
-    }
-
-    D3D11_DEPTH_STENCIL_VIEW_DESC depthViewDesc;
-    memset(&depthViewDesc, 0, sizeof(depthViewDesc));
-
-    depthViewDesc.Format = deptTexDesc.Format;
-    depthViewDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
-    depthViewDesc.Texture2D.MipSlice = 0;
-
-    hr = ID3D11Device_CreateDepthStencilView(sys->d3ddevice, (ID3D11Resource *)pDepthStencil, &depthViewDesc, &sys->d3ddepthStencilView);
-    ID3D11Texture2D_Release(pDepthStencil);
-
-    if (FAILED(hr)) {
-       msg_Err(vd, "Could not create the depth stencil view. (hr=0x%lX)", hr);
-       return hr;
-    }
-
-    return S_OK;
-}
-
-static void Manage(vout_display_t *vd)
-{
-    vout_display_sys_t *sys = vd->sys;
-    RECT size_before = sys->rect_dest_clipped;
-
-    CommonManage(vd);
-
-    if (RECTWidth(size_before)  != RECTWidth(sys->rect_dest_clipped) ||
-        RECTHeight(size_before) != RECTHeight(sys->rect_dest_clipped))
-    {
-        msg_Dbg(vd, "Manage detected size change %dx%d", RECTWidth(sys->rect_dest_clipped),
-                RECTHeight(sys->rect_dest_clipped));
-
-        UpdateBackBuffer(vd);
-
-        UpdatePicQuadPosition(vd);
-    }
-}
-
-static void Prepare(vout_display_t *vd, picture_t *picture, subpicture_t *subpicture)
-{
-    vout_display_sys_t *sys = vd->sys;
-
-#ifdef HAVE_ID3D11VIDEODECODER 
-    if (picture->format.i_chroma == VLC_CODEC_D3D11_OPAQUE) {
-        D3D11_BOX box;
-        box.left = 0;
-        box.right = picture->format.i_visible_width;
-        box.top = 0;
-        box.bottom = picture->format.i_visible_height;
-        box.back = 1;
-        box.front = 0;
-
-        picture_sys_t *p_sys = picture->p_sys;
-        ID3D11DeviceContext_CopySubresourceRegion(sys->d3dcontext,
-                                                  (ID3D11Resource*) sys->picQuad.pTexture,
-                                                  0, 0, 0, 0,
-                                                  (ID3D11Resource*) p_sys->texture,
-                                                  0, &box);
-    }
-#endif
-
-    if (subpicture) {
-        int subpicture_region_count    = 0;
-        picture_t **subpicture_regions = NULL;
-        Direct3D11MapSubpicture(vd, &subpicture_region_count, &subpicture_regions, subpicture);
-        Direct3D11DeleteRegions(sys->d3dregion_count, sys->d3dregions);
-        sys->d3dregion_count = subpicture_region_count;
-        sys->d3dregions      = subpicture_regions;
-    }
-}
-
-static void DisplayD3DPicture(vout_display_sys_t *sys, d3d_quad_t *quad)
-{
-    UINT stride = sizeof(d3d_vertex_t);
-    UINT offset = 0;
-
-    /* Render the quad */
-    ID3D11DeviceContext_RSSetViewports(sys->d3dcontext, 1, &quad->cropViewport);
-    ID3D11DeviceContext_PSSetShader(sys->d3dcontext, quad->d3dpixelShader, NULL, 0);
-    ID3D11DeviceContext_PSSetShaderResources(sys->d3dcontext, 0, 1, &quad->d3dresViewY);
-
-    if( quad->d3dresViewUV )
-        ID3D11DeviceContext_PSSetShaderResources(sys->d3dcontext, 1, 1, &quad->d3dresViewUV);
-
-    ID3D11DeviceContext_IASetVertexBuffers(sys->d3dcontext, 0, 1, &quad->pVertexBuffer, &stride, &offset);
-    ID3D11DeviceContext_DrawIndexed(sys->d3dcontext, 6, 0, 0);
-}
-
-static void Display(vout_display_t *vd, picture_t *picture, subpicture_t *subpicture)
-{
-    vout_display_sys_t *sys = vd->sys;
-
-    FLOAT blackRGBA[4] = {0.0f, 0.0f, 0.0f, 1.0f};
-    ID3D11DeviceContext_ClearRenderTargetView(sys->d3dcontext, sys->d3drenderTargetView, blackRGBA);
-
-    /* no ID3D11Device operations should come here */
-
-    ID3D11DeviceContext_OMSetRenderTargets(sys->d3dcontext, 1, &sys->d3drenderTargetView, sys->d3ddepthStencilView);
-
-    ID3D11DeviceContext_ClearDepthStencilView(sys->d3dcontext, sys->d3ddepthStencilView, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0);
-
-    if (picture->format.i_chroma != VLC_CODEC_D3D11_OPAQUE)
-        Direct3D11UnmapTexture(picture);
-
-    /* Render the quad */
-    DisplayD3DPicture(sys, &sys->picQuad);
-
-    if (subpicture) {
-        // draw the additional vertices
-        for (int i = 0; i < sys->d3dregion_count; ++i) {
-            DisplayD3DPicture(sys, (d3d_quad_t *) sys->d3dregions[i]->p_sys);
-        }
-    }
-
-    DXGI_PRESENT_PARAMETERS presentParams;
-    memset(&presentParams, 0, sizeof(presentParams));
-    HRESULT hr = IDXGISwapChain1_Present1(sys->dxgiswapChain, 0, 0, &presentParams);
-    if (hr == DXGI_ERROR_DEVICE_REMOVED || hr == DXGI_ERROR_DEVICE_RESET)
-    {
-        /* TODO device lost */
-    }
-
-    picture_Release(picture);
-    if (subpicture)
-        subpicture_Delete(subpicture);
-
-    CommonDisplay(vd);
-}
-
-static void Direct3D11Destroy(vout_display_t *vd)
-{
-#if !VLC_WINSTORE_APP
-    vout_display_sys_t *sys = vd->sys;
-
-# if USE_DXGI
-    if (sys->hdxgi_dll)
-        FreeLibrary(sys->hdxgi_dll);
-# endif
-
-    if (sys->hd3d11_dll)
-        FreeLibrary(sys->hd3d11_dll);
-    if (sys->hd3dcompiler_dll)
-        FreeLibrary(sys->hd3dcompiler_dll);
-
-    /* TODO : add release of d3d11 objects here */
-
-    sys->OurD3D11CreateDevice = NULL;
-    sys->OurD3D11CreateDeviceAndSwapChain = NULL;
-    sys->OurD3DCompile = NULL;
-    sys->hdxgi_dll = NULL;
-    sys->hd3d11_dll = NULL;
-    sys->hd3dcompiler_dll = NULL;
-#else
-    VLC_UNUSED(vd);
-#endif
-}
-
-#if !VLC_WINSTORE_APP
-static HINSTANCE Direct3D11LoadShaderLibrary(void)
-{
-    HINSTANCE instance = NULL;
-    /* d3dcompiler_47 is the latest on windows 8.1 */
-    for (int i = 47; i > 41; --i) {
-        TCHAR filename[19];
-        _sntprintf(filename, 19, TEXT("D3DCOMPILER_%d.dll"), i);
-        instance = LoadLibrary(filename);
-        if (instance) break;
-    }
-    return instance;
-}
-#endif
-
-
-static int Direct3D11Open(vout_display_t *vd, video_format_t *fmt)
-{
-    vout_display_sys_t *sys = vd->sys;
-    *fmt = vd->source;
-
-#if !VLC_WINSTORE_APP
-
-    UINT creationFlags = 0;
-    HRESULT hr = S_OK;
-
-# if !defined(NDEBUG) && defined(_MSC_VER)
-    creationFlags |= D3D11_CREATE_DEVICE_DEBUG;
-# endif
-
-    DXGI_SWAP_CHAIN_DESC1 scd;
-    memset(&scd, 0, sizeof(scd));
-    scd.BufferCount = 2;
-    scd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
-    scd.SampleDesc.Count = 1;
-    scd.SampleDesc.Quality = 0;
-    scd.Width = fmt->i_visible_width;
-    scd.Height = fmt->i_visible_height;
-    scd.Format = DXGI_FORMAT_R8G8B8A8_UNORM; /* TODO: use DXGI_FORMAT_NV12 */
-    //scd.Flags = 512; // DXGI_SWAP_CHAIN_FLAG_YUV_VIDEO;
-    scd.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL;
-
-    IDXGIAdapter *dxgiadapter;
-    static const D3D_FEATURE_LEVEL featureLevels[] =
-    {
-        0xc000 /* D3D_FEATURE_LEVEL_12_1 */,
-        0xc100 /* D3D_FEATURE_LEVEL_12_0 */,
-        D3D_FEATURE_LEVEL_11_1,
-        D3D_FEATURE_LEVEL_11_0,
-        D3D_FEATURE_LEVEL_10_1,
-        D3D_FEATURE_LEVEL_10_0,
-        D3D_FEATURE_LEVEL_9_3,
-        D3D_FEATURE_LEVEL_9_2,
-        D3D_FEATURE_LEVEL_9_1,
-    };
-
-# if USE_DXGI
-    /* TODO : list adapters for the user to choose from */
-    hr = IDXGIFactory2_EnumAdapters(sys->dxgifactory, 0, &dxgiadapter);
-    if (FAILED(hr)) {
-       msg_Err(vd, "Could not create find factory. (hr=0x%lX)", hr);
-       return VLC_EGENERIC;
-    }
-
-    IDXGIOutput* output;
-    hr = IDXGIAdapter_EnumOutputs(dxgiadapter, 0, &output);
-    if (FAILED(hr)) {
-       msg_Err(vd, "Could not Enumerate DXGI Outputs. (hr=0x%lX)", hr);
-       IDXGIAdapter_Release(dxgiadapter);
-       return VLC_EGENERIC;
-    }
-
-    DXGI_MODE_DESC md;
-    memset(&md, 0, sizeof(md));
-    md.Width  = fmt->i_visible_width;
-    md.Height = fmt->i_visible_height;
-    md.Format = scd.BufferDesc.Format;
-    md.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
-
-    hr = IDXGIOutput_FindClosestMatchingMode(output, &md, &scd.BufferDesc, NULL);
-    if (FAILED(hr)) {
-       msg_Err(vd, "Failed to find a supported video mode. (hr=0x%lX)", hr);
-       IDXGIAdapter_Release(dxgiadapter);
-       return VLC_EGENERIC;
-    }
-
-    /* mode desc doesn't carry over the width and height*/
-    scd.BufferDesc.Width = fmt->i_visible_width;
-    scd.BufferDesc.Height = fmt->i_visible_height;
-
-    hr = D3D11CreateDeviceAndSwapChain(dxgiadapter,
-                    D3D_DRIVER_TYPE_UNKNOWN, NULL, creationFlags,
-                    featureLevels, ARRAYSIZE(featureLevels),
-                    D3D11_SDK_VERSION, &scd, &sys->dxgiswapChain,
-                    &sys->d3ddevice, NULL, &sys->d3dcontext);
-    IDXGIAdapter_Release(dxgiadapter);
-    if (FAILED(hr)) {
-       msg_Err(vd, "Could not Create the D3D11 device and SwapChain. (hr=0x%lX)", hr);
-       return VLC_EGENERIC;
-    }
-
-# else
-
-    static const D3D_DRIVER_TYPE driverAttempts[] = {
-        D3D_DRIVER_TYPE_HARDWARE,
-        D3D_DRIVER_TYPE_WARP,
-#ifndef NDEBUG
-        D3D_DRIVER_TYPE_REFERENCE,
-#endif
-    };
-
-    for (UINT driver = 0; driver < ARRAYSIZE(driverAttempts); driver++) {
-        D3D_FEATURE_LEVEL i_feature_level;
-        hr = D3D11CreateDevice(NULL, driverAttempts[driver], NULL, creationFlags,
-                    featureLevels, 9, D3D11_SDK_VERSION,
-                    &sys->d3ddevice, &i_feature_level, &sys->d3dcontext);
-        if (SUCCEEDED(hr)) {
-#ifndef NDEBUG
-            msg_Dbg(vd, "Created the D3D11 device 0x%p ctx 0x%p type %d level %d.",
-                    (void *)sys->d3ddevice, (void *)sys->d3dcontext,
-                    driverAttempts[driver], i_feature_level);
-#endif
-            break;
-        }
-    }
-
-    if (FAILED(hr)) {
-       msg_Err(vd, "Could not Create the D3D11 device. (hr=0x%lX)", hr);
-       return VLC_EGENERIC;
-    }
-
-    IDXGIDevice *pDXGIDevice = NULL;
-    hr = ID3D11Device_QueryInterface(sys->d3ddevice, &IID_IDXGIDevice, (void **)&pDXGIDevice);
-    if (FAILED(hr)) {
-       msg_Err(vd, "Could not Query DXGI Interface. (hr=0x%lX)", hr);
-       return VLC_EGENERIC;
-    }
-
-    hr = IDXGIDevice_GetAdapter(pDXGIDevice, &dxgiadapter);
-    IDXGIAdapter_Release(pDXGIDevice);
-    if (FAILED(hr)) {
-       msg_Err(vd, "Could not get the DXGI Adapter. (hr=0x%lX)", hr);
-       return VLC_EGENERIC;
-    }
-
-    hr = IDXGIAdapter_GetParent(dxgiadapter, &IID_IDXGIFactory2, (void **)&sys->dxgifactory);
-    IDXGIAdapter_Release(dxgiadapter);
-    if (FAILED(hr)) {
-       msg_Err(vd, "Could not get the DXGI Factory. (hr=0x%lX)", hr);
-       return VLC_EGENERIC;
-    }
-
-    hr = IDXGIFactory2_CreateSwapChainForHwnd(sys->dxgifactory, (IUnknown *)sys->d3ddevice,
-                                              sys->hvideownd, &scd, NULL, NULL, &sys->dxgiswapChain);
-    IDXGIFactory2_Release(sys->dxgifactory);
-    if (FAILED(hr)) {
-       msg_Err(vd, "Could not create the SwapChain. (hr=0x%lX)", hr);
-       return VLC_EGENERIC;
-    }
-
-# endif
-#endif
-
-    vlc_fourcc_t i_src_chroma = fmt->i_chroma;
-    fmt->i_chroma = 0;
-
-    // look for the request pixel format first
-    UINT i_quadSupportFlags = D3D11_FORMAT_SUPPORT_TEXTURE2D | D3D11_FORMAT_SUPPORT_SHADER_LOAD;
-    UINT i_formatSupport;
-    for (const d3d_format_t *output_format = GetRenderFormatList();
-         output_format->name != NULL; ++output_format)
-    {
-        if( i_src_chroma == output_format->fourcc)
-        {
-            if( SUCCEEDED( ID3D11Device_CheckFormatSupport(sys->d3ddevice,
-                                                           output_format->formatTexture,
-                                                           &i_formatSupport)) &&
-                    ( i_formatSupport & i_quadSupportFlags ) == i_quadSupportFlags )
-            {
-                msg_Dbg(vd, "Using pixel format %s with chroma %4.4s for source %4.4s", output_format->name, (char *)&output_format->fourcc, (char *)&i_src_chroma );
-                fmt->i_chroma = output_format->fourcc;
-                sys->picQuadConfig.textureFormat      = output_format->formatTexture;
-                sys->picQuadConfig.resourceFormatYRGB = output_format->formatY;
-                sys->picQuadConfig.resourceFormatUV   = output_format->formatUV;
-                break;
-            }
-        }
-    }
-
-    // look for any pixel format that we can handle
-    if ( !fmt->i_chroma )
-    {
-        for (const d3d_format_t *output_format = GetRenderFormatList();
-             output_format->name != NULL; ++output_format)
-        {
-            if( SUCCEEDED( ID3D11Device_CheckFormatSupport(sys->d3ddevice,
-                                                           output_format->formatTexture,
-                                                           &i_formatSupport)) &&
-                    ( i_formatSupport & i_quadSupportFlags ) == i_quadSupportFlags )
-            {
-                msg_Dbg(vd, "Using pixel format %s for chroma %4.4s", output_format->name, (char *)&output_format->fourcc );
-                fmt->i_chroma = output_format->fourcc;
-                sys->picQuadConfig.textureFormat      = output_format->formatTexture;
-                sys->picQuadConfig.resourceFormatYRGB = output_format->formatY;
-                sys->picQuadConfig.resourceFormatUV   = output_format->formatUV;
-                break;
-            }
-        }
-    }
-    if ( !fmt->i_chroma )
-    {
-       msg_Err(vd, "Could not get a suitable texture pixel format");
-       return VLC_EGENERIC;
-    }
-
-    /* check the region pixel format */
-    i_quadSupportFlags |= D3D11_FORMAT_SUPPORT_BLENDABLE;
-    if( SUCCEEDED( ID3D11Device_CheckFormatSupport(sys->d3ddevice,
-                                                   DXGI_FORMAT_R8G8B8A8_UNORM,
-                                                   &i_formatSupport)) &&
-            ( i_formatSupport & i_quadSupportFlags ) == i_quadSupportFlags) {
-        sys->d3dregion_format = DXGI_FORMAT_R8G8B8A8_UNORM;
-        sys->pSubpictureChromas[0] = VLC_CODEC_RGBA;
-        sys->pSubpictureChromas[1] = 0;
-    } else if( SUCCEEDED( ID3D11Device_CheckFormatSupport(sys->d3ddevice,
-                                                          DXGI_FORMAT_B8G8R8A8_UNORM,
-                                                          &i_formatSupport)) &&
-                   ( i_formatSupport & i_quadSupportFlags ) == i_quadSupportFlags) {
-        sys->d3dregion_format = DXGI_FORMAT_B8G8R8A8_UNORM;
-        sys->pSubpictureChromas[0] = VLC_CODEC_BGRA;
-        sys->pSubpictureChromas[1] = 0;
-    } else {
-        sys->d3dregion_format = DXGI_FORMAT_UNKNOWN;
-    }
-
-    sys->d3dPxShader = globPixelShaderDefault;
-    if (sys->picQuadConfig.resourceFormatYRGB == DXGI_FORMAT_R8_UNORM)
-    {
-        switch (fmt->i_chroma)
-        {
-        case VLC_CODEC_NV12:
-        case VLC_CODEC_D3D11_OPAQUE:
-            if( fmt->i_height > 576 )
-                sys->d3dPxShader = globPixelShaderBiplanarYUV_BT709_2RGB;
-            else
-                sys->d3dPxShader = globPixelShaderBiplanarYUV_BT601_2RGB;
-            break;
-        case VLC_CODEC_YV12:
-        case VLC_CODEC_I420:
-            if( fmt->i_height > 576 )
-                sys->d3dPxShader = globPixelShaderBiplanarI420_BT709_2RGB;
-            else
-                sys->d3dPxShader = globPixelShaderBiplanarI420_BT601_2RGB;
-            break;
-        default:
-            vlc_assert_unreachable();
-            break;
-        }
-    }
-
-    if (sys->d3dregion_format != DXGI_FORMAT_UNKNOWN)
-        sys->psz_rgbaPxShader = globPixelShaderDefault;
-    else
-        sys->psz_rgbaPxShader = NULL;
-
-    UpdateRects(vd, NULL, NULL, true);
-
-    if (Direct3D11CreateResources(vd, fmt)) {
-        msg_Err(vd, "Failed to allocate resources");
-        Direct3D11DestroyResources(vd);
-        return VLC_EGENERIC;
-    }
-
-#if !VLC_WINSTORE_APP
-    EventThreadUpdateTitle(sys->event, VOUT_TITLE " (Direct3D11 output)");
-#endif
-
-    msg_Dbg(vd, "Direct3D11 device adapter successfully initialized");
-    return VLC_SUCCESS;
-}
-
-static void Direct3D11Close(vout_display_t *vd)
-{
-    vout_display_sys_t *sys = vd->sys;
-
-    Direct3D11DestroyResources(vd);
-    if (sys->d3dcontext)
-    {
-        ID3D11DeviceContext_Flush(sys->d3dcontext);
-        ID3D11DeviceContext_Release(sys->d3dcontext);
-        sys->d3dcontext = NULL;
-    }
-    if (sys->d3ddevice)
-    {
-        ID3D11Device_Release(sys->d3ddevice);
-        sys->d3ddevice = NULL;
-    }
-    if (sys->dxgiswapChain)
-    {
-        IDXGISwapChain_Release(sys->dxgiswapChain);
-        sys->dxgiswapChain = NULL;
-    }
-
-    msg_Dbg(vd, "Direct3D11 device adapter closed");
-}
-
-static void UpdatePicQuadPosition(vout_display_t *vd)
-{
-    vout_display_sys_t *sys = vd->sys;
-    int i_width  = RECTWidth(sys->rect_dest_clipped);
-    int i_height = RECTHeight(sys->rect_dest_clipped);
-
-    int i_top = sys->rect_src_clipped.top * i_height;
-    i_top /= vd->source.i_visible_height;
-    i_top -= sys->rect_dest_clipped.top;
-    int i_left = sys->rect_src_clipped.left * i_width;
-    i_left /= vd->source.i_visible_width;
-    i_left -= sys->rect_dest_clipped.left;
-
-    sys->picQuad.cropViewport.Width =  (FLOAT) vd->source.i_width  * i_width  / vd->source.i_visible_width;
-    sys->picQuad.cropViewport.Height = (FLOAT) vd->source.i_height * i_height / vd->source.i_visible_height;
-    sys->picQuad.cropViewport.MinDepth = 0.0f;
-    sys->picQuad.cropViewport.MaxDepth = 1.0f;
-    sys->picQuad.cropViewport.TopLeftX = -i_left;
-    sys->picQuad.cropViewport.TopLeftY = -i_top;
-
-#ifndef NDEBUG
-    msg_Dbg(vd, "picQuad position (%.02f,%.02f) %.02fx%.02f", sys->picQuad.cropViewport.TopLeftX, sys->picQuad.cropViewport.TopLeftY, sys->picQuad.cropViewport.Width, sys->picQuad.cropViewport.Height );
-#endif
-}
-
-/* TODO : handle errors better
-   TODO : seperate out into smaller functions like createshaders */
-static int Direct3D11CreateResources(vout_display_t *vd, video_format_t *fmt)
-{
-    vout_display_sys_t *sys = vd->sys;
-    HRESULT hr;
-
-    hr = UpdateBackBuffer(vd);
-    if (FAILED(hr)) {
-       msg_Err(vd, "Could not update the backbuffer. (hr=0x%lX)", hr);
-       return VLC_EGENERIC;
-    }
-
-    ID3D11BlendState *pSpuBlendState;
-    D3D11_BLEND_DESC spuBlendDesc = { 0 };
-    spuBlendDesc.RenderTarget[0].BlendEnable = TRUE;
-    spuBlendDesc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
-    spuBlendDesc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
-    spuBlendDesc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
-
-    spuBlendDesc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
-    spuBlendDesc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO;
-    spuBlendDesc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
-
-    spuBlendDesc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
-
-    spuBlendDesc.RenderTarget[1].BlendEnable = TRUE;
-    spuBlendDesc.RenderTarget[1].SrcBlend = D3D11_BLEND_ONE;
-    spuBlendDesc.RenderTarget[1].DestBlend = D3D11_BLEND_ZERO;
-    spuBlendDesc.RenderTarget[1].BlendOp = D3D11_BLEND_OP_ADD;
-
-    spuBlendDesc.RenderTarget[1].SrcBlendAlpha = D3D11_BLEND_ONE;
-    spuBlendDesc.RenderTarget[1].DestBlendAlpha = D3D11_BLEND_ZERO;
-    spuBlendDesc.RenderTarget[1].BlendOpAlpha = D3D11_BLEND_OP_ADD;
-
-    spuBlendDesc.RenderTarget[1].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
-    hr = ID3D11Device_CreateBlendState(sys->d3ddevice, &spuBlendDesc, &pSpuBlendState);
-    if (FAILED(hr)) {
-       msg_Err(vd, "Could not create SPU blend state. (hr=0x%lX)", hr);
-       return VLC_EGENERIC;
-    }
-    ID3D11DeviceContext_OMSetBlendState(sys->d3dcontext, pSpuBlendState, NULL, 0xFFFFFFFF);
-    ID3D11BlendState_Release(pSpuBlendState);
-
-    /* disable depth testing as we're only doing 2D
-     * see https://msdn.microsoft.com/en-us/library/windows/desktop/bb205074%28v=vs.85%29.aspx
-     * see http://rastertek.com/dx11tut11.html
-    */
-    D3D11_DEPTH_STENCIL_DESC stencilDesc;
-    ZeroMemory(&stencilDesc, sizeof(stencilDesc));
-    stencilDesc.DepthEnable                  = FALSE;
-    stencilDesc.StencilEnable                = TRUE;
-    stencilDesc.DepthWriteMask               = D3D11_DEPTH_WRITE_MASK_ALL;
-    stencilDesc.DepthFunc                    = D3D11_COMPARISON_LESS;
-    stencilDesc.StencilReadMask              = 0xFF;
-    stencilDesc.StencilWriteMask             = 0xFF;
-    stencilDesc.FrontFace.StencilFailOp      = D3D11_STENCIL_OP_KEEP;
-    stencilDesc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_INCR;
-    stencilDesc.FrontFace.StencilPassOp      = D3D11_STENCIL_OP_KEEP;
-    stencilDesc.FrontFace.StencilFunc        = D3D11_COMPARISON_ALWAYS;
-    stencilDesc.BackFace.StencilFailOp       = D3D11_STENCIL_OP_KEEP;
-    stencilDesc.BackFace.StencilDepthFailOp  = D3D11_STENCIL_OP_DECR;
-    stencilDesc.BackFace.StencilPassOp       = D3D11_STENCIL_OP_KEEP;
-    stencilDesc.BackFace.StencilFunc         = D3D11_COMPARISON_ALWAYS;
-
-    ID3D11DepthStencilState *pDepthStencilState;
-    hr = ID3D11Device_CreateDepthStencilState(sys->d3ddevice, &stencilDesc, &pDepthStencilState );
-    if (SUCCEEDED(hr)) {
-        ID3D11DeviceContext_OMSetDepthStencilState(sys->d3dcontext, pDepthStencilState, 0);
-        ID3D11DepthStencilState_Release(pDepthStencilState);
-    }
-
-    ID3DBlob* pVSBlob = NULL;
-
-    /* TODO : Match the version to the D3D_FEATURE_LEVEL */
-    hr = D3DCompile(globVertexShaderDefault, strlen(globVertexShaderDefault),
-                    NULL, NULL, NULL, "VS", "vs_4_0_level_9_1", 0, 0, &pVSBlob, NULL);
-
-    if( FAILED(hr)) {
-      msg_Err(vd, "The Vertex Shader is invalid.");
-      return VLC_EGENERIC;
-    }
-
-    ID3D11VertexShader *d3dvertexShader;
-    hr = ID3D11Device_CreateVertexShader(sys->d3ddevice, (void *)ID3D10Blob_GetBufferPointer(pVSBlob),
-                                        ID3D10Blob_GetBufferSize(pVSBlob), NULL, &d3dvertexShader);
-
-    if(FAILED(hr)) {
-      ID3D11Device_Release(pVSBlob);
-      msg_Err(vd, "Failed to create the vertex shader.");
-      return VLC_EGENERIC;
-    }
-    ID3D11DeviceContext_VSSetShader(sys->d3dcontext, d3dvertexShader, NULL, 0);
-    ID3D11VertexShader_Release(d3dvertexShader);
-
-    D3D11_INPUT_ELEMENT_DESC layout[] = {
-    { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0,  0, D3D11_INPUT_PER_VERTEX_DATA, 0},
-    { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT,    0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0},
-    { "OPACITY",  0, DXGI_FORMAT_R32_FLOAT,       0, 20, D3D11_INPUT_PER_VERTEX_DATA, 0},
-    };
-
-    ID3D11InputLayout* pVertexLayout = NULL;
-    hr = ID3D11Device_CreateInputLayout(sys->d3ddevice, layout, 3, (void *)ID3D10Blob_GetBufferPointer(pVSBlob),
-                                        ID3D10Blob_GetBufferSize(pVSBlob), &pVertexLayout);
-
-    ID3D10Blob_Release(pVSBlob);
-
-    if(FAILED(hr)) {
-      msg_Err(vd, "Failed to create the vertex input layout");
-      return VLC_EGENERIC;
-    }
-
-    ID3D11DeviceContext_IASetInputLayout(sys->d3dcontext, pVertexLayout);
-    ID3D11SamplerState_Release(pVertexLayout);
-
-    /* create the index of the vertices */
-    WORD indices[] = {
-      3, 1, 0,
-      2, 1, 3,
-    };
-
-    D3D11_BUFFER_DESC quadDesc = {
-        .Usage = D3D11_USAGE_DEFAULT,
-        .ByteWidth = sizeof(WORD) * 6,
-        .BindFlags = D3D11_BIND_INDEX_BUFFER,
-        .CPUAccessFlags = 0,
-    };
-
-    D3D11_SUBRESOURCE_DATA quadIndicesInit = {
-        .pSysMem = indices,
-    };
-
-    ID3D11Buffer* pIndexBuffer = NULL;
-    hr = ID3D11Device_CreateBuffer(sys->d3ddevice, &quadDesc, &quadIndicesInit, &pIndexBuffer);
-    if(FAILED(hr)) {
-        msg_Err(vd, "Could not Create the common quad indices. (hr=0x%lX)", hr);
-        return VLC_EGENERIC;
-    }
-    ID3D11DeviceContext_IASetIndexBuffer(sys->d3dcontext, pIndexBuffer, DXGI_FORMAT_R16_UINT, 0);
-    ID3D11Buffer_Release(pIndexBuffer);
-
-    ID3D11DeviceContext_IASetPrimitiveTopology(sys->d3dcontext, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
-
-    ID3DBlob* pPSBlob = NULL;
-
-    /* TODO : Match the version to the D3D_FEATURE_LEVEL */
-    hr = D3DCompile(sys->d3dPxShader, strlen(sys->d3dPxShader),
-                    NULL, NULL, NULL, "PS", "ps_4_0_level_9_1", 0, 0, &pPSBlob, NULL);
-
-
-    if( FAILED(hr)) {
-      msg_Err(vd, "The Pixel Shader is invalid. (hr=0x%lX)", hr );
-      return VLC_EGENERIC;
-    }
-
-    ID3D11PixelShader *pPicQuadShader;
-    hr = ID3D11Device_CreatePixelShader(sys->d3ddevice, (void *)ID3D10Blob_GetBufferPointer(pPSBlob),
-                                        ID3D10Blob_GetBufferSize(pPSBlob), NULL, &pPicQuadShader);
-
-    ID3D10Blob_Release(pPSBlob);
-
-    if(FAILED(hr)) {
-      msg_Err(vd, "Failed to create the pixel shader.");
-      return VLC_EGENERIC;
-    }
-
-    if (sys->psz_rgbaPxShader != NULL)
-    {
-        hr = D3DCompile(sys->psz_rgbaPxShader, strlen(sys->psz_rgbaPxShader),
-                        NULL, NULL, NULL, "PS", "ps_4_0_level_9_1", 0, 0, &pPSBlob, NULL);
-        if( FAILED(hr)) {
-          ID3D11PixelShader_Release(pPicQuadShader);
-          msg_Err(vd, "The RGBA Pixel Shader is invalid. (hr=0x%lX)", hr );
-          return VLC_EGENERIC;
-        }
-
-        hr = ID3D11Device_CreatePixelShader(sys->d3ddevice, (void *)ID3D10Blob_GetBufferPointer(pPSBlob),
-                                            ID3D10Blob_GetBufferSize(pPSBlob), NULL, &sys->pSPUPixelShader);
-
-        ID3D10Blob_Release(pPSBlob);
-
-        if(FAILED(hr)) {
-          ID3D11PixelShader_Release(pPicQuadShader);
-          msg_Err(vd, "Failed to create the SPU pixel shader.");
-          return VLC_EGENERIC;
-        }
-    }
-
-    if (AllocQuad( vd, fmt, &sys->picQuad, &sys->picQuadConfig, pPicQuadShader) != VLC_SUCCESS) {
-        ID3D11PixelShader_Release(pPicQuadShader);
-        msg_Err(vd, "Could not Create the main quad picture. (hr=0x%lX)", hr);
-        return VLC_EGENERIC;
-    }
-    ID3D11PixelShader_Release(pPicQuadShader);
-
-    UpdatePicQuadPosition(vd);
-
-    D3D11_SAMPLER_DESC sampDesc;
-    memset(&sampDesc, 0, sizeof(sampDesc));
-    sampDesc.Filter = D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT;
-    sampDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
-    sampDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
-    sampDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
-    sampDesc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
-    sampDesc.MinLOD = 0;
-    sampDesc.MaxLOD = D3D11_FLOAT32_MAX;
-
-    ID3D11SamplerState *d3dsampState;
-    hr = ID3D11Device_CreateSamplerState(sys->d3ddevice, &sampDesc, &d3dsampState);
-
-    if (FAILED(hr)) {
-      msg_Err(vd, "Could not Create the D3d11 Sampler State. (hr=0x%lX)", hr);
-      return VLC_EGENERIC;
-    }
-    ID3D11DeviceContext_PSSetSamplers(sys->d3dcontext, 0, 1, &d3dsampState);
-    ID3D11SamplerState_Release(d3dsampState);
-
-    if (Direct3D11CreatePool(vd, fmt))
-    {
-        msg_Err(vd, "Direct3D picture pool initialization failed");
-        return VLC_EGENERIC;
-    }
-
-    msg_Dbg(vd, "Direct3D11 resources created");
-    return VLC_SUCCESS;
-}
-
-static int Direct3D11CreatePool(vout_display_t *vd, video_format_t *fmt)
-{
-    vout_display_sys_t *sys = vd->sys;
-
-    if ( fmt->i_chroma == VLC_CODEC_D3D11_OPAQUE )
-        /* a D3D11VA pool will be created when needed */
-        return VLC_SUCCESS;
-
-    picture_sys_pool_t *picsys = calloc(1, sizeof(*picsys));
-    if (unlikely(picsys == NULL)) {
-        return VLC_ENOMEM;
-    }
-
-    picsys->texture  = sys->picQuad.pTexture;
-    picsys->vd       = vd;
-
-    picture_resource_t resource = {
-        .p_sys = (picture_sys_t*) picsys,
-        .pf_destroy = DestroyDisplayPicture,
-    };
-
-    picture_t *picture = picture_NewFromResource(fmt, &resource);
-    if (!picture) {
-        free(picsys);
-        return VLC_ENOMEM;
-    }
-    ID3D11Texture2D_AddRef(picsys->texture);
-
-    picture_pool_configuration_t pool_cfg;
-    memset(&pool_cfg, 0, sizeof(pool_cfg));
-    pool_cfg.picture_count = 1;
-    pool_cfg.picture       = &picture;
-    pool_cfg.lock          = Direct3D11MapTexture;
-    //pool_cfg.unlock        = Direct3D11UnmapTexture;
-
-    sys->pool = picture_pool_NewExtended(&pool_cfg);
-    if (!sys->pool) {
-        picture_Release(picture);
-        return VLC_ENOMEM;
-    }
-
-    return VLC_SUCCESS;
-}
-
-static void Direct3D11DestroyPool(vout_display_t *vd)
-{
-    vout_display_sys_t *sys = vd->sys;
-
-    if (sys->pool)
-        picture_pool_Release(sys->pool);
-    sys->pool = NULL;
-}
-
-static int AllocQuad(vout_display_t *vd, const video_format_t *fmt, d3d_quad_t *quad,
-                     d3d_quad_cfg_t *cfg, ID3D11PixelShader *d3dpixelShader)
-{
-    vout_display_sys_t *sys = vd->sys;
-    D3D11_MAPPED_SUBRESOURCE mappedResource;
-    HRESULT hr;
-
-    D3D11_BUFFER_DESC bd;
-    memset(&bd, 0, sizeof(bd));
-    bd.Usage = D3D11_USAGE_DYNAMIC;
-    bd.ByteWidth = sizeof(d3d_vertex_t) * 4;
-    bd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
-    bd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
-
-    hr = ID3D11Device_CreateBuffer(sys->d3ddevice, &bd, NULL, &quad->pVertexBuffer);
-    if(FAILED(hr)) {
-      msg_Err(vd, "Failed to create vertex buffer.");
-      goto error;
-    }
-
-    D3D11_TEXTURE2D_DESC texDesc;
-    memset(&texDesc, 0, sizeof(texDesc));
-    texDesc.Width = fmt->i_width;
-    texDesc.Height = fmt->i_height;
-    texDesc.MipLevels = texDesc.ArraySize = 1;
-    texDesc.Format = cfg->textureFormat;
-    texDesc.SampleDesc.Count = 1;
-    texDesc.Usage = D3D11_USAGE_DYNAMIC;
-    texDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
-    texDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
-    texDesc.MiscFlags = 0;
-
-    hr = ID3D11Device_CreateTexture2D(sys->d3ddevice, &texDesc, NULL, &quad->pTexture);
-    if (FAILED(hr)) {
-        msg_Err(vd, "Could not Create the D3d11 Texture. (hr=0x%lX)", hr);
-        goto error;
-    }
-
-    D3D11_SHADER_RESOURCE_VIEW_DESC resviewDesc;
-    memset(&resviewDesc, 0, sizeof(resviewDesc));
-    resviewDesc.Format = cfg->resourceFormatYRGB;
-    resviewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
-    resviewDesc.Texture2D.MipLevels = texDesc.MipLevels;
-
-    hr = ID3D11Device_CreateShaderResourceView(sys->d3ddevice, (ID3D11Resource *)quad->pTexture, &resviewDesc, &quad->d3dresViewY);
-    if (FAILED(hr)) {
-        msg_Err(vd, "Could not Create the Y/RGB D3d11 Texture ResourceView. (hr=0x%lX)", hr);
-        goto error;
-    }
-
-    if( cfg->resourceFormatUV )
-    {
-        resviewDesc.Format = cfg->resourceFormatUV;
-        hr = ID3D11Device_CreateShaderResourceView(sys->d3ddevice, (ID3D11Resource *)quad->pTexture, &resviewDesc, &quad->d3dresViewUV);
-        if (FAILED(hr)) {
-            msg_Err(vd, "Could not Create the UV D3d11 Texture ResourceView. (hr=0x%lX)", hr);
-            goto error;
-        }
-    }
-
-    quad->d3dpixelShader = d3dpixelShader;
-    ID3D11PixelShader_AddRef(quad->d3dpixelShader);
-
-    float right = 1.0f;
-    float left = -1.0f;
-    float top = 1.0f;
-    float bottom = -1.0f;
-
-    hr = ID3D11DeviceContext_Map(sys->d3dcontext, (ID3D11Resource *)quad->pVertexBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
-    if (SUCCEEDED(hr)) {
-        d3d_vertex_t *dst_data = mappedResource.pData;
-
-        // bottom left
-        dst_data[0].position.x = left;
-        dst_data[0].position.y = bottom;
-        dst_data[0].position.z = 0.0f;
-        dst_data[0].texture.x = 0.0f;
-        dst_data[0].texture.y = 1.0f;
-        dst_data[0].opacity = 1.0f;
-
-        // bottom right
-        dst_data[1].position.x = right;
-        dst_data[1].position.y = bottom;
-        dst_data[1].position.z = 0.0f;
-        dst_data[1].texture.x = 1.0f;
-        dst_data[1].texture.y = 1.0f;
-        dst_data[1].opacity = 1.0f;
-
-        // top right
-        dst_data[2].position.x = right;
-        dst_data[2].position.y = top;
-        dst_data[2].position.z = 0.0f;
-        dst_data[2].texture.x = 1.0f;
-        dst_data[2].texture.y = 0.0f;
-        dst_data[2].opacity = 1.0f;
-
-        // top left
-        dst_data[3].position.x = left;
-        dst_data[3].position.y = top;
-        dst_data[3].position.z = 0.0f;
-        dst_data[3].texture.x = 0.0f;
-        dst_data[3].texture.y = 0.0f;
-        dst_data[3].opacity = 1.0f;
-
-        ID3D11DeviceContext_Unmap(sys->d3dcontext, (ID3D11Resource *)quad->pVertexBuffer, 0);
-    }
-    else {
-        msg_Err(vd, "Failed to lock the subpicture vertex buffer (hr=0x%lX)", hr);
-    }
-
-    return VLC_SUCCESS;
-
-error:
-    ReleaseQuad(quad);
-    return VLC_EGENERIC;
-}
-
-static void ReleaseQuad(d3d_quad_t *quad)
-{
-    if (quad->pVertexBuffer)
-        ID3D11Buffer_Release(quad->pVertexBuffer);
-    if (quad->pTexture)
-        ID3D11Texture2D_Release(quad->pTexture);
-    if (quad->d3dresViewY)
-        ID3D11ShaderResourceView_Release(quad->d3dresViewY);
-    if (quad->d3dresViewUV)
-        ID3D11ShaderResourceView_Release(quad->d3dresViewUV);
-    if (quad->d3dpixelShader)
-        ID3D11VertexShader_Release(quad->d3dpixelShader);
-}
-
-static void Direct3D11DestroyResources(vout_display_t *vd)
-{
-    vout_display_sys_t *sys = vd->sys;
-
-    Direct3D11DestroyPool(vd);
-
-    ReleaseQuad(&sys->picQuad);
-    Direct3D11DeleteRegions(sys->d3dregion_count, sys->d3dregions);
-    sys->d3dregion_count = 0;
-
-    if (sys->d3drenderTargetView)
-        ID3D11RenderTargetView_Release(sys->d3drenderTargetView);
-    if (sys->d3ddepthStencilView)
-        ID3D11DepthStencilView_Release(sys->d3ddepthStencilView);
-    if (sys->pSPUPixelShader)
-        ID3D11VertexShader_Release(sys->pSPUPixelShader);
-
-    msg_Dbg(vd, "Direct3D11 resources destroyed");
-}
-
-static int Direct3D11MapTexture(picture_t *picture)
-{
-    picture_sys_pool_t *p_sys = (picture_sys_pool_t*) picture->p_sys;
-    vout_display_t     *vd = p_sys->vd;
-    D3D11_MAPPED_SUBRESOURCE mappedResource;
-    HRESULT hr;
-    int res;
-    hr = ID3D11DeviceContext_Map(vd->sys->d3dcontext, (ID3D11Resource *)p_sys->texture, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
-    if( FAILED(hr) )
-    {
-        msg_Dbg( vd, "failed to map the texture (hr=0x%lX)", hr );
-        return VLC_EGENERIC;
-    }
-    return CommonUpdatePicture(picture, NULL, mappedResource.pData, mappedResource.RowPitch);
-}
-
-static int Direct3D11UnmapTexture(picture_t *picture)
-{
-    picture_sys_pool_t *p_sys = (picture_sys_pool_t*)picture->p_sys;
-    vout_display_t     *vd = p_sys->vd;
-    ID3D11DeviceContext_Unmap(vd->sys->d3dcontext, (ID3D11Resource *)p_sys->texture, 0);
-    return VLC_SUCCESS;
-}
-
-static void Direct3D11DeleteRegions(int count, picture_t **region)
-{
-    for (int i = 0; i < count; ++i) {
-        if (region[i]) {
-            picture_Release(region[i]);
-        }
-    }
-    free(region);
-}
-
-static void DestroyPictureQuad(picture_t *p_picture)
-{
-    ReleaseQuad( (d3d_quad_t *) p_picture->p_sys );
-    free( p_picture );
-}
-
-static void UpdateQuadOpacity(vout_display_t *vd, const d3d_quad_t *quad, float opacity)
-{
-    vout_display_sys_t *sys = vd->sys;
-    D3D11_MAPPED_SUBRESOURCE mappedResource;
-
-    HRESULT hr = ID3D11DeviceContext_Map(sys->d3dcontext, (ID3D11Resource *)quad->pVertexBuffer, 0, D3D11_MAP_WRITE_NO_OVERWRITE, 0, &mappedResource);
-    if (SUCCEEDED(hr)) {
-        d3d_vertex_t *dst_data = mappedResource.pData;
-
-        dst_data[0].opacity = opacity;
-        dst_data[1].opacity = opacity;
-        dst_data[2].opacity = opacity;
-        dst_data[3].opacity = opacity;
-
-        ID3D11DeviceContext_Unmap(sys->d3dcontext, (ID3D11Resource *)quad->pVertexBuffer, 0);
-    }
-    else {
-        msg_Err(vd, "Failed to lock the subpicture vertex buffer (hr=0x%lX)", hr);
-    }
-}
-
-static int Direct3D11MapSubpicture(vout_display_t *vd, int *subpicture_region_count,
-                                   picture_t ***region, subpicture_t *subpicture)
-{
-    vout_display_sys_t *sys = vd->sys;
-    D3D11_MAPPED_SUBRESOURCE mappedResource;
-    D3D11_TEXTURE2D_DESC texDesc;
-    HRESULT hr;
-    int err;
-
-    int count = 0;
-    for (subpicture_region_t *r = subpicture->p_region; r; r = r->p_next)
-        count++;
-
-    *region = calloc(count, sizeof(picture_t *));
-    if (unlikely(*region==NULL))
-        return VLC_ENOMEM;
-    *subpicture_region_count = count;
-
-    int i = 0;
-    for (subpicture_region_t *r = subpicture->p_region; r; r = r->p_next, i++) {
-        for (int j = 0; j < sys->d3dregion_count; j++) {
-            picture_t *cache = sys->d3dregions[j];
-            if (cache != NULL && ((d3d_quad_t *) cache->p_sys)->pTexture) {
-                ID3D11Texture2D_GetDesc( ((d3d_quad_t *) cache->p_sys)->pTexture, &texDesc );
-                if (texDesc.Format == sys->d3dregion_format &&
-                    texDesc.Width  == r->fmt.i_visible_width &&
-                    texDesc.Height == r->fmt.i_visible_height) {
-                    (*region)[i] = cache;
-                    memset(&sys->d3dregions[j], 0, sizeof(cache)); // do not reuse this cached value
-                    break;
-                }
-            }
-        }
-
-        picture_t *quad_picture = (*region)[i];
-        if (quad_picture == NULL) {
-            d3d_quad_t *d3dquad = calloc(1, sizeof(*d3dquad));
-            if (unlikely(d3dquad==NULL)) {
-                continue;
-            }
-            d3d_quad_cfg_t rgbaCfg = {
-                .textureFormat      = sys->d3dregion_format,
-                .resourceFormatYRGB = sys->d3dregion_format,
-            };
-            err = AllocQuad(vd, &r->fmt, d3dquad, &rgbaCfg, sys->pSPUPixelShader);
-            if (err != VLC_SUCCESS) {
-                msg_Err(vd, "Failed to create %dx%d texture for OSD",
-                        r->fmt.i_visible_width, r->fmt.i_visible_height);
-                free(d3dquad);
-                continue;
-            }
-            picture_resource_t picres = {
-                .p_sys      = (picture_sys_t *) d3dquad,
-                .pf_destroy = DestroyPictureQuad,
-            };
-            (*region)[i] = picture_NewFromResource(&r->fmt, &picres);
-            if ((*region)[i] == NULL) {
-                msg_Err(vd, "Failed to create %dx%d picture for OSD",
-                        r->fmt.i_visible_width, r->fmt.i_visible_height);
-                ReleaseQuad(d3dquad);
-                continue;
-            }
-            quad_picture = (*region)[i];
-        }
-
-        hr = ID3D11DeviceContext_Map(sys->d3dcontext, (ID3D11Resource *)((d3d_quad_t *) quad_picture->p_sys)->pTexture, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
-        if( SUCCEEDED(hr) ) {
-            err = CommonUpdatePicture(quad_picture, NULL, mappedResource.pData, mappedResource.RowPitch);
-            if (err != VLC_SUCCESS) {
-                msg_Err(vd, "Failed to set the buffer on the SPU picture" );
-                picture_Release(quad_picture);
-                continue;
-            }
-
-            picture_CopyPixels(quad_picture, r->p_picture);
-
-            ID3D11DeviceContext_Unmap(sys->d3dcontext, (ID3D11Resource *)((d3d_quad_t *) quad_picture->p_sys)->pTexture, 0);
-        } else {
-            msg_Err(vd, "Failed to map the SPU texture (hr=0x%lX)", hr );
-            picture_Release(quad_picture);
-            continue;
-        }
-
-        d3d_quad_t *quad = (d3d_quad_t *) quad_picture->p_sys;
-
-        quad->cropViewport.Width =  (FLOAT) r->fmt.i_visible_width * RECTHeight(sys->rect_dest) / subpicture->i_original_picture_height;
-        quad->cropViewport.Height = (FLOAT) r->fmt.i_visible_height * RECTWidth(sys->rect_dest) / subpicture->i_original_picture_width;
-        quad->cropViewport.MinDepth = 0.0f;
-        quad->cropViewport.MaxDepth = 1.0f;
-        quad->cropViewport.TopLeftX = r->i_x * RECTHeight(sys->rect_dest) / subpicture->i_original_picture_height;
-        quad->cropViewport.TopLeftY = r->i_y * RECTWidth(sys->rect_dest) / subpicture->i_original_picture_width;
-
-        UpdateQuadOpacity(vd, quad, r->i_alpha / 255.0f );
-    }
-    return VLC_SUCCESS;
-}
-
diff --git a/modules/video_output/msw/direct3d9.c b/modules/video_output/msw/direct3d9.c
deleted file mode 100644 (file)
index f9e68a8..0000000
+++ /dev/null
@@ -1,1905 +0,0 @@
-/*****************************************************************************
- * direct3d9.c: Windows Direct3D9 video output module
- *****************************************************************************
- * Copyright (C) 2006-2014 VLC authors and VideoLAN
- *$Id$
- *
- * Authors: Martell Malone <martellmalone@gmail.com>,
- *          Damien Fouilleul <damienf@videolan.org>,
- *          Sasha Koruga <skoruga@gmail.com>,
- *          Felix Abecassis <felix.abecassis@gmail.com>
- *
- * 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 Lesser General Public License for more details.
- *
- * 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.
- *****************************************************************************/
-
-/*****************************************************************************
- * Preamble:
- *
- * This plugin will use YUV surface if supported, using YUV will result in
- * the best video quality (hardware filtering when rescaling the picture)
- * and the fastest display as it requires less processing.
- *
- * If YUV overlay is not supported this plugin will use RGB offscreen video
- * surfaces that will be blitted onto the primary surface (display) to
- * effectively display the pictures.
- *
- *****************************************************************************/
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#include <vlc_common.h>
-#include <vlc_plugin.h>
-#include <vlc_vout_display.h>
-#include <vlc_charset.h> /* ToT function */
-
-#include <windows.h>
-#include <d3d9.h>
-
-#include "common.h"
-#include "builtin_shaders.h"
-
-/*****************************************************************************
- * Module descriptor
- *****************************************************************************/
-static int  Open(vlc_object_t *);
-static void Close(vlc_object_t *);
-
-#define DESKTOP_LONGTEXT N_(\
-    "The desktop mode allows you to display the video on the desktop.")
-
-#define HW_BLENDING_TEXT N_("Use hardware blending support")
-#define HW_BLENDING_LONGTEXT N_(\
-    "Try to use hardware acceleration for subtitle/OSD blending.")
-
-#define PIXEL_SHADER_TEXT N_("Pixel Shader")
-#define PIXEL_SHADER_LONGTEXT N_(\
-        "Choose a pixel shader to apply.")
-#define PIXEL_SHADER_FILE_TEXT N_("Path to HLSL file")
-#define PIXEL_SHADER_FILE_LONGTEXT N_("Path to an HLSL file containing a single pixel shader.")
-/* The latest option in the selection list: used for loading a shader file. */
-#define SELECTED_SHADER_FILE N_("HLSL File")
-
-#define D3D9_HELP N_("Recommended video output for Windows Vista and later versions")
-
-static int FindShadersCallback(vlc_object_t *, const char *,
-                               char ***, char ***);
-
-vlc_module_begin ()
-    set_shortname("Direct3D9")
-    set_description(N_("Direct3D9 video output"))
-    set_help(D3D9_HELP)
-    set_category(CAT_VIDEO)
-    set_subcategory(SUBCAT_VIDEO_VOUT)
-
-    add_bool("direct3d9-hw-blending", true, HW_BLENDING_TEXT, HW_BLENDING_LONGTEXT, true)
-
-    add_string("direct3d9-shader", "", PIXEL_SHADER_TEXT, PIXEL_SHADER_LONGTEXT, true)
-        change_string_cb(FindShadersCallback)
-    add_loadfile("direct3d9-shader-file", NULL, PIXEL_SHADER_FILE_TEXT, PIXEL_SHADER_FILE_LONGTEXT, false)
-
-    set_capability("vout display", 280)
-    add_shortcut("direct3d9", "direct3d")
-    set_callbacks(Open, Close)
-
-vlc_module_end ()
-
-/*****************************************************************************
- * Local prototypes.
- *****************************************************************************/
-static const vlc_fourcc_t d3d_subpicture_chromas[] = {
-    VLC_CODEC_RGBA,
-    0
-};
-
-struct picture_sys_t
-{
-    LPDIRECT3DSURFACE9 surface;
-    picture_t          *fallback;
-};
-
-static int  Open(vlc_object_t *);
-
-static picture_pool_t *Pool  (vout_display_t *, unsigned);
-static void           Prepare(vout_display_t *, picture_t *, subpicture_t *subpicture);
-static void           Display(vout_display_t *, picture_t *, subpicture_t *subpicture);
-static int            Control(vout_display_t *, int, va_list);
-static void           Manage (vout_display_t *);
-
-static int  Direct3D9Create (vout_display_t *);
-static int  Direct3D9Reset  (vout_display_t *);
-static void Direct3D9Destroy(vout_display_t *);
-
-static int  Direct3D9Open (vout_display_t *, video_format_t *);
-static void Direct3D9Close(vout_display_t *);
-
-/* */
-typedef struct
-{
-    FLOAT       x,y,z;      // vertex untransformed position
-    FLOAT       rhw;        // eye distance
-    D3DCOLOR    diffuse;    // diffuse color
-    FLOAT       tu, tv;     // texture relative coordinates
-} CUSTOMVERTEX;
-#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZRHW|D3DFVF_DIFFUSE|D3DFVF_TEX1)
-
-typedef struct d3d_region_t {
-    D3DFORMAT          format;
-    unsigned           width;
-    unsigned           height;
-    CUSTOMVERTEX       vertex[4];
-    LPDIRECT3DTEXTURE9 texture;
-} d3d_region_t;
-
-static void Direct3D9DeleteRegions(int, d3d_region_t *);
-
-static int  Direct3D9ImportPicture(vout_display_t *vd, d3d_region_t *, LPDIRECT3DSURFACE9 surface);
-static void Direct3D9ImportSubpicture(vout_display_t *vd, int *, d3d_region_t **, subpicture_t *);
-
-static void Direct3D9RenderScene(vout_display_t *vd, d3d_region_t *, int, d3d_region_t *);
-
-/* */
-static int DesktopCallback(vlc_object_t *, char const *, vlc_value_t, vlc_value_t, void *);
-
-/**
- * It creates a Direct3D vout display.
- */
-static int Open(vlc_object_t *object)
-{
-    vout_display_t *vd = (vout_display_t *)object;
-    vout_display_sys_t *sys;
-
-    OSVERSIONINFO winVer;
-    winVer.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
-    if(GetVersionEx(&winVer) && winVer.dwMajorVersion < 6 && !object->b_force)
-        return VLC_EGENERIC;
-
-    /* Allocate structure */
-    vd->sys = sys = calloc(1, sizeof(vout_display_sys_t));
-    if (!sys)
-        return VLC_ENOMEM;
-
-    if (Direct3D9Create(vd)) {
-        msg_Err(vd, "Direct3D9 could not be initialized");
-        Direct3D9Destroy(vd);
-        free(sys);
-        return VLC_EGENERIC;
-    }
-
-    sys->use_desktop = var_CreateGetBool(vd, "video-wallpaper");
-    sys->reset_device = false;
-    sys->reopen_device = false;
-    sys->lost_not_ready = false;
-    sys->allow_hw_yuv = var_CreateGetBool(vd, "directx-hw-yuv");
-    sys->desktop_save.is_fullscreen = vd->cfg->is_fullscreen;
-    sys->desktop_save.is_on_top     = false;
-    sys->desktop_save.win.left      = var_InheritInteger(vd, "video-x");
-    sys->desktop_save.win.right     = vd->cfg->display.width;
-    sys->desktop_save.win.top       = var_InheritInteger(vd, "video-y");
-    sys->desktop_save.win.bottom    = vd->cfg->display.height;
-
-    if (CommonInit(vd))
-        goto error;
-
-    /* */
-    video_format_t fmt;
-    if (Direct3D9Open(vd, &fmt)) {
-        msg_Err(vd, "Direct3D9 could not be opened");
-        goto error;
-    }
-
-    /* */
-    vout_display_info_t info = vd->info;
-    info.is_slow = fmt.i_chroma != VLC_CODEC_D3D9_OPAQUE;
-    info.has_double_click = true;
-    info.has_hide_mouse = false;
-    info.has_pictures_invalid = fmt.i_chroma != VLC_CODEC_D3D9_OPAQUE;
-    info.has_event_thread = true;
-    if (var_InheritBool(vd, "direct3d9-hw-blending") &&
-        sys->d3dregion_format != D3DFMT_UNKNOWN &&
-        (sys->d3dcaps.SrcBlendCaps  & D3DPBLENDCAPS_SRCALPHA) &&
-        (sys->d3dcaps.DestBlendCaps & D3DPBLENDCAPS_INVSRCALPHA) &&
-        (sys->d3dcaps.TextureCaps   & D3DPTEXTURECAPS_ALPHA) &&
-        (sys->d3dcaps.TextureOpCaps & D3DTEXOPCAPS_SELECTARG1) &&
-        (sys->d3dcaps.TextureOpCaps & D3DTEXOPCAPS_MODULATE))
-        info.subpicture_chromas = d3d_subpicture_chromas;
-    else
-        info.subpicture_chromas = NULL;
-
-    /* Interaction */
-    vlc_mutex_init(&sys->lock);
-    sys->ch_desktop = false;
-    sys->desktop_requested = sys->use_desktop;
-
-    vlc_value_t val;
-    val.psz_string = _("Desktop");
-    var_Change(vd, "video-wallpaper", VLC_VAR_SETTEXT, &val, NULL);
-    var_AddCallback(vd, "video-wallpaper", DesktopCallback, NULL);
-
-    /* Setup vout_display now that everything is fine */
-    video_format_Clean(&vd->fmt);
-    video_format_Copy(&vd->fmt, &fmt);
-    vd->info = info;
-
-    vd->pool    = Pool;
-    vd->prepare = Prepare;
-    vd->display = Display;
-    vd->control = Control;
-    vd->manage  = Manage;
-
-    /* Fix state in case of desktop mode */
-    if (sys->use_desktop && vd->cfg->is_fullscreen)
-        vout_display_SendEventFullscreen(vd, false);
-
-    return VLC_SUCCESS;
-error:
-    Direct3D9Close(vd);
-    CommonClean(vd);
-    Direct3D9Destroy(vd);
-    free(vd->sys);
-    return VLC_EGENERIC;
-}
-
-/**
- * It destroyes a Direct3D vout display.
- */
-static void Close(vlc_object_t *object)
-{
-    vout_display_t * vd = (vout_display_t *)object;
-
-    var_DelCallback(vd, "video-wallpaper", DesktopCallback, NULL);
-    vlc_mutex_destroy(&vd->sys->lock);
-
-    Direct3D9Close(vd);
-
-    CommonClean(vd);
-
-    Direct3D9Destroy(vd);
-
-    free(vd->sys);
-}
-
-static void DestroyPicture(picture_t *picture)
-{
-    IDirect3DSurface9_Release(picture->p_sys->surface);
-
-    free(picture->p_sys);
-    free(picture);
-}
-
-/* */
-static picture_pool_t *Pool(vout_display_t *vd, unsigned count)
-{
-    if ( vd->sys->pool != NULL )
-        return vd->sys->pool;
-
-    picture_t**       pictures = NULL;
-    unsigned          picture_count = 0;
-
-    pictures = calloc(count, sizeof(*pictures));
-    if (!pictures)
-        goto error;
-    for (picture_count = 0; picture_count < count; ++picture_count)
-    {
-        picture_sys_t *picsys = malloc(sizeof(*picsys));
-        if (unlikely(picsys == NULL))
-            goto error;
-
-        HRESULT hr = IDirect3DDevice9_CreateOffscreenPlainSurface(vd->sys->d3ddev,
-                                                          vd->fmt.i_width,
-                                                          vd->fmt.i_height,
-                                                          MAKEFOURCC('N','V','1','2'),
-                                                          D3DPOOL_DEFAULT,
-                                                          &picsys->surface,
-                                                          NULL);
-        if (FAILED(hr)) {
-           msg_Err(vd, "Failed to allocate surface %d (hr=0x%0lx)", picture_count, hr);
-           goto error;
-        }
-
-        picture_resource_t resource = {
-            .p_sys = picsys,
-            .pf_destroy = DestroyPicture,
-        };
-
-        picture_t *picture = picture_NewFromResource(&vd->fmt, &resource);
-        if (unlikely(picture == NULL)) {
-            free(picsys);
-            goto error;
-        }
-
-        pictures[picture_count] = picture;
-    }
-
-    picture_pool_configuration_t pool_cfg;
-    memset(&pool_cfg, 0, sizeof(pool_cfg));
-    pool_cfg.picture_count = count;
-    pool_cfg.picture       = pictures;
-
-    vd->sys->pool = picture_pool_NewExtended( &pool_cfg );
-
-error:
-    if (vd->sys->pool == NULL && pictures) {
-        for (unsigned i=0;i<picture_count; ++i)
-            DestroyPicture(pictures[i]);
-    }
-    free(pictures);
-    return vd->sys->pool;
-}
-
-static int  Direct3D9LockSurface(picture_t *);
-static void Direct3D9UnlockSurface(picture_t *);
-
-static void Prepare(vout_display_t *vd, picture_t *picture, subpicture_t *subpicture)
-{
-    vout_display_sys_t *sys = vd->sys;
-    LPDIRECT3DSURFACE9 surface = picture->p_sys->surface;
-
-    /* FIXME it is a bit ugly, we need the surface to be unlocked for
-     * rendering.
-     *  The clean way would be to release the picture (and ensure that
-     * the vout doesn't keep a reference). But because of the vout
-     * wrapper, we can't */
-    if ( picture->format.i_chroma != VLC_CODEC_D3D9_OPAQUE )
-        Direct3D9UnlockSurface(picture);
-
-    /* check if device is still available */
-    HRESULT hr = IDirect3DDevice9_TestCooperativeLevel(sys->d3ddev);
-    if (FAILED(hr)) {
-        if (hr == D3DERR_DEVICENOTRESET && !sys->reset_device) {
-            vout_display_SendEventPicturesInvalid(vd);
-            sys->reset_device = true;
-            sys->lost_not_ready = false;
-        }
-        if (hr == D3DERR_DEVICELOST && !sys->lost_not_ready) {
-            /* Device is lost but not yet ready for reset. */
-            sys->lost_not_ready = true;
-        }
-        return;
-    }
-
-    d3d_region_t picture_region;
-    if (!Direct3D9ImportPicture(vd, &picture_region, surface)) {
-        picture_region.width = picture->format.i_visible_width;
-        picture_region.height = picture->format.i_visible_height;
-        int subpicture_region_count     = 0;
-        d3d_region_t *subpicture_region = NULL;
-        if (subpicture)
-            Direct3D9ImportSubpicture(vd, &subpicture_region_count, &subpicture_region,
-                                     subpicture);
-
-        Direct3D9RenderScene(vd, &picture_region,
-                            subpicture_region_count, subpicture_region);
-
-        Direct3D9DeleteRegions(sys->d3dregion_count, sys->d3dregion);
-        sys->d3dregion_count = subpicture_region_count;
-        sys->d3dregion       = subpicture_region;
-    }
-}
-
-static void Display(vout_display_t *vd, picture_t *picture, subpicture_t *subpicture)
-{
-    vout_display_sys_t *sys = vd->sys;
-
-    if (sys->lost_not_ready) {
-        picture_Release(picture);
-        if (subpicture)
-            subpicture_Delete(subpicture);
-        return;
-    }
-
-    // Present the back buffer contents to the display
-    // No stretching should happen here !
-    const RECT src = sys->rect_dest_clipped;
-    const RECT dst = sys->rect_dest_clipped;
-
-    HRESULT hr;
-    if (sys->use_d3d9ex) {
-        LPDIRECT3DDEVICE9EX d3ddev = (LPDIRECT3DDEVICE9EX)sys->d3ddev;
-        hr = IDirect3DDevice9Ex_PresentEx(d3ddev, &src, &dst, NULL, NULL, 0);
-    } else {
-        LPDIRECT3DDEVICE9 d3ddev = sys->d3ddev;
-        hr = IDirect3DDevice9_Present(d3ddev, &src, &dst, NULL, NULL);
-    }
-    if (FAILED(hr)) {
-        msg_Dbg(vd, "Failed IDirect3DDevice9_Present: 0x%0lx", hr);
-    }
-
-    /* XXX See Prepare() */
-    if ( picture->format.i_chroma != VLC_CODEC_D3D9_OPAQUE )
-        Direct3D9LockSurface(picture);
-    picture_Release(picture);
-    if (subpicture)
-        subpicture_Delete(subpicture);
-
-    CommonDisplay(vd);
-}
-static int ControlResetDevice(vout_display_t *vd)
-{
-    return Direct3D9Reset(vd);
-}
-static int ControlReopenDevice(vout_display_t *vd)
-{
-    vout_display_sys_t *sys = vd->sys;
-
-    if (!sys->use_desktop) {
-        /* Save non-desktop state */
-        sys->desktop_save.is_fullscreen = vd->cfg->is_fullscreen;
-        sys->desktop_save.is_on_top     = sys->is_on_top;
-
-        WINDOWPLACEMENT wp = { .length = sizeof(wp), };
-        GetWindowPlacement(sys->hparent ? sys->hparent : sys->hwnd, &wp);
-        sys->desktop_save.win = wp.rcNormalPosition;
-    }
-
-    /* */
-    Direct3D9Close(vd);
-    EventThreadStop(sys->event);
-
-    /* */
-    vlc_mutex_lock(&sys->lock);
-    sys->use_desktop = sys->desktop_requested;
-    sys->ch_desktop = false;
-    vlc_mutex_unlock(&sys->lock);
-
-    /* */
-    event_cfg_t cfg;
-    memset(&cfg, 0, sizeof(cfg));
-    cfg.use_desktop = sys->use_desktop;
-    if (!sys->use_desktop) {
-        cfg.x      = sys->desktop_save.win.left;
-        cfg.y      = sys->desktop_save.win.top;
-        cfg.width  = sys->desktop_save.win.right  - sys->desktop_save.win.left;
-        cfg.height = sys->desktop_save.win.bottom - sys->desktop_save.win.top;
-    }
-
-    event_hwnd_t hwnd;
-    if (EventThreadStart(sys->event, &hwnd, &cfg)) {
-        msg_Err(vd, "Failed to restart event thread");
-        return VLC_EGENERIC;
-    }
-    sys->parent_window = hwnd.parent_window;
-    sys->hparent       = hwnd.hparent;
-    sys->hwnd          = hwnd.hwnd;
-    sys->hvideownd     = hwnd.hvideownd;
-    sys->hfswnd        = hwnd.hfswnd;
-    SetRectEmpty(&sys->rect_parent);
-
-    /* */
-    video_format_t fmt;
-    if (Direct3D9Open(vd, &fmt)) {
-        CommonClean(vd);
-        msg_Err(vd, "Failed to reopen device");
-        return VLC_EGENERIC;
-    }
-    vd->fmt = fmt;
-    sys->is_first_display = true;
-
-    if (sys->use_desktop) {
-        /* Disable fullscreen/on_top while using desktop */
-        if (sys->desktop_save.is_fullscreen)
-            vout_display_SendEventFullscreen(vd, false);
-        if (sys->desktop_save.is_on_top)
-            vout_display_SendWindowState(vd, VOUT_WINDOW_STATE_NORMAL);
-    } else {
-        /* Restore fullscreen/on_top */
-        if (sys->desktop_save.is_fullscreen)
-            vout_display_SendEventFullscreen(vd, true);
-        if (sys->desktop_save.is_on_top)
-            vout_display_SendWindowState(vd, VOUT_WINDOW_STATE_ABOVE);
-    }
-    return VLC_SUCCESS;
-}
-static int Control(vout_display_t *vd, int query, va_list args)
-{
-    vout_display_sys_t *sys = vd->sys;
-
-    switch (query) {
-    case VOUT_DISPLAY_RESET_PICTURES:
-        /* FIXME what to do here in case of failure */
-        if (sys->reset_device) {
-            if (ControlResetDevice(vd)) {
-                msg_Err(vd, "Failed to reset device");
-                return VLC_EGENERIC;
-            }
-            sys->reset_device = false;
-        } else if(sys->reopen_device) {
-            if (ControlReopenDevice(vd)) {
-                msg_Err(vd, "Failed to reopen device");
-                return VLC_EGENERIC;
-            }
-            sys->reopen_device = false;
-        }
-        return VLC_SUCCESS;
-    default:
-        return CommonControl(vd, query, args);
-    }
-}
-static void Manage (vout_display_t *vd)
-{
-    vout_display_sys_t *sys = vd->sys;
-
-    CommonManage(vd);
-
-    /* Desktop mode change */
-    vlc_mutex_lock(&sys->lock);
-    const bool ch_desktop = sys->ch_desktop;
-    sys->ch_desktop = false;
-    vlc_mutex_unlock(&sys->lock);
-
-    if (ch_desktop) {
-        sys->reopen_device = true;
-        vout_display_SendEventPicturesInvalid(vd);
-    }
-
-    /* Position Change */
-    if (sys->changes & DX_POSITION_CHANGE) {
-#if 0 /* need that when bicubic filter is available */
-        RECT rect;
-        UINT width, height;
-
-        GetClientRect(p_sys->hvideownd, &rect);
-        width  = rect.right-rect.left;
-        height = rect.bottom-rect.top;
-
-        if (width != p_sys->d3dpp.BackBufferWidth || height != p_sys->d3dpp.BackBufferHeight)
-        {
-            msg_Dbg(vd, "resizing device back buffers to (%lux%lu)", width, height);
-            // need to reset D3D device to resize back buffer
-            if (VLC_SUCCESS != Direct3D9ResetDevice(vd, width, height))
-                return VLC_EGENERIC;
-        }
-#endif
-        sys->clear_scene = true;
-        sys->changes &= ~DX_POSITION_CHANGE;
-    }
-}
-
-static HINSTANCE Direct3D9LoadShaderLibrary(void)
-{
-    HINSTANCE instance = NULL;
-    for (int i = 43; i > 23; --i) {
-        TCHAR filename[16];
-        _sntprintf(filename, 16, TEXT("D3dx9_%d.dll"), i);
-        instance = LoadLibrary(filename);
-        if (instance)
-            break;
-    }
-    return instance;
-}
-
-/**
- * It initializes an instance of Direct3D9
- */
-static int Direct3D9Create(vout_display_t *vd)
-{
-    vout_display_sys_t *sys = vd->sys;
-
-    sys->hd3d9_dll = LoadLibrary(TEXT("D3D9.DLL"));
-    if (!sys->hd3d9_dll) {
-        msg_Warn(vd, "cannot load d3d9.dll, aborting");
-        return VLC_EGENERIC;
-    }
-
-    LPDIRECT3D9 (WINAPI *OurDirect3DCreate9)(UINT SDKVersion);
-    OurDirect3DCreate9 =
-        (void *)GetProcAddress(sys->hd3d9_dll, "Direct3DCreate9");
-    if (!OurDirect3DCreate9) {
-        msg_Err(vd, "Cannot locate reference to Direct3DCreate9 ABI in DLL");
-        return VLC_EGENERIC;
-    }
-
-    HRESULT (WINAPI *OurDirect3DCreate9Ex)(UINT SDKVersion, IDirect3D9Ex **ppD3D);
-    OurDirect3DCreate9Ex =
-        (void *)GetProcAddress(sys->hd3d9_dll, "Direct3DCreate9Ex");
-
-    /* Create the D3D object. */
-    if (OurDirect3DCreate9Ex) {
-        LPDIRECT3D9EX d3d9exobj;
-        HRESULT hr = OurDirect3DCreate9Ex(D3D_SDK_VERSION, &d3d9exobj);
-        if(!FAILED(hr)) {
-            msg_Dbg(vd, "Using Direct3D9 Extended API!");
-            sys->d3dobj = (LPDIRECT3D9)d3d9exobj;
-            sys->use_d3d9ex = true;
-        }
-    }
-
-    if (!sys->d3dobj)
-    {
-        LPDIRECT3D9 d3dobj = OurDirect3DCreate9(D3D_SDK_VERSION);
-        if (!d3dobj) {
-            msg_Err(vd, "Could not create Direct3D9 instance.");
-            return VLC_EGENERIC;
-        }
-        sys->d3dobj = d3dobj;
-    }
-
-    sys->hd3d9x_dll = Direct3D9LoadShaderLibrary();
-    if (!sys->hd3d9x_dll)
-        msg_Warn(vd, "cannot load Direct3D9 Shader Library; HLSL pixel shading will be disabled.");
-
-    /*
-    ** Get device capabilities
-    */
-    ZeroMemory(&sys->d3dcaps, sizeof(sys->d3dcaps));
-    HRESULT hr = IDirect3D9_GetDeviceCaps(sys->d3dobj, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &sys->d3dcaps);
-    if (FAILED(hr)) {
-       msg_Err(vd, "Could not read adapter capabilities. (hr=0x%0lx)", hr);
-       return VLC_EGENERIC;
-    }
-
-    /* TODO: need to test device capabilities and select the right render function */
-    if (!(sys->d3dcaps.DevCaps2 & D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES) ||
-        !(sys->d3dcaps.TextureFilterCaps & (D3DPTFILTERCAPS_MAGFLINEAR)) ||
-        !(sys->d3dcaps.TextureFilterCaps & (D3DPTFILTERCAPS_MINFLINEAR))) {
-        msg_Err(vd, "Device does not support stretching from textures.");
-        return VLC_EGENERIC;
-    }
-
-    return VLC_SUCCESS;
-}
-
-/**
- * It releases an instance of Direct3D9
- */
-static void Direct3D9Destroy(vout_display_t *vd)
-{
-    vout_display_sys_t *sys = vd->sys;
-
-    if (sys->d3dobj)
-       IDirect3D9_Release(sys->d3dobj);
-    if (sys->hd3d9_dll)
-        FreeLibrary(sys->hd3d9_dll);
-    if (sys->hd3d9x_dll)
-        FreeLibrary(sys->hd3d9x_dll);
-
-    sys->d3dobj = NULL;
-    sys->hd3d9_dll = NULL;
-    sys->hd3d9x_dll = NULL;
-}
-
-
-/**
- * It setup vout_display_sys_t::d3dpp and vout_display_sys_t::rect_display
- * from the default adapter.
- */
-static int Direct3D9FillPresentationParameters(vout_display_t *vd)
-{
-    vout_display_sys_t *sys = vd->sys;
-
-    /*
-    ** Get the current desktop display mode, so we can set up a back
-    ** buffer of the same format
-    */
-    D3DDISPLAYMODE d3ddm;
-    HRESULT hr = IDirect3D9_GetAdapterDisplayMode(sys->d3dobj,
-                                                  D3DADAPTER_DEFAULT, &d3ddm);
-    if (FAILED(hr)) {
-       msg_Err(vd, "Could not read adapter display mode. (hr=0x%0lx)", hr);
-       return VLC_EGENERIC;
-    }
-
-    /* Set up the structure used to create the D3DDevice. */
-    D3DPRESENT_PARAMETERS *d3dpp = &vd->sys->d3dpp;
-    ZeroMemory(d3dpp, sizeof(D3DPRESENT_PARAMETERS));
-    d3dpp->Flags                  = D3DPRESENTFLAG_VIDEO;
-    d3dpp->Windowed               = TRUE;
-    d3dpp->hDeviceWindow          = vd->sys->hvideownd;
-    d3dpp->BackBufferWidth        = __MAX((unsigned int)GetSystemMetrics(SM_CXVIRTUALSCREEN),
-                                          d3ddm.Width);
-    d3dpp->BackBufferHeight       = __MAX((unsigned int)GetSystemMetrics(SM_CYVIRTUALSCREEN),
-                                          d3ddm.Height);
-    d3dpp->SwapEffect             = D3DSWAPEFFECT_COPY;
-    d3dpp->MultiSampleType        = D3DMULTISAMPLE_NONE;
-    d3dpp->PresentationInterval   = D3DPRESENT_INTERVAL_DEFAULT;
-    d3dpp->BackBufferFormat       = d3ddm.Format;
-    d3dpp->BackBufferCount        = 1;
-    d3dpp->EnableAutoDepthStencil = FALSE;
-
-    /* */
-    RECT *display = &vd->sys->rect_display;
-    display->left   = 0;
-    display->top    = 0;
-    display->right  = d3dpp->BackBufferWidth;
-    display->bottom = d3dpp->BackBufferHeight;
-
-    return VLC_SUCCESS;
-}
-
-/* */
-static int  Direct3D9CreateResources (vout_display_t *, video_format_t *);
-static void Direct3D9DestroyResources(vout_display_t *);
-
-/**
- * It creates a Direct3D9 device and the associated resources.
- */
-static int Direct3D9Open(vout_display_t *vd, video_format_t *fmt)
-{
-    vout_display_sys_t *sys = vd->sys;
-    LPDIRECT3D9 d3dobj = sys->d3dobj;
-
-    if (Direct3D9FillPresentationParameters(vd))
-        return VLC_EGENERIC;
-
-
-    UINT AdapterToUse = D3DADAPTER_DEFAULT;
-    D3DDEVTYPE DeviceType = D3DDEVTYPE_HAL;
-
-#ifndef NDEBUG
-    // Look for 'NVIDIA PerfHUD' adapter
-    // If it is present, override default settings
-    for (UINT Adapter=0; Adapter< IDirect3D9_GetAdapterCount(d3dobj); ++Adapter) {
-        D3DADAPTER_IDENTIFIER9 Identifier;
-        HRESULT Res = IDirect3D9_GetAdapterIdentifier(d3dobj,Adapter,0,&Identifier);
-        if (SUCCEEDED(Res) && strstr(Identifier.Description,"PerfHUD") != 0) {
-            AdapterToUse = Adapter;
-            DeviceType = D3DDEVTYPE_REF;
-            break;
-        }
-    }
-#endif
-
-    /* */
-    D3DADAPTER_IDENTIFIER9 d3dai;
-    if (FAILED(IDirect3D9_GetAdapterIdentifier(d3dobj,AdapterToUse,0, &d3dai))) {
-        msg_Warn(vd, "IDirect3D9_GetAdapterIdentifier failed");
-    } else {
-        msg_Dbg(vd, "Direct3d9 Device: %s %lu %lu %lu", d3dai.Description,
-                d3dai.VendorId, d3dai.DeviceId, d3dai.Revision );
-    }
-
-    // Create the D3DDevice
-    HRESULT hr;
-    if (sys->use_d3d9ex) {
-        LPDIRECT3DDEVICE9EX d3ddevex;
-        hr = IDirect3D9Ex_CreateDeviceEx((LPDIRECT3D9EX)d3dobj, AdapterToUse,
-                                         DeviceType, sys->hvideownd,
-                                         D3DCREATE_SOFTWARE_VERTEXPROCESSING|
-                                         D3DCREATE_MULTITHREADED,
-                                         &sys->d3dpp, NULL, &d3ddevex);
-        sys->d3ddev = (LPDIRECT3DDEVICE9)d3ddevex;
-    } else {
-        LPDIRECT3DDEVICE9 d3ddev;
-        hr = IDirect3D9_CreateDevice(d3dobj, AdapterToUse,
-                                     DeviceType, sys->hvideownd,
-                                     D3DCREATE_SOFTWARE_VERTEXPROCESSING|
-                                     D3DCREATE_MULTITHREADED,
-                                     &sys->d3dpp, &d3ddev);
-        sys->d3ddev = d3ddev;
-    }
-
-    if (FAILED(hr)) {
-       msg_Err(vd, "Could not create the D3D9 device! (hr=0x%0lx)", hr);
-       return VLC_EGENERIC;
-    }
-
-    UpdateRects(vd, NULL, NULL, true);
-
-    if (Direct3D9CreateResources(vd, fmt)) {
-        msg_Err(vd, "Failed to allocate resources");
-        return VLC_EGENERIC;
-    }
-
-    /* Change the window title bar text */
-    EventThreadUpdateTitle(sys->event, VOUT_TITLE " (Direct3D9 output)");
-
-    msg_Dbg(vd, "Direct3D9 device adapter successfully initialized");
-    return VLC_SUCCESS;
-}
-
-/**
- * It releases the Direct3D9 device and its resources.
- */
-static void Direct3D9Close(vout_display_t *vd)
-{
-    vout_display_sys_t *sys = vd->sys;
-
-    Direct3D9DestroyResources(vd);
-
-    if (sys->d3ddev)
-       IDirect3DDevice9_Release(sys->d3ddev);
-
-    sys->d3ddev = NULL;
-}
-
-/**
- * It reset the Direct3D9 device and its resources.
- */
-static int Direct3D9Reset(vout_display_t *vd)
-{
-    vout_display_sys_t *sys = vd->sys;
-
-    if (Direct3D9FillPresentationParameters(vd))
-        return VLC_EGENERIC;
-
-    /* release all D3D objects */
-    Direct3D9DestroyResources(vd);
-
-    /* */
-    HRESULT hr;
-    if (sys->use_d3d9ex){
-        LPDIRECT3DDEVICE9EX d3ddev = (LPDIRECT3DDEVICE9EX)sys->d3ddev;
-        hr = IDirect3DDevice9Ex_ResetEx(d3ddev, &sys->d3dpp, NULL);
-    } else {
-        LPDIRECT3DDEVICE9 d3ddev = sys->d3ddev;
-        hr = IDirect3DDevice9_Reset(d3ddev, &sys->d3dpp);
-    }
-    if (FAILED(hr)) {
-        msg_Err(vd, "IDirect3DDevice9_Reset failed! (hr=0x%0lx)", hr);
-        return VLC_EGENERIC;
-    }
-
-    UpdateRects(vd, NULL, NULL, true);
-
-    /* re-create them */
-    if (Direct3D9CreateResources(vd, &vd->fmt)) {
-        msg_Dbg(vd, "Direct3D9CreateResources failed !");
-        return VLC_EGENERIC;
-    }
-    return VLC_SUCCESS;
-}
-
-/* */
-static int  Direct3D9CreatePool(vout_display_t *vd, video_format_t *fmt);
-static void Direct3D9DestroyPool(vout_display_t *vd);
-
-static int  Direct3D9CreateScene(vout_display_t *vd, const video_format_t *fmt);
-static void Direct3D9DestroyScene(vout_display_t *vd);
-
-static int  Direct3D9CreateShaders(vout_display_t *vd);
-static void Direct3D9DestroyShaders(vout_display_t *vd);
-
-/**
- * It creates the picture and scene resources.
- */
-static int Direct3D9CreateResources(vout_display_t *vd, video_format_t *fmt)
-{
-    vout_display_sys_t *sys = vd->sys;
-
-    if (Direct3D9CreatePool(vd, fmt)) {
-        msg_Err(vd, "Direct3D picture pool initialization failed");
-        return VLC_EGENERIC;
-    }
-    if (Direct3D9CreateScene(vd, fmt)) {
-        msg_Err(vd, "Direct3D scene initialization failed !");
-        return VLC_EGENERIC;
-    }
-    if (Direct3D9CreateShaders(vd)) {
-        /* Failing to initialize shaders is not fatal. */
-        msg_Warn(vd, "Direct3D shaders initialization failed !");
-    }
-
-    sys->d3dregion_format = D3DFMT_UNKNOWN;
-    for (int i = 0; i < 2; i++) {
-        D3DFORMAT fmt = i == 0 ? D3DFMT_A8B8G8R8 : D3DFMT_A8R8G8B8;
-        if (SUCCEEDED(IDirect3D9_CheckDeviceFormat(sys->d3dobj,
-                                                   D3DADAPTER_DEFAULT,
-                                                   D3DDEVTYPE_HAL,
-                                                   sys->d3dpp.BackBufferFormat,
-                                                   D3DUSAGE_DYNAMIC,
-                                                   D3DRTYPE_TEXTURE,
-                                                   fmt))) {
-            sys->d3dregion_format = fmt;
-            break;
-        }
-    }
-    return VLC_SUCCESS;
-}
-/**
- * It destroys the picture and scene resources.
- */
-static void Direct3D9DestroyResources(vout_display_t *vd)
-{
-    Direct3D9DestroyScene(vd);
-    Direct3D9DestroyPool(vd);
-    Direct3D9DestroyShaders(vd);
-}
-
-/**
- * It tests if the conversion from src to dst is supported.
- */
-static int Direct3D9CheckConversion(vout_display_t *vd,
-                                   D3DFORMAT src, D3DFORMAT dst)
-{
-    vout_display_sys_t *sys = vd->sys;
-    LPDIRECT3D9 d3dobj = sys->d3dobj;
-    HRESULT hr;
-
-    /* test whether device can create a surface of that format */
-    hr = IDirect3D9_CheckDeviceFormat(d3dobj, D3DADAPTER_DEFAULT,
-                                      D3DDEVTYPE_HAL, dst, 0,
-                                      D3DRTYPE_SURFACE, src);
-    if (SUCCEEDED(hr)) {
-        /* test whether device can perform color-conversion
-        ** from that format to target format
-        */
-        hr = IDirect3D9_CheckDeviceFormatConversion(d3dobj,
-                                                    D3DADAPTER_DEFAULT,
-                                                    D3DDEVTYPE_HAL,
-                                                    src, dst);
-    }
-    if (!SUCCEEDED(hr)) {
-        if (D3DERR_NOTAVAILABLE != hr)
-            msg_Err(vd, "Could not query adapter supported formats. (hr=0x%0lx)", hr);
-        return VLC_EGENERIC;
-    }
-    return VLC_SUCCESS;
-}
-
-typedef struct
-{
-    const char   *name;
-    D3DFORMAT    format;    /* D3D format */
-    vlc_fourcc_t fourcc;    /* VLC fourcc */
-    uint32_t     rmask;
-    uint32_t     gmask;
-    uint32_t     bmask;
-} d3d_format_t;
-
-static const d3d_format_t d3d_formats[] = {
-    /* YV12 is always used for planar 420, the planes are then swapped in Lock() */
-    { "YV12",       MAKEFOURCC('Y','V','1','2'),    VLC_CODEC_YV12,  0,0,0 },
-    { "YV12",       MAKEFOURCC('Y','V','1','2'),    VLC_CODEC_I420,  0,0,0 },
-    { "YV12",       MAKEFOURCC('Y','V','1','2'),    VLC_CODEC_J420,  0,0,0 },
-    { "NV12",       MAKEFOURCC('N','V','1','2'),    VLC_CODEC_NV12,  0,0,0 },
-    { "DXA9",       MAKEFOURCC('N','V','1','2'),    VLC_CODEC_D3D9_OPAQUE,  0,0,0 },
-    { "UYVY",       D3DFMT_UYVY,    VLC_CODEC_UYVY,  0,0,0 },
-    { "YUY2",       D3DFMT_YUY2,    VLC_CODEC_YUYV,  0,0,0 },
-    { "X8R8G8B8",   D3DFMT_X8R8G8B8,VLC_CODEC_RGB32, 0xff0000, 0x00ff00, 0x0000ff },
-    { "A8R8G8B8",   D3DFMT_A8R8G8B8,VLC_CODEC_RGB32, 0xff0000, 0x00ff00, 0x0000ff },
-    { "8G8B8",      D3DFMT_R8G8B8,  VLC_CODEC_RGB24, 0xff0000, 0x00ff00, 0x0000ff },
-    { "R5G6B5",     D3DFMT_R5G6B5,  VLC_CODEC_RGB16, 0x1f<<11, 0x3f<<5,  0x1f<<0 },
-    { "X1R5G5B5",   D3DFMT_X1R5G5B5,VLC_CODEC_RGB15, 0x1f<<10, 0x1f<<5,  0x1f<<0 },
-
-    { NULL, 0, 0, 0,0,0}
-};
-
-/**
- * It returns the format (closest to chroma) that can be converted to target */
-static const d3d_format_t *Direct3DFindFormat(vout_display_t *vd, vlc_fourcc_t chroma, D3DFORMAT target)
-{
-    vout_display_sys_t *sys = vd->sys;
-
-    for (unsigned pass = 0; pass < 2; pass++) {
-        const vlc_fourcc_t *list;
-        const vlc_fourcc_t dxva_chroma[] = {chroma, 0};
-
-        if (pass == 0 && chroma == VLC_CODEC_D3D9_OPAQUE)
-            list = dxva_chroma;
-        else if (pass == 0 && sys->allow_hw_yuv && vlc_fourcc_IsYUV(chroma))
-            list = vlc_fourcc_GetYUVFallback(chroma);
-        else if (pass == 1)
-            list = vlc_fourcc_GetRGBFallback(chroma);
-        else
-            continue;
-
-        for (unsigned i = 0; list[i] != 0; i++) {
-            for (unsigned j = 0; d3d_formats[j].name; j++) {
-                const d3d_format_t *format = &d3d_formats[j];
-
-                if (format->fourcc != list[i])
-                    continue;
-
-                msg_Warn(vd, "trying surface pixel format: %s",
-                         format->name);
-                if (!Direct3D9CheckConversion(vd, format->format, target)) {
-                    msg_Dbg(vd, "selected surface pixel format is %s",
-                            format->name);
-                    return format;
-                }
-            }
-        }
-    }
-    return NULL;
-}
-
-/**
- * It locks the surface associated to the picture and get the surface
- * descriptor which amongst other things has the pointer to the picture
- * data and its pitch.
- */
-static int Direct3D9LockSurface(picture_t *picture)
-{
-    /* Lock the surface to get a valid pointer to the picture buffer */
-    D3DLOCKED_RECT d3drect;
-    HRESULT hr = IDirect3DSurface9_LockRect(picture->p_sys->surface, &d3drect, NULL, 0);
-    if (FAILED(hr)) {
-        //msg_Dbg(vd, "Failed IDirect3DSurface9_LockRect: 0x%0lx", hr);
-        return CommonUpdatePicture(picture, &picture->p_sys->fallback, NULL, 0);
-    }
-
-    CommonUpdatePicture(picture, NULL, d3drect.pBits, d3drect.Pitch);
-    return VLC_SUCCESS;
-}
-/**
- * It unlocks the surface associated to the picture.
- */
-static void Direct3D9UnlockSurface(picture_t *picture)
-{
-    /* Unlock the Surface */
-    HRESULT hr = IDirect3DSurface9_UnlockRect(picture->p_sys->surface);
-    if (FAILED(hr)) {
-        //msg_Dbg(vd, "Failed IDirect3DSurface9_UnlockRect: 0x%0lx", hr);
-    }
-}
-
-/**
- * It creates the pool of picture (only 1).
- *
- * Each picture has an associated offscreen surface in video memory
- * depending on hardware capabilities the picture chroma will be as close
- * as possible to the orginal render chroma to reduce CPU conversion overhead
- * and delegate this work to video card GPU
- */
-static int Direct3D9CreatePool(vout_display_t *vd, video_format_t *fmt)
-{
-    vout_display_sys_t *sys = vd->sys;
-    LPDIRECT3DDEVICE9 d3ddev = sys->d3ddev;
-
-    /* */
-    *fmt = vd->source;
-
-    /* Find the appropriate D3DFORMAT for the render chroma, the format will be the closest to
-     * the requested chroma which is usable by the hardware in an offscreen surface, as they
-     * typically support more formats than textures */
-    const d3d_format_t *d3dfmt = Direct3DFindFormat(vd, fmt->i_chroma, sys->d3dpp.BackBufferFormat);
-    if (!d3dfmt) {
-        msg_Err(vd, "surface pixel format is not supported.");
-        return VLC_EGENERIC;
-    }
-    fmt->i_chroma = d3dfmt->fourcc;
-    fmt->i_rmask  = d3dfmt->rmask;
-    fmt->i_gmask  = d3dfmt->gmask;
-    fmt->i_bmask  = d3dfmt->bmask;
-
-    if ( fmt->i_chroma == VLC_CODEC_D3D9_OPAQUE )
-        /* a DXA9 pool will be created when needed */
-        return VLC_SUCCESS;
-
-    /* We create one picture.
-     * It is useless to create more as we can't be used for direct rendering */
-
-    /* Create a surface */
-    LPDIRECT3DSURFACE9 surface;
-    HRESULT hr = IDirect3DDevice9_CreateOffscreenPlainSurface(d3ddev,
-                                                              fmt->i_width,
-                                                              fmt->i_height,
-                                                              d3dfmt->format,
-                                                              D3DPOOL_DEFAULT,
-                                                              &surface,
-                                                              NULL);
-    if (FAILED(hr)) {
-        msg_Err(vd, "Failed to create picture surface. (hr=0x%lx)", hr);
-        return VLC_EGENERIC;
-    }
-
-#ifndef NDEBUG
-    msg_Dbg(vd, "Direct3D created offscreen surface: %ix%i",
-                fmt->i_width, fmt->i_height);
-#endif
-
-    /* fill surface with black color */
-    IDirect3DDevice9_ColorFill(d3ddev, surface, NULL, D3DCOLOR_ARGB(0xFF, 0, 0, 0));
-
-    /* Create the associated picture */
-    picture_sys_t *picsys = malloc(sizeof(*picsys));
-    if (unlikely(picsys == NULL)) {
-        IDirect3DSurface9_Release(surface);
-        return VLC_ENOMEM;
-    }
-    picsys->surface = surface;
-    picsys->fallback = NULL;
-
-    picture_resource_t resource = { .p_sys = picsys };
-    for (int i = 0; i < PICTURE_PLANE_MAX; i++)
-        resource.p[i].i_lines = fmt->i_height / (i > 0 ? 2 : 1);
-
-    picture_t *picture = picture_NewFromResource(fmt, &resource);
-    if (!picture) {
-        msg_Err(vd, "Failed to create a picture from resources.");
-        IDirect3DSurface9_Release(surface);
-        free(picsys);
-        return VLC_ENOMEM;
-    }
-    sys->picsys = picsys;
-
-    /* Wrap it into a picture pool */
-    picture_pool_configuration_t pool_cfg;
-    memset(&pool_cfg, 0, sizeof(pool_cfg));
-    pool_cfg.picture_count = 1;
-    pool_cfg.picture       = &picture;
-    pool_cfg.lock          = Direct3D9LockSurface;
-    pool_cfg.unlock        = Direct3D9UnlockSurface;
-
-    sys->pool = picture_pool_NewExtended(&pool_cfg);
-    if (!sys->pool) {
-        picture_Release(picture);
-        IDirect3DSurface9_Release(surface);
-        return VLC_ENOMEM;
-    }
-    return VLC_SUCCESS;
-}
-/**
- * It destroys the pool of picture and its resources.
- */
-static void Direct3D9DestroyPool(vout_display_t *vd)
-{
-    vout_display_sys_t *sys = vd->sys;
-
-    if (sys->pool) {
-        picture_sys_t *picsys = sys->picsys;
-        if ( picsys != NULL ) {
-            IDirect3DSurface9_Release(picsys->surface);
-            if (picsys->fallback)
-                picture_Release(picsys->fallback);
-        }
-        picture_pool_Release(sys->pool);
-    }
-    sys->pool = NULL;
-}
-
-/**
- * It allocates and initializes the resources needed to render the scene.
- */
-static int Direct3D9CreateScene(vout_display_t *vd, const video_format_t *fmt)
-{
-    vout_display_sys_t *sys = vd->sys;
-    LPDIRECT3DDEVICE9       d3ddev = sys->d3ddev;
-    HRESULT hr;
-
-    /*
-     * Create a texture for use when rendering a scene
-     * for performance reason, texture format is identical to backbuffer
-     * which would usually be a RGB format
-     */
-    LPDIRECT3DTEXTURE9 d3dtex;
-    hr = IDirect3DDevice9_CreateTexture(d3ddev,
-                                        fmt->i_visible_width,
-                                        fmt->i_visible_height,
-                                        1,
-                                        D3DUSAGE_RENDERTARGET,
-                                        sys->d3dpp.BackBufferFormat,
-                                        D3DPOOL_DEFAULT,
-                                        &d3dtex,
-                                        NULL);
-    if (FAILED(hr)) {
-        msg_Err(vd, "Failed to create texture. (hr=0x%lx)", hr);
-        return VLC_EGENERIC;
-    }
-
-#ifndef NDEBUG
-    msg_Dbg(vd, "Direct3D created texture: %ix%i",
-                fmt->i_width, fmt->i_height);
-#endif
-
-    /*
-    ** Create a vertex buffer for use when rendering scene
-    */
-    LPDIRECT3DVERTEXBUFFER9 d3dvtc;
-    hr = IDirect3DDevice9_CreateVertexBuffer(d3ddev,
-                                             sizeof(CUSTOMVERTEX)*4,
-                                             D3DUSAGE_DYNAMIC|D3DUSAGE_WRITEONLY,
-                                             D3DFVF_CUSTOMVERTEX,
-                                             D3DPOOL_DEFAULT,
-                                             &d3dvtc,
-                                             NULL);
-    if (FAILED(hr)) {
-        msg_Err(vd, "Failed to create vertex buffer. (hr=0x%lx)", hr);
-        IDirect3DTexture9_Release(d3dtex);
-        return VLC_EGENERIC;
-    }
-
-    /* */
-    sys->d3dtex = d3dtex;
-    sys->d3dvtc = d3dvtc;
-
-    sys->d3dregion_count = 0;
-    sys->d3dregion       = NULL;
-
-    sys->clear_scene = true;
-
-    // Texture coordinates outside the range [0.0, 1.0] are set
-    // to the texture color at 0.0 or 1.0, respectively.
-    IDirect3DDevice9_SetSamplerState(d3ddev, 0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);
-    IDirect3DDevice9_SetSamplerState(d3ddev, 0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);
-
-    // Set linear filtering quality
-    if (sys->d3dcaps.TextureFilterCaps & D3DPTFILTERCAPS_MINFLINEAR) {
-        //msg_Dbg(vd, "Using D3DTEXF_LINEAR for minification");
-        IDirect3DDevice9_SetSamplerState(d3ddev, 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
-    } else {
-        //msg_Dbg(vd, "Using D3DTEXF_POINT for minification");
-        IDirect3DDevice9_SetSamplerState(d3ddev, 0, D3DSAMP_MINFILTER, D3DTEXF_POINT);
-    }
-    if (sys->d3dcaps.TextureFilterCaps & D3DPTFILTERCAPS_MAGFLINEAR) {
-        //msg_Dbg(vd, "Using D3DTEXF_LINEAR for magnification");
-        IDirect3DDevice9_SetSamplerState(d3ddev, 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
-    } else {
-        //msg_Dbg(vd, "Using D3DTEXF_POINT for magnification");
-        IDirect3DDevice9_SetSamplerState(d3ddev, 0, D3DSAMP_MAGFILTER, D3DTEXF_POINT);
-    }
-
-    // set maximum ambient light
-    IDirect3DDevice9_SetRenderState(d3ddev, D3DRS_AMBIENT, D3DCOLOR_XRGB(255,255,255));
-
-    // Turn off culling
-    IDirect3DDevice9_SetRenderState(d3ddev, D3DRS_CULLMODE, D3DCULL_NONE);
-
-    // Turn off the zbuffer
-    IDirect3DDevice9_SetRenderState(d3ddev, D3DRS_ZENABLE, D3DZB_FALSE);
-
-    // Turn off lights
-    IDirect3DDevice9_SetRenderState(d3ddev, D3DRS_LIGHTING, FALSE);
-
-    // Enable dithering
-    IDirect3DDevice9_SetRenderState(d3ddev, D3DRS_DITHERENABLE, TRUE);
-
-    // disable stencil
-    IDirect3DDevice9_SetRenderState(d3ddev, D3DRS_STENCILENABLE, FALSE);
-
-    // manage blending
-    IDirect3DDevice9_SetRenderState(d3ddev, D3DRS_ALPHABLENDENABLE, FALSE);
-    IDirect3DDevice9_SetRenderState(d3ddev, D3DRS_SRCBLEND,D3DBLEND_SRCALPHA);
-    IDirect3DDevice9_SetRenderState(d3ddev, D3DRS_DESTBLEND,D3DBLEND_INVSRCALPHA);
-
-    if (sys->d3dcaps.AlphaCmpCaps & D3DPCMPCAPS_GREATER) {
-        IDirect3DDevice9_SetRenderState(d3ddev, D3DRS_ALPHATESTENABLE,TRUE);
-        IDirect3DDevice9_SetRenderState(d3ddev, D3DRS_ALPHAREF, 0x00);
-        IDirect3DDevice9_SetRenderState(d3ddev, D3DRS_ALPHAFUNC,D3DCMP_GREATER);
-    }
-
-    // Set texture states
-    IDirect3DDevice9_SetTextureStageState(d3ddev, 0, D3DTSS_COLOROP,D3DTOP_SELECTARG1);
-    IDirect3DDevice9_SetTextureStageState(d3ddev, 0, D3DTSS_COLORARG1,D3DTA_TEXTURE);
-
-    IDirect3DDevice9_SetTextureStageState(d3ddev, 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
-    IDirect3DDevice9_SetTextureStageState(d3ddev, 0, D3DTSS_ALPHAARG1,D3DTA_TEXTURE);
-    IDirect3DDevice9_SetTextureStageState(d3ddev, 0, D3DTSS_ALPHAARG2,D3DTA_DIFFUSE);
-
-    msg_Dbg(vd, "Direct3D9 scene created successfully");
-
-    return VLC_SUCCESS;
-}
-
-/**
- * It releases the scene resources.
- */
-static void Direct3D9DestroyScene(vout_display_t *vd)
-{
-    vout_display_sys_t *sys = vd->sys;
-
-    Direct3D9DeleteRegions(sys->d3dregion_count, sys->d3dregion);
-
-    LPDIRECT3DVERTEXBUFFER9 d3dvtc = sys->d3dvtc;
-    if (d3dvtc)
-        IDirect3DVertexBuffer9_Release(d3dvtc);
-
-    LPDIRECT3DTEXTURE9 d3dtex = sys->d3dtex;
-    if (d3dtex)
-        IDirect3DTexture9_Release(d3dtex);
-
-    sys->d3dvtc = NULL;
-    sys->d3dtex = NULL;
-
-    sys->d3dregion_count = 0;
-    sys->d3dregion       = NULL;
-
-    msg_Dbg(vd, "Direct3D9 scene released successfully");
-}
-
-static int Direct3D9CompileShader(vout_display_t *vd, const char *shader_source, size_t source_length)
-{
-    vout_display_sys_t *sys = vd->sys;
-
-    HRESULT (WINAPI * OurD3DXCompileShader)(
-            LPCSTR pSrcData,
-            UINT srcDataLen,
-            const D3DXMACRO *pDefines,
-            LPD3DXINCLUDE pInclude,
-            LPCSTR pFunctionName,
-            LPCSTR pProfile,
-            DWORD Flags,
-            LPD3DXBUFFER *ppShader,
-            LPD3DXBUFFER *ppErrorMsgs,
-            LPD3DXCONSTANTTABLE *ppConstantTable);
-
-    OurD3DXCompileShader = (void*)GetProcAddress(sys->hd3d9x_dll, "D3DXCompileShader");
-    if (!OurD3DXCompileShader) {
-        msg_Warn(vd, "Cannot locate reference to D3DXCompileShader; pixel shading will be disabled");
-        return VLC_EGENERIC;
-    }
-
-    LPD3DXBUFFER error_msgs = NULL;
-    LPD3DXBUFFER compiled_shader = NULL;
-
-    DWORD shader_flags = 0;
-    HRESULT hr = OurD3DXCompileShader(shader_source, source_length, NULL, NULL,
-                "main", "ps_3_0", shader_flags, &compiled_shader, &error_msgs, NULL);
-
-    if (FAILED(hr)) {
-        msg_Warn(vd, "D3DXCompileShader Error (hr=0x%0lx)", hr);
-        if (error_msgs) {
-            msg_Warn(vd, "HLSL Compilation Error: %s", (char*)ID3DXBuffer_GetBufferPointer(error_msgs));
-            ID3DXBuffer_Release(error_msgs);
-    }
-        return VLC_EGENERIC;
-    }
-
-    hr = IDirect3DDevice9_CreatePixelShader(sys->d3ddev,
-            ID3DXBuffer_GetBufferPointer(compiled_shader),
-            &sys->d3dx_shader);
-
-    if (compiled_shader)
-        ID3DXBuffer_Release(compiled_shader);
-    if (error_msgs)
-        ID3DXBuffer_Release(error_msgs);
-
-    if (FAILED(hr)) {
-        msg_Warn(vd, "IDirect3DDevice9_CreatePixelShader error (hr=0x%0lx)", hr);
-        return VLC_EGENERIC;
-    }
-    return VLC_SUCCESS;
-}
-
-#define MAX_SHADER_FILE_SIZE 1024*1024
-
-static int Direct3D9CreateShaders(vout_display_t *vd)
-{
-    vout_display_sys_t *sys = vd->sys;
-
-    if (!sys->hd3d9x_dll)
-        return VLC_EGENERIC;
-
-    /* Find which shader was selected in the list. */
-    char *selected_shader = var_InheritString(vd, "direct3d9-shader");
-    if (!selected_shader)
-        return VLC_SUCCESS; /* Nothing to do */
-
-    const char *shader_source_builtin = NULL;
-    char *shader_source_file = NULL;
-    FILE *fs = NULL;
-
-    for (size_t i = 0; i < BUILTIN_SHADERS_COUNT; ++i) {
-        if (!strcmp(selected_shader, builtin_shaders[i].name)) {
-            shader_source_builtin = builtin_shaders[i].code;
-            break;
-        }
-    }
-
-    if (shader_source_builtin) {
-        /* A builtin shader was selected. */
-        int err = Direct3D9CompileShader(vd, shader_source_builtin, strlen(shader_source_builtin));
-        if (err)
-            goto error;
-    } else {
-        if (strcmp(selected_shader, SELECTED_SHADER_FILE))
-            goto error; /* Unrecognized entry in the list. */
-        /* The source code of the shader needs to be read from a file. */
-        char *filepath = var_InheritString(vd, "direct3d9-shader-file");
-        if (!filepath || !*filepath)
-        {
-            free(filepath);
-            goto error;
-        }
-        /* Open file, find its size with fseek/ftell and read its content in a buffer. */
-        fs = fopen(filepath, "rb");
-        if (!fs)
-            goto error;
-        int ret = fseek(fs, 0, SEEK_END);
-        if (ret == -1)
-            goto error;
-        long length = ftell(fs);
-        if (length == -1 || length >= MAX_SHADER_FILE_SIZE)
-            goto error;
-        rewind(fs);
-        shader_source_file = malloc(sizeof(*shader_source_file) * length);
-        if (!shader_source_file)
-            goto error;
-        ret = fread(shader_source_file, length, 1, fs);
-        if (ret != 1)
-            goto error;
-        ret = Direct3D9CompileShader(vd, shader_source_file, length);
-        if (ret)
-            goto error;
-    }
-
-    free(selected_shader);
-    free(shader_source_file);
-    fclose(fs);
-
-    return VLC_SUCCESS;
-
-error:
-    Direct3D9DestroyShaders(vd);
-    free(selected_shader);
-    free(shader_source_file);
-    if (fs)
-        fclose(fs);
-    return VLC_EGENERIC;
-}
-
-static void Direct3D9DestroyShaders(vout_display_t *vd)
-{
-    vout_display_sys_t *sys = vd->sys;
-
-    if (sys->d3dx_shader)
-        IDirect3DPixelShader9_Release(sys->d3dx_shader);
-    sys->d3dx_shader = NULL;
-}
-
-/**
- * Compute the vertex ordering needed to rotate the video. Without
- * rotation, the vertices of the rectangle are defined in a clockwise
- * order. This function computes a remapping of the coordinates to
- * implement the rotation, given fixed texture coordinates.
- * The unrotated order is the following:
- * 0--1
- * |  |
- * 3--2
- * For a 180 degrees rotation it should like this:
- * 2--3
- * |  |
- * 1--0
- * Vertex 0 should be assigned coordinates at index 2 from the
- * unrotated order and so on, thus yielding order: 2 3 0 1.
- */
-static void orientationVertexOrder(video_orientation_t orientation, int vertex_order[static 4])
-{
-    switch (orientation) {
-        case ORIENT_ROTATED_90:
-            vertex_order[0] = 1;
-            vertex_order[1] = 2;
-            vertex_order[2] = 3;
-            vertex_order[3] = 0;
-            break;
-        case ORIENT_ROTATED_270:
-            vertex_order[0] = 3;
-            vertex_order[1] = 0;
-            vertex_order[2] = 1;
-            vertex_order[3] = 2;
-            break;
-        case ORIENT_ROTATED_180:
-            vertex_order[0] = 2;
-            vertex_order[1] = 3;
-            vertex_order[2] = 0;
-            vertex_order[3] = 1;
-            break;
-        case ORIENT_TRANSPOSED:
-            vertex_order[0] = 0;
-            vertex_order[1] = 3;
-            vertex_order[2] = 2;
-            vertex_order[3] = 1;
-            break;
-        case ORIENT_HFLIPPED:
-            vertex_order[0] = 3;
-            vertex_order[1] = 2;
-            vertex_order[2] = 1;
-            vertex_order[3] = 0;
-            break;
-        case ORIENT_VFLIPPED:
-            vertex_order[0] = 1;
-            vertex_order[1] = 0;
-            vertex_order[2] = 3;
-            vertex_order[3] = 2;
-            break;
-        case ORIENT_ANTI_TRANSPOSED: /* transpose + vflip */
-            vertex_order[0] = 1;
-            vertex_order[1] = 2;
-            vertex_order[2] = 3;
-            vertex_order[3] = 0;
-            break;
-       default:
-            vertex_order[0] = 0;
-            vertex_order[1] = 1;
-            vertex_order[2] = 2;
-            vertex_order[3] = 3;
-            break;
-    }
-}
-
-static void Direct3D9SetupVertices(CUSTOMVERTEX *vertices,
-                                  const RECT dst,
-                                  int alpha,
-                                  video_orientation_t orientation)
-{
-    /* Vertices of the dst rectangle in the unrotated (clockwise) order. */
-    const int vertices_coords[4][2] = {
-        { dst.left,  dst.top    },
-        { dst.right, dst.top    },
-        { dst.right, dst.bottom },
-        { dst.left,  dst.bottom },
-    };
-
-    /* Compute index remapping necessary to implement the rotation. */
-    int vertex_order[4];
-    orientationVertexOrder(orientation, vertex_order);
-
-    for (int i = 0; i < 4; ++i) {
-        vertices[i].x  = vertices_coords[vertex_order[i]][0];
-        vertices[i].y  = vertices_coords[vertex_order[i]][1];
-    }
-
-    vertices[0].tu = .0f;
-    vertices[0].tv = .0f;
-
-    vertices[1].tu = 1.f;
-    vertices[1].tv = .0f;
-
-    vertices[2].tu = 1.f;
-    vertices[2].tv = 1.f;
-
-    vertices[3].tu = .0f;
-    vertices[3].tv = 1.f;
-
-    for (int i = 0; i < 4; i++) {
-        /* -0.5f is a "feature" of DirectX and it seems to apply to Direct3d also */
-        /* http://www.sjbrown.co.uk/2003/05/01/fix-directx-rasterisation/ */
-        vertices[i].x -= 0.5;
-        vertices[i].y -= 0.5;
-
-        vertices[i].z       = 0.0f;
-        vertices[i].rhw     = 1.0f;
-        vertices[i].diffuse = D3DCOLOR_ARGB(alpha, 255, 255, 255);
-    }
-}
-
-/**
- * It copies picture surface into a texture and setup the associated d3d_region_t.
- */
-static int Direct3D9ImportPicture(vout_display_t *vd,
-                                 d3d_region_t *region,
-                                 LPDIRECT3DSURFACE9 source)
-{
-    vout_display_sys_t *sys = vd->sys;
-    HRESULT hr;
-
-    if (!source) {
-        msg_Dbg(vd, "no surface to render?");
-        return VLC_EGENERIC;
-    }
-
-    /* retrieve texture top-level surface */
-    LPDIRECT3DSURFACE9 destination;
-    hr = IDirect3DTexture9_GetSurfaceLevel(sys->d3dtex, 0, &destination);
-    if (FAILED(hr)) {
-        msg_Dbg(vd, "Failed IDirect3DTexture9_GetSurfaceLevel: 0x%0lx", hr);
-        return VLC_EGENERIC;
-    }
-
-    /* Copy picture surface into texture surface
-     * color space conversion happen here */
-    hr = IDirect3DDevice9_StretchRect(sys->d3ddev, source, &vd->sys->rect_src_clipped, destination, NULL, D3DTEXF_LINEAR);
-    IDirect3DSurface9_Release(destination);
-    if (FAILED(hr)) {
-        msg_Dbg(vd, "Failed IDirect3DDevice9_StretchRect: source 0x%p 0x%0lx",
-                (LPVOID)source, hr);
-        return VLC_EGENERIC;
-    }
-
-    /* */
-    region->texture = sys->d3dtex;
-    Direct3D9SetupVertices(region->vertex, vd->sys->rect_dest_clipped, 255, vd->fmt.orientation);
-    return VLC_SUCCESS;
-}
-
-static void Direct3D9DeleteRegions(int count, d3d_region_t *region)
-{
-    for (int i = 0; i < count; i++) {
-        if (region[i].texture)
-            IDirect3DTexture9_Release(region[i].texture);
-    }
-    free(region);
-}
-
-static void Direct3D9ImportSubpicture(vout_display_t *vd,
-                                     int *count_ptr, d3d_region_t **region,
-                                     subpicture_t *subpicture)
-{
-    vout_display_sys_t *sys = vd->sys;
-
-    int count = 0;
-    for (subpicture_region_t *r = subpicture->p_region; r; r = r->p_next)
-        count++;
-
-    *count_ptr = count;
-    *region    = calloc(count, sizeof(**region));
-    if (*region == NULL) {
-        *count_ptr = 0;
-        return;
-    }
-
-    int i = 0;
-    for (subpicture_region_t *r = subpicture->p_region; r; r = r->p_next, i++) {
-        d3d_region_t *d3dr = &(*region)[i];
-        HRESULT hr;
-
-        d3dr->texture = NULL;
-        for (int j = 0; j < sys->d3dregion_count; j++) {
-            d3d_region_t *cache = &sys->d3dregion[j];
-            if (cache->texture &&
-                cache->format == sys->d3dregion_format &&
-                cache->width  == r->fmt.i_visible_width &&
-                cache->height == r->fmt.i_visible_height) {
-                *d3dr = *cache;
-                memset(cache, 0, sizeof(*cache));
-                break;
-            }
-        }
-        if (!d3dr->texture) {
-            d3dr->format = sys->d3dregion_format;
-            d3dr->width  = r->fmt.i_visible_width;
-            d3dr->height = r->fmt.i_visible_height;
-            hr = IDirect3DDevice9_CreateTexture(sys->d3ddev,
-                                                d3dr->width, d3dr->height,
-                                                1,
-                                                D3DUSAGE_DYNAMIC,
-                                                d3dr->format,
-                                                D3DPOOL_DEFAULT,
-                                                &d3dr->texture,
-                                                NULL);
-            if (FAILED(hr)) {
-                d3dr->texture = NULL;
-                msg_Err(vd, "Failed to create %dx%d texture for OSD (hr=0x%0lx)",
-                        d3dr->width, d3dr->height, hr);
-                continue;
-            }
-#ifndef NDEBUG
-            msg_Dbg(vd, "Created %dx%d texture for OSD",
-                    r->fmt.i_visible_width, r->fmt.i_visible_height);
-#endif
-        }
-
-        D3DLOCKED_RECT lock;
-        hr = IDirect3DTexture9_LockRect(d3dr->texture, 0, &lock, NULL, 0);
-        if (SUCCEEDED(hr)) {
-            uint8_t  *dst_data   = lock.pBits;
-            int       dst_pitch  = lock.Pitch;
-            const int src_offset = r->fmt.i_y_offset * r->p_picture->p->i_pitch +
-                                   r->fmt.i_x_offset * r->p_picture->p->i_pixel_pitch;
-            uint8_t  *src_data   = &r->p_picture->p->p_pixels[src_offset];
-            int       src_pitch  = r->p_picture->p->i_pitch;
-            if (d3dr->format == D3DFMT_A8B8G8R8) {
-                if (dst_pitch == r->p_picture->p->i_visible_pitch) {
-                    memcpy(dst_data, src_data, r->fmt.i_visible_height * dst_pitch);
-                } else {
-                    int copy_pitch = __MIN(dst_pitch, r->p_picture->p->i_visible_pitch);
-                    for (unsigned y = 0; y < r->fmt.i_visible_height; y++) {
-                        memcpy(&dst_data[y * dst_pitch], &src_data[y * src_pitch], copy_pitch);
-                    }
-                }
-            } else {
-                int copy_pitch = __MIN(dst_pitch, r->p_picture->p->i_visible_pitch);
-                for (unsigned y = 0; y < r->fmt.i_visible_height; y++) {
-                    for (int x = 0; x < copy_pitch; x += 4) {
-                        dst_data[y * dst_pitch + x + 0] = src_data[y * src_pitch + x + 2];
-                        dst_data[y * dst_pitch + x + 1] = src_data[y * src_pitch + x + 1];
-                        dst_data[y * dst_pitch + x + 2] = src_data[y * src_pitch + x + 0];
-                        dst_data[y * dst_pitch + x + 3] = src_data[y * src_pitch + x + 3];
-                    }
-                }
-            }
-            hr = IDirect3DTexture9_UnlockRect(d3dr->texture, 0);
-            if (FAILED(hr))
-                msg_Err(vd, "Failed to unlock the texture");
-        } else {
-            msg_Err(vd, "Failed to lock the texture");
-        }
-
-        /* Map the subpicture to sys->rect_dest */
-        const RECT video = sys->rect_dest;
-        const float scale_w = (float)(video.right  - video.left) / subpicture->i_original_picture_width;
-        const float scale_h = (float)(video.bottom - video.top)  / subpicture->i_original_picture_height;
-
-        RECT dst;
-        dst.left   = video.left + scale_w * r->i_x,
-        dst.right  = dst.left + scale_w * r->fmt.i_visible_width,
-        dst.top    = video.top  + scale_h * r->i_y,
-        dst.bottom = dst.top  + scale_h * r->fmt.i_visible_height,
-        Direct3D9SetupVertices(d3dr->vertex,
-                              dst, subpicture->i_alpha * r->i_alpha / 255, ORIENT_NORMAL);
-    }
-}
-
-static int Direct3D9RenderRegion(vout_display_t *vd,
-                                d3d_region_t *region,
-                                bool use_pixel_shader)
-{
-    vout_display_sys_t *sys = vd->sys;
-
-    LPDIRECT3DDEVICE9 d3ddev = vd->sys->d3ddev;
-
-    LPDIRECT3DVERTEXBUFFER9 d3dvtc = sys->d3dvtc;
-    LPDIRECT3DTEXTURE9      d3dtex = region->texture;
-
-    HRESULT hr;
-
-    /* Import vertices */
-    void *vertex;
-    hr = IDirect3DVertexBuffer9_Lock(d3dvtc, 0, 0, &vertex, D3DLOCK_DISCARD);
-    if (FAILED(hr)) {
-        msg_Dbg(vd, "Failed IDirect3DVertexBuffer9_Lock: 0x%0lx", hr);
-        return -1;
-    }
-    memcpy(vertex, region->vertex, sizeof(region->vertex));
-    hr = IDirect3DVertexBuffer9_Unlock(d3dvtc);
-    if (FAILED(hr)) {
-        msg_Dbg(vd, "Failed IDirect3DVertexBuffer9_Unlock: 0x%0lx", hr);
-        return -1;
-    }
-
-    // Setup our texture. Using textures introduces the texture stage states,
-    // which govern how textures get blended together (in the case of multiple
-    // textures) and lighting information. In this case, we are modulating
-    // (blending) our texture with the diffuse color of the vertices.
-    hr = IDirect3DDevice9_SetTexture(d3ddev, 0, (LPDIRECT3DBASETEXTURE9)d3dtex);
-    if (FAILED(hr)) {
-        msg_Dbg(vd, "Failed IDirect3DDevice9_SetTexture: 0x%0lx", hr);
-        return -1;
-    }
-
-    if (sys->d3dx_shader) {
-        if (use_pixel_shader)
-        {
-            hr = IDirect3DDevice9_SetPixelShader(d3ddev, sys->d3dx_shader);
-            float shader_data[4] = { region->width, region->height, 0, 0 };
-            hr = IDirect3DDevice9_SetPixelShaderConstantF(d3ddev, 0, shader_data, 1);
-            if (FAILED(hr)) {
-                msg_Dbg(vd, "Failed IDirect3DDevice9_SetPixelShaderConstantF: 0x%0lx", hr);
-                return -1;
-            }
-        }
-        else /* Disable any existing pixel shader. */
-            hr = IDirect3DDevice9_SetPixelShader(d3ddev, NULL);
-        if (FAILED(hr)) {
-            msg_Dbg(vd, "Failed IDirect3DDevice9_SetPixelShader: 0x%0lx", hr);
-            return -1;
-        }
-    }
-
-    // Render the vertex buffer contents
-    hr = IDirect3DDevice9_SetStreamSource(d3ddev, 0, d3dvtc, 0, sizeof(CUSTOMVERTEX));
-    if (FAILED(hr)) {
-        msg_Dbg(vd, "Failed IDirect3DDevice9_SetStreamSource: 0x%0lx", hr);
-        return -1;
-    }
-
-    // we use FVF instead of vertex shader
-    hr = IDirect3DDevice9_SetFVF(d3ddev, D3DFVF_CUSTOMVERTEX);
-    if (FAILED(hr)) {
-        msg_Dbg(vd, "Failed IDirect3DDevice9_SetFVF: 0x%0lx", hr);
-        return -1;
-    }
-
-    // draw rectangle
-    hr = IDirect3DDevice9_DrawPrimitive(d3ddev, D3DPT_TRIANGLEFAN, 0, 2);
-    if (FAILED(hr)) {
-        msg_Dbg(vd, "Failed IDirect3DDevice9_DrawPrimitive: 0x%0lx", hr);
-        return -1;
-    }
-    return 0;
-}
-
-/**
- * It renders the scene.
- *
- * This function is intented for higher end 3D cards, with pixel shader support
- * and at least 64 MiB of video RAM.
- */
-static void Direct3D9RenderScene(vout_display_t *vd,
-                                d3d_region_t *picture,
-                                int subpicture_count,
-                                d3d_region_t *subpicture)
-{
-    vout_display_sys_t *sys = vd->sys;
-    LPDIRECT3DDEVICE9 d3ddev = sys->d3ddev;
-    HRESULT hr;
-
-    if (sys->clear_scene) {
-        /* Clear the backbuffer and the zbuffer */
-        hr = IDirect3DDevice9_Clear(d3ddev, 0, NULL, D3DCLEAR_TARGET,
-                                  D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
-        if (FAILED(hr)) {
-            msg_Dbg(vd, "Failed IDirect3DDevice9_Clear: 0x%0lx", hr);
-            return;
-        }
-        sys->clear_scene = false;
-    }
-
-    // Begin the scene
-    hr = IDirect3DDevice9_BeginScene(d3ddev);
-    if (FAILED(hr)) {
-        msg_Dbg(vd, "Failed IDirect3DDevice9_BeginScene: 0x%0lx", hr);
-        return;
-    }
-
-    Direct3D9RenderRegion(vd, picture, true);
-
-    if (subpicture_count > 0)
-        IDirect3DDevice9_SetRenderState(d3ddev, D3DRS_ALPHABLENDENABLE, TRUE);
-    for (int i = 0; i < subpicture_count; i++) {
-        d3d_region_t *r = &subpicture[i];
-        if (r->texture)
-            Direct3D9RenderRegion(vd, r, false);
-    }
-    if (subpicture_count > 0)
-        IDirect3DDevice9_SetRenderState(d3ddev, D3DRS_ALPHABLENDENABLE, FALSE);
-
-    // End the scene
-    hr = IDirect3DDevice9_EndScene(d3ddev);
-    if (FAILED(hr)) {
-        msg_Dbg(vd, "Failed IDirect3DDevice9_EndScene: 0x%0lx", hr);
-        return;
-    }
-}
-
-/*****************************************************************************
- * DesktopCallback: desktop mode variable callback
- *****************************************************************************/
-static int DesktopCallback(vlc_object_t *object, char const *psz_cmd,
-                            vlc_value_t oldval, vlc_value_t newval,
-                            void *p_data)
-{
-    vout_display_t *vd = (vout_display_t *)object;
-    vout_display_sys_t *sys = vd->sys;
-    VLC_UNUSED(psz_cmd);
-    VLC_UNUSED(oldval);
-    VLC_UNUSED(p_data);
-
-    vlc_mutex_lock(&sys->lock);
-    const bool ch_desktop = !sys->desktop_requested != !newval.b_bool;
-    sys->ch_desktop |= ch_desktop;
-    sys->desktop_requested = newval.b_bool;
-    vlc_mutex_unlock(&sys->lock);
-    return VLC_SUCCESS;
-}
-
-typedef struct
-{
-    char **values;
-    char **descs;
-    size_t count;
-} enum_context_t;
-
-static void ListShaders(enum_context_t *ctx)
-{
-    size_t num_shaders = BUILTIN_SHADERS_COUNT;
-    ctx->values = xrealloc(ctx->values, (ctx->count + num_shaders + 1) * sizeof(char *));
-    ctx->descs = xrealloc(ctx->descs, (ctx->count + num_shaders + 1) * sizeof(char *));
-    for (size_t i = 0; i < num_shaders; ++i) {
-        ctx->values[ctx->count] = strdup(builtin_shaders[i].name);
-        ctx->descs[ctx->count] = strdup(builtin_shaders[i].name);
-        ctx->count++;
-    }
-    ctx->values[ctx->count] = strdup(SELECTED_SHADER_FILE);
-    ctx->descs[ctx->count] = strdup(SELECTED_SHADER_FILE);
-    ctx->count++;
-}
-
-/* Populate the list of available shader techniques in the options */
-static int FindShadersCallback(vlc_object_t *object, const char *name,
-                               char ***values, char ***descs)
-{
-    VLC_UNUSED(object);
-    VLC_UNUSED(name);
-
-    enum_context_t ctx = { NULL, NULL, 0 };
-
-    ListShaders(&ctx);
-
-    *values = ctx.values;
-    *descs = ctx.descs;
-    return ctx.count;
-
-}
diff --git a/modules/video_output/msw/directdraw.c b/modules/video_output/msw/directdraw.c
deleted file mode 100644 (file)
index 2216ab0..0000000
+++ /dev/null
@@ -1,1474 +0,0 @@
-/*****************************************************************************
- * directdraw.c: Windows DirectDraw video output
- *****************************************************************************
- * Copyright (C) 2001-2009 VLC authors and VideoLAN
- * $Id$
- *
- * Authors: Gildas Bazin <gbazin@videolan.org>
- *
- * 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 Lesser General Public License for more details.
- *
- * 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.
- *****************************************************************************/
-
-/*****************************************************************************
- * Preamble:
- *
- * This plugin will use YUV overlay if supported, using overlay will result in
- * the best video quality (hardware interpolation when rescaling the picture)
- * and the fastest display as it requires less processing.
- *
- * If YUV overlay is not supported this plugin will use RGB offscreen video
- * surfaces that will be blitted onto the primary surface (display) to
- * effectively display the pictures. This fallback method also enables us to
- * display video in window mode.
- *
- *****************************************************************************/
-
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#include <assert.h>
-
-#include <vlc_common.h>
-#include <vlc_plugin.h>
-#include <vlc_vout_display.h>
-#include <vlc_charset.h>    /* FromT */
-
-#include <windows.h>
-#include <ddraw.h>
-#include <commctrl.h>       /* ListView_(Get|Set)* */
-
-#include "common.h"
-
-/* Unicode function "DirectDrawEnumerateExW" has been desactivated
-   since in some cases this function fails and the callbacks are not
-   called. If the Unicode mode is restored, one should modify the
-   prototype of the callbacks and call the FromT conversion function.
-*/
-#define DIRECTDRAWENUMERATEEX_NAME "DirectDrawEnumerateExA"
-
-/*****************************************************************************
- * Module descriptor
- *****************************************************************************/
-#define HW_YUV_TEXT N_("Use hardware YUV->RGB conversions")
-#define HW_YUV_LONGTEXT N_(\
-    "Try to use hardware acceleration for YUV->RGB conversions. " \
-    "This option doesn't have any effect when using overlays.")
-
-#define SYSMEM_TEXT N_("Use video buffers in system memory")
-#define SYSMEM_LONGTEXT N_(\
-    "Create video buffers in system memory instead of video memory. This " \
-    "isn't recommended as usually using video memory allows benefiting from " \
-    "more hardware acceleration (like rescaling or YUV->RGB conversions). " \
-    "This option doesn't have any effect when using overlays.")
-
-#define TRIPLEBUF_TEXT N_("Use triple buffering for overlays")
-#define TRIPLEBUF_LONGTEXT N_(\
-    "Try to use triple buffering when using YUV overlays. That results in " \
-    "much better video quality (no flickering).")
-
-#define DEVICE_TEXT N_("Name of desired display device")
-#define DEVICE_LONGTEXT N_("In a multiple monitor configuration, you can " \
-    "specify the Windows device name of the display that you want the video " \
-    "window to open on. For example, \"\\\\.\\DISPLAY1\" or " \
-    "\"\\\\.\\DISPLAY2\".")
-
-#define DX_HELP N_("Recommended video output for Windows XP. " \
-    "Incompatible with Vista's Aero interface" )
-
-static int  Open (vlc_object_t *);
-static void Close(vlc_object_t *);
-
-static int FindDevicesCallback(vlc_object_t *, const char *,
-                               char ***, char ***);
-vlc_module_begin()
-    set_shortname("DirectDraw")
-    set_description(N_("DirectX (DirectDraw) video output"))
-    set_help(DX_HELP)
-    set_category(CAT_VIDEO)
-    set_subcategory(SUBCAT_VIDEO_VOUT)
-    add_bool("directx-hw-yuv", true, HW_YUV_TEXT, HW_YUV_LONGTEXT,
-              true)
-    add_bool("directx-use-sysmem", false, SYSMEM_TEXT, SYSMEM_LONGTEXT,
-              true)
-    add_bool("directx-3buffering", true, TRIPLEBUF_TEXT,
-              TRIPLEBUF_LONGTEXT, true)
-    add_string("directx-device", "", DEVICE_TEXT, DEVICE_LONGTEXT, true)
-        change_string_cb(FindDevicesCallback)
-
-    set_capability("vout display", 230)
-    add_shortcut("directx", "directdraw")
-    set_callbacks(Open, Close)
-vlc_module_end()
-
-/*****************************************************************************
- * Local prototypes.
- *****************************************************************************/
-
-struct picture_sys_t {
-    LPDIRECTDRAWSURFACE2 surface;
-    LPDIRECTDRAWSURFACE2 front_surface;
-    picture_t            *fallback;
-};
-
-/*****************************************************************************
- * DirectDraw GUIDs.
- * Defining them here allows us to get rid of the dxguid library during
- * the linking stage.
- *****************************************************************************/
-#include <initguid.h>
-#undef GUID_EXT
-#define GUID_EXT
-DEFINE_GUID(IID_IDirectDraw2, 0xB3A6F3E0,0x2B43,0x11CF,0xA2,0xDE,0x00,0xAA,0x00,0xB9,0x33,0x56);
-DEFINE_GUID(IID_IDirectDrawSurface2, 0x57805885,0x6eec,0x11cf,0x94,0x41,0xa8,0x23,0x03,0xc1,0x0e,0x27);
-
-static picture_pool_t *Pool  (vout_display_t *, unsigned);
-static void           Display(vout_display_t *, picture_t *, subpicture_t *);
-static int            Control(vout_display_t *, int, va_list);
-static void           Manage (vout_display_t *);
-
-/* */
-static int WallpaperCallback(vlc_object_t *, char const *,
-                             vlc_value_t, vlc_value_t, void *);
-
-static int  DirectXOpen(vout_display_t *, video_format_t *fmt);
-static void DirectXClose(vout_display_t *);
-
-static int  DirectXLock(picture_t *);
-static void DirectXUnlock(picture_t *);
-
-static int DirectXUpdateOverlay(vout_display_t *, LPDIRECTDRAWSURFACE2 surface);
-
-static void WallpaperChange(vout_display_t *vd, bool use_wallpaper);
-
-/** This function allocates and initialize the DirectX vout display.
- */
-static int Open(vlc_object_t *object)
-{
-    vout_display_t *vd = (vout_display_t *)object;
-    vout_display_sys_t *sys;
-
-    /* Allocate structure */
-    vd->sys = sys = calloc(1, sizeof(*sys));
-    if (!sys)
-        return VLC_ENOMEM;
-
-    /* Load direct draw DLL */
-    sys->hddraw_dll = LoadLibrary(_T("DDRAW.DLL"));
-    if (!sys->hddraw_dll) {
-        msg_Warn(vd, "DirectXInitDDraw failed loading ddraw.dll");
-        free(sys);
-        return VLC_EGENERIC;
-    }
-
-    /* */
-    sys->use_wallpaper = var_CreateGetBool(vd, "video-wallpaper");
-    /* FIXME */
-    sys->use_overlay = false;//var_CreateGetBool(vd, "overlay"); /* FIXME */
-    sys->restore_overlay = false;
-    var_Create(vd, "directx-device", VLC_VAR_STRING | VLC_VAR_DOINHERIT);
-
-    /* Initialisation */
-    if (CommonInit(vd))
-        goto error;
-
-    /* */
-    video_format_t fmt = vd->fmt;
-
-    if (DirectXOpen(vd, &fmt))
-        goto error;
-
-    /* */
-    vout_display_info_t info = vd->info;
-    info.is_slow = true;
-    info.has_double_click = true;
-    info.has_hide_mouse = false;
-    info.has_pictures_invalid = true;
-    info.has_event_thread = true;
-
-    /* Interaction TODO support starting with wallpaper mode */
-    vlc_mutex_init(&sys->lock);
-    sys->ch_wallpaper = sys->use_wallpaper;
-    sys->wallpaper_requested = sys->use_wallpaper;
-    sys->use_wallpaper = false;
-
-    vlc_value_t val;
-    val.psz_string = _("Wallpaper");
-    var_Change(vd, "video-wallpaper", VLC_VAR_SETTEXT, &val, NULL);
-    var_AddCallback(vd, "video-wallpaper", WallpaperCallback, NULL);
-
-    /* Setup vout_display now that everything is fine */
-    video_format_Clean(&vd->fmt);
-    video_format_Copy(&vd->fmt, &fmt);
-    vd->info    = info;
-
-    vd->pool    = Pool;
-    vd->prepare = NULL;
-    vd->display = Display;
-    vd->control = Control;
-    vd->manage  = Manage;
-    return VLC_SUCCESS;
-
-error:
-    DirectXClose(vd);
-    CommonClean(vd);
-    if (sys->hddraw_dll)
-        FreeLibrary(sys->hddraw_dll);
-    free(sys);
-    return VLC_EGENERIC;
-}
-
-/** Terminate a vout display created by Open.
- */
-static void Close(vlc_object_t *object)
-{
-    vout_display_t *vd = (vout_display_t *)object;
-    vout_display_sys_t *sys = vd->sys;
-
-    var_DelCallback(vd, "video-wallpaper", WallpaperCallback, NULL);
-    vlc_mutex_destroy(&sys->lock);
-
-    /* Make sure the wallpaper is restored */
-    WallpaperChange(vd, false);
-
-    DirectXClose(vd);
-
-    CommonClean(vd);
-
-    if (sys->hddraw_dll)
-        FreeLibrary(sys->hddraw_dll);
-    free(sys);
-}
-
-static picture_pool_t *Pool(vout_display_t *vd, unsigned count)
-{
-    VLC_UNUSED(count);
-    return vd->sys->pool;
-}
-static void Display(vout_display_t *vd, picture_t *picture, subpicture_t *subpicture)
-{
-    vout_display_sys_t *sys = vd->sys;
-
-    assert(sys->display);
-
-    /* Our surface can be lost so be sure to check this
-     * and restore it if need be */
-    if (IDirectDrawSurface2_IsLost(sys->display) == DDERR_SURFACELOST) {
-        if (IDirectDrawSurface2_Restore(sys->display) == DD_OK) {
-            if (sys->use_overlay)
-                DirectXUpdateOverlay(vd, NULL);
-        }
-    }
-    if (sys->restore_overlay)
-        DirectXUpdateOverlay(vd, NULL);
-
-    /* */
-    DirectXUnlock(picture);
-
-    if (sys->use_overlay) {
-        /* Flip the overlay buffers if we are using back buffers */
-        if (picture->p_sys->surface != picture->p_sys->front_surface) {
-            HRESULT hr = IDirectDrawSurface2_Flip(picture->p_sys->front_surface,
-                                                  NULL, DDFLIP_WAIT);
-            if (hr != DD_OK)
-                msg_Warn(vd, "could not flip overlay (error %li)", hr);
-        }
-    } else {
-        /* Blit video surface to display with the NOTEARING option */
-        DDBLTFX  ddbltfx;
-        ZeroMemory(&ddbltfx, sizeof(ddbltfx));
-        ddbltfx.dwSize = sizeof(ddbltfx);
-        ddbltfx.dwDDFX = DDBLTFX_NOTEARING;
-
-        HRESULT hr = IDirectDrawSurface2_Blt(sys->display,
-                                             &sys->rect_dest_clipped,
-                                             picture->p_sys->surface,
-                                             &sys->rect_src_clipped,
-                                             DDBLT_ASYNC, &ddbltfx);
-        if (hr != DD_OK)
-            msg_Warn(vd, "could not blit surface (error %li)", hr);
-    }
-    DirectXLock(picture);
-
-    if (sys->is_first_display) {
-        IDirectDraw_WaitForVerticalBlank(sys->ddobject,
-                                         DDWAITVB_BLOCKBEGIN, NULL);
-        if (sys->use_overlay) {
-            HBRUSH brush = CreateSolidBrush(sys->i_rgb_colorkey);
-            /* set the colorkey as the backgound brush for the video window */
-            SetClassLongPtr(sys->hvideownd, GCLP_HBRBACKGROUND, (LONG_PTR)brush);
-        }
-    }
-    CommonDisplay(vd);
-
-    picture_Release(picture);
-    VLC_UNUSED(subpicture);
-}
-static int Control(vout_display_t *vd, int query, va_list args)
-{
-    vout_display_sys_t *sys = vd->sys;
-
-    switch (query) {
-    case VOUT_DISPLAY_RESET_PICTURES:
-        DirectXClose(vd);
-        /* Make sure the wallpaper is restored */
-        if (sys->use_wallpaper) {
-            vlc_mutex_lock(&sys->lock);
-            if (!sys->ch_wallpaper) {
-                sys->ch_wallpaper = true;
-                sys->wallpaper_requested = true;
-            }
-            vlc_mutex_unlock(&sys->lock);
-
-            WallpaperChange(vd, false);
-        }
-        return DirectXOpen(vd, &vd->fmt);
-    default:
-        return CommonControl(vd, query, args);
-    }
-}
-static void Manage(vout_display_t *vd)
-{
-    vout_display_sys_t *sys = vd->sys;
-
-    CommonManage(vd);
-
-    if (sys->changes & DX_POSITION_CHANGE) {
-        /* Update overlay */
-        if (sys->use_overlay)
-            DirectXUpdateOverlay(vd, NULL);
-
-        /* Check if we are still on the same monitor */
-        HMONITOR hmon = MonitorFromWindow(sys->hwnd, MONITOR_DEFAULTTONEAREST);
-        if (sys->hmonitor != hmon) {
-            vout_display_SendEventPicturesInvalid(vd);
-        }
-        /* */
-        sys->changes &= ~DX_POSITION_CHANGE;
-    }
-
-    /* Wallpaper mode change */
-    vlc_mutex_lock(&sys->lock);
-    const bool ch_wallpaper = sys->ch_wallpaper;
-    const bool wallpaper_requested = sys->wallpaper_requested;
-    sys->ch_wallpaper = false;
-    vlc_mutex_unlock(&sys->lock);
-
-    if (ch_wallpaper)
-        WallpaperChange(vd, wallpaper_requested);
-
-    /* */
-    if (sys->restore_overlay)
-        DirectXUpdateOverlay(vd, NULL);
-}
-
-/* */
-static int  DirectXOpenDDraw(vout_display_t *);
-static void DirectXCloseDDraw(vout_display_t *);
-
-static int  DirectXOpenDisplay(vout_display_t *vd);
-static void DirectXCloseDisplay(vout_display_t *vd);
-
-static int  DirectXCreatePool(vout_display_t *, bool *, video_format_t *);
-static void DirectXDestroyPool(vout_display_t *);
-
-static int DirectXOpen(vout_display_t *vd, video_format_t *fmt)
-{
-    vout_display_sys_t *sys = vd->sys;
-
-    assert(!sys->ddobject);
-    assert(!sys->display);
-    assert(!sys->clipper);
-
-    /* Initialise DirectDraw */
-    if (DirectXOpenDDraw(vd)) {
-        msg_Err(vd, "cannot initialize DirectX DirectDraw");
-        return VLC_EGENERIC;
-    }
-
-    /* Create the directx display */
-    if (DirectXOpenDisplay(vd)) {
-        msg_Err(vd, "cannot initialize DirectX DirectDraw");
-        return VLC_EGENERIC;
-    }
-    UpdateRects(vd, NULL, NULL, true);
-
-    /* Create the picture pool */
-    if (DirectXCreatePool(vd, &sys->use_overlay, fmt)) {
-        msg_Err(vd, "cannot create any DirectX surface");
-        return VLC_EGENERIC;
-    }
-
-    /* */
-    if (sys->use_overlay)
-        DirectXUpdateOverlay(vd, NULL);
-    EventThreadUseOverlay(sys->event, sys->use_overlay);
-
-    /* Change the window title bar text */
-    const char *fallback;
-    if (sys->use_overlay)
-        fallback = VOUT_TITLE " (hardware YUV overlay DirectX output)";
-    else if (vlc_fourcc_IsYUV(fmt->i_chroma))
-        fallback = VOUT_TITLE " (hardware YUV DirectX output)";
-    else
-        fallback = VOUT_TITLE " (software RGB DirectX output)";
-    EventThreadUpdateTitle(sys->event, fallback);
-
-    return VLC_SUCCESS;
-}
-static void DirectXClose(vout_display_t *vd)
-{
-    DirectXDestroyPool(vd);
-    DirectXCloseDisplay(vd);
-    DirectXCloseDDraw(vd);
-}
-
-/* */
-static BOOL WINAPI DirectXOpenDDrawCallback(GUID *guid, LPSTR desc,
-                                            LPSTR drivername, VOID *context,
-                                            HMONITOR hmon)
-{
-    vout_display_t *vd = context;
-    vout_display_sys_t *sys = vd->sys;
-
-    /* This callback function is called by DirectDraw once for each
-     * available DirectDraw device.
-     *
-     * Returning TRUE keeps enumerating.
-     */
-    if (!hmon)
-        return TRUE;
-
-    char *psz_drivername = drivername;
-    char *psz_desc = desc;
-
-    msg_Dbg(vd, "DirectXEnumCallback: %s, %s", psz_desc, psz_drivername);
-
-    char *device = var_GetString(vd, "directx-device");
-
-    /* Check for forced device */
-    if (device && *device && !strcmp(psz_drivername, device)) {
-        MONITORINFO monitor_info;
-        monitor_info.cbSize = sizeof(MONITORINFO);
-
-        if (GetMonitorInfoA(hmon, &monitor_info)) {
-            RECT rect;
-
-            /* Move window to the right screen */
-            GetWindowRect(sys->hwnd, &rect);
-            if (!IntersectRect(&rect, &rect, &monitor_info.rcWork)) {
-                rect.left = monitor_info.rcWork.left;
-                rect.top = monitor_info.rcWork.top;
-                msg_Dbg(vd, "DirectXEnumCallback: setting window "
-                            "position to %ld,%ld", rect.left, rect.top);
-                SetWindowPos(sys->hwnd, NULL,
-                             rect.left, rect.top, 0, 0,
-                             SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
-            }
-        }
-        sys->hmonitor = hmon;
-    }
-    free(device);
-
-    if (hmon == sys->hmonitor) {
-        msg_Dbg(vd, "selecting %s, %s", psz_desc, psz_drivername);
-
-        free(sys->display_driver);
-        sys->display_driver = malloc(sizeof(*guid));
-        if (sys->display_driver)
-            *sys->display_driver = *guid;
-    }
-
-    return TRUE;
-}
-/**
- * Probe the capabilities of the hardware
- *
- * It is nice to know which features are supported by the hardware so we can
- * find ways to optimize our rendering.
- */
-static void DirectXGetDDrawCaps(vout_display_t *vd)
-{
-    vout_display_sys_t *sys = vd->sys;
-
-    /* This is just an indication of whether or not we'll support overlay,
-     * but with this test we don't know if we support YUV overlay */
-    DDCAPS ddcaps;
-    ZeroMemory(&ddcaps, sizeof(ddcaps));
-    ddcaps.dwSize = sizeof(ddcaps);
-    HRESULT hr = IDirectDraw2_GetCaps(sys->ddobject, &ddcaps, NULL);
-    if (hr != DD_OK) {
-        msg_Warn(vd, "cannot get caps");
-        return;
-    }
-
-    /* Determine if the hardware supports overlay surfaces */
-    const bool has_overlay = ddcaps.dwCaps & DDCAPS_OVERLAY;
-    /* Determine if the hardware supports overlay surfaces */
-    const bool has_overlay_fourcc = ddcaps.dwCaps & DDCAPS_OVERLAYFOURCC;
-    /* Determine if the hardware supports overlay deinterlacing */
-    const bool can_deinterlace = ddcaps.dwCaps & DDCAPS2_CANFLIPODDEVEN;
-    /* Determine if the hardware supports colorkeying */
-    const bool has_color_key = ddcaps.dwCaps & DDCAPS_COLORKEY;
-    /* Determine if the hardware supports scaling of the overlay surface */
-    const bool can_stretch = ddcaps.dwCaps & DDCAPS_OVERLAYSTRETCH;
-    /* Determine if the hardware supports color conversion during a blit */
-    sys->can_blit_fourcc = ddcaps.dwCaps & DDCAPS_BLTFOURCC;
-    /* Determine overlay source boundary alignment */
-    const bool align_boundary_src  = ddcaps.dwCaps & DDCAPS_ALIGNBOUNDARYSRC;
-    /* Determine overlay destination boundary alignment */
-    const bool align_boundary_dest = ddcaps.dwCaps & DDCAPS_ALIGNBOUNDARYDEST;
-    /* Determine overlay destination size alignment */
-    const bool align_size_src  = ddcaps.dwCaps & DDCAPS_ALIGNSIZESRC;
-    /* Determine overlay destination size alignment */
-    const bool align_size_dest = ddcaps.dwCaps & DDCAPS_ALIGNSIZEDEST;
-
-    msg_Dbg(vd, "DirectDraw Capabilities: overlay=%i yuvoverlay=%i "
-                "can_deinterlace_overlay=%i colorkey=%i stretch=%i "
-                "bltfourcc=%i",
-                has_overlay, has_overlay_fourcc, can_deinterlace,
-                has_color_key, can_stretch, sys->can_blit_fourcc);
-
-    if (align_boundary_src || align_boundary_dest || align_size_src || align_size_dest) {
-        if (align_boundary_src)
-            vd->sys->i_align_src_boundary = ddcaps.dwAlignBoundarySrc;
-        if (align_boundary_dest)
-            vd->sys->i_align_dest_boundary = ddcaps.dwAlignBoundaryDest;
-        if (align_size_src)
-            vd->sys->i_align_src_size = ddcaps.dwAlignSizeSrc;
-        if (align_size_dest)
-            vd->sys->i_align_dest_size = ddcaps.dwAlignSizeDest;
-
-        msg_Dbg(vd,
-                "align_boundary_src=%i,%i align_boundary_dest=%i,%i "
-                "align_size_src=%i,%i align_size_dest=%i,%i",
-                align_boundary_src,  vd->sys->i_align_src_boundary,
-                align_boundary_dest, vd->sys->i_align_dest_boundary,
-                align_size_src,  vd->sys->i_align_src_size,
-                align_size_dest, vd->sys->i_align_dest_size);
-    }
-}
-
-
-
-/* */
-static int DirectXOpenDDraw(vout_display_t *vd)
-{
-    vout_display_sys_t *sys = vd->sys;
-    HRESULT hr;
-
-    /* */
-    HRESULT (WINAPI *OurDirectDrawCreate)(GUID *,LPDIRECTDRAW *,IUnknown *);
-    OurDirectDrawCreate =
-        (void *)GetProcAddress(sys->hddraw_dll, "DirectDrawCreate");
-    if (!OurDirectDrawCreate) {
-        msg_Err(vd, "DirectXInitDDraw failed GetProcAddress");
-        return VLC_EGENERIC;
-    }
-
-    /* */
-    HRESULT (WINAPI *OurDirectDrawEnumerateEx)(LPDDENUMCALLBACKEXA, LPVOID, DWORD);
-    OurDirectDrawEnumerateEx =
-      (void *)GetProcAddress(sys->hddraw_dll, DIRECTDRAWENUMERATEEX_NAME);
-
-    if (OurDirectDrawEnumerateEx) {
-        char *device = var_GetString(vd, "directx-device");
-        if (device) {
-            msg_Dbg(vd, "directx-device: %s", device);
-            free(device);
-        }
-
-        sys->hmonitor = MonitorFromWindow(sys->hwnd, MONITOR_DEFAULTTONEAREST);
-
-        /* Enumerate displays */
-        OurDirectDrawEnumerateEx(DirectXOpenDDrawCallback,
-                                 vd, DDENUM_ATTACHEDSECONDARYDEVICES);
-    }
-
-    /* Initialize DirectDraw now */
-    LPDIRECTDRAW ddobject;
-    hr = OurDirectDrawCreate(sys->display_driver, &ddobject, NULL);
-    if (hr != DD_OK) {
-        msg_Err(vd, "DirectXInitDDraw cannot initialize DDraw");
-        return VLC_EGENERIC;
-    }
-
-    /* Get the IDirectDraw2 interface */
-    void *ptr;
-    hr = IDirectDraw_QueryInterface(ddobject, &IID_IDirectDraw2,
-                                    &ptr);
-    /* Release the unused interface */
-    IDirectDraw_Release(ddobject);
-
-    if (hr != DD_OK) {
-        msg_Err(vd, "cannot get IDirectDraw2 interface");
-        sys->ddobject = NULL;
-        return VLC_EGENERIC;
-    }
-    sys->ddobject = ptr;
-
-    /* Set DirectDraw Cooperative level, ie what control we want over Windows
-     * display */
-    hr = IDirectDraw2_SetCooperativeLevel(sys->ddobject, NULL, DDSCL_NORMAL);
-    if (hr != DD_OK) {
-        msg_Err(vd, "cannot set direct draw cooperative level");
-        return VLC_EGENERIC;
-    }
-
-    /* Get the size of the current display device */
-    if (sys->hmonitor) {
-        MONITORINFO monitor_info;
-        monitor_info.cbSize = sizeof(MONITORINFO);
-        GetMonitorInfoA(vd->sys->hmonitor, &monitor_info);
-        sys->rect_display = monitor_info.rcMonitor;
-    } else {
-        sys->rect_display.left   = 0;
-        sys->rect_display.top    = 0;
-        sys->rect_display.right  = GetSystemMetrics(SM_CXSCREEN);
-        sys->rect_display.bottom = GetSystemMetrics(SM_CYSCREEN);
-    }
-
-    msg_Dbg(vd, "screen dimensions (%lix%li,%lix%li)",
-            sys->rect_display.left,
-            sys->rect_display.top,
-            sys->rect_display.right,
-            sys->rect_display.bottom);
-
-    /* Probe the capabilities of the hardware */
-    DirectXGetDDrawCaps(vd);
-
-    return VLC_SUCCESS;
-}
-
-static void DirectXCloseDDraw(vout_display_t *vd)
-{
-    vout_display_sys_t *sys = vd->sys;
-    if (sys->ddobject)
-        IDirectDraw2_Release(sys->ddobject);
-
-    sys->ddobject = NULL;
-
-    free(sys->display_driver);
-    sys->display_driver = NULL;
-
-    sys->hmonitor = NULL;
-}
-
-/**
- * Create a clipper that will be used when blitting the RGB surface to the main display.
- *
- * This clipper prevents us to modify by mistake anything on the screen
- * which doesn't belong to our window. For example when a part of our video
- * window is hidden by another window.
- */
-static void DirectXCreateClipper(vout_display_t *vd)
-{
-    vout_display_sys_t *sys = vd->sys;
-    HRESULT hr;
-
-    /* Create the clipper */
-    hr = IDirectDraw2_CreateClipper(sys->ddobject, 0, &sys->clipper, NULL);
-    if (hr != DD_OK) {
-        msg_Warn(vd, "cannot create clipper (error %li)", hr);
-        goto error;
-    }
-
-    /* Associate the clipper to the window */
-    hr = IDirectDrawClipper_SetHWnd(sys->clipper, 0, sys->hvideownd);
-    if (hr != DD_OK) {
-        msg_Warn(vd, "cannot attach clipper to window (error %li)", hr);
-        goto error;
-    }
-
-    /* associate the clipper with the surface */
-    hr = IDirectDrawSurface_SetClipper(sys->display, sys->clipper);
-    if (hr != DD_OK)
-    {
-        msg_Warn(vd, "cannot attach clipper to surface (error %li)", hr);
-        goto error;
-    }
-
-    return;
-
-error:
-    if (sys->clipper)
-        IDirectDrawClipper_Release(sys->clipper);
-    sys->clipper = NULL;
-}
-
-/**
- * It finds out the 32bits RGB pixel value of the colorkey.
- */
-static uint32_t DirectXFindColorkey(vout_display_t *vd, uint32_t *color)
-{
-    vout_display_sys_t *sys = vd->sys;
-    HRESULT hr;
-
-    /* */
-    DDSURFACEDESC ddsd;
-    ddsd.dwSize = sizeof(ddsd);
-    hr = IDirectDrawSurface2_Lock(sys->display, NULL, &ddsd, DDLOCK_WAIT, NULL);
-    if (hr != DD_OK)
-        return 0;
-
-    uint32_t backup = *(uint32_t *)ddsd.lpSurface;
-
-    switch (ddsd.ddpfPixelFormat.dwRGBBitCount) {
-    case 4:
-        *(uint8_t *)ddsd.lpSurface = *color | (*color << 4);
-        break;
-    case 8:
-        *(uint8_t *)ddsd.lpSurface = *color;
-        break;
-    case 15:
-    case 16:
-        *(uint16_t *)ddsd.lpSurface = *color;
-        break;
-    case 24:
-        /* Seems to be problematic so we'll just put black as the colorkey */
-        *color = 0;
-    default:
-        *(uint32_t *)ddsd.lpSurface = *color;
-        break;
-    }
-    IDirectDrawSurface2_Unlock(sys->display, NULL);
-
-    /* */
-    HDC hdc;
-    COLORREF rgb;
-    if (IDirectDrawSurface2_GetDC(sys->display, &hdc) == DD_OK) {
-        rgb = GetPixel(hdc, 0, 0);
-        IDirectDrawSurface2_ReleaseDC(sys->display, hdc);
-    } else {
-        rgb = 0;
-    }
-
-    /* Restore the pixel value */
-    ddsd.dwSize = sizeof(ddsd);
-    if (IDirectDrawSurface2_Lock(sys->display, NULL, &ddsd, DDLOCK_WAIT, NULL) == DD_OK) {
-        *(uint32_t *)ddsd.lpSurface = backup;
-        IDirectDrawSurface2_Unlock(sys->display, NULL);
-    }
-
-    return rgb;
-}
-
-/**
- * Create and initialize display according to preferences specified in the vout
- * thread fields.
- */
-static int DirectXOpenDisplay(vout_display_t *vd)
-{
-    vout_display_sys_t *sys = vd->sys;
-    HRESULT hr;
-
-    /* Now get the primary surface. This surface is what you actually see
-     * on your screen */
-    DDSURFACEDESC ddsd;
-    ZeroMemory(&ddsd, sizeof(ddsd));
-    ddsd.dwSize = sizeof(ddsd);
-    ddsd.dwFlags = DDSD_CAPS;
-    ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
-
-    LPDIRECTDRAWSURFACE display;
-    hr = IDirectDraw2_CreateSurface(sys->ddobject, &ddsd, &display, NULL);
-    if (hr != DD_OK) {
-        msg_Err(vd, "cannot get primary surface (error %li)", hr);
-        return VLC_EGENERIC;
-    }
-
-    void *ptr;
-    hr = IDirectDrawSurface_QueryInterface(display, &IID_IDirectDrawSurface2,
-                                           &ptr);
-    /* Release the old interface */
-    IDirectDrawSurface_Release(display);
-
-    if (hr != DD_OK) {
-        msg_Err(vd, "cannot query IDirectDrawSurface2 interface (error %li)", hr);
-        sys->display = NULL;
-        return VLC_EGENERIC;
-    }
-    sys->display = ptr;
-
-    /* The clipper will be used only in non-overlay mode */
-    DirectXCreateClipper(vd);
-
-    /* Make sure the colorkey will be painted */
-    sys->i_colorkey = 1;
-    sys->i_rgb_colorkey = DirectXFindColorkey(vd, &sys->i_colorkey);
-
-    return VLC_SUCCESS;
-}
-static void DirectXCloseDisplay(vout_display_t *vd)
-{
-    vout_display_sys_t *sys = vd->sys;
-
-    if (sys->clipper != NULL)
-        IDirectDrawClipper_Release(sys->clipper);
-
-    if (sys->display != NULL)
-        IDirectDrawSurface2_Release(sys->display);
-
-    sys->clipper = NULL;
-    sys->display = NULL;
-}
-
-/**
- * Create an YUV overlay or RGB surface for the video.
- *
- * The best method of display is with an YUV overlay because the YUV->RGB
- * conversion is done in hardware.
- * You can also create a plain RGB surface.
- * (Maybe we could also try an RGB overlay surface, which could have hardware
- * scaling and which would also be faster in window mode because you don't
- * need to do any blitting to the main display...)
- */
-static int DirectXCreateSurface(vout_display_t *vd,
-                                LPDIRECTDRAWSURFACE2 *surface,
-                                const video_format_t *fmt,
-                                DWORD fourcc,
-                                bool use_overlay,
-                                bool use_sysmem,
-                                int backbuffer_count)
-{
-    vout_display_sys_t *sys = vd->sys;
-
-    DDSURFACEDESC ddsd;
-
-    ZeroMemory(&ddsd, sizeof(ddsd));
-    ddsd.dwSize   = sizeof(ddsd);
-    ddsd.ddpfPixelFormat.dwSize = sizeof(ddsd.ddpfPixelFormat);
-    ddsd.dwFlags  = DDSD_HEIGHT | DDSD_WIDTH;
-    ddsd.dwWidth  = fmt->i_width;
-    ddsd.dwHeight = fmt->i_height;
-    if (fourcc) {
-        ddsd.dwFlags |= DDSD_PIXELFORMAT;
-        ddsd.ddpfPixelFormat.dwFlags = DDPF_FOURCC;
-        ddsd.ddpfPixelFormat.dwFourCC = fourcc;
-    }
-    if (use_overlay) {
-        ddsd.dwFlags |= DDSD_CAPS;
-        ddsd.ddsCaps.dwCaps = DDSCAPS_OVERLAY | DDSCAPS_VIDEOMEMORY;
-        ddsd.ddsCaps.dwCaps |= DDSCAPS_FLIP | DDSCAPS_FRONTBUFFER;
-        if (backbuffer_count > 0)
-            ddsd.ddsCaps.dwCaps |= DDSCAPS_COMPLEX;
-
-        if (backbuffer_count > 0) {
-            ddsd.dwFlags |= DDSD_BACKBUFFERCOUNT;
-            ddsd.dwBackBufferCount = backbuffer_count;
-        }
-    } else {
-        ddsd.dwFlags |= DDSD_CAPS;
-        ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
-        if (use_sysmem)
-            ddsd.ddsCaps.dwCaps |= DDSCAPS_SYSTEMMEMORY;
-        else
-            ddsd.ddsCaps.dwCaps |= DDSCAPS_VIDEOMEMORY;
-    }
-
-    /* Create the video surface */
-    LPDIRECTDRAWSURFACE surface_v1;
-    if (IDirectDraw2_CreateSurface(sys->ddobject, &ddsd, &surface_v1, NULL) != DD_OK)
-        return VLC_EGENERIC;
-
-    /* Now that the surface is created, try to get a newer DirectX interface */
-    HRESULT hr = IDirectDrawSurface_QueryInterface(surface_v1,
-                                                   &IID_IDirectDrawSurface2,
-                                                   (LPVOID *)surface);
-    IDirectDrawSurface_Release(surface_v1);
-    if (hr != DD_OK) {
-        msg_Err(vd, "cannot query IDirectDrawSurface2 interface (error %li)", hr);
-        return VLC_EGENERIC;
-    }
-
-    if (use_overlay) {
-        /* Check the overlay is useable as some graphics cards allow creating
-         * several overlays but only one can be used at one time. */
-        if (DirectXUpdateOverlay(vd, *surface)) {
-            IDirectDrawSurface2_Release(*surface);
-            msg_Err(vd, "overlay unuseable (might already be in use)");
-            return VLC_EGENERIC;
-        }
-    }
-
-    return VLC_SUCCESS;
-}
-
-static void DirectXDestroySurface(LPDIRECTDRAWSURFACE2 surface)
-{
-    IDirectDrawSurface2_Release(surface);
-}
-/**
- * This function locks a surface and get the surface descriptor.
- */
-static int DirectXLockSurface(LPDIRECTDRAWSURFACE2 front_surface,
-                              LPDIRECTDRAWSURFACE2 surface,
-                              DDSURFACEDESC *ddsd)
-{
-    HRESULT hr;
-
-    DDSURFACEDESC ddsd_dummy;
-    if (!ddsd)
-        ddsd = &ddsd_dummy;
-
-    ZeroMemory(ddsd, sizeof(*ddsd));
-    ddsd->dwSize = sizeof(*ddsd);
-    hr = IDirectDrawSurface2_Lock(surface, NULL, ddsd, DDLOCK_NOSYSLOCK | DDLOCK_WAIT, NULL);
-    if (hr != DD_OK) {
-        if (hr == DDERR_INVALIDPARAMS) {
-            /* DirectX 3 doesn't support the DDLOCK_NOSYSLOCK flag, resulting
-             * in an invalid params error */
-            hr = IDirectDrawSurface2_Lock(surface, NULL, ddsd, DDLOCK_WAIT, NULL);
-        }
-        if (hr == DDERR_SURFACELOST) {
-            /* Your surface can be lost so be sure
-             * to check this and restore it if needed */
-
-            /* When using overlays with back-buffers, we need to restore
-             * the front buffer so the back-buffers get restored as well. */
-            if (front_surface != surface)
-                IDirectDrawSurface2_Restore(front_surface);
-            else
-                IDirectDrawSurface2_Restore(surface);
-
-            hr = IDirectDrawSurface2_Lock(surface, NULL, ddsd, DDLOCK_WAIT, NULL);
-        }
-        if (hr != DD_OK)
-            return VLC_EGENERIC;
-    }
-    return VLC_SUCCESS;
-}
-static void DirectXUnlockSurface(LPDIRECTDRAWSURFACE2 front_surface,
-                                 LPDIRECTDRAWSURFACE2 surface)
-{
-    VLC_UNUSED(front_surface);
-    IDirectDrawSurface2_Unlock(surface, NULL);
-}
-static int DirectXCheckLockingSurface(LPDIRECTDRAWSURFACE2 front_surface,
-                                      LPDIRECTDRAWSURFACE2 surface)
-{
-    if (DirectXLockSurface(front_surface, surface, NULL))
-        return VLC_EGENERIC;
-
-    DirectXUnlockSurface(front_surface, surface);
-    return VLC_SUCCESS;
-}
-
-
-
-typedef struct {
-    vlc_fourcc_t codec;
-    DWORD        fourcc;
-} dx_format_t;
-
-static DWORD DirectXGetFourcc(vlc_fourcc_t codec)
-{
-    static const dx_format_t dx_formats[] = {
-        { VLC_CODEC_YUYV, MAKEFOURCC('Y','U','Y','2') },
-        { VLC_CODEC_UYVY, MAKEFOURCC('U','Y','V','Y') },
-        { VLC_CODEC_YVYU, MAKEFOURCC('Y','V','Y','U') },
-        { VLC_CODEC_YV12, MAKEFOURCC('Y','V','1','2') },
-        { VLC_CODEC_I420, MAKEFOURCC('Y','V','1','2') },
-        { VLC_CODEC_J420, MAKEFOURCC('Y','V','1','2') },
-        { 0, 0 }
-    };
-
-    for (unsigned i = 0; dx_formats[i].codec != 0; i++) {
-        if (dx_formats[i].codec == codec)
-            return dx_formats[i].fourcc;
-    }
-    return 0;
-}
-
-static int DirectXCreatePictureResourceYuvOverlay(vout_display_t *vd,
-                                                  const video_format_t *fmt,
-                                                  DWORD fourcc)
-{
-    vout_display_sys_t *sys = vd->sys;
-
-    bool allow_3buf    = var_InheritBool(vd, "directx-3buffering");
-
-    /* The overlay surface that we create won't be used to decode directly
-     * into it because accessing video memory directly is way to slow (remember
-     * that pictures are decoded macroblock per macroblock). Instead the video
-     * will be decoded in picture buffers in system memory which will then be
-     * memcpy() to the overlay surface. */
-    LPDIRECTDRAWSURFACE2 front_surface;
-    int ret = VLC_EGENERIC;
-    if (allow_3buf) {
-        /* Triple buffering rocks! it doesn't have any processing overhead
-         * (you don't have to wait for the vsync) and provides for a very nice
-         * video quality (no tearing). */
-        ret = DirectXCreateSurface(vd, &front_surface, fmt, fourcc, true, false, 2);
-    }
-    if (ret)
-        ret = DirectXCreateSurface(vd, &front_surface, fmt, fourcc, true, false, 0);
-    if (ret)
-        return VLC_EGENERIC;
-    msg_Dbg(vd, "YUV overlay surface (%4.4s) created successfully", (const char *)&fourcc);
-
-    /* Get the back buffer */
-    LPDIRECTDRAWSURFACE2 surface;
-    DDSCAPS dds_caps;
-    ZeroMemory(&dds_caps, sizeof(dds_caps));
-    dds_caps.dwCaps = DDSCAPS_BACKBUFFER;
-    if (IDirectDrawSurface2_GetAttachedSurface(front_surface, &dds_caps, &surface) != DD_OK) {
-        msg_Warn(vd, "Failed to get surface back buffer");
-        /* front buffer is the same as back buffer */
-        surface = front_surface;
-    }
-
-    if (DirectXCheckLockingSurface(front_surface, surface)) {
-        DirectXDestroySurface(front_surface);
-        return VLC_EGENERIC;
-    }
-
-    /* */
-    picture_sys_t *picsys = sys->picsys;
-    picsys->front_surface = front_surface;
-    picsys->surface       = surface;
-    picsys->fallback      = NULL;
-    return VLC_SUCCESS;
-}
-static int DirectXCreatePictureResourceYuv(vout_display_t *vd,
-                                           const video_format_t *fmt,
-                                           DWORD fourcc)
-{
-    vout_display_sys_t *sys = vd->sys;
-
-    bool allow_sysmem  = var_InheritBool(vd, "directx-use-sysmem");
-
-    /* As we can't have an overlay, we'll try to create a plain offscreen
-     * surface. This surface will reside in video memory because there's a
-     * better chance then that we'll be able to use some kind of hardware
-     * acceleration like rescaling, blitting or YUV->RGB conversions.
-     * We then only need to blit this surface onto the main display when we
-     * want to display it */
-
-    /* Check if the chroma is supported first. This is required
-     * because a few buggy drivers don't mind creating the surface
-     * even if they don't know about the chroma. */
-    DWORD count;
-    if (IDirectDraw2_GetFourCCCodes(sys->ddobject, &count, NULL) != DD_OK)
-        return VLC_EGENERIC;
-
-    DWORD *list = calloc(count, sizeof(*list));
-    if (!list)
-        return VLC_ENOMEM;
-    if (IDirectDraw2_GetFourCCCodes(sys->ddobject, &count, list) != DD_OK) {
-        free(list);
-        return VLC_EGENERIC;
-    }
-    unsigned index;
-    for (index = 0; index < count; index++) {
-        if (list[index] == fourcc)
-            break;
-    }
-    free(list);
-    if (index >= count)
-        return VLC_EGENERIC;
-
-    /* */
-    LPDIRECTDRAWSURFACE2 surface;
-    if (DirectXCreateSurface(vd, &surface, fmt, fourcc, false, allow_sysmem, 0))
-        return VLC_EGENERIC;
-    msg_Dbg(vd, "YUV plain surface (%4.4s) created successfully", (const char *)&fourcc);
-
-    if (DirectXCheckLockingSurface(surface, surface)) {
-        DirectXDestroySurface(surface);
-        return VLC_EGENERIC;
-    }
-
-    /* */
-    picture_sys_t *picsys = sys->picsys;
-    picsys->front_surface = surface;
-    picsys->surface       = surface;
-    picsys->fallback      = NULL;
-    return VLC_SUCCESS;
-}
-static int DirectXCreatePictureResourceRgb(vout_display_t *vd,
-                                           video_format_t *fmt)
-{
-    vout_display_sys_t *sys = vd->sys;
-    bool allow_sysmem  = var_InheritBool(vd, "directx-use-sysmem");
-
-    /* Our last choice is to use a plain RGB surface */
-    DDPIXELFORMAT ddpfPixelFormat;
-    ZeroMemory(&ddpfPixelFormat, sizeof(ddpfPixelFormat));
-    ddpfPixelFormat.dwSize = sizeof(ddpfPixelFormat);
-
-    IDirectDrawSurface2_GetPixelFormat(sys->display, &ddpfPixelFormat);
-    if ((ddpfPixelFormat.dwFlags & DDPF_RGB) == 0)
-        return VLC_EGENERIC;
-
-    switch (ddpfPixelFormat.dwRGBBitCount) {
-    case 8:
-        fmt->i_chroma = VLC_CODEC_RGB8;
-        break;
-    case 15:
-        fmt->i_chroma = VLC_CODEC_RGB15;
-        break;
-    case 16:
-        fmt->i_chroma = VLC_CODEC_RGB16;
-        break;
-    case 24:
-        fmt->i_chroma = VLC_CODEC_RGB24;
-        break;
-    case 32:
-        fmt->i_chroma = VLC_CODEC_RGB32;
-        break;
-    default:
-        msg_Err(vd, "unknown screen depth");
-        return VLC_EGENERIC;
-    }
-    fmt->i_rmask = ddpfPixelFormat.dwRBitMask;
-    fmt->i_gmask = ddpfPixelFormat.dwGBitMask;
-    fmt->i_bmask = ddpfPixelFormat.dwBBitMask;
-
-    /* */
-    LPDIRECTDRAWSURFACE2 surface;
-    int ret = DirectXCreateSurface(vd, &surface, fmt, 0, false, allow_sysmem, 0);
-    if (ret && !allow_sysmem)
-        ret = DirectXCreateSurface(vd, &surface, fmt, 0, false, true, 0);
-    if (ret)
-        return VLC_EGENERIC;
-    msg_Dbg(vd, "RGB plain surface (%4.4s) created successfully", (const char *)&fmt->i_chroma);
-
-    if (DirectXCheckLockingSurface(surface, surface)) {
-        DirectXDestroySurface(surface);
-        return VLC_EGENERIC;
-    }
-
-    /* */
-    picture_sys_t *picsys = sys->picsys;
-    picsys->front_surface = surface;
-    picsys->surface       = surface;
-    picsys->fallback      = NULL;
-    return VLC_SUCCESS;
-}
-
-static int DirectXCreatePictureResource(vout_display_t *vd,
-                                        bool *use_overlay,
-                                        video_format_t *fmt)
-{
-    vout_display_sys_t *sys = vd->sys;
-
-    /* */
-    picture_sys_t *picsys = calloc(1, sizeof(*picsys));
-    if (unlikely(picsys == NULL))
-        return VLC_ENOMEM;
-    sys->picsys = picsys;
-
-    /* */
-    bool allow_hw_yuv  = sys->can_blit_fourcc &&
-                         vlc_fourcc_IsYUV(fmt->i_chroma) &&
-                         var_InheritBool(vd, "directx-hw-yuv");
-    bool allow_overlay = var_InheritBool(vd, "overlay");
-
-    /* Try to use an yuv surface */
-    if (allow_hw_yuv) {
-        const vlc_fourcc_t *list = vlc_fourcc_GetYUVFallback(fmt->i_chroma);
-        /*  Try with overlay first */
-        for (unsigned pass = allow_overlay ? 0 : 1; pass < 2; pass++) {
-            for (unsigned i = 0; list[i] != 0; i++) {
-                const DWORD fourcc = DirectXGetFourcc(list[i]);
-                if (!fourcc)
-                    continue;
-
-                if (pass == 0) {
-                    if (DirectXCreatePictureResourceYuvOverlay(vd, fmt, fourcc))
-                    {
-#ifndef NDEBUG
-                        msg_Dbg(vd, "Failed to create YUV overlay surface %4.4s", (const char*)&fourcc);
-#endif
-                        continue;
-                    }
-                } else {
-                    if (DirectXCreatePictureResourceYuv(vd, fmt, fourcc))
-                    {
-#ifndef NDEBUG
-                        msg_Dbg(vd, "Failed to create YUV surface %4.4s", (const char*)&fourcc);
-#endif
-                        continue;
-                    }
-                }
-                /* */
-                *use_overlay = pass == 0;
-                fmt->i_chroma = list[i];
-                return VLC_SUCCESS;
-            }
-        }
-    }
-
-    /* Try plain RGB */
-    return DirectXCreatePictureResourceRgb(vd, fmt);
-}
-static void DirectXDestroyPictureResource(vout_display_t *vd)
-{
-    vout_display_sys_t *sys = vd->sys;
-
-    if (sys->picsys->front_surface != sys->picsys->surface)
-        DirectXDestroySurface(sys->picsys->surface);
-    DirectXDestroySurface(sys->picsys->front_surface);
-    if (sys->picsys->fallback)
-        picture_Release(sys->picsys->fallback);
-}
-
-static int DirectXLock(picture_t *picture)
-{
-    DDSURFACEDESC ddsd;
-    if (DirectXLockSurface(picture->p_sys->front_surface,
-                           picture->p_sys->surface, &ddsd))
-        return CommonUpdatePicture(picture, &picture->p_sys->fallback, NULL, 0);
-
-    CommonUpdatePicture(picture, NULL, ddsd.lpSurface, ddsd.lPitch);
-    return VLC_SUCCESS;
-}
-static void DirectXUnlock(picture_t *picture)
-{
-    DirectXUnlockSurface(picture->p_sys->front_surface,
-                         picture->p_sys->surface);
-}
-
-static int DirectXCreatePool(vout_display_t *vd,
-                             bool *use_overlay, video_format_t *fmt)
-{
-    vout_display_sys_t *sys = vd->sys;
-
-    /* */
-    *fmt = vd->source;
-
-    if (DirectXCreatePictureResource(vd, use_overlay, fmt))
-        return VLC_EGENERIC;
-
-    /* Create the associated picture */
-    picture_resource_t resource = { .p_sys = sys->picsys };
-    picture_t *picture = picture_NewFromResource(fmt, &resource);
-    if (!picture) {
-        DirectXDestroyPictureResource(vd);
-        free(sys->picsys);
-        return VLC_ENOMEM;
-    }
-
-    /* Wrap it into a picture pool */
-    picture_pool_configuration_t cfg;
-    memset(&cfg, 0, sizeof(cfg));
-    cfg.picture_count = 1;
-    cfg.picture       = &picture;
-    cfg.lock          = DirectXLock;
-    cfg.unlock        = DirectXUnlock;
-
-    sys->pool = picture_pool_NewExtended(&cfg);
-    if (!sys->pool) {
-        picture_Release(picture);
-        DirectXDestroyPictureResource(vd);
-        return VLC_ENOMEM;
-    }
-    return VLC_SUCCESS;
-}
-static void DirectXDestroyPool(vout_display_t *vd)
-{
-    vout_display_sys_t *sys = vd->sys;
-
-    if (sys->pool) {
-        DirectXDestroyPictureResource(vd);
-        picture_pool_Release(sys->pool);
-    }
-    sys->pool = NULL;
-}
-
-/**
- * Move or resize overlay surface on video display.
- *
- * This function is used to move or resize an overlay surface on the screen.
- * Ususally the overlay is moved by the user and thus, by a move or resize
- * event.
- */
-static int DirectXUpdateOverlay(vout_display_t *vd, LPDIRECTDRAWSURFACE2 surface)
-{
-    vout_display_sys_t *sys = vd->sys;
-
-    RECT src = sys->rect_src_clipped;
-    RECT dst = sys->rect_dest_clipped;
-
-    if (sys->use_wallpaper) {
-        src.left   = vd->source.i_x_offset;
-        src.top    = vd->source.i_y_offset;
-        src.right  = vd->source.i_x_offset + vd->source.i_visible_width;
-        src.bottom = vd->source.i_y_offset + vd->source.i_visible_height;
-        AlignRect(&src, sys->i_align_src_boundary, sys->i_align_src_size);
-
-        vout_display_cfg_t cfg = *vd->cfg;
-        cfg.display.width  = sys->rect_display.right;
-        cfg.display.height = sys->rect_display.bottom;
-
-        vout_display_place_t place;
-        vout_display_PlacePicture(&place, &vd->source, &cfg, true);
-
-        dst.left   = sys->rect_display.left + place.x;
-        dst.top    = sys->rect_display.top  + place.y;
-        dst.right  = dst.left + place.width;
-        dst.bottom = dst.top  + place.height;
-        AlignRect(&dst, sys->i_align_dest_boundary, sys->i_align_dest_size);
-    }
-
-    if (!surface) {
-        if (!sys->pool)
-            return VLC_EGENERIC;
-        surface = sys->picsys->front_surface;
-    }
-
-    /* The new window dimensions should already have been computed by the
-     * caller of this function */
-
-    /* Position and show the overlay */
-    DDOVERLAYFX ddofx;
-    ZeroMemory(&ddofx, sizeof(ddofx));
-    ddofx.dwSize = sizeof(ddofx);
-    ddofx.dckDestColorkey.dwColorSpaceLowValue = sys->i_colorkey;
-    ddofx.dckDestColorkey.dwColorSpaceHighValue = sys->i_colorkey;
-
-    HRESULT hr = IDirectDrawSurface2_UpdateOverlay(surface,
-                                                   &src, sys->display, &dst,
-                                                   DDOVER_SHOW | DDOVER_KEYDESTOVERRIDE, &ddofx);
-    sys->restore_overlay = hr != DD_OK;
-
-    if (hr != DD_OK) {
-        msg_Warn(vd, "DirectDrawUpdateOverlay cannot move/resize overlay. (hr=0x%lX)", hr);
-        return VLC_EGENERIC;
-    }
-    return VLC_SUCCESS;
-}
-
-/* */
-static void WallpaperChange(vout_display_t *vd, bool use_wallpaper)
-{
-    vout_display_sys_t *sys = vd->sys;
-
-    if (!sys->use_wallpaper == !use_wallpaper)
-        return;
-
-    HWND hwnd = FindWindow(_T("Progman"), NULL);
-    if (hwnd)
-        hwnd = FindWindowEx(hwnd, NULL, _T("SHELLDLL_DefView"), NULL);
-    if (hwnd)
-        hwnd = FindWindowEx(hwnd, NULL, _T("SysListView32"), NULL);
-    if (!hwnd) {
-        msg_Warn(vd, "couldn't find \"SysListView32\" window, "
-                     "wallpaper mode not supported");
-        return;
-    }
-
-    msg_Dbg(vd, "wallpaper mode %s", use_wallpaper ? "enabled" : "disabled");
-    sys->use_wallpaper = use_wallpaper;
-
-    if (sys->use_wallpaper) {
-        sys->color_bkg    = ListView_GetBkColor(hwnd);
-        sys->color_bkgtxt = ListView_GetTextBkColor(hwnd);
-
-        ListView_SetBkColor(hwnd,     sys->i_rgb_colorkey);
-        ListView_SetTextBkColor(hwnd, sys->i_rgb_colorkey);
-    } else {
-        ListView_SetBkColor(hwnd,     sys->color_bkg);
-        ListView_SetTextBkColor(hwnd, sys->color_bkgtxt);
-    }
-
-    /* Update desktop */
-    InvalidateRect(hwnd, NULL, TRUE);
-    UpdateWindow(hwnd);
-
-    if (sys->use_overlay)
-      DirectXUpdateOverlay(vd, NULL);
-}
-
-/* */
-static int WallpaperCallback(vlc_object_t *object, char const *cmd,
-                             vlc_value_t oldval, vlc_value_t newval, void *data)
-{
-    vout_display_t *vd = (vout_display_t *)object;
-    vout_display_sys_t *sys = vd->sys;
-    VLC_UNUSED(cmd); VLC_UNUSED(oldval); VLC_UNUSED(data);
-
-    vlc_mutex_lock(&sys->lock);
-    const bool ch_wallpaper = !sys->wallpaper_requested != !newval.b_bool;
-    sys->ch_wallpaper |= ch_wallpaper;
-    sys->wallpaper_requested = newval.b_bool;
-    vlc_mutex_unlock(&sys->lock);
-    return VLC_SUCCESS;
-}
-
-typedef struct
-{
-    char **values;
-    char **descs;
-    size_t count;
-} enum_context_t;
-
-/*****************************************************************************
- * config variable callback
- *****************************************************************************/
-static BOOL WINAPI DirectXEnumCallback2(GUID *guid, LPSTR desc,
-                                        LPSTR drivername, VOID *data,
-                                        HMONITOR hmon)
-{
-    enum_context_t *ctx = data;
-
-    VLC_UNUSED(guid); VLC_UNUSED(desc); VLC_UNUSED(hmon);
-
-    char *psz_drivername = drivername;
-    ctx->values = xrealloc(ctx->values, (ctx->count + 1) * sizeof(char *));
-    ctx->descs = xrealloc(ctx->descs, (ctx->count + 1) * sizeof(char *));
-
-    ctx->values[ctx->count] = strdup(psz_drivername);
-    ctx->descs[ctx->count] = strdup(psz_drivername);
-    ctx->count++;
-
-    return TRUE; /* Keep enumerating */
-}
-
-static int FindDevicesCallback(vlc_object_t *object, const char *name,
-                               char ***values, char ***descs)
-{
-    enum_context_t ctx;
-
-    ctx.values = xmalloc(sizeof(char *));
-    ctx.descs = xmalloc(sizeof(char *));
-    ctx.values[0] = strdup("");
-    ctx.descs[0] = strdup(_("Default"));
-    ctx.count = 1;
-
-    /* Load direct draw DLL */
-    HINSTANCE hddraw_dll = LoadLibrary(_T("DDRAW.DLL"));
-    if (hddraw_dll != NULL)
-    {
-        /* Enumerate displays */
-        HRESULT (WINAPI *OurDirectDrawEnumerateEx)(LPDDENUMCALLBACKEXA,
-                                                   LPVOID, DWORD) =
-              (void *)GetProcAddress(hddraw_dll, DIRECTDRAWENUMERATEEX_NAME);
-        if (OurDirectDrawEnumerateEx != NULL)
-            OurDirectDrawEnumerateEx(DirectXEnumCallback2, &ctx,
-                                     DDENUM_ATTACHEDSECONDARYDEVICES);
-        FreeLibrary(hddraw_dll);
-    }
-
-    VLC_UNUSED(object);
-    VLC_UNUSED(name);
-
-    *values = ctx.values;
-    *descs = ctx.descs;
-    return ctx.count;
-}
-
-
diff --git a/modules/video_output/msw/events.c b/modules/video_output/msw/events.c
deleted file mode 100644 (file)
index c41fd89..0000000
+++ /dev/null
@@ -1,1124 +0,0 @@
-/*****************************************************************************
- * events.c: Windows video output events handler
- *****************************************************************************
- * Copyright (C) 2001-2009 VLC authors and VideoLAN
- * $Id$
- *
- * Authors: Gildas Bazin <gbazin@videolan.org>
- *          Martell Malone <martellmalone@gmail.com>
- *
- * 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 Lesser General Public License for more details.
- *
- * 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.
- *****************************************************************************/
-
-/*****************************************************************************
- * Preamble: This file contains the functions related to the creation of
- *             a window and the handling of its messages (events).
- *****************************************************************************/
-
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#include "win32touch.h"
-
-#include <vlc_common.h>
-#include <vlc_vout_display.h>
-
-#include <windows.h>
-#include <windowsx.h>                                        /* GET_X_LPARAM */
-#include <shellapi.h>                                         /* ExtractIcon */
-
-#include "common.h"
-
-/*****************************************************************************
- * Local prototypes.
- *****************************************************************************/
-#define WM_VLC_HIDE_MOUSE   (WM_APP + 0)
-#define WM_VLC_CHANGE_TEXT  (WM_APP + 1)
-
-struct event_thread_t
-{
-    vout_display_t *vd;
-
-    /* */
-    vlc_thread_t thread;
-    vlc_mutex_t  lock;
-    vlc_cond_t   wait;
-    bool         b_ready;
-    bool         b_done;
-    bool         b_error;
-
-    /* */
-    bool use_desktop;
-    bool use_overlay;
-
-    /* Mouse */
-    bool is_cursor_hidden;
-    HCURSOR cursor_arrow;
-    HCURSOR cursor_empty;
-    unsigned button_pressed;
-
-    /* Gestures */
-    win32_gesture_sys_t *p_gesture;
-
-    /* Title */
-    char *psz_title;
-
-    int i_window_style;
-    int x, y;
-    unsigned width, height;
-
-    /* */
-    vout_window_t *parent_window;
-    TCHAR class_main[256];
-    TCHAR class_video[256];
-    HWND hparent;
-    HWND hwnd;
-    HWND hvideownd;
-    HWND hfswnd;
-    video_format_t       source;
-    vout_display_place_t place;
-
-    HICON vlc_icon;
-
-    bool has_moved;
-};
-
-/***************************
- * Local Prototypes        *
- ***************************/
-/* Window Creation */
-static int  Win32VoutCreateWindow( event_thread_t * );
-static void Win32VoutCloseWindow ( event_thread_t * );
-static long FAR PASCAL WinVoutEventProc( HWND, UINT, WPARAM, LPARAM );
-static int  Win32VoutConvertKey( int i_key );
-
-/* Display/Hide Cursor */
-static void UpdateCursor( event_thread_t *p_event, bool b_show );
-static HCURSOR EmptyCursor( HINSTANCE instance );
-
-/* Mouse events sending functions */
-static void MouseReleased( event_thread_t *p_event, unsigned button );
-static void MousePressed( event_thread_t *p_event, HWND hwnd, unsigned button );
-
-/* Local helpers */
-static inline bool isMouseEvent( WPARAM type )
-{
-    return type >= WM_MOUSEFIRST &&
-           type <= WM_MOUSELAST;
-}
-
-static inline bool isKeyEvent( WPARAM type )
-{
-    return type >= WM_KEYFIRST &&
-           type <= WM_KEYLAST;
-}
-/*****************************************************************************
- * EventThread: Create video window & handle its messages
- *****************************************************************************
- * This function creates a video window and then enters an infinite loop
- * that handles the messages sent to that window.
- * The main goal of this thread is to isolate the Win32 PeekMessage function
- * because this one can block for a long time.
- *****************************************************************************/
-static void *EventThread( void *p_this )
-{
-    event_thread_t *p_event = (event_thread_t *)p_this;
-    vout_display_t *vd = p_event->vd;
-    MSG msg;
-    POINT old_mouse_pos = {0,0}, mouse_pos;
-    int canc = vlc_savecancel ();
-
-    bool b_mouse_support = var_InheritBool( p_event->vd, "mouse-events" );
-    bool b_key_support = var_InheritBool( p_event->vd, "keyboard-events" );
-
-    vlc_mutex_lock( &p_event->lock );
-    /* Create a window for the video */
-    /* Creating a window under Windows also initializes the thread's event
-     * message queue */
-    if( Win32VoutCreateWindow( p_event ) )
-        p_event->b_error = true;
-
-    p_event->b_ready = true;
-    vlc_cond_signal( &p_event->wait );
-
-    const bool b_error = p_event->b_error;
-    vlc_mutex_unlock( &p_event->lock );
-
-    if( b_error )
-    {
-        vlc_restorecancel( canc );
-        return NULL;
-    }
-
-    /* Prevent monitor from powering off */
-    if (var_GetBool(vd, "disable-screensaver"))
-        SetThreadExecutionState( ES_DISPLAY_REQUIRED | ES_SYSTEM_REQUIRED | ES_CONTINUOUS );
-
-    /* Main loop */
-    /* GetMessage will sleep if there's no message in the queue */
-    for( ;; )
-    {
-        vout_display_place_t place;
-        video_format_t       source;
-
-        if( !GetMessage( &msg, 0, 0, 0 ) )
-        {
-            vlc_mutex_lock( &p_event->lock );
-            p_event->b_done = true;
-            vlc_mutex_unlock( &p_event->lock );
-            break;
-        }
-
-        /* Check if we are asked to exit */
-        vlc_mutex_lock( &p_event->lock );
-        const bool b_done = p_event->b_done;
-        vlc_mutex_unlock( &p_event->lock );
-        if( b_done )
-            break;
-
-        if( !b_mouse_support && isMouseEvent( msg.message ) )
-            continue;
-
-        if( !b_key_support && isKeyEvent( msg.message ) )
-            continue;
-
-        /* Handle mouse state */
-        if( msg.message == WM_MOUSEMOVE ||
-            msg.message == WM_NCMOUSEMOVE )
-        {
-            GetCursorPos( &mouse_pos );
-            /* FIXME, why this >2 limits ? */
-            if( (abs(mouse_pos.x - old_mouse_pos.x) > 2 ||
-                (abs(mouse_pos.y - old_mouse_pos.y)) > 2 ) )
-            {
-                old_mouse_pos = mouse_pos;
-                UpdateCursor( p_event, true );
-            }
-        }
-        else if( isMouseEvent( msg.message ) )
-        {
-            UpdateCursor( p_event, true );
-        }
-        else if( msg.message == WM_VLC_HIDE_MOUSE )
-        {
-            UpdateCursor( p_event, false );
-        }
-
-        /* */
-        switch( msg.message )
-        {
-        case WM_MOUSEMOVE:
-            vlc_mutex_lock( &p_event->lock );
-            place  = p_event->place;
-            source = p_event->source;
-            vlc_mutex_unlock( &p_event->lock );
-
-            if( place.width > 0 && place.height > 0 )
-            {
-                if( msg.hwnd == p_event->hvideownd )
-                {
-                    /* Child window */
-                    place.x = 0;
-                    place.y = 0;
-                }
-                const int x = source.i_x_offset +
-                    (int64_t)(GET_X_LPARAM(msg.lParam) - place.x) * source.i_width  / place.width;
-                const int y = source.i_y_offset +
-                    (int64_t)(GET_Y_LPARAM(msg.lParam) - place.y) * source.i_height / place.height;
-                vout_display_SendEventMouseMoved(vd, x, y);
-            }
-            break;
-        case WM_NCMOUSEMOVE:
-            break;
-
-        case WM_VLC_HIDE_MOUSE:
-            break;
-
-        case WM_LBUTTONDOWN:
-            MousePressed( p_event, msg.hwnd, MOUSE_BUTTON_LEFT );
-            break;
-        case WM_LBUTTONUP:
-            MouseReleased( p_event, MOUSE_BUTTON_LEFT );
-            break;
-        case WM_LBUTTONDBLCLK:
-            vout_display_SendEventMouseDoubleClick(vd);
-            break;
-
-        case WM_MBUTTONDOWN:
-            MousePressed( p_event, msg.hwnd, MOUSE_BUTTON_CENTER );
-            break;
-        case WM_MBUTTONUP:
-            MouseReleased( p_event, MOUSE_BUTTON_CENTER );
-            break;
-
-        case WM_RBUTTONDOWN:
-            MousePressed( p_event, msg.hwnd, MOUSE_BUTTON_RIGHT );
-            break;
-        case WM_RBUTTONUP:
-            MouseReleased( p_event, MOUSE_BUTTON_RIGHT );
-            break;
-
-        case WM_KEYDOWN:
-        case WM_SYSKEYDOWN:
-        {
-            /* The key events are first processed here and not translated
-             * into WM_CHAR events because we need to know the status of the
-             * modifier keys. */
-            int i_key = Win32VoutConvertKey( msg.wParam );
-            if( !i_key )
-            {
-                /* This appears to be a "normal" (ascii) key */
-                i_key = tolower( (unsigned char)MapVirtualKey( msg.wParam, 2 ) );
-            }
-
-            if( i_key )
-            {
-                if( GetKeyState(VK_CONTROL) & 0x8000 )
-                {
-                    i_key |= KEY_MODIFIER_CTRL;
-                }
-                if( GetKeyState(VK_SHIFT) & 0x8000 )
-                {
-                    i_key |= KEY_MODIFIER_SHIFT;
-                }
-                if( GetKeyState(VK_MENU) & 0x8000 )
-                {
-                    i_key |= KEY_MODIFIER_ALT;
-                }
-
-                vout_display_SendEventKey(vd, i_key);
-            }
-            break;
-        }
-
-        case WM_MOUSEWHEEL:
-        {
-            int i_key;
-            if( GET_WHEEL_DELTA_WPARAM( msg.wParam ) > 0 )
-            {
-                i_key = KEY_MOUSEWHEELUP;
-            }
-            else
-            {
-                i_key = KEY_MOUSEWHEELDOWN;
-            }
-            if( i_key )
-            {
-                if( GetKeyState(VK_CONTROL) & 0x8000 )
-                {
-                    i_key |= KEY_MODIFIER_CTRL;
-                }
-                if( GetKeyState(VK_SHIFT) & 0x8000 )
-                {
-                    i_key |= KEY_MODIFIER_SHIFT;
-                }
-                if( GetKeyState(VK_MENU) & 0x8000 )
-                {
-                    i_key |= KEY_MODIFIER_ALT;
-                }
-                vout_display_SendEventKey(vd, i_key);
-            }
-            break;
-        }
-
-        case WM_VLC_CHANGE_TEXT:
-        {
-            vlc_mutex_lock( &p_event->lock );
-            wchar_t *pwz_title = NULL;
-            if( p_event->psz_title )
-            {
-                const size_t i_length = strlen(p_event->psz_title);
-                pwz_title = malloc( 2 * (i_length + 1) );
-                if( pwz_title )
-                {
-                    mbstowcs( pwz_title, p_event->psz_title, 2 * i_length );
-                    pwz_title[i_length] = 0;
-                }
-            }
-            vlc_mutex_unlock( &p_event->lock );
-
-            if( pwz_title )
-            {
-                SetWindowTextW( p_event->hwnd, pwz_title );
-                if( p_event->hfswnd )
-                    SetWindowTextW( p_event->hfswnd, pwz_title );
-                free( pwz_title );
-            }
-            break;
-        }
-
-        default:
-            /* Messages we don't handle directly are dispatched to the
-             * window procedure */
-            TranslateMessage(&msg);
-            DispatchMessage(&msg);
-            break;
-
-        } /* End Switch */
-
-    } /* End Main loop */
-
-    /* Check for WM_QUIT if we created the window */
-    if( !p_event->hparent && msg.message == WM_QUIT )
-    {
-        msg_Warn( vd, "WM_QUIT... should not happen!!" );
-        p_event->hwnd = NULL; /* Window already destroyed */
-    }
-
-    msg_Dbg( vd, "Win32 Vout EventThread terminating" );
-
-    Win32VoutCloseWindow( p_event );
-    vlc_restorecancel(canc);
-    return NULL;
-}
-
-void EventThreadMouseHide( event_thread_t *p_event )
-{
-    PostMessage( p_event->hwnd, WM_VLC_HIDE_MOUSE, 0, 0 );
-}
-
-void EventThreadUpdateTitle( event_thread_t *p_event, const char *psz_fallback )
-{
-    char *psz_title = var_InheritString( p_event->vd, "video-title" );
-    if( !psz_title )
-        psz_title = strdup( psz_fallback );
-    if( !psz_title )
-        return;
-
-    vlc_mutex_lock( &p_event->lock );
-    free( p_event->psz_title );
-    p_event->psz_title = psz_title;
-    vlc_mutex_unlock( &p_event->lock );
-
-    PostMessage( p_event->hwnd, WM_VLC_CHANGE_TEXT, 0, 0 );
-}
-int EventThreadGetWindowStyle( event_thread_t *p_event )
-{
-    /* No need to lock, it is serialized by EventThreadStart */
-    return p_event->i_window_style;
-}
-
-void EventThreadUpdateWindowPosition( event_thread_t *p_event,
-                                      bool *pb_moved, bool *pb_resized,
-                                      int x, int y, unsigned w, unsigned h )
-{
-    vlc_mutex_lock( &p_event->lock );
-    *pb_moved   = x != p_event->x || y != p_event->y;
-    *pb_resized = w != p_event->width || h != p_event->height;
-
-    p_event->x      = x;
-    p_event->y      = y;
-    p_event->width  = w;
-    p_event->height = h;
-    vlc_mutex_unlock( &p_event->lock );
-}
-
-void EventThreadUpdateSourceAndPlace( event_thread_t *p_event,
-                                      const video_format_t *p_source,
-                                      const vout_display_place_t *p_place )
-{
-    vlc_mutex_lock( &p_event->lock );
-    p_event->source = *p_source;
-    p_event->place  = *p_place;
-    vlc_mutex_unlock( &p_event->lock );
-}
-
-void EventThreadUseOverlay( event_thread_t *p_event, bool b_used )
-{
-    vlc_mutex_lock( &p_event->lock );
-    p_event->use_overlay = b_used;
-    vlc_mutex_unlock( &p_event->lock );
-}
-bool EventThreadGetAndResetHasMoved( event_thread_t *p_event )
-{
-    vlc_mutex_lock( &p_event->lock );
-    const bool has_moved = p_event->has_moved;
-    p_event->has_moved = false;
-    vlc_mutex_unlock( &p_event->lock );
-
-    return has_moved;
-}
-
-event_thread_t *EventThreadCreate( vout_display_t *vd)
-{
-     /* Create the Vout EventThread, this thread is created by us to isolate
-     * the Win32 PeekMessage function calls. We want to do this because
-     * Windows can stay blocked inside this call for a long time, and when
-     * this happens it thus blocks vlc's video_output thread.
-     * Vout EventThread will take care of the creation of the video
-     * window (because PeekMessage has to be called from the same thread which
-     * created the window). */
-    msg_Dbg( vd, "creating Vout EventThread" );
-    event_thread_t *p_event = malloc( sizeof(*p_event) );
-    if( !p_event )
-        return NULL;
-
-    p_event->vd = vd;
-    vlc_mutex_init( &p_event->lock );
-    vlc_cond_init( &p_event->wait );
-
-    p_event->is_cursor_hidden = false;
-    p_event->button_pressed = 0;
-    p_event->psz_title = NULL;
-    p_event->source = vd->source;
-    vout_display_PlacePicture(&p_event->place, &vd->source, vd->cfg, false);
-
-    _sntprintf( p_event->class_main, sizeof(p_event->class_main)/sizeof(*p_event->class_main),
-               _T("VLC video main %p"), (void *)p_event );
-    _sntprintf( p_event->class_video, sizeof(p_event->class_video)/sizeof(*p_event->class_video),
-               _T("VLC video output %p"), (void *)p_event );
-    return p_event;
-}
-
-void EventThreadDestroy( event_thread_t *p_event )
-{
-    free( p_event->psz_title );
-    vlc_cond_destroy( &p_event->wait );
-    vlc_mutex_destroy( &p_event->lock );
-    free( p_event );
-}
-
-int EventThreadStart( event_thread_t *p_event, event_hwnd_t *p_hwnd, const event_cfg_t *p_cfg )
-{
-    p_event->use_desktop = p_cfg->use_desktop;
-    p_event->use_overlay = p_cfg->use_overlay;
-    p_event->x           = p_cfg->x;
-    p_event->y           = p_cfg->y;
-    p_event->width       = p_cfg->width;
-    p_event->height      = p_cfg->height;
-
-    p_event->has_moved = false;
-
-    p_event->b_ready = false;
-    p_event->b_done  = false;
-    p_event->b_error = false;
-
-    if( vlc_clone( &p_event->thread, EventThread, p_event,
-                   VLC_THREAD_PRIORITY_LOW ) )
-    {
-        msg_Err( p_event->vd, "cannot create Vout EventThread" );
-        return VLC_EGENERIC;
-    }
-
-    vlc_mutex_lock( &p_event->lock );
-    while( !p_event->b_ready )
-        vlc_cond_wait( &p_event->wait, &p_event->lock );
-    const bool b_error = p_event->b_error;
-    vlc_mutex_unlock( &p_event->lock );
-
-    if( b_error )
-    {
-        vlc_join( p_event->thread, NULL );
-        p_event->b_ready = false;
-        return VLC_EGENERIC;
-    }
-    msg_Dbg( p_event->vd, "Vout EventThread running" );
-
-    /* */
-    p_hwnd->parent_window = p_event->parent_window;
-    p_hwnd->hparent       = p_event->hparent;
-    p_hwnd->hwnd          = p_event->hwnd;
-    p_hwnd->hvideownd     = p_event->hvideownd;
-    p_hwnd->hfswnd        = p_event->hfswnd;
-    return VLC_SUCCESS;
-}
-
-void EventThreadStop( event_thread_t *p_event )
-{
-    if( !p_event->b_ready )
-        return;
-
-    vlc_mutex_lock( &p_event->lock );
-    p_event->b_done = true;
-    vlc_mutex_unlock( &p_event->lock );
-
-    /* we need to be sure Vout EventThread won't stay stuck in
-     * GetMessage, so we send a fake message */
-    if( p_event->hwnd )
-        PostMessage( p_event->hwnd, WM_NULL, 0, 0);
-
-    vlc_join( p_event->thread, NULL );
-    p_event->b_ready = false;
-}
-
-
-/***********************************
- * Local functions implementations *
- ***********************************/
-static void UpdateCursor( event_thread_t *p_event, bool b_show )
-{
-    if( p_event->is_cursor_hidden == !b_show )
-        return;
-    p_event->is_cursor_hidden = !b_show;
-
-#if 1
-    HCURSOR cursor = b_show ? p_event->cursor_arrow : p_event->cursor_empty;
-    if( p_event->hvideownd )
-        SetClassLongPtr( p_event->hvideownd, GCLP_HCURSOR, (LONG_PTR)cursor );
-    if( p_event->hwnd )
-        SetClassLongPtr( p_event->hwnd, GCLP_HCURSOR, (LONG_PTR)cursor );
-#endif
-
-    /* FIXME I failed to find a cleaner way to force a redraw of the cursor */
-    POINT p;
-    GetCursorPos(&p);
-    HWND hwnd = WindowFromPoint(p);
-    if( hwnd == p_event->hvideownd || hwnd == p_event->hwnd )
-    {
-        if( b_show )
-            SetCursor( cursor );
-        else
-            SetCursorPos( p.x, p.y );
-    }
-}
-
-static HCURSOR EmptyCursor( HINSTANCE instance )
-{
-    const int cw = GetSystemMetrics(SM_CXCURSOR);
-    const int ch = GetSystemMetrics(SM_CYCURSOR);
-
-    HCURSOR cursor = NULL;
-    uint8_t *and = malloc(cw * ch);
-    uint8_t *xor = malloc(cw * ch);
-    if( and && xor )
-    {
-        memset(and, 0xff, cw * ch );
-        memset(xor, 0x00, cw * ch );
-        cursor = CreateCursor( instance, 0, 0, cw, ch, and, xor);
-    }
-    free( and );
-    free( xor );
-
-    return cursor;
-}
-
-static void MousePressed( event_thread_t *p_event, HWND hwnd, unsigned button )
-{
-    if( !p_event->button_pressed )
-        SetCapture( hwnd );
-    p_event->button_pressed |= 1 << button;
-    vout_display_SendEventMousePressed( p_event->vd, button );
-}
-
-static void MouseReleased( event_thread_t *p_event, unsigned button )
-{
-    p_event->button_pressed &= ~(1 << button);
-    if( !p_event->button_pressed )
-        ReleaseCapture();
-    vout_display_SendEventMouseReleased( p_event->vd, button );
-}
-
-#if defined(MODULE_NAME_IS_direct3d9) || defined(MODULE_NAME_IS_direct3d11)
-static int CALLBACK
-enumWindowsProc(HWND hwnd, LPARAM lParam)
-{
-    HWND *wnd = (HWND *)lParam;
-
-    char name[128];
-    name[0] = '\0';
-    GetClassNameA( hwnd, name, 128 );
-
-    if( !strcasecmp( name, "WorkerW" ) )
-    {
-        hwnd = FindWindowEx( hwnd, NULL, _T("SHELLDLL_DefView"), NULL );
-        if( hwnd ) hwnd = FindWindowEx( hwnd, NULL, _T("SysListView32"), NULL );
-        if( hwnd )
-        {
-            *wnd = hwnd;
-            return false;
-        }
-    }
-    return true;
-}
-
-static HWND GetDesktopHandle(vout_display_t *vd)
-{
-    /* Find Program Manager */
-    HWND hwnd = FindWindow( _T("Progman"), NULL );
-    if( hwnd ) hwnd = FindWindowEx( hwnd, NULL, _T("SHELLDLL_DefView"), NULL );
-    if( hwnd ) hwnd = FindWindowEx( hwnd, NULL, _T("SysListView32"), NULL );
-    if( hwnd )
-        return hwnd;
-
-    msg_Dbg( vd, "Couldn't find desktop icon window,. Trying the hard way." );
-
-    EnumWindows( enumWindowsProc, (LPARAM)&hwnd );
-    return hwnd;
-}
-#endif
-
-/*****************************************************************************
- * Win32VoutCreateWindow: create a window for the video.
- *****************************************************************************
- * Before creating a direct draw surface, we need to create a window in which
- * the video will be displayed. This window will also allow us to capture the
- * events.
- *****************************************************************************/
-static int Win32VoutCreateWindow( event_thread_t *p_event )
-{
-    vout_display_t *vd = p_event->vd;
-    HINSTANCE  hInstance;
-    HMENU      hMenu;
-    RECT       rect_window;
-    WNDCLASS   wc;                            /* window class components */
-    TCHAR      vlc_path[MAX_PATH+1];
-    int        i_style;
-
-    msg_Dbg( vd, "Win32VoutCreateWindow" );
-
-    /* Get this module's instance */
-    hInstance = GetModuleHandle(NULL);
-
-    #if defined(MODULE_NAME_IS_direct3d9) || defined(MODULE_NAME_IS_direct3d11)
-    if( !p_event->use_desktop )
-    #endif
-    {
-        /* If an external window was specified, we'll draw in it. */
-        p_event->parent_window = vout_display_NewWindow(vd, VOUT_WINDOW_TYPE_HWND);
-        if( p_event->parent_window )
-            p_event->hparent = p_event->parent_window->handle.hwnd;
-        else
-            p_event->hparent = NULL;
-    }
-    #if defined(MODULE_NAME_IS_direct3d9) || defined(MODULE_NAME_IS_direct3d11)
-    else
-    {
-        vout_display_DeleteWindow(vd, NULL);
-        p_event->parent_window = NULL;
-        p_event->hparent = GetDesktopHandle(vd);
-    }
-    #endif
-    p_event->cursor_arrow = LoadCursor(NULL, IDC_ARROW);
-    p_event->cursor_empty = EmptyCursor(hInstance);
-
-    /* Get the Icon from the main app */
-    p_event->vlc_icon = NULL;
-    if( GetModuleFileName( NULL, vlc_path, MAX_PATH ) )
-    {
-        p_event->vlc_icon = ExtractIcon( hInstance, vlc_path, 0 );
-    }
-
-    /* Fill in the window class structure */
-    wc.style         = CS_OWNDC|CS_DBLCLKS;          /* style: dbl click */
-    wc.lpfnWndProc   = (WNDPROC)WinVoutEventProc;       /* event handler */
-    wc.cbClsExtra    = 0;                         /* no extra class data */
-    wc.cbWndExtra    = 0;                        /* no extra window data */
-    wc.hInstance     = hInstance;                            /* instance */
-    wc.hIcon         = p_event->vlc_icon;       /* load the vlc big icon */
-    wc.hCursor       = p_event->is_cursor_hidden ? p_event->cursor_empty :
-                                                   p_event->cursor_arrow;
-#if !VLC_WINSTORE_APP
-    wc.hbrBackground = GetStockObject(BLACK_BRUSH);  /* background color */
-#else
-    wc.hbrBackground = NULL;
-#endif
-    wc.lpszMenuName  = NULL;                                  /* no menu */
-    wc.lpszClassName = p_event->class_main;       /* use a special class */
-
-    /* Register the window class */
-    if( !RegisterClass(&wc) )
-    {
-        if( p_event->vlc_icon )
-            DestroyIcon( p_event->vlc_icon );
-
-        msg_Err( vd, "Win32VoutCreateWindow RegisterClass FAILED (err=%lu)", GetLastError() );
-        return VLC_EGENERIC;
-    }
-
-    /* Register the video sub-window class */
-    wc.lpszClassName = p_event->class_video;
-    wc.hIcon = 0;
-    wc.hbrBackground = NULL; /* no background color */
-    if( !RegisterClass(&wc) )
-    {
-        msg_Err( vd, "Win32VoutCreateWindow RegisterClass FAILED (err=%lu)", GetLastError() );
-        return VLC_EGENERIC;
-    }
-
-    /* When you create a window you give the dimensions you wish it to
-     * have. Unfortunatly these dimensions will include the borders and
-     * titlebar. We use the following function to find out the size of
-     * the window corresponding to the useable surface we want */
-    rect_window.left   = 10;
-    rect_window.top    = 10;
-    rect_window.right  = rect_window.left + p_event->width;
-    rect_window.bottom = rect_window.top  + p_event->height;
-
-    i_style = var_GetBool( vd, "video-deco" )
-        /* Open with window decoration */
-        ? WS_OVERLAPPEDWINDOW|WS_SIZEBOX
-        /* No window decoration */
-        : WS_POPUP;
-    AdjustWindowRect( &rect_window, i_style, 0 );
-    i_style |= WS_VISIBLE|WS_CLIPCHILDREN;
-
-    if( p_event->hparent )
-    {
-        i_style = WS_VISIBLE|WS_CLIPCHILDREN|WS_CHILD;
-
-        /* allow user to regain control over input events if requested */
-        bool b_mouse_support = var_InheritBool( vd, "mouse-events" );
-        bool b_key_support = var_InheritBool( vd, "keyboard-events" );
-        if( !b_mouse_support && !b_key_support )
-            i_style |= WS_DISABLED;
-    }
-
-    p_event->i_window_style = i_style;
-
-    /* Create the window */
-    p_event->hwnd =
-        CreateWindowEx( WS_EX_NOPARENTNOTIFY,
-                    p_event->class_main,             /* name of window class */
-                    _T(VOUT_TITLE) _T(" (VLC Video Output)"),/* window title */
-                    i_style,                                 /* window style */
-                    (!p_event->x) ? (UINT)CW_USEDEFAULT :
-                        (UINT)p_event->x,            /* default X coordinate */
-                    (!p_event->y) ? (UINT)CW_USEDEFAULT :
-                        (UINT)p_event->y,            /* default Y coordinate */
-                    rect_window.right - rect_window.left,    /* window width */
-                    rect_window.bottom - rect_window.top,   /* window height */
-                    p_event->hparent,                       /* parent window */
-                    NULL,                          /* no menu in this window */
-                    hInstance,            /* handle of this program instance */
-                    (LPVOID)p_event );           /* send vd to WM_CREATE */
-
-    if( !p_event->hwnd )
-    {
-        msg_Warn( vd, "Win32VoutCreateWindow create window FAILED (err=%lu)", GetLastError() );
-        return VLC_EGENERIC;
-    }
-
-    InitGestures( p_event->hwnd, &p_event->p_gesture );
-
-    if( p_event->hparent )
-    {
-        LONG i_style;
-
-        /* We don't want the window owner to overwrite our client area */
-        i_style = GetWindowLong( p_event->hparent, GWL_STYLE );
-
-        if( !(i_style & WS_CLIPCHILDREN) )
-            /* Hmmm, apparently this is a blocking call... */
-            SetWindowLong( p_event->hparent, GWL_STYLE,
-                           i_style | WS_CLIPCHILDREN );
-
-        /* Create our fullscreen window */
-        p_event->hfswnd =
-            CreateWindowEx( WS_EX_APPWINDOW, p_event->class_main,
-                            _T(VOUT_TITLE) _T(" (VLC Fullscreen Video Output)"),
-                            WS_OVERLAPPEDWINDOW|WS_CLIPCHILDREN|WS_SIZEBOX,
-                            CW_USEDEFAULT, CW_USEDEFAULT,
-                            CW_USEDEFAULT, CW_USEDEFAULT,
-                            NULL, NULL, hInstance, NULL );
-    }
-    else
-    {
-        p_event->hfswnd = NULL;
-    }
-
-    /* Append a "Always On Top" entry in the system menu */
-    hMenu = GetSystemMenu( p_event->hwnd, FALSE );
-    AppendMenu( hMenu, MF_SEPARATOR, 0, _T("") );
-    AppendMenu( hMenu, MF_STRING | MF_UNCHECKED,
-                       IDM_TOGGLE_ON_TOP, _T("Always on &Top") );
-
-    /* Create video sub-window. This sub window will always exactly match
-     * the size of the video, which allows us to use crazy overlay colorkeys
-     * without having them shown outside of the video area. */
-    /* FIXME vd->source.i_width/i_height seems wrong */
-    p_event->hvideownd =
-    CreateWindow( p_event->class_video, _T(""),   /* window class */
-        WS_CHILD,                   /* window style, not visible initially */
-        0, 0,
-        vd->source.i_width,          /* default width */
-        vd->source.i_height,        /* default height */
-        p_event->hwnd,               /* parent window */
-        NULL, hInstance,
-        (LPVOID)p_event );    /* send vd to WM_CREATE */
-
-    if( !p_event->hvideownd )
-        msg_Warn( vd, "can't create video sub-window" );
-    else
-        msg_Dbg( vd, "created video sub-window" );
-
-    /* Now display the window */
-    ShowWindow( p_event->hwnd, SW_SHOW );
-
-    return VLC_SUCCESS;
-}
-
-/*****************************************************************************
- * Win32VoutCloseWindow: close the window created by Win32VoutCreateWindow
- *****************************************************************************
- * This function returns all resources allocated by Win32VoutCreateWindow.
- *****************************************************************************/
-static void Win32VoutCloseWindow( event_thread_t *p_event )
-{
-    vout_display_t *vd = p_event->vd;
-    msg_Dbg( vd, "Win32VoutCloseWindow" );
-
-    #if defined(MODULE_NAME_IS_direct3d9) || defined(MODULE_NAME_IS_direct3d11)
-    DestroyWindow( p_event->hvideownd );
-    #endif
-    DestroyWindow( p_event->hwnd );
-    if( p_event->hfswnd )
-        DestroyWindow( p_event->hfswnd );
-
-    #if defined(MODULE_NAME_IS_direct3d9) || defined(MODULE_NAME_IS_direct3d11)
-    if( !p_event->use_desktop )
-    #endif
-        vout_display_DeleteWindow( vd, p_event->parent_window );
-    p_event->hwnd = NULL;
-
-    HINSTANCE hInstance = GetModuleHandle(NULL);
-    UnregisterClass( p_event->class_video, hInstance );
-    UnregisterClass( p_event->class_main, hInstance );
-
-    if( p_event->vlc_icon )
-        DestroyIcon( p_event->vlc_icon );
-
-    DestroyCursor( p_event->cursor_empty );
-
-    CloseGestures( p_event->p_gesture);
-}
-
-/*****************************************************************************
- * WinVoutEventProc: This is the window event processing function.
- *****************************************************************************
- * On Windows, when you create a window you have to attach an event processing
- * function to it. The aim of this function is to manage "Queued Messages" and
- * "Nonqueued Messages".
- * Queued Messages are those picked up and retransmitted by vout_Manage
- * (using the GetMessage and DispatchMessage functions).
- * Nonqueued Messages are those that Windows will send directly to this
- * procedure (like WM_DESTROY, WM_WINDOWPOSCHANGED...)
- *****************************************************************************/
-static long FAR PASCAL WinVoutEventProc( HWND hwnd, UINT message,
-                                         WPARAM wParam, LPARAM lParam )
-{
-    event_thread_t *p_event;
-
-    if( message == WM_CREATE )
-    {
-        /* Store vd for future use */
-        p_event = (event_thread_t *)((CREATESTRUCT *)lParam)->lpCreateParams;
-        SetWindowLongPtr( hwnd, GWLP_USERDATA, (LONG_PTR)p_event );
-        return TRUE;
-    }
-    else
-    {
-        LONG_PTR p_user_data = GetWindowLongPtr( hwnd, GWLP_USERDATA );
-        p_event = (event_thread_t *)p_user_data;
-        if( !p_event )
-        {
-            /* Hmmm mozilla does manage somehow to save the pointer to our
-             * windowproc and still calls it after the vout has been closed. */
-            return DefWindowProc(hwnd, message, wParam, lParam);
-        }
-    }
-    vout_display_t *vd = p_event->vd;
-
-#if 0
-    if( message == WM_SETCURSOR )
-    {
-        msg_Err(vd, "WM_SETCURSOR: %d (t2)", p_event->is_cursor_hidden);
-        SetCursor( p_event->is_cursor_hidden ? p_event->cursor_empty : p_event->cursor_arrow );
-        return 1;
-    }
-#endif
-    if( message == WM_CAPTURECHANGED )
-    {
-        for( int button = 0; p_event->button_pressed; button++ )
-        {
-            unsigned m = 1 << button;
-            if( p_event->button_pressed & m )
-                vout_display_SendEventMouseReleased( p_event->vd, button );
-            p_event->button_pressed &= ~m;
-        }
-        p_event->button_pressed = 0;
-        return 0;
-    }
-
-    if( hwnd == p_event->hvideownd )
-    {
-#ifdef MODULE_NAME_IS_directdraw
-        vlc_mutex_lock( &p_event->lock );
-        const bool use_overlay = p_event->use_overlay;
-        vlc_mutex_unlock( &p_event->lock );
-#endif
-
-        switch( message )
-        {
-#ifdef MODULE_NAME_IS_directdraw
-        case WM_ERASEBKGND:
-        /* For overlay, we need to erase background */
-            return !use_overlay ? 1 : DefWindowProc(hwnd, message, wParam, lParam);
-        case WM_PAINT:
-        /*
-        ** For overlay, DefWindowProc() will erase dirty regions
-        ** with colorkey.
-        ** For non-overlay, vout will paint the whole window at
-        ** regular interval, therefore dirty regions can be ignored
-        ** to minimize repaint.
-        */
-            if( !use_overlay )
-            {
-                ValidateRect(hwnd, NULL);
-            }
-            // fall through to default
-#else
-        /*
-        ** For OpenGL and Direct3D, vout will update the whole
-        ** window at regular interval, therefore dirty region
-        ** can be ignored to minimize repaint.
-        */
-        case WM_ERASEBKGND:
-            /* nothing to erase */
-            return 1;
-        case WM_PAINT:
-            /* nothing to repaint */
-            ValidateRect(hwnd, NULL);
-            // fall through
-#endif
-        default:
-            return DefWindowProc(hwnd, message, wParam, lParam);
-        }
-    }
-
-    switch( message )
-    {
-
-    case WM_WINDOWPOSCHANGED:
-        vlc_mutex_lock( &p_event->lock );
-        p_event->has_moved = true;
-        vlc_mutex_unlock( &p_event->lock );
-        return 0;
-
-    /* the user wants to close the window */
-    case WM_CLOSE:
-        vout_display_SendEventClose(vd);
-        return 0;
-
-    /* the window has been closed so shut down everything now */
-    case WM_DESTROY:
-        msg_Dbg( vd, "WinProc WM_DESTROY" );
-        /* just destroy the window */
-        PostQuitMessage( 0 );
-        return 0;
-
-    case WM_SYSCOMMAND:
-        switch (wParam)
-        {
-        case IDM_TOGGLE_ON_TOP:            /* toggle the "on top" status */
-        {
-            msg_Dbg(vd, "WinProc WM_SYSCOMMAND: IDM_TOGGLE_ON_TOP");
-            HMENU hMenu = GetSystemMenu(vd->sys->hwnd, FALSE);
-            vout_display_SendWindowState(vd, (GetMenuState(hMenu, IDM_TOGGLE_ON_TOP, MF_BYCOMMAND) & MF_CHECKED) ?
-                    VOUT_WINDOW_STATE_NORMAL : VOUT_WINDOW_STATE_ABOVE);
-            return 0;
-        }
-        default:
-            break;
-        }
-        break;
-
-    case WM_PAINT:
-    case WM_NCPAINT:
-    case WM_ERASEBKGND:
-        return DefWindowProc(hwnd, message, wParam, lParam);
-
-    case WM_KILLFOCUS:
-        return 0;
-
-    case WM_SETFOCUS:
-        return 0;
-
-    case WM_GESTURE:
-        return DecodeGesture( VLC_OBJECT(vd), p_event->p_gesture, hwnd, message, wParam, lParam );
-
-    default:
-        //msg_Dbg( vd, "WinProc WM Default %i", message );
-        break;
-    }
-
-    /* Let windows handle the message */
-    return DefWindowProc(hwnd, message, wParam, lParam);
-}
-
-static struct
-{
-    int i_dxkey;
-    int i_vlckey;
-
-} dxkeys_to_vlckeys[] =
-{
-    { VK_F1, KEY_F1 }, { VK_F2, KEY_F2 }, { VK_F3, KEY_F3 }, { VK_F4, KEY_F4 },
-    { VK_F5, KEY_F5 }, { VK_F6, KEY_F6 }, { VK_F7, KEY_F7 }, { VK_F8, KEY_F8 },
-    { VK_F9, KEY_F9 }, { VK_F10, KEY_F10 }, { VK_F11, KEY_F11 },
-    { VK_F12, KEY_F12 },
-
-    { VK_RETURN, KEY_ENTER },
-    { VK_SPACE, ' ' },
-    { VK_ESCAPE, KEY_ESC },
-
-    { VK_LEFT, KEY_LEFT },
-    { VK_RIGHT, KEY_RIGHT },
-    { VK_UP, KEY_UP },
-    { VK_DOWN, KEY_DOWN },
-
-    { VK_HOME, KEY_HOME },
-    { VK_END, KEY_END },
-    { VK_PRIOR, KEY_PAGEUP },
-    { VK_NEXT, KEY_PAGEDOWN },
-
-    { VK_INSERT, KEY_INSERT },
-    { VK_DELETE, KEY_DELETE },
-
-    { VK_CONTROL, 0 },
-    { VK_SHIFT, 0 },
-    { VK_MENU, 0 },
-
-    { VK_BROWSER_BACK, KEY_BROWSER_BACK },
-    { VK_BROWSER_FORWARD, KEY_BROWSER_FORWARD },
-    { VK_BROWSER_REFRESH, KEY_BROWSER_REFRESH },
-    { VK_BROWSER_STOP, KEY_BROWSER_STOP },
-    { VK_BROWSER_SEARCH, KEY_BROWSER_SEARCH },
-    { VK_BROWSER_FAVORITES, KEY_BROWSER_FAVORITES },
-    { VK_BROWSER_HOME, KEY_BROWSER_HOME },
-    { VK_VOLUME_MUTE, KEY_VOLUME_MUTE },
-    { VK_VOLUME_DOWN, KEY_VOLUME_DOWN },
-    { VK_VOLUME_UP, KEY_VOLUME_UP },
-    { VK_MEDIA_NEXT_TRACK, KEY_MEDIA_NEXT_TRACK },
-    { VK_MEDIA_PREV_TRACK, KEY_MEDIA_PREV_TRACK },
-    { VK_MEDIA_STOP, KEY_MEDIA_STOP },
-    { VK_MEDIA_PLAY_PAUSE, KEY_MEDIA_PLAY_PAUSE },
-
-    { 0, 0 }
-};
-
-static int Win32VoutConvertKey( int i_key )
-{
-    for( int i = 0; dxkeys_to_vlckeys[i].i_dxkey != 0; i++ )
-    {
-        if( dxkeys_to_vlckeys[i].i_dxkey == i_key )
-        {
-            return dxkeys_to_vlckeys[i].i_vlckey;
-        }
-    }
-
-    return 0;
-}
-
diff --git a/modules/video_output/msw/events.h b/modules/video_output/msw/events.h
deleted file mode 100644 (file)
index 883d769..0000000
+++ /dev/null
@@ -1,64 +0,0 @@
-/*****************************************************************************
- * events.h: Windows video output header file
- *****************************************************************************
- * Copyright (C) 2001-2009 VLC authors and VideoLAN
- * $Id$
- *
- * Authors: Gildas Bazin <gbazin@videolan.org>
- *          Damien Fouilleul <damienf@videolan.org>
- *
- * 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 Lesser General Public License for more details.
- *
- * 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.
- *****************************************************************************/
-
-#include <vlc_vout_window.h>
-
-/**
- * HWNDs manager.
- */
-typedef struct event_thread_t event_thread_t;
-
-typedef struct {
-    bool use_desktop; /* direct3d */
-    bool use_overlay; /* directdraw */
-    int x;
-    int y;
-    unsigned width;
-    unsigned height;
-} event_cfg_t;
-
-typedef struct {
-    vout_window_t *parent_window;
-    HWND hparent;
-    HWND hwnd;
-    HWND hvideownd;
-    HWND hfswnd;
-} event_hwnd_t;
-
-event_thread_t *EventThreadCreate( vout_display_t *);
-void            EventThreadDestroy( event_thread_t * );
-int             EventThreadStart( event_thread_t *, event_hwnd_t *, const event_cfg_t * );
-void            EventThreadStop( event_thread_t * );
-
-void            EventThreadMouseHide( event_thread_t * );
-void            EventThreadUpdateTitle( event_thread_t *, const char *psz_fallback );
-int             EventThreadGetWindowStyle( event_thread_t * );
-void            EventThreadUpdateWindowPosition( event_thread_t *, bool *pb_moved, bool *pb_resized,
-                                                 int x, int y, unsigned w, unsigned h );
-void            EventThreadUpdateSourceAndPlace( event_thread_t *p_event,
-                                                 const video_format_t *p_source,
-                                                 const vout_display_place_t *p_place );
-void            EventThreadUseOverlay( event_thread_t *, bool b_used );
-bool            EventThreadGetAndResetHasMoved( event_thread_t * );
-
diff --git a/modules/video_output/msw/glwin32.c b/modules/video_output/msw/glwin32.c
deleted file mode 100644 (file)
index 0e04446..0000000
+++ /dev/null
@@ -1,317 +0,0 @@
-/*****************************************************************************
- * glwin32.c: Windows OpenGL provider
- *****************************************************************************
- * Copyright (C) 2001-2009 VLC authors and VideoLAN
- * $Id$
- *
- * Authors: Gildas Bazin <gbazin@videolan.org>
- *
- * 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 Lesser General Public License for more details.
- *
- * 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.
- *****************************************************************************/
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#include <vlc_common.h>
-#include <vlc_plugin.h>
-#include <vlc_vout_display.h>
-
-#include <windows.h>
-
-#define GLEW_STATIC
-#include "../opengl.h"
-#include <GL/wglew.h>
-
-#include "common.h"
-
-/*****************************************************************************
- * Module descriptor
- *****************************************************************************/
-static int  Open (vlc_object_t *);
-static void Close(vlc_object_t *);
-
-#define HW_GPU_AFFINITY_TEXT N_("GPU affinity")
-
-vlc_module_begin()
-    set_category(CAT_VIDEO)
-    set_subcategory(SUBCAT_VIDEO_VOUT)
-    set_shortname("OpenGL")
-    set_description(N_("OpenGL video output"))
-
-    add_integer("gpu-affinity", -1, HW_GPU_AFFINITY_TEXT, HW_GPU_AFFINITY_TEXT, true)
-
-    set_capability("vout display", 220)
-    add_shortcut("glwin32", "opengl")
-    set_callbacks(Open, Close)
-vlc_module_end()
-
-/*****************************************************************************
- * Local prototypes.
- *****************************************************************************/
-static picture_pool_t *Pool  (vout_display_t *, unsigned);
-static void           Prepare(vout_display_t *, picture_t *, subpicture_t *);
-static void           Display(vout_display_t *, picture_t *, subpicture_t *);
-static void           Manage (vout_display_t *);
-
-static void           Swap   (vlc_gl_t *);
-static void          *OurGetProcAddress(vlc_gl_t *, const char *);
-
-/* Create an GPU Affinity DC */
-static void CreateGPUAffinityDC(vout_display_t *vd, UINT nVidiaAffinity) {
-    PIXELFORMATDESCRIPTOR pfd;
-    memset(&pfd, 0, sizeof(pfd));
-    pfd.nSize = sizeof(pfd);
-    pfd.nVersion = 1;
-    pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
-    pfd.iPixelType = PFD_TYPE_RGBA;
-    pfd.cColorBits = 24;
-    pfd.cDepthBits = 16;
-    pfd.iLayerType = PFD_MAIN_PLANE;
-
-    /* create a temporary GL context */
-    HDC winDC = GetDC(vd->sys->hvideownd);
-    SetPixelFormat(winDC, ChoosePixelFormat(winDC, &pfd), &pfd);
-    HGLRC hGLRC = wglCreateContext(winDC);
-    wglMakeCurrent(winDC, hGLRC);
-
-    /* Initialize the neccessary function pointers */
-    PFNWGLENUMGPUSNVPROC fncEnumGpusNV = (PFNWGLENUMGPUSNVPROC)wglGetProcAddress("wglEnumGpusNV");
-    PFNWGLCREATEAFFINITYDCNVPROC fncCreateAffinityDCNV = (PFNWGLCREATEAFFINITYDCNVPROC)wglGetProcAddress("wglCreateAffinityDCNV");
-
-    /* delete the temporary GL context */
-    wglDeleteContext(hGLRC);
-
-    /* see if we have the extensions */
-    if (!fncEnumGpusNV || !fncCreateAffinityDCNV) return;
-
-    /* find the graphics card */
-    HGPUNV GpuMask[2];
-    GpuMask[0] = NULL;
-    GpuMask[1] = NULL;
-    HGPUNV hGPU;
-    if (!fncEnumGpusNV(nVidiaAffinity, &hGPU)) return;
-
-    /* make the affinity DC */
-    GpuMask[0] = hGPU;
-    vd->sys->affinityHDC = fncCreateAffinityDCNV(GpuMask);
-    if (vd->sys->affinityHDC == NULL) return;
-    SetPixelFormat(vd->sys->affinityHDC,
-        ChoosePixelFormat(vd->sys->affinityHDC, &pfd), &pfd);
-
-    msg_Dbg( vd, "GPU affinity set to adapter: %d",
-                     nVidiaAffinity );
-}
-
-/* Destroy an GPU Affinity DC */
-static void DestroyGPUAffinityDC(vout_display_t *vd) {
-    if (vd->sys->affinityHDC == NULL) return;
-
-    PIXELFORMATDESCRIPTOR pfd;
-    memset(&pfd, 0, sizeof(pfd));
-    pfd.nSize = sizeof(pfd);
-    pfd.nVersion = 1;
-    pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
-    pfd.iPixelType = PFD_TYPE_RGBA;
-    pfd.cColorBits = 24;
-    pfd.cDepthBits = 16;
-    pfd.iLayerType = PFD_MAIN_PLANE;
-
-    /* create a temporary GL context */
-    HDC winDC = GetDC(vd->sys->hvideownd);
-    SetPixelFormat(winDC, ChoosePixelFormat(winDC, &pfd), &pfd);
-    HGLRC hGLRC = wglCreateContext(winDC);
-    wglMakeCurrent(winDC, hGLRC);
-
-    /* Initialize the neccessary function pointers */
-    PFNWGLDELETEDCNVPROC fncDeleteDCNV = (PFNWGLDELETEDCNVPROC)wglGetProcAddress("wglDeleteDCNV");
-
-    /* delete the temporary GL context */
-    wglDeleteContext(hGLRC);
-
-    /* see if we have the extensions */
-    if (!fncDeleteDCNV) return;
-
-    /* delete the affinity DC */
-    fncDeleteDCNV(vd->sys->affinityHDC);
-}
-
-/**
- * It creates an OpenGL vout display.
- */
-static int Open(vlc_object_t *object)
-{
-    vout_display_t *vd = (vout_display_t *)object;
-    vout_display_sys_t *sys;
-
-    /* Allocate structure */
-    vd->sys = sys = calloc(1, sizeof(*sys));
-    if (!sys)
-        return VLC_ENOMEM;
-
-    /* */
-    if (CommonInit(vd))
-        goto error;
-
-    EventThreadUpdateTitle(sys->event, VOUT_TITLE " (OpenGL output)");
-
-    /* process selected GPU affinity */
-    int nVidiaAffinity = var_InheritInteger(vd, "gpu-affinity");
-    if (nVidiaAffinity >= 0) CreateGPUAffinityDC(vd, nVidiaAffinity);
-
-    /* */
-    sys->hGLDC = GetDC(sys->hvideownd);
-
-    /* Set the pixel format for the DC */
-    PIXELFORMATDESCRIPTOR pfd;
-    memset(&pfd, 0, sizeof(pfd));
-    pfd.nSize = sizeof(pfd);
-    pfd.nVersion = 1;
-    pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
-    pfd.iPixelType = PFD_TYPE_RGBA;
-    pfd.cColorBits = 24;
-    pfd.cDepthBits = 16;
-    pfd.iLayerType = PFD_MAIN_PLANE;
-    SetPixelFormat(sys->hGLDC,
-                   ChoosePixelFormat(sys->hGLDC, &pfd), &pfd);
-
-    /*
-     * Create and enable the render context
-     * For GPU affinity, attach the window DC
-     * to the GPU affinity DC
-     */
-    sys->hGLRC = wglCreateContext((sys->affinityHDC != NULL) ? sys->affinityHDC : sys->hGLDC);
-    wglMakeCurrent(sys->hGLDC, sys->hGLRC);
-
-    const char *extensions = (const char*)glGetString(GL_EXTENSIONS);
-#ifdef WGL_EXT_swap_control
-    if (HasExtension(extensions, "WGL_EXT_swap_control")) {
-        PFNWGLSWAPINTERVALEXTPROC SwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC)wglGetProcAddress("wglSwapIntervalEXT");
-        if (SwapIntervalEXT)
-            SwapIntervalEXT(1);
-    }
-#endif
-
-    /* */
-    sys->gl.swap = Swap;
-    sys->gl.getProcAddress = OurGetProcAddress;
-    sys->gl.sys = vd;
-
-    video_format_t fmt = vd->fmt;
-    const vlc_fourcc_t *subpicture_chromas;
-    sys->vgl = vout_display_opengl_New(&fmt, &subpicture_chromas, &sys->gl);
-    if (!sys->vgl)
-        goto error;
-
-    vout_display_info_t info = vd->info;
-    info.has_double_click = true;
-    info.has_hide_mouse = false;
-    info.has_event_thread = true;
-    info.subpicture_chromas = subpicture_chromas;
-
-   /* Setup vout_display now that everything is fine */
-    vd->fmt  = fmt;
-    vd->info = info;
-
-    vd->pool    = Pool;
-    vd->prepare = Prepare;
-    vd->display = Display;
-    vd->control = CommonControl;
-    vd->manage  = Manage;
-
-    return VLC_SUCCESS;
-
-error:
-    Close(object);
-    return VLC_EGENERIC;
-}
-
-/**
- * It destroys an OpenGL vout display.
- */
-static void Close(vlc_object_t *object)
-{
-    vout_display_t *vd = (vout_display_t *)object;
-    vout_display_sys_t *sys = vd->sys;
-
-    if (sys->vgl)
-        vout_display_opengl_Delete(sys->vgl);
-
-    if (sys->hGLDC && sys->hGLRC)
-        wglMakeCurrent(NULL, NULL);
-    if (sys->hGLRC)
-        wglDeleteContext(sys->hGLRC);
-    if (sys->hGLDC)
-        ReleaseDC(sys->hvideownd, sys->hGLDC);
-    DestroyGPUAffinityDC(vd);
-
-    CommonClean(vd);
-
-    free(sys);
-}
-
-/* */
-static picture_pool_t *Pool(vout_display_t *vd, unsigned count)
-{
-    vout_display_sys_t *sys = vd->sys;
-
-    if (!sys->pool)
-        sys->pool = vout_display_opengl_GetPool(sys->vgl, count);
-    return sys->pool;
-}
-
-static void Prepare(vout_display_t *vd, picture_t *picture, subpicture_t *subpicture)
-{
-    vout_display_sys_t *sys = vd->sys;
-
-    vout_display_opengl_Prepare(sys->vgl, picture, subpicture);
-}
-
-static void Display(vout_display_t *vd, picture_t *picture, subpicture_t *subpicture)
-{
-    vout_display_sys_t *sys = vd->sys;
-
-    vout_display_opengl_Display(sys->vgl, &vd->source);
-
-    picture_Release(picture);
-    if (subpicture)
-        subpicture_Delete(subpicture);
-
-    CommonDisplay(vd);
-}
-
-static void Manage (vout_display_t *vd)
-{
-    vout_display_sys_t *sys = vd->sys;
-
-    CommonManage(vd);
-
-    const int width  = sys->rect_dest.right  - sys->rect_dest.left;
-    const int height = sys->rect_dest.bottom - sys->rect_dest.top;
-    glViewport(0, 0, width, height);
-}
-
-static void Swap(vlc_gl_t *gl)
-{
-    vout_display_t *vd = gl->sys;
-
-    SwapBuffers(vd->sys->hGLDC);
-}
-
-static void *OurGetProcAddress(vlc_gl_t *gl, const char *name)
-{
-    VLC_UNUSED(gl);
-    return wglGetProcAddress(name);
-}
-
diff --git a/modules/video_output/msw/win32touch.c b/modules/video_output/msw/win32touch.c
deleted file mode 100644 (file)
index be9fd71..0000000
+++ /dev/null
@@ -1,247 +0,0 @@
-/*****************************************************************************
- * win32touch.c: touch gestures recognition
- *****************************************************************************
- * Copyright © 2013-2014 VideoLAN
- *
- * Authors: Ludovic Fauvet <etix@videolan.org>
- *          Jean-Baptiste Kempf <jb@videolan.org>
- *
- * 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 Lesser General Public License for more details.
- *
- * 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.
- *****************************************************************************/
-
-#include "win32touch.h"
-
-#include <vlc_keys.h>
-
-#include <assert.h>
-
-LRESULT DecodeGesture( vlc_object_t *p_this, win32_gesture_sys_t *p_gesture,
-                       HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam )
-{
-    if( !p_gesture )
-        return DefWindowProc( hWnd, message, wParam, lParam );
-
-    GESTUREINFO gi;
-    ZeroMemory( &gi, sizeof( GESTUREINFO ) );
-    gi.cbSize = sizeof( GESTUREINFO );
-
-    BOOL bResult  = p_gesture->OurGetGestureInfo((HGESTUREINFO)lParam, &gi);
-    BOOL bHandled = FALSE; /* Needed to release the handle */
-
-    if( bResult )
-    {
-        switch ( gi.dwID )
-        {
-            case GID_BEGIN:
-                /* Set the win32_gesture_sys_t values */
-                p_gesture->i_beginx      = gi.ptsLocation.x;
-                p_gesture->i_beginy      = gi.ptsLocation.y;
-                p_gesture->i_lasty       = p_gesture->i_beginy;
-                p_gesture->b_2fingers    = false;
-                break;
-            case GID_END:
-                if( p_gesture->i_type != 0 &&
-                    p_gesture->i_action == GESTURE_ACTION_JUMP )
-                {
-                    int action_id;
-                    if( p_gesture->i_beginx > gi.ptsLocation.x )
-                    {
-                        if( p_gesture->b_2fingers )
-                            action_id = ACTIONID_JUMP_BACKWARD_MEDIUM;
-                        else
-                            action_id = ACTIONID_JUMP_BACKWARD_SHORT;
-                    }
-                    else
-                    {
-                        if( p_gesture->b_2fingers )
-                            action_id = ACTIONID_JUMP_FORWARD_MEDIUM;
-                        else
-                            action_id = ACTIONID_JUMP_FORWARD_SHORT;
-                    }
-                    var_SetInteger( p_this->p_libvlc, "key-action", action_id );
-                }
-                /* Reset the values */
-                p_gesture->i_action = GESTURE_ACTION_UNDEFINED;
-                p_gesture->i_type = p_gesture->i_beginx = p_gesture->i_beginy = -1;
-                p_gesture->b_2fingers = false;
-                break;
-            case GID_PAN:
-                p_gesture->i_type = GID_PAN;
-                bHandled = TRUE;
-
-                if( (DWORD)gi.ullArguments > 0 )
-                    p_gesture->b_2fingers = true;
-
-                if( p_gesture->i_action == GESTURE_ACTION_UNDEFINED )
-                {
-                    if( abs( p_gesture->i_beginx - gi.ptsLocation.x ) +
-                        abs( p_gesture->i_beginy - gi.ptsLocation.y ) > 50 )
-                    {
-                        if( abs( p_gesture->i_beginx - gi.ptsLocation.x ) >
-                            abs( p_gesture->i_beginy - gi.ptsLocation.y ) )
-                           p_gesture->i_action =  GESTURE_ACTION_JUMP;
-                        else if ( p_gesture->b_2fingers )
-                           p_gesture->i_action = GESTURE_ACTION_BRIGHTNESS;
-                        else
-                           p_gesture->i_action =  GESTURE_ACTION_VOLUME;
-                    }
-                }
-
-                if( p_gesture->i_action == GESTURE_ACTION_VOLUME )
-                {
-                    int offset = p_gesture->i_lasty - gi.ptsLocation.y;
-
-                    if( offset > 100)
-                        var_SetInteger( p_this->p_libvlc, "key-action", ACTIONID_VOL_UP );
-                    else if( offset < -100)
-                        var_SetInteger( p_this->p_libvlc, "key-action", ACTIONID_VOL_DOWN );
-                    else
-                        break;
-
-                    p_gesture->i_lasty = gi.ptsLocation.y;
-                }
-                else if ( p_gesture->i_action == GESTURE_ACTION_BRIGHTNESS )
-                {
-                    /* Currently unimplemented
-                    if( p_gesture->i_lasty == -1 )
-                        p_gesture->i_lasty = p_gesture->i_beginy;
-
-                    if( p_gesture->i_lasty - p_gesture->i_beginy > 80 )
-                    {
-                        var_SetInteger( p_this->p_libvlc, "key-action", ACTIONID_BRIGHTNESS_DOWN );
-                        p_gesture->i_lasty = gi.ptsLocation.y;
-                    }
-                    else if ( p_gesture->i_lasty - p_gesture->i_beginy < 80 )
-                    {
-                        var_SetInteger( p_this->p_libvlc, "key-action", ACTIONID_BRIGHTNESS_UP );
-                        p_gesture->i_lasty = gi.ptsLocation.y;
-                    } */
-                }
-                break;
-            case GID_TWOFINGERTAP:
-                p_gesture->i_type = GID_TWOFINGERTAP;
-                var_SetInteger( p_this->p_libvlc, "key-action", ACTIONID_PLAY_PAUSE );
-                bHandled = TRUE;
-                break;
-            case GID_ZOOM:
-                p_gesture->i_type = GID_ZOOM;
-                switch( gi.dwFlags )
-                {
-                    case GF_BEGIN:
-                        p_gesture->i_ullArguments = gi.ullArguments;
-                        break;
-                    case GF_END:
-                        {
-                            double k = (double)(gi.ullArguments) /
-                                       (double)(p_gesture->i_ullArguments);
-                            if( k > 1 )
-                                var_SetInteger( p_this->p_libvlc, "key-action",
-                                        ACTIONID_TOGGLE_FULLSCREEN );
-                            else
-                                var_SetInteger( p_this->p_libvlc, "key-action",
-                                        ACTIONID_LEAVE_FULLSCREEN );
-                        }
-                        break;
-                    default:
-                        msg_Err( p_this, "Unmanaged dwFlag: %lx", gi.dwFlags );
-                }
-                bHandled = TRUE;
-                break;
-            case WM_VSCROLL:
-                bHandled = TRUE;
-                break;
-            default:
-                break;
-        }
-    }
-    else
-    {
-        DWORD dwErr = GetLastError();
-        if( dwErr > 0 )
-            msg_Err( p_this, "Could not retrieve a valid GESTUREINFO structure" );
-    }
-
-
-    if( bHandled )
-    {
-        /* Close the Handle, if we handled the gesture, a contrario
-         * from the doc example */
-        p_gesture->OurCloseGestureInfoHandle((HGESTUREINFO)lParam);
-        return 0;
-    }
-    else
-        return DefWindowProc( hWnd, message, wParam, lParam );
-}
-
-BOOL InitGestures( HWND hwnd, win32_gesture_sys_t **pp_gesture )
-{
-    BOOL result = FALSE;
-    GESTURECONFIG config = { 0, 0, 0 };
-    config.dwID    = GID_PAN;
-    config.dwWant  = GC_PAN |
-                     GC_PAN_WITH_SINGLE_FINGER_HORIZONTALLY |
-                     GC_PAN_WITH_SINGLE_FINGER_VERTICALLY;
-    config.dwBlock = GC_PAN_WITH_INERTIA;
-
-    win32_gesture_sys_t *p_gesture = malloc( sizeof(win32_gesture_sys_t) );
-    if( !p_gesture )
-    {
-        *pp_gesture = NULL;
-        return FALSE;
-    }
-
-    HINSTANCE h_user32_dll = LoadLibrary(TEXT("user32.dll"));
-    if( !h_user32_dll )
-    {
-        *pp_gesture = NULL;
-        free( p_gesture );
-        return FALSE;
-    }
-
-    BOOL (WINAPI *OurSetGestureConfig) (HWND, DWORD, UINT, PGESTURECONFIG, UINT);
-    OurSetGestureConfig = (void *)GetProcAddress(h_user32_dll, "SetGestureConfig");
-
-    p_gesture->OurCloseGestureInfoHandle =
-        (void *)GetProcAddress(h_user32_dll, "CloseGestureInfoHandle" );
-    p_gesture->OurGetGestureInfo =
-        (void *)GetProcAddress(h_user32_dll, "GetGestureInfo");
-    if( OurSetGestureConfig )
-    {
-        result = OurSetGestureConfig(
-                hwnd,
-                0,
-                1,
-                &config,
-                sizeof( GESTURECONFIG )
-                );
-    }
-
-    p_gesture->i_type     = 0;
-    p_gesture->b_2fingers = false;
-    p_gesture->i_action   = GESTURE_ACTION_UNDEFINED;
-    p_gesture->i_beginx   = p_gesture->i_beginy = -1;
-    p_gesture->i_lasty    = -1;
-    p_gesture->huser_dll  = h_user32_dll;
-
-    *pp_gesture = p_gesture;
-    return result;
-}
-
-void CloseGestures( win32_gesture_sys_t *p_gesture )
-{
-    if (p_gesture && p_gesture->huser_dll )
-        FreeLibrary( p_gesture->huser_dll );
-    free( p_gesture );
-}
diff --git a/modules/video_output/msw/win32touch.h b/modules/video_output/msw/win32touch.h
deleted file mode 100644 (file)
index 8e86eae..0000000
+++ /dev/null
@@ -1,83 +0,0 @@
-/*****************************************************************************
- * win32touch.c: touch gestures recognition
- *****************************************************************************
- * Copyright © 2013-2014 VideoLAN
- *
- * Authors: Ludovic Fauvet <etix@videolan.org>
- *          Jean-Baptiste Kempf <jb@videolan.org>
- *
- * 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 Lesser General Public License for more details.
- *
- * 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.
- *****************************************************************************/
-
-#ifndef VLC_GESTURE_H_
-#define VLC_GESTURE_H_
-
-# if !defined(_WIN32_WINNT) || _WIN32_WINNT < 0x601
-#  undef _WIN32_WINNT
-#  define _WIN32_WINNT 0x0601
-# endif
-# include <windows.h>
-# include <winuser.h>
-
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#include <vlc_common.h>
-
-#ifndef WM_GESTURE
-# define WM_GESTURE 0x0119
-#endif
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-enum {
-    GESTURE_ACTION_UNDEFINED = 0,
-    GESTURE_ACTION_VOLUME,
-    GESTURE_ACTION_JUMP,
-    GESTURE_ACTION_BRIGHTNESS
-};
-
-typedef struct {
-    DWORD       i_type;                 /* Gesture ID */
-    int         i_action;               /* GESTURE_ACTION */
-
-    int         i_beginx;               /* Start X position */
-    int         i_beginy;               /* Start Y position */
-    int         i_lasty;                /* Last known Y position for PAN */
-
-    ULONGLONG   i_ullArguments;         /* Base values to compare between 2 zoom gestures */
-    bool        b_2fingers;             /* Did we detect 2 fingers? */
-
-    HINSTANCE   huser_dll;              /* user32.dll */
-    BOOL (WINAPI * OurCloseGestureInfoHandle)(HGESTUREINFO hGestureInfo);
-    BOOL (WINAPI * OurGetGestureInfo)(HGESTUREINFO hGestureInfo, PGESTUREINFO pGestureInfo);
-} win32_gesture_sys_t;
-
-
-BOOL InitGestures( HWND hwnd, win32_gesture_sys_t **p_gesture );
-
-LRESULT DecodeGesture( vlc_object_t *p_intf, win32_gesture_sys_t *p_gesture,
-        HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam );
-
-void CloseGestures( win32_gesture_sys_t *p_gesture );
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/modules/video_output/msw/wingdi.c b/modules/video_output/msw/wingdi.c
deleted file mode 100644 (file)
index ea4b237..0000000
+++ /dev/null
@@ -1,315 +0,0 @@
-/*****************************************************************************
- * wingdi.c : Win32 / WinCE GDI video output plugin for vlc
- *****************************************************************************
- * Copyright (C) 2002-2009 VLC authors and VideoLAN
- * $Id$
- *
- * Authors: Gildas Bazin <gbazin@videolan.org>
- *          Samuel Hocevar <sam@zoy.org>
- *
- * 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 Lesser General Public License for more details.
- *
- * 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.
- *****************************************************************************/
-
-/*****************************************************************************
- * Preamble
- *****************************************************************************/
-
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-#include <assert.h>
-
-#include <vlc_common.h>
-#include <vlc_plugin.h>
-#include <vlc_vout_display.h>
-
-#include <windows.h>
-
-#include "common.h"
-
-/*****************************************************************************
- * Module descriptor
- *****************************************************************************/
-static int  Open (vlc_object_t *);
-static void Close(vlc_object_t *);
-
-vlc_module_begin ()
-    set_category(CAT_VIDEO)
-    set_subcategory(SUBCAT_VIDEO_VOUT)
-    set_shortname("GDI")
-    set_description(N_("Windows GDI video output"))
-    set_capability("vout display", 110)
-    set_callbacks(Open, Close)
-vlc_module_end ()
-
-
-/*****************************************************************************
- * Local prototypes
- *****************************************************************************/
-static picture_pool_t *Pool  (vout_display_t *, unsigned);
-static void           Display(vout_display_t *, picture_t *, subpicture_t *subpicture);
-static int            Control(vout_display_t *, int, va_list);
-static void           Manage (vout_display_t *);
-
-static int            Init(vout_display_t *, video_format_t *, int, int);
-static void           Clean(vout_display_t *);
-
-/* */
-static int Open(vlc_object_t *object)
-{
-    vout_display_t *vd = (vout_display_t *)object;
-    vout_display_sys_t *sys;
-
-    vd->sys = sys = calloc(1, sizeof(*sys));
-    if (!sys)
-        return VLC_ENOMEM;
-
-    if (CommonInit(vd))
-        goto error;
-
-    /* */
-    video_format_t fmt = vd->fmt;
-    if (Init(vd, &fmt, fmt.i_width, fmt.i_height))
-        goto error;
-
-    vout_display_info_t info = vd->info;
-    info.is_slow              = false;
-    info.has_double_click     = true;
-    info.has_hide_mouse       = false;
-    info.has_pictures_invalid = true;
-
-    /* */
-    vd->fmt  = fmt;
-    vd->info = info;
-
-    vd->pool    = Pool;
-    vd->prepare = NULL;
-    vd->display = Display;
-    vd->manage  = Manage;
-    vd->control = Control;
-    return VLC_SUCCESS;
-
-error:
-    Close(VLC_OBJECT(vd));
-    return VLC_EGENERIC;
-}
-
-/* */
-static void Close(vlc_object_t *object)
-{
-    vout_display_t *vd = (vout_display_t *)object;
-
-    Clean(vd);
-
-    CommonClean(vd);
-
-    free(vd->sys);
-}
-
-/* */
-static picture_pool_t *Pool(vout_display_t *vd, unsigned count)
-{
-    VLC_UNUSED(count);
-    return vd->sys->pool;
-}
-
-static void Display(vout_display_t *vd, picture_t *picture, subpicture_t *subpicture)
-{
-    vout_display_sys_t *sys = vd->sys;
-
-#define rect_src vd->sys->rect_src
-#define rect_src_clipped vd->sys->rect_src_clipped
-#define rect_dest vd->sys->rect_dest
-#define rect_dest_clipped vd->sys->rect_dest_clipped
-    RECT rect_dst = rect_dest_clipped;
-    HDC hdc = GetDC(sys->hvideownd);
-
-    OffsetRect(&rect_dst, -rect_dest.left, -rect_dest.top);
-    SelectObject(sys->off_dc, sys->off_bitmap);
-
-    if (rect_dest_clipped.right - rect_dest_clipped.left !=
-        rect_src_clipped.right - rect_src_clipped.left ||
-        rect_dest_clipped.bottom - rect_dest_clipped.top !=
-        rect_src_clipped.bottom - rect_src_clipped.top) {
-        StretchBlt(hdc, rect_dst.left, rect_dst.top,
-                   rect_dst.right, rect_dst.bottom,
-                   sys->off_dc,
-                   rect_src_clipped.left,  rect_src_clipped.top,
-                   rect_src_clipped.right, rect_src_clipped.bottom,
-                   SRCCOPY);
-    } else {
-        BitBlt(hdc, rect_dst.left, rect_dst.top,
-               rect_dst.right, rect_dst.bottom,
-               sys->off_dc,
-               rect_src_clipped.left, rect_src_clipped.top,
-               SRCCOPY);
-    }
-
-    ReleaseDC(sys->hvideownd, hdc);
-#undef rect_src
-#undef rect_src_clipped
-#undef rect_dest
-#undef rect_dest_clipped
-    /* TODO */
-    picture_Release(picture);
-    VLC_UNUSED(subpicture);
-
-    CommonDisplay(vd);
-}
-
-static int Control(vout_display_t *vd, int query, va_list args)
-{
-    switch (query) {
-    case VOUT_DISPLAY_RESET_PICTURES:
-        vlc_assert_unreachable();
-        return VLC_EGENERIC;
-    default:
-        return CommonControl(vd, query, args);
-    }
-
-}
-
-static void Manage(vout_display_t *vd)
-{
-    CommonManage(vd);
-}
-
-static int Init(vout_display_t *vd,
-                video_format_t *fmt, int width, int height)
-{
-    vout_display_sys_t *sys = vd->sys;
-
-    /* */
-    RECT *display = &sys->rect_display;
-    display->left   = 0;
-    display->top    = 0;
-    display->right  = GetSystemMetrics(SM_CXSCREEN);;
-    display->bottom = GetSystemMetrics(SM_CYSCREEN);;
-
-    /* Initialize an offscreen bitmap for direct buffer operations. */
-
-    /* */
-    HDC window_dc = GetDC(sys->hvideownd);
-
-    /* */
-    sys->i_depth = GetDeviceCaps(window_dc, PLANES) *
-                   GetDeviceCaps(window_dc, BITSPIXEL);
-
-    /* */
-    msg_Dbg(vd, "GDI depth is %i", sys->i_depth);
-    switch (sys->i_depth) {
-    case 8:
-        fmt->i_chroma = VLC_CODEC_RGB8;
-        break;
-    case 15:
-        fmt->i_chroma = VLC_CODEC_RGB15;
-        fmt->i_rmask  = 0x7c00;
-        fmt->i_gmask  = 0x03e0;
-        fmt->i_bmask  = 0x001f;
-        break;
-    case 16:
-        fmt->i_chroma = VLC_CODEC_RGB16;
-        fmt->i_rmask  = 0xf800;
-        fmt->i_gmask  = 0x07e0;
-        fmt->i_bmask  = 0x001f;
-        break;
-    case 24:
-        fmt->i_chroma = VLC_CODEC_RGB24;
-        fmt->i_rmask  = 0x00ff0000;
-        fmt->i_gmask  = 0x0000ff00;
-        fmt->i_bmask  = 0x000000ff;
-        break;
-    case 32:
-        fmt->i_chroma = VLC_CODEC_RGB32;
-        fmt->i_rmask  = 0x00ff0000;
-        fmt->i_gmask  = 0x0000ff00;
-        fmt->i_bmask  = 0x000000ff;
-        break;
-    default:
-        msg_Err(vd, "screen depth %i not supported", sys->i_depth);
-        return VLC_EGENERIC;
-    }
-    fmt->i_width  = width;
-    fmt->i_height = height;
-
-    void *p_pic_buffer;
-    int     i_pic_pitch;
-    /* Initialize offscreen bitmap */
-    BITMAPINFO *bi = &sys->bitmapinfo;
-    memset(bi, 0, sizeof(BITMAPINFO) + 3 * sizeof(RGBQUAD));
-    if (sys->i_depth > 8) {
-        ((DWORD*)bi->bmiColors)[0] = fmt->i_rmask;
-        ((DWORD*)bi->bmiColors)[1] = fmt->i_gmask;
-        ((DWORD*)bi->bmiColors)[2] = fmt->i_bmask;;
-    }
-
-    BITMAPINFOHEADER *bih = &sys->bitmapinfo.bmiHeader;
-    bih->biSize = sizeof(BITMAPINFOHEADER);
-    bih->biSizeImage     = 0;
-    bih->biPlanes        = 1;
-    bih->biCompression   = (sys->i_depth == 15 ||
-                            sys->i_depth == 16) ? BI_BITFIELDS : BI_RGB;
-    bih->biBitCount      = sys->i_depth;
-    bih->biWidth         = fmt->i_width;
-    bih->biHeight        = -fmt->i_height;
-    bih->biClrImportant  = 0;
-    bih->biClrUsed       = 0;
-    bih->biXPelsPerMeter = 0;
-    bih->biYPelsPerMeter = 0;
-
-    i_pic_pitch = bih->biBitCount * bih->biWidth / 8;
-    sys->off_bitmap = CreateDIBSection(window_dc,
-                                       (BITMAPINFO *)bih,
-                                       DIB_RGB_COLORS,
-                                       &p_pic_buffer, NULL, 0);
-
-    sys->off_dc = CreateCompatibleDC(window_dc);
-
-    SelectObject(sys->off_dc, sys->off_bitmap);
-    ReleaseDC(sys->hvideownd, window_dc);
-
-    EventThreadUpdateTitle(sys->event, VOUT_TITLE " (WinGDI output)");
-
-    /* */
-    picture_resource_t rsc;
-    memset(&rsc, 0, sizeof(rsc));
-    rsc.p[0].p_pixels = p_pic_buffer;
-    rsc.p[0].i_lines  = fmt->i_height;
-    rsc.p[0].i_pitch  = i_pic_pitch;;
-
-    picture_t *picture = picture_NewFromResource(fmt, &rsc);
-    if (picture != NULL)
-        sys->pool = picture_pool_New(1, &picture);
-    else
-        sys->pool = NULL;
-
-    UpdateRects(vd, NULL, NULL, true);
-
-    return VLC_SUCCESS;
-}
-
-static void Clean(vout_display_t *vd)
-{
-    vout_display_sys_t *sys = vd->sys;
-
-    if (sys->pool)
-        picture_pool_Release(sys->pool);
-    sys->pool = NULL;
-
-    if (sys->off_dc)
-        DeleteDC(sys->off_dc);
-    if (sys->off_bitmap)
-        DeleteObject(sys->off_bitmap);
-}
diff --git a/modules/video_output/win32/builtin_shaders.h b/modules/video_output/win32/builtin_shaders.h
new file mode 100644 (file)
index 0000000..3a87ce2
--- /dev/null
@@ -0,0 +1,150 @@
+/*****************************************************************************
+ * builtin_shaders.h: Builtin HLSL shader functions.
+ *****************************************************************************
+ * Copyright (C) 2014 the VideoLAN team
+ *
+ * Authors: Sasha Koruga <skoruga@gmail.com>,
+ *          Felix Abecassis <felix.abecassis@gmail.com>
+ * 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 Lesser General Public License for more details.
+ *
+ * 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.
+ *****************************************************************************/
+
+static const char shader_disabled_source[] =
+    "sampler2D screen;\n"
+    "float4 main(float2 screenCoords : TEXCOORD0) : COLOR\n"
+    "{\n"
+    "    return saturate(tex2D(screen, screenCoords.xy));\n"
+    "}\n";
+
+static const char shader_invert_source[] =
+    "sampler2D screen;\n"
+    "float4 main(float2 screenCoords : TEXCOORD0) : COLOR\n"
+    "{\n"
+    "    float4 color = tex2D(screen, screenCoords.xy);\n"
+    "    color.r = 1.0 - color.r;\n"
+    "    color.g = 1.0 - color.g;\n"
+    "    color.b = 1.0 - color.b;\n"
+    "    return color;\n"
+    "}\n";
+
+static const char shader_grayscale_source[] =
+    "sampler2D screen;\n"
+    "float4 main(float2 screenCoords : TEXCOORD0) : COLOR0\n"
+    "{\n"
+    "    float4 color = tex2D(screen, screenCoords.xy);\n"
+    "    float gray = 0.2989 * color.r + 0.5870 * color.g + 0.1140 * color.b;\n"
+    "    color.r = color.g = color.b = gray;\n"
+    "    return color;\n"
+    "}\n";
+
+static const char shader_convert601to709_source[] =
+    "sampler2D screen;\n"
+    "float4 rgb_to_yuv601(float4 RGB)\n"
+    "{\n"
+    "    float Kr = 0.299;\n"
+    "    float Kg = 0.587;\n"
+    "    float Kb = 0.114;\n"
+    "    float Y = Kr*RGB.r + Kg*RGB.g + Kb*RGB.b;\n"
+    "    float V = (RGB.r-Y)/(1-Kr);\n"
+    "    float U = (RGB.b-Y)/(1-Kb);\n"
+    "    return float4(Y,U,V,1);\n"
+    "}\n"
+
+    "float4 yuv709_to_rgb(float4 YUV)\n"
+    "{\n"
+    "    float Kr = 0.2125;\n"
+    "    float Kg = 0.7154;\n"
+    "    float Kb = 0.0721;\n"
+    "    float Y = YUV.x;\n"
+    "    float U = YUV.y;\n"
+    "    float V = YUV.z;\n"
+    "    float R = Y + V*(1-Kr);\n"
+    "    float G = Y - U*(1-Kb)*Kb/Kg - V*(1-Kr)*Kr/Kg;\n"
+    "    float B = Y + U*(1-Kb);\n"
+    "    return float4(R,G,B,1);\n"
+    "}\n"
+
+    "float4 main(float2 screenCoords : TEXCOORD0) : COLOR0\n"
+    "{\n"
+    "    float4 color = tex2D(screen, screenCoords.xy);\n"
+    "    return yuv709_to_rgb(rgb_to_yuv601(color));\n"
+    "}\n";
+
+static const char shader_gammacorrection18_source[] =
+    "sampler2D screen;\n"
+    "float4 main(float2 screenCoords : TEXCOORD0) : COLOR0\n"
+    "{\n"
+    "    float4 color = tex2D( screen, screenCoords.xy);\n"
+    "    color = pow(color,1.0/1.8);\n"
+    "    return color;\n"
+    "}\n";
+
+static const char shader_gammacorrection22_source[] =
+    "sampler2D screen;\n"
+    "float4 main(float2 screenCoords : TEXCOORD0) : COLOR0\n"
+    "{\n"
+    "    float4 color = tex2D( screen, screenCoords.xy);\n"
+    "    color = pow(color,1.0/2.2);\n"
+    "    return color;\n"
+    "}\n";
+
+static const char shader_gammacorrectionbt709_source[] =
+    "sampler2D screen;\n"
+    "float4 main(float2 screenCoords : TEXCOORD0) : COLOR0\n"
+    "{\n"
+    "    float4 color = tex2D(screen, screenCoords.xy);\n"
+    "    if(color.r > 0.018)\n"
+    "        color.r = 1.099 * pow(color.r,0.45) - 0.099;\n"
+    "    else\n"
+    "        color.r = 4.5138 * color.r;\n"
+    "    if(color.g > 0.018)\n"
+    "        color.g = 1.099 * pow(color.g,0.45) - 0.099;\n"
+    "    else\n"
+    "        color.g = 4.5138 * color.g;\n"
+    "    if(color.b > 0.018)\n"
+    "        color.b = 1.099 * pow(color.b,0.45) - 0.099;\n"
+    "    else\n"
+    "        color.b = 4.5138 * color.b;\n"
+    "    return color;\n"
+    "}\n";
+
+static const char shader_widencolorspace_source[] =
+    "sampler2D screen;\n"
+    "float4 main(float2 screenCoords : TEXCOORD0) : COLOR0\n"
+    "{\n"
+    "    float4 color = tex2D(screen, screenCoords.xy);\n"
+    "    color.r = max(color.r - 0.0627450980392157,0) * 1.164383561643836;\n"
+    "    color.g = max(color.g - 0.0627450980392157,0) * 1.164383561643836;\n"
+    "    color.b = max(color.b - 0.0627450980392157,0) * 1.164383561643836;\n"
+    "    return saturate(color);\n"
+    "}\n";
+
+typedef struct
+{
+    const char *name;
+    const char *code;
+} builtin_shader_t;
+
+static const builtin_shader_t builtin_shaders[] =
+{
+    { "Disabled", shader_disabled_source },
+    { "Invert", shader_invert_source },
+    { "Grayscale", shader_grayscale_source },
+    { "Convert601to709", shader_convert601to709_source },
+    { "GammaCorrection18", shader_gammacorrection18_source },
+    { "GammaCorrection22", shader_gammacorrection22_source },
+    { "GammaCorrectionBT709", shader_gammacorrectionbt709_source },
+    { "WidenColorSpace", shader_widencolorspace_source },
+};
+#define BUILTIN_SHADERS_COUNT (sizeof(builtin_shaders)/sizeof(builtin_shaders[0]))
diff --git a/modules/video_output/win32/common.c b/modules/video_output/win32/common.c
new file mode 100644 (file)
index 0000000..4c880fa
--- /dev/null
@@ -0,0 +1,757 @@
+/*****************************************************************************
+ * common.c: Windows video output common code
+ *****************************************************************************
+ * Copyright (C) 2001-2009 VLC authors and VideoLAN
+ * $Id$
+ *
+ * Authors: Gildas Bazin <gbazin@videolan.org>
+ *          Martell Malone <martellmalone@gmail.com>
+ *
+ * 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 Lesser General Public License for more details.
+ *
+ * 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.
+ *****************************************************************************/
+
+/*****************************************************************************
+ * 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 <vlc_common.h>
+#include <vlc_vout_display.h>
+
+#include <windows.h>
+#include <assert.h>
+
+#define COBJMACROS
+#include <shobjidl.h>
+
+#include "common.h"
+
+static void CommonChangeThumbnailClip(vout_display_t *, bool show);
+#if !VLC_WINSTORE_APP
+static int  CommonControlSetFullscreen(vout_display_t *, bool is_fullscreen);
+
+static void DisableScreensaver(vout_display_t *);
+static void RestoreScreensaver(vout_display_t *);
+#endif
+
+/* */
+int CommonInit(vout_display_t *vd)
+{
+    vout_display_sys_t *sys = vd->sys;
+
+    sys->hwnd      = NULL;
+    sys->hvideownd = NULL;
+    sys->hparent   = NULL;
+    sys->hfswnd    = NULL;
+    sys->changes   = 0;
+    sys->is_first_display = true;
+    sys->is_on_top        = false;
+
+#if !VLC_WINSTORE_APP
+    SetRectEmpty(&sys->rect_display);
+    SetRectEmpty(&sys->rect_parent);
+
+    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);
+    if (!sys->event)
+        return VLC_EGENERIC;
+#endif
+
+    event_cfg_t cfg;
+    memset(&cfg, 0, sizeof(cfg));
+#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.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;
+
+#if !VLC_WINSTORE_APP
+    event_hwnd_t hwnd;
+    if (EventThreadStart(sys->event, &hwnd, &cfg))
+        return VLC_EGENERIC;
+
+    sys->parent_window = hwnd.parent_window;
+    sys->hparent       = hwnd.hparent;
+    sys->hwnd          = hwnd.hwnd;
+    sys->hvideownd     = hwnd.hvideownd;
+    sys->hfswnd        = hwnd.hfswnd;
+
+    if (vd->cfg->is_fullscreen) {
+        if (CommonControlSetFullscreen(vd, true))
+            vout_display_SendEventFullscreen(vd, false);
+    }
+
+    DisableScreensaver (vd);
+#endif
+
+    return VLC_SUCCESS;
+}
+
+/* */
+picture_pool_t *CommonPool(vout_display_t *vd, unsigned count)
+{
+    VLC_UNUSED(count);
+    return vd->sys->pool;
+}
+
+/*****************************************************************************
+* UpdateRects: update clipping rectangles
+*****************************************************************************
+* This function is called when the window position or size are changed, and
+* its job is to update the source and destination RECTs used to display the
+* picture.
+*****************************************************************************/
+void UpdateRects(vout_display_t *vd,
+    const vout_display_cfg_t *cfg,
+    const video_format_t *source,
+    bool is_forced)
+{
+    vout_display_sys_t *sys = vd->sys;
+#define rect_src sys->rect_src
+#define rect_src_clipped sys->rect_src_clipped
+#define rect_dest sys->rect_dest
+#define rect_dest_clipped sys->rect_dest_clipped
+
+    RECT  rect;
+    POINT point;
+
+    /* */
+    if (!cfg)
+        cfg = vd->cfg;
+    if (!source)
+        source = &vd->source;
+
+    /* Retrieve the window size */
+#if VLC_WINSTORE_APP && MODULE_NAME_IS_direct3d11
+    rect.left   = 0;
+    rect.top    = 0;
+    uint32_t i_width;
+    uint32_t i_height;
+    UINT dataSize = sizeof(i_width);
+    HRESULT hr = IDXGISwapChain_GetPrivateData(sys->dxgiswapChain, &GUID_SWAPCHAIN_WIDTH, &dataSize, &i_width);
+    if (FAILED(hr)) {
+        msg_Err(vd, "Can't get swapchain width, size %d. (hr=0x%lX)", hr, dataSize);
+        return;
+    }
+    dataSize = sizeof(i_height);
+    hr = IDXGISwapChain_GetPrivateData(sys->dxgiswapChain, &GUID_SWAPCHAIN_HEIGHT, &dataSize, &i_height);
+    if (FAILED(hr)) {
+        msg_Err(vd, "Can't get swapchain height, size %d. (hr=0x%lX)", hr, dataSize);
+        return;
+    }
+    rect.right  = i_width;
+    rect.bottom = i_height;
+#else
+    GetClientRect(sys->hwnd, &rect);
+#endif
+
+    /* Retrieve the window position */
+    point.x = point.y = 0;
+#if !VLC_WINSTORE_APP
+    ClientToScreen(sys->hwnd, &point);
+#endif
+
+    /* If nothing changed, we can return */
+    bool has_moved;
+    bool is_resized;
+#if VLC_WINSTORE_APP
+    has_moved = false;
+    is_resized = rect.right != (sys->rect_display.right - sys->rect_display.left) ||
+        rect.bottom != (sys->rect_display.bottom - sys->rect_display.top);
+    sys->rect_display = rect;
+#else
+    EventThreadUpdateWindowPosition(sys->event, &has_moved, &is_resized,
+        point.x, point.y,
+        rect.right, rect.bottom);
+#endif
+    if (is_resized)
+        vout_display_SendEventDisplaySize(vd, rect.right, rect.bottom);
+    if (!is_forced && !has_moved && !is_resized)
+        return;
+
+    /* Update the window position and size */
+    vout_display_cfg_t place_cfg = *cfg;
+    place_cfg.display.width = rect.right;
+    place_cfg.display.height = rect.bottom;
+
+    vout_display_place_t place;
+    vout_display_PlacePicture(&place, source, &place_cfg, false);
+
+#if !VLC_WINSTORE_APP
+    EventThreadUpdateSourceAndPlace(sys->event, source, &place);
+
+    if (sys->hvideownd)
+        SetWindowPos(sys->hvideownd, 0,
+            place.x, place.y, place.width, place.height,
+            SWP_NOCOPYBITS | SWP_NOZORDER | SWP_ASYNCWINDOWPOS);
+#endif
+
+    /* Destination image position and dimensions */
+#if (defined(MODULE_NAME_IS_direct3d9) || defined(MODULE_NAME_IS_direct3d11) || defined(MODULE_NAME_IS_direct2d)) && !VLC_WINSTORE_APP
+    rect_dest.left = 0;
+    rect_dest.right = place.width;
+    rect_dest.top = 0;
+    rect_dest.bottom = place.height;
+#else
+    rect_dest.left = point.x + place.x;
+    rect_dest.right = rect_dest.left + place.width;
+    rect_dest.top = point.y + place.y;
+    rect_dest.bottom = rect_dest.top + place.height;
+
+#ifdef MODULE_NAME_IS_directdraw
+    /* Apply overlay hardware constraints */
+    if (sys->use_overlay)
+        AlignRect(&rect_dest, sys->i_align_dest_boundary, sys->i_align_dest_size);
+#endif
+
+#endif
+
+#if defined(MODULE_NAME_IS_directdraw)
+    /* UpdateOverlay directdraw function doesn't automatically clip to the
+    * display size so we need to do it otherwise it will fail */
+
+    /* Clip the destination window */
+    if (!IntersectRect(&rect_dest_clipped, &rect_dest,
+        &sys->rect_display)) {
+        SetRectEmpty(&rect_src_clipped);
+        goto exit;
+    }
+
+#ifndef NDEBUG
+    msg_Dbg(vd, "DirectXUpdateRects image_dst_clipped coords:"
+        " %li,%li,%li,%li",
+        rect_dest_clipped.left, rect_dest_clipped.top,
+        rect_dest_clipped.right, rect_dest_clipped.bottom);
+#endif
+
+#else
+
+    /* AFAIK, there are no clipping constraints in Direct3D, OpenGL and GDI */
+    rect_dest_clipped = rect_dest;
+
+#endif
+
+    /* the 2 following lines are to fix a bug when clicking on the desktop */
+    if ((rect_dest_clipped.right - rect_dest_clipped.left) == 0 ||
+        (rect_dest_clipped.bottom - rect_dest_clipped.top) == 0) {
+#if !VLC_WINSTORE_APP
+        SetRectEmpty(&rect_src_clipped);
+#endif
+        goto exit;
+    }
+
+    /* src image dimensions */
+    rect_src.left = 0;
+    rect_src.top = 0;
+    rect_src.right = vd->fmt.i_width;
+    rect_src.bottom = vd->fmt.i_height;
+
+    /* Clip the source image */
+    rect_src_clipped.left = source->i_x_offset +
+        (rect_dest_clipped.left - rect_dest.left) *
+        source->i_visible_width / (rect_dest.right - rect_dest.left);
+    rect_src_clipped.right = source->i_x_offset +
+        source->i_visible_width -
+        (rect_dest.right - rect_dest_clipped.right) *
+        source->i_visible_width / (rect_dest.right - rect_dest.left);
+    rect_src_clipped.top = source->i_y_offset +
+        (rect_dest_clipped.top - rect_dest.top) *
+        source->i_visible_height / (rect_dest.bottom - rect_dest.top);
+    rect_src_clipped.bottom = source->i_y_offset +
+        source->i_visible_height -
+        (rect_dest.bottom - rect_dest_clipped.bottom) *
+        source->i_visible_height / (rect_dest.bottom - rect_dest.top);
+
+#ifdef MODULE_NAME_IS_directdraw
+    /* 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_direct3d9) || defined(MODULE_NAME_IS_direct3d11) || defined(MODULE_NAME_IS_direct2d)
+    /* Needed at least with YUV content */
+    rect_src_clipped.left &= ~1;
+    rect_src_clipped.right &= ~1;
+    rect_src_clipped.top &= ~1;
+    rect_src_clipped.bottom &= ~1;
+#endif
+
+#ifndef NDEBUG
+    msg_Dbg(vd, "DirectXUpdateRects souce"
+        " offset: %i,%i visible: %ix%i",
+        source->i_x_offset, source->i_y_offset,
+        source->i_visible_width, source->i_visible_height);
+    msg_Dbg(vd, "DirectXUpdateRects image_src"
+        " coords: %li,%li,%li,%li",
+        rect_src.left, rect_src.top,
+        rect_src.right, rect_src.bottom);
+    msg_Dbg(vd, "DirectXUpdateRects image_src_clipped"
+        " coords: %li,%li,%li,%li",
+        rect_src_clipped.left, rect_src_clipped.top,
+        rect_src_clipped.right, rect_src_clipped.bottom);
+    msg_Dbg(vd, "DirectXUpdateRects image_dst"
+        " coords: %li,%li,%li,%li",
+        rect_dest.left, rect_dest.top,
+        rect_dest.right, rect_dest.bottom);
+    msg_Dbg(vd, "DirectXUpdateRects image_dst_clipped"
+        " coords: %li,%li,%li,%li",
+        rect_dest_clipped.left, rect_dest_clipped.top,
+        rect_dest_clipped.right, rect_dest_clipped.bottom);
+#endif
+
+#ifdef MODULE_NAME_IS_directdraw
+    /* The destination coordinates need to be relative to the current
+    * directdraw primary surface (display) */
+    rect_dest_clipped.left -= sys->rect_display.left;
+    rect_dest_clipped.right -= sys->rect_display.left;
+    rect_dest_clipped.top -= sys->rect_display.top;
+    rect_dest_clipped.bottom -= sys->rect_display.top;
+#endif
+
+    CommonChangeThumbnailClip(vd, true);
+
+exit:
+    /* Signal the change in size/position */
+    sys->changes |= DX_POSITION_CHANGE;
+
+#undef rect_src
+#undef rect_src_clipped
+#undef rect_dest
+#undef rect_dest_clipped
+}
+
+#if !VLC_WINSTORE_APP
+/* */
+void CommonClean(vout_display_t *vd)
+{
+    vout_display_sys_t *sys = vd->sys;
+    if (sys->event) {
+        CommonChangeThumbnailClip(vd, false);
+        EventThreadStop(sys->event);
+        EventThreadDestroy(sys->event);
+    }
+
+    RestoreScreensaver(vd);
+}
+
+void CommonManage(vout_display_t *vd)
+{
+    vout_display_sys_t *sys = vd->sys;
+
+    /* We used to call the Win32 PeekMessage function here to read the window
+     * messages. But since window can stay blocked into this function for a
+     * long time (for example when you move your window on the screen), I
+     * decided to isolate PeekMessage in another thread. */
+    /* If we do not control our window, we check for geometry changes
+     * ourselves because the parent might not send us its events. */
+    if (sys->hparent) {
+        RECT rect_parent;
+        POINT point;
+
+        /* Check if the parent window has resized or moved */
+        GetClientRect(sys->hparent, &rect_parent);
+        point.x = point.y = 0;
+        ClientToScreen(sys->hparent, &point);
+        OffsetRect(&rect_parent, point.x, point.y);
+
+        if (!EqualRect(&rect_parent, &sys->rect_parent)) {
+            sys->rect_parent = rect_parent;
+
+            /* This code deals with both resize and move
+             *
+             * For most drivers(direct3d9, gdi, opengl), move is never
+             * an issue. The surface automatically gets moved together
+             * with the associated window (hvideownd)
+             *
+             * 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,
+                         rect_parent.right - rect_parent.left,
+                         rect_parent.bottom - rect_parent.top,
+                         SWP_NOZORDER);
+
+            UpdateRects(vd, NULL, NULL, true);
+        }
+    }
+
+    /* HasMoved means here resize or move */
+    if (EventThreadGetAndResetHasMoved(sys->event))
+        UpdateRects(vd, NULL, NULL, false);
+}
+
+/**
+ * It ensures that the video window is shown after the first picture
+ * is displayed.
+ */
+void CommonDisplay(vout_display_t *vd)
+{
+    vout_display_sys_t *sys = vd->sys;
+    if (!sys->is_first_display)
+        return;
+
+    /* Video window is initially hidden, show it now since we got a
+     * picture to show.
+     */
+    SetWindowPos(sys->hvideownd, 0, 0, 0, 0, 0,
+                 SWP_ASYNCWINDOWPOS|
+                 SWP_FRAMECHANGED|
+                 SWP_SHOWWINDOW|
+                 SWP_NOMOVE|
+                 SWP_NOSIZE|
+                 SWP_NOZORDER);
+    sys->is_first_display = false;
+}
+#endif
+
+/**
+ * It updates a picture data/pitches.
+ */
+int CommonUpdatePicture(picture_t *picture, picture_t **fallback,
+                        uint8_t *data, unsigned pitch)
+{
+    if (fallback) {
+        if (*fallback == NULL) {
+            *fallback = picture_NewFromFormat(&picture->format);
+            if (*fallback == NULL)
+                return VLC_EGENERIC;
+        }
+        for (int n = 0; n < picture->i_planes; n++) {
+            const plane_t *src = &(*fallback)->p[n];
+            plane_t       *dst = &picture->p[n];
+            dst->p_pixels = src->p_pixels;
+            dst->i_pitch  = src->i_pitch;
+            dst->i_lines  = src->i_lines;
+        }
+        return VLC_SUCCESS;
+    }
+    /* 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;
+
+    /*  Fill chroma planes for biplanar YUV */
+    if (picture->format.i_chroma == VLC_CODEC_NV12 ||
+        picture->format.i_chroma == VLC_CODEC_NV21) {
+
+        for (int n = 1; n < picture->i_planes; n++) {
+            const plane_t *o = &picture->p[n-1];
+            plane_t *p = &picture->p[n];
+
+            p->p_pixels = o->p_pixels + o->i_lines * o->i_pitch;
+            p->i_pitch  = pitch;
+            p->i_lines  = picture->format.i_height;
+        }
+        /* The dx/d3d buffer is always allocated as NV12 */
+        if (vlc_fourcc_AreUVPlanesSwapped(picture->format.i_chroma, VLC_CODEC_NV12)) {
+            /* TODO : Swap NV21 UV planes to match NV12 */
+            return VLC_EGENERIC;
+        }
+    }
+
+    /*  Fill chroma planes for planar YUV */
+    if (picture->format.i_chroma == VLC_CODEC_I420 ||
+        picture->format.i_chroma == VLC_CODEC_J420 ||
+        picture->format.i_chroma == VLC_CODEC_YV12) {
+
+        for (int n = 1; n < picture->i_planes; n++) {
+            const plane_t *o = &picture->p[n-1];
+            plane_t *p = &picture->p[n];
+
+            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;
+        }
+        /* The dx/d3d buffer is always allocated as YV12 */
+        if (vlc_fourcc_AreUVPlanesSwapped(picture->format.i_chroma, VLC_CODEC_YV12)) {
+            uint8_t *p_tmp = picture->p[1].p_pixels;
+            picture->p[1].p_pixels = picture->p[2].p_pixels;
+            picture->p[2].p_pixels = p_tmp;
+        }
+    }
+    return VLC_SUCCESS;
+}
+
+void AlignRect(RECT *r, int align_boundary, int align_size)
+{
+    if (align_boundary)
+        r->left = (r->left + align_boundary/2) & ~align_boundary;
+    if (align_size)
+        r->right = ((r->right - r->left + align_size/2) & ~align_size) + r->left;
+}
+
+#if !VLC_WINSTORE_APP
+/* */
+static void CommonChangeThumbnailClip(vout_display_t *vd, bool show)
+{
+    vout_display_sys_t *sys = vd->sys;
+
+    /* Windows 7 taskbar thumbnail code */
+    OSVERSIONINFO winVer;
+    winVer.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
+    if (!GetVersionEx(&winVer) || winVer.dwMajorVersion <= 5)
+        return;
+
+    if( FAILED(CoInitializeEx(NULL, COINIT_MULTITHREADED)) )
+        vlc_assert_unreachable();
+
+    void *ptr;
+    if (S_OK == CoCreateInstance(&CLSID_TaskbarList,
+                                 NULL, CLSCTX_INPROC_SERVER,
+                                 &IID_ITaskbarList3,
+                                 &ptr)) {
+        ITaskbarList3 *taskbl = ptr;
+        taskbl->lpVtbl->HrInit(taskbl);
+
+        HWND hroot = GetAncestor(sys->hwnd,GA_ROOT);
+        RECT relative;
+        if (show) {
+            RECT video, parent;
+            GetWindowRect(sys->hvideownd, &video);
+            GetWindowRect(hroot, &parent);
+            relative.left   = video.left   - parent.left - 8;
+            relative.top    = video.top    - parent.top - 10;
+
+            relative.right  = video.right  - video.left + relative.left;
+            relative.bottom = video.bottom - video.top  + relative.top - 25;
+        }
+        if (S_OK != taskbl->lpVtbl->SetThumbnailClip(taskbl, hroot,
+                                                 show ? &relative : NULL))
+            msg_Err(vd, "SetThumbNailClip failed");
+
+        taskbl->lpVtbl->Release(taskbl);
+    }
+    CoUninitialize();
+}
+
+static int CommonControlSetFullscreen(vout_display_t *vd, bool is_fullscreen)
+{
+    vout_display_sys_t *sys = vd->sys;
+
+#ifdef MODULE_NAME_IS_direct3d9
+    if (sys->use_desktop && is_fullscreen)
+