diff options
author | Uoti Urpala <uau@glyph.nonexistent.invalid> | 2009-01-31 04:52:15 +0200 |
---|---|---|
committer | Uoti Urpala <uau@glyph.nonexistent.invalid> | 2009-01-31 04:52:15 +0200 |
commit | ccf4d9e96cd7aa8506e6632d2a7352ec89b2b9e3 (patch) | |
tree | a5f3a6d636e96f05bb52f0b2407107a7f0c8b443 /libvo | |
parent | 03aa64687fc109c5f2346a3c191b70698b333509 (diff) | |
parent | 0e77da241da8b911c96a0e22898e84d7f7b74678 (diff) | |
download | mpv-ccf4d9e96cd7aa8506e6632d2a7352ec89b2b9e3.tar.bz2 mpv-ccf4d9e96cd7aa8506e6632d2a7352ec89b2b9e3.tar.xz |
Merge svn changes up to r28403
Diffstat (limited to 'libvo')
-rw-r--r-- | libvo/aclib.c | 32 | ||||
-rw-r--r-- | libvo/aclib_template.c | 8 | ||||
-rw-r--r-- | libvo/fastmemcpy.h | 2 | ||||
-rw-r--r-- | libvo/osd.c | 40 | ||||
-rw-r--r-- | libvo/osd_template.c | 12 | ||||
-rw-r--r-- | libvo/video_out.c | 2 | ||||
-rw-r--r-- | libvo/vo_direct3d.c | 156 |
7 files changed, 161 insertions, 91 deletions
diff --git a/libvo/aclib.c b/libvo/aclib.c index 4c51709b2a..bc9bb2e55c 100644 --- a/libvo/aclib.c +++ b/libvo/aclib.c @@ -30,7 +30,7 @@ #ifdef CAN_COMPILE_X86_ASM -#if (HAVE_MMX && !HAVE_3DNOW && !HAVE_MMX2) || defined (RUNTIME_CPUDETECT) +#if (HAVE_MMX && !HAVE_AMD3DNOW && !HAVE_MMX2) || defined (RUNTIME_CPUDETECT) #define COMPILE_MMX #endif @@ -38,7 +38,7 @@ #define COMPILE_MMX2 #endif -#if (HAVE_3DNOW && !HAVE_MMX2) || defined (RUNTIME_CPUDETECT) +#if (HAVE_AMD3DNOW && !HAVE_MMX2) || defined (RUNTIME_CPUDETECT) #define COMPILE_3DNOW #endif @@ -48,24 +48,24 @@ #undef HAVE_MMX #undef HAVE_MMX2 -#undef HAVE_3DNOW +#undef HAVE_AMD3DNOW #undef HAVE_SSE #undef HAVE_SSE2 #define HAVE_MMX 0 #define HAVE_MMX2 0 -#define HAVE_3DNOW 0 +#define HAVE_AMD3DNOW 0 #define HAVE_SSE 0 #define HAVE_SSE2 0 /* #ifdef COMPILE_C #undef HAVE_MMX #undef HAVE_MMX2 -#undef HAVE_3DNOW +#undef HAVE_AMD3DNOW #undef HAVE_SSE #undef HAVE_SSE2 #define HAVE_MMX 0 #define HAVE_MMX2 0 -#define HAVE_3DNOW 0 +#define HAVE_AMD3DNOW 0 #define HAVE_SSE 0 #define HAVE_SSE2 0 #define RENAME(a) a ## _C @@ -77,12 +77,12 @@ #undef RENAME #undef HAVE_MMX #undef HAVE_MMX2 -#undef HAVE_3DNOW +#undef HAVE_AMD3DNOW #undef HAVE_SSE #undef HAVE_SSE2 #define HAVE_MMX 1 #define HAVE_MMX2 0 -#define HAVE_3DNOW 0 +#define HAVE_AMD3DNOW 0 #define HAVE_SSE 0 #define HAVE_SSE2 0 #define RENAME(a) a ## _MMX @@ -94,12 +94,12 @@ #undef RENAME #undef HAVE_MMX #undef HAVE_MMX2 -#undef HAVE_3DNOW +#undef HAVE_AMD3DNOW #undef HAVE_SSE #undef HAVE_SSE2 #define HAVE_MMX 1 #define HAVE_MMX2 1 -#define HAVE_3DNOW 0 +#define HAVE_AMD3DNOW 0 #define HAVE_SSE 0 #define HAVE_SSE2 0 #define RENAME(a) a ## _MMX2 @@ -111,12 +111,12 @@ #undef RENAME #undef HAVE_MMX #undef HAVE_MMX2 -#undef HAVE_3DNOW +#undef HAVE_AMD3DNOW #undef HAVE_SSE #undef HAVE_SSE2 #define HAVE_MMX 1 #define HAVE_MMX2 0 -#define HAVE_3DNOW 1 +#define HAVE_AMD3DNOW 1 #define HAVE_SSE 0 #define HAVE_SSE2 0 #define RENAME(a) a ## _3DNow @@ -128,12 +128,12 @@ #undef RENAME #undef HAVE_MMX #undef HAVE_MMX2 -#undef HAVE_3DNOW +#undef HAVE_AMD3DNOW #undef HAVE_SSE #undef HAVE_SSE2 #define HAVE_MMX 1 #define HAVE_MMX2 1 -#define HAVE_3DNOW 0 +#define HAVE_AMD3DNOW 0 #define HAVE_SSE 1 #define HAVE_SSE2 1 #define RENAME(a) a ## _SSE @@ -165,7 +165,7 @@ void * fast_memcpy(void * to, const void * from, size_t len) fast_memcpy_SSE(to, from, len); #elif HAVE_MMX2 fast_memcpy_MMX2(to, from, len); -#elif HAVE_3DNOW +#elif HAVE_AMD3DNOW fast_memcpy_3DNow(to, from, len); #elif HAVE_MMX fast_memcpy_MMX(to, from, len); @@ -199,7 +199,7 @@ void * mem2agpcpy(void * to, const void * from, size_t len) mem2agpcpy_SSE(to, from, len); #elif HAVE_MMX2 mem2agpcpy_MMX2(to, from, len); -#elif HAVE_3DNOW +#elif HAVE_AMD3DNOW mem2agpcpy_3DNow(to, from, len); #elif HAVE_MMX mem2agpcpy_MMX(to, from, len); diff --git a/libvo/aclib_template.c b/libvo/aclib_template.c index 74f0371a63..ab2ed6e5f5 100644 --- a/libvo/aclib_template.c +++ b/libvo/aclib_template.c @@ -66,7 +66,7 @@ If you have questions please contact with me: Nick Kurshev: nickols_k@mail.ru. #undef HAVE_ONLY_MMX1 -#if HAVE_MMX && !HAVE_MMX2 && !HAVE_3DNOW && !HAVE_SSE +#if HAVE_MMX && !HAVE_MMX2 && !HAVE_AMD3DNOW && !HAVE_SSE /* means: mmx v.1. Note: Since we added alignment of destinition it speedups of memory copying on PentMMX, Celeron-1 and P2 upto 12% versus standard (non MMX-optimized) version. @@ -77,7 +77,7 @@ If you have questions please contact with me: Nick Kurshev: nickols_k@mail.ru. #undef HAVE_K6_2PLUS -#if !HAVE_MMX2 && HAVE_3DNOW +#if !HAVE_MMX2 && HAVE_AMD3DNOW #define HAVE_K6_2PLUS #endif @@ -107,14 +107,14 @@ __asm__ volatile(\ #if HAVE_MMX2 #define PREFETCH "prefetchnta" -#elif HAVE_3DNOW +#elif HAVE_AMD3DNOW #define PREFETCH "prefetch" #else #define PREFETCH " # nop" #endif /* On K6 femms is faster of emms. On K7 femms is directly mapped on emms. */ -#if HAVE_3DNOW +#if HAVE_AMD3DNOW #define EMMS "femms" #else #define EMMS "emms" diff --git a/libvo/fastmemcpy.h b/libvo/fastmemcpy.h index 69ded04bcf..fa736b62f0 100644 --- a/libvo/fastmemcpy.h +++ b/libvo/fastmemcpy.h @@ -24,7 +24,7 @@ #include <string.h> #ifdef CONFIG_FASTMEMCPY -#if HAVE_MMX || HAVE_MMX2 || HAVE_3DNOW \ +#if HAVE_MMX || HAVE_MMX2 || HAVE_AMD3DNOW \ /* || HAVE_SSE || HAVE_SSE2 */ #include <stddef.h> diff --git a/libvo/osd.c b/libvo/osd.c index df91ffbae0..80a8da7f1c 100644 --- a/libvo/osd.c +++ b/libvo/osd.c @@ -29,7 +29,7 @@ static const unsigned long long mask24hl __attribute__((aligned(8))) = 0x0000FF #ifdef CAN_COMPILE_X86_ASM -#if (HAVE_MMX && !HAVE_3DNOW && !HAVE_MMX2) || defined (RUNTIME_CPUDETECT) +#if (HAVE_MMX && !HAVE_AMD3DNOW && !HAVE_MMX2) || defined (RUNTIME_CPUDETECT) #define COMPILE_MMX #endif @@ -37,27 +37,27 @@ static const unsigned long long mask24hl __attribute__((aligned(8))) = 0x0000FF #define COMPILE_MMX2 #endif -#if (HAVE_3DNOW && !HAVE_MMX2) || defined (RUNTIME_CPUDETECT) +#if (HAVE_AMD3DNOW && !HAVE_MMX2) || defined (RUNTIME_CPUDETECT) #define COMPILE_3DNOW #endif #endif //CAN_COMPILE_X86_ASM #undef HAVE_MMX #undef HAVE_MMX2 -#undef HAVE_3DNOW +#undef HAVE_AMD3DNOW #define HAVE_MMX 0 #define HAVE_MMX2 0 -#define HAVE_3DNOW 0 +#define HAVE_AMD3DNOW 0 #ifndef CAN_COMPILE_X86_ASM #ifdef COMPILE_C #undef HAVE_MMX #undef HAVE_MMX2 -#undef HAVE_3DNOW +#undef HAVE_AMD3DNOW #define HAVE_MMX 0 #define HAVE_MMX2 0 -#define HAVE_3DNOW 0 +#define HAVE_AMD3DNOW 0 #define RENAME(a) a ## _C #include "osd_template.c" #endif @@ -69,10 +69,10 @@ static const unsigned long long mask24hl __attribute__((aligned(8))) = 0x0000FF #undef RENAME #undef HAVE_MMX #undef HAVE_MMX2 -#undef HAVE_3DNOW +#undef HAVE_AMD3DNOW #define HAVE_MMX 0 #define HAVE_MMX2 0 -#define HAVE_3DNOW 0 +#define HAVE_AMD3DNOW 0 #define RENAME(a) a ## _X86 #include "osd_template.c" #endif @@ -82,10 +82,10 @@ static const unsigned long long mask24hl __attribute__((aligned(8))) = 0x0000FF #undef RENAME #undef HAVE_MMX #undef HAVE_MMX2 -#undef HAVE_3DNOW +#undef HAVE_AMD3DNOW #define HAVE_MMX 1 #define HAVE_MMX2 0 -#define HAVE_3DNOW 0 +#define HAVE_AMD3DNOW 0 #define RENAME(a) a ## _MMX #include "osd_template.c" #endif @@ -95,10 +95,10 @@ static const unsigned long long mask24hl __attribute__((aligned(8))) = 0x0000FF #undef RENAME #undef HAVE_MMX #undef HAVE_MMX2 -#undef HAVE_3DNOW +#undef HAVE_AMD3DNOW #define HAVE_MMX 1 #define HAVE_MMX2 1 -#define HAVE_3DNOW 0 +#define HAVE_AMD3DNOW 0 #define RENAME(a) a ## _MMX2 #include "osd_template.c" #endif @@ -108,10 +108,10 @@ static const unsigned long long mask24hl __attribute__((aligned(8))) = 0x0000FF #undef RENAME #undef HAVE_MMX #undef HAVE_MMX2 -#undef HAVE_3DNOW +#undef HAVE_AMD3DNOW #define HAVE_MMX 1 #define HAVE_MMX2 0 -#define HAVE_3DNOW 1 +#define HAVE_AMD3DNOW 1 #define RENAME(a) a ## _3DNow #include "osd_template.c" #endif @@ -136,7 +136,7 @@ void vo_draw_alpha_yv12(int w,int h, unsigned char* src, unsigned char *srca, in #else //RUNTIME_CPUDETECT #if HAVE_MMX2 vo_draw_alpha_yv12_MMX2(w, h, src, srca, srcstride, dstbase, dststride); -#elif HAVE_3DNOW +#elif HAVE_AMD3DNOW vo_draw_alpha_yv12_3DNow(w, h, src, srca, srcstride, dstbase, dststride); #elif HAVE_MMX vo_draw_alpha_yv12_MMX(w, h, src, srca, srcstride, dstbase, dststride); @@ -166,7 +166,7 @@ void vo_draw_alpha_yuy2(int w,int h, unsigned char* src, unsigned char *srca, in #else //RUNTIME_CPUDETECT #if HAVE_MMX2 vo_draw_alpha_yuy2_MMX2(w, h, src, srca, srcstride, dstbase, dststride); -#elif HAVE_3DNOW +#elif HAVE_AMD3DNOW vo_draw_alpha_yuy2_3DNow(w, h, src, srca, srcstride, dstbase, dststride); #elif HAVE_MMX vo_draw_alpha_yuy2_MMX(w, h, src, srca, srcstride, dstbase, dststride); @@ -196,7 +196,7 @@ void vo_draw_alpha_uyvy(int w,int h, unsigned char* src, unsigned char *srca, in #else //RUNTIME_CPUDETECT #if HAVE_MMX2 vo_draw_alpha_uyvy_MMX2(w, h, src, srca, srcstride, dstbase, dststride); -#elif HAVE_3DNOW +#elif HAVE_AMD3DNOW vo_draw_alpha_uyvy_3DNow(w, h, src, srca, srcstride, dstbase, dststride); #elif HAVE_MMX vo_draw_alpha_uyvy_MMX(w, h, src, srca, srcstride, dstbase, dststride); @@ -226,7 +226,7 @@ void vo_draw_alpha_rgb24(int w,int h, unsigned char* src, unsigned char *srca, i #else //RUNTIME_CPUDETECT #if HAVE_MMX2 vo_draw_alpha_rgb24_MMX2(w, h, src, srca, srcstride, dstbase, dststride); -#elif HAVE_3DNOW +#elif HAVE_AMD3DNOW vo_draw_alpha_rgb24_3DNow(w, h, src, srca, srcstride, dstbase, dststride); #elif HAVE_MMX vo_draw_alpha_rgb24_MMX(w, h, src, srca, srcstride, dstbase, dststride); @@ -256,7 +256,7 @@ void vo_draw_alpha_rgb32(int w,int h, unsigned char* src, unsigned char *srca, i #else //RUNTIME_CPUDETECT #if HAVE_MMX2 vo_draw_alpha_rgb32_MMX2(w, h, src, srca, srcstride, dstbase, dststride); -#elif HAVE_3DNOW +#elif HAVE_AMD3DNOW vo_draw_alpha_rgb32_3DNow(w, h, src, srca, srcstride, dstbase, dststride); #elif HAVE_MMX vo_draw_alpha_rgb32_MMX(w, h, src, srca, srcstride, dstbase, dststride); @@ -301,7 +301,7 @@ void vo_draw_alpha_init(void){ #else //RUNTIME_CPUDETECT #if HAVE_MMX2 mp_msg(MSGT_OSD,MSGL_INFO,"Using MMX (with tiny bit MMX2) Optimized OnScreenDisplay\n"); -#elif HAVE_3DNOW +#elif HAVE_AMD3DNOW mp_msg(MSGT_OSD,MSGL_INFO,"Using MMX (with tiny bit 3DNow) Optimized OnScreenDisplay\n"); #elif HAVE_MMX mp_msg(MSGT_OSD,MSGL_INFO,"Using MMX Optimized OnScreenDisplay\n"); diff --git a/libvo/osd_template.c b/libvo/osd_template.c index 8700a176c6..bc37b9d460 100644 --- a/libvo/osd_template.c +++ b/libvo/osd_template.c @@ -7,7 +7,7 @@ #undef PREFETCHW #undef PAVGB -#if HAVE_3DNOW +#if HAVE_AMD3DNOW #define PREFETCH "prefetch" #define PREFETCHW "prefetchw" #define PAVGB "pavgusb" @@ -20,7 +20,7 @@ #define PREFETCHW " # nop" #endif -#if HAVE_3DNOW +#if HAVE_AMD3DNOW /* On K6 femms is faster of emms. On K7 femms is directly mapped on emms. */ #define EMMS "femms" #else @@ -307,12 +307,12 @@ static inline void RENAME(vo_draw_alpha_rgb32)(int w,int h, unsigned char* src, dstbase++; #endif #if HAVE_MMX -#if HAVE_3DNOW +#if HAVE_AMD3DNOW __asm__ volatile( "pxor %%mm7, %%mm7\n\t" "pcmpeqb %%mm6, %%mm6\n\t" // F..F ::); -#else /* HAVE_3DNOW */ +#else /* HAVE_AMD3DNOW */ __asm__ volatile( "pxor %%mm7, %%mm7\n\t" "pcmpeqb %%mm5, %%mm5\n\t" // F..F @@ -320,13 +320,13 @@ static inline void RENAME(vo_draw_alpha_rgb32)(int w,int h, unsigned char* src, "psllw $8, %%mm5\n\t" //FF00FF00FF00 "psrlw $8, %%mm4\n\t" //00FF00FF00FF ::); -#endif /* HAVE_3DNOW */ +#endif /* HAVE_AMD3DNOW */ #endif /* HAVE_MMX */ for(y=0;y<h;y++){ register int x; #if ARCH_X86 && (!ARCH_X86_64 || HAVE_MMX) #if HAVE_MMX -#if HAVE_3DNOW +#if HAVE_AMD3DNOW __asm__ volatile( PREFETCHW" %0\n\t" PREFETCH" %1\n\t" diff --git a/libvo/video_out.c b/libvo/video_out.c index dfdebf077e..d0a873a486 100644 --- a/libvo/video_out.c +++ b/libvo/video_out.c @@ -213,7 +213,7 @@ const struct vo_driver *video_out_drivers[] = #endif &video_out_null, // should not be auto-selected -#ifdef CONFIG_XVMC +#if CONFIG_XVMC &video_out_xvmc, #endif &video_out_mpegpes, diff --git a/libvo/vo_direct3d.c b/libvo/vo_direct3d.c index c32cdc663a..c86cc94c07 100644 --- a/libvo/vo_direct3d.c +++ b/libvo/vo_direct3d.c @@ -78,6 +78,8 @@ static struct global_priv { cannot lock a normal texture. Uses RGBA */ IDirect3DSurface9 *d3d_backbuf; /**< Video card's back buffer (used to display next frame) */ + int cur_backbuf_width; /**< Current backbuffer width */ + int cur_backbuf_height; /**< Current backbuffer height */ int is_osd_populated; /**< 1 = OSD texture has something to display, 0 = OSD texture is clear */ int device_caps_power2_only; /**< 1 = texture sizes have to be power 2 @@ -126,6 +128,10 @@ typedef struct { float tu, tv; /* Texture coordinates */ } struct_vertex; +typedef enum back_buffer_action { + BACKBUFFER_CREATE, + BACKBUFFER_RESET +} back_buffer_action_e; /**************************************************************************** * * * * @@ -224,7 +230,8 @@ static void destroy_d3d_surfaces(void) priv->d3d_backbuf = NULL; } -/** @brief Create D3D Offscreen and Backbuffer surfaces. +/** @brief Create D3D Offscreen and Backbuffer surfaces. Each + * surface is created only if it's not already present. * @return 1 on success, 0 on failure */ static int create_d3d_surfaces(void) @@ -233,7 +240,8 @@ static int create_d3d_surfaces(void) int tex_width = osd_width, tex_height = osd_height; mp_msg(MSGT_VO, MSGL_V, "<vo_direct3d><INFO>create_d3d_surfaces called.\n"); - if (FAILED(IDirect3DDevice9_CreateOffscreenPlainSurface( + if (!priv->d3d_surface && + FAILED(IDirect3DDevice9_CreateOffscreenPlainSurface( priv->d3d_device, priv->src_width, priv->src_height, priv->movie_src_fmt, D3DPOOL_DEFAULT, &priv->d3d_surface, NULL))) { mp_msg(MSGT_VO, MSGL_ERR, @@ -241,7 +249,8 @@ static int create_d3d_surfaces(void) return 0; } - if (FAILED(IDirect3DDevice9_GetBackBuffer(priv->d3d_device, 0, 0, + if (!priv->d3d_backbuf && + FAILED(IDirect3DDevice9_GetBackBuffer(priv->d3d_device, 0, 0, D3DBACKBUFFER_TYPE_MONO, &priv->d3d_backbuf))) { mp_msg(MSGT_VO, MSGL_ERR, "<vo_direct3d>Back Buffer address get failed\n"); @@ -279,7 +288,8 @@ static int create_d3d_surfaces(void) vo_dwidth, vo_dheight, priv->osd_texture_width, priv->osd_texture_height); /* create OSD */ - if (FAILED(IDirect3DDevice9_CreateTexture(priv->d3d_device, + if (!priv->d3d_texture_system && + FAILED(IDirect3DDevice9_CreateTexture(priv->d3d_device, priv->osd_texture_width, priv->osd_texture_height, 1, @@ -295,7 +305,8 @@ static int create_d3d_surfaces(void) if (!priv->device_texture_sys) { /* only create if we need a shadow version on the external device */ - if (FAILED(IDirect3DDevice9_CreateTexture(priv->d3d_device, + if (!priv->d3d_texture_osd && + FAILED(IDirect3DDevice9_CreateTexture(priv->d3d_device, priv->osd_texture_width, priv->osd_texture_height, 1, @@ -332,27 +343,78 @@ static void fill_d3d_presentparams(D3DPRESENT_PARAMETERS *present_params) present_params->SwapEffect = D3DSWAPEFFECT_COPY; present_params->Flags = D3DPRESENTFLAG_VIDEO; present_params->hDeviceWindow = vo_w32_window; /* w32_common var */ - present_params->BackBufferWidth = 0; /* Fill up window Width */ - present_params->BackBufferHeight = 0; /* Fill up window Height */ + present_params->BackBufferWidth = priv->cur_backbuf_width; + present_params->BackBufferHeight = priv->cur_backbuf_height; present_params->MultiSampleType = D3DMULTISAMPLE_NONE; - /* D3DPRESENT_INTERVAL_ONE = vsync */ present_params->PresentationInterval = D3DPRESENT_INTERVAL_ONE; present_params->BackBufferFormat = priv->desktop_fmt; present_params->BackBufferCount = 1; present_params->EnableAutoDepthStencil = FALSE; } + +/** @brief Create a new backbuffer. Create or Reset the D3D + * device. + * @return 1 on success, 0 on failure + */ +static int change_d3d_backbuffer(back_buffer_action_e action) +{ + D3DPRESENT_PARAMETERS present_params; + + destroy_d3d_surfaces(); + + /* Grow the backbuffer in the required dimension. */ + if (vo_dwidth > priv->cur_backbuf_width) + priv->cur_backbuf_width = vo_dwidth; + + if (vo_dheight > priv->cur_backbuf_height) + priv->cur_backbuf_height = vo_dheight; + + /* The grown backbuffer dimensions are ready and fill_d3d_presentparams + * will use them, so we can reset the device. + */ + fill_d3d_presentparams(&present_params); + + /* vo_w32_window is w32_common variable. It's a handle to the window. */ + if (action == BACKBUFFER_CREATE && + FAILED(IDirect3D9_CreateDevice(priv->d3d_handle, + D3DADAPTER_DEFAULT, + D3DDEVTYPE_HAL, vo_w32_window, + D3DCREATE_SOFTWARE_VERTEXPROCESSING, + &present_params, &priv->d3d_device))) { + mp_msg(MSGT_VO, MSGL_ERR, + "<vo_direct3d><INFO>Could not create the D3D device\n"); + return 0; + } + + if (action == BACKBUFFER_RESET && + FAILED(IDirect3DDevice9_Reset(priv->d3d_device, &present_params))) { + mp_msg(MSGT_VO, MSGL_ERR, + "<vo_direct3d><INFO>Could not reset the D3D device\n"); + return 0; + } + + mp_msg(MSGT_VO, MSGL_V, + "<vo_direct3d><INFO>New backbuffer: Width: %d, Height:%d. VO Dest Width:%d, Height: %d\n", + present_params.BackBufferWidth, present_params.BackBufferHeight, + vo_dwidth, vo_dheight); + + return 1; +} + /** @brief Configure initial Direct3D context. The first * function called to initialize the D3D context. * @return 1 on success, 0 on failure */ static int configure_d3d(void) { - D3DPRESENT_PARAMETERS present_params; D3DDISPLAYMODE disp_mode; + D3DVIEWPORT9 vp = {0, 0, vo_dwidth, vo_dheight, 0, 1}; mp_msg(MSGT_VO, MSGL_V, "<vo_direct3d><INFO>configure_d3d called\n"); + destroy_d3d_surfaces(); + /* Get the current desktop display mode, so we can set up a back buffer * of the same format. */ if (FAILED(IDirect3D9_GetAdapterDisplayMode(priv->d3d_handle, @@ -366,26 +428,17 @@ static int configure_d3d(void) /* Write current Desktop's colorspace format in the global storage. */ priv->desktop_fmt = disp_mode.Format; - fill_d3d_presentparams(&present_params); - - /* vo_w32_window is w32_common variable. It's a handle to the window. */ - if (FAILED(IDirect3D9_CreateDevice(priv->d3d_handle, - D3DADAPTER_DEFAULT, - D3DDEVTYPE_HAL, vo_w32_window, - D3DCREATE_SOFTWARE_VERTEXPROCESSING, - &present_params, &priv->d3d_device))) { - mp_msg(MSGT_VO, MSGL_ERR, - "<vo_direct3d><INFO>Could not create the D3D device\n"); + if (!change_d3d_backbuffer(BACKBUFFER_CREATE)) return 0; - } if (!create_d3d_surfaces()) return 0; - mp_msg(MSGT_VO, MSGL_V, - "New BackBuffer: Width: %d, Height:%d. VO Dest Width:%d, Height: %d\n", - present_params.BackBufferWidth, present_params.BackBufferHeight, - vo_dwidth, vo_dheight); + if (FAILED(IDirect3DDevice9_SetViewport(priv->d3d_device, + &vp))) { + mp_msg(MSGT_VO, MSGL_ERR, "<vo_direct3d>Unable to set the viewport\n"); + return VO_ERROR; + } calc_fs_rect(); @@ -400,7 +453,7 @@ static int reconfigure_d3d(void) { mp_msg(MSGT_VO, MSGL_V, "<vo_direct3d><INFO>reconfigure_d3d called.\n"); - /* Destroy the Offscreen and Backbuffer surfaces */ + /* Destroy the offscreen, OSD and backbuffer surfaces */ destroy_d3d_surfaces(); /* Destroy the D3D Device */ @@ -425,35 +478,49 @@ static int reconfigure_d3d(void) return 1; } - /** @brief Resize Direct3D context on window resize. * @return 1 on success, 0 on failure */ static int resize_d3d(void) { - D3DPRESENT_PARAMETERS present_params; + D3DVIEWPORT9 vp = {0, 0, vo_dwidth, vo_dheight, 0, 1}; mp_msg(MSGT_VO, MSGL_V, "<vo_direct3d><INFO>resize_d3d called.\n"); - destroy_d3d_surfaces(); + /* Make sure that backbuffer is large enough to accomodate the new + viewport dimensions. Grow it if necessary. */ - /* Reset the D3D Device with all parameters the same except the new - * width/height. - */ - fill_d3d_presentparams(&present_params); - if (FAILED(IDirect3DDevice9_Reset(priv->d3d_device, &present_params))) { - mp_msg(MSGT_VO, MSGL_ERR, - "<vo_direct3d><INFO>Could not reset the D3D device\n"); - return 0; + if (vo_dwidth > priv->cur_backbuf_width || + vo_dheight > priv->cur_backbuf_height) { + change_d3d_backbuffer (BACKBUFFER_RESET); } + /* Destroy the OSD textures. They should always match the new dimensions + * of the onscreen window, so on each resize we need new OSD dimensions. + */ + + if (priv->d3d_texture_osd) + IDirect3DTexture9_Release(priv->d3d_texture_osd); + priv->d3d_texture_osd = NULL; + + if (priv->d3d_texture_system) + IDirect3DTexture9_Release(priv->d3d_texture_system); + priv->d3d_texture_system = NULL; + + + /* Recreate the OSD. The function will observe that the offscreen plain + * surface and the backbuffer are not destroyed and will skip their creation, + * effectively recreating only the OSD. + */ + if (!create_d3d_surfaces()) return 0; - mp_msg(MSGT_VO, MSGL_V, - "New BackBuffer: Width: %d, Height:%d. VO Dest Width:%d, Height: %d\n", - present_params.BackBufferWidth, present_params.BackBufferHeight, - vo_dwidth, vo_dheight); + if (FAILED(IDirect3DDevice9_SetViewport(priv->d3d_device, + &vp))) { + mp_msg(MSGT_VO, MSGL_ERR, "<vo_direct3d>Unable to set the viewport\n"); + return VO_ERROR; + } calc_fs_rect(); @@ -644,8 +711,10 @@ static int preinit(const char *arg) /* Store in priv->desktop_fmt the user desktop's colorspace. Usually XRGB. */ priv->desktop_fmt = disp_mode.Format; + priv->cur_backbuf_width = disp_mode.Width; + priv->cur_backbuf_height = disp_mode.Height; - mp_msg(MSGT_VO, MSGL_V, "disp_mode.Width %d, disp_mode.Height %d\n", + mp_msg(MSGT_VO, MSGL_V, "Setting backbuffer to the screen width: %d, height: %d\n", disp_mode.Width, disp_mode.Height); if (FAILED(IDirect3D9_GetDeviceCaps(priv->d3d_handle, @@ -787,7 +856,8 @@ static int config(uint32_t width, uint32_t height, uint32_t d_width, */ static void flip_page(void) { - if (FAILED(IDirect3DDevice9_Present(priv->d3d_device, 0, 0, 0, 0))) { + RECT rect = {0, 0, vo_dwidth, vo_dheight}; + if (FAILED(IDirect3DDevice9_Present(priv->d3d_device, &rect, 0, 0, 0))) { mp_msg(MSGT_VO, MSGL_V, "<vo_direct3d>Video adapter became uncooperative.\n"); mp_msg(MSGT_VO, MSGL_ERR, "<vo_direct3d>Trying to reinitialize it...\n"); @@ -795,7 +865,7 @@ static void flip_page(void) mp_msg(MSGT_VO, MSGL_V, "<vo_direct3d>Reinitialization Failed.\n"); return; } - if (FAILED(IDirect3DDevice9_Present(priv->d3d_device, 0, 0, 0, 0))) { + if (FAILED(IDirect3DDevice9_Present(priv->d3d_device, &rect, 0, 0, 0))) { mp_msg(MSGT_VO, MSGL_V, "<vo_direct3d>Reinitialization Failed.\n"); return; } |