Index: libvo/vo_directx.c =================================================================== --- libvo/vo_directx.c (版本 24868) +++ libvo/vo_directx.c (工作副本) @@ -19,6 +19,7 @@ *****************************************************************************/ #include +#include #include #include #include @@ -62,6 +63,8 @@ static RECT rs; //rect of our source image static HWND hWnd=NULL; //handle to the window static HWND hWndFS=NULL; //fullscreen window +static HANDLE hThread; +static HANDLE hInitEvent; static HBRUSH colorbrush = NULL; // Handle to colorkey brush static HBRUSH blackbrush = NULL; // Handle to black brush static HICON mplayericon = NULL; // Handle to mplayer icon @@ -86,6 +89,7 @@ static float window_aspect; static BOOL (WINAPI* myGetMonitorInfo)(HMONITOR, LPMONITORINFO) = NULL; static RECT last_rect = {0xDEADC0DE, 0xDEADC0DE, 0xDEADC0DE, 0xDEADC0DE}; +static volatile int init_failed; extern void vo_draw_text(int dxs,int dys,void (*draw_alpha)(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride)); extern int vidmode; @@ -329,7 +333,7 @@ return 0; } -static void uninit(void) +static void cleanup(void) { if (g_cc != NULL) { @@ -378,6 +382,13 @@ mp_msg(MSGT_VO, MSGL_DBG3,"uninited\n"); } +static void uninit(void) +{ + PostMessage(hWnd, WM_ENDSESSION, TRUE, 0); + WaitForSingleObject(hThread, INFINITE); + CloseHandle(hThread); +} + static BOOL WINAPI EnumCallbackEx(GUID FAR *lpGUID, LPSTR lpDriverDescription, LPSTR lpDriverName, LPVOID lpContext, HMONITOR hm) { mp_msg(MSGT_VO, MSGL_INFO ," adapter %d: ", adapter_count); @@ -523,12 +534,6 @@ static void check_events(void) { - MSG msg; - while (PeekMessage(&msg, NULL, 0, 0,PM_REMOVE)) - { - TranslateMessage(&msg); - DispatchMessage(&msg); - } } static uint32_t Directx_ManageDisplay() @@ -913,6 +918,12 @@ mplayer_put_key(KEY_CLOSE_WIN); return 0; } + case WM_ENDSESSION: + { + if (wParam) + cleanup(); + break; + } case WM_WINDOWPOSCHANGED: { //printf("Windowposchange\n"); @@ -1050,20 +1061,11 @@ return DefWindowProc(hWnd, message, wParam, lParam); } - -static int preinit(const char *arg) +static int init_window(void) { HINSTANCE hInstance = GetModuleHandle(NULL); char exedir[MAX_PATH]; WNDCLASS wc; - if(arg) - { - if(strstr(arg,"noaccel")) - { - mp_msg(MSGT_VO,MSGL_V,"disabled overlay\n"); - nooverlay = 1; - } - } /*load icon from the main app*/ if(GetModuleFileName(NULL,exedir,MAX_PATH)) { @@ -1113,6 +1115,54 @@ mp_msg(MSGT_VO, MSGL_V ,"using backpuffer\n"); nooverlay = 1; } + SetActiveWindow(hWnd); + return 0; +} + +static unsigned __stdcall thread(void* param) +{ + MSG msg; + init_failed = init_window(); + SetEvent(hInitEvent); + if (init_failed) + return 0; + while (GetMessage(&msg, NULL, 0, 0)) { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + return 0; +} + +static int preinit(const char *arg) +{ + unsigned id; + if(arg) + { + if(strstr(arg,"noaccel")) + { + mp_msg(MSGT_VO,MSGL_V,"disabled overlay\n"); + nooverlay = 1; + } + } + + hInitEvent = CreateEvent(NULL, FALSE, FALSE, NULL); + if (!hInitEvent) { + mp_msg(MSGT_VO, MSGL_ERR, "can't create event.\n"); + return 1; + } + hThread = (HANDLE)_beginthreadex(NULL, 0, thread, NULL, 0, &id); + if (!hThread) { + mp_msg(MSGT_VO, MSGL_ERR, "can't create thread.\n"); + CloseHandle(hInitEvent); + return 1; + } + WaitForSingleObject(hInitEvent, INFINITE); + CloseHandle(hInitEvent); + if (init_failed) { + WaitForSingleObject(hThread, INFINITE); + CloseHandle(hThread); + return 1; + } mp_msg(MSGT_VO, MSGL_DBG3 ,"preinit succesfully finished\n"); return 0; }