diff --git a/gfx/d3d9/d3d.cpp b/gfx/d3d9/d3d.cpp index a40e1a2313..ac92db3ad6 100644 --- a/gfx/d3d9/d3d.cpp +++ b/gfx/d3d9/d3d.cpp @@ -26,8 +26,6 @@ #include "../../compat/posix_string.h" #include "../../performance.h" -static bool d3d_quit = false; - static void d3d_render_msg(void *data, const char *msg, void *userdata); #ifndef _XBOX @@ -102,49 +100,11 @@ static void d3d_deinitialize(void *data) d3d->needs_restore = false; } -static void d3d_resize(void *data, unsigned new_width, unsigned new_height); #ifdef HAVE_WINDOW -namespace Callback -{ - static D3DVideo *curD3D = NULL; - static void *dinput; - LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, - WPARAM wParam, LPARAM lParam) - { - switch (message) - { - case WM_CREATE: - LPCREATESTRUCT p_cs; - p_cs = (LPCREATESTRUCT)lParam; - curD3D = (D3DVideo*)p_cs->lpCreateParams; - 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_DESTROY: - d3d_quit = true; - return 0; - case WM_SIZE: - unsigned new_width, new_height; - new_width = LOWORD(lParam); - new_height = HIWORD(lParam); - - if (new_width && new_height) - d3d_resize(curD3D, new_width, new_height); - return 0; - } - if (dinput_handle_message(dinput, message, wParam, lParam)) - return 0; - return DefWindowProc(hWnd, message, wParam, lParam); - } -} +extern LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, + WPARAM wParam, LPARAM lParam); #endif static bool d3d_init_base(void *data, const video_info_t *info) @@ -262,7 +222,7 @@ static bool d3d_initialize(void *data, const video_info_t *info) return true; } -static bool d3d_restore(void *data) +bool d3d_restore(void *data) { D3DVideo *d3d = reinterpret_cast(data); d3d_deinitialize(d3d); @@ -274,22 +234,6 @@ static bool d3d_restore(void *data) return !d3d->needs_restore; } -static void d3d_resize(void *data, unsigned new_width, unsigned new_height) -{ - D3DVideo *d3d = reinterpret_cast(data); - if (!d3d->dev) - return; - - RARCH_LOG("[D3D]: Resize %ux%u.\n", new_width, new_height); - - if (new_width != d3d->video_info.width || new_height != d3d->video_info.height) - { - d3d->video_info.width = d3d->screen_width = new_width; - d3d->video_info.height = d3d->screen_height = new_height; - d3d_restore(d3d); - } -} - #ifdef HAVE_OVERLAY static void d3d_overlay_render(void *data, overlay_t &overlay) { @@ -573,12 +517,10 @@ static bool d3d_alive(void *data) d3d->ctx_driver->check_window(&quit, &resize, &d3d->screen_width, &d3d->screen_height, g_extern.frame_count); - if (quit) - d3d_quit = true; else if (resize) d3d->should_resize = true; - return !d3d_quit; + return !quit; } static bool d3d_focus(void *data) @@ -1017,7 +959,7 @@ static void d3d_get_poke_interface(void *data, const video_poke_interface_t **if } // Delay constructor due to lack of exceptions. -bool d3d_construct(void *data, const video_info_t *info, const input_driver_t **input, +static bool d3d_construct(void *data, const video_info_t *info, const input_driver_t **input, void **input_data) { D3DVideo *d3d = reinterpret_cast(data); @@ -1042,7 +984,7 @@ bool d3d_construct(void *data, const video_info_t *info, const input_driver_t ** memset(&d3d->windowClass, 0, sizeof(d3d->windowClass)); d3d->windowClass.cbSize = sizeof(d3d->windowClass); d3d->windowClass.style = CS_HREDRAW | CS_VREDRAW; - d3d->windowClass.lpfnWndProc = Callback::WindowProc; + d3d->windowClass.lpfnWndProc = WindowProc; d3d->windowClass.hInstance = NULL; d3d->windowClass.hCursor = LoadCursor(NULL, IDC_ARROW); d3d->windowClass.lpszClassName = "RetroArch"; @@ -1106,7 +1048,6 @@ bool d3d_construct(void *data, const video_info_t *info, const input_driver_t ** || d3d->overlays_enabled #endif ); - d3d_quit = false; ShowWindow(d3d->hWnd, SW_RESTORE); UpdateWindow(d3d->hWnd); @@ -1130,14 +1071,9 @@ bool d3d_construct(void *data, const video_info_t *info, const input_driver_t ** if (!d3d_initialize(d3d, &d3d->video_info)) return false; -#ifndef _XBOX - if (input && input_data) - { - Callback::dinput = input_dinput.init(); - *input = Callback::dinput ? &input_dinput : NULL; - *input_data = Callback::dinput; - } -#endif + if (input && input_data && + d3d->ctx_driver && d3d->ctx_driver->input_driver) + d3d->ctx_driver->input_driver(input, input_data); RARCH_LOG("[D3D]: Init complete.\n"); return true; diff --git a/gfx/d3d9/d3d9_pc.cpp b/gfx/d3d9/d3d9_pc.cpp index 5779d3d76e..831faa1824 100644 --- a/gfx/d3d9/d3d9_pc.cpp +++ b/gfx/d3d9/d3d9_pc.cpp @@ -29,6 +29,65 @@ #endif #endif +static D3DVideo *curD3D = NULL; +static bool d3d_quit = false; +static void *dinput; + +extern bool d3d_restore(void *data); + +static void d3d_resize(void *data, unsigned new_width, unsigned new_height) +{ + D3DVideo *d3d = reinterpret_cast(data); + if (!d3d->dev) + return; + + RARCH_LOG("[D3D]: Resize %ux%u.\n", new_width, new_height); + + if (new_width != d3d->video_info.width || new_height != d3d->video_info.height) + { + d3d->video_info.width = d3d->screen_width = new_width; + d3d->video_info.height = d3d->screen_height = new_height; + d3d_restore(d3d); + } +} + +#ifdef HAVE_WINDOW +LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, + WPARAM wParam, LPARAM lParam) +{ + switch (message) + { + case WM_CREATE: + LPCREATESTRUCT p_cs; + p_cs = (LPCREATESTRUCT)lParam; + curD3D = (D3DVideo*)p_cs->lpCreateParams; + 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_DESTROY: + d3d_quit = true; + return 0; + case WM_SIZE: + unsigned new_width, new_height; + new_width = LOWORD(lParam); + new_height = HIWORD(lParam); + + if (new_width && new_height) + d3d_resize(curD3D, new_width, new_height); + return 0; + } + if (dinput_handle_message(dinput, message, wParam, lParam)) + return 0; + return DefWindowProc(hWnd, message, wParam, lParam); +} +#endif + bool d3d_process_shader(void *data) { D3DVideo *d3d = reinterpret_cast(data); @@ -496,21 +555,28 @@ static bool gfx_ctx_d3d_init(void) return true; } +static void gfx_ctx_d3d_input_driver(const input_driver_t **input, void **input_data) +{ + dinput = input_dinput.init(); + *input = dinput ? &input_dinput : NULL; + *input_data = dinput; +} + const gfx_ctx_driver_t gfx_ctx_d3d9 = { - gfx_ctx_d3d_init, // gfx_ctx_init + gfx_ctx_d3d_init, NULL, // gfx_ctx_destroy - gfx_ctx_d3d_bind_api, // gfx_ctx_bind_api + gfx_ctx_d3d_bind_api, NULL, // gfx_ctx_swap_interval NULL, // gfx_ctx_set_video_mode NULL, // gfx_ctx_get_video_size NULL, - gfx_ctx_d3d_update_title, // gfx_ctx_update_window_title - gfx_ctx_d3d_check_window, // gfx_ctx_check_window + gfx_ctx_d3d_update_title, + gfx_ctx_d3d_check_window, NULL, // gfx_ctx_set_resize - gfx_ctx_d3d_has_focus, // gfx_ctx_has_focus - gfx_ctx_d3d_swap_buffers, // gfx_ctx_swap_buffers - NULL, // gfx_ctx_input_driver - NULL, // gfx_ctx_get_proc_address - gfx_ctx_d3d_show_mouse, // gfx_ctx_show_mouse + gfx_ctx_d3d_has_focus, + gfx_ctx_d3d_swap_buffers, + gfx_ctx_d3d_input_driver, + NULL, + gfx_ctx_d3d_show_mouse, "d3d9", };