Cosmetics: rename variables etc. in vo_direct3d.c

Patch by Georgi Petrov (gogothebee gmail com)


git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@27962 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
reimar 2008-11-20 15:13:14 +00:00
parent c351d29392
commit f525ba25e7
1 changed files with 223 additions and 251 deletions

View File

@ -46,53 +46,54 @@ static const vo_info_t info =
const LIBVO_EXTERN(direct3d) const LIBVO_EXTERN(direct3d)
/* Global variables. Each one starts with "g". Pointers include "p". /* Global variables "priv" structure. I try to keep their count low.
* I try to keep their count low.
*/ */
static struct global_priv {
int is_paused; /**< 1 = Movie is paused,
0 = Movie is not paused */
int is_cfg_finished; /**< Synchronization "semaphore". 1 when
instance of reconfigure_d3d is finished */
int is_panscan; /**< 1= Panscan enabled, 0 = Panscan disabled */
static int gIsPaused; /**< 1 = Movie is paused, RECT fs_movie_rect; /**< Rect (upscaled) of the movie when displayed
0 = Movie is not paused */ in fullscreen */
static int gIsD3DConfigFinished; /**< Synchronization "semaphore". 1 when RECT fs_panscan_rect; /**< PanScan source surface cropping in
instance of D3DConfigure is finished */ fullscreen */
static int gIsPanscan; /**< 1= Panscan enabled, 0 = Panscan disabled */ int src_width; /**< Source (movie) width */
static RECT gFullScrMovieRect; /**< Rect (upscaled) of the movie when displayed int src_height; /**< Source (movie) heigth */
in fullscreen */
static RECT gPanScanSrcRect; /**< PanScan source surface cropping in D3DFORMAT movie_src_fmt; /**< Movie colorspace format (depends on
fullscreen */ the movie's codec) */
static int gSrcWidth; /**< Source (movie) width */ D3DFORMAT desktop_fmt; /**< Desktop (screen) colorspace format.
static int gSrcHeight; /**< Source (movie) heigth */ Usually XRGB */
static LPDIRECT3D9 gpD3DHandle; /**< Direct3D Handle */ LPDIRECT3D9 d3d_handle; /**< Direct3D Handle */
static LPDIRECT3DDEVICE9 gpD3DDevice; /**< The Direct3D Adapter */ LPDIRECT3DDEVICE9 d3d_device; /**< The Direct3D Adapter */
static IDirect3DSurface9 *gpD3DSurface; /**< Offscreen Direct3D Surface. MPlayer IDirect3DSurface9 *d3d_surface; /**< Offscreen Direct3D Surface. MPlayer
renders inside it. Uses colorspace renders inside it. Uses colorspace
MovieSrcFmt */ priv->movie_src_fmt */
static IDirect3DSurface9 *gpD3DBackBuf; /**< Video card's back buffer (used to IDirect3DSurface9 *d3d_backbuf; /**< Video card's back buffer (used to
display next frame) */ display next frame) */
static D3DFORMAT gMovieSrcFmt; /**< Movie colorspace format (depends on } *priv;
the movie's codec) */
static D3DFORMAT gDesktopFmt; /**< Desktop (screen) colorspace format. typedef struct {
Usually XRGB */ const unsigned int mplayer_fmt; /**< Given by MPlayer */
typedef struct const D3DFORMAT fourcc; /**< Required by D3D's test function */
{ } struct_fmt_table;
const unsigned int MPlayerFormat; /**< Given by MPlayer */
const D3DFORMAT FourCC; /**< Required by D3D's test function */
} DisplayFormatTable;
/* Map table from reported MPlayer format to the required /* Map table from reported MPlayer format to the required
FourCC. This is needed to perform the format query. */ fourcc. This is needed to perform the format query. */
static const DisplayFormatTable gDisplayFormatTable[] = static const struct_fmt_table fmt_table[] = {
{
{IMGFMT_YV12, MAKEFOURCC('Y','V','1','2')}, {IMGFMT_YV12, MAKEFOURCC('Y','V','1','2')},
{IMGFMT_I420, MAKEFOURCC('I','4','2','0')}, {IMGFMT_I420, MAKEFOURCC('I','4','2','0')},
{IMGFMT_IYUV, MAKEFOURCC('I','Y','U','V')}, {IMGFMT_IYUV, MAKEFOURCC('I','Y','U','V')},
{IMGFMT_YVU9, MAKEFOURCC('Y','V','U','9')}, {IMGFMT_YVU9, MAKEFOURCC('Y','V','U','9')},
{IMGFMT_YUY2, MAKEFOURCC('Y','U','Y','2')}, {IMGFMT_YUY2, MAKEFOURCC('Y','U','Y','2')},
{IMGFMT_UYVY, MAKEFOURCC('U','Y','V','Y')} {IMGFMT_UYVY, MAKEFOURCC('U','Y','V','Y')},
}; };
#define DISPLAY_FORMAT_TABLE_ENTRIES \ #define DISPLAY_FORMAT_TABLE_ENTRIES \
(sizeof(gDisplayFormatTable) / sizeof(gDisplayFormatTable[0])) (sizeof(fmt_table) / sizeof(fmt_table[0]))
/**************************************************************************** /****************************************************************************
* * * *
@ -106,108 +107,105 @@ static const DisplayFormatTable gDisplayFormatTable[] =
/** @brief Calculate panscan source RECT in fullscreen. /** @brief Calculate panscan source RECT in fullscreen.
*/ */
static void CalculatePanscanRect (void) static void calc_panscan_rect(void)
{ {
int scaledHeight = 0; int scaled_height = 0;
int scaledWidth = 0; int scaled_width = 0;
int srcPanx; int srcPanx;
int srcPany; int srcPany;
mp_msg(MSGT_VO,MSGL_ERR,"<vo_direct3d>CalculatePanscanRect called\r\n"); mp_msg(MSGT_VO,MSGL_ERR,"<vo_direct3d>calc_panscan_rect called\r\n");
aspect(&scaledWidth, &scaledHeight, A_ZOOM); aspect(&scaled_width, &scaled_height, A_ZOOM);
panscan_calc(); panscan_calc();
if (vo_panscan_x != 0 || vo_panscan_y != 0) if (vo_panscan_x != 0 || vo_panscan_y != 0) {
{ priv->is_panscan = 1;
gIsPanscan = 1;
mp_msg(MSGT_VO,MSGL_V, mp_msg(MSGT_VO,MSGL_V,
"<vo_direct3d>Panscan destination correction: x: %d, y: %d\r\n", "<vo_direct3d>Panscan destination correction: x: %d, y: %d\r\n",
vo_panscan_x, vo_panscan_y); vo_panscan_x, vo_panscan_y);
mp_msg(MSGT_VO,MSGL_V, mp_msg(MSGT_VO,MSGL_V,
"<vo_direct3d>vo_panscan_x %d, scaledWidth %d, vo_screenwidth %d\r\n", "<vo_direct3d>vo_panscan_x %d, scaled_width %d, vo_screenwidth %d\r\n",
vo_panscan_x, scaledWidth, vo_screenwidth); vo_panscan_x, scaled_width, vo_screenwidth);
mp_msg(MSGT_VO,MSGL_V, mp_msg(MSGT_VO,MSGL_V,
"<vo_direct3d>vo_panscan_y %d, scaledHeight %d, vo_screenheight %d\r\n", "<vo_direct3d>vo_panscan_y %d, scaled_height %d, vo_screenheight %d\r\n",
vo_panscan_y, scaledHeight, vo_screenheight); vo_panscan_y, scaled_height, vo_screenheight);
srcPanx = vo_panscan_x / (vo_screenwidth / scaledWidth); srcPanx = vo_panscan_x / (vo_screenwidth / scaled_width);
srcPany = vo_panscan_y / (vo_screenheight / scaledHeight); srcPany = vo_panscan_y / (vo_screenheight / scaled_height);
mp_msg(MSGT_VO,MSGL_V, mp_msg(MSGT_VO,MSGL_V,
"<vo_direct3d>Panscan source (needed) correction: x: %d, y: %d\r\n", "<vo_direct3d>Panscan source (needed) correction: x: %d, y: %d\r\n",
srcPanx, srcPany); srcPanx, srcPany);
gPanScanSrcRect.left = srcPanx / 2; priv->fs_panscan_rect.left = srcPanx / 2;
if (gPanScanSrcRect.left % 2 != 0) gPanScanSrcRect.left++; if (priv->fs_panscan_rect.left % 2 != 0) priv->fs_panscan_rect.left++;
gPanScanSrcRect.right = gSrcWidth - (srcPanx / 2); priv->fs_panscan_rect.right = priv->src_width - (srcPanx / 2);
if (gPanScanSrcRect.right % 2 != 0) gPanScanSrcRect.right--; if (priv->fs_panscan_rect.right % 2 != 0) priv->fs_panscan_rect.right--;
gPanScanSrcRect.top = srcPany / 2; priv->fs_panscan_rect.top = srcPany / 2;
if (gPanScanSrcRect.top % 2 != 0) gPanScanSrcRect.top++; if (priv->fs_panscan_rect.top % 2 != 0) priv->fs_panscan_rect.top++;
gPanScanSrcRect.bottom = gSrcHeight - (srcPany / 2); priv->fs_panscan_rect.bottom = priv->src_height - (srcPany / 2);
if (gPanScanSrcRect.bottom % 2 != 0) gPanScanSrcRect.bottom--; if (priv->fs_panscan_rect.bottom % 2 != 0) priv->fs_panscan_rect.bottom--;
mp_msg(MSGT_VO,MSGL_V, mp_msg(MSGT_VO,MSGL_V,
"<vo_direct3d>Panscan Source Rect: t: %ld, l: %ld, r: %ld, b:%ld\r\n", "<vo_direct3d>Panscan Source Rect: t: %ld, l: %ld, r: %ld, b:%ld\r\n",
gPanScanSrcRect.top, gPanScanSrcRect.left, priv->fs_panscan_rect.top, priv->fs_panscan_rect.left,
gPanScanSrcRect.right, gPanScanSrcRect.bottom); priv->fs_panscan_rect.right, priv->fs_panscan_rect.bottom);
} }
else else
gIsPanscan = 0; priv->is_panscan = 0;
} }
/** @brief Calculate scaled fullscreen movie rectangle with /** @brief Calculate scaled fullscreen movie rectangle with
* preserved aspect ratio. * preserved aspect ratio.
*/ */
static void CalculateFullscreenRect (void) static void calc_fs_rect(void)
{ {
int scaledHeight = 0; int scaled_height = 0;
int scaledWidth = 0; int scaled_width = 0;
/* If we've created fullscreen context, we should calculate stretched /* If we've created fullscreen context, we should calculate stretched
* movie RECT, otherwise it will fill the whole fullscreen with * movie RECT, otherwise it will fill the whole fullscreen with
* wrong aspect ratio */ * wrong aspect ratio */
aspect(&scaledWidth, &scaledHeight, A_ZOOM); aspect(&scaled_width, &scaled_height, A_ZOOM);
gFullScrMovieRect.left = (vo_screenwidth - scaledWidth) / 2; priv->fs_movie_rect.left = (vo_screenwidth - scaled_width) / 2;
gFullScrMovieRect.right = gFullScrMovieRect.left + scaledWidth; priv->fs_movie_rect.right = priv->fs_movie_rect.left + scaled_width;
gFullScrMovieRect.top = (vo_screenheight - scaledHeight) / 2; priv->fs_movie_rect.top = (vo_screenheight - scaled_height) / 2;
gFullScrMovieRect.bottom = gFullScrMovieRect.top + scaledHeight; priv->fs_movie_rect.bottom = priv->fs_movie_rect.top + scaled_height;
mp_msg(MSGT_VO,MSGL_V, mp_msg(MSGT_VO,MSGL_V,
"<vo_direct3d>Fullscreen Movie Rect: t: %ld, l: %ld, r: %ld, b:%ld\r\n", "<vo_direct3d>Fullscreen Movie Rect: t: %ld, l: %ld, r: %ld, b:%ld\r\n",
gFullScrMovieRect.top, gFullScrMovieRect.left, priv->fs_movie_rect.top, priv->fs_movie_rect.left,
gFullScrMovieRect.right, gFullScrMovieRect.bottom); priv->fs_movie_rect.right, priv->fs_movie_rect.bottom);
/*CalculatePanscanRect();*/ /*calc_panscan_rect();*/
} }
/** @brief Destroy D3D Context related to the current window. /** @brief Destroy D3D Context related to the current window.
*/ */
static void D3DDestroyContext (void) static void destroy_d3d_context(void)
{ {
mp_msg(MSGT_VO,MSGL_V,"<vo_direct3d>D3DDestroyContext called\r\n"); mp_msg(MSGT_VO,MSGL_V,"<vo_direct3d>destroy_d3d_context called\r\n");
/* Let's destroy the old (if any) D3D Content */ /* Let's destroy the old (if any) D3D Content */
if (gpD3DSurface != NULL) if (priv->d3d_surface != NULL) {
{ IDirect3DSurface9_Release (priv->d3d_surface);
IDirect3DSurface9_Release (gpD3DSurface); priv->d3d_surface = NULL;
gpD3DSurface = NULL;
} }
if (gpD3DDevice != NULL) if (priv->d3d_device != NULL) {
{ IDirect3DDevice9_Release (priv->d3d_device);
IDirect3DDevice9_Release (gpD3DDevice); priv->d3d_device = NULL;
gpD3DDevice = NULL;
} }
/* The following is not a memory leak. pD3DBackBuf is not malloc'ed /* The following is not a memory leak. d3d_backbuf is not malloc'ed
* but just holds a pointer to the back buffer. Nobody gets hurt from * but just holds a pointer to the back buffer. Nobody gets hurt from
* setting it to NULL. * setting it to NULL.
*/ */
gpD3DBackBuf = NULL; priv->d3d_backbuf = NULL;
} }
@ -215,51 +213,49 @@ static void D3DDestroyContext (void)
* The first function called to initialize D3D context. * The first function called to initialize D3D context.
* @return 1 on success, 0 on failure * @return 1 on success, 0 on failure
*/ */
static int D3DConfigure (void) static int reconfigure_d3d(void)
{ {
D3DPRESENT_PARAMETERS PresentParams; D3DPRESENT_PARAMETERS present_params;
D3DDISPLAYMODE DisplayMode; D3DDISPLAYMODE disp_mode;
mp_msg(MSGT_VO,MSGL_V,"<vo_direct3d><INFO>D3DConfigure CALLED\n"); mp_msg(MSGT_VO,MSGL_V,"<vo_direct3d><INFO>reconfigure_d3d called \n");
D3DDestroyContext(); destroy_d3d_context();
/* Get the current desktop display mode, so we can set up a back buffer /* Get the current desktop display mode, so we can set up a back buffer
* of the same format. */ * of the same format. */
if (FAILED (IDirect3D9_GetAdapterDisplayMode (gpD3DHandle, if (FAILED(IDirect3D9_GetAdapterDisplayMode(priv->d3d_handle,
D3DADAPTER_DEFAULT, D3DADAPTER_DEFAULT,
&DisplayMode))) &disp_mode))) {
{
mp_msg(MSGT_VO,MSGL_ERR, mp_msg(MSGT_VO,MSGL_ERR,
"<vo_direct3d><INFO>Could not read adapter display mode.\n"); "<vo_direct3d><INFO>Could not read adapter display mode.\n");
return 0; return 0;
} }
/* Write current Desktop's colorspace format in the global storage. */ /* Write current Desktop's colorspace format in the global storage. */
gDesktopFmt = DisplayMode.Format; priv->desktop_fmt = disp_mode.Format;
/* Prepare Direct3D initialization parameters. */ /* Prepare Direct3D initialization parameters. */
memset(&PresentParams, 0, sizeof(D3DPRESENT_PARAMETERS)); memset(&present_params, 0, sizeof(D3DPRESENT_PARAMETERS));
PresentParams.Windowed = TRUE; present_params.Windowed = TRUE;
PresentParams.SwapEffect = D3DSWAPEFFECT_COPY; present_params.SwapEffect = D3DSWAPEFFECT_COPY;
PresentParams.Flags = D3DPRESENTFLAG_VIDEO; present_params.Flags = D3DPRESENTFLAG_VIDEO;
PresentParams.hDeviceWindow = vo_w32_window; /* w32_common var */ present_params.hDeviceWindow = vo_w32_window; /* w32_common var */
PresentParams.BackBufferWidth = 0; /* Fill up window Width */ present_params.BackBufferWidth = 0; /* Fill up window Width */
PresentParams.BackBufferHeight = 0; /* Fill up window Height */ present_params.BackBufferHeight = 0; /* Fill up window Height */
PresentParams.MultiSampleType = D3DMULTISAMPLE_NONE; present_params.MultiSampleType = D3DMULTISAMPLE_NONE;
/* D3DPRESENT_INTERVAL_ONE = vsync */ /* D3DPRESENT_INTERVAL_ONE = vsync */
PresentParams.PresentationInterval = D3DPRESENT_INTERVAL_ONE; present_params.PresentationInterval = D3DPRESENT_INTERVAL_ONE;
PresentParams.BackBufferFormat = gDesktopFmt; present_params.BackBufferFormat = priv->desktop_fmt;
PresentParams.BackBufferCount = 1; present_params.BackBufferCount = 1;
PresentParams.EnableAutoDepthStencil = FALSE; present_params.EnableAutoDepthStencil = FALSE;
/* vo_w32_window is w32_common variable. It's a handle to the window. */ /* vo_w32_window is w32_common variable. It's a handle to the window. */
if (FAILED (IDirect3D9_CreateDevice(gpD3DHandle, if (FAILED(IDirect3D9_CreateDevice(priv->d3d_handle,
D3DADAPTER_DEFAULT, D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL, vo_w32_window, D3DDEVTYPE_HAL, vo_w32_window,
D3DCREATE_SOFTWARE_VERTEXPROCESSING, D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&PresentParams, &gpD3DDevice))) &present_params, &priv->d3d_device))) {
{
mp_msg(MSGT_VO,MSGL_ERR, mp_msg(MSGT_VO,MSGL_ERR,
"<vo_direct3d><INFO>Could not create the D3D device\n"); "<vo_direct3d><INFO>Could not create the D3D device\n");
return 0; return 0;
@ -267,53 +263,50 @@ static int D3DConfigure (void)
mp_msg(MSGT_VO,MSGL_V, mp_msg(MSGT_VO,MSGL_V,
"New BackBuffer: Width: %d, Height:%d. VO Dest Width:%d, Height: %d\n", "New BackBuffer: Width: %d, Height:%d. VO Dest Width:%d, Height: %d\n",
PresentParams.BackBufferWidth, PresentParams.BackBufferHeight, present_params.BackBufferWidth, present_params.BackBufferHeight,
vo_dwidth, vo_dheight); vo_dwidth, vo_dheight);
if (FAILED (IDirect3DDevice9_CreateOffscreenPlainSurface( if (FAILED(IDirect3DDevice9_CreateOffscreenPlainSurface(
gpD3DDevice, gSrcWidth, gSrcHeight, priv->d3d_device, priv->src_width, priv->src_height,
gMovieSrcFmt, D3DPOOL_DEFAULT, &gpD3DSurface, NULL))) priv->movie_src_fmt, D3DPOOL_DEFAULT, &priv->d3d_surface, NULL))) {
{
mp_msg(MSGT_VO,MSGL_ERR, mp_msg(MSGT_VO,MSGL_ERR,
"<vo_direct3d><INFO>IDirect3D9_CreateOffscreenPlainSurface Failed.\n"); "<vo_direct3d><INFO>IDirect3D9_CreateOffscreenPlainSurface Failed.\n");
return 0; return 0;
} }
if (FAILED (IDirect3DDevice9_GetBackBuffer (gpD3DDevice, 0, 0, if (FAILED(IDirect3DDevice9_GetBackBuffer(priv->d3d_device, 0, 0,
D3DBACKBUFFER_TYPE_MONO, D3DBACKBUFFER_TYPE_MONO,
&(gpD3DBackBuf)))) &(priv->d3d_backbuf)))) {
{
mp_msg(MSGT_VO,MSGL_ERR,"<vo_direct3d>Back Buffer address get failed\n"); mp_msg(MSGT_VO,MSGL_ERR,"<vo_direct3d>Back Buffer address get failed\n");
return 0; return 0;
} }
/* Fill the Surface with black color. */ /* Fill the Surface with black color. */
IDirect3DDevice9_ColorFill(gpD3DDevice, gpD3DSurface, NULL, IDirect3DDevice9_ColorFill(priv->d3d_device, priv->d3d_surface, NULL,
D3DCOLOR_ARGB(0xFF, 0, 0, 0) ); D3DCOLOR_ARGB(0xFF, 0, 0, 0) );
if (vo_fs) if (vo_fs)
CalculateFullscreenRect (); calc_fs_rect();
return 1; return 1;
} }
/** @brief Uninitialize Direct3D and close the window. /** @brief Uninitialize Direct3D and close the window.
*/ */
static void D3DUninit(void) static void uninit_d3d(void)
{ {
mp_msg(MSGT_VO,MSGL_V,"<vo_direct3d>D3DUninit called\r\n"); mp_msg(MSGT_VO,MSGL_V,"<vo_direct3d>uninit_d3d called\r\n");
/* Block further calls to D3DConfigure(). */ /* Block further calls to reconfigure_d3d(). */
gIsD3DConfigFinished = 0; priv->is_cfg_finished = 0;
/* Destroy D3D Context inside the window. */ /* Destroy D3D Context inside the window. */
D3DDestroyContext(); destroy_d3d_context();
/* Stop the whole D3D. */ /* Stop the whole D3D. */
if (NULL != gpD3DHandle) if (NULL != priv->d3d_handle) {
{
mp_msg(MSGT_VO,MSGL_V,"<vo_direct3d>Calling IDirect3D9_Release\r\n"); mp_msg(MSGT_VO,MSGL_V,"<vo_direct3d>Calling IDirect3D9_Release\r\n");
IDirect3D9_Release (gpD3DHandle); IDirect3D9_Release(priv->d3d_handle);
} }
} }
@ -321,9 +314,9 @@ static void D3DUninit(void)
* @param mpi mpi structure with the decoded frame inside * @param mpi mpi structure with the decoded frame inside
* @return VO_TRUE on success, VO_ERROR on failure * @return VO_TRUE on success, VO_ERROR on failure
*/ */
static uint32_t D3DRenderFrame (mp_image_t *mpi) static uint32_t render_d3d_frame(mp_image_t *mpi)
{ {
D3DLOCKED_RECT stLockedRect; /**< Offscreen surface we lock in order D3DLOCKED_RECT locked_rect; /**< Offscreen surface we lock in order
to copy MPlayer's frame inside it.*/ to copy MPlayer's frame inside it.*/
/* Uncomment when direct rendering is implemented. /* Uncomment when direct rendering is implemented.
@ -333,51 +326,45 @@ static uint32_t D3DRenderFrame (mp_image_t *mpi)
if (mpi->flags & MP_IMGFLAG_DRAW_CALLBACK) if (mpi->flags & MP_IMGFLAG_DRAW_CALLBACK)
return VO_TRUE; return VO_TRUE;
if (mpi->flags & MP_IMGFLAG_PLANAR) if (mpi->flags & MP_IMGFLAG_PLANAR) { /* Copy a planar frame. */
{ /* Copy a planar frame. */
draw_slice(mpi->planes,mpi->stride,mpi->w,mpi->h,0,0); draw_slice(mpi->planes,mpi->stride,mpi->w,mpi->h,0,0);
return VO_TRUE; return VO_TRUE;
} }
/* If the previous if failed, we should draw a packed frame */ /* If the previous if failed, we should draw a packed frame */
if (FAILED (IDirect3DDevice9_BeginScene(gpD3DDevice))) if (FAILED(IDirect3DDevice9_BeginScene(priv->d3d_device))) {
{
mp_msg(MSGT_VO,MSGL_ERR,"<vo_direct3d>BeginScene failed\n"); mp_msg(MSGT_VO,MSGL_ERR,"<vo_direct3d>BeginScene failed\n");
return VO_ERROR; return VO_ERROR;
} }
if (FAILED (IDirect3DSurface9_LockRect(gpD3DSurface, if (FAILED(IDirect3DSurface9_LockRect(priv->d3d_surface,
&stLockedRect, NULL, 0))) &locked_rect, NULL, 0))) {
{
mp_msg(MSGT_VO,MSGL_ERR,"<vo_direct3d>Surface lock failure\n"); mp_msg(MSGT_VO,MSGL_ERR,"<vo_direct3d>Surface lock failure\n");
return VO_ERROR; return VO_ERROR;
} }
memcpy_pic(stLockedRect.pBits, mpi->planes[0], mpi->stride[0], memcpy_pic(locked_rect.pBits, mpi->planes[0], mpi->stride[0],
mpi->height, stLockedRect.Pitch, mpi->stride[0]); mpi->height, locked_rect.Pitch, mpi->stride[0]);
if (FAILED (IDirect3DSurface9_UnlockRect(gpD3DSurface))) if (FAILED(IDirect3DSurface9_UnlockRect(priv->d3d_surface))) {
{
mp_msg(MSGT_VO,MSGL_V,"<vo_direct3d>Surface unlock failure\n"); mp_msg(MSGT_VO,MSGL_V,"<vo_direct3d>Surface unlock failure\n");
return VO_ERROR; return VO_ERROR;
} }
if (FAILED (IDirect3DDevice9_StretchRect (gpD3DDevice, if (FAILED(IDirect3DDevice9_StretchRect(priv->d3d_device,
gpD3DSurface, priv->d3d_surface,
gIsPanscan ? priv->is_panscan ?
&gPanScanSrcRect : NULL, &priv->fs_panscan_rect : NULL,
gpD3DBackBuf, priv->d3d_backbuf,
vo_fs ? vo_fs ?
&gFullScrMovieRect : NULL, &priv->fs_movie_rect : NULL,
D3DTEXF_LINEAR))) D3DTEXF_LINEAR))) {
{
mp_msg(MSGT_VO,MSGL_ERR, mp_msg(MSGT_VO,MSGL_ERR,
"<vo_direct3d>Unable to copy the frame to the back buffer\n"); "<vo_direct3d>Unable to copy the frame to the back buffer\n");
return VO_ERROR; return VO_ERROR;
} }
if (FAILED (IDirect3DDevice9_EndScene(gpD3DDevice))) if (FAILED(IDirect3DDevice9_EndScene(priv->d3d_device))) {
{
mp_msg(MSGT_VO,MSGL_ERR,"<vo_direct3d>EndScene failed\n"); mp_msg(MSGT_VO,MSGL_ERR,"<vo_direct3d>EndScene failed\n");
return VO_ERROR; return VO_ERROR;
} }
@ -390,26 +377,28 @@ static uint32_t D3DRenderFrame (mp_image_t *mpi)
* @return 0 on failure, device capabilities (not probed * @return 0 on failure, device capabilities (not probed
* currently) on success. * currently) on success.
*/ */
static int query_format (uint32_t MovieFormat) static int query_format(uint32_t movie_fmt)
{ {
int i; int i;
for (i=0; i < DISPLAY_FORMAT_TABLE_ENTRIES; i++) for (i=0; i < DISPLAY_FORMAT_TABLE_ENTRIES; i++) {
{ if (fmt_table[i].mplayer_fmt == movie_fmt) {
if (gDisplayFormatTable[i].MPlayerFormat == MovieFormat)
{
/* Test conversion from Movie colorspace to /* Test conversion from Movie colorspace to
* display's target colorspace. */ * display's target colorspace. */
if (FAILED (IDirect3D9_CheckDeviceFormatConversion( if (FAILED(IDirect3D9_CheckDeviceFormatConversion(
gpD3DHandle, priv->d3d_handle,
D3DADAPTER_DEFAULT, D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL, D3DDEVTYPE_HAL,
gDisplayFormatTable[i].FourCC, fmt_table[i].fourcc,
gDesktopFmt))) priv->desktop_fmt))) {
return 0; mp_msg(MSGT_VO,MSGL_V,
"<vo_direct3d>Rejected image format: %s\n",
vo_format_name(fmt_table[i].mplayer_fmt));
return 0;
}
gMovieSrcFmt = gDisplayFormatTable[i].FourCC; priv->movie_src_fmt = fmt_table[i].fourcc;
mp_msg(MSGT_VO,MSGL_V,"<vo_direct3d>Accepted Colorspace %s\n", mp_msg(MSGT_VO,MSGL_V,"<vo_direct3d>Accepted image format: %s\n",
vo_format_name(gDisplayFormatTable[i].MPlayerFormat)); vo_format_name(fmt_table[i].mplayer_fmt));
return (VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW return (VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW
/*| VFCAP_OSD*/ | VFCAP_HWSCALE_UP | VFCAP_HWSCALE_DOWN); /*| VFCAP_OSD*/ | VFCAP_HWSCALE_UP | VFCAP_HWSCALE_DOWN);
@ -438,55 +427,52 @@ static int query_format (uint32_t MovieFormat)
* *
* @return 0 on success, -1 on failure * @return 0 on success, -1 on failure
*/ */
static int preinit(const char *arg) static int preinit(const char *arg)
{ {
D3DDISPLAYMODE DisplayMode; D3DDISPLAYMODE disp_mode;
/* Set to zero all global variables. */ /* Set to zero all global variables. */
gIsPaused = 0; priv = calloc(1, sizeof (struct global_priv));
gIsD3DConfigFinished = 0; if (!priv) {
gIsPanscan = 0; mp_msg(MSGT_VO,MSGL_ERR,"<vo_direct3d>Not enough memory\r\n");
gpD3DHandle = NULL; return -1;
gpD3DDevice = NULL; }
gpD3DSurface = NULL;
gpD3DBackBuf = NULL;
/* FIXME /* FIXME
> Please use subopt-helper.h for this, see vo_gl.c:preinit for > Please use subopt-helper.h for this, see vo_gl.c:preinit for
> an example of how to use it. > an example of how to use it.
*/ */
gpD3DHandle = Direct3DCreate9 (D3D_SDK_VERSION); priv->d3d_handle = Direct3DCreate9(D3D_SDK_VERSION);
if (!gpD3DHandle) if (!priv->d3d_handle) {
{
mp_msg(MSGT_VO,MSGL_ERR,"<vo_direct3d>Unable to initialize Direct3D\n"); mp_msg(MSGT_VO,MSGL_ERR,"<vo_direct3d>Unable to initialize Direct3D\n");
return -1; return -1;
} }
if (FAILED (IDirect3D9_GetAdapterDisplayMode (gpD3DHandle, if (FAILED(IDirect3D9_GetAdapterDisplayMode(priv->d3d_handle,
D3DADAPTER_DEFAULT, D3DADAPTER_DEFAULT,
&DisplayMode))) &disp_mode))) {
{
mp_msg(MSGT_VO,MSGL_ERR,"<vo_direct3d>Could not read display mode\n"); mp_msg(MSGT_VO,MSGL_ERR,"<vo_direct3d>Could not read display mode\n");
return -1; return -1;
} }
/* Store in gDesktopFmt the user desktop's colorspace. Usually XRGB. */ /* Store in priv->desktop_fmt the user desktop's colorspace. Usually XRGB. */
gDesktopFmt = DisplayMode.Format; priv->desktop_fmt = disp_mode.Format;
mp_msg(MSGT_VO,MSGL_V,"DisplayMode.Width %d, DisplayMode.Height %d\n", mp_msg(MSGT_VO,MSGL_V,"disp_mode.Width %d, disp_mode.Height %d\n",
DisplayMode.Width, DisplayMode.Height); disp_mode.Width, disp_mode.Height);
/* w32_common framework call. Configures window on the screen, gets /* w32_common framework call. Configures window on the screen, gets
* fullscreen dimensions and does other useful stuff. * fullscreen dimensions and does other useful stuff.
*/ */
if (!vo_w32_init()) if (!vo_w32_init()) {
{
mp_msg(MSGT_VO,MSGL_V,"Unable to configure onscreen window\r\n"); mp_msg(MSGT_VO,MSGL_V,"Unable to configure onscreen window\r\n");
return -1; return -1;
} }
/* Allow the first call to D3DConfigure. */ /* Allow the first call to reconfigure_d3d. */
gIsD3DConfigFinished = 1; priv->is_cfg_finished = 1;
return 0; return 0;
} }
@ -498,27 +484,26 @@ static int preinit(const char *arg)
*/ */
static int control(uint32_t request, void *data, ...) static int control(uint32_t request, void *data, ...)
{ {
switch (request) switch (request) {
{
case VOCTRL_QUERY_FORMAT: case VOCTRL_QUERY_FORMAT:
return query_format (*(uint32_t*) data); return query_format(*(uint32_t*) data);
case VOCTRL_GET_IMAGE: /* Direct Rendering. Not implemented yet. */ case VOCTRL_GET_IMAGE: /* Direct Rendering. Not implemented yet. */
mp_msg(MSGT_VO,MSGL_V, mp_msg(MSGT_VO,MSGL_V,
"<vo_direct3d>Direct Rendering request. Not implemented yet\n"); "<vo_direct3d>Direct Rendering request. Not implemented yet\n");
return VO_NOTIMPL; return VO_NOTIMPL;
case VOCTRL_DRAW_IMAGE: case VOCTRL_DRAW_IMAGE:
return D3DRenderFrame (data); return render_d3d_frame(data);
case VOCTRL_FULLSCREEN: case VOCTRL_FULLSCREEN:
vo_w32_fullscreen(); vo_w32_fullscreen();
D3DConfigure(); reconfigure_d3d();
return VO_TRUE; return VO_TRUE;
case VOCTRL_RESET: case VOCTRL_RESET:
return VO_NOTIMPL; return VO_NOTIMPL;
case VOCTRL_PAUSE: case VOCTRL_PAUSE:
gIsPaused = 1; priv->is_paused = 1;
return VO_TRUE; return VO_TRUE;
case VOCTRL_RESUME: case VOCTRL_RESUME:
gIsPaused = 0; priv->is_paused = 0;
return VO_TRUE; return VO_TRUE;
case VOCTRL_GUISUPPORT: case VOCTRL_GUISUPPORT:
return VO_NOTIMPL; return VO_NOTIMPL;
@ -531,14 +516,14 @@ static int control(uint32_t request, void *data, ...)
return VO_TRUE; return VO_TRUE;
case VOCTRL_BORDER: case VOCTRL_BORDER:
vo_w32_border(); vo_w32_border();
D3DConfigure(); reconfigure_d3d();
return VO_TRUE; return VO_TRUE;
case VOCTRL_UPDATE_SCREENINFO: case VOCTRL_UPDATE_SCREENINFO:
w32_update_xinerama_info(); w32_update_xinerama_info();
return VO_TRUE; return VO_TRUE;
/* /*
case VOCTRL_SET_PANSCAN: case VOCTRL_SET_PANSCAN:
CalculatePanscanRect (); calc_panscan_rect ();
return VO_TRUE; return VO_TRUE;
case VOCTRL_GET_PANSCAN: case VOCTRL_GET_PANSCAN:
return VO_TRUE; return VO_TRUE;
@ -562,27 +547,25 @@ static int config(uint32_t width, uint32_t height, uint32_t d_width,
uint32_t d_height, uint32_t options, char *title, uint32_t d_height, uint32_t options, char *title,
uint32_t format) uint32_t format)
{ {
gSrcWidth = width;
gSrcHeight = height; priv->src_width = width;
priv->src_height = height;
/* w32_common framework call. Creates window on the screen with /* w32_common framework call. Creates window on the screen with
* the given coordinates. * the given coordinates.
*/ */
if (!vo_w32_config(d_width, d_height, options)) if (!vo_w32_config(d_width, d_height, options)) {
{
mp_msg(MSGT_VO,MSGL_V,"Unable to create onscreen window\r\n"); mp_msg(MSGT_VO,MSGL_V,"Unable to create onscreen window\r\n");
return VO_ERROR; return VO_ERROR;
} }
if (gIsD3DConfigFinished) if (priv->is_cfg_finished) {
{ priv->is_cfg_finished = 0;
gIsD3DConfigFinished = 0; if (!reconfigure_d3d()) {
if (!D3DConfigure ()) priv->is_cfg_finished = 1;
{
gIsD3DConfigFinished = 1;
return VO_ERROR; return VO_ERROR;
} }
gIsD3DConfigFinished = 1; priv->is_cfg_finished = 1;
} }
return 0; /* Success */ return 0; /* Success */
} }
@ -593,18 +576,15 @@ static int config(uint32_t width, uint32_t height, uint32_t d_width,
*/ */
static void flip_page(void) static void flip_page(void)
{ {
if (FAILED (IDirect3DDevice9_Present (gpD3DDevice, 0, 0, 0, 0))) if (FAILED(IDirect3DDevice9_Present(priv->d3d_device, 0, 0, 0, 0))) {
{
mp_msg(MSGT_VO,MSGL_V, mp_msg(MSGT_VO,MSGL_V,
"<vo_direct3d>Video adapter became uncooperative.\n"); "<vo_direct3d>Video adapter became uncooperative.\n");
mp_msg(MSGT_VO,MSGL_ERR,"<vo_direct3d>Trying to reinitialize it...\n"); mp_msg(MSGT_VO,MSGL_ERR,"<vo_direct3d>Trying to reinitialize it...\n");
if (!D3DConfigure()) if (!reconfigure_d3d()) {
{
mp_msg(MSGT_VO,MSGL_V,"<vo_direct3d>Reinitialization Failed.\n"); mp_msg(MSGT_VO,MSGL_V,"<vo_direct3d>Reinitialization Failed.\n");
return; return;
} }
if (FAILED (IDirect3DDevice9_Present (gpD3DDevice, 0, 0, 0, 0))) if (FAILED(IDirect3DDevice9_Present(priv->d3d_device, 0, 0, 0, 0))) {
{
mp_msg(MSGT_VO,MSGL_V,"<vo_direct3d>Reinitialization Failed.\n"); mp_msg(MSGT_VO,MSGL_V,"<vo_direct3d>Reinitialization Failed.\n");
return; return;
} }
@ -612,7 +592,7 @@ static void flip_page(void)
mp_msg(MSGT_VO,MSGL_V,"<vo_direct3d>Video adapter reinitialized.\n"); mp_msg(MSGT_VO,MSGL_V,"<vo_direct3d>Video adapter reinitialized.\n");
} }
/*IDirect3DDevice9_Clear (gpD3DDevice, 0, NULL, D3DCLEAR_TARGET, 0, 0, 0);*/ /*IDirect3DDevice9_Clear (priv->d3d_device, 0, NULL, D3DCLEAR_TARGET, 0, 0, 0);*/
} }
/** @brief libvo Callback: Draw OSD/Subtitles, /** @brief libvo Callback: Draw OSD/Subtitles,
@ -630,8 +610,10 @@ static void uninit(void)
{ {
mp_msg(MSGT_VO,MSGL_V,"<vo_direct3d>Uninitialization\r\n"); mp_msg(MSGT_VO,MSGL_V,"<vo_direct3d>Uninitialization\r\n");
D3DUninit(); uninit_d3d();
vo_w32_uninit(); /* w32_common framework call */ vo_w32_uninit(); /* w32_common framework call */
free (priv);
priv = NULL;
} }
/** @brief libvo Callback: Handles video window events. /** @brief libvo Callback: Handles video window events.
@ -646,9 +628,9 @@ static void check_events(void)
*/ */
flags = vo_w32_check_events(); flags = vo_w32_check_events();
if (flags & VO_EVENT_RESIZE) if (flags & VO_EVENT_RESIZE)
D3DConfigure(); reconfigure_d3d();
if ((flags & VO_EVENT_EXPOSE) && gIsPaused) if ((flags & VO_EVENT_EXPOSE) && priv->is_paused)
flip_page(); flip_page();
} }
@ -657,40 +639,38 @@ static void check_events(void)
*/ */
static int draw_slice(uint8_t *src[], int stride[], int w,int h,int x,int y ) static int draw_slice(uint8_t *src[], int stride[], int w,int h,int x,int y )
{ {
D3DLOCKED_RECT stLockedRect; /**< Offscreen surface we lock in order D3DLOCKED_RECT locked_rect; /**< Offscreen surface we lock in order
to copy MPlayer's frame inside it.*/ to copy MPlayer's frame inside it.*/
char *Src; /**< Pointer to the source image */ char *Src; /**< Pointer to the source image */
char *Dst; /**< Pointer to the destination image */ char *Dst; /**< Pointer to the destination image */
int UVstride; /**< Stride of the U/V planes */ int UVstride; /**< Stride of the U/V planes */
if (FAILED (IDirect3DDevice9_BeginScene(gpD3DDevice))) if (FAILED(IDirect3DDevice9_BeginScene(priv->d3d_device))) {
{
mp_msg(MSGT_VO,MSGL_ERR,"<vo_direct3d>BeginScene failed\n"); mp_msg(MSGT_VO,MSGL_ERR,"<vo_direct3d>BeginScene failed\n");
return VO_ERROR; return VO_ERROR;
} }
if (FAILED (IDirect3DSurface9_LockRect(gpD3DSurface, if (FAILED(IDirect3DSurface9_LockRect(priv->d3d_surface,
&stLockedRect, NULL, 0))) &locked_rect, NULL, 0))) {
{
mp_msg(MSGT_VO,MSGL_V,"<vo_direct3d>Surface lock failure\n"); mp_msg(MSGT_VO,MSGL_V,"<vo_direct3d>Surface lock failure\n");
return VO_FALSE; return VO_FALSE;
} }
UVstride = stLockedRect.Pitch / 2; UVstride = locked_rect.Pitch / 2;
/* Copy Y */ /* Copy Y */
Dst = stLockedRect.pBits; Dst = locked_rect.pBits;
Dst = Dst + stLockedRect.Pitch * y + x; Dst = Dst + locked_rect.Pitch * y + x;
Src=src[0]; Src=src[0];
memcpy_pic(Dst, Src, w, h, stLockedRect.Pitch, stride[0]); memcpy_pic(Dst, Src, w, h, locked_rect.Pitch, stride[0]);
w/=2;h/=2;x/=2;y/=2; w/=2;h/=2;x/=2;y/=2;
/* Copy U */ /* Copy U */
Dst = stLockedRect.pBits; Dst = locked_rect.pBits;
Dst = Dst + stLockedRect.Pitch * gSrcHeight Dst = Dst + locked_rect.Pitch * priv->src_height
+ UVstride * y + x; + UVstride * y + x;
if (gMovieSrcFmt == MAKEFOURCC('Y','V','1','2')) if (priv->movie_src_fmt == MAKEFOURCC('Y','V','1','2'))
Src=src[2]; Src=src[2];
else else
Src=src[1]; Src=src[1];
@ -698,38 +678,35 @@ static int draw_slice(uint8_t *src[], int stride[], int w,int h,int x,int y )
memcpy_pic(Dst, Src, w, h, UVstride, stride[1]); memcpy_pic(Dst, Src, w, h, UVstride, stride[1]);
/* Copy V */ /* Copy V */
Dst = stLockedRect.pBits; Dst = locked_rect.pBits;
Dst = Dst + stLockedRect.Pitch * gSrcHeight Dst = Dst + locked_rect.Pitch * priv->src_height
+ UVstride * (gSrcHeight / 2) + UVstride * y + x; + UVstride * (priv->src_height / 2) + UVstride * y + x;
if (gMovieSrcFmt == MAKEFOURCC('Y','V','1','2')) if (priv->movie_src_fmt == MAKEFOURCC('Y','V','1','2'))
Src=src[1]; Src=src[1];
else else
Src=src[2]; Src=src[2];
memcpy_pic(Dst, Src, w, h, UVstride, stride[2]); memcpy_pic(Dst, Src, w, h, UVstride, stride[2]);
if (FAILED (IDirect3DSurface9_UnlockRect(gpD3DSurface))) if (FAILED(IDirect3DSurface9_UnlockRect(priv->d3d_surface))) {
{
mp_msg(MSGT_VO,MSGL_V,"<vo_direct3d>Surface unlock failure\n"); mp_msg(MSGT_VO,MSGL_V,"<vo_direct3d>Surface unlock failure\n");
return VO_ERROR; return VO_ERROR;
} }
if (FAILED (IDirect3DDevice9_StretchRect (gpD3DDevice, if (FAILED(IDirect3DDevice9_StretchRect(priv->d3d_device,
gpD3DSurface, priv->d3d_surface,
gIsPanscan ? priv->is_panscan ?
&gPanScanSrcRect : NULL, &priv->fs_panscan_rect : NULL,
gpD3DBackBuf, priv->d3d_backbuf,
vo_fs ? vo_fs ?
&gFullScrMovieRect : NULL, &priv->fs_movie_rect : NULL,
D3DTEXF_LINEAR))) D3DTEXF_LINEAR))) {
{
mp_msg(MSGT_VO,MSGL_V, mp_msg(MSGT_VO,MSGL_V,
"<vo_direct3d>Unable to copy the frame to the back buffer\n"); "<vo_direct3d>Unable to copy the frame to the back buffer\n");
return VO_ERROR; return VO_ERROR;
} }
if (FAILED (IDirect3DDevice9_EndScene(gpD3DDevice))) if (FAILED(IDirect3DDevice9_EndScene(priv->d3d_device))) {
{
mp_msg(MSGT_VO,MSGL_ERR,"<vo_direct3d>EndScene failed\n"); mp_msg(MSGT_VO,MSGL_ERR,"<vo_direct3d>EndScene failed\n");
return VO_ERROR; return VO_ERROR;
} }
@ -745,8 +722,3 @@ static int draw_frame(uint8_t *src[])
mp_msg(MSGT_VO,MSGL_V,"<vo_direct3d>draw_frame called\n"); mp_msg(MSGT_VO,MSGL_V,"<vo_direct3d>draw_frame called\n");
return VO_FALSE; return VO_FALSE;
} }