(D3D) Refactor D3DVideo class to d3d_video_t - should be very

similar to XDK D3D driver now
This commit is contained in:
twinaphex 2014-03-07 19:34:17 +01:00
parent 85bfecf1e9
commit fd76a28a32
5 changed files with 66 additions and 64 deletions

View File

@ -51,7 +51,7 @@ static BOOL CALLBACK monitor_enum_proc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT
// Multi-monitor support.
RECT d3d_monitor_rect(void *data)
{
D3DVideo *d3d = reinterpret_cast<D3DVideo*>(data);
d3d_video_t *d3d = (d3d_video_t*)data;
Monitor::num_mons = 0;
EnumDisplayMonitors(NULL, NULL, monitor_enum_proc, 0);
@ -88,7 +88,7 @@ RECT d3d_monitor_rect(void *data)
static void d3d_deinitialize(void *data)
{
D3DVideo *d3d = reinterpret_cast<D3DVideo*>(data);
d3d_video_t *d3d = (d3d_video_t*)data;
if (d3d->font_ctx && d3d->font_ctx->deinit)
d3d->font_ctx->deinit(d3d);
@ -107,7 +107,7 @@ extern LRESULT CALLBACK WindowProc(HWND hWnd, UINT message,
static bool d3d_init_base(void *data, const video_info_t *info)
{
D3DVideo *d3d = reinterpret_cast<D3DVideo*>(data);
d3d_video_t *d3d = (d3d_video_t*)data;
D3DPRESENT_PARAMETERS d3dpp;
d3d_make_d3dpp(d3d, info, &d3dpp);
@ -150,7 +150,7 @@ static void d3d_calculate_rect(void *data, unsigned width, unsigned height,
static bool d3d_initialize(void *data, const video_info_t *info)
{
D3DVideo *d3d = reinterpret_cast<D3DVideo*>(data);
d3d_video_t *d3d = (d3d_video_t*)data;
bool ret = true;
if (!d3d->g_pD3D)
ret = d3d_init_base(d3d, info);
@ -223,7 +223,7 @@ static bool d3d_initialize(void *data, const video_info_t *info)
bool d3d_restore(void *data)
{
D3DVideo *d3d = reinterpret_cast<D3DVideo*>(data);
d3d_video_t *d3d = (d3d_video_t*)data;
d3d_deinitialize(d3d);
d3d->needs_restore = !d3d_initialize(d3d, &d3d->video_info);
@ -236,7 +236,7 @@ bool d3d_restore(void *data)
#ifdef HAVE_OVERLAY
static void d3d_overlay_render(void *data, overlay_t *overlay)
{
D3DVideo *d3d = reinterpret_cast<D3DVideo*>(data);
d3d_video_t *d3d = (d3d_video_t*)data;
if (!overlay || !overlay->tex)
return;
@ -355,7 +355,7 @@ static void d3d_overlay_render(void *data, overlay_t *overlay)
static void d3d_set_viewport(void *data, int x, int y, unsigned width, unsigned height)
{
D3DVideo *d3d = reinterpret_cast<D3DVideo*>(data);
d3d_video_t *d3d = (d3d_video_t*)data;
D3DVIEWPORT viewport;
// D3D doesn't support negative X/Y viewports ...
@ -379,7 +379,7 @@ static void d3d_set_viewport(void *data, int x, int y, unsigned width, unsigned
static void d3d_calculate_rect(void *data, unsigned width, unsigned height,
bool keep, float desired_aspect)
{
D3DVideo *d3d = reinterpret_cast<D3DVideo*>(data);
d3d_video_t *d3d = (d3d_video_t*)data;
if (g_settings.video.scale_integer)
{
@ -419,7 +419,7 @@ static bool d3d_frame(void *data, const void *frame,
unsigned width, unsigned height, unsigned pitch,
const char *msg)
{
D3DVideo *d3d = reinterpret_cast<D3DVideo*>(data);
d3d_video_t *d3d = (d3d_video_t*)data;
if (!frame)
return true;
@ -503,14 +503,14 @@ static bool d3d_frame(void *data, const void *frame,
static void d3d_set_nonblock_state(void *data, bool state)
{
D3DVideo *d3d = reinterpret_cast<D3DVideo*>(data);
d3d_video_t *d3d = (d3d_video_t*)data;
d3d->video_info.vsync = !state;
d3d_restore(d3d);
}
static bool d3d_alive(void *data)
{
D3DVideo *d3d = reinterpret_cast<D3DVideo*>(data);
d3d_video_t *d3d = (d3d_video_t*)data;
bool quit = false, resize = false;
if (d3d->ctx_driver && d3d->ctx_driver->check_window)
@ -525,7 +525,7 @@ static bool d3d_alive(void *data)
static bool d3d_focus(void *data)
{
D3DVideo *d3d = reinterpret_cast<D3DVideo*>(data);
d3d_video_t *d3d = (d3d_video_t*)data;
if (d3d && d3d->ctx_driver && d3d->ctx_driver->has_focus)
return d3d->ctx_driver->has_focus();
return false;
@ -533,14 +533,14 @@ static bool d3d_focus(void *data)
static void d3d_set_rotation(void *data, unsigned rot)
{
D3DVideo *d3d = reinterpret_cast<D3DVideo*>(data);
d3d_video_t *d3d = (d3d_video_t*)data;
d3d->dev_rotation = rot;
}
#ifdef HAVE_OVERLAY
void d3d_free_overlay(void *data, overlay_t *overlay)
{
D3DVideo *d3d = reinterpret_cast<D3DVideo*>(data);
d3d_video_t *d3d = (d3d_video_t*)data;
if (overlay->tex)
overlay->tex->Release();
if (overlay->vert_buf)
@ -549,7 +549,7 @@ void d3d_free_overlay(void *data, overlay_t *overlay)
void d3d_free_overlays(void *data)
{
D3DVideo *d3d = reinterpret_cast<D3DVideo*>(data);
d3d_video_t *d3d = (d3d_video_t*)data;
for (unsigned i = 0; i < d3d->overlays.size(); i++)
d3d_free_overlay(d3d, &d3d->overlays[i]);
d3d->overlays.clear();
@ -558,7 +558,7 @@ void d3d_free_overlays(void *data)
static void d3d_free(void *data)
{
D3DVideo *d3d = reinterpret_cast<D3DVideo*>(data);
d3d_video_t *d3d = (d3d_video_t*)data;
d3d_deinitialize(d3d);
#ifdef HAVE_OVERLAY
d3d_free_overlays(d3d);
@ -576,7 +576,8 @@ static void d3d_free(void *data)
#endif
DestroyWindow(d3d->hWnd);
delete d3d;
if (d3d)
free(d3d);
#ifndef _XBOX
UnregisterClass("RetroArch", GetModuleHandle(NULL));
@ -585,7 +586,7 @@ static void d3d_free(void *data)
static void d3d_viewport_info(void *data, struct rarch_viewport *vp)
{
D3DVideo *d3d = reinterpret_cast<D3DVideo*>(data);
d3d_video_t *d3d = (d3d_video_t*)data;
vp->x = d3d->final_viewport.X;
vp->y = d3d->final_viewport.Y;
@ -598,7 +599,7 @@ static void d3d_viewport_info(void *data, struct rarch_viewport *vp)
static bool d3d_read_viewport(void *data, uint8_t *buffer)
{
D3DVideo *d3d = reinterpret_cast<D3DVideo*>(data);
d3d_video_t *d3d = (d3d_video_t*)data;
LPDIRECT3DDEVICE d3dr = d3d->dev;
RARCH_PERFORMANCE_INIT(d3d_read_viewport);
@ -663,7 +664,7 @@ end:
static bool d3d_set_shader(void *data, enum rarch_shader_type type, const char *path)
{
D3DVideo *d3d = reinterpret_cast<D3DVideo*>(data);
d3d_video_t *d3d = (d3d_video_t*)data;
std::string shader = "";
if (path && type == RARCH_SHADER_CG)
shader = path;
@ -698,7 +699,7 @@ static void d3d_overlay_tex_geom(void *data,
float x, float y,
float w, float h)
{
D3DVideo *d3d = reinterpret_cast<D3DVideo*>(data);
d3d_video_t *d3d = (d3d_video_t*)data;
d3d->overlays[index].tex_coords.x = x;
d3d->overlays[index].tex_coords.y = y;
@ -711,7 +712,7 @@ static void d3d_overlay_vertex_geom(void *data,
float x, float y,
float w, float h)
{
D3DVideo *d3d = reinterpret_cast<D3DVideo*>(data);
d3d_video_t *d3d = (d3d_video_t*)data;
y = 1.0f - y;
h = -h;
@ -723,7 +724,7 @@ static void d3d_overlay_vertex_geom(void *data,
static bool d3d_overlay_load(void *data, const texture_image *images, unsigned num_images)
{
D3DVideo *d3d = reinterpret_cast<D3DVideo*>(data);
d3d_video_t *d3d = (d3d_video_t*)data;
d3d_free_overlays(data);
d3d->overlays.resize(num_images);
@ -764,7 +765,7 @@ static bool d3d_overlay_load(void *data, const texture_image *images, unsigned n
static void d3d_overlay_enable(void *data, bool state)
{
D3DVideo *d3d = reinterpret_cast<D3DVideo*>(data);
d3d_video_t *d3d = (d3d_video_t*)data;
for (unsigned i = 0; i < d3d->overlays.size(); i++)
d3d->overlays_enabled = state;
@ -775,7 +776,7 @@ static void d3d_overlay_enable(void *data, bool state)
static void d3d_overlay_full_screen(void *data, bool enable)
{
D3DVideo *d3d = reinterpret_cast<D3DVideo*>(data);
d3d_video_t *d3d = (d3d_video_t*)data;
for (unsigned i = 0; i < d3d->overlays.size(); i++)
d3d->overlays[i].fullscreen = enable;
@ -783,7 +784,7 @@ static void d3d_overlay_full_screen(void *data, bool enable)
static void d3d_overlay_set_alpha(void *data, unsigned index, float mod)
{
D3DVideo *d3d = reinterpret_cast<D3DVideo*>(data);
d3d_video_t *d3d = (d3d_video_t*)data;
d3d->overlays[index].alpha_mod = mod;
}
@ -805,7 +806,7 @@ static void d3d_get_overlay_interface(void *data, const video_overlay_interface_
static void d3d_set_aspect_ratio(void *data, unsigned aspect_ratio_idx)
{
D3DVideo *d3d = reinterpret_cast<D3DVideo*>(data);
d3d_video_t *d3d = (d3d_video_t*)data;
switch (aspect_ratio_idx)
{
@ -833,14 +834,14 @@ static void d3d_set_aspect_ratio(void *data, unsigned aspect_ratio_idx)
static void d3d_apply_state_changes(void *data)
{
D3DVideo *d3d = reinterpret_cast<D3DVideo*>(data);
d3d_video_t *d3d = (d3d_video_t*)data;
d3d->should_resize = true;
}
static void d3d_set_osd_msg(void *data, const char *msg, void *userdata)
{
font_params_t *params = (font_params_t*)userdata;
D3DVideo *d3d = reinterpret_cast<D3DVideo*>(data);
d3d_video_t *d3d = (d3d_video_t*)data;
if (params)
d3d_set_font_rect(d3d, params);
@ -851,7 +852,7 @@ static void d3d_set_osd_msg(void *data, const char *msg, void *userdata)
static void d3d_show_mouse(void *data, bool state)
{
D3DVideo *d3d = reinterpret_cast<D3DVideo*>(data);
d3d_video_t *d3d = (d3d_video_t*)data;
if (d3d && d3d->ctx_driver && d3d->ctx_driver->show_mouse)
d3d->ctx_driver->show_mouse(state);
@ -862,7 +863,7 @@ static void d3d_set_rgui_texture_frame(void *data,
const void *frame, bool rgb32, unsigned width, unsigned height,
float alpha)
{
D3DVideo *d3d = reinterpret_cast<D3DVideo*>(data);
d3d_video_t *d3d = (d3d_video_t*)data;
if (!d3d->rgui->tex || d3d->rgui->tex_w != width || d3d->rgui->tex_h != height)
{
@ -925,7 +926,7 @@ static void d3d_set_rgui_texture_frame(void *data,
static void d3d_set_rgui_texture_enable(void *data, bool state, bool full_screen)
{
D3DVideo *d3d = reinterpret_cast<D3DVideo*>(data);
d3d_video_t *d3d = (d3d_video_t*)data;
if (!d3d || !d3d->rgui)
return;
@ -962,7 +963,7 @@ static void d3d_get_poke_interface(void *data, const video_poke_interface_t **if
static bool d3d_construct(void *data, const video_info_t *info, const input_driver_t **input,
void **input_data)
{
D3DVideo *d3d = reinterpret_cast<D3DVideo*>(data);
d3d_video_t *d3d = (d3d_video_t*)data;
d3d->should_resize = false;
#ifndef _XBOX
gfx_set_dwm();
@ -1094,14 +1095,14 @@ static const gfx_ctx_driver_t *d3d_get_context(void)
static void *d3d_init(const video_info_t *info, const input_driver_t **input,
void **input_data)
{
D3DVideo *vid = new D3DVideo;
d3d_video_t *vid = (d3d_video_t*)calloc(1, sizeof(d3d_video_t));
if (!vid)
return NULL;
vid->ctx_driver = d3d_get_context();
if (!vid->ctx_driver)
{
delete vid;
free(vid);
return NULL;
}
@ -1122,7 +1123,7 @@ static void *d3d_init(const video_info_t *info, const input_driver_t **input,
if (!d3d_construct(vid, info, input, input_data))
{
RARCH_ERR("[D3D]: Failed to init D3D.\n");
delete vid;
free(vid);
return NULL;
}

View File

@ -86,7 +86,7 @@ void d3d_show_cursor(void *data, bool state);
void d3d_make_d3dpp(void *data, const video_info_t *info, D3DPRESENT_PARAMETERS *d3dpp);
bool d3d_alive_func(void *data);
struct D3DVideo
typedef struct d3d_video
{
const d3d_font_renderer_t *font_ctx;
const gfx_ctx_driver_t *ctx_driver;
@ -133,7 +133,7 @@ struct D3DVideo
overlay_t *rgui;
#endif
void *chain;
};
} d3d_video_t;
#ifndef _XBOX
extern "C" bool dinput_handle_message(void *dinput, UINT message, WPARAM wParam, LPARAM lParam);

View File

@ -29,7 +29,7 @@
#endif
#endif
static D3DVideo *curD3D = NULL;
static d3d_video_t *curD3D = NULL;
static bool d3d_quit = false;
static void *dinput;
@ -37,8 +37,8 @@ extern bool d3d_restore(void *data);
static void d3d_resize(unsigned new_width, unsigned new_height)
{
D3DVideo *d3d = reinterpret_cast<D3DVideo*>(curD3D);
LPDIRECT3DDEVICE d3dr = d3d->dev;
d3d_video_t *d3d = (d3d_video_t*)curD3D;
LPDIRECT3DDEVICE d3dr = (LPDIRECT3DDEVICE)d3d->dev;
if (!d3dr)
return;
@ -61,7 +61,7 @@ LRESULT CALLBACK WindowProc(HWND hWnd, UINT message,
case WM_CREATE:
LPCREATESTRUCT p_cs;
p_cs = (LPCREATESTRUCT)lParam;
curD3D = (D3DVideo*)p_cs->lpCreateParams;
curD3D = (d3d_video_t*)p_cs->lpCreateParams;
break;
case WM_CHAR:
@ -91,7 +91,7 @@ LRESULT CALLBACK WindowProc(HWND hWnd, UINT message,
bool d3d_process_shader(void *data)
{
D3DVideo *d3d = reinterpret_cast<D3DVideo*>(data);
d3d_video_t *d3d = (d3d_video_t*)data;
#ifdef HAVE_FBO
if (strcmp(path_get_extension(d3d->cg_shader.c_str()), "cgp") == 0)
return d3d_init_multipass(d3d);
@ -102,8 +102,8 @@ bool d3d_process_shader(void *data)
static void gfx_ctx_d3d_swap_buffers(void)
{
D3DVideo *d3d = reinterpret_cast<D3DVideo*>(driver.video_data);
LPDIRECT3DDEVICE d3dr = d3d->dev;
d3d_video_t *d3d = (d3d_video_t*)driver.video_data;
LPDIRECT3DDEVICE d3dr = (LPDIRECT3DDEVICE)d3d->dev;
if (d3dr->Present(NULL, NULL, NULL, NULL) != D3D_OK)
{
d3d->needs_restore = true;
@ -113,7 +113,7 @@ static void gfx_ctx_d3d_swap_buffers(void)
static void gfx_ctx_d3d_update_title(void)
{
D3DVideo *d3d = reinterpret_cast<D3DVideo*>(driver.video_data);
d3d_video_t *d3d = (d3d_video_t*)driver.video_data;
char buffer[128], buffer_fps[128];
bool fps_draw = g_settings.fps_show;
if (gfx_get_fps(buffer, sizeof(buffer), fps_draw ? buffer_fps : NULL, sizeof(buffer_fps)))
@ -131,7 +131,7 @@ static void gfx_ctx_d3d_update_title(void)
void d3d_set_font_rect(void *data, font_params_t *params)
{
D3DVideo *d3d = reinterpret_cast<D3DVideo*>(data);
d3d_video_t *d3d = (d3d_video_t*)data;
float pos_x = g_settings.video.msg_pos_x;
float pos_y = g_settings.video.msg_pos_y;
float font_size = g_settings.video.font_size;
@ -157,7 +157,7 @@ void d3d_set_font_rect(void *data, font_params_t *params)
void d3d_recompute_pass_sizes(void *data)
{
D3DVideo *d3d = reinterpret_cast<D3DVideo*>(data);
d3d_video_t *d3d = (d3d_video_t*)data;
LinkInfo link_info = {0};
link_info.pass = &d3d->shader.pass[0];
link_info.tex_w = link_info.tex_h = d3d->video_info.input_scale * RARCH_SCALE_BASE;
@ -197,7 +197,7 @@ void d3d_recompute_pass_sizes(void *data)
bool d3d_init_singlepass(void *data)
{
D3DVideo *d3d = reinterpret_cast<D3DVideo*>(data);
d3d_video_t *d3d = (d3d_video_t*)data;
memset(&d3d->shader, 0, sizeof(d3d->shader));
d3d->shader.passes = 1;
gfx_shader_pass &pass = d3d->shader.pass[0];
@ -211,7 +211,7 @@ bool d3d_init_singlepass(void *data)
bool d3d_init_imports(void *data)
{
D3DVideo *d3d = reinterpret_cast<D3DVideo*>(data);
d3d_video_t *d3d = (d3d_video_t*)data;
if (!d3d->shader.variables)
return true;
@ -244,7 +244,7 @@ bool d3d_init_imports(void *data)
bool d3d_init_luts(void *data)
{
D3DVideo *d3d = reinterpret_cast<D3DVideo*>(data);
d3d_video_t *d3d = (d3d_video_t*)data;
for (unsigned i = 0; i < d3d->shader.luts; i++)
{
bool ret = renderchain_add_lut(d3d->chain, d3d->shader.lut[i].id, d3d->shader.lut[i].path,
@ -262,7 +262,7 @@ bool d3d_init_luts(void *data)
#ifdef HAVE_FBO
bool d3d_init_multipass(void *data)
{
D3DVideo *d3d = reinterpret_cast<D3DVideo*>(data);
d3d_video_t *d3d = (d3d_video_t*)data;
config_file_t *conf = config_file_new(d3d->cg_shader.c_str());
if (!conf)
{
@ -316,8 +316,8 @@ bool d3d_init_multipass(void *data)
bool d3d_init_chain(void *data, const video_info_t *video_info)
{
D3DVideo *d3d = reinterpret_cast<D3DVideo*>(data);
LPDIRECT3DDEVICE d3dr = d3d->dev;
d3d_video_t *d3d = (d3d_video_t*)data;
LPDIRECT3DDEVICE d3dr = (LPDIRECT3DDEVICE)d3d->dev;
// Setup information for first pass.
LinkInfo link_info = {0};
@ -379,8 +379,9 @@ bool d3d_init_chain(void *data, const video_info_t *video_info)
void d3d_deinit_chain(void *data)
{
D3DVideo *d3d = reinterpret_cast<D3DVideo*>(data);
delete d3d->chain;
d3d_video_t *d3d = (d3d_video_t*)data;
if (d3d->chain)
free(d3d->chain);
d3d->chain = NULL;
}
@ -396,7 +397,7 @@ static void gfx_ctx_d3d_show_mouse(bool state)
void d3d_make_d3dpp(void *data, const video_info_t *info, D3DPRESENT_PARAMETERS *d3dpp)
{
D3DVideo *d3d = reinterpret_cast<D3DVideo*>(data);
d3d_video_t *d3d = (d3d_video_t*)data;
memset(d3dpp, 0, sizeof(*d3dpp));
d3dpp->Windowed = g_settings.video.windowed_fullscreen || !info->fullscreen;
@ -430,7 +431,7 @@ void d3d_make_d3dpp(void *data, const video_info_t *info, D3DPRESENT_PARAMETERS
static void gfx_ctx_d3d_check_window(bool *quit,
bool *resize, unsigned *width, unsigned *height, unsigned frame_count)
{
D3DVideo *d3d = reinterpret_cast<D3DVideo*>(driver.video_data);
d3d_video_t *d3d = (d3d_video_t*)driver.video_data;
*quit = false;
*resize = false;
@ -452,7 +453,7 @@ static bool gfx_ctx_d3d_has_focus(void)
#ifdef _XBOX
return true;
#else
D3DVideo *d3d = reinterpret_cast<D3DVideo*>(driver.video_data);
d3d_video_t *d3d = (d3d_video_t*)driver.video_data;
return GetFocus() == d3d->hWnd;
#endif
}

View File

@ -542,7 +542,7 @@ void renderchain_bind_pass(void *data, Pass &pass, unsigned pass_index)
bool d3d_init_shader(void *data)
{
D3DVideo *d3d = reinterpret_cast<D3DVideo*>(data);
d3d_video_t *d3d = (d3d_video_t*)data;
d3d->cgCtx = cgCreateContext();
if (!d3d->cgCtx)
return false;
@ -558,7 +558,7 @@ bool d3d_init_shader(void *data)
void d3d_deinit_shader(void *data)
{
D3DVideo *d3d = reinterpret_cast<D3DVideo*>(data);
d3d_video_t *d3d = (d3d_video_t*)data;
if (!d3d->cgCtx)
return;

View File

@ -23,7 +23,7 @@ static bool d3dfonts_w32_init_font(void *data, const char *font_path, unsigned f
{
(void)font_path;
D3DVideo *d3d = reinterpret_cast<D3DVideo*>(data);
d3d_video_t *d3d = (d3d_video_t*)data;
D3DXFONT_DESC desc = {
static_cast<int>(font_size), 0, 400, 0,
false, DEFAULT_CHARSET,
@ -43,7 +43,7 @@ static bool d3dfonts_w32_init_font(void *data, const char *font_path, unsigned f
static void d3dfonts_w32_deinit_font(void *data)
{
D3DVideo *d3d = reinterpret_cast<D3DVideo*>(data);
d3d_video_t *d3d = (d3d_video_t*)data;
if (d3d->font)
d3d->font->Release();
d3d->font = NULL;
@ -51,7 +51,7 @@ static void d3dfonts_w32_deinit_font(void *data)
static void d3dfonts_w32_render_msg(void *data, const char *msg, void *userdata)
{
D3DVideo *d3d = reinterpret_cast<D3DVideo*>(data);
d3d_video_t *d3d = (d3d_video_t*)data;
font_params_t *params = (font_params_t*)userdata;
if (msg && SUCCEEDED(d3d->dev->BeginScene()))