(D3D/GL) Try to use common code for both

This commit is contained in:
twinaphex 2015-11-11 19:41:32 +01:00
parent 8e08db3446
commit 938dfa775a
5 changed files with 58 additions and 135 deletions

View File

@ -93,6 +93,8 @@ void win32_monitor_init(void)
{
win32_monitor_count = 0;
EnumDisplayMonitors(NULL, NULL, win32_monitor_enum_proc, 0);
g_quit = false;
}
void win32_monitor_from_window(HWND data, bool destroy)
@ -149,10 +151,23 @@ void win32_monitor_info(void *data, void *hm_data, unsigned *mon_id)
GetMonitorInfo(*hm_to_use, (MONITORINFO*)mon);
}
static const char *win32_video_get_ident(void)
{
#ifdef HAVE_THREADS
settings_t *settings = config_get_ptr();
if (settings->video.threaded)
return rarch_threaded_video_get_ident();
#endif
return video_driver_get_ident();
}
static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
WPARAM wparam, LPARAM lparam)
{
settings_t *settings = config_get_ptr();
driver_t *driver = driver_get_ptr();
const char *video_driver = win32_video_get_ident();
switch (message)
{
@ -174,7 +189,13 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
return win32_handle_keyboard_event(hwnd, message, wparam, lparam);
case WM_CREATE:
if (!strcmp(video_driver, "gl"))
create_gl_context(hwnd);
else if (!strcmp(video_driver, "d3d"))
{
LPCREATESTRUCT p_cs = (LPCREATESTRUCT)lparam;
curD3D = (d3d_video_t*)p_cs->lpCreateParams;
}
return 0;
case WM_CLOSE:
@ -200,20 +221,26 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
case WM_COMMAND:
if (settings->ui.menubar_enable)
{
LRESULT ret = win32_menu_loop(g_hwnd, wparam);
HWND d3dr = g_hwnd;
if (!strcmp(video_driver, "d3d"))
{
d3d_video_t *d3d = (d3d_video_t*)driver->video_data;
d3dr = d3d->hWnd;
}
LRESULT ret = win32_menu_loop(d3dr, wparam);
(void)ret;
}
break;
}
if (dinput_handle_message(dinput_wgl, message, wparam, lparam))
if (dinput_handle_message((!strcmp(video_driver, "gl")) ? dinput_wgl : dinput, message, wparam, lparam))
return 0;
return DefWindowProc(hwnd, message, wparam, lparam);
}
bool win32_window_init(WNDCLASSEX *wndclass)
bool win32_window_init(WNDCLASSEX *wndclass, bool fullscreen)
{
wndclass->cbSize = sizeof(*wndclass);
wndclass->cbSize = sizeof(WNDCLASSEX);
wndclass->style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
wndclass->lpfnWndProc = WndProc;
wndclass->hInstance = GetModuleHandle(NULL);
@ -222,6 +249,8 @@ bool win32_window_init(WNDCLASSEX *wndclass)
wndclass->hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON));
wndclass->hIconSm = (HICON)LoadImage(GetModuleHandle(NULL),
MAKEINTRESOURCE(IDI_ICON), IMAGE_ICON, 16, 16, 0);
if (!fullscreen)
wndclass->hbrBackground = (HBRUSH)COLOR_WINDOW;
if (!RegisterClassEx(wndclass))
return false;
@ -425,7 +454,7 @@ void win32_show_cursor(bool state)
#endif
}
void win32_check_window(void)
void win32_check_window(bool *quit, unsigned *resize, unsigned *width, unsigned *height)
{
#ifndef _XBOX
MSG msg;
@ -436,6 +465,15 @@ void win32_check_window(void)
DispatchMessage(&msg);
}
#endif
*quit = g_quit;
if (g_resized)
{
*resize = true;
*width = g_resize_width;
*height = g_resize_height;
g_resized = false;
}
}
bool win32_suppress_screensaver(void *data, bool enable)

View File

@ -56,7 +56,7 @@ void win32_monitor_get_info(void);
void win32_monitor_info(void *data, void *hm_data, unsigned *mon_id);
bool win32_window_init(WNDCLASSEX *wndclass);
bool win32_window_init(WNDCLASSEX *wndclass, bool fullscreen);
void create_gl_context(HWND hwnd);
#endif
@ -68,7 +68,8 @@ bool win32_get_metrics(void *data,
void win32_show_cursor(bool state);
void win32_check_window(void);
void win32_check_window(bool *quit,
unsigned *resize, unsigned *width, unsigned *height);
#ifdef __cplusplus
}

View File

@ -88,14 +88,6 @@ static void d3d_free_overlays(d3d_video_t *d3d);
static void d3d_free_overlay(d3d_video_t *d3d, overlay_t *overlay);
#endif
#ifdef HAVE_WINDOW
#define IDI_ICON 1
extern LRESULT CALLBACK WindowProc(HWND hWnd, UINT message,
WPARAM wParam, LPARAM lParam);
#endif
static void d3d_deinit_chain(d3d_video_t *d3d)
{
d3d->renderchain_driver->chain_free(d3d->renderchain_data);
@ -604,20 +596,7 @@ static bool d3d_construct(d3d_video_t *d3d,
#if defined(HAVE_WINDOW) && !defined(_XBOX)
memset(&d3d->windowClass, 0, sizeof(d3d->windowClass));
d3d->windowClass.cbSize = sizeof(d3d->windowClass);
d3d->windowClass.style = CS_HREDRAW | CS_VREDRAW;
d3d->windowClass.lpfnWndProc = WindowProc;
d3d->windowClass.hInstance = NULL;
d3d->windowClass.hCursor = LoadCursor(NULL, IDC_ARROW);
d3d->windowClass.lpszClassName = "RetroArch";
d3d->windowClass.hIcon = LoadIcon(GetModuleHandle(NULL),
MAKEINTRESOURCE(IDI_ICON));
d3d->windowClass.hIconSm = (HICON)LoadImage(GetModuleHandle(NULL),
MAKEINTRESOURCE(IDI_ICON), IMAGE_ICON, 16, 16, 0);
if (!info->fullscreen)
d3d->windowClass.hbrBackground = (HBRUSH)COLOR_WINDOW;
RegisterClassEx(&d3d->windowClass);
win32_window_init(&d3d->windowClass, true);
#endif
#ifdef HAVE_MONITOR

View File

@ -46,11 +46,7 @@ static bool widescreen_mode = false;
#endif
static d3d_video_t *curD3D = NULL;
static bool d3d_quit = false;
static void *dinput;
static unsigned g_d3d_resize_width;
static unsigned g_d3d_resize_height;
static bool g_d3d_resized;
extern bool d3d_restore(d3d_video_t *data);
@ -75,69 +71,6 @@ static void d3d_resize(void *data, unsigned new_width, unsigned new_height)
}
}
#ifdef HAVE_WINDOW
LRESULT CALLBACK WindowProc(HWND hwnd, UINT message,
WPARAM wparam, LPARAM lparam)
{
driver_t *driver = driver_get_ptr();
settings_t *settings = config_get_ptr();
switch (message)
{
case WM_SYSCOMMAND:
/* Prevent screensavers, etc, while running. */
switch (wparam)
{
case SC_SCREENSAVE:
case SC_MONITORPOWER:
return 0;
}
break;
case WM_CHAR:
case WM_KEYDOWN:
case WM_KEYUP:
case WM_SYSKEYUP:
case WM_SYSKEYDOWN:
return win32_handle_keyboard_event(hwnd, message, wparam, lparam);
case WM_CREATE:
{
LPCREATESTRUCT p_cs = (LPCREATESTRUCT)lparam;
curD3D = (d3d_video_t*)p_cs->lpCreateParams;
}
break;
case WM_CLOSE:
case WM_DESTROY:
case WM_QUIT:
d3d_quit = true;
return 0;
case WM_SIZE:
/* Do not send resize message if we minimize. */
if (wparam != SIZE_MAXHIDE && wparam != SIZE_MINIMIZED)
{
g_d3d_resize_width = LOWORD(lparam);
g_d3d_resize_height = HIWORD(lparam);
g_d3d_resized = true;
}
return 0;
case WM_COMMAND:
if (settings->ui.menubar_enable)
{
d3d_video_t *d3d = (d3d_video_t*)driver->video_data;
HWND d3dr = d3d->hWnd;
LRESULT ret = win32_menu_loop(d3dr, wparam);
}
break;
}
if (dinput_handle_message(dinput, message, wparam, lparam))
return 0;
return DefWindowProc(hwnd, message, wparam, lparam);
}
#endif
static void gfx_ctx_d3d_swap_buffers(void *data)
{
d3d_video_t *d3d = (d3d_video_t*)data;
@ -188,20 +121,7 @@ static void gfx_ctx_d3d_check_window(void *data, bool *quit,
bool *resize, unsigned *width,
unsigned *height, unsigned frame_count)
{
win32_check_window();
(void)data;
(void)frame_count;
*quit = d3d_quit;
if (g_d3d_resized)
{
*resize = true;
*width = g_d3d_resize_width;
*height = g_d3d_resize_height;
g_d3d_resized = false;
}
win32_check_window(quit, resize, width, height);
}
#ifdef _XBOX
@ -257,8 +177,6 @@ static bool gfx_ctx_d3d_init(void *data)
{
(void)data;
d3d_quit = false;
#ifndef _XBOX
win32_monitor_init();
#endif

View File

@ -245,20 +245,7 @@ static void gfx_ctx_wgl_swap_interval(void *data, unsigned interval)
static void gfx_ctx_wgl_check_window(void *data, bool *quit,
bool *resize, unsigned *width, unsigned *height, unsigned frame_count)
{
win32_check_window();
(void)data;
(void)frame_count;
*quit = g_quit;
if (g_resized)
{
*resize = true;
*width = g_resize_width;
*height = g_resize_height;
g_resized = false;
}
win32_check_window(quit, resize, width, height);
}
static void gfx_ctx_wgl_swap_buffers(void *data)
@ -326,7 +313,7 @@ static bool gfx_ctx_wgl_init(void *data)
g_restore_desktop = false;
win32_monitor_init();
if (!win32_window_init(&wndclass))
if (!win32_window_init(&wndclass, true))
return false;
if (!wgl_shader_dlg_init())