/*****************************************************************************
* directx.c: Windows DirectDraw video output
*****************************************************************************
- * Copyright (C) 2001-2009 the VideoLAN team
+ * 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 General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
*
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
/*****************************************************************************
* 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_playlist.h> /* needed for wallpaper */
-#include <vlc_charset.h>
+#include <vlc_charset.h> /* FromT */
#include <windows.h>
-#include <winuser.h>
#include <ddraw.h>
#include <commctrl.h> /* ListView_(Get|Set)* */
#include "common.h"
-#ifdef UNICODE
-# error "Unicode mode not supported"
-#endif
+/* 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
var_AddCallback(vd, "video-wallpaper", WallpaperCallback, NULL);
/* Setup vout_display now that everything is fine */
- vd->fmt = fmt;
+ video_format_Clean(&vd->fmt);
+ video_format_Copy(&vd->fmt, &fmt);
vd->info = info;
vd->pool = Pool;
}
/* */
-static BOOL WINAPI DirectXOpenDDrawCallback(GUID *guid, LPTSTR desc,
- LPTSTR drivername, VOID *context,
+static BOOL WINAPI DirectXOpenDDrawCallback(GUID *guid, LPSTR desc,
+ LPSTR drivername, VOID *context,
HMONITOR hmon)
{
vout_display_t *vd = context;
if (!hmon)
return TRUE;
- msg_Dbg(vd, "DirectXEnumCallback: %s, %s", desc, drivername);
+ 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(drivername, device)) {
+ if (device && *device && !strcmp(psz_drivername, device)) {
MONITORINFO monitor_info;
monitor_info.cbSize = sizeof(MONITORINFO);
free(device);
if (hmon == sys->hmonitor) {
- msg_Dbg(vd, "selecting %s, %s", desc, drivername);
+ msg_Dbg(vd, "selecting %s, %s", psz_desc, psz_drivername);
free(sys->display_driver);
sys->display_driver = malloc(sizeof(*guid));
/* */
HRESULT (WINAPI *OurDirectDrawCreate)(GUID *,LPDIRECTDRAW *,IUnknown *);
OurDirectDrawCreate =
- (void *)GetProcAddress(sys->hddraw_dll, _T("DirectDrawCreate"));
+ (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, _T("DirectDrawEnumerateExA"));
+ (void *)GetProcAddress(sys->hddraw_dll, DIRECTDRAWENUMERATEEX_NAME);
if (OurDirectDrawEnumerateEx) {
char *device = var_GetString(vd, "directx-device");
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;
+ ddsd.dwWidth = fmt->i_visible_width;
+ ddsd.dwHeight = fmt->i_visible_height;
if (fourcc) {
ddsd.dwFlags |= DDSD_PIXELFORMAT;
ddsd.ddpfPixelFormat.dwFlags = DDPF_FOURCC;
}
/* */
- picture_resource_t *rsc = &sys->resource;
- rsc->p_sys->front_surface = front_surface;
- rsc->p_sys->surface = surface;
- rsc->p_sys->fallback = NULL;
+ 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,
}
/* */
- picture_resource_t *rsc = &sys->resource;
- rsc->p_sys->front_surface = surface;
- rsc->p_sys->surface = surface;
- rsc->p_sys->fallback = NULL;
+ 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,
}
/* */
- picture_resource_t *rsc = &sys->resource;
- rsc->p_sys->front_surface = surface;
- rsc->p_sys->surface = surface;
- rsc->p_sys->fallback = NULL;
+ picture_sys_t *picsys = sys->picsys;
+ picsys->front_surface = surface;
+ picsys->surface = surface;
+ picsys->fallback = NULL;
return VLC_SUCCESS;
}
vout_display_sys_t *sys = vd->sys;
/* */
- picture_resource_t *rsc = &sys->resource;
- rsc->p_sys = calloc(1, sizeof(*rsc->p_sys));
- if (!rsc->p_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 &&
{
vout_display_sys_t *sys = vd->sys;
- if (sys->resource.p_sys->front_surface != sys->resource.p_sys->surface)
- DirectXDestroySurface(sys->resource.p_sys->surface);
- DirectXDestroySurface(sys->resource.p_sys->front_surface);
- if (sys->resource.p_sys->fallback)
- picture_Release(sys->resource.p_sys->fallback);
+ 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)
return VLC_EGENERIC;
/* Create the associated picture */
- picture_resource_t *rsc = &sys->resource;
- for (int i = 0; i < PICTURE_PLANE_MAX; i++) {
- rsc->p[i].p_pixels = NULL;
- rsc->p[i].i_pitch = 0;
- rsc->p[i].i_lines = 0;
- }
- picture_t *picture = picture_NewFromResource(fmt, rsc);
+ picture_resource_t resource = { .p_sys = sys->picsys };
+ picture_t *picture = picture_NewFromResource(fmt, &resource);
if (!picture) {
DirectXDestroyPictureResource(vd);
- free(rsc->p_sys);
+ free(sys->picsys);
return VLC_ENOMEM;
}
if (!surface) {
if (!sys->pool)
return VLC_EGENERIC;
- surface = sys->resource.p_sys->front_surface;
+ surface = sys->picsys->front_surface;
}
/* The new window dimensions should already have been computed by the
sys->ch_wallpaper |= ch_wallpaper;
sys->wallpaper_requested = newval.b_bool;
vlc_mutex_unlock(&sys->lock);
-
- /* FIXME we should have a way to export variable to be saved */
- if (ch_wallpaper) {
- playlist_t *p_playlist = pl_Get(vd);
- /* Modify playlist as well because the vout might have to be
- * restarted */
- var_Create(p_playlist, "video-wallpaper", VLC_VAR_BOOL);
- var_SetBool(p_playlist, "video-wallpaper", newval.b_bool);
- }
return VLC_SUCCESS;
}
/*****************************************************************************
* config variable callback
*****************************************************************************/
-static BOOL WINAPI DirectXEnumCallback2(GUID *guid, LPTSTR desc,
- LPTSTR drivername, VOID *data,
+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 *));
- /* TODO? Unicode APIs */
- ctx->values[ctx->count] = FromANSI(drivername);
- ctx->descs[ctx->count] = FromANSI(drivername);
+ ctx->values[ctx->count] = strdup(psz_drivername);
+ ctx->descs[ctx->count] = strdup(psz_drivername);
ctx->count++;
return TRUE; /* Keep enumerating */
/* Enumerate displays */
HRESULT (WINAPI *OurDirectDrawEnumerateEx)(LPDDENUMCALLBACKEXA,
LPVOID, DWORD) =
- (void *)GetProcAddress(hddraw_dll, _T("DirectDrawEnumerateExA"));
+ (void *)GetProcAddress(hddraw_dll, DIRECTDRAWENUMERATEEX_NAME);
if (OurDirectDrawEnumerateEx != NULL)
OurDirectDrawEnumerateEx(DirectXEnumCallback2, &ctx,
DDENUM_ATTACHEDSECONDARYDEVICES);