summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
author couriersud <couriersud@arcor.de>2015-02-05 23:24:15 +0100
committer couriersud <couriersud@arcor.de>2015-02-05 23:24:15 +0100
commit950b1b05147dea8dd86bb2326d841e0b05f2580a (patch)
tree5aec42b8c8f05b36981b57c4079bec900b88f4f4
parent388875c61d471d882c811a785ea27c93f9349ff4 (diff)
Introduced a comparable "osd_renderer" interface like it now exists for
SDL to mainline. Ultimately, this will allow renderers to be placed in modules\renderer and e.g. allow the opengl renderer to be used in mainline or the d3d renderer to be used in sdlmame. (nw)
-rw-r--r--src/osd/windows/d3dhlsl.c56
-rw-r--r--src/osd/windows/drawbgfx.c66
-rw-r--r--src/osd/windows/drawd3d.c164
-rw-r--r--src/osd/windows/drawd3d.h18
-rw-r--r--src/osd/windows/drawdd.c542
-rw-r--r--src/osd/windows/drawgdi.c113
-rw-r--r--src/osd/windows/drawnone.c50
-rw-r--r--src/osd/windows/window.c49
-rw-r--r--src/osd/windows/window.h48
9 files changed, 578 insertions, 528 deletions
diff --git a/src/osd/windows/d3dhlsl.c b/src/osd/windows/d3dhlsl.c
index 69f8b94dcd9..5a6772e9281 100644
--- a/src/osd/windows/d3dhlsl.c
+++ b/src/osd/windows/d3dhlsl.c
@@ -224,7 +224,7 @@ void shaders::window_save()
if (!master_enable || !d3dintf->post_fx_available)
return;
- renderer *d3d = (renderer *)window->m_drawdata;
+ renderer *d3d = dynamic_cast<renderer *>(window->m_renderer);
HRESULT result = (*d3dintf->device.create_texture)(d3d->get_device(), snap_width, snap_height, 1, D3DUSAGE_DYNAMIC, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &snap_copy_texture);
if (result != D3D_OK)
@@ -276,7 +276,7 @@ void shaders::avi_update_snap(surface *surface)
if (!master_enable || !d3dintf->post_fx_available)
return;
- renderer *d3d = (renderer *)window->m_drawdata;
+ renderer *d3d = dynamic_cast<renderer *>(window->m_renderer);
D3DLOCKED_RECT rect;
@@ -326,7 +326,7 @@ void shaders::render_snapshot(surface *surface)
if (!master_enable || !d3dintf->post_fx_available)
return;
- renderer *d3d = (renderer *)window->m_drawdata;
+ renderer *d3d = dynamic_cast<renderer *>(window->m_renderer);
D3DLOCKED_RECT rect;
@@ -519,7 +519,7 @@ void shaders::begin_avi_recording(const char *name)
if (!master_enable || !d3dintf->post_fx_available)
return;
- renderer *d3d = (renderer *)window->m_drawdata;
+ renderer *d3d = dynamic_cast<renderer *>(window->m_renderer);
// stop any existing recording
end_avi_recording();
@@ -678,7 +678,7 @@ void shaders::set_texture(texture_info *texture)
if (!master_enable || !d3dintf->post_fx_available)
return;
- renderer *d3d = (renderer *)window->m_drawdata;
+ renderer *d3d = dynamic_cast<renderer *>(window->m_renderer);
if(texture != NULL)
{
@@ -820,7 +820,7 @@ void shaders::init_fsfx_quad(void *vertbuf)
if (!master_enable || !d3dintf->post_fx_available)
return;
- renderer *d3d = (renderer *)window->m_drawdata;
+ renderer *d3d = dynamic_cast<renderer *>(window->m_renderer);
// get a pointer to the vertex buffer
fsfx_vertices = (vertex *)vertbuf;
@@ -892,7 +892,7 @@ int shaders::create_resources(bool reset)
if (!master_enable || !d3dintf->post_fx_available)
return 0;
- renderer *d3d = (renderer *)window->m_drawdata;
+ renderer *d3d = dynamic_cast<renderer *>(window->m_renderer);
HRESULT result = (*d3dintf->device.get_render_target)(d3d->get_device(), 0, &backbuffer);
if (result != D3D_OK) osd_printf_verbose("Direct3D: Error %08X during device get_render_target call\n", (int)result);
@@ -1066,7 +1066,7 @@ void shaders::begin_draw()
if (!master_enable || !d3dintf->post_fx_available)
return;
- renderer *d3d = (renderer *)window->m_drawdata;
+ renderer *d3d = dynamic_cast<renderer *>(window->m_renderer);
curr_effect = default_effect;
@@ -1101,7 +1101,7 @@ void shaders::begin_frame()
void shaders::blit(surface *dst, texture *src, surface *new_dst, D3DPRIMITIVETYPE prim_type,
UINT32 prim_index, UINT32 prim_count, int dstw, int dsth)
{
- renderer *d3d = (renderer *)window->m_drawdata;
+ renderer *d3d = dynamic_cast<renderer *>(window->m_renderer);
HRESULT result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, dst);
if (result != D3D_OK) osd_printf_verbose("Direct3D: Error %08X during device set_render_target call\n", (int)result);
@@ -1146,7 +1146,7 @@ void shaders::blit(surface *dst, texture *src, surface *new_dst, D3DPRIMITIVETYP
void shaders::blit(surface *dst, texture *src, surface *new_dst, D3DPRIMITIVETYPE prim_type,
UINT32 prim_index, UINT32 prim_count)
{
- renderer *d3d = (renderer *)window->m_drawdata;
+ renderer *d3d = dynamic_cast<renderer *>(window->m_renderer);
HRESULT result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, dst);
if (result != D3D_OK) osd_printf_verbose("Direct3D: Error %08X during device set_render_target call\n", (int)result);
@@ -1231,7 +1231,7 @@ void shaders::init_effect_info(poly_info *poly)
if (!master_enable || !d3dintf->post_fx_available)
return;
- renderer *d3d = (renderer *)window->m_drawdata;
+ renderer *d3d = dynamic_cast<renderer *>(window->m_renderer);
texture_info *texture = poly->get_texture();
if(PRIMFLAG_GET_SCREENTEX(d3d->get_last_texture_flags()) && texture != NULL)
@@ -1308,7 +1308,7 @@ cache_target* shaders::find_cache_target(UINT32 screen_index, int width, int hei
void shaders::ntsc_pass(render_target *rt, vec2f &sourcedims, vec2f &delta)
{
- renderer *d3d = (renderer *)window->m_drawdata;
+ renderer *d3d = dynamic_cast<renderer *>(window->m_renderer);
UINT num_passes = 0;
if(options->yiq_enable)
@@ -1370,7 +1370,7 @@ void shaders::ntsc_pass(render_target *rt, vec2f &sourcedims, vec2f &delta)
void shaders::color_convolution_pass(render_target *rt, vec2f &texsize, vec2f &sourcedims)
{
- renderer *d3d = (renderer *)window->m_drawdata;
+ renderer *d3d = dynamic_cast<renderer *>(window->m_renderer);
UINT num_passes = 0;
curr_effect = color_effect;
@@ -1398,7 +1398,7 @@ void shaders::color_convolution_pass(render_target *rt, vec2f &texsize, vec2f &s
void shaders::prescale_pass(render_target *rt, vec2f &texsize, vec2f &sourcedims)
{
- renderer *d3d = (renderer *)window->m_drawdata;
+ renderer *d3d = dynamic_cast<renderer *>(window->m_renderer);
UINT num_passes = 0;
curr_effect = prescale_effect;
@@ -1426,7 +1426,7 @@ void shaders::prescale_pass(render_target *rt, vec2f &texsize, vec2f &sourcedims
void shaders::deconverge_pass(render_target *rt, vec2f &texsize, vec2f &delta, vec2f &sourcedims)
{
- renderer *d3d = (renderer *)window->m_drawdata;
+ renderer *d3d = dynamic_cast<renderer *>(window->m_renderer);
UINT num_passes = 0;
curr_effect = deconverge_effect;
@@ -1454,7 +1454,7 @@ void shaders::deconverge_pass(render_target *rt, vec2f &texsize, vec2f &delta, v
void shaders::defocus_pass(render_target *rt, vec2f &texsize)
{
- renderer *d3d = (renderer *)window->m_drawdata;
+ renderer *d3d = dynamic_cast<renderer *>(window->m_renderer);
UINT num_passes = 0;
// Defocus pass 1
@@ -1503,7 +1503,7 @@ void shaders::defocus_pass(render_target *rt, vec2f &texsize)
void shaders::phosphor_pass(render_target *rt, cache_target *ct, vec2f &texsize, bool focus_enable)
{
- renderer *d3d = (renderer *)window->m_drawdata;
+ renderer *d3d = dynamic_cast<renderer *>(window->m_renderer);
UINT num_passes = 0;
curr_effect = phosphor_effect;
@@ -1561,7 +1561,7 @@ void shaders::phosphor_pass(render_target *rt, cache_target *ct, vec2f &texsize,
void shaders::avi_post_pass(render_target *rt, vec2f &texsize, vec2f &delta, vec2f &sourcedims, poly_info *poly, int vertnum)
{
- renderer *d3d = (renderer *)window->m_drawdata;
+ renderer *d3d = dynamic_cast<renderer *>(window->m_renderer);
UINT num_passes = 0;
curr_effect = post_effect;
@@ -1616,7 +1616,7 @@ void shaders::avi_post_pass(render_target *rt, vec2f &texsize, vec2f &delta, vec
void shaders::screen_post_pass(render_target *rt, vec2f &texsize, vec2f &delta, vec2f &sourcedims, poly_info *poly, int vertnum)
{
- renderer *d3d = (renderer *)window->m_drawdata;
+ renderer *d3d = dynamic_cast<renderer *>(window->m_renderer);
UINT num_passes = 0;
curr_effect = post_effect;
@@ -1650,7 +1650,7 @@ void shaders::screen_post_pass(render_target *rt, vec2f &texsize, vec2f &delta,
void shaders::raster_bloom_pass(render_target *rt, vec2f &texsize, vec2f &delta, poly_info *poly, int vertnum)
{
- renderer *d3d = (renderer *)window->m_drawdata;
+ renderer *d3d = dynamic_cast<renderer *>(window->m_renderer);
UINT num_passes = 0;
curr_effect = downsample_effect;
@@ -1755,7 +1755,7 @@ void shaders::render_quad(poly_info *poly, int vertnum)
return;
UINT num_passes = 0;
- renderer *d3d = (renderer *)window->m_drawdata;
+ renderer *d3d = dynamic_cast<renderer *>(window->m_renderer);
curr_texture = poly->get_texture();
if(PRIMFLAG_GET_SCREENTEX(d3d->get_last_texture_flags()) && curr_texture != NULL)
@@ -2080,14 +2080,14 @@ render_target* shaders::get_vector_target()
return NULL;
}
- renderer *d3d = (renderer *)window->m_drawdata;
+ renderer *d3d = dynamic_cast<renderer *>(window->m_renderer);
return find_render_target(d3d->get_width(), d3d->get_height(), 0, 0);
}
void shaders::create_vector_target(render_primitive *prim)
{
- renderer *d3d = (renderer *)window->m_drawdata;
+ renderer *d3d = dynamic_cast<renderer *>(window->m_renderer);
if (!add_render_target(d3d, NULL, d3d->get_width(), d3d->get_height(), 1, 1))
{
vector_enable = false;
@@ -2202,7 +2202,7 @@ bool shaders::register_texture(texture_info *texture)
enumerate_screens();
- renderer *d3d = (renderer *)window->m_drawdata;
+ renderer *d3d = dynamic_cast<renderer *>(window->m_renderer);
int hlsl_prescale_x = prescale_force_x;
int hlsl_prescale_y = prescale_force_y;
@@ -2994,7 +2994,7 @@ void uniform::update()
}
shaders *shadersys = m_shader->m_shaders;
- renderer *d3d = (renderer *)shadersys->window->m_drawdata;
+ renderer *d3d = dynamic_cast<renderer *>(shadersys->window->m_renderer);
hlsl_options *options = shadersys->options;
switch(m_id)
@@ -3422,7 +3422,7 @@ static file_error open_next(d3d::renderer *d3d, emu_file &file, const char *temp
UINT32 origflags = file.openflags();
// handle defaults
- const char *snapname = templ ? templ : d3d->get_window()->machine().options().snap_name();
+ const char *snapname = templ ? templ : d3d->window().machine().options().snap_name();
if (snapname == NULL || snapname[0] == 0)
snapname = "%g/%i";
@@ -3469,7 +3469,7 @@ static file_error open_next(d3d::renderer *d3d, emu_file &file, const char *temp
snapdevname.cpysubstr(snapstr, pos + 3, end - pos - 3);
// verify that there is such a device for this system
- image_interface_iterator iter(d3d->get_window()->machine().root_device());
+ image_interface_iterator iter(d3d->window().machine().root_device());
for (device_image_interface *image = iter.first(); image != NULL; iter.next())
{
// get the device name
@@ -3506,7 +3506,7 @@ static file_error open_next(d3d::renderer *d3d, emu_file &file, const char *temp
// substitute path and gamename up front
snapstr.replace(0, "/", PATH_SEPARATOR);
- snapstr.replace(0, "%g", d3d->get_window()->machine().basename());
+ snapstr.replace(0, "%g", d3d->window().machine().basename());
// determine if the template has an index; if not, we always use the same name
astring fname;
diff --git a/src/osd/windows/drawbgfx.c b/src/osd/windows/drawbgfx.c
index 8c15a108ec1..bf42b17fb62 100644
--- a/src/osd/windows/drawbgfx.c
+++ b/src/osd/windows/drawbgfx.c
@@ -22,32 +22,52 @@
#include <bgfxplatform.h>
#include <bgfx.h>
+class renderer_bgfx : public osd_renderer
+{
+public:
+ renderer_bgfx(win_window_info *window)
+ : osd_renderer(window, FLAG_NONE) { }
+
+ virtual ~renderer_bgfx() { }
+
+ virtual int init();
+ virtual render_primitive_list *get_primitives();
+ virtual int draw(HDC dc, int update);
+ virtual void save() {};
+ virtual void record() {};
+ virtual void toggle_fsfx() {};
+ virtual void destroy();
+
+private:
+};
+
+
//============================================================
// PROTOTYPES
//============================================================
// core functions
static void drawbgfx_exit(void);
-static int drawbgfx_window_init(win_window_info *window);
-static void drawbgfx_window_destroy(win_window_info *window);
-static render_primitive_list *drawbgfx_window_get_primitives(win_window_info *window);
-static int drawbgfx_window_draw(win_window_info *window, HDC dc, int update);
+//============================================================
+// drawnone_create
+//============================================================
+osd_renderer *drawbgfx_create(win_window_info *window)
+{
+ return global_alloc(renderer_bgfx(window));
+}
//============================================================
// drawbgfx_init
//============================================================
-int drawbgfx_init(running_machine &machine, win_draw_callbacks *callbacks)
+int drawbgfx_init(running_machine &machine, osd_draw_callbacks *callbacks)
{
// fill in the callbacks
memset(callbacks, 0, sizeof(*callbacks));
callbacks->exit = drawbgfx_exit;
- callbacks->window_init = drawbgfx_window_init;
- callbacks->window_get_primitives = drawbgfx_window_get_primitives;
- callbacks->window_draw = drawbgfx_window_draw;
- callbacks->window_destroy = drawbgfx_window_destroy;
+ callbacks->create = drawbgfx_create;
return 0;
}
@@ -67,19 +87,18 @@ static void drawbgfx_exit(void)
// drawbgfx_window_init
//============================================================
-static int drawbgfx_window_init(win_window_info *window)
+int renderer_bgfx::init()
{
RECT client;
- GetClientRect(window->m_hwnd, &client);
+ GetClientRect(window().m_hwnd, &client);
- bgfx::winSetHwnd(window->m_hwnd);
+ bgfx::winSetHwnd(window().m_hwnd);
bgfx::init();
bgfx::reset(rect_width(&client), rect_height(&client), BGFX_RESET_VSYNC);
// Enable debug text.
bgfx::setDebug(BGFX_DEBUG_STATS);// BGFX_DEBUG_TEXT);
- window->m_drawdata = window->m_hwnd;
return 0;
}
@@ -89,11 +108,10 @@ static int drawbgfx_window_init(win_window_info *window)
// drawbgfx_window_destroy
//============================================================
-static void drawbgfx_window_destroy(win_window_info *window)
+void renderer_bgfx::destroy()
{
// Shutdown bgfx.
bgfx::shutdown();
- window->m_drawdata = NULL;
}
@@ -102,12 +120,12 @@ static void drawbgfx_window_destroy(win_window_info *window)
// drawbgfx_window_get_primitives
//============================================================
-static render_primitive_list *drawbgfx_window_get_primitives(win_window_info *window)
+render_primitive_list *renderer_bgfx::get_primitives()
{
RECT client;
- GetClientRect(window->m_hwnd, &client);
- window->m_target->set_bounds(rect_width(&client), rect_height(&client), window->m_monitor->get_aspect());
- return &window->m_target->get_primitives();
+ GetClientRect(window().m_hwnd, &client);
+ window().m_target->set_bounds(rect_width(&client), rect_height(&client), window().m_monitor->get_aspect());
+ return &window().m_target->get_primitives();
}
@@ -116,10 +134,10 @@ static render_primitive_list *drawbgfx_window_get_primitives(win_window_info *wi
// drawbgfx_window_draw
//============================================================
-static int drawbgfx_window_draw(win_window_info *window, HDC dc, int update)
+int renderer_bgfx::draw(HDC dc, int update)
{
RECT client;
- GetClientRect(window->m_hwnd, &client);
+ GetClientRect(window().m_hwnd, &client);
bgfx::setViewClear(0
, BGFX_CLEAR_COLOR|BGFX_CLEAR_DEPTH
@@ -134,10 +152,10 @@ static int drawbgfx_window_draw(win_window_info *window, HDC dc, int update)
// if no other draw calls are submitted to view 0.
bgfx::submit(0);
- window->m_primlist->acquire_lock();
+ window().m_primlist->acquire_lock();
// now draw
- for (render_primitive *prim = window->m_primlist->first(); prim != NULL; prim = prim->next())
+ for (render_primitive *prim = window().m_primlist->first(); prim != NULL; prim = prim->next())
{
switch (prim->type)
{
@@ -219,7 +237,7 @@ static int drawbgfx_window_draw(win_window_info *window, HDC dc, int update)
}
}
- window->m_primlist->release_lock();
+ window().m_primlist->release_lock();
// Advance to next frame. Rendering thread will be kicked to
// process submitted rendering primitives.
bgfx::frame();
diff --git a/src/osd/windows/drawd3d.c b/src/osd/windows/drawd3d.c
index b09904d30af..74da21a495c 100644
--- a/src/osd/windows/drawd3d.c
+++ b/src/osd/windows/drawd3d.c
@@ -179,28 +179,16 @@ static d3d::base * d3dintf; // FIX ME
// core functions
static void drawd3d_exit(void);
-static int drawd3d_window_init(win_window_info *window);
-static void drawd3d_window_destroy(win_window_info *window);
-static render_primitive_list *drawd3d_window_get_primitives(win_window_info *window);
-static void drawd3d_window_save(win_window_info *window);
-static void drawd3d_window_record(win_window_info *window);
-static void drawd3d_window_toggle_fsfx(win_window_info *window);
-static int drawd3d_window_draw(win_window_info *window, HDC dc, int update);
-
//============================================================
// drawd3d_window_init
//============================================================
-static int drawd3d_window_init(win_window_info *window)
+int d3d::renderer::init()
{
- // allocate memory for our structures
- d3d::renderer *d3d = global_alloc(d3d::renderer(window));
- window->m_drawdata = d3d;
-
- if (!d3d->initialize())
+ if (!initialize())
{
- drawd3d_window_destroy(window);
+ destroy();
osd_printf_error("Unable to initialize Direct3D.\n");
return 1;
}
@@ -218,22 +206,19 @@ static void drawd3d_exit(void)
(*d3dintf->d3d.release)(d3dintf);
}
-static void drawd3d_window_toggle_fsfx(win_window_info *window)
+void d3d::renderer::toggle_fsfx()
{
- d3d::renderer *d3d = (d3d::renderer *)window->m_drawdata;
- d3d->set_restarting(true);
+ set_restarting(true);
}
-static void drawd3d_window_record(win_window_info *window)
+void d3d::renderer::record()
{
- d3d::renderer *d3d = (d3d::renderer *)window->m_drawdata;
- d3d->get_shaders()->window_record();
+ get_shaders()->window_record();
}
-static void drawd3d_window_save(win_window_info *window)
+void d3d::renderer::save()
{
- d3d::renderer *d3d = (d3d::renderer *)window->m_drawdata;
- d3d->get_shaders()->window_save();
+ get_shaders()->window_save();
}
@@ -242,20 +227,11 @@ static void drawd3d_window_save(win_window_info *window)
// drawd3d_window_destroy
//============================================================
-static void drawd3d_window_destroy(win_window_info *window)
+void d3d::renderer::destroy()
{
- d3d::renderer *d3d = (d3d::renderer *)window->m_drawdata;
-
- // skip if nothing
- if (d3d == NULL)
- return;
+ if (get_shaders() != NULL && get_shaders()->recording())
+ get_shaders()->window_record();
- if (d3d->get_shaders() != NULL && d3d->get_shaders()->recording())
- d3d->get_shaders()->window_record();
-
- // free the memory in the window
- global_free(d3d);
- window->m_drawdata = NULL;
}
@@ -264,21 +240,29 @@ static void drawd3d_window_destroy(win_window_info *window)
// drawd3d_window_get_primitives
//============================================================
-static render_primitive_list *drawd3d_window_get_primitives(win_window_info *window)
+render_primitive_list *d3d::renderer::get_primitives()
{
- d3d::renderer *d3d = (d3d::renderer *)window->m_drawdata;
RECT client;
- GetClientRectExceptMenu(window->m_hwnd, &client, window->m_fullscreen);
+ GetClientRectExceptMenu(window().m_hwnd, &client, window().m_fullscreen);
if (rect_width(&client) > 0 && rect_height(&client) > 0)
{
- window->m_target->set_bounds(rect_width(&client), rect_height(&client), window->m_monitor->get_aspect());
- window->m_target->set_max_update_rate((d3d->get_refresh() == 0) ? d3d->get_origmode().RefreshRate : d3d->get_refresh());
+ window().m_target->set_bounds(rect_width(&client), rect_height(&client), window().m_monitor->get_aspect());
+ window().m_target->set_max_update_rate((get_refresh() == 0) ? get_origmode().RefreshRate : get_refresh());
}
- return &window->m_target->get_primitives();
+ return &window().m_target->get_primitives();
+}
+
+//============================================================
+// drawnone_create
+//============================================================
+
+static osd_renderer *drawd3d_create(win_window_info *window)
+{
+ return global_alloc(d3d::renderer(window));
}
-int drawd3d_init(running_machine &machine, win_draw_callbacks *callbacks)
+int drawd3d_init(running_machine &machine, osd_draw_callbacks *callbacks)
{
d3dintf = NULL;
@@ -295,13 +279,7 @@ int drawd3d_init(running_machine &machine, win_draw_callbacks *callbacks)
// fill in the callbacks
memset(callbacks, 0, sizeof(*callbacks));
callbacks->exit = drawd3d_exit;
- callbacks->window_init = drawd3d_window_init;
- callbacks->window_get_primitives = drawd3d_window_get_primitives;
- callbacks->window_draw = drawd3d_window_draw;
- callbacks->window_save = drawd3d_window_save;
- callbacks->window_record = drawd3d_window_record;
- callbacks->window_toggle_fsfx = drawd3d_window_toggle_fsfx;
- callbacks->window_destroy = drawd3d_window_destroy;
+ callbacks->create = drawd3d_create;
return 0;
}
@@ -309,21 +287,15 @@ int drawd3d_init(running_machine &machine, win_draw_callbacks *callbacks)
// drawd3d_window_draw
//============================================================
-static int drawd3d_window_draw(win_window_info *window, HDC dc, int update)
+int d3d::renderer::draw(HDC dc, int update)
{
- d3d::renderer *d3d = (d3d::renderer *)window->m_drawdata;
-
- // if we haven't been created, just punt
- if (d3d == NULL)
- return 1;
-
- int check = d3d->pre_window_draw_check();
+ int check = pre_window_draw_check();
if (check >= 0)
return check;
- d3d->begin_frame();
- d3d->process_primitives();
- d3d->end_frame();
+ begin_frame();
+ process_primitives();
+ end_frame();
return 0;
}
@@ -496,7 +468,7 @@ texture_manager::texture_manager(renderer *d3d)
osd_printf_verbose("Direct3D: YUV format = %s\n", (m_yuv_format == D3DFMT_YUY2) ? "YUY2" : (m_yuv_format == D3DFMT_UYVY) ? "UYVY" : "RGB");
// set the max texture size
- d3d->get_window()->m_target->set_max_texture_size(m_texture_max_width, m_texture_max_height);
+ d3d->window().m_target->set_max_texture_size(m_texture_max_width, m_texture_max_height);
osd_printf_verbose("Direct3D: Max texture size = %dx%d\n", (int)m_texture_max_width, (int)m_texture_max_height);
}
@@ -508,7 +480,7 @@ void texture_manager::create_resources()
{
// experimental: load a PNG to use for vector rendering; it is treated
// as a brightness map
- emu_file file(m_renderer->get_window()->machine().options().art_path(), OPEN_FLAG_READ);
+ emu_file file(m_renderer->window().machine().options().art_path(), OPEN_FLAG_READ);
render_load_png(m_vector_bitmap, file, NULL, "vector.png");
if (m_vector_bitmap.valid())
{
@@ -650,10 +622,10 @@ texture_info *texture_manager::find_texinfo(const render_texinfo *texinfo, UINT3
}
renderer::renderer(win_window_info *window)
+ : osd_renderer(window, FLAG_NONE)
{
m_device = NULL;
m_restarting = false;
- m_window = window;
m_shaders = NULL;
m_numverts = 0;
m_numpolys = 0;
@@ -672,7 +644,7 @@ int renderer::initialize()
return false;
// create the device immediately for the full screen case (defer for window mode)
- if (m_window->m_fullscreen && device_create())
+ if (window().m_fullscreen && device_create())
return false;
return true;
@@ -681,7 +653,7 @@ int renderer::initialize()
int renderer::pre_window_draw_check()
{
// if we're in the middle of resizing, leave things alone
- if (m_window->m_resize_state == RESIZE_STATE_RESIZING)
+ if (window().m_resize_state == RESIZE_STATE_RESIZING)
return 0;
// if we're restarting the renderer, leave things alone
@@ -706,7 +678,7 @@ int renderer::pre_window_draw_check()
}
// in window mode, we need to track the window size
- if (!m_window->m_fullscreen || m_device == NULL)
+ if (!window().m_fullscreen || m_device == NULL)
{
// if the size changes, skip this update since the render target will be out of date
if (update_window_size())
@@ -722,7 +694,7 @@ int renderer::pre_window_draw_check()
void texture_manager::update_textures()
{
- for (render_primitive *prim = m_renderer->get_window()->m_primlist->first(); prim != NULL; prim = prim->next())
+ for (render_primitive *prim = m_renderer->window().m_primlist->first(); prim != NULL; prim = prim->next())
{
if (prim->texture.base != NULL)
{
@@ -759,7 +731,7 @@ void renderer::begin_frame()
m_shaders->begin_frame();
- m_window->m_primlist->acquire_lock();
+ window().m_primlist->acquire_lock();
// first update any textures
m_texture_manager->update_textures();
@@ -780,7 +752,7 @@ mtlog_add("drawd3d_window_draw: begin_scene");
m_line_count = 0;
// loop over primitives
- for (render_primitive *prim = m_window->m_primlist->first(); prim != NULL; prim = prim->next())
+ for (render_primitive *prim = window().m_primlist->first(); prim != NULL; prim = prim->next())
if (prim->type == render_primitive::LINE && PRIMFLAG_GET_VECTOR(prim->flags))
m_line_count++;
}
@@ -788,7 +760,7 @@ mtlog_add("drawd3d_window_draw: begin_scene");
void renderer::process_primitives()
{
// Rotating index for vector time offsets
- for (render_primitive *prim = m_window->m_primlist->first(); prim != NULL; prim = prim->next())
+ for (render_primitive *prim = window().m_primlist->first(); prim != NULL; prim = prim->next())
{
switch (prim->type)
{
@@ -818,7 +790,7 @@ void renderer::process_primitives()
void renderer::end_frame()
{
- m_window->m_primlist->release_lock();
+ window().m_primlist->release_lock();
// flush any pending polygons
primitive_flush_pending();
@@ -893,18 +865,18 @@ try_again:
m_presentation.BackBufferCount = video_config.triplebuf ? 2 : 1;
m_presentation.MultiSampleType = D3DMULTISAMPLE_NONE;
m_presentation.SwapEffect = D3DSWAPEFFECT_DISCARD;
- m_presentation.hDeviceWindow = m_window->m_hwnd;
- m_presentation.Windowed = !m_window->m_fullscreen || win_has_menu(m_window);
+ m_presentation.hDeviceWindow = window().m_hwnd;
+ m_presentation.Windowed = !window().m_fullscreen || win_has_menu(&window());
m_presentation.EnableAutoDepthStencil = FALSE;
m_presentation.AutoDepthStencilFormat = D3DFMT_D16;
m_presentation.Flags = 0;
m_presentation.FullScreen_RefreshRateInHz = m_refresh;
- m_presentation.PresentationInterval = ((video_config.triplebuf && m_window->m_fullscreen) ||
+ m_presentation.PresentationInterval = ((video_config.triplebuf && window().m_fullscreen) ||
video_config.waitvsync || video_config.syncrefresh) ?
D3DPRESENT_INTERVAL_ONE : D3DPRESENT_INTERVAL_IMMEDIATE;
// create the D3D device
- result = (*d3dintf->d3d.create_device)(d3dintf, m_adapter, D3DDEVTYPE_HAL, m_window->m_focus_hwnd,
+ result = (*d3dintf->d3d.create_device)(d3dintf, m_adapter, D3DDEVTYPE_HAL, window().m_focus_hwnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING | D3DCREATE_FPU_PRESERVE, &m_presentation, &m_device);
if (result != D3D_OK)
{
@@ -927,10 +899,10 @@ try_again:
osd_printf_verbose("Direct3D: Device created at %dx%d\n", m_width, m_height);
// set the gamma if we need to
- if (m_window->m_fullscreen)
+ if (window().m_fullscreen)
{
// only set the gamma if it's not 1.0f
- windows_options &options = downcast<windows_options &>(m_window->machine().options());
+ windows_options &options = downcast<windows_options &>(window().machine().options());
float brightness = options.full_screen_brightness();
float contrast = options.full_screen_contrast();
float gamma = options.full_screen_gamma();
@@ -1092,7 +1064,7 @@ int renderer::device_verify_caps()
int retval = 0;
m_shaders = global_alloc_clear(shaders);
- m_shaders->init(d3dintf, m_window);
+ m_shaders->init(d3dintf, &window());
DWORD tempcaps;
HRESULT result = (*d3dintf->d3d.get_caps_dword)(d3dintf, m_adapter, D3DDEVTYPE_HAL, CAPS_MAX_PS30_INSN_SLOTS, &tempcaps);
@@ -1231,12 +1203,12 @@ int renderer::config_adapter_mode()
}
// choose a resolution: window mode case
- if (!m_window->m_fullscreen || !video_config.switchres || win_has_menu(m_window))
+ if (!window().m_fullscreen || !video_config.switchres || win_has_menu(&window()))
{
RECT client;
// bounds are from the window client rect
- GetClientRectExceptMenu(m_window->m_hwnd, &client, m_window->m_fullscreen);
+ GetClientRectExceptMenu(window().m_hwnd, &client, window().m_fullscreen);
m_width = client.right - client.left;
m_height = client.bottom - client.top;
@@ -1247,7 +1219,7 @@ int renderer::config_adapter_mode()
// make sure it's a pixel format we can get behind
if (m_pixformat != D3DFMT_X1R5G5B5 && m_pixformat != D3DFMT_R5G6B5 && m_pixformat != D3DFMT_X8R8G8B8)
{
- char *utf8_device = utf8_from_tstring(m_window->m_monitor->info.szDevice);
+ char *utf8_device = utf8_from_tstring(window().m_monitor->info.szDevice);
if (utf8_device != NULL)
{
osd_printf_error("Device %s currently in an unsupported mode\n", utf8_device);
@@ -1272,10 +1244,10 @@ int renderer::config_adapter_mode()
}
// see if we can handle the device type
- result = (*d3dintf->d3d.check_device_type)(d3dintf, m_adapter, D3DDEVTYPE_HAL, m_pixformat, m_pixformat, !m_window->m_fullscreen);
+ result = (*d3dintf->d3d.check_device_type)(d3dintf, m_adapter, D3DDEVTYPE_HAL, m_pixformat, m_pixformat, !window().m_fullscreen);
if (result != D3D_OK)
{
- char *utf8_device = utf8_from_tstring(m_window->m_monitor->info.szDevice);
+ char *utf8_device = utf8_from_tstring(window().m_monitor->info.szDevice);
if (utf8_device != NULL)
{
osd_printf_error("Proposed video mode not supported on device %s\n", utf8_device);
@@ -1303,7 +1275,7 @@ int renderer::get_adapter_for_monitor()
HMONITOR curmonitor = (*d3dintf->d3d.get_adapter_monitor)(d3dintf, adapternum);
// if we match the proposed monitor, this is it
- if (curmonitor == m_window->m_monitor->handle)
+ if (curmonitor == window().m_monitor->handle)
{
return adapternum;
}
@@ -1326,7 +1298,7 @@ void renderer::pick_best_mode()
float best_score = 0.0f;
// determine the refresh rate of the primary screen
- const screen_device *primary_screen = m_window->machine().config().first_screen();
+ const screen_device *primary_screen = window().machine().config().first_screen();
if (primary_screen != NULL)
{
target_refresh = ATTOSECONDS_TO_HZ(primary_screen->refresh_attoseconds());
@@ -1336,7 +1308,7 @@ void renderer::pick_best_mode()
// note: technically we should not be calling this from an alternate window
// thread; however, it is only done during init time, and the init code on
// the main thread is waiting for us to finish, so it is safe to do so here
- m_window->m_target->compute_minimum_size(minwidth, minheight);
+ window().m_target->compute_minimum_size(minwidth, minheight);
// use those as the target for now
INT32 target_width = minwidth;
@@ -1371,7 +1343,7 @@ void renderer::pick_best_mode()
size_score *= 0.1f;
// if we're looking for a particular mode, that's a winner
- if (mode.Width == m_window->m_maxwidth && mode.Height == m_window->m_maxheight)
+ if (mode.Width == window().m_maxwidth && mode.Height == window().m_maxheight)
size_score = 2.0f;
// compute refresh score
@@ -1382,7 +1354,7 @@ void renderer::pick_best_mode()
refresh_score *= 0.1f;
// if we're looking for a particular refresh, make sure it matches
- if (mode.RefreshRate == m_window->m_refresh)
+ if (mode.RefreshRate == window().m_refresh)
refresh_score = 2.0f;
// weight size and refresh equally
@@ -1412,19 +1384,19 @@ int renderer::update_window_size()
{
// get the current window bounds
RECT client;
- GetClientRectExceptMenu(m_window->m_hwnd, &client, m_window->m_fullscreen);
+ GetClientRectExceptMenu(window().m_hwnd, &client, window().m_fullscreen);
// if we have a device and matching width/height, nothing to do
if (m_device != NULL && rect_width(&client) == m_width && rect_height(&client) == m_height)
{
// clear out any pending resizing if the area didn't change
- if (m_window->m_resize_state == RESIZE_STATE_PENDING)
- m_window->m_resize_state = RESIZE_STATE_NORMAL;
+ if (window().m_resize_state == RESIZE_STATE_PENDING)
+ window().m_resize_state = RESIZE_STATE_NORMAL;
return FALSE;
}
// if we're in the middle of resizing, leave it alone as well
- if (m_window->m_resize_state == RESIZE_STATE_RESIZING)
+ if (window().m_resize_state == RESIZE_STATE_RESIZING)
return FALSE;
// set the new bounds and create the device again
@@ -1434,7 +1406,7 @@ int renderer::update_window_size()
return FALSE;
// reset the resize state to normal, and indicate we made a change
- m_window->m_resize_state = RESIZE_STATE_NORMAL;
+ window().m_resize_state = RESIZE_STATE_NORMAL;
return TRUE;
}
@@ -1444,7 +1416,7 @@ int renderer::update_window_size()
void renderer::batch_vectors()
{
- windows_options &options = downcast<windows_options &>(m_window->machine().options());
+ windows_options &options = downcast<windows_options &>(window().machine().options());
int vector_size = (options.antialias() ? 24 : 6);
m_vectorbatch = mesh_alloc(m_line_count * vector_size);
@@ -1454,7 +1426,7 @@ void renderer::batch_vectors()
int line_index = 0;
float period = options.screen_vector_time_period();
UINT32 cached_flags = 0;
- for (render_primitive *prim = m_window->m_primlist->first(); prim != NULL; prim = prim->next())
+ for (render_primitive *prim = window().m_primlist->first(); prim != NULL; prim = prim->next())
{
switch (prim->type)
{
diff --git a/src/osd/windows/drawd3d.h b/src/osd/windows/drawd3d.h
index 57a6e2fd264..6bcf248b0dd 100644
--- a/src/osd/windows/drawd3d.h
+++ b/src/osd/windows/drawd3d.h
@@ -95,12 +95,20 @@ public:
};
/* renderer is the information about Direct3D for the current screen */
-class renderer
+class renderer : public osd_renderer
{
public:
- renderer() { }
+ //renderer() { }
renderer(win_window_info *window);
- ~renderer();
+ virtual ~renderer();
+
+ virtual int init();
+ virtual render_primitive_list *get_primitives();
+ virtual int draw(HDC dc, int update);
+ virtual void save();
+ virtual void record();
+ virtual void toggle_fsfx();
+ virtual void destroy();
int initialize();
@@ -148,8 +156,6 @@ public:
int get_height() { return m_height; }
int get_refresh() { return m_refresh; }
- win_window_info * get_window() { return m_window; }
-
device * get_device() { return m_device; }
present_parameters * get_presentation() { return &m_presentation; }
@@ -181,8 +187,6 @@ private:
int m_refresh; // current refresh rate
int m_create_error_count; // number of consecutive create errors
- win_window_info * m_window; // current window info
-
device * m_device; // pointer to the Direct3DDevice object
int m_gamma_supported; // is full screen gamma supported?
present_parameters m_presentation; // set of presentation parameters
diff --git a/src/osd/windows/drawdd.c b/src/osd/windows/drawdd.c
index 7d07aab8c6e..5dd81b6d373 100644
--- a/src/osd/windows/drawdd.c
+++ b/src/osd/windows/drawdd.c
@@ -36,12 +36,73 @@ typedef HRESULT (WINAPI *directdrawenumerateex_ptr)(LPDDENUMCALLBACKEXA lpCallba
/* dd_info is the information about DirectDraw for the current screen */
-struct dd_info
+class renderer_dd : public osd_renderer
{
- GUID adapter; // current display adapter
- GUID * adapter_ptr; // pointer to current display adapter
+public:
+ renderer_dd(win_window_info *window)
+ : osd_renderer(window, FLAG_NONE),
+ //adapter(0),
+ adapter_ptr(NULL),
+ clearouter(0),
+ blitwidth(0), blitheight(0),
+ //lastdest
+ ddraw(NULL),
+ primary(NULL),
+ back(NULL),
+ blit(NULL),
+ clipper(NULL),
+ gamma(NULL),
+ //DDSURFACEDESC2 primarydesc;
+ //DDSURFACEDESC2 blitdesc;
+ //DDSURFACEDESC2 origmode;
+ //ddcaps(0),
+ //helcaps(0),
+ membuffer(NULL),
+ membuffersize(NULL)
+ { }
+
+ virtual ~renderer_dd() { }
+
+ virtual int init();
+ virtual render_primitive_list *get_primitives();
+ virtual int draw(HDC dc, int update);
+ virtual void save() {};
+ virtual void record() {};
+ virtual void toggle_fsfx() {};
+ virtual void destroy();
+
int width, height; // current width, height
int refresh; // current refresh rate
+
+private:
+
+ inline void update_outer_rects();
+
+ // surface management
+ int ddraw_create();
+ int ddraw_create_surfaces();
+ void ddraw_delete();
+ void ddraw_delete_surfaces();
+ int ddraw_verify_caps();
+ int ddraw_test_cooperative();
+ HRESULT create_surface(DDSURFACEDESC2 *desc, IDirectDrawSurface7 **surface, const char *type);
+ int create_clipper();
+
+ // drawing helpers
+ void compute_blit_surface_size();
+ void blit_to_primary(int srcwidth, int srcheight);
+
+ // video modes
+ int config_adapter_mode();
+ void get_adapter_for_monitor(win_monitor_info *monitor);
+ void pick_best_mode();
+
+ // various
+ void calc_fullscreen_margins(DWORD desc_width, DWORD desc_height, RECT *margins);
+
+
+ GUID adapter; // current display adapter
+ GUID * adapter_ptr; // pointer to current display adapter
int clearouter; // clear the outer areas?
INT32 blitwidth, blitheight; // current blit width/height values
@@ -79,7 +140,7 @@ struct monitor_enum_info
/* mode_enum_info holds information during a display mode enumeration */
struct mode_enum_info
{
- win_window_info * window;
+ win_window_info * window;
INT32 minimum_width, minimum_height;
INT32 target_width, target_height;
double target_refresh;
@@ -102,9 +163,9 @@ static directdrawenumerateex_ptr directdrawenumerateex;
// INLINES
//============================================================
-INLINE void update_outer_rects(dd_info *dd)
+inline void renderer_dd::update_outer_rects()
{
- dd->clearouter = (dd->back != NULL) ? 3 : 1;
+ clearouter = (back != NULL) ? 3 : 1;
}
@@ -123,37 +184,24 @@ INLINE int better_mode(int width0, int height0, int width1, int height1, float d
// core functions
static void drawdd_exit(void);
-static int drawdd_window_init(win_window_info *window);
-static void drawdd_window_destroy(win_window_info *window);
-static render_primitive_list *drawdd_window_get_primitives(win_window_info *window);
-static int drawdd_window_draw(win_window_info *window, HDC dc, int update);
-// surface management
-static int ddraw_create(win_window_info *window);
-static int ddraw_create_surfaces(win_window_info *window);
-static void ddraw_delete(win_window_info *window);
-static void ddraw_delete_surfaces(win_window_info *window);
-static int ddraw_verify_caps(dd_info *dd);
-static int ddraw_test_cooperative(win_window_info *window);
-static HRESULT create_surface(dd_info *dd, DDSURFACEDESC2 *desc, IDirectDrawSurface7 **surface, const char *type);
-static int create_clipper(win_window_info *window);
-// drawing helpers
-static void compute_blit_surface_size(win_window_info *window);
-static void blit_to_primary(win_window_info *window, int srcwidth, int srcheight);
-// video modes
-static int config_adapter_mode(win_window_info *window);
-static void get_adapter_for_monitor(dd_info *dd, win_monitor_info *monitor);
-static void pick_best_mode(win_window_info *window);
+//============================================================
+// drawnone_create
+//============================================================
+static osd_renderer *drawdd_create(win_window_info *window)
+{
+ return global_alloc(renderer_dd(window));
+}
//============================================================
// drawdd_init
//============================================================
-int drawdd_init(running_machine &machine, win_draw_callbacks *callbacks)
+int drawdd_init(running_machine &machine, osd_draw_callbacks *callbacks)
{
// dynamically grab the create function from ddraw.dll
dllhandle = LoadLibrary(TEXT("ddraw.dll"));
@@ -186,10 +234,7 @@ int drawdd_init(running_machine &machine, win_draw_callbacks *callbacks)
// fill in the callbacks
memset(callbacks, 0, sizeof(*callbacks));
callbacks->exit = drawdd_exit;
- callbacks->window_init = drawdd_window_init;
- callbacks->window_get_primitives = drawdd_window_get_primitives;
- callbacks->window_draw = drawdd_window_draw;
- callbacks->window_destroy = drawdd_window_destroy;
+ callbacks->create = drawdd_create;
osd_printf_verbose("DirectDraw: Using DirectDraw 7\n");
return 0;
@@ -213,26 +258,20 @@ static void drawdd_exit(void)
// drawdd_window_init
//============================================================
-static int drawdd_window_init(win_window_info *window)
+int renderer_dd::init()
{
- dd_info *dd;
-
- // allocate memory for our structures
- dd = global_alloc_clear(dd_info);
- window->m_drawdata = dd;
-
// configure the adapter for the mode we want
- if (config_adapter_mode(window))
+ if (config_adapter_mode())
goto error;
// create the ddraw object
- if (ddraw_create(window))
+ if (ddraw_create())
goto error;
return 0;
error:
- drawdd_window_destroy(window);
+ destroy();
osd_printf_error("Unable to initialize DirectDraw.\n");
return 1;
}
@@ -243,20 +282,10 @@ error:
// drawdd_window_destroy
//============================================================
-static void drawdd_window_destroy(win_window_info *window)
+void renderer_dd::destroy()
{
- dd_info *dd = (dd_info *)window->m_drawdata;
-
- // skip if nothing
- if (dd == NULL)
- return;
-
// delete the ddraw object
- ddraw_delete(window);
-
- // free the memory in the window
- global_free(dd);
- window->m_drawdata = NULL;
+ ddraw_delete();
}
@@ -265,15 +294,13 @@ static void drawdd_window_destroy(win_window_info *window)
// drawdd_window_get_primitives
//============================================================
-static render_primitive_list *drawdd_window_get_primitives(win_window_info *window)
+render_primitive_list *renderer_dd::get_primitives()
{
- dd_info *dd = (dd_info *)window->m_drawdata;
-
- compute_blit_surface_size(window);
- window->m_target->set_bounds(dd->blitwidth, dd->blitheight, 0);
- window->m_target->set_max_update_rate((dd->refresh == 0) ? dd->origmode.dwRefreshRate : dd->refresh);
+ compute_blit_surface_size();
+ window().m_target->set_bounds(blitwidth, blitheight, 0);
+ window().m_target->set_max_update_rate((refresh == 0) ? origmode.dwRefreshRate : refresh);
- return &window->m_target->get_primitives();
+ return &window().m_target->get_primitives();
}
@@ -282,39 +309,34 @@ static render_primitive_list *drawdd_window_get_primitives(win_window_info *wind
// drawdd_window_draw
//============================================================
-static int drawdd_window_draw(win_window_info *window, HDC dc, int update)
+int renderer_dd::draw(HDC dc, int update)
{
- dd_info *dd = (dd_info *)window->m_drawdata;
render_primitive *prim;
int usemembuffer = FALSE;
HRESULT result;
- // if we haven't been created, just punt
- if (dd == NULL)
- return 1;
-
// if we're updating, remember to erase the outer stuff
if (update)
- update_outer_rects(dd);
+ update_outer_rects();
// if we have a ddraw object, check the cooperative level
- if (ddraw_test_cooperative(window))
+ if (ddraw_test_cooperative())
return 1;
// get the size; if we're too small, delete the existing surfaces
- if (dd->blitwidth > dd->blitdesc.dwWidth || dd->blitheight > dd->blitdesc.dwHeight)
- ddraw_delete_surfaces(window);
+ if (blitwidth > blitdesc.dwWidth || blitheight > blitdesc.dwHeight)
+ ddraw_delete_surfaces();
// if we need to create surfaces, do it now
- if (dd->blit == NULL && ddraw_create_surfaces(window) != 0)
+ if (blit == NULL && ddraw_create_surfaces() != 0)
return 1;
// select our surface and lock it
- result = IDirectDrawSurface7_Lock(dd->blit, NULL, &dd->blitdesc, DDLOCK_WAIT, NULL);
+ result = IDirectDrawSurface7_Lock(blit, NULL, &blitdesc, DDLOCK_WAIT, NULL);
if (result == DDERR_SURFACELOST)
{
osd_printf_verbose("DirectDraw: Lost surfaces; deleting and retrying next frame\n");
- ddraw_delete_surfaces(window);
+ ddraw_delete_surfaces();
return 1;
}
if (result != DD_OK)
@@ -324,10 +346,10 @@ static int drawdd_window_draw(win_window_info *window, HDC dc, int update)
}
// render to it
- window->m_primlist->acquire_lock();
+ window().m_primlist->acquire_lock();
// scan the list of primitives for tricky stuff
- for (prim = window->m_primlist->first(); prim != NULL; prim = prim->next())
+ for (prim = window().m_primlist->first(); prim != NULL; prim = prim->next())
if (PRIMFLAG_GET_BLENDMODE(prim->flags) != BLENDMODE_NONE ||
(prim->texture.base != NULL && PRIMFLAG_GET_TEXFORMAT(prim->flags) == TEXFORMAT_ARGB32))
{
@@ -341,32 +363,32 @@ static int drawdd_window_draw(win_window_info *window, HDC dc, int update)
int x, y;
// based on the target format, use one of our standard renderers
- switch (dd->blitdesc.ddpfPixelFormat.dwRBitMask)
+ switch (blitdesc.ddpfPixelFormat.dwRBitMask)
{
- case 0x00ff0000: software_renderer<UINT32, 0,0,0, 16,8,0>::draw_primitives(*window->m_primlist, dd->membuffer, dd->blitwidth, dd->blitheight, dd->blitwidth); break;
- case 0x000000ff: software_renderer<UINT32, 0,0,0, 0,8,16>::draw_primitives(*window->m_primlist, dd->membuffer, dd->blitwidth, dd->blitheight, dd->blitwidth); break;
- case 0xf800: software_renderer<UINT16, 3,2,3, 11,5,0>::draw_primitives(*window->m_primlist, dd->membuffer, dd->blitwidth, dd->blitheight, dd->blitwidth); break;
- case 0x7c00: software_renderer<UINT16, 3,3,3, 10,5,0>::draw_primitives(*window->m_primlist, dd->membuffer, dd->blitwidth, dd->blitheight, dd->blitwidth); break;
+ case 0x00ff0000: software_renderer<UINT32, 0,0,0, 16,8,0>::draw_primitives(*window().m_primlist, membuffer, blitwidth, blitheight, blitwidth); break;
+ case 0x000000ff: software_renderer<UINT32, 0,0,0, 0,8,16>::draw_primitives(*window().m_primlist, membuffer, blitwidth, blitheight, blitwidth); break;
+ case 0xf800: software_renderer<UINT16, 3,2,3, 11,5,0>::draw_primitives(*window().m_primlist, membuffer, blitwidth, blitheight, blitwidth); break;
+ case 0x7c00: software_renderer<UINT16, 3,3,3, 10,5,0>::draw_primitives(*window().m_primlist, membuffer, blitwidth, blitheight, blitwidth); break;
default:
- osd_printf_verbose("DirectDraw: Unknown target mode: R=%08X G=%08X B=%08X\n", (int)dd->blitdesc.ddpfPixelFormat.dwRBitMask, (int)dd->blitdesc.ddpfPixelFormat.dwGBitMask, (int)dd->blitdesc.ddpfPixelFormat.dwBBitMask);
+ osd_printf_verbose("DirectDraw: Unknown target mode: R=%08X G=%08X B=%08X\n", (int)blitdesc.ddpfPixelFormat.dwRBitMask, (int)blitdesc.ddpfPixelFormat.dwGBitMask, (int)blitdesc.ddpfPixelFormat.dwBBitMask);
break;
}
// handle copying to both 16bpp and 32bpp destinations
- for (y = 0; y < dd->blitheight; y++)
+ for (y = 0; y < blitheight; y++)
{
- if (dd->blitdesc.ddpfPixelFormat.dwRGBBitCount == 32)
+ if (blitdesc.ddpfPixelFormat.dwRGBBitCount == 32)
{
- UINT32 *src = (UINT32 *)dd->membuffer + y * dd->blitwidth;
- UINT32 *dst = (UINT32 *)((UINT8 *)dd->blitdesc.lpSurface + y * dd->blitdesc.lPitch);
- for (x = 0; x < dd->blitwidth; x++)
+ UINT32 *src = (UINT32 *)membuffer + y * blitwidth;
+ UINT32 *dst = (UINT32 *)((UINT8 *)blitdesc.lpSurface + y * blitdesc.lPitch);
+ for (x = 0; x < blitwidth; x++)
*dst++ = *src++;
}
- else if (dd->blitdesc.ddpfPixelFormat.dwRGBBitCount == 16)
+ else if (blitdesc.ddpfPixelFormat.dwRGBBitCount == 16)
{
- UINT16 *src = (UINT16 *)dd->membuffer + y * dd->blitwidth;
- UINT16 *dst = (UINT16 *)((UINT8 *)dd->blitdesc.lpSurface + y * dd->blitdesc.lPitch);
- for (x = 0; x < dd->blitwidth; x++)
+ UINT16 *src = (UINT16 *)membuffer + y * blitwidth;
+ UINT16 *dst = (UINT16 *)((UINT8 *)blitdesc.lpSurface + y * blitdesc.lPitch);
+ for (x = 0; x < blitwidth; x++)
*dst++ = *src++;
}
}
@@ -377,32 +399,32 @@ static int drawdd_window_draw(win_window_info *window, HDC dc, int update)
else
{
// based on the target format, use one of our standard renderers
- switch (dd->blitdesc.ddpfPixelFormat.dwRBitMask)
+ switch (blitdesc.ddpfPixelFormat.dwRBitMask)
{
- case 0x00ff0000: software_renderer<UINT32, 0,0,0, 16,8,0, true>::draw_primitives(*window->m_primlist, dd->blitdesc.lpSurface, dd->blitwidth, dd->blitheight, dd->blitdesc.lPitch / 4); break;
- case 0x000000ff: software_renderer<UINT32, 0,0,0, 0,8,16, true>::draw_primitives(*window->m_primlist, dd->blitdesc.lpSurface, dd->blitwidth, dd->blitheight, dd->blitdesc.lPitch / 4); break;
- case 0xf800: software_renderer<UINT16, 3,2,3, 11,5,0, true>::draw_primitives(*window->m_primlist, dd->blitdesc.lpSurface, dd->blitwidth, dd->blitheight, dd->blitdesc.lPitch / 2); break;
- case 0x7c00: software_renderer<UINT16, 3,3,3, 10,5,0, true>::draw_primitives(*window->m_primlist, dd->blitdesc.lpSurface, dd->blitwidth, dd->blitheight, dd->blitdesc.lPitch / 2); break;
+ case 0x00ff0000: software_renderer<UINT32, 0,0,0, 16,8,0, true>::draw_primitives(*window().m_primlist, blitdesc.lpSurface, blitwidth, blitheight, blitdesc.lPitch / 4); break;
+ case 0x000000ff: software_renderer<UINT32, 0,0,0, 0,8,16, true>::draw_primitives(*window().m_primlist, blitdesc.lpSurface, blitwidth, blitheight, blitdesc.lPitch / 4); break;
+ case 0xf800: software_renderer<UINT16, 3,2,3, 11,5,0, true>::draw_primitives(*window().m_primlist, blitdesc.lpSurface, blitwidth, blitheight, blitdesc.lPitch / 2); break;
+ case 0x7c00: software_renderer<UINT16, 3,3,3, 10,5,0, true>::draw_primitives(*window().m_primlist, blitdesc.lpSurface, blitwidth, blitheight, blitdesc.lPitch / 2); break;
default:
- osd_printf_verbose("DirectDraw: Unknown target mode: R=%08X G=%08X B=%08X\n", (int)dd->blitdesc.ddpfPixelFormat.dwRBitMask, (int)dd->blitdesc.ddpfPixelFormat.dwGBitMask, (int)dd->blitdesc.ddpfPixelFormat.dwBBitMask);
+ osd_printf_verbose("DirectDraw: Unknown target mode: R=%08X G=%08X B=%08X\n", (int)blitdesc.ddpfPixelFormat.dwRBitMask, (int)blitdesc.ddpfPixelFormat.dwGBitMask, (int)blitdesc.ddpfPixelFormat.dwBBitMask);
break;
}
}
- window->m_primlist->release_lock();
+ window().m_primlist->release_lock();
// unlock and blit
- result = IDirectDrawSurface7_Unlock(dd->blit, NULL);
+ result = IDirectDrawSurface7_Unlock(blit, NULL);
if (result != DD_OK) osd_printf_verbose("DirectDraw: Error %08X unlocking blit surface\n", (int)result);
// sync to VBLANK
- if ((video_config.waitvsync || video_config.syncrefresh) && window->machine().video().throttled() && (!window->m_fullscreen || dd->back == NULL))
+ if ((video_config.waitvsync || video_config.syncrefresh) && window().machine().video().throttled() && (!window().m_fullscreen || back == NULL))
{
- result = IDirectDraw7_WaitForVerticalBlank(dd->ddraw, DDWAITVB_BLOCKBEGIN, NULL);
+ result = IDirectDraw7_WaitForVerticalBlank(ddraw, DDWAITVB_BLOCKBEGIN, NULL);
if (result != DD_OK) osd_printf_verbose("DirectDraw: Error %08X waiting for VBLANK\n", (int)result);
}
// complete the blitting
- blit_to_primary(window, dd->blitwidth, dd->blitheight);
+ blit_to_primary(blitwidth, blitheight);
return 0;
}
@@ -412,18 +434,17 @@ static int drawdd_window_draw(win_window_info *window, HDC dc, int update)
// ddraw_create
//============================================================
-static int ddraw_create(win_window_info *window)
+int renderer_dd::ddraw_create()
{
- dd_info *dd = (dd_info *)window->m_drawdata;
HRESULT result;
int verify;
// if a device exists, free it
- if (dd->ddraw != NULL)
- ddraw_delete(window);
+ if (ddraw != NULL)
+ ddraw_delete();
// create the DirectDraw object
- result = (*directdrawcreateex)(dd->adapter_ptr, (LPVOID *)&dd->ddraw, WRAP_REFIID(IID_IDirectDraw7), NULL);
+ result = (*directdrawcreateex)(adapter_ptr, (LPVOID *)&ddraw, WRAP_REFIID(IID_IDirectDraw7), NULL);
if (result != DD_OK)
{
osd_printf_verbose("DirectDraw: Error %08X during DirectDrawCreateEx call\n", (int)result);
@@ -431,7 +452,7 @@ static int ddraw_create(win_window_info *window)
}
// verify the caps
- verify = ddraw_verify_caps(dd);
+ verify = ddraw_verify_caps();
if (verify == 2)
{
osd_printf_error("DirectDraw: Error - Device does not meet minimum requirements for DirectDraw rendering\n");
@@ -442,13 +463,13 @@ static int ddraw_create(win_window_info *window)
// set the cooperative level
// for non-window modes, we will use full screen here
- result = IDirectDraw7_SetCooperativeLevel(dd->ddraw, win_window_list->m_hwnd, DDSCL_SETFOCUSWINDOW);
+ result = IDirectDraw7_SetCooperativeLevel(ddraw, win_window_list->m_hwnd, DDSCL_SETFOCUSWINDOW);
if (result != DD_OK)
{
osd_printf_verbose("DirectDraw: Error %08X during IDirectDraw7_SetCooperativeLevel(FOCUSWINDOW) call\n", (int)result);
goto error;
}
- result = IDirectDraw7_SetCooperativeLevel(dd->ddraw, window->m_hwnd, DDSCL_SETDEVICEWINDOW | (window->m_fullscreen ? DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE : DDSCL_NORMAL));
+ result = IDirectDraw7_SetCooperativeLevel(ddraw, window().m_hwnd, DDSCL_SETDEVICEWINDOW | (window().m_fullscreen ? DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE : DDSCL_NORMAL));
if (result != DD_OK)
{
osd_printf_verbose("DirectDraw: Error %08X during IDirectDraw7_SetCooperativeLevel(DEVICEWINDOW) call\n", (int)result);
@@ -456,20 +477,20 @@ static int ddraw_create(win_window_info *window)
}
// full screen mode: set the resolution
- if (window->m_fullscreen && video_config.switchres)
+ if (window().m_fullscreen && video_config.switchres)
{
- result = IDirectDraw7_SetDisplayMode(dd->ddraw, dd->width, dd->height, 32, dd->refresh, 0);
+ result = IDirectDraw7_SetDisplayMode(ddraw, width, height, 32, refresh, 0);
if (result != DD_OK)
{
- osd_printf_verbose("DirectDraw: Error %08X attempting to set video mode %dx%d@%d call\n", (int)result, dd->width, dd->height, dd->refresh);
+ osd_printf_verbose("DirectDraw: Error %08X attempting to set video mode %dx%d@%d call\n", (int)result, width, height, refresh);
goto error;
}
}
- return ddraw_create_surfaces(window);
+ return ddraw_create_surfaces();
error:
- ddraw_delete(window);
+ ddraw_delete();
return 1;
}
@@ -479,35 +500,34 @@ error:
// ddraw_create_surfaces
//============================================================
-static int ddraw_create_surfaces(win_window_info *window)
+int renderer_dd::ddraw_create_surfaces()
{
- dd_info *dd = (dd_info *)window->m_drawdata;
HRESULT result;
// make a description of the primary surface
- memset(&dd->primarydesc, 0, sizeof(dd->primarydesc));
- dd->primarydesc.dwSize = sizeof(dd->primarydesc);
- dd->primarydesc.dwFlags = DDSD_CAPS;
- dd->primarydesc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
+ memset(&primarydesc, 0, sizeof(primarydesc));
+ primarydesc.dwSize = sizeof(primarydesc);
+ primarydesc.dwFlags = DDSD_CAPS;
+ primarydesc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
// for triple-buffered full screen mode, allocate flipping surfaces
- if (window->m_fullscreen && video_config.triplebuf)
+ if (window().m_fullscreen && video_config.triplebuf)
{
- dd->primarydesc.dwFlags |= DDSD_BACKBUFFERCOUNT;
- dd->primarydesc.ddsCaps.dwCaps |= DDSCAPS_FLIP | DDSCAPS_COMPLEX;
- dd->primarydesc.dwBackBufferCount = 2;
+ primarydesc.dwFlags |= DDSD_BACKBUFFERCOUNT;
+ primarydesc.ddsCaps.dwCaps |= DDSCAPS_FLIP | DDSCAPS_COMPLEX;
+ primarydesc.dwBackBufferCount = 2;
}
// create the primary surface and report errors
- result = create_surface(dd, &dd->primarydesc, &dd->primary, "primary");
+ result = create_surface(&primarydesc, &primary, "primary");
if (result != DD_OK) goto error;
// full screen mode: get the back surface
- dd->back = NULL;
- if (window->m_fullscreen && video_config.triplebuf)
+ back = NULL;
+ if (window().m_fullscreen && video_config.triplebuf)
{
DDSCAPS2 caps = { DDSCAPS_BACKBUFFER };
- result = IDirectDrawSurface7_GetAttachedSurface(dd->primary, &caps, &dd->back);
+ result = IDirectDrawSurface7_GetAttachedSurface(primary, &caps, &back);
if (result != DD_OK)
{
osd_printf_verbose("DirectDraw: Error %08X getting attached back surface\n", (int)result);
@@ -516,67 +536,67 @@ static int ddraw_create_surfaces(win_window_info *window)
}
// now make a description of our blit surface, based on the primary surface
- if (dd->blitwidth == 0 || dd->blitheight == 0)
- compute_blit_surface_size(window);
- dd->blitdesc = dd->primarydesc;
- dd->blitdesc.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CAPS;
- dd->blitdesc.dwWidth = dd->blitwidth;
- dd->blitdesc.dwHeight = dd->blitheight;
- dd->blitdesc.ddsCaps.dwCaps = DDSCAPS_VIDEOMEMORY;
+ if (blitwidth == 0 || blitheight == 0)
+ compute_blit_surface_size();
+ blitdesc = primarydesc;
+ blitdesc.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CAPS;
+ blitdesc.dwWidth = blitwidth;
+ blitdesc.dwHeight = blitheight;
+ blitdesc.ddsCaps.dwCaps = DDSCAPS_VIDEOMEMORY;
// then create the blit surface, fall back to system memory if video mem doesn't work
- result = create_surface(dd, &dd->blitdesc, &dd->blit, "blit");
+ result = create_surface(&blitdesc, &blit, "blit");
if (result != DD_OK)
{
- dd->blitdesc.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY;
- result = create_surface(dd, &dd->blitdesc, &dd->blit, "blit");
+ blitdesc.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY;
+ result = create_surface(&blitdesc, &blit, "blit");
}
if (result != DD_OK) goto error;
// create a memory buffer for offscreen drawing
- if (dd->membuffersize < dd->blitwidth * dd->blitheight * 4)
+ if (membuffersize < blitwidth * blitheight * 4)
{
- dd->membuffersize = dd->blitwidth * dd->blitheight * 4;
- global_free_array(dd->membuffer);
- dd->membuffer = global_alloc_array(UINT8, dd->membuffersize);
+ membuffersize = blitwidth * blitheight * 4;
+ global_free_array(membuffer);
+ membuffer = global_alloc_array(UINT8, membuffersize);
}
- if (dd->membuffer == NULL)
+ if (membuffer == NULL)
goto error;
// create a clipper for windowed mode
- if (!window->m_fullscreen && create_clipper(window))
+ if (!window().m_fullscreen && create_clipper())
goto error;
// full screen mode: set the gamma
- if (window->m_fullscreen)
+ if (window().m_fullscreen)
{
// only set the gamma if it's not 1.0f
- windows_options &options = downcast<windows_options &>(window->machine().options());
+ windows_options &options = downcast<windows_options &>(window().machine().options());
float brightness = options.full_screen_brightness();
float contrast = options.full_screen_contrast();
- float gamma = options.full_screen_gamma();
- if (brightness != 1.0f || contrast != 1.0f || gamma != 1.0f)
+ float fgamma = options.full_screen_gamma();
+ if (brightness != 1.0f || contrast != 1.0f || fgamma != 1.0f)
{
// see if we can get a GammaControl object
- result = IDirectDrawSurface_QueryInterface(dd->primary, WRAP_REFIID(IID_IDirectDrawGammaControl), (void **)&dd->gamma);
+ result = IDirectDrawSurface_QueryInterface(primary, WRAP_REFIID(IID_IDirectDrawGammaControl), (void **)&gamma);
if (result != DD_OK)
{
osd_printf_warning("DirectDraw: Warning - device does not support full screen gamma correction.\n");
- dd->gamma = NULL;
+ this->gamma = NULL;
}
// proceed if we can
- if (dd->gamma != NULL)
+ if (this->gamma != NULL)
{
DDGAMMARAMP ramp;
int i;
// create a standard ramp and set it
for (i = 0; i < 256; i++)
- ramp.red[i] = ramp.green[i] = ramp.blue[i] = apply_brightness_contrast_gamma(i, brightness, contrast, gamma) << 8;
+ ramp.red[i] = ramp.green[i] = ramp.blue[i] = apply_brightness_contrast_gamma(i, brightness, contrast, fgamma) << 8;
// attempt to set it
- result = IDirectDrawGammaControl_SetGammaRamp(dd->gamma, 0, &ramp);
+ result = IDirectDrawGammaControl_SetGammaRamp(this->gamma, 0, &ramp);
if (result != DD_OK)
osd_printf_verbose("DirectDraw: Error %08X attempting to set gamma correction.\n", (int)result);
}
@@ -584,11 +604,11 @@ static int ddraw_create_surfaces(win_window_info *window)
}
// force some updates
- update_outer_rects(dd);
+ update_outer_rects();
return 0;
error:
- ddraw_delete_surfaces(window);
+ ddraw_delete_surfaces();
return 1;
}
@@ -598,25 +618,23 @@ error:
// ddraw_delete
//============================================================
-static void ddraw_delete(win_window_info *window)
+void renderer_dd::ddraw_delete()
{
- dd_info *dd = (dd_info *)window->m_drawdata;
-
// free surfaces
- ddraw_delete_surfaces(window);
+ ddraw_delete_surfaces();
// restore resolutions
- if (dd->ddraw != NULL)
- IDirectDraw7_RestoreDisplayMode(dd->ddraw);
+ if (ddraw != NULL)
+ IDirectDraw7_RestoreDisplayMode(ddraw);
// reset cooperative level
- if (dd->ddraw != NULL && window->m_hwnd != NULL)
- IDirectDraw7_SetCooperativeLevel(dd->ddraw, window->m_hwnd, DDSCL_NORMAL);
+ if (ddraw != NULL && window().m_hwnd != NULL)
+ IDirectDraw7_SetCooperativeLevel(ddraw, window().m_hwnd, DDSCL_NORMAL);
// release the DirectDraw object itself
- if (dd->ddraw != NULL)
- IDirectDraw7_Release(dd->ddraw);
- dd->ddraw = NULL;
+ if (ddraw != NULL)
+ IDirectDraw7_Release(ddraw);
+ ddraw = NULL;
}
@@ -625,39 +643,37 @@ static void ddraw_delete(win_window_info *window)
// ddraw_delete_surfaces
//============================================================
-static void ddraw_delete_surfaces(win_window_info *window)
+void renderer_dd::ddraw_delete_surfaces()
{
- dd_info *dd = (dd_info *)window->m_drawdata;
-
// release the gamma control
- if (dd->gamma != NULL)
- IDirectDrawGammaControl_Release(dd->gamma);
- dd->gamma = NULL;
+ if (gamma != NULL)
+ IDirectDrawGammaControl_Release(gamma);
+ gamma = NULL;
// release the clipper
- if (dd->clipper != NULL)
- IDirectDrawClipper_Release(dd->clipper);
- dd->clipper = NULL;
+ if (clipper != NULL)
+ IDirectDrawClipper_Release(clipper);
+ clipper = NULL;
// free the memory buffer
- global_free_array(dd->membuffer);
- dd->membuffer = NULL;
- dd->membuffersize = 0;
+ global_free_array(membuffer);
+ membuffer = NULL;
+ membuffersize = 0;
// release the blit surface
- if (dd->blit != NULL)
- IDirectDrawSurface7_Release(dd->blit);
- dd->blit = NULL;
+ if (blit != NULL)
+ IDirectDrawSurface7_Release(blit);
+ blit = NULL;
// release the back surface
- if (dd->back != NULL)
- IDirectDrawSurface7_Release(dd->back);
- dd->back = NULL;
+ if (back != NULL)
+ IDirectDrawSurface7_Release(back);
+ back = NULL;
// release the primary surface
- if (dd->primary != NULL)
- IDirectDrawSurface7_Release(dd->primary);
- dd->primary = NULL;
+ if (primary != NULL)
+ IDirectDrawSurface7_Release(primary);
+ primary = NULL;
}
@@ -666,15 +682,15 @@ static void ddraw_delete_surfaces(win_window_info *window)
// ddraw_verify_caps
//============================================================
-static int ddraw_verify_caps(dd_info *dd)
+int renderer_dd::ddraw_verify_caps()
{
int retval = 0;
HRESULT result;
// get the capabilities
- dd->ddcaps.dwSize = sizeof(dd->ddcaps);
- dd->helcaps.dwSize = sizeof(dd->helcaps);
- result = IDirectDraw7_GetCaps(dd->ddraw, &dd->ddcaps, &dd->helcaps);
+ ddcaps.dwSize = sizeof(ddcaps);
+ helcaps.dwSize = sizeof(helcaps);
+ result = IDirectDraw7_GetCaps(ddraw, &ddcaps, &helcaps);
if (result != DD_OK)
{
osd_printf_verbose("DirectDraw: Error %08X during IDirectDraw7_GetCaps call\n", (int)result);
@@ -682,7 +698,7 @@ static int ddraw_verify_caps(dd_info *dd)
}
// determine if hardware stretching is available
- if ((dd->ddcaps.dwCaps & DDCAPS_BLTSTRETCH) == 0)
+ if ((ddcaps.dwCaps & DDCAPS_BLTSTRETCH) == 0)
{
osd_printf_verbose("DirectDraw: Warning - Device does not support hardware stretching\n");
retval = 1;
@@ -697,26 +713,25 @@ static int ddraw_verify_caps(dd_info *dd)
// ddraw_test_cooperative
//============================================================
-static int ddraw_test_cooperative(win_window_info *window)
+int renderer_dd::ddraw_test_cooperative()
{
- dd_info *dd = (dd_info *)window->m_drawdata;
HRESULT result;
// check our current status; if we lost the device, punt to GDI
- result = IDirectDraw7_TestCooperativeLevel(dd->ddraw);
+ result = IDirectDraw7_TestCooperativeLevel(ddraw);
switch (result)
{
// punt to GDI if someone else has exclusive mode
case DDERR_NOEXCLUSIVEMODE:
case DDERR_EXCLUSIVEMODEALREADYSET:
- ddraw_delete_surfaces(window);
+ ddraw_delete_surfaces();
return 1;
// if we're ok, but we don't have a primary surface, create one
default:
case DD_OK:
- if (dd->primary == NULL)
- return ddraw_create_surfaces(window);
+ if (primary == NULL)
+ return ddraw_create_surfaces();
return 0;
}
}
@@ -727,12 +742,12 @@ static int ddraw_test_cooperative(win_window_info *window)
// create_surface
//============================================================
-static HRESULT create_surface(dd_info *dd, DDSURFACEDESC2 *desc, IDirectDrawSurface7 **surface, const char *type)
+HRESULT renderer_dd::create_surface(DDSURFACEDESC2 *desc, IDirectDrawSurface7 **surface, const char *type)
{
HRESULT result;
// create the surface as requested
- result = IDirectDraw7_CreateSurface(dd->ddraw, desc, surface, NULL);
+ result = IDirectDraw7_CreateSurface(ddraw, desc, surface, NULL);
if (result != DD_OK)
{
osd_printf_verbose("DirectDraw: Error %08X creating %s surface\n", (int)result, type);
@@ -767,13 +782,12 @@ static HRESULT create_surface(dd_info *dd, DDSURFACEDESC2 *desc, IDirectDrawSurf
// create_clipper
//============================================================
-static int create_clipper(win_window_info *window)
+int renderer_dd::create_clipper()
{
- dd_info *dd = (dd_info *)window->m_drawdata;
HRESULT result;
// create a clipper for the primary surface
- result = IDirectDraw7_CreateClipper(dd->ddraw, 0, &dd->clipper, NULL);
+ result = IDirectDraw7_CreateClipper(ddraw, 0, &clipper, NULL);
if (result != DD_OK)
{
osd_printf_verbose("DirectDraw: Error %08X creating clipper\n", (int)result);
@@ -781,7 +795,7 @@ static int create_clipper(win_window_info *window)
}
// set the clipper's hwnd
- result = IDirectDrawClipper_SetHWnd(dd->clipper, 0, window->m_hwnd);
+ result = IDirectDrawClipper_SetHWnd(clipper, 0, window().m_hwnd);
if (result != DD_OK)
{
osd_printf_verbose("DirectDraw: Error %08X setting clipper hwnd\n", (int)result);
@@ -789,7 +803,7 @@ static int create_clipper(win_window_info *window)
}
// set the clipper on the primary surface
- result = IDirectDrawSurface7_SetClipper(dd->primary, dd->clipper);
+ result = IDirectDrawSurface7_SetClipper(primary, clipper);
if (result != DD_OK)
{
osd_printf_verbose("DirectDraw: Error %08X setting clipper on primary surface\n", (int)result);
@@ -804,18 +818,17 @@ static int create_clipper(win_window_info *window)
// compute_blit_surface_size
//============================================================
-static void compute_blit_surface_size(win_window_info *window)
+void renderer_dd::compute_blit_surface_size()
{
- dd_info *dd = (dd_info *)window->m_drawdata;
INT32 newwidth, newheight;
int xscale, yscale;
RECT client;
// start with the minimum size
- window->m_target->compute_minimum_size(newwidth, newheight);
+ window().m_target->compute_minimum_size(newwidth, newheight);
// get the window's client rectangle
- GetClientRect(window->m_hwnd, &client);
+ GetClientRect(window().m_hwnd, &client);
// hardware stretch case: apply prescale
if (video_config.hwstretch)
@@ -841,8 +854,8 @@ static void compute_blit_surface_size(win_window_info *window)
// compute the appropriate visible area if we're trying to keepaspect
if (video_config.keepaspect)
{
- win_monitor_info *monitor = winwindow_video_window_monitor(window, NULL);
- window->m_target->compute_visible_area(target_width, target_height, monitor->get_aspect(), window->m_target->orientation(), target_width, target_height);
+ win_monitor_info *monitor = winwindow_video_window_monitor(&window(), NULL);
+ window().m_target->compute_visible_area(target_width, target_height, monitor->get_aspect(), window().m_target->orientation(), target_width, target_height);
desired_aspect = (float)target_width / (float)target_height;
}
@@ -884,14 +897,14 @@ static void compute_blit_surface_size(win_window_info *window)
// apply the final scale
newwidth *= xscale;
newheight *= yscale;
- if (newwidth != dd->blitwidth || newheight != dd->blitheight)
+ if (newwidth != blitwidth || newheight != blitheight)
{
// force some updates
- update_outer_rects(dd);
+ update_outer_rects();
osd_printf_verbose("DirectDraw: New blit size = %dx%d\n", newwidth, newheight);
}
- dd->blitwidth = newwidth;
- dd->blitheight = newheight;
+ blitwidth = newwidth;
+ blitheight = newheight;
}
@@ -900,14 +913,14 @@ static void compute_blit_surface_size(win_window_info *window)
// calc_fullscreen_margins
//============================================================
-static void calc_fullscreen_margins(win_window_info *window, DWORD desc_width, DWORD desc_height, RECT *margins)
+void renderer_dd::calc_fullscreen_margins(DWORD desc_width, DWORD desc_height, RECT *margins)
{
margins->left = 0;
margins->top = 0;
margins->right = desc_width;
margins->bottom = desc_height;
- if (win_has_menu(window))
+ if (win_has_menu(&window()))
{
static int height_with_menubar = 0;
if (height_with_menubar == 0)
@@ -928,11 +941,10 @@ static void calc_fullscreen_margins(win_window_info *window, DWORD desc_width, D
// blit_to_primary
//============================================================
-static void blit_to_primary(win_window_info *window, int srcwidth, int srcheight)
+void renderer_dd::blit_to_primary(int srcwidth, int srcheight)
{
- dd_info *dd = (dd_info *)window->m_drawdata;
- IDirectDrawSurface7 *target = (dd->back != NULL) ? dd->back : dd->primary;
- win_monitor_info *monitor = winwindow_video_window_monitor(window, NULL);
+ IDirectDrawSurface7 *target = (back != NULL) ? back : primary;
+ win_monitor_info *monitor = winwindow_video_window_monitor(&window(), NULL);
DDBLTFX blitfx = { sizeof(DDBLTFX) };
RECT clear, outer, dest, source;
INT32 dstwidth, dstheight;
@@ -944,11 +956,11 @@ static void blit_to_primary(win_window_info *window, int srcwidth, int srcheight
source.bottom = srcheight;
// compute outer rect -- windowed version
- if (!window->m_fullscreen)
+ if (!window().m_fullscreen)
{
- GetClientRect(window->m_hwnd, &outer);
- ClientToScreen(window->m_hwnd, &((LPPOINT)&outer)[0]);
- ClientToScreen(window->m_hwnd, &((LPPOINT)&outer)[1]);
+ GetClientRect(window().m_hwnd, &outer);
+ ClientToScreen(window().m_hwnd, &((LPPOINT)&outer)[0]);
+ ClientToScreen(window().m_hwnd, &((LPPOINT)&outer)[1]);
// adjust to be relative to the monitor
outer.left -= monitor->info.rcMonitor.left;
@@ -960,7 +972,7 @@ static void blit_to_primary(win_window_info *window, int srcwidth, int srcheight
// compute outer rect -- full screen version
else
{
- calc_fullscreen_margins(window, dd->primarydesc.dwWidth, dd->primarydesc.dwHeight, &outer);
+ calc_fullscreen_margins(primarydesc.dwWidth, primarydesc.dwHeight, &outer);
}
// if we're respecting the aspect ratio, we need to adjust to fit
@@ -987,7 +999,7 @@ static void blit_to_primary(win_window_info *window, int srcwidth, int srcheight
else if (video_config.keepaspect)
{
// compute the appropriate visible area
- window->m_target->compute_visible_area(rect_width(&outer), rect_height(&outer), monitor->get_aspect(), window->m_target->orientation(), dstwidth, dstheight);
+ window().m_target->compute_visible_area(rect_width(&outer), rect_height(&outer), monitor->get_aspect(), window().m_target->orientation(), dstwidth, dstheight);
}
// center within
@@ -997,16 +1009,16 @@ static void blit_to_primary(win_window_info *window, int srcwidth, int srcheight
dest.bottom = dest.top + dstheight;
// compare against last destination; if different, force a redraw
- if (dest.left != dd->lastdest.left || dest.right != dd->lastdest.right || dest.top != dd->lastdest.top || dest.bottom != dd->lastdest.bottom)
+ if (dest.left != lastdest.left || dest.right != lastdest.right || dest.top != lastdest.top || dest.bottom != lastdest.bottom)
{
- dd->lastdest = dest;
- update_outer_rects(dd);
+ lastdest = dest;
+ update_outer_rects();
}
// clear outer rects if we need to
- if (dd->clearouter != 0)
+ if (clearouter != 0)
{
- dd->clearouter--;
+ clearouter--;
// clear the left edge
if (dest.left > outer.left)
@@ -1046,13 +1058,13 @@ static void blit_to_primary(win_window_info *window, int srcwidth, int srcheight
}
// do the blit
- result = IDirectDrawSurface7_Blt(target, &dest, dd->blit, &source, DDBLT_WAIT, NULL);
+ result = IDirectDrawSurface7_Blt(target, &dest, blit, &source, DDBLT_WAIT, NULL);
if (result != DD_OK) osd_printf_verbose("DirectDraw: Error %08X blitting to the screen\n", (int)result);
// page flip if triple buffered
- if (window->m_fullscreen && dd->back != NULL)
+ if (window().m_fullscreen && back != NULL)
{
- result = IDirectDrawSurface7_Flip(dd->primary, NULL, DDFLIP_WAIT);
+ result = IDirectDrawSurface7_Flip(primary, NULL, DDFLIP_WAIT);
if (result != DD_OK) osd_printf_verbose("DirectDraw: Error %08X waiting for VBLANK\n", (int)result);
}
}
@@ -1063,17 +1075,16 @@ static void blit_to_primary(win_window_info *window, int srcwidth, int srcheight
// config_adapter_mode
//============================================================
-static int config_adapter_mode(win_window_info *window)
+int renderer_dd::config_adapter_mode()
{
DDDEVICEIDENTIFIER2 identifier;
- dd_info *dd = (dd_info *)window->m_drawdata;
HRESULT result;
// choose the monitor number
- get_adapter_for_monitor(dd, window->m_monitor);
+ get_adapter_for_monitor(window().m_monitor);
// create a temporary DirectDraw object
- result = (*directdrawcreateex)(dd->adapter_ptr, (LPVOID *)&dd->ddraw, WRAP_REFIID(IID_IDirectDraw7), NULL);
+ result = (*directdrawcreateex)(adapter_ptr, (LPVOID *)&ddraw, WRAP_REFIID(IID_IDirectDraw7), NULL);
if (result != DD_OK)
{
osd_printf_verbose("DirectDraw: Error %08X during DirectDrawCreateEx call\n", (int)result);
@@ -1081,7 +1092,7 @@ static int config_adapter_mode(win_window_info *window)
}
// get the identifier
- result = IDirectDraw7_GetDeviceIdentifier(dd->ddraw, &identifier, 0);
+ result = IDirectDraw7_GetDeviceIdentifier(ddraw, &identifier, 0);
if (result != DD_OK)
{
osd_printf_error("Error getting identifier for device\n");
@@ -1090,37 +1101,37 @@ static int config_adapter_mode(win_window_info *window)
osd_printf_verbose("DirectDraw: Configuring device %s\n", identifier.szDescription);
// get the current display mode
- memset(&dd->origmode, 0, sizeof(dd->origmode));
- dd->origmode.dwSize = sizeof(dd->origmode);
- result = IDirectDraw7_GetDisplayMode(dd->ddraw, &dd->origmode);
+ memset(&origmode, 0, sizeof(origmode));
+ origmode.dwSize = sizeof(origmode);
+ result = IDirectDraw7_GetDisplayMode(ddraw, &origmode);
if (result != DD_OK)
{
osd_printf_verbose("DirectDraw: Error %08X getting current display mode\n", (int)result);
- IDirectDraw7_Release(dd->ddraw);
+ IDirectDraw7_Release(ddraw);
return 1;
}
// choose a resolution: full screen mode case
- if (window->m_fullscreen)
+ if (window().m_fullscreen)
{
// default to the current mode exactly
- dd->width = dd->origmode.dwWidth;
- dd->height = dd->origmode.dwHeight;
- dd->refresh = dd->origmode.dwRefreshRate;
+ width = origmode.dwWidth;
+ height = origmode.dwHeight;
+ refresh = origmode.dwRefreshRate;
// if we're allowed to switch resolutions, override with something better
if (video_config.switchres)
- pick_best_mode(window);
+ pick_best_mode();
}
// release the DirectDraw object
- IDirectDraw7_Release(dd->ddraw);
- dd->ddraw = NULL;
+ IDirectDraw7_Release(ddraw);
+ ddraw = NULL;
// if we're not changing resolutions, make sure we have a resolution we can handle
- if (!window->m_fullscreen || !video_config.switchres)
+ if (!window().m_fullscreen || !video_config.switchres)
{
- switch (dd->origmode.ddpfPixelFormat.dwRBitMask)
+ switch (origmode.ddpfPixelFormat.dwRBitMask)
{
case 0x00ff0000:
case 0x000000ff:
@@ -1129,7 +1140,7 @@ static int config_adapter_mode(win_window_info *window)
break;
default:
- osd_printf_verbose("DirectDraw: Unknown target mode: R=%08X G=%08X B=%08X\n", (int)dd->origmode.ddpfPixelFormat.dwRBitMask, (int)dd->origmode.ddpfPixelFormat.dwGBitMask, (int)dd->origmode.ddpfPixelFormat.dwBBitMask);
+ osd_printf_verbose("DirectDraw: Unknown target mode: R=%08X G=%08X B=%08X\n", (int)origmode.ddpfPixelFormat.dwRBitMask, (int)origmode.ddpfPixelFormat.dwGBitMask, (int)origmode.ddpfPixelFormat.dwBBitMask);
return 1;
}
}
@@ -1164,7 +1175,7 @@ static BOOL WINAPI monitor_enum_callback(GUID FAR *guid, LPSTR description, LPST
// get_adapter_for_monitor
//============================================================
-static void get_adapter_for_monitor(dd_info *dd, win_monitor_info *monitor)
+void renderer_dd::get_adapter_for_monitor(win_monitor_info *monitor)
{
monitor_enum_info einfo;
HRESULT result;
@@ -1178,11 +1189,11 @@ static void get_adapter_for_monitor(dd_info *dd, win_monitor_info *monitor)
// set up the adapter
if (einfo.foundit && einfo.guid_ptr != NULL)
{
- dd->adapter = einfo.guid;
- dd->adapter_ptr = &dd->adapter;
+ adapter = einfo.guid;
+ adapter_ptr = &adapter;
}
else
- dd->adapter_ptr = NULL;
+ adapter_ptr = NULL;
}
@@ -1195,7 +1206,7 @@ static HRESULT WINAPI enum_modes_callback(LPDDSURFACEDESC2 desc, LPVOID context)
{
float size_score, refresh_score, final_score;
mode_enum_info *einfo = (mode_enum_info *)context;
- dd_info *dd = (dd_info *)einfo->window->m_drawdata;
+ renderer_dd *dd = dynamic_cast<renderer_dd *>(einfo->window->m_renderer);
// skip non-32 bit modes
if (desc->ddpfPixelFormat.dwRGBBitCount != 32)
@@ -1248,9 +1259,8 @@ static HRESULT WINAPI enum_modes_callback(LPDDSURFACEDESC2 desc, LPVOID context)
// pick_best_mode
//============================================================
-static void pick_best_mode(win_window_info *window)
+void renderer_dd::pick_best_mode()
{
- dd_info *dd = (dd_info *)window->m_drawdata;
mode_enum_info einfo;
HRESULT result;
@@ -1258,7 +1268,7 @@ static void pick_best_mode(win_window_info *window)
// note: technically we should not be calling this from an alternate window
// thread; however, it is only done during init time, and the init code on
// the main thread is waiting for us to finish, so it is safe to do so here
- window->m_target->compute_minimum_size(einfo.minimum_width, einfo.minimum_height);
+ window().m_target->compute_minimum_size(einfo.minimum_width, einfo.minimum_height);
// use those as the target for now
einfo.target_width = einfo.minimum_width * MAX(1, video_config.prescale);
@@ -1266,7 +1276,7 @@ static void pick_best_mode(win_window_info *window)
// determine the refresh rate of the primary screen
einfo.target_refresh = 60.0;
- const screen_device *primary_screen = window->machine().config().first_screen();
+ const screen_device *primary_screen = window().machine().config().first_screen();
if (primary_screen != NULL)
einfo.target_refresh = ATTOSECONDS_TO_HZ(primary_screen->refresh_attoseconds());
printf("Target refresh = %f\n", einfo.target_refresh);
@@ -1286,12 +1296,12 @@ static void pick_best_mode(win_window_info *window)
}
// fill in the rest of the data
- einfo.window = window;
+ einfo.window = &window();
einfo.best_score = 0.0f;
// enumerate the modes
osd_printf_verbose("DirectDraw: Selecting video mode...\n");
- result = IDirectDraw7_EnumDisplayModes(dd->ddraw, DDEDM_REFRESHRATES, NULL, &einfo, enum_modes_callback);
+ result = IDirectDraw7_EnumDisplayModes(ddraw, DDEDM_REFRESHRATES, NULL, &einfo, enum_modes_callback);
if (result != DD_OK) osd_printf_verbose("DirectDraw: Error %08X during EnumDisplayModes call\n", (int)result);
- osd_printf_verbose("DirectDraw: Mode selected = %4dx%4d@%3dHz\n", dd->width, dd->height, dd->refresh);
+ osd_printf_verbose("DirectDraw: Mode selected = %4dx%4d@%3dHz\n", width, height, refresh);
}
diff --git a/src/osd/windows/drawgdi.c b/src/osd/windows/drawgdi.c
index 2ace10c26dd..c01f333fe5f 100644
--- a/src/osd/windows/drawgdi.c
+++ b/src/osd/windows/drawgdi.c
@@ -18,47 +18,61 @@
#include "window.h"
-
//============================================================
// TYPE DEFINITIONS
//============================================================
-/* gdi_info is the information for the current screen */
-struct gdi_info
+class renderer_gdi : public osd_renderer
{
+public:
+ renderer_gdi(win_window_info *window)
+ : osd_renderer(window, FLAG_NONE), bmdata(NULL), bmsize(0) { }
+
+ virtual ~renderer_gdi() { }
+
+ virtual int init();
+ virtual render_primitive_list *get_primitives();
+ virtual int draw(HDC dc, int update);
+ virtual void save() {};
+ virtual void record() {};
+ virtual void toggle_fsfx() {};
+ virtual void destroy();
+
+private:
+ /* gdi_info is the information for the current screen */
BITMAPINFO bminfo;
UINT8 * bmdata;
size_t bmsize;
};
-
//============================================================
// PROTOTYPES
//============================================================
// core functions
static void drawgdi_exit(void);
-static int drawgdi_window_init(win_window_info *window);
-static void drawgdi_window_destroy(win_window_info *window);
-static render_primitive_list *drawgdi_window_get_primitives(win_window_info *window);
-static int drawgdi_window_draw(win_window_info *window, HDC dc, int update);
+//============================================================
+// drawnone_create
+//============================================================
+
+static osd_renderer *drawgdi_create(win_window_info *window)
+{
+ return global_alloc(renderer_gdi(window));
+}
//============================================================
// drawgdi_init
//============================================================
-int drawgdi_init(running_machine &machine, win_draw_callbacks *callbacks)
+int drawgdi_init(running_machine &machine, osd_draw_callbacks *callbacks)
{
// fill in the callbacks
memset(callbacks, 0, sizeof(*callbacks));
callbacks->exit = drawgdi_exit;
- callbacks->window_init = drawgdi_window_init;
- callbacks->window_get_primitives = drawgdi_window_get_primitives;
- callbacks->window_draw = drawgdi_window_draw;
- callbacks->window_destroy = drawgdi_window_destroy;
+ callbacks->create = drawgdi_create;
return 0;
}
@@ -78,22 +92,19 @@ static void drawgdi_exit(void)
// drawgdi_window_init
//============================================================
-static int drawgdi_window_init(win_window_info *window)
+int renderer_gdi::init()
{
- // allocate memory for our structures
- gdi_info *gdi = global_alloc_clear(gdi_info);
- window->m_drawdata = gdi;
// fill in the bitmap info header
- gdi->bminfo.bmiHeader.biSize = sizeof(gdi->bminfo.bmiHeader);
- gdi->bminfo.bmiHeader.biPlanes = 1;
- gdi->bminfo.bmiHeader.biBitCount = 32;
- gdi->bminfo.bmiHeader.biCompression = BI_RGB;
- gdi->bminfo.bmiHeader.biSizeImage = 0;
- gdi->bminfo.bmiHeader.biXPelsPerMeter = 0;
- gdi->bminfo.bmiHeader.biYPelsPerMeter = 0;
- gdi->bminfo.bmiHeader.biClrUsed = 0;
- gdi->bminfo.bmiHeader.biClrImportant = 0;
+ bminfo.bmiHeader.biSize = sizeof(bminfo.bmiHeader);
+ bminfo.bmiHeader.biPlanes = 1;
+ bminfo.bmiHeader.biBitCount = 32;
+ bminfo.bmiHeader.biCompression = BI_RGB;
+ bminfo.bmiHeader.biSizeImage = 0;
+ bminfo.bmiHeader.biXPelsPerMeter = 0;
+ bminfo.bmiHeader.biYPelsPerMeter = 0;
+ bminfo.bmiHeader.biClrUsed = 0;
+ bminfo.bmiHeader.biClrImportant = 0;
return 0;
}
@@ -104,19 +115,12 @@ static int drawgdi_window_init(win_window_info *window)
// drawgdi_window_destroy
//============================================================
-static void drawgdi_window_destroy(win_window_info *window)
+void renderer_gdi::destroy()
{
- gdi_info *gdi = (gdi_info *)window->m_drawdata;
-
- // skip if nothing
- if (gdi == NULL)
- return;
// free the bitmap memory
- if (gdi->bmdata != NULL)
- global_free_array(gdi->bmdata);
- global_free(gdi);
- window->m_drawdata = NULL;
+ if (bmdata != NULL)
+ global_free_array(bmdata);
}
@@ -125,12 +129,12 @@ static void drawgdi_window_destroy(win_window_info *window)
// drawgdi_window_get_primitives
//============================================================
-static render_primitive_list *drawgdi_window_get_primitives(win_window_info *window)
+render_primitive_list *renderer_gdi::get_primitives()
{
RECT client;
- GetClientRect(window->m_hwnd, &client);
- window->m_target->set_bounds(rect_width(&client), rect_height(&client), window->m_monitor->get_aspect());
- return &window->m_target->get_primitives();
+ GetClientRect(window().m_hwnd, &client);
+ window().m_target->set_bounds(rect_width(&client), rect_height(&client), window().m_monitor->get_aspect());
+ return &window().m_target->get_primitives();
}
@@ -139,18 +143,17 @@ static render_primitive_list *drawgdi_window_get_primitives(win_window_info *win
// drawgdi_window_draw
//============================================================
-static int drawgdi_window_draw(win_window_info *window, HDC dc, int update)
+int renderer_gdi::draw(HDC dc, int update)
{
- gdi_info *gdi = (gdi_info *)window->m_drawdata;
int width, height, pitch;
RECT bounds;
// we don't have any special resize behaviors
- if (window->m_resize_state == RESIZE_STATE_PENDING)
- window->m_resize_state = RESIZE_STATE_NORMAL;
+ if (window().m_resize_state == RESIZE_STATE_PENDING)
+ window().m_resize_state = RESIZE_STATE_NORMAL;
// get the target bounds
- GetClientRect(window->m_hwnd, &bounds);
+ GetClientRect(window().m_hwnd, &bounds);
// compute width/height/pitch of target
width = rect_width(&bounds);
@@ -158,25 +161,25 @@ static int drawgdi_window_draw(win_window_info *window, HDC dc, int update)
pitch = (width + 3) & ~3;
// make sure our temporary bitmap is big enough
- if (pitch * height * 4 > gdi->bmsize)
+ if (pitch * height * 4 > bmsize)
{
- gdi->bmsize = pitch * height * 4 * 2;
- global_free_array(gdi->bmdata);
- gdi->bmdata = global_alloc_array(UINT8, gdi->bmsize);
+ bmsize = pitch * height * 4 * 2;
+ global_free_array(bmdata);
+ bmdata = global_alloc_array(UINT8, bmsize);
}
// draw the primitives to the bitmap
- window->m_primlist->acquire_lock();
- software_renderer<UINT32, 0,0,0, 16,8,0>::draw_primitives(*window->m_primlist, gdi->bmdata, width, height, pitch);
- window->m_primlist->release_lock();
+ window().m_primlist->acquire_lock();
+ software_renderer<UINT32, 0,0,0, 16,8,0>::draw_primitives(*window().m_primlist, bmdata, width, height, pitch);
+ window().m_primlist->release_lock();
// fill in bitmap-specific info
- gdi->bminfo.bmiHeader.biWidth = pitch;
- gdi->bminfo.bmiHeader.biHeight = -height;
+ bminfo.bmiHeader.biWidth = pitch;
+ bminfo.bmiHeader.biHeight = -height;
// blit to the screen
StretchDIBits(dc, 0, 0, width, height,
0, 0, width, height,
- gdi->bmdata, &gdi->bminfo, DIB_RGB_COLORS, SRCCOPY);
+ bmdata, &bminfo, DIB_RGB_COLORS, SRCCOPY);
return 0;
}
diff --git a/src/osd/windows/drawnone.c b/src/osd/windows/drawnone.c
index c7400500ea9..236cd533948 100644
--- a/src/osd/windows/drawnone.c
+++ b/src/osd/windows/drawnone.c
@@ -17,6 +17,24 @@
#include "window.h"
+class renderer_none : public osd_renderer
+{
+public:
+ renderer_none(win_window_info *window)
+ : osd_renderer(window, FLAG_NONE) { }
+
+ virtual ~renderer_none() { }
+
+ virtual int init();
+ virtual render_primitive_list *get_primitives();
+ virtual int draw(HDC dc, int update);
+ virtual void save() { };
+ virtual void record() { };
+ virtual void toggle_fsfx() { };
+ virtual void destroy();
+
+private:
+};
//============================================================
// PROTOTYPES
@@ -24,26 +42,26 @@
// core functions
static void drawnone_exit(void);
-static int drawnone_window_init(win_window_info *window);
-static void drawnone_window_destroy(win_window_info *window);
-static render_primitive_list *drawnone_window_get_primitives(win_window_info *window);
-static int drawnone_window_draw(win_window_info *window, HDC dc, int update);
+//============================================================
+// drawnone_create
+//============================================================
+osd_renderer *drawnone_create(win_window_info *window)
+{
+ return global_alloc(renderer_none(window));
+}
//============================================================
// drawnone_init
//============================================================
-int drawnone_init(running_machine &machine, win_draw_callbacks *callbacks)
+int drawnone_init(running_machine &machine, osd_draw_callbacks *callbacks)
{
// fill in the callbacks
memset(callbacks, 0, sizeof(*callbacks));
callbacks->exit = drawnone_exit;
- callbacks->window_init = drawnone_window_init;
- callbacks->window_get_primitives = drawnone_window_get_primitives;
- callbacks->window_draw = drawnone_window_draw;
- callbacks->window_destroy = drawnone_window_destroy;
+ callbacks->create = drawnone_create;
return 0;
}
@@ -63,7 +81,7 @@ static void drawnone_exit(void)
// drawnone_window_init
//============================================================
-static int drawnone_window_init(win_window_info *window)
+int renderer_none::init()
{
return 0;
}
@@ -74,7 +92,7 @@ static int drawnone_window_init(win_window_info *window)
// drawnone_window_destroy
//============================================================
-static void drawnone_window_destroy(win_window_info *window)
+void renderer_none::destroy()
{
}
@@ -84,12 +102,12 @@ static void drawnone_window_destroy(win_window_info *window)
// drawnone_window_get_primitives
//============================================================
-static render_primitive_list *drawnone_window_get_primitives(win_window_info *window)
+render_primitive_list *renderer_none::get_primitives()
{
RECT client;
- GetClientRect(window->m_hwnd, &client);
- window->m_target->set_bounds(rect_width(&client), rect_height(&client), window->m_monitor->get_aspect());
- return &window->m_target->get_primitives();
+ GetClientRect(window().m_hwnd, &client);
+ window().m_target->set_bounds(rect_width(&client), rect_height(&client), window().m_monitor->get_aspect());
+ return &window().m_target->get_primitives();
}
@@ -98,7 +116,7 @@ static render_primitive_list *drawnone_window_get_primitives(win_window_info *wi
// drawnone_window_draw
//============================================================
-static int drawnone_window_draw(win_window_info *window, HDC dc, int update)
+int renderer_none::draw(HDC dc, int update)
{
return 0;
}
diff --git a/src/osd/windows/window.c b/src/osd/windows/window.c
index 2a854c39d45..976b34081ad 100644
--- a/src/osd/windows/window.c
+++ b/src/osd/windows/window.c
@@ -35,11 +35,11 @@
#include "config.h"
#include "winutf8.h"
-extern int drawnone_init(running_machine &machine, win_draw_callbacks *callbacks);
-extern int drawgdi_init(running_machine &machine, win_draw_callbacks *callbacks);
-extern int drawdd_init(running_machine &machine, win_draw_callbacks *callbacks);
-extern int drawd3d_init(running_machine &machine, win_draw_callbacks *callbacks);
-extern int drawbgfx_init(running_machine &machine, win_draw_callbacks *callbacks);
+extern int drawnone_init(running_machine &machine, osd_draw_callbacks *callbacks);
+extern int drawgdi_init(running_machine &machine, osd_draw_callbacks *callbacks);
+extern int drawdd_init(running_machine &machine, osd_draw_callbacks *callbacks);
+extern int drawd3d_init(running_machine &machine, osd_draw_callbacks *callbacks);
+extern int drawbgfx_init(running_machine &machine, osd_draw_callbacks *callbacks);
//============================================================
@@ -107,7 +107,7 @@ static DWORD window_threadid;
static DWORD last_update_time;
-static win_draw_callbacks draw;
+static osd_draw_callbacks draw;
static HANDLE ui_pause_event;
static HANDLE window_thread_ready_event;
@@ -320,7 +320,7 @@ win_window_info::win_window_info(running_machine &machine)
m_lastclicktime(0),
m_lastclickx(0),
m_lastclicky(0),
- m_drawdata(NULL),
+ m_renderer(NULL),
m_machine(machine)
{
memset(m_title,0,sizeof(m_title));
@@ -504,9 +504,6 @@ void winwindow_dispatch_message(running_machine &machine, MSG *message)
void winwindow_take_snap(void)
{
- if (draw.window_record == NULL)
- return;
-
win_window_info *window;
assert(GetCurrentThreadId() == main_threadid);
@@ -514,7 +511,7 @@ void winwindow_take_snap(void)
// iterate over windows and request a snap
for (window = win_window_list; window != NULL; window = window->m_next)
{
- (*draw.window_save)(window);
+ window->m_renderer->save();
}
}
@@ -527,9 +524,6 @@ void winwindow_take_snap(void)
void winwindow_toggle_fsfx(void)
{
- if (draw.window_toggle_fsfx == NULL)
- return;
-
win_window_info *window;
assert(GetCurrentThreadId() == main_threadid);
@@ -537,7 +531,7 @@ void winwindow_toggle_fsfx(void)
// iterate over windows and request a snap
for (window = win_window_list; window != NULL; window = window->m_next)
{
- (*draw.window_toggle_fsfx)(window);
+ window->m_renderer->toggle_fsfx();
}
}
@@ -550,9 +544,6 @@ void winwindow_toggle_fsfx(void)
void winwindow_take_video(void)
{
- if (draw.window_record == NULL)
- return;
-
win_window_info *window;
assert(GetCurrentThreadId() == main_threadid);
@@ -560,7 +551,7 @@ void winwindow_take_video(void)
// iterate over windows and request a snap
for (window = win_window_list; window != NULL; window = window->m_next)
{
- (*draw.window_record)(window);
+ window->m_renderer->record();
}
}
@@ -812,7 +803,7 @@ void win_window_info::update()
}
// if we're visible and running and not in the middle of a resize, draw
- if (m_hwnd != NULL && m_target != NULL && m_drawdata != NULL)
+ if (m_hwnd != NULL && m_target != NULL)
{
int got_lock = TRUE;
@@ -835,7 +826,7 @@ void win_window_info::update()
osd_lock_release(m_render_lock);
// ensure the target bounds are up-to-date, and then get the primitives
- primlist = (*draw.window_get_primitives)(this);
+ primlist = m_renderer->get_primitives();
// post a redraw request with the primitive list as a parameter
last_update_time = timeGetTime();
@@ -1241,7 +1232,8 @@ static int complete_create(win_window_info *window)
if (!window->m_fullscreen || window->m_fullscreen_safe)
{
// finish off by trying to initialize DirectX; if we fail, ignore it
- if ((*draw.window_init)(window))
+ window->m_renderer = draw.create(window);
+ if (window->m_renderer->init())
return 1;
ShowWindow(window->m_hwnd, SW_SHOW);
}
@@ -1417,7 +1409,9 @@ LRESULT CALLBACK winwindow_video_window_proc(HWND wnd, UINT message, WPARAM wpar
// destroy: clean up all attached rendering bits and NULL out our hwnd
case WM_DESTROY:
- (*draw.window_destroy)(window);
+ window->m_renderer->destroy();
+ global_free(window->m_renderer);
+ window->m_renderer = NULL;
window->m_hwnd = NULL;
return DefWindowProc(wnd, message, wparam, lparam);
@@ -1501,7 +1495,7 @@ static void draw_video_contents(win_window_info *window, HDC dc, int update)
// otherwise, render with our drawing system
else
{
- (*draw.window_draw)(window, dc, update);
+ window->m_renderer->draw(dc, update);
mtlog_add("draw_video_contents: drawing finished");
}
}
@@ -1871,7 +1865,9 @@ static void set_fullscreen(win_window_info *window, int fullscreen)
window->m_fullscreen = fullscreen;
// kill off the drawers
- (*draw.window_destroy)(window);
+ window->m_renderer->destroy();
+ global_free(window->m_renderer);
+ window->m_renderer = NULL;
// hide ourself
ShowWindow(window->m_hwnd, SW_HIDE);
@@ -1927,7 +1923,8 @@ static void set_fullscreen(win_window_info *window, int fullscreen)
{
if (video_config.mode != VIDEO_MODE_NONE)
ShowWindow(window->m_hwnd, SW_SHOW);
- if ((*draw.window_init)(window))
+ window->m_renderer = draw.create(window);
+ if (window->m_renderer->init())
exit(1);
}
diff --git a/src/osd/windows/window.h b/src/osd/windows/window.h
index b2c6ea2e994..4d61b8e843e 100644
--- a/src/osd/windows/window.h
+++ b/src/osd/windows/window.h
@@ -32,6 +32,8 @@
// TYPE DEFINITIONS
//============================================================
+class osd_renderer;
+
class win_window_info
{
public:
@@ -77,24 +79,50 @@ public:
int m_lastclicky;
// drawing data
- void * m_drawdata;
+ osd_renderer * m_renderer;
private:
running_machine & m_machine;
};
+class osd_renderer
+{
+public:
+
+ /* Generic flags */
+ static const int FLAG_NONE = 0x0000;
+ static const int FLAG_NEEDS_OPENGL = 0x0001;
+
+ /* SDL 1.2 flags */
+ static const int FLAG_NEEDS_DOUBLEBUF = 0x0100;
+ static const int FLAG_NEEDS_ASYNCBLIT = 0x0200;
+
+ osd_renderer(win_window_info *window, const int flags)
+ : m_window(window), m_flags(flags) { }
+
+ virtual ~osd_renderer() { }
-struct win_draw_callbacks
+ win_window_info &window() { return *m_window; }
+ int flags() const { return m_flags; }
+ bool check_flag(const int flag) { return ((m_flags & flag)) == flag; }
+
+ virtual int init() = 0;
+ virtual render_primitive_list *get_primitives() = 0;
+ virtual int draw(HDC dc, int update) = 0;
+ virtual void save() = 0;
+ virtual void record() = 0;
+ virtual void toggle_fsfx() = 0;
+ virtual void destroy() = 0;
+
+private:
+ win_window_info *m_window;
+ int m_flags;
+};
+
+struct osd_draw_callbacks
{
+ osd_renderer *(*create)(win_window_info *window);
void (*exit)(void);
-
- int (*window_init)(win_window_info *window);
- render_primitive_list *(*window_get_primitives)(win_window_info *window);
- int (*window_draw)(win_window_info *window, HDC dc, int update);
- void (*window_save)(win_window_info *window);
- void (*window_record)(win_window_info *window);
- void (*window_toggle_fsfx)(win_window_info *window);
- void (*window_destroy)(win_window_info *window);
};