Revert "(win32_common) No longer expose global variables to outside"

This reverts commit 33884de94c557f7e6de875c009ad6c56314d824b.
This commit is contained in:
twinaphex 2015-11-17 09:33:27 +01:00
parent 33884de94c
commit f9e4ec72c4
5 changed files with 47 additions and 102 deletions

View File

@ -50,7 +50,7 @@ static unsigned g_pos_y = CW_USEDEFAULT;
static bool g_resized; static bool g_resized;
bool g_inited; bool g_inited;
bool g_quit; bool g_quit;
static HWND g_hwnd; HWND g_hwnd;
extern void *dinput_wgl; extern void *dinput_wgl;
extern void *curD3D; extern void *curD3D;
@ -678,46 +678,10 @@ static HANDLE GetFocus(void)
} }
#endif #endif
uintptr_t win32_get_handle(void)
{
return (uintptr_t)GetFocus();
}
bool win32_has_focus(void) bool win32_has_focus(void)
{ {
if (!g_inited) if (!g_inited)
return false; return false;
return win32_get_handle() == g_hwnd; return GetFocus() == 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;
} }

View File

@ -36,6 +36,7 @@ extern unsigned g_resize_height;
extern bool g_quit; extern bool g_quit;
extern bool g_inited; extern bool g_inited;
extern bool g_restore_desktop; extern bool g_restore_desktop;
extern HWND g_hwnd;
LRESULT win32_handle_keyboard_event(HWND hwnd, UINT message, LRESULT win32_handle_keyboard_event(HWND hwnd, UINT message,
WPARAM wparam, LPARAM lparam); WPARAM wparam, LPARAM lparam);
@ -79,16 +80,4 @@ bool win32_has_focus(void);
void win32_check_window(bool *quit, void win32_check_window(bool *quit,
bool *resize, unsigned *width, unsigned *height); 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 #endif

View File

@ -161,7 +161,7 @@ void d3d_make_d3dpp(void *data,
#endif #endif
info->rgb32 ? D3DFMT_X8R8G8B8 : D3DFMT_LIN_R5G6B5; info->rgb32 ? D3DFMT_X8R8G8B8 : D3DFMT_LIN_R5G6B5;
#else #else
d3dpp->hDeviceWindow = (HWND)win32_get_handle(); d3dpp->hDeviceWindow = g_hwnd;
d3dpp->BackBufferFormat = !d3dpp->Windowed ? D3DFMT_X8R8G8B8 : D3DFMT_UNKNOWN; d3dpp->BackBufferFormat = !d3dpp->Windowed ? D3DFMT_X8R8G8B8 : D3DFMT_UNKNOWN;
#endif #endif
@ -230,7 +230,6 @@ static bool d3d_init_base(void *data, const video_info_t *info)
{ {
D3DPRESENT_PARAMETERS d3dpp; D3DPRESENT_PARAMETERS d3dpp;
d3d_video_t *d3d = (d3d_video_t*)data; d3d_video_t *d3d = (d3d_video_t*)data;
HWND handle = (HWND)win32_get_handle();
d3d_make_d3dpp(d3d, info, &d3dpp); 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( if (FAILED(d3d->d3d_err = d3d->g_pD3D->CreateDevice(
d3d->cur_mon_id, d3d->cur_mon_id,
D3DDEVTYPE_HAL, D3DDEVTYPE_HAL,
handle, g_hwnd,
D3DCREATE_HARDWARE_VERTEXPROCESSING, D3DCREATE_HARDWARE_VERTEXPROCESSING,
&d3dpp, &d3dpp,
&d3d->dev))) &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( if (FAILED(d3d->d3d_err = d3d->g_pD3D->CreateDevice(
d3d->cur_mon_id, d3d->cur_mon_id,
D3DDEVTYPE_HAL, D3DDEVTYPE_HAL,
handle, g_hwnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING, D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp, &d3dpp,
&d3d->dev))) &d3d->dev)))
@ -648,22 +647,20 @@ static bool d3d_construct(d3d_video_t *d3d,
if (!info->fullscreen || windowed_full) if (!info->fullscreen || windowed_full)
{ {
HWND handle = (HWND)win32_get_handle();
if (!info->fullscreen && settings->ui.menubar_enable) if (!info->fullscreen && settings->ui.menubar_enable)
{ {
RECT rc_temp = {0, 0, (LONG)win_height, 0x7FFF}; RECT rc_temp = {0, 0, (LONG)win_height, 0x7FFF};
SetMenu(handle, LoadMenu(GetModuleHandle(NULL),MAKEINTRESOURCE(IDR_MENU))); SetMenu(g_hwnd, LoadMenu(GetModuleHandle(NULL),MAKEINTRESOURCE(IDR_MENU)));
SendMessage(handle, WM_NCCALCSIZE, FALSE, (LPARAM)&rc_temp); SendMessage(g_hwnd, WM_NCCALCSIZE, FALSE, (LPARAM)&rc_temp);
g_resize_height = win_height += rc_temp.top + rect.top; 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); ShowWindow(g_hwnd, SW_RESTORE);
UpdateWindow(handle); UpdateWindow(g_hwnd);
SetForegroundWindow(handle); SetForegroundWindow(g_hwnd);
SetFocus(handle); SetFocus(g_hwnd);
} }
#endif #endif
@ -822,8 +819,7 @@ error:
static void d3d_free(void *data) static void d3d_free(void *data)
{ {
d3d_video_t *d3d = (d3d_video_t*)data; d3d_video_t *d3d = (d3d_video_t*)data;
HWND handle = (HWND)win32_get_handle();
if (!d3d) if (!d3d)
return; return;
@ -848,13 +844,15 @@ static void d3d_free(void *data)
d3d->g_pD3D->Release(); d3d->g_pD3D->Release();
#ifdef HAVE_MONITOR #ifdef HAVE_MONITOR
win32_monitor_from_window(handle, true); win32_monitor_from_window(g_hwnd, true);
#endif #endif
if (d3d) if (d3d)
delete d3d; delete d3d;
win32_destroy(); #ifndef _XBOX
UnregisterClass("RetroArch", GetModuleHandle(NULL));
#endif
} }
#ifndef DONT_HAVE_STATE_TRACKER #ifndef DONT_HAVE_STATE_TRACKER
@ -1471,7 +1469,6 @@ static bool d3d_frame(void *data, const void *frame,
driver_t *driver = driver_get_ptr(); driver_t *driver = driver_get_ptr();
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
const font_renderer_t *font_ctx = driver->font_osd_driver; const font_renderer_t *font_ctx = driver->font_osd_driver;
HWND handle = (HWND)win32_get_handle();
(void)i; (void)i;
@ -1483,10 +1480,11 @@ static bool d3d_frame(void *data, const void *frame,
rarch_perf_init(&d3d_frame, "d3d_frame"); rarch_perf_init(&d3d_frame, "d3d_frame");
retro_perf_start(&d3d_frame); retro_perf_start(&d3d_frame);
#ifndef _XBOX
/* We cannot recover in fullscreen. */ /* We cannot recover in fullscreen. */
if (d3d->needs_restore && IsIconic(handle)) if (d3d->needs_restore && IsIconic(g_hwnd))
return true; return true;
#endif
if (d3d->needs_restore && !d3d_restore(d3d)) if (d3d->needs_restore && !d3d_restore(d3d))
{ {
RARCH_ERR("[D3D]: Failed to restore.\n"); RARCH_ERR("[D3D]: Failed to restore.\n");

View File

@ -84,13 +84,16 @@ static void gfx_ctx_d3d_update_title(void *data)
char buf[128] = {0}; char buf[128] = {0};
char buffer_fps[128] = {0}; char buffer_fps[128] = {0};
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
HWND handle = (HWND)win32_get_handle();
(void)handle;
if (video_monitor_get_fps(buf, sizeof(buf), if (video_monitor_get_fps(buf, sizeof(buf),
buffer_fps, sizeof(buffer_fps))) 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) if (settings->fps_show)
{ {

View File

@ -103,7 +103,6 @@ static void setup_pixel_format(HDC hdc)
void create_gl_context(HWND hwnd) void create_gl_context(HWND hwnd)
{ {
bool core_context; bool core_context;
bool about_to_quit = true;
const struct retro_hw_render_callback *hw_render = const struct retro_hw_render_callback *hw_render =
(const struct retro_hw_render_callback*)video_driver_callback(); (const struct retro_hw_render_callback*)video_driver_callback();
driver_t *driver = driver_get_ptr(); driver_t *driver = driver_get_ptr();
@ -139,27 +138,24 @@ void create_gl_context(HWND hwnd)
if (!wglShareLists(g_hrc, g_hw_hrc)) if (!wglShareLists(g_hrc, g_hw_hrc))
{ {
RARCH_LOG("[WGL]: Failed to share contexts.\n"); RARCH_LOG("[WGL]: Failed to share contexts.\n");
win32_state_set(&about_to_quit, NULL, NULL); g_quit = true;
} }
} }
else else
win32_state_set(&about_to_quit, NULL, NULL); g_quit = true;
} }
} }
if (g_hrc) if (g_hrc)
{ {
if (wglMakeCurrent(g_hdc, g_hrc)) if (wglMakeCurrent(g_hdc, g_hrc))
{ g_inited = true;
bool inited = true;
win32_state_set(NULL, NULL, &inited);
}
else else
win32_state_set(&about_to_quit, NULL, NULL); g_quit = true;
} }
else else
{ {
win32_state_set(&about_to_quit, NULL, NULL); g_quit = true;
return; return;
} }
@ -208,7 +204,7 @@ void create_gl_context(HWND hwnd)
wglDeleteContext(g_hrc); wglDeleteContext(g_hrc);
g_hrc = context; g_hrc = context;
if (!wglMakeCurrent(g_hdc, g_hrc)) if (!wglMakeCurrent(g_hdc, g_hrc))
win32_state_set(&about_to_quit, NULL, NULL); g_quit = true;
} }
else else
RARCH_ERR("[WGL]: Failed to create core context. Falling back to legacy context.\n"); 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) if (!g_hw_hrc)
{ {
RARCH_ERR("[WGL]: Failed to create shared context.\n"); 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[128] = {0};
char buf_fps[128] = {0}; char buf_fps[128] = {0};
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
HWND handle = (HWND)win32_get_handle();
(void)data; (void)data;
if (video_monitor_get_fps(buf, sizeof(buf), if (video_monitor_get_fps(buf, sizeof(buf),
buf_fps, sizeof(buf_fps))) buf_fps, sizeof(buf_fps)))
SetWindowText(handle, buf); SetWindowText(g_hwnd, buf);
if (settings->fps_show) if (settings->fps_show)
rarch_main_msg_queue_push(buf_fps, 1, 1, false); 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) static void gfx_ctx_wgl_get_video_size(void *data, unsigned *width, unsigned *height)
{ {
(void)data; (void)data;
HWND handle = (HWND)win32_get_handle();
if (!handle) if (!g_hwnd)
{ {
unsigned mon_id; unsigned mon_id;
RECT mon_rect; 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) static bool gfx_ctx_wgl_init(void *data)
{ {
bool about_to_quit = false;
bool restore_desktop = false;
WNDCLASSEX wndclass = {0}; WNDCLASSEX wndclass = {0};
(void)data; (void)data;
@ -316,7 +308,8 @@ static bool gfx_ctx_wgl_init(void *data)
if (g_inited) if (g_inited)
return false; return false;
win32_state_set(&about_to_quit, &restore_desktop, NULL); g_quit = false;
g_restore_desktop = false;
win32_monitor_init(); win32_monitor_init();
if (!win32_window_init(&wndclass, true)) if (!win32_window_init(&wndclass, true))
@ -348,9 +341,7 @@ error:
static void gfx_ctx_wgl_destroy(void *data) static void gfx_ctx_wgl_destroy(void *data)
{ {
bool not_inited = false;
driver_t *driver = driver_get_ptr(); driver_t *driver = driver_get_ptr();
HWND handle = (HWND)win32_get_handle();
(void)data; (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; g_hdc = NULL;
} }
if (handle) if (g_hwnd)
{ {
win32_monitor_from_window(handle, true); win32_monitor_from_window(g_hwnd, true);
win32_destroy(); UnregisterClass("RetroArch", GetModuleHandle(NULL));
g_hwnd = NULL;
} }
if (g_restore_desktop) if (g_restore_desktop)
{ {
bool restore_desktop = false;
win32_monitor_get_info(); win32_monitor_get_info();
win32_state_set(NULL, &restore_desktop, NULL); g_restore_desktop = false;
} }
win32_state_set(NULL, NULL, &not_inited); g_inited = false;
g_major = g_minor = 0; g_major = g_minor = 0;
p_swap_interval = NULL; p_swap_interval = NULL;
} }