diff --git a/gfx/common/win32_common.cpp b/gfx/common/win32_common.cpp index 153d0cc0f6..03fc815257 100644 --- a/gfx/common/win32_common.cpp +++ b/gfx/common/win32_common.cpp @@ -50,7 +50,7 @@ static unsigned g_pos_y = CW_USEDEFAULT; static bool g_resized; bool g_inited; bool g_quit; -static HWND g_hwnd; +HWND g_hwnd; extern void *dinput_wgl; extern void *curD3D; @@ -678,46 +678,10 @@ static HANDLE GetFocus(void) } #endif -uintptr_t win32_get_handle(void) -{ - return (uintptr_t)GetFocus(); -} - bool win32_has_focus(void) { if (!g_inited) return false; - return win32_get_handle() == g_hwnd; -} - -#ifdef _XBOX -/* stub */ -BOOL SetWindowText(HWND hWnd, LPCTSTR lpString) -{ - return TRUE; -} - -BOOL IsIconic(HWND hWnd) -{ - return FALSE; -} -#endif - -void win32_state_set(bool *quit, bool *restore_desktop, bool *inited) -{ - if (*quit) - g_quit = *quit; - if (*restore_desktop) - g_restore_desktop = *restore_desktop; - if (*inited) - g_inited = *inited; -} - -void win32_destroy(void) -{ -#ifndef _XBOX - UnregisterClass("RetroArch", GetModuleHandle(NULL)); -#endif - g_hwnd = NULL; + return GetFocus() == g_hwnd; } diff --git a/gfx/common/win32_common.h b/gfx/common/win32_common.h index d6b4b2868f..2c2533baa1 100644 --- a/gfx/common/win32_common.h +++ b/gfx/common/win32_common.h @@ -36,6 +36,7 @@ extern unsigned g_resize_height; extern bool g_quit; extern bool g_inited; extern bool g_restore_desktop; +extern HWND g_hwnd; LRESULT win32_handle_keyboard_event(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam); @@ -79,16 +80,4 @@ bool win32_has_focus(void); void win32_check_window(bool *quit, bool *resize, unsigned *width, unsigned *height); -#ifdef _XBOX -BOOL SetWindowText(HWND hWnd, LPCTSTR lpString); - -BOOL IsIconic(HWND hWnd); -#endif - -void win32_state_set(bool *quit, bool *restore_desktop, bool *inited); - -uintptr_t win32_get_handle(void); - -void win32_destroy(void); - #endif diff --git a/gfx/d3d/d3d.cpp b/gfx/d3d/d3d.cpp index a0f80bc31d..9712a9e36a 100644 --- a/gfx/d3d/d3d.cpp +++ b/gfx/d3d/d3d.cpp @@ -161,7 +161,7 @@ void d3d_make_d3dpp(void *data, #endif info->rgb32 ? D3DFMT_X8R8G8B8 : D3DFMT_LIN_R5G6B5; #else - d3dpp->hDeviceWindow = (HWND)win32_get_handle(); + d3dpp->hDeviceWindow = g_hwnd; d3dpp->BackBufferFormat = !d3dpp->Windowed ? D3DFMT_X8R8G8B8 : D3DFMT_UNKNOWN; #endif @@ -230,7 +230,6 @@ static bool d3d_init_base(void *data, const video_info_t *info) { D3DPRESENT_PARAMETERS d3dpp; d3d_video_t *d3d = (d3d_video_t*)data; - HWND handle = (HWND)win32_get_handle(); d3d_make_d3dpp(d3d, info, &d3dpp); @@ -248,7 +247,7 @@ static bool d3d_init_base(void *data, const video_info_t *info) if (FAILED(d3d->d3d_err = d3d->g_pD3D->CreateDevice( d3d->cur_mon_id, D3DDEVTYPE_HAL, - handle, + g_hwnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, &d3dpp, &d3d->dev))) @@ -259,7 +258,7 @@ static bool d3d_init_base(void *data, const video_info_t *info) if (FAILED(d3d->d3d_err = d3d->g_pD3D->CreateDevice( d3d->cur_mon_id, D3DDEVTYPE_HAL, - handle, + g_hwnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &d3d->dev))) @@ -648,22 +647,20 @@ static bool d3d_construct(d3d_video_t *d3d, if (!info->fullscreen || windowed_full) { - HWND handle = (HWND)win32_get_handle(); - if (!info->fullscreen && settings->ui.menubar_enable) { RECT rc_temp = {0, 0, (LONG)win_height, 0x7FFF}; - SetMenu(handle, LoadMenu(GetModuleHandle(NULL),MAKEINTRESOURCE(IDR_MENU))); - SendMessage(handle, WM_NCCALCSIZE, FALSE, (LPARAM)&rc_temp); + SetMenu(g_hwnd, LoadMenu(GetModuleHandle(NULL),MAKEINTRESOURCE(IDR_MENU))); + SendMessage(g_hwnd, WM_NCCALCSIZE, FALSE, (LPARAM)&rc_temp); g_resize_height = win_height += rc_temp.top + rect.top; - SetWindowPos(handle, NULL, 0, 0, win_width, win_height, SWP_NOMOVE); + SetWindowPos(g_hwnd, NULL, 0, 0, win_width, win_height, SWP_NOMOVE); } - ShowWindow(handle, SW_RESTORE); - UpdateWindow(handle); - SetForegroundWindow(handle); - SetFocus(handle); + ShowWindow(g_hwnd, SW_RESTORE); + UpdateWindow(g_hwnd); + SetForegroundWindow(g_hwnd); + SetFocus(g_hwnd); } #endif @@ -822,8 +819,7 @@ error: static void d3d_free(void *data) { - d3d_video_t *d3d = (d3d_video_t*)data; - HWND handle = (HWND)win32_get_handle(); + d3d_video_t *d3d = (d3d_video_t*)data; if (!d3d) return; @@ -848,13 +844,15 @@ static void d3d_free(void *data) d3d->g_pD3D->Release(); #ifdef HAVE_MONITOR - win32_monitor_from_window(handle, true); + win32_monitor_from_window(g_hwnd, true); #endif if (d3d) delete d3d; - win32_destroy(); +#ifndef _XBOX + UnregisterClass("RetroArch", GetModuleHandle(NULL)); +#endif } #ifndef DONT_HAVE_STATE_TRACKER @@ -1471,7 +1469,6 @@ static bool d3d_frame(void *data, const void *frame, driver_t *driver = driver_get_ptr(); settings_t *settings = config_get_ptr(); const font_renderer_t *font_ctx = driver->font_osd_driver; - HWND handle = (HWND)win32_get_handle(); (void)i; @@ -1483,10 +1480,11 @@ static bool d3d_frame(void *data, const void *frame, rarch_perf_init(&d3d_frame, "d3d_frame"); retro_perf_start(&d3d_frame); +#ifndef _XBOX /* We cannot recover in fullscreen. */ - if (d3d->needs_restore && IsIconic(handle)) + if (d3d->needs_restore && IsIconic(g_hwnd)) return true; - +#endif if (d3d->needs_restore && !d3d_restore(d3d)) { RARCH_ERR("[D3D]: Failed to restore.\n"); diff --git a/gfx/drivers_context/d3d_ctx.cpp b/gfx/drivers_context/d3d_ctx.cpp index 49cf7f2493..bb0bb44c3e 100644 --- a/gfx/drivers_context/d3d_ctx.cpp +++ b/gfx/drivers_context/d3d_ctx.cpp @@ -84,13 +84,16 @@ static void gfx_ctx_d3d_update_title(void *data) char buf[128] = {0}; char buffer_fps[128] = {0}; settings_t *settings = config_get_ptr(); - HWND handle = (HWND)win32_get_handle(); - - (void)handle; if (video_monitor_get_fps(buf, sizeof(buf), buffer_fps, sizeof(buffer_fps))) - SetWindowText(handle, buf); + { +#ifndef _XBOX + d3d_video_t *d3d = (d3d_video_t*)data; + + SetWindowText(g_hwnd, buf); +#endif + } if (settings->fps_show) { diff --git a/gfx/drivers_context/wgl_ctx.cpp b/gfx/drivers_context/wgl_ctx.cpp index 3df17a715c..0e397fd5c3 100644 --- a/gfx/drivers_context/wgl_ctx.cpp +++ b/gfx/drivers_context/wgl_ctx.cpp @@ -103,7 +103,6 @@ static void setup_pixel_format(HDC hdc) void create_gl_context(HWND hwnd) { bool core_context; - bool about_to_quit = true; const struct retro_hw_render_callback *hw_render = (const struct retro_hw_render_callback*)video_driver_callback(); driver_t *driver = driver_get_ptr(); @@ -139,27 +138,24 @@ void create_gl_context(HWND hwnd) if (!wglShareLists(g_hrc, g_hw_hrc)) { RARCH_LOG("[WGL]: Failed to share contexts.\n"); - win32_state_set(&about_to_quit, NULL, NULL); + g_quit = true; } } else - win32_state_set(&about_to_quit, NULL, NULL); + g_quit = true; } } if (g_hrc) { if (wglMakeCurrent(g_hdc, g_hrc)) - { - bool inited = true; - win32_state_set(NULL, NULL, &inited); - } + g_inited = true; else - win32_state_set(&about_to_quit, NULL, NULL); + g_quit = true; } else { - win32_state_set(&about_to_quit, NULL, NULL); + g_quit = true; return; } @@ -208,7 +204,7 @@ void create_gl_context(HWND hwnd) wglDeleteContext(g_hrc); g_hrc = context; if (!wglMakeCurrent(g_hdc, g_hrc)) - win32_state_set(&about_to_quit, NULL, NULL); + g_quit = true; } else RARCH_ERR("[WGL]: Failed to create core context. Falling back to legacy context.\n"); @@ -219,7 +215,7 @@ void create_gl_context(HWND hwnd) if (!g_hw_hrc) { RARCH_ERR("[WGL]: Failed to create shared context.\n"); - win32_state_set(&about_to_quit, NULL, NULL); + g_quit = true; } } } @@ -270,13 +266,12 @@ static void gfx_ctx_wgl_update_window_title(void *data) char buf[128] = {0}; char buf_fps[128] = {0}; settings_t *settings = config_get_ptr(); - HWND handle = (HWND)win32_get_handle(); (void)data; if (video_monitor_get_fps(buf, sizeof(buf), buf_fps, sizeof(buf_fps))) - SetWindowText(handle, buf); + SetWindowText(g_hwnd, buf); if (settings->fps_show) rarch_main_msg_queue_push(buf_fps, 1, 1, false); } @@ -284,9 +279,8 @@ static void gfx_ctx_wgl_update_window_title(void *data) static void gfx_ctx_wgl_get_video_size(void *data, unsigned *width, unsigned *height) { (void)data; - HWND handle = (HWND)win32_get_handle(); - if (!handle) + if (!g_hwnd) { unsigned mon_id; RECT mon_rect; @@ -307,8 +301,6 @@ static void gfx_ctx_wgl_get_video_size(void *data, unsigned *width, unsigned *he static bool gfx_ctx_wgl_init(void *data) { - bool about_to_quit = false; - bool restore_desktop = false; WNDCLASSEX wndclass = {0}; (void)data; @@ -316,7 +308,8 @@ static bool gfx_ctx_wgl_init(void *data) if (g_inited) return false; - win32_state_set(&about_to_quit, &restore_desktop, NULL); + g_quit = false; + g_restore_desktop = false; win32_monitor_init(); if (!win32_window_init(&wndclass, true)) @@ -348,9 +341,7 @@ error: static void gfx_ctx_wgl_destroy(void *data) { - bool not_inited = false; driver_t *driver = driver_get_ptr(); - HWND handle = (HWND)win32_get_handle(); (void)data; @@ -369,26 +360,26 @@ static void gfx_ctx_wgl_destroy(void *data) } } - if (handle && g_hdc) + if (g_hwnd && g_hdc) { - ReleaseDC(handle, g_hdc); + ReleaseDC(g_hwnd, g_hdc); g_hdc = NULL; } - if (handle) + if (g_hwnd) { - win32_monitor_from_window(handle, true); - win32_destroy(); + win32_monitor_from_window(g_hwnd, true); + UnregisterClass("RetroArch", GetModuleHandle(NULL)); + g_hwnd = NULL; } if (g_restore_desktop) { - bool restore_desktop = false; win32_monitor_get_info(); - win32_state_set(NULL, &restore_desktop, NULL); + g_restore_desktop = false; } - win32_state_set(NULL, NULL, ¬_inited); + g_inited = false; g_major = g_minor = 0; p_swap_interval = NULL; }