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;
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;
}

View File

@ -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

View File

@ -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");

View File

@ -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)
{

View File

@ -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, &not_inited);
g_inited = false;
g_major = g_minor = 0;
p_swap_interval = NULL;
}