Previous 199869 Revisions Next

r34879 Thursday 5th February, 2015 at 22:24:15 UTC by Couriersud
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)
[src/osd/windows]d3dhlsl.c drawbgfx.c drawd3d.c drawd3d.h drawdd.c drawgdi.c drawnone.c window.c window.h

trunk/src/osd/windows/d3dhlsl.c
r243390r243391
224224   if (!master_enable || !d3dintf->post_fx_available)
225225      return;
226226
227   renderer *d3d = (renderer *)window->m_drawdata;
227   renderer *d3d = dynamic_cast<renderer *>(window->m_renderer);
228228
229229   HRESULT result = (*d3dintf->device.create_texture)(d3d->get_device(), snap_width, snap_height, 1, D3DUSAGE_DYNAMIC, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &snap_copy_texture);
230230   if (result != D3D_OK)
r243390r243391
276276   if (!master_enable || !d3dintf->post_fx_available)
277277      return;
278278
279   renderer *d3d = (renderer *)window->m_drawdata;
279   renderer *d3d = dynamic_cast<renderer *>(window->m_renderer);
280280
281281   D3DLOCKED_RECT rect;
282282
r243390r243391
326326   if (!master_enable || !d3dintf->post_fx_available)
327327      return;
328328
329   renderer *d3d = (renderer *)window->m_drawdata;
329   renderer *d3d = dynamic_cast<renderer *>(window->m_renderer);
330330
331331   D3DLOCKED_RECT rect;
332332
r243390r243391
519519   if (!master_enable || !d3dintf->post_fx_available)
520520      return;
521521
522   renderer *d3d = (renderer *)window->m_drawdata;
522   renderer *d3d = dynamic_cast<renderer *>(window->m_renderer);
523523
524524   // stop any existing recording
525525   end_avi_recording();
r243390r243391
678678   if (!master_enable || !d3dintf->post_fx_available)
679679      return;
680680
681   renderer *d3d = (renderer *)window->m_drawdata;
681   renderer *d3d = dynamic_cast<renderer *>(window->m_renderer);
682682
683683   if(texture != NULL)
684684   {
r243390r243391
820820   if (!master_enable || !d3dintf->post_fx_available)
821821      return;
822822
823   renderer *d3d = (renderer *)window->m_drawdata;
823   renderer *d3d = dynamic_cast<renderer *>(window->m_renderer);
824824
825825   // get a pointer to the vertex buffer
826826   fsfx_vertices = (vertex *)vertbuf;
r243390r243391
892892   if (!master_enable || !d3dintf->post_fx_available)
893893      return 0;
894894
895   renderer *d3d = (renderer *)window->m_drawdata;
895   renderer *d3d = dynamic_cast<renderer *>(window->m_renderer);
896896
897897   HRESULT result = (*d3dintf->device.get_render_target)(d3d->get_device(), 0, &backbuffer);
898898   if (result != D3D_OK) osd_printf_verbose("Direct3D: Error %08X during device get_render_target call\n", (int)result);
r243390r243391
10661066   if (!master_enable || !d3dintf->post_fx_available)
10671067      return;
10681068
1069   renderer *d3d = (renderer *)window->m_drawdata;
1069   renderer *d3d = dynamic_cast<renderer *>(window->m_renderer);
10701070
10711071   curr_effect = default_effect;
10721072
r243390r243391
11011101void shaders::blit(surface *dst, texture *src, surface *new_dst, D3DPRIMITIVETYPE prim_type,
11021102                  UINT32 prim_index, UINT32 prim_count, int dstw, int dsth)
11031103{
1104   renderer *d3d = (renderer *)window->m_drawdata;
1104   renderer *d3d = dynamic_cast<renderer *>(window->m_renderer);
11051105
11061106   HRESULT result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, dst);
11071107   if (result != D3D_OK) osd_printf_verbose("Direct3D: Error %08X during device set_render_target call\n", (int)result);
r243390r243391
11461146void shaders::blit(surface *dst, texture *src, surface *new_dst, D3DPRIMITIVETYPE prim_type,
11471147                  UINT32 prim_index, UINT32 prim_count)
11481148{
1149   renderer *d3d = (renderer *)window->m_drawdata;
1149   renderer *d3d = dynamic_cast<renderer *>(window->m_renderer);
11501150
11511151   HRESULT result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, dst);
11521152   if (result != D3D_OK) osd_printf_verbose("Direct3D: Error %08X during device set_render_target call\n", (int)result);
r243390r243391
12311231   if (!master_enable || !d3dintf->post_fx_available)
12321232      return;
12331233
1234   renderer *d3d = (renderer *)window->m_drawdata;
1234   renderer *d3d = dynamic_cast<renderer *>(window->m_renderer);
12351235   texture_info *texture = poly->get_texture();
12361236
12371237   if(PRIMFLAG_GET_SCREENTEX(d3d->get_last_texture_flags()) && texture != NULL)
r243390r243391
13081308
13091309void shaders::ntsc_pass(render_target *rt, vec2f &sourcedims, vec2f &delta)
13101310{
1311   renderer *d3d = (renderer *)window->m_drawdata;
1311   renderer *d3d = dynamic_cast<renderer *>(window->m_renderer);
13121312   UINT num_passes = 0;
13131313
13141314   if(options->yiq_enable)
r243390r243391
13701370
13711371void shaders::color_convolution_pass(render_target *rt, vec2f &texsize, vec2f &sourcedims)
13721372{
1373   renderer *d3d = (renderer *)window->m_drawdata;
1373   renderer *d3d = dynamic_cast<renderer *>(window->m_renderer);
13741374   UINT num_passes = 0;
13751375
13761376   curr_effect = color_effect;
r243390r243391
13981398
13991399void shaders::prescale_pass(render_target *rt, vec2f &texsize, vec2f &sourcedims)
14001400{
1401   renderer *d3d = (renderer *)window->m_drawdata;
1401   renderer *d3d = dynamic_cast<renderer *>(window->m_renderer);
14021402   UINT num_passes = 0;
14031403
14041404   curr_effect = prescale_effect;
r243390r243391
14261426
14271427void shaders::deconverge_pass(render_target *rt, vec2f &texsize, vec2f &delta, vec2f &sourcedims)
14281428{
1429   renderer *d3d = (renderer *)window->m_drawdata;
1429   renderer *d3d = dynamic_cast<renderer *>(window->m_renderer);
14301430   UINT num_passes = 0;
14311431
14321432   curr_effect = deconverge_effect;
r243390r243391
14541454
14551455void shaders::defocus_pass(render_target *rt, vec2f &texsize)
14561456{
1457   renderer *d3d = (renderer *)window->m_drawdata;
1457   renderer *d3d = dynamic_cast<renderer *>(window->m_renderer);
14581458   UINT num_passes = 0;
14591459
14601460   // Defocus pass 1
r243390r243391
15031503
15041504void shaders::phosphor_pass(render_target *rt, cache_target *ct, vec2f &texsize, bool focus_enable)
15051505{
1506   renderer *d3d = (renderer *)window->m_drawdata;
1506   renderer *d3d = dynamic_cast<renderer *>(window->m_renderer);
15071507   UINT num_passes = 0;
15081508
15091509   curr_effect = phosphor_effect;
r243390r243391
15611561
15621562void shaders::avi_post_pass(render_target *rt, vec2f &texsize, vec2f &delta, vec2f &sourcedims, poly_info *poly, int vertnum)
15631563{
1564   renderer *d3d = (renderer *)window->m_drawdata;
1564   renderer *d3d = dynamic_cast<renderer *>(window->m_renderer);
15651565   UINT num_passes = 0;
15661566
15671567   curr_effect = post_effect;
r243390r243391
16161616
16171617void shaders::screen_post_pass(render_target *rt, vec2f &texsize, vec2f &delta, vec2f &sourcedims, poly_info *poly, int vertnum)
16181618{
1619   renderer *d3d = (renderer *)window->m_drawdata;
1619   renderer *d3d = dynamic_cast<renderer *>(window->m_renderer);
16201620   UINT num_passes = 0;
16211621
16221622   curr_effect = post_effect;
r243390r243391
16501650
16511651void shaders::raster_bloom_pass(render_target *rt, vec2f &texsize, vec2f &delta, poly_info *poly, int vertnum)
16521652{
1653   renderer *d3d = (renderer *)window->m_drawdata;
1653   renderer *d3d = dynamic_cast<renderer *>(window->m_renderer);
16541654   UINT num_passes = 0;
16551655
16561656   curr_effect = downsample_effect;
r243390r243391
17551755      return;
17561756
17571757   UINT num_passes = 0;
1758   renderer *d3d = (renderer *)window->m_drawdata;
1758   renderer *d3d = dynamic_cast<renderer *>(window->m_renderer);
17591759   curr_texture = poly->get_texture();
17601760
17611761   if(PRIMFLAG_GET_SCREENTEX(d3d->get_last_texture_flags()) && curr_texture != NULL)
r243390r243391
20802080      return NULL;
20812081   }
20822082
2083   renderer *d3d = (renderer *)window->m_drawdata;
2083   renderer *d3d = dynamic_cast<renderer *>(window->m_renderer);
20842084
20852085   return find_render_target(d3d->get_width(), d3d->get_height(), 0, 0);
20862086}
20872087
20882088void shaders::create_vector_target(render_primitive *prim)
20892089{
2090   renderer *d3d = (renderer *)window->m_drawdata;
2090   renderer *d3d = dynamic_cast<renderer *>(window->m_renderer);
20912091   if (!add_render_target(d3d, NULL, d3d->get_width(), d3d->get_height(), 1, 1))
20922092   {
20932093      vector_enable = false;
r243390r243391
22022202
22032203   enumerate_screens();
22042204
2205   renderer *d3d = (renderer *)window->m_drawdata;
2205   renderer *d3d = dynamic_cast<renderer *>(window->m_renderer);
22062206
22072207   int hlsl_prescale_x = prescale_force_x;
22082208   int hlsl_prescale_y = prescale_force_y;
r243390r243391
29942994   }
29952995
29962996   shaders *shadersys = m_shader->m_shaders;
2997   renderer *d3d = (renderer *)shadersys->window->m_drawdata;
2997   renderer *d3d = dynamic_cast<renderer *>(shadersys->window->m_renderer);
29982998   hlsl_options *options = shadersys->options;
29992999
30003000   switch(m_id)
r243390r243391
34223422   UINT32 origflags = file.openflags();
34233423
34243424   // handle defaults
3425   const char *snapname = templ ? templ : d3d->get_window()->machine().options().snap_name();
3425   const char *snapname = templ ? templ : d3d->window().machine().options().snap_name();
34263426
34273427   if (snapname == NULL || snapname[0] == 0)
34283428      snapname = "%g/%i";
r243390r243391
34693469         snapdevname.cpysubstr(snapstr, pos + 3, end - pos - 3);
34703470
34713471         // verify that there is such a device for this system
3472         image_interface_iterator iter(d3d->get_window()->machine().root_device());
3472         image_interface_iterator iter(d3d->window().machine().root_device());
34733473         for (device_image_interface *image = iter.first(); image != NULL; iter.next())
34743474         {
34753475            // get the device name
r243390r243391
35063506
35073507   // substitute path and gamename up front
35083508   snapstr.replace(0, "/", PATH_SEPARATOR);
3509   snapstr.replace(0, "%g", d3d->get_window()->machine().basename());
3509   snapstr.replace(0, "%g", d3d->window().machine().basename());
35103510
35113511   // determine if the template has an index; if not, we always use the same name
35123512   astring fname;
trunk/src/osd/windows/drawbgfx.c
r243390r243391
2222#include <bgfxplatform.h>
2323#include <bgfx.h>
2424
25class renderer_bgfx : public osd_renderer
26{
27public:
28   renderer_bgfx(win_window_info *window)
29   : osd_renderer(window, FLAG_NONE) { }
30
31   virtual ~renderer_bgfx() { }
32
33   virtual int init();
34   virtual render_primitive_list *get_primitives();
35   virtual int draw(HDC dc, int update);
36   virtual void save() {};
37   virtual void record() {};
38   virtual void toggle_fsfx() {};
39   virtual void destroy();
40
41private:
42};
43
44
2545//============================================================
2646//  PROTOTYPES
2747//============================================================
2848
2949// core functions
3050static void drawbgfx_exit(void);
31static int drawbgfx_window_init(win_window_info *window);
32static void drawbgfx_window_destroy(win_window_info *window);
33static render_primitive_list *drawbgfx_window_get_primitives(win_window_info *window);
34static int drawbgfx_window_draw(win_window_info *window, HDC dc, int update);
3551
52//============================================================
53//  drawnone_create
54//============================================================
3655
56osd_renderer *drawbgfx_create(win_window_info *window)
57{
58   return global_alloc(renderer_bgfx(window));
59}
3760
3861//============================================================
3962//  drawbgfx_init
4063//============================================================
4164
42int drawbgfx_init(running_machine &machine, win_draw_callbacks *callbacks)
65int drawbgfx_init(running_machine &machine, osd_draw_callbacks *callbacks)
4366{
4467   // fill in the callbacks
4568   memset(callbacks, 0, sizeof(*callbacks));
4669   callbacks->exit = drawbgfx_exit;
47   callbacks->window_init = drawbgfx_window_init;
48   callbacks->window_get_primitives = drawbgfx_window_get_primitives;
49   callbacks->window_draw = drawbgfx_window_draw;
50   callbacks->window_destroy = drawbgfx_window_destroy;
70   callbacks->create = drawbgfx_create;
5171   return 0;
5272}
5373
r243390r243391
6787//  drawbgfx_window_init
6888//============================================================
6989
70static int drawbgfx_window_init(win_window_info *window)
90int renderer_bgfx::init()
7191{
7292   RECT client;
73   GetClientRect(window->m_hwnd, &client);
93   GetClientRect(window().m_hwnd, &client);
7494
75   bgfx::winSetHwnd(window->m_hwnd);
95   bgfx::winSetHwnd(window().m_hwnd);
7696   bgfx::init();
7797   bgfx::reset(rect_width(&client), rect_height(&client), BGFX_RESET_VSYNC);
7898   
7999   // Enable debug text.
80100   bgfx::setDebug(BGFX_DEBUG_STATS);// BGFX_DEBUG_TEXT);
81101
82   window->m_drawdata = window->m_hwnd;
83102   return 0;
84103}
85104
r243390r243391
89108//  drawbgfx_window_destroy
90109//============================================================
91110
92static void drawbgfx_window_destroy(win_window_info *window)
111void renderer_bgfx::destroy()
93112{
94113   // Shutdown bgfx.
95114   bgfx::shutdown();
96   window->m_drawdata = NULL;
97115}
98116
99117
r243390r243391
102120//  drawbgfx_window_get_primitives
103121//============================================================
104122
105static render_primitive_list *drawbgfx_window_get_primitives(win_window_info *window)
123render_primitive_list *renderer_bgfx::get_primitives()
106124{
107125   RECT client;
108   GetClientRect(window->m_hwnd, &client);
109   window->m_target->set_bounds(rect_width(&client), rect_height(&client), window->m_monitor->get_aspect());
110   return &window->m_target->get_primitives();   
126   GetClientRect(window().m_hwnd, &client);
127   window().m_target->set_bounds(rect_width(&client), rect_height(&client), window().m_monitor->get_aspect());
128   return &window().m_target->get_primitives();
111129}
112130
113131
r243390r243391
116134//  drawbgfx_window_draw
117135//============================================================
118136
119static int drawbgfx_window_draw(win_window_info *window, HDC dc, int update)
137int renderer_bgfx::draw(HDC dc, int update)
120138{
121139   RECT client;
122   GetClientRect(window->m_hwnd, &client);
140   GetClientRect(window().m_hwnd, &client);
123141
124142   bgfx::setViewClear(0
125143      , BGFX_CLEAR_COLOR|BGFX_CLEAR_DEPTH
r243390r243391
134152   // if no other draw calls are submitted to view 0.
135153   bgfx::submit(0);
136154
137   window->m_primlist->acquire_lock();
155   window().m_primlist->acquire_lock();
138156
139157   // now draw
140   for (render_primitive *prim = window->m_primlist->first(); prim != NULL; prim = prim->next())
158   for (render_primitive *prim = window().m_primlist->first(); prim != NULL; prim = prim->next())
141159   {
142160      switch (prim->type)
143161      {
r243390r243391
219237      }
220238   }
221239
222   window->m_primlist->release_lock();   
240   window().m_primlist->release_lock();
223241   // Advance to next frame. Rendering thread will be kicked to
224242   // process submitted rendering primitives.
225243   bgfx::frame();
trunk/src/osd/windows/drawd3d.c
r243390r243391
179179
180180// core functions
181181static void drawd3d_exit(void);
182static int drawd3d_window_init(win_window_info *window);
183static void drawd3d_window_destroy(win_window_info *window);
184static render_primitive_list *drawd3d_window_get_primitives(win_window_info *window);
185static void drawd3d_window_save(win_window_info *window);
186static void drawd3d_window_record(win_window_info *window);
187static void drawd3d_window_toggle_fsfx(win_window_info *window);
188static int drawd3d_window_draw(win_window_info *window, HDC dc, int update);
189182
190
191183//============================================================
192184//  drawd3d_window_init
193185//============================================================
194186
195static int drawd3d_window_init(win_window_info *window)
187int d3d::renderer::init()
196188{
197   // allocate memory for our structures
198   d3d::renderer *d3d = global_alloc(d3d::renderer(window));
199   window->m_drawdata = d3d;
200
201   if (!d3d->initialize())
189   if (!initialize())
202190   {
203      drawd3d_window_destroy(window);
191      destroy();
204192      osd_printf_error("Unable to initialize Direct3D.\n");
205193      return 1;
206194   }
r243390r243391
218206      (*d3dintf->d3d.release)(d3dintf);
219207}
220208
221static void drawd3d_window_toggle_fsfx(win_window_info *window)
209void d3d::renderer::toggle_fsfx()
222210{
223   d3d::renderer *d3d = (d3d::renderer *)window->m_drawdata;
224   d3d->set_restarting(true);
211   set_restarting(true);
225212}
226213
227static void drawd3d_window_record(win_window_info *window)
214void d3d::renderer::record()
228215{
229   d3d::renderer *d3d = (d3d::renderer *)window->m_drawdata;
230   d3d->get_shaders()->window_record();
216   get_shaders()->window_record();
231217}
232218
233static void drawd3d_window_save(win_window_info *window)
219void d3d::renderer::save()
234220{
235   d3d::renderer *d3d = (d3d::renderer *)window->m_drawdata;
236   d3d->get_shaders()->window_save();
221   get_shaders()->window_save();
237222}
238223
239224
r243390r243391
242227//  drawd3d_window_destroy
243228//============================================================
244229
245static void drawd3d_window_destroy(win_window_info *window)
230void d3d::renderer::destroy()
246231{
247   d3d::renderer *d3d = (d3d::renderer *)window->m_drawdata;
232   if (get_shaders() != NULL && get_shaders()->recording())
233      get_shaders()->window_record();
248234
249   // skip if nothing
250   if (d3d == NULL)
251      return;
252
253   if (d3d->get_shaders() != NULL && d3d->get_shaders()->recording())
254      d3d->get_shaders()->window_record();
255
256   // free the memory in the window
257   global_free(d3d);
258   window->m_drawdata = NULL;
259235}
260236
261237
r243390r243391
264240//  drawd3d_window_get_primitives
265241//============================================================
266242
267static render_primitive_list *drawd3d_window_get_primitives(win_window_info *window)
243render_primitive_list *d3d::renderer::get_primitives()
268244{
269   d3d::renderer *d3d = (d3d::renderer *)window->m_drawdata;
270245   RECT client;
271246
272   GetClientRectExceptMenu(window->m_hwnd, &client, window->m_fullscreen);
247   GetClientRectExceptMenu(window().m_hwnd, &client, window().m_fullscreen);
273248   if (rect_width(&client) > 0 && rect_height(&client) > 0)
274249   {
275      window->m_target->set_bounds(rect_width(&client), rect_height(&client), window->m_monitor->get_aspect());
276      window->m_target->set_max_update_rate((d3d->get_refresh() == 0) ? d3d->get_origmode().RefreshRate : d3d->get_refresh());
250      window().m_target->set_bounds(rect_width(&client), rect_height(&client), window().m_monitor->get_aspect());
251      window().m_target->set_max_update_rate((get_refresh() == 0) ? get_origmode().RefreshRate : get_refresh());
277252   }
278   return &window->m_target->get_primitives();
253   return &window().m_target->get_primitives();
279254}
280255
281int drawd3d_init(running_machine &machine, win_draw_callbacks *callbacks)
256//============================================================
257//  drawnone_create
258//============================================================
259
260static osd_renderer *drawd3d_create(win_window_info *window)
282261{
262   return global_alloc(d3d::renderer(window));
263}
264
265int drawd3d_init(running_machine &machine, osd_draw_callbacks *callbacks)
266{
283267   d3dintf = NULL;
284268
285269   // Use Direct3D9
r243390r243391
295279   // fill in the callbacks
296280   memset(callbacks, 0, sizeof(*callbacks));
297281   callbacks->exit = drawd3d_exit;
298   callbacks->window_init = drawd3d_window_init;
299   callbacks->window_get_primitives = drawd3d_window_get_primitives;
300   callbacks->window_draw = drawd3d_window_draw;
301   callbacks->window_save = drawd3d_window_save;
302   callbacks->window_record = drawd3d_window_record;
303   callbacks->window_toggle_fsfx = drawd3d_window_toggle_fsfx;
304   callbacks->window_destroy = drawd3d_window_destroy;
282   callbacks->create = drawd3d_create;
305283   return 0;
306284}
307285
r243390r243391
309287//  drawd3d_window_draw
310288//============================================================
311289
312static int drawd3d_window_draw(win_window_info *window, HDC dc, int update)
290int d3d::renderer::draw(HDC dc, int update)
313291{
314   d3d::renderer *d3d = (d3d::renderer *)window->m_drawdata;
315
316   // if we haven't been created, just punt
317   if (d3d == NULL)
318      return 1;
319
320   int check = d3d->pre_window_draw_check();
292   int check = pre_window_draw_check();
321293   if (check >= 0)
322294      return check;
323295
324   d3d->begin_frame();
325   d3d->process_primitives();
326   d3d->end_frame();
296   begin_frame();
297   process_primitives();
298   end_frame();
327299
328300   return 0;
329301}
r243390r243391
496468   osd_printf_verbose("Direct3D: YUV format = %s\n", (m_yuv_format == D3DFMT_YUY2) ? "YUY2" : (m_yuv_format == D3DFMT_UYVY) ? "UYVY" : "RGB");
497469
498470   // set the max texture size
499   d3d->get_window()->m_target->set_max_texture_size(m_texture_max_width, m_texture_max_height);
471   d3d->window().m_target->set_max_texture_size(m_texture_max_width, m_texture_max_height);
500472   osd_printf_verbose("Direct3D: Max texture size = %dx%d\n", (int)m_texture_max_width, (int)m_texture_max_height);
501473}
502474
r243390r243391
508480{
509481   // experimental: load a PNG to use for vector rendering; it is treated
510482   // as a brightness map
511   emu_file file(m_renderer->get_window()->machine().options().art_path(), OPEN_FLAG_READ);
483   emu_file file(m_renderer->window().machine().options().art_path(), OPEN_FLAG_READ);
512484   render_load_png(m_vector_bitmap, file, NULL, "vector.png");
513485   if (m_vector_bitmap.valid())
514486   {
r243390r243391
650622}
651623
652624renderer::renderer(win_window_info *window)
625   : osd_renderer(window, FLAG_NONE)
653626{
654627   m_device = NULL;
655628   m_restarting = false;
656   m_window = window;
657629   m_shaders = NULL;
658630   m_numverts = 0;
659631   m_numpolys = 0;
r243390r243391
672644      return false;
673645
674646   // create the device immediately for the full screen case (defer for window mode)
675   if (m_window->m_fullscreen && device_create())
647   if (window().m_fullscreen && device_create())
676648      return false;
677649
678650   return true;
r243390r243391
681653int renderer::pre_window_draw_check()
682654{
683655   // if we're in the middle of resizing, leave things alone
684   if (m_window->m_resize_state == RESIZE_STATE_RESIZING)
656   if (window().m_resize_state == RESIZE_STATE_RESIZING)
685657      return 0;
686658
687659   // if we're restarting the renderer, leave things alone
r243390r243391
706678   }
707679
708680   // in window mode, we need to track the window size
709   if (!m_window->m_fullscreen || m_device == NULL)
681   if (!window().m_fullscreen || m_device == NULL)
710682   {
711683      // if the size changes, skip this update since the render target will be out of date
712684      if (update_window_size())
r243390r243391
722694
723695void texture_manager::update_textures()
724696{
725   for (render_primitive *prim = m_renderer->get_window()->m_primlist->first(); prim != NULL; prim = prim->next())
697   for (render_primitive *prim = m_renderer->window().m_primlist->first(); prim != NULL; prim = prim->next())
726698   {
727699      if (prim->texture.base != NULL)
728700      {
r243390r243391
759731
760732   m_shaders->begin_frame();
761733
762   m_window->m_primlist->acquire_lock();
734   window().m_primlist->acquire_lock();
763735
764736   // first update any textures
765737   m_texture_manager->update_textures();
r243390r243391
780752   m_line_count = 0;
781753
782754   // loop over primitives
783   for (render_primitive *prim = m_window->m_primlist->first(); prim != NULL; prim = prim->next())
755   for (render_primitive *prim = window().m_primlist->first(); prim != NULL; prim = prim->next())
784756      if (prim->type == render_primitive::LINE && PRIMFLAG_GET_VECTOR(prim->flags))
785757         m_line_count++;
786758}
r243390r243391
788760void renderer::process_primitives()
789761{
790762   // Rotating index for vector time offsets
791   for (render_primitive *prim = m_window->m_primlist->first(); prim != NULL; prim = prim->next())
763   for (render_primitive *prim = window().m_primlist->first(); prim != NULL; prim = prim->next())
792764   {
793765      switch (prim->type)
794766      {
r243390r243391
818790
819791void renderer::end_frame()
820792{
821   m_window->m_primlist->release_lock();
793   window().m_primlist->release_lock();
822794
823795   // flush any pending polygons
824796   primitive_flush_pending();
r243390r243391
893865   m_presentation.BackBufferCount               = video_config.triplebuf ? 2 : 1;
894866   m_presentation.MultiSampleType               = D3DMULTISAMPLE_NONE;
895867   m_presentation.SwapEffect                    = D3DSWAPEFFECT_DISCARD;
896   m_presentation.hDeviceWindow                 = m_window->m_hwnd;
897   m_presentation.Windowed                      = !m_window->m_fullscreen || win_has_menu(m_window);
868   m_presentation.hDeviceWindow                 = window().m_hwnd;
869   m_presentation.Windowed                      = !window().m_fullscreen || win_has_menu(&window());
898870   m_presentation.EnableAutoDepthStencil        = FALSE;
899871   m_presentation.AutoDepthStencilFormat        = D3DFMT_D16;
900872   m_presentation.Flags                         = 0;
901873   m_presentation.FullScreen_RefreshRateInHz    = m_refresh;
902   m_presentation.PresentationInterval          = ((video_config.triplebuf && m_window->m_fullscreen) ||
874   m_presentation.PresentationInterval          = ((video_config.triplebuf && window().m_fullscreen) ||
903875                                       video_config.waitvsync || video_config.syncrefresh) ?
904876                                       D3DPRESENT_INTERVAL_ONE : D3DPRESENT_INTERVAL_IMMEDIATE;
905877
906878   // create the D3D device
907   result = (*d3dintf->d3d.create_device)(d3dintf, m_adapter, D3DDEVTYPE_HAL, m_window->m_focus_hwnd,
879   result = (*d3dintf->d3d.create_device)(d3dintf, m_adapter, D3DDEVTYPE_HAL, window().m_focus_hwnd,
908880               D3DCREATE_SOFTWARE_VERTEXPROCESSING | D3DCREATE_FPU_PRESERVE, &m_presentation, &m_device);
909881   if (result != D3D_OK)
910882   {
r243390r243391
927899   osd_printf_verbose("Direct3D: Device created at %dx%d\n", m_width, m_height);
928900
929901   // set the gamma if we need to
930   if (m_window->m_fullscreen)
902   if (window().m_fullscreen)
931903   {
932904      // only set the gamma if it's not 1.0f
933      windows_options &options = downcast<windows_options &>(m_window->machine().options());
905      windows_options &options = downcast<windows_options &>(window().machine().options());
934906      float brightness = options.full_screen_brightness();
935907      float contrast = options.full_screen_contrast();
936908      float gamma = options.full_screen_gamma();
r243390r243391
10921064   int retval = 0;
10931065
10941066   m_shaders = global_alloc_clear(shaders);
1095   m_shaders->init(d3dintf, m_window);
1067   m_shaders->init(d3dintf, &window());
10961068
10971069   DWORD tempcaps;
10981070   HRESULT result = (*d3dintf->d3d.get_caps_dword)(d3dintf, m_adapter, D3DDEVTYPE_HAL, CAPS_MAX_PS30_INSN_SLOTS, &tempcaps);
r243390r243391
12311203   }
12321204
12331205   // choose a resolution: window mode case
1234   if (!m_window->m_fullscreen || !video_config.switchres || win_has_menu(m_window))
1206   if (!window().m_fullscreen || !video_config.switchres || win_has_menu(&window()))
12351207   {
12361208      RECT client;
12371209
12381210      // bounds are from the window client rect
1239      GetClientRectExceptMenu(m_window->m_hwnd, &client, m_window->m_fullscreen);
1211      GetClientRectExceptMenu(window().m_hwnd, &client, window().m_fullscreen);
12401212      m_width = client.right - client.left;
12411213      m_height = client.bottom - client.top;
12421214
r243390r243391
12471219      // make sure it's a pixel format we can get behind
12481220      if (m_pixformat != D3DFMT_X1R5G5B5 && m_pixformat != D3DFMT_R5G6B5 && m_pixformat != D3DFMT_X8R8G8B8)
12491221      {
1250         char *utf8_device = utf8_from_tstring(m_window->m_monitor->info.szDevice);
1222         char *utf8_device = utf8_from_tstring(window().m_monitor->info.szDevice);
12511223         if (utf8_device != NULL)
12521224         {
12531225            osd_printf_error("Device %s currently in an unsupported mode\n", utf8_device);
r243390r243391
12721244   }
12731245
12741246   // see if we can handle the device type
1275   result = (*d3dintf->d3d.check_device_type)(d3dintf, m_adapter, D3DDEVTYPE_HAL, m_pixformat, m_pixformat, !m_window->m_fullscreen);
1247   result = (*d3dintf->d3d.check_device_type)(d3dintf, m_adapter, D3DDEVTYPE_HAL, m_pixformat, m_pixformat, !window().m_fullscreen);
12761248   if (result != D3D_OK)
12771249   {
1278      char *utf8_device = utf8_from_tstring(m_window->m_monitor->info.szDevice);
1250      char *utf8_device = utf8_from_tstring(window().m_monitor->info.szDevice);
12791251      if (utf8_device != NULL)
12801252      {
12811253         osd_printf_error("Proposed video mode not supported on device %s\n", utf8_device);
r243390r243391
13031275      HMONITOR curmonitor = (*d3dintf->d3d.get_adapter_monitor)(d3dintf, adapternum);
13041276
13051277      // if we match the proposed monitor, this is it
1306      if (curmonitor == m_window->m_monitor->handle)
1278      if (curmonitor == window().m_monitor->handle)
13071279      {
13081280         return adapternum;
13091281      }
r243390r243391
13261298   float best_score = 0.0f;
13271299
13281300   // determine the refresh rate of the primary screen
1329   const screen_device *primary_screen = m_window->machine().config().first_screen();
1301   const screen_device *primary_screen = window().machine().config().first_screen();
13301302   if (primary_screen != NULL)
13311303   {
13321304      target_refresh = ATTOSECONDS_TO_HZ(primary_screen->refresh_attoseconds());
r243390r243391
13361308   // note: technically we should not be calling this from an alternate window
13371309   // thread; however, it is only done during init time, and the init code on
13381310   // the main thread is waiting for us to finish, so it is safe to do so here
1339   m_window->m_target->compute_minimum_size(minwidth, minheight);
1311   window().m_target->compute_minimum_size(minwidth, minheight);
13401312
13411313   // use those as the target for now
13421314   INT32 target_width = minwidth;
r243390r243391
13711343         size_score *= 0.1f;
13721344
13731345      // if we're looking for a particular mode, that's a winner
1374      if (mode.Width == m_window->m_maxwidth && mode.Height == m_window->m_maxheight)
1346      if (mode.Width == window().m_maxwidth && mode.Height == window().m_maxheight)
13751347         size_score = 2.0f;
13761348
13771349      // compute refresh score
r243390r243391
13821354         refresh_score *= 0.1f;
13831355
13841356      // if we're looking for a particular refresh, make sure it matches
1385      if (mode.RefreshRate == m_window->m_refresh)
1357      if (mode.RefreshRate == window().m_refresh)
13861358         refresh_score = 2.0f;
13871359
13881360      // weight size and refresh equally
r243390r243391
14121384{
14131385   // get the current window bounds
14141386   RECT client;
1415   GetClientRectExceptMenu(m_window->m_hwnd, &client, m_window->m_fullscreen);
1387   GetClientRectExceptMenu(window().m_hwnd, &client, window().m_fullscreen);
14161388
14171389   // if we have a device and matching width/height, nothing to do
14181390   if (m_device != NULL && rect_width(&client) == m_width && rect_height(&client) == m_height)
14191391   {
14201392      // clear out any pending resizing if the area didn't change
1421      if (m_window->m_resize_state == RESIZE_STATE_PENDING)
1422         m_window->m_resize_state = RESIZE_STATE_NORMAL;
1393      if (window().m_resize_state == RESIZE_STATE_PENDING)
1394         window().m_resize_state = RESIZE_STATE_NORMAL;
14231395      return FALSE;
14241396   }
14251397
14261398   // if we're in the middle of resizing, leave it alone as well
1427   if (m_window->m_resize_state == RESIZE_STATE_RESIZING)
1399   if (window().m_resize_state == RESIZE_STATE_RESIZING)
14281400      return FALSE;
14291401
14301402   // set the new bounds and create the device again
r243390r243391
14341406      return FALSE;
14351407
14361408   // reset the resize state to normal, and indicate we made a change
1437   m_window->m_resize_state = RESIZE_STATE_NORMAL;
1409   window().m_resize_state = RESIZE_STATE_NORMAL;
14381410   return TRUE;
14391411}
14401412
r243390r243391
14441416
14451417void renderer::batch_vectors()
14461418{
1447   windows_options &options = downcast<windows_options &>(m_window->machine().options());
1419   windows_options &options = downcast<windows_options &>(window().machine().options());
14481420
14491421   int vector_size = (options.antialias() ? 24 : 6);
14501422   m_vectorbatch = mesh_alloc(m_line_count * vector_size);
r243390r243391
14541426   int line_index = 0;
14551427   float period = options.screen_vector_time_period();
14561428   UINT32 cached_flags = 0;
1457   for (render_primitive *prim = m_window->m_primlist->first(); prim != NULL; prim = prim->next())
1429   for (render_primitive *prim = window().m_primlist->first(); prim != NULL; prim = prim->next())
14581430   {
14591431      switch (prim->type)
14601432      {
trunk/src/osd/windows/drawd3d.h
r243390r243391
9595};
9696
9797/* renderer is the information about Direct3D for the current screen */
98class renderer
98class renderer : public osd_renderer
9999{
100100public:
101   renderer() { }
101   //renderer() { }
102102   renderer(win_window_info *window);
103   ~renderer();
103   virtual ~renderer();
104104
105   virtual int init();
106   virtual render_primitive_list *get_primitives();
107   virtual int draw(HDC dc, int update);
108   virtual void save();
109   virtual void record();
110   virtual void toggle_fsfx();
111   virtual void destroy();
112
105113   int                     initialize();
106114
107115   int                     device_create();
r243390r243391
148156   int                     get_height() { return m_height; }
149157   int                     get_refresh() { return m_refresh; }
150158
151   win_window_info *       get_window() { return m_window; }
152
153159   device *                get_device() { return m_device; }
154160   present_parameters *    get_presentation() { return &m_presentation; }
155161
r243390r243391
181187   int                     m_refresh;                  // current refresh rate
182188   int                     m_create_error_count;       // number of consecutive create errors
183189
184   win_window_info *       m_window;                     // current window info
185
186190   device *                m_device;                   // pointer to the Direct3DDevice object
187191   int                     m_gamma_supported;          // is full screen gamma supported?
188192   present_parameters      m_presentation;             // set of presentation parameters
trunk/src/osd/windows/drawdd.c
r243390r243391
3636
3737
3838/* dd_info is the information about DirectDraw for the current screen */
39struct dd_info
39class renderer_dd : public osd_renderer
4040{
41public:
42   renderer_dd(win_window_info *window)
43   : osd_renderer(window, FLAG_NONE),
44      //adapter(0),
45      adapter_ptr(NULL),
46      clearouter(0),
47      blitwidth(0), blitheight(0),
48      //lastdest
49      ddraw(NULL),
50      primary(NULL),
51      back(NULL),
52      blit(NULL),
53      clipper(NULL),
54      gamma(NULL),
55      //DDSURFACEDESC2          primarydesc;
56      //DDSURFACEDESC2          blitdesc;
57      //DDSURFACEDESC2          origmode;
58      //ddcaps(0),
59      //helcaps(0),
60      membuffer(NULL),
61      membuffersize(NULL)
62   { }
63
64   virtual ~renderer_dd() { }
65
66   virtual int init();
67   virtual render_primitive_list *get_primitives();
68   virtual int draw(HDC dc, int update);
69   virtual void save() {};
70   virtual void record() {};
71   virtual void toggle_fsfx() {};
72   virtual void destroy();
73
74   int                     width, height;              // current width, height
75   int                     refresh;                    // current refresh rate
76
77private:
78
79   inline void update_outer_rects();
80
81   // surface management
82   int ddraw_create();
83   int ddraw_create_surfaces();
84   void ddraw_delete();
85   void ddraw_delete_surfaces();
86   int ddraw_verify_caps();
87   int ddraw_test_cooperative();
88   HRESULT create_surface(DDSURFACEDESC2 *desc, IDirectDrawSurface7 **surface, const char *type);
89   int create_clipper();
90
91   // drawing helpers
92   void compute_blit_surface_size();
93   void blit_to_primary(int srcwidth, int srcheight);
94
95   // video modes
96   int config_adapter_mode();
97   void get_adapter_for_monitor(win_monitor_info *monitor);
98   void pick_best_mode();
99
100   // various
101   void calc_fullscreen_margins(DWORD desc_width, DWORD desc_height, RECT *margins);
102
103
41104   GUID                    adapter;                    // current display adapter
42105   GUID *                  adapter_ptr;                // pointer to current display adapter
43   int                     width, height;              // current width, height
44   int                     refresh;                    // current refresh rate
45106   int                     clearouter;                 // clear the outer areas?
46107
47108   INT32                   blitwidth, blitheight;      // current blit width/height values
r243390r243391
79140/* mode_enum_info holds information during a display mode enumeration */
80141struct mode_enum_info
81142{
82   win_window_info *       window;
143   win_window_info *      window;
83144   INT32                   minimum_width, minimum_height;
84145   INT32                   target_width, target_height;
85146   double                  target_refresh;
r243390r243391
102163//  INLINES
103164//============================================================
104165
105INLINE void update_outer_rects(dd_info *dd)
166inline void renderer_dd::update_outer_rects()
106167{
107   dd->clearouter = (dd->back != NULL) ? 3 : 1;
168   clearouter = (back != NULL) ? 3 : 1;
108169}
109170
110171
r243390r243391
123184
124185// core functions
125186static void drawdd_exit(void);
126static int drawdd_window_init(win_window_info *window);
127static void drawdd_window_destroy(win_window_info *window);
128static render_primitive_list *drawdd_window_get_primitives(win_window_info *window);
129static int drawdd_window_draw(win_window_info *window, HDC dc, int update);
130187
131// surface management
132static int ddraw_create(win_window_info *window);
133static int ddraw_create_surfaces(win_window_info *window);
134static void ddraw_delete(win_window_info *window);
135static void ddraw_delete_surfaces(win_window_info *window);
136static int ddraw_verify_caps(dd_info *dd);
137static int ddraw_test_cooperative(win_window_info *window);
138static HRESULT create_surface(dd_info *dd, DDSURFACEDESC2 *desc, IDirectDrawSurface7 **surface, const char *type);
139static int create_clipper(win_window_info *window);
140188
141// drawing helpers
142static void compute_blit_surface_size(win_window_info *window);
143static void blit_to_primary(win_window_info *window, int srcwidth, int srcheight);
144189
145// video modes
146static int config_adapter_mode(win_window_info *window);
147static void get_adapter_for_monitor(dd_info *dd, win_monitor_info *monitor);
148static void pick_best_mode(win_window_info *window);
190//============================================================
191//  drawnone_create
192//============================================================
149193
194static osd_renderer *drawdd_create(win_window_info *window)
195{
196   return global_alloc(renderer_dd(window));
197}
150198
151199
152200//============================================================
153201//  drawdd_init
154202//============================================================
155203
156int drawdd_init(running_machine &machine, win_draw_callbacks *callbacks)
204int drawdd_init(running_machine &machine, osd_draw_callbacks *callbacks)
157205{
158206   // dynamically grab the create function from ddraw.dll
159207   dllhandle = LoadLibrary(TEXT("ddraw.dll"));
r243390r243391
186234   // fill in the callbacks
187235   memset(callbacks, 0, sizeof(*callbacks));
188236   callbacks->exit = drawdd_exit;
189   callbacks->window_init = drawdd_window_init;
190   callbacks->window_get_primitives = drawdd_window_get_primitives;
191   callbacks->window_draw = drawdd_window_draw;
192   callbacks->window_destroy = drawdd_window_destroy;
237   callbacks->create = drawdd_create;
193238
194239   osd_printf_verbose("DirectDraw: Using DirectDraw 7\n");
195240   return 0;
r243390r243391
213258//  drawdd_window_init
214259//============================================================
215260
216static int drawdd_window_init(win_window_info *window)
261int renderer_dd::init()
217262{
218   dd_info *dd;
219
220   // allocate memory for our structures
221   dd = global_alloc_clear(dd_info);
222   window->m_drawdata = dd;
223
224263   // configure the adapter for the mode we want
225   if (config_adapter_mode(window))
264   if (config_adapter_mode())
226265      goto error;
227266
228267   // create the ddraw object
229   if (ddraw_create(window))
268   if (ddraw_create())
230269      goto error;
231270
232271   return 0;
233272
234273error:
235   drawdd_window_destroy(window);
274   destroy();
236275   osd_printf_error("Unable to initialize DirectDraw.\n");
237276   return 1;
238277}
r243390r243391
243282//  drawdd_window_destroy
244283//============================================================
245284
246static void drawdd_window_destroy(win_window_info *window)
285void renderer_dd::destroy()
247286{
248   dd_info *dd = (dd_info *)window->m_drawdata;
249
250   // skip if nothing
251   if (dd == NULL)
252      return;
253
254287   // delete the ddraw object
255   ddraw_delete(window);
256
257   // free the memory in the window
258   global_free(dd);
259   window->m_drawdata = NULL;
288   ddraw_delete();
260289}
261290
262291
r243390r243391
265294//  drawdd_window_get_primitives
266295//============================================================
267296
268static render_primitive_list *drawdd_window_get_primitives(win_window_info *window)
297render_primitive_list *renderer_dd::get_primitives()
269298{
270   dd_info *dd = (dd_info *)window->m_drawdata;
299   compute_blit_surface_size();
300   window().m_target->set_bounds(blitwidth, blitheight, 0);
301   window().m_target->set_max_update_rate((refresh == 0) ? origmode.dwRefreshRate : refresh);
271302
272   compute_blit_surface_size(window);
273   window->m_target->set_bounds(dd->blitwidth, dd->blitheight, 0);
274   window->m_target->set_max_update_rate((dd->refresh == 0) ? dd->origmode.dwRefreshRate : dd->refresh);
275
276   return &window->m_target->get_primitives();
303   return &window().m_target->get_primitives();
277304}
278305
279306
r243390r243391
282309//  drawdd_window_draw
283310//============================================================
284311
285static int drawdd_window_draw(win_window_info *window, HDC dc, int update)
312int renderer_dd::draw(HDC dc, int update)
286313{
287   dd_info *dd = (dd_info *)window->m_drawdata;
288314   render_primitive *prim;
289315   int usemembuffer = FALSE;
290316   HRESULT result;
291317
292   // if we haven't been created, just punt
293   if (dd == NULL)
294      return 1;
295
296318   // if we're updating, remember to erase the outer stuff
297319   if (update)
298      update_outer_rects(dd);
320      update_outer_rects();
299321
300322   // if we have a ddraw object, check the cooperative level
301   if (ddraw_test_cooperative(window))
323   if (ddraw_test_cooperative())
302324      return 1;
303325
304326   // get the size; if we're too small, delete the existing surfaces
305   if (dd->blitwidth > dd->blitdesc.dwWidth || dd->blitheight > dd->blitdesc.dwHeight)
306      ddraw_delete_surfaces(window);
327   if (blitwidth > blitdesc.dwWidth || blitheight > blitdesc.dwHeight)
328      ddraw_delete_surfaces();
307329
308330   // if we need to create surfaces, do it now
309   if (dd->blit == NULL && ddraw_create_surfaces(window) != 0)
331   if (blit == NULL && ddraw_create_surfaces() != 0)
310332      return 1;
311333
312334   // select our surface and lock it
313   result = IDirectDrawSurface7_Lock(dd->blit, NULL, &dd->blitdesc, DDLOCK_WAIT, NULL);
335   result = IDirectDrawSurface7_Lock(blit, NULL, &blitdesc, DDLOCK_WAIT, NULL);
314336   if (result == DDERR_SURFACELOST)
315337   {
316338      osd_printf_verbose("DirectDraw: Lost surfaces; deleting and retrying next frame\n");
317      ddraw_delete_surfaces(window);
339      ddraw_delete_surfaces();
318340      return 1;
319341   }
320342   if (result != DD_OK)
r243390r243391
324346   }
325347
326348   // render to it
327   window->m_primlist->acquire_lock();
349   window().m_primlist->acquire_lock();
328350
329351   // scan the list of primitives for tricky stuff
330   for (prim = window->m_primlist->first(); prim != NULL; prim = prim->next())
352   for (prim = window().m_primlist->first(); prim != NULL; prim = prim->next())
331353      if (PRIMFLAG_GET_BLENDMODE(prim->flags) != BLENDMODE_NONE ||
332354         (prim->texture.base != NULL && PRIMFLAG_GET_TEXFORMAT(prim->flags) == TEXFORMAT_ARGB32))
333355      {
r243390r243391
341363      int x, y;
342364
343365      // based on the target format, use one of our standard renderers
344      switch (dd->blitdesc.ddpfPixelFormat.dwRBitMask)
366      switch (blitdesc.ddpfPixelFormat.dwRBitMask)
345367      {
346         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;
347         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;
348         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;
349         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;
368         case 0x00ff0000:    software_renderer<UINT32, 0,0,0, 16,8,0>::draw_primitives(*window().m_primlist, membuffer, blitwidth, blitheight, blitwidth);  break;
369         case 0x000000ff:    software_renderer<UINT32, 0,0,0, 0,8,16>::draw_primitives(*window().m_primlist, membuffer, blitwidth, blitheight, blitwidth);  break;
370         case 0xf800:        software_renderer<UINT16, 3,2,3, 11,5,0>::draw_primitives(*window().m_primlist, membuffer, blitwidth, blitheight, blitwidth);  break;
371         case 0x7c00:        software_renderer<UINT16, 3,3,3, 10,5,0>::draw_primitives(*window().m_primlist, membuffer, blitwidth, blitheight, blitwidth);  break;
350372         default:
351            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);
373            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);
352374            break;
353375      }
354376
355377      // handle copying to both 16bpp and 32bpp destinations
356      for (y = 0; y < dd->blitheight; y++)
378      for (y = 0; y < blitheight; y++)
357379      {
358         if (dd->blitdesc.ddpfPixelFormat.dwRGBBitCount == 32)
380         if (blitdesc.ddpfPixelFormat.dwRGBBitCount == 32)
359381         {
360            UINT32 *src = (UINT32 *)dd->membuffer + y * dd->blitwidth;
361            UINT32 *dst = (UINT32 *)((UINT8 *)dd->blitdesc.lpSurface + y * dd->blitdesc.lPitch);
362            for (x = 0; x < dd->blitwidth; x++)
382            UINT32 *src = (UINT32 *)membuffer + y * blitwidth;
383            UINT32 *dst = (UINT32 *)((UINT8 *)blitdesc.lpSurface + y * blitdesc.lPitch);
384            for (x = 0; x < blitwidth; x++)
363385               *dst++ = *src++;
364386         }
365         else if (dd->blitdesc.ddpfPixelFormat.dwRGBBitCount == 16)
387         else if (blitdesc.ddpfPixelFormat.dwRGBBitCount == 16)
366388         {
367            UINT16 *src = (UINT16 *)dd->membuffer + y * dd->blitwidth;
368            UINT16 *dst = (UINT16 *)((UINT8 *)dd->blitdesc.lpSurface + y * dd->blitdesc.lPitch);
369            for (x = 0; x < dd->blitwidth; x++)
389            UINT16 *src = (UINT16 *)membuffer + y * blitwidth;
390            UINT16 *dst = (UINT16 *)((UINT8 *)blitdesc.lpSurface + y * blitdesc.lPitch);
391            for (x = 0; x < blitwidth; x++)
370392               *dst++ = *src++;
371393         }
372394      }
r243390r243391
377399   else
378400   {
379401      // based on the target format, use one of our standard renderers
380      switch (dd->blitdesc.ddpfPixelFormat.dwRBitMask)
402      switch (blitdesc.ddpfPixelFormat.dwRBitMask)
381403      {
382         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;
383         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;
384         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;
385         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;
404         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;
405         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;
406         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;
407         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;
386408         default:
387            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);
409            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);
388410            break;
389411      }
390412   }
391   window->m_primlist->release_lock();
413   window().m_primlist->release_lock();
392414
393415   // unlock and blit
394   result = IDirectDrawSurface7_Unlock(dd->blit, NULL);
416   result = IDirectDrawSurface7_Unlock(blit, NULL);
395417   if (result != DD_OK) osd_printf_verbose("DirectDraw: Error %08X unlocking blit surface\n", (int)result);
396418
397419   // sync to VBLANK
398   if ((video_config.waitvsync || video_config.syncrefresh) && window->machine().video().throttled() && (!window->m_fullscreen || dd->back == NULL))
420   if ((video_config.waitvsync || video_config.syncrefresh) && window().machine().video().throttled() && (!window().m_fullscreen || back == NULL))
399421   {
400      result = IDirectDraw7_WaitForVerticalBlank(dd->ddraw, DDWAITVB_BLOCKBEGIN, NULL);
422      result = IDirectDraw7_WaitForVerticalBlank(ddraw, DDWAITVB_BLOCKBEGIN, NULL);
401423      if (result != DD_OK) osd_printf_verbose("DirectDraw: Error %08X waiting for VBLANK\n", (int)result);
402424   }
403425
404426   // complete the blitting
405   blit_to_primary(window, dd->blitwidth, dd->blitheight);
427   blit_to_primary(blitwidth, blitheight);
406428   return 0;
407429}
408430
r243390r243391
412434//  ddraw_create
413435//============================================================
414436
415static int ddraw_create(win_window_info *window)
437int renderer_dd::ddraw_create()
416438{
417   dd_info *dd = (dd_info *)window->m_drawdata;
418439   HRESULT result;
419440   int verify;
420441
421442   // if a device exists, free it
422   if (dd->ddraw != NULL)
423      ddraw_delete(window);
443   if (ddraw != NULL)
444      ddraw_delete();
424445
425446   // create the DirectDraw object
426   result = (*directdrawcreateex)(dd->adapter_ptr, (LPVOID *)&dd->ddraw, WRAP_REFIID(IID_IDirectDraw7), NULL);
447   result = (*directdrawcreateex)(adapter_ptr, (LPVOID *)&ddraw, WRAP_REFIID(IID_IDirectDraw7), NULL);
427448   if (result != DD_OK)
428449   {
429450      osd_printf_verbose("DirectDraw: Error %08X during DirectDrawCreateEx call\n", (int)result);
r243390r243391
431452   }
432453
433454   // verify the caps
434   verify = ddraw_verify_caps(dd);
455   verify = ddraw_verify_caps();
435456   if (verify == 2)
436457   {
437458      osd_printf_error("DirectDraw: Error - Device does not meet minimum requirements for DirectDraw rendering\n");
r243390r243391
442463
443464   // set the cooperative level
444465   // for non-window modes, we will use full screen here
445   result = IDirectDraw7_SetCooperativeLevel(dd->ddraw, win_window_list->m_hwnd, DDSCL_SETFOCUSWINDOW);
466   result = IDirectDraw7_SetCooperativeLevel(ddraw, win_window_list->m_hwnd, DDSCL_SETFOCUSWINDOW);
446467   if (result != DD_OK)
447468   {
448469      osd_printf_verbose("DirectDraw: Error %08X during IDirectDraw7_SetCooperativeLevel(FOCUSWINDOW) call\n", (int)result);
449470      goto error;
450471   }
451   result = IDirectDraw7_SetCooperativeLevel(dd->ddraw, window->m_hwnd, DDSCL_SETDEVICEWINDOW | (window->m_fullscreen ? DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE : DDSCL_NORMAL));
472   result = IDirectDraw7_SetCooperativeLevel(ddraw, window().m_hwnd, DDSCL_SETDEVICEWINDOW | (window().m_fullscreen ? DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE : DDSCL_NORMAL));
452473   if (result != DD_OK)
453474   {
454475      osd_printf_verbose("DirectDraw: Error %08X during IDirectDraw7_SetCooperativeLevel(DEVICEWINDOW) call\n", (int)result);
r243390r243391
456477   }
457478
458479   // full screen mode: set the resolution
459   if (window->m_fullscreen && video_config.switchres)
480   if (window().m_fullscreen && video_config.switchres)
460481   {
461      result = IDirectDraw7_SetDisplayMode(dd->ddraw, dd->width, dd->height, 32, dd->refresh, 0);
482      result = IDirectDraw7_SetDisplayMode(ddraw, width, height, 32, refresh, 0);
462483      if (result != DD_OK)
463484      {
464         osd_printf_verbose("DirectDraw: Error %08X attempting to set video mode %dx%d@%d call\n", (int)result, dd->width, dd->height, dd->refresh);
485         osd_printf_verbose("DirectDraw: Error %08X attempting to set video mode %dx%d@%d call\n", (int)result, width, height, refresh);
465486         goto error;
466487      }
467488   }
468489
469   return ddraw_create_surfaces(window);
490   return ddraw_create_surfaces();
470491
471492error:
472   ddraw_delete(window);
493   ddraw_delete();
473494   return 1;
474495}
475496
r243390r243391
479500//  ddraw_create_surfaces
480501//============================================================
481502
482static int ddraw_create_surfaces(win_window_info *window)
503int renderer_dd::ddraw_create_surfaces()
483504{
484   dd_info *dd = (dd_info *)window->m_drawdata;
485505   HRESULT result;
486506
487507   // make a description of the primary surface
488   memset(&dd->primarydesc, 0, sizeof(dd->primarydesc));
489   dd->primarydesc.dwSize = sizeof(dd->primarydesc);
490   dd->primarydesc.dwFlags = DDSD_CAPS;
491   dd->primarydesc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
508   memset(&primarydesc, 0, sizeof(primarydesc));
509   primarydesc.dwSize = sizeof(primarydesc);
510   primarydesc.dwFlags = DDSD_CAPS;
511   primarydesc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
492512
493513   // for triple-buffered full screen mode, allocate flipping surfaces
494   if (window->m_fullscreen && video_config.triplebuf)
514   if (window().m_fullscreen && video_config.triplebuf)
495515   {
496      dd->primarydesc.dwFlags |= DDSD_BACKBUFFERCOUNT;
497      dd->primarydesc.ddsCaps.dwCaps |= DDSCAPS_FLIP | DDSCAPS_COMPLEX;
498      dd->primarydesc.dwBackBufferCount = 2;
516      primarydesc.dwFlags |= DDSD_BACKBUFFERCOUNT;
517      primarydesc.ddsCaps.dwCaps |= DDSCAPS_FLIP | DDSCAPS_COMPLEX;
518      primarydesc.dwBackBufferCount = 2;
499519   }
500520
501521   // create the primary surface and report errors
502   result = create_surface(dd, &dd->primarydesc, &dd->primary, "primary");
522   result = create_surface(&primarydesc, &primary, "primary");
503523   if (result != DD_OK) goto error;
504524
505525   // full screen mode: get the back surface
506   dd->back = NULL;
507   if (window->m_fullscreen && video_config.triplebuf)
526   back = NULL;
527   if (window().m_fullscreen && video_config.triplebuf)
508528   {
509529      DDSCAPS2 caps = { DDSCAPS_BACKBUFFER };
510      result = IDirectDrawSurface7_GetAttachedSurface(dd->primary, &caps, &dd->back);
530      result = IDirectDrawSurface7_GetAttachedSurface(primary, &caps, &back);
511531      if (result != DD_OK)
512532      {
513533         osd_printf_verbose("DirectDraw: Error %08X getting attached back surface\n", (int)result);
r243390r243391
516536   }
517537
518538   // now make a description of our blit surface, based on the primary surface
519   if (dd->blitwidth == 0 || dd->blitheight == 0)
520      compute_blit_surface_size(window);
521   dd->blitdesc = dd->primarydesc;
522   dd->blitdesc.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CAPS;
523   dd->blitdesc.dwWidth = dd->blitwidth;
524   dd->blitdesc.dwHeight = dd->blitheight;
525   dd->blitdesc.ddsCaps.dwCaps = DDSCAPS_VIDEOMEMORY;
539   if (blitwidth == 0 || blitheight == 0)
540      compute_blit_surface_size();
541   blitdesc = primarydesc;
542   blitdesc.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CAPS;
543   blitdesc.dwWidth = blitwidth;
544   blitdesc.dwHeight = blitheight;
545   blitdesc.ddsCaps.dwCaps = DDSCAPS_VIDEOMEMORY;
526546
527547   // then create the blit surface, fall back to system memory if video mem doesn't work
528   result = create_surface(dd, &dd->blitdesc, &dd->blit, "blit");
548   result = create_surface(&blitdesc, &blit, "blit");
529549   if (result != DD_OK)
530550   {
531      dd->blitdesc.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY;
532      result = create_surface(dd, &dd->blitdesc, &dd->blit, "blit");
551      blitdesc.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY;
552      result = create_surface(&blitdesc, &blit, "blit");
533553   }
534554   if (result != DD_OK) goto error;
535555
536556   // create a memory buffer for offscreen drawing
537   if (dd->membuffersize < dd->blitwidth * dd->blitheight * 4)
557   if (membuffersize < blitwidth * blitheight * 4)
538558   {
539      dd->membuffersize = dd->blitwidth * dd->blitheight * 4;
540      global_free_array(dd->membuffer);
541      dd->membuffer = global_alloc_array(UINT8, dd->membuffersize);
559      membuffersize = blitwidth * blitheight * 4;
560      global_free_array(membuffer);
561      membuffer = global_alloc_array(UINT8, membuffersize);
542562   }
543   if (dd->membuffer == NULL)
563   if (membuffer == NULL)
544564      goto error;
545565
546566   // create a clipper for windowed mode
547   if (!window->m_fullscreen && create_clipper(window))
567   if (!window().m_fullscreen && create_clipper())
548568      goto error;
549569
550570   // full screen mode: set the gamma
551   if (window->m_fullscreen)
571   if (window().m_fullscreen)
552572   {
553573      // only set the gamma if it's not 1.0f
554      windows_options &options = downcast<windows_options &>(window->machine().options());
574      windows_options &options = downcast<windows_options &>(window().machine().options());
555575      float brightness = options.full_screen_brightness();
556576      float contrast = options.full_screen_contrast();
557      float gamma = options.full_screen_gamma();
558      if (brightness != 1.0f || contrast != 1.0f || gamma != 1.0f)
577      float fgamma = options.full_screen_gamma();
578      if (brightness != 1.0f || contrast != 1.0f || fgamma != 1.0f)
559579      {
560580         // see if we can get a GammaControl object
561         result = IDirectDrawSurface_QueryInterface(dd->primary, WRAP_REFIID(IID_IDirectDrawGammaControl), (void **)&dd->gamma);
581         result = IDirectDrawSurface_QueryInterface(primary, WRAP_REFIID(IID_IDirectDrawGammaControl), (void **)&gamma);
562582         if (result != DD_OK)
563583         {
564584            osd_printf_warning("DirectDraw: Warning - device does not support full screen gamma correction.\n");
565            dd->gamma = NULL;
585            this->gamma = NULL;
566586         }
567587
568588         // proceed if we can
569         if (dd->gamma != NULL)
589         if (this->gamma != NULL)
570590         {
571591            DDGAMMARAMP ramp;
572592            int i;
573593
574594            // create a standard ramp and set it
575595            for (i = 0; i < 256; i++)
576               ramp.red[i] = ramp.green[i] = ramp.blue[i] = apply_brightness_contrast_gamma(i, brightness, contrast, gamma) << 8;
596               ramp.red[i] = ramp.green[i] = ramp.blue[i] = apply_brightness_contrast_gamma(i, brightness, contrast, fgamma) << 8;
577597
578598            // attempt to set it
579            result = IDirectDrawGammaControl_SetGammaRamp(dd->gamma, 0, &ramp);
599            result = IDirectDrawGammaControl_SetGammaRamp(this->gamma, 0, &ramp);
580600            if (result != DD_OK)
581601               osd_printf_verbose("DirectDraw: Error %08X attempting to set gamma correction.\n", (int)result);
582602         }
r243390r243391
584604   }
585605
586606   // force some updates
587   update_outer_rects(dd);
607   update_outer_rects();
588608   return 0;
589609
590610error:
591   ddraw_delete_surfaces(window);
611   ddraw_delete_surfaces();
592612   return 1;
593613}
594614
r243390r243391
598618//  ddraw_delete
599619//============================================================
600620
601static void ddraw_delete(win_window_info *window)
621void renderer_dd::ddraw_delete()
602622{
603   dd_info *dd = (dd_info *)window->m_drawdata;
604
605623   // free surfaces
606   ddraw_delete_surfaces(window);
624   ddraw_delete_surfaces();
607625
608626   // restore resolutions
609   if (dd->ddraw != NULL)
610      IDirectDraw7_RestoreDisplayMode(dd->ddraw);
627   if (ddraw != NULL)
628      IDirectDraw7_RestoreDisplayMode(ddraw);
611629
612630   // reset cooperative level
613   if (dd->ddraw != NULL && window->m_hwnd != NULL)
614      IDirectDraw7_SetCooperativeLevel(dd->ddraw, window->m_hwnd, DDSCL_NORMAL);
631   if (ddraw != NULL && window().m_hwnd != NULL)
632      IDirectDraw7_SetCooperativeLevel(ddraw, window().m_hwnd, DDSCL_NORMAL);
615633
616634   // release the DirectDraw object itself
617   if (dd->ddraw != NULL)
618      IDirectDraw7_Release(dd->ddraw);
619   dd->ddraw = NULL;
635   if (ddraw != NULL)
636      IDirectDraw7_Release(ddraw);
637   ddraw = NULL;
620638}
621639
622640
r243390r243391
625643//  ddraw_delete_surfaces
626644//============================================================
627645
628static void ddraw_delete_surfaces(win_window_info *window)
646void renderer_dd::ddraw_delete_surfaces()
629647{
630   dd_info *dd = (dd_info *)window->m_drawdata;
631
632648   // release the gamma control
633   if (dd->gamma != NULL)
634      IDirectDrawGammaControl_Release(dd->gamma);
635   dd->gamma = NULL;
649   if (gamma != NULL)
650      IDirectDrawGammaControl_Release(gamma);
651   gamma = NULL;
636652
637653   // release the clipper
638   if (dd->clipper != NULL)
639      IDirectDrawClipper_Release(dd->clipper);
640   dd->clipper = NULL;
654   if (clipper != NULL)
655      IDirectDrawClipper_Release(clipper);
656   clipper = NULL;
641657
642658   // free the memory buffer
643   global_free_array(dd->membuffer);
644   dd->membuffer = NULL;
645   dd->membuffersize = 0;
659   global_free_array(membuffer);
660   membuffer = NULL;
661   membuffersize = 0;
646662
647663   // release the blit surface
648   if (dd->blit != NULL)
649      IDirectDrawSurface7_Release(dd->blit);
650   dd->blit = NULL;
664   if (blit != NULL)
665      IDirectDrawSurface7_Release(blit);
666   blit = NULL;
651667
652668   // release the back surface
653   if (dd->back != NULL)
654      IDirectDrawSurface7_Release(dd->back);
655   dd->back = NULL;
669   if (back != NULL)
670      IDirectDrawSurface7_Release(back);
671   back = NULL;
656672
657673   // release the primary surface
658   if (dd->primary != NULL)
659      IDirectDrawSurface7_Release(dd->primary);
660   dd->primary = NULL;
674   if (primary != NULL)
675      IDirectDrawSurface7_Release(primary);
676   primary = NULL;
661677}
662678
663679
r243390r243391
666682//  ddraw_verify_caps
667683//============================================================
668684
669static int ddraw_verify_caps(dd_info *dd)
685int renderer_dd::ddraw_verify_caps()
670686{
671687   int retval = 0;
672688   HRESULT result;
673689
674690   // get the capabilities
675   dd->ddcaps.dwSize = sizeof(dd->ddcaps);
676   dd->helcaps.dwSize = sizeof(dd->helcaps);
677   result = IDirectDraw7_GetCaps(dd->ddraw, &dd->ddcaps, &dd->helcaps);
691   ddcaps.dwSize = sizeof(ddcaps);
692   helcaps.dwSize = sizeof(helcaps);
693   result = IDirectDraw7_GetCaps(ddraw, &ddcaps, &helcaps);
678694   if (result != DD_OK)
679695   {
680696      osd_printf_verbose("DirectDraw: Error %08X during IDirectDraw7_GetCaps call\n", (int)result);
r243390r243391
682698   }
683699
684700   // determine if hardware stretching is available
685   if ((dd->ddcaps.dwCaps & DDCAPS_BLTSTRETCH) == 0)
701   if ((ddcaps.dwCaps & DDCAPS_BLTSTRETCH) == 0)
686702   {
687703      osd_printf_verbose("DirectDraw: Warning - Device does not support hardware stretching\n");
688704      retval = 1;
r243390r243391
697713//  ddraw_test_cooperative
698714//============================================================
699715
700static int ddraw_test_cooperative(win_window_info *window)
716int renderer_dd::ddraw_test_cooperative()
701717{
702   dd_info *dd = (dd_info *)window->m_drawdata;
703718   HRESULT result;
704719
705720   // check our current status; if we lost the device, punt to GDI
706   result = IDirectDraw7_TestCooperativeLevel(dd->ddraw);
721   result = IDirectDraw7_TestCooperativeLevel(ddraw);
707722   switch (result)
708723   {
709724      // punt to GDI if someone else has exclusive mode
710725      case DDERR_NOEXCLUSIVEMODE:
711726      case DDERR_EXCLUSIVEMODEALREADYSET:
712         ddraw_delete_surfaces(window);
727         ddraw_delete_surfaces();
713728         return 1;
714729
715730      // if we're ok, but we don't have a primary surface, create one
716731      default:
717732      case DD_OK:
718         if (dd->primary == NULL)
719            return ddraw_create_surfaces(window);
733         if (primary == NULL)
734            return ddraw_create_surfaces();
720735         return 0;
721736   }
722737}
r243390r243391
727742//  create_surface
728743//============================================================
729744
730static HRESULT create_surface(dd_info *dd, DDSURFACEDESC2 *desc, IDirectDrawSurface7 **surface, const char *type)
745HRESULT renderer_dd::create_surface(DDSURFACEDESC2 *desc, IDirectDrawSurface7 **surface, const char *type)
731746{
732747   HRESULT result;
733748
734749   // create the surface as requested
735   result = IDirectDraw7_CreateSurface(dd->ddraw, desc, surface, NULL);
750   result = IDirectDraw7_CreateSurface(ddraw, desc, surface, NULL);
736751   if (result != DD_OK)
737752   {
738753      osd_printf_verbose("DirectDraw: Error %08X creating %s surface\n", (int)result, type);
r243390r243391
767782//  create_clipper
768783//============================================================
769784
770static int create_clipper(win_window_info *window)
785int renderer_dd::create_clipper()
771786{
772   dd_info *dd = (dd_info *)window->m_drawdata;
773787   HRESULT result;
774788
775789   // create a clipper for the primary surface
776   result = IDirectDraw7_CreateClipper(dd->ddraw, 0, &dd->clipper, NULL);
790   result = IDirectDraw7_CreateClipper(ddraw, 0, &clipper, NULL);
777791   if (result != DD_OK)
778792   {
779793      osd_printf_verbose("DirectDraw: Error %08X creating clipper\n", (int)result);
r243390r243391
781795   }
782796
783797   // set the clipper's hwnd
784   result = IDirectDrawClipper_SetHWnd(dd->clipper, 0, window->m_hwnd);
798   result = IDirectDrawClipper_SetHWnd(clipper, 0, window().m_hwnd);
785799   if (result != DD_OK)
786800   {
787801      osd_printf_verbose("DirectDraw: Error %08X setting clipper hwnd\n", (int)result);
r243390r243391
789803   }
790804
791805   // set the clipper on the primary surface
792   result = IDirectDrawSurface7_SetClipper(dd->primary, dd->clipper);
806   result = IDirectDrawSurface7_SetClipper(primary, clipper);
793807   if (result != DD_OK)
794808   {
795809      osd_printf_verbose("DirectDraw: Error %08X setting clipper on primary surface\n", (int)result);
r243390r243391
804818//  compute_blit_surface_size
805819//============================================================
806820
807static void compute_blit_surface_size(win_window_info *window)
821void renderer_dd::compute_blit_surface_size()
808822{
809   dd_info *dd = (dd_info *)window->m_drawdata;
810823   INT32 newwidth, newheight;
811824   int xscale, yscale;
812825   RECT client;
813826
814827   // start with the minimum size
815   window->m_target->compute_minimum_size(newwidth, newheight);
828   window().m_target->compute_minimum_size(newwidth, newheight);
816829
817830   // get the window's client rectangle
818   GetClientRect(window->m_hwnd, &client);
831   GetClientRect(window().m_hwnd, &client);
819832
820833   // hardware stretch case: apply prescale
821834   if (video_config.hwstretch)
r243390r243391
841854      // compute the appropriate visible area if we're trying to keepaspect
842855      if (video_config.keepaspect)
843856      {
844         win_monitor_info *monitor = winwindow_video_window_monitor(window, NULL);
845         window->m_target->compute_visible_area(target_width, target_height, monitor->get_aspect(), window->m_target->orientation(), target_width, target_height);
857         win_monitor_info *monitor = winwindow_video_window_monitor(&window(), NULL);
858         window().m_target->compute_visible_area(target_width, target_height, monitor->get_aspect(), window().m_target->orientation(), target_width, target_height);
846859         desired_aspect = (float)target_width / (float)target_height;
847860      }
848861
r243390r243391
884897   // apply the final scale
885898   newwidth *= xscale;
886899   newheight *= yscale;
887   if (newwidth != dd->blitwidth || newheight != dd->blitheight)
900   if (newwidth != blitwidth || newheight != blitheight)
888901   {
889902      // force some updates
890      update_outer_rects(dd);
903      update_outer_rects();
891904      osd_printf_verbose("DirectDraw: New blit size = %dx%d\n", newwidth, newheight);
892905   }
893   dd->blitwidth = newwidth;
894   dd->blitheight = newheight;
906   blitwidth = newwidth;
907   blitheight = newheight;
895908}
896909
897910
r243390r243391
900913//  calc_fullscreen_margins
901914//============================================================
902915
903static void calc_fullscreen_margins(win_window_info *window, DWORD desc_width, DWORD desc_height, RECT *margins)
916void renderer_dd::calc_fullscreen_margins(DWORD desc_width, DWORD desc_height, RECT *margins)
904917{
905918   margins->left = 0;
906919   margins->top = 0;
907920   margins->right = desc_width;
908921   margins->bottom = desc_height;
909922
910   if (win_has_menu(window))
923   if (win_has_menu(&window()))
911924   {
912925      static int height_with_menubar = 0;
913926      if (height_with_menubar == 0)
r243390r243391
928941//  blit_to_primary
929942//============================================================
930943
931static void blit_to_primary(win_window_info *window, int srcwidth, int srcheight)
944void renderer_dd::blit_to_primary(int srcwidth, int srcheight)
932945{
933   dd_info *dd = (dd_info *)window->m_drawdata;
934   IDirectDrawSurface7 *target = (dd->back != NULL) ? dd->back : dd->primary;
935   win_monitor_info *monitor = winwindow_video_window_monitor(window, NULL);
946   IDirectDrawSurface7 *target = (back != NULL) ? back : primary;
947   win_monitor_info *monitor = winwindow_video_window_monitor(&window(), NULL);
936948   DDBLTFX blitfx = { sizeof(DDBLTFX) };
937949   RECT clear, outer, dest, source;
938950   INT32 dstwidth, dstheight;
r243390r243391
944956   source.bottom = srcheight;
945957
946958   // compute outer rect -- windowed version
947   if (!window->m_fullscreen)
959   if (!window().m_fullscreen)
948960   {
949      GetClientRect(window->m_hwnd, &outer);
950      ClientToScreen(window->m_hwnd, &((LPPOINT)&outer)[0]);
951      ClientToScreen(window->m_hwnd, &((LPPOINT)&outer)[1]);
961      GetClientRect(window().m_hwnd, &outer);
962      ClientToScreen(window().m_hwnd, &((LPPOINT)&outer)[0]);
963      ClientToScreen(window().m_hwnd, &((LPPOINT)&outer)[1]);
952964
953965      // adjust to be relative to the monitor
954966      outer.left -= monitor->info.rcMonitor.left;
r243390r243391
960972   // compute outer rect -- full screen version
961973   else
962974   {
963      calc_fullscreen_margins(window, dd->primarydesc.dwWidth, dd->primarydesc.dwHeight, &outer);
975      calc_fullscreen_margins(primarydesc.dwWidth, primarydesc.dwHeight, &outer);
964976   }
965977
966978   // if we're respecting the aspect ratio, we need to adjust to fit
r243390r243391
987999   else if (video_config.keepaspect)
9881000   {
9891001      // compute the appropriate visible area
990      window->m_target->compute_visible_area(rect_width(&outer), rect_height(&outer), monitor->get_aspect(), window->m_target->orientation(), dstwidth, dstheight);
1002      window().m_target->compute_visible_area(rect_width(&outer), rect_height(&outer), monitor->get_aspect(), window().m_target->orientation(), dstwidth, dstheight);
9911003   }
9921004
9931005   // center within
r243390r243391
9971009   dest.bottom = dest.top + dstheight;
9981010
9991011   // compare against last destination; if different, force a redraw
1000   if (dest.left != dd->lastdest.left || dest.right != dd->lastdest.right || dest.top != dd->lastdest.top || dest.bottom != dd->lastdest.bottom)
1012   if (dest.left != lastdest.left || dest.right != lastdest.right || dest.top != lastdest.top || dest.bottom != lastdest.bottom)
10011013   {
1002      dd->lastdest = dest;
1003      update_outer_rects(dd);
1014      lastdest = dest;
1015      update_outer_rects();
10041016   }
10051017
10061018   // clear outer rects if we need to
1007   if (dd->clearouter != 0)
1019   if (clearouter != 0)
10081020   {
1009      dd->clearouter--;
1021      clearouter--;
10101022
10111023      // clear the left edge
10121024      if (dest.left > outer.left)
r243390r243391
10461058   }
10471059
10481060   // do the blit
1049   result = IDirectDrawSurface7_Blt(target, &dest, dd->blit, &source, DDBLT_WAIT, NULL);
1061   result = IDirectDrawSurface7_Blt(target, &dest, blit, &source, DDBLT_WAIT, NULL);
10501062   if (result != DD_OK) osd_printf_verbose("DirectDraw: Error %08X blitting to the screen\n", (int)result);
10511063
10521064   // page flip if triple buffered
1053   if (window->m_fullscreen && dd->back != NULL)
1065   if (window().m_fullscreen && back != NULL)
10541066   {
1055      result = IDirectDrawSurface7_Flip(dd->primary, NULL, DDFLIP_WAIT);
1067      result = IDirectDrawSurface7_Flip(primary, NULL, DDFLIP_WAIT);
10561068      if (result != DD_OK) osd_printf_verbose("DirectDraw: Error %08X waiting for VBLANK\n", (int)result);
10571069   }
10581070}
r243390r243391
10631075//  config_adapter_mode
10641076//============================================================
10651077
1066static int config_adapter_mode(win_window_info *window)
1078int renderer_dd::config_adapter_mode()
10671079{
10681080   DDDEVICEIDENTIFIER2 identifier;
1069   dd_info *dd = (dd_info *)window->m_drawdata;
10701081   HRESULT result;
10711082
10721083   // choose the monitor number
1073   get_adapter_for_monitor(dd, window->m_monitor);
1084   get_adapter_for_monitor(window().m_monitor);
10741085
10751086   // create a temporary DirectDraw object
1076   result = (*directdrawcreateex)(dd->adapter_ptr, (LPVOID *)&dd->ddraw, WRAP_REFIID(IID_IDirectDraw7), NULL);
1087   result = (*directdrawcreateex)(adapter_ptr, (LPVOID *)&ddraw, WRAP_REFIID(IID_IDirectDraw7), NULL);
10771088   if (result != DD_OK)
10781089   {
10791090      osd_printf_verbose("DirectDraw: Error %08X during DirectDrawCreateEx call\n", (int)result);
r243390r243391
10811092   }
10821093
10831094   // get the identifier
1084   result = IDirectDraw7_GetDeviceIdentifier(dd->ddraw, &identifier, 0);
1095   result = IDirectDraw7_GetDeviceIdentifier(ddraw, &identifier, 0);
10851096   if (result != DD_OK)
10861097   {
10871098      osd_printf_error("Error getting identifier for device\n");
r243390r243391
10901101   osd_printf_verbose("DirectDraw: Configuring device %s\n", identifier.szDescription);
10911102
10921103   // get the current display mode
1093   memset(&dd->origmode, 0, sizeof(dd->origmode));
1094   dd->origmode.dwSize = sizeof(dd->origmode);
1095   result = IDirectDraw7_GetDisplayMode(dd->ddraw, &dd->origmode);
1104   memset(&origmode, 0, sizeof(origmode));
1105   origmode.dwSize = sizeof(origmode);
1106   result = IDirectDraw7_GetDisplayMode(ddraw, &origmode);
10961107   if (result != DD_OK)
10971108   {
10981109      osd_printf_verbose("DirectDraw: Error %08X getting current display mode\n", (int)result);
1099      IDirectDraw7_Release(dd->ddraw);
1110      IDirectDraw7_Release(ddraw);
11001111      return 1;
11011112   }
11021113
11031114   // choose a resolution: full screen mode case
1104   if (window->m_fullscreen)
1115   if (window().m_fullscreen)
11051116   {
11061117      // default to the current mode exactly
1107      dd->width = dd->origmode.dwWidth;
1108      dd->height = dd->origmode.dwHeight;
1109      dd->refresh = dd->origmode.dwRefreshRate;
1118      width = origmode.dwWidth;
1119      height = origmode.dwHeight;
1120      refresh = origmode.dwRefreshRate;
11101121
11111122      // if we're allowed to switch resolutions, override with something better
11121123      if (video_config.switchres)
1113         pick_best_mode(window);
1124         pick_best_mode();
11141125   }
11151126
11161127   // release the DirectDraw object
1117   IDirectDraw7_Release(dd->ddraw);
1118   dd->ddraw = NULL;
1128   IDirectDraw7_Release(ddraw);
1129   ddraw = NULL;
11191130
11201131   // if we're not changing resolutions, make sure we have a resolution we can handle
1121   if (!window->m_fullscreen || !video_config.switchres)
1132   if (!window().m_fullscreen || !video_config.switchres)
11221133   {
1123      switch (dd->origmode.ddpfPixelFormat.dwRBitMask)
1134      switch (origmode.ddpfPixelFormat.dwRBitMask)
11241135      {
11251136         case 0x00ff0000:
11261137         case 0x000000ff:
r243390r243391
11291140            break;
11301141
11311142         default:
1132            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);
1143            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);
11331144            return 1;
11341145      }
11351146   }
r243390r243391
11641175//  get_adapter_for_monitor
11651176//============================================================
11661177
1167static void get_adapter_for_monitor(dd_info *dd, win_monitor_info *monitor)
1178void renderer_dd::get_adapter_for_monitor(win_monitor_info *monitor)
11681179{
11691180   monitor_enum_info einfo;
11701181   HRESULT result;
r243390r243391
11781189   // set up the adapter
11791190   if (einfo.foundit && einfo.guid_ptr != NULL)
11801191   {
1181      dd->adapter = einfo.guid;
1182      dd->adapter_ptr = &dd->adapter;
1192      adapter = einfo.guid;
1193      adapter_ptr = &adapter;
11831194   }
11841195   else
1185      dd->adapter_ptr = NULL;
1196      adapter_ptr = NULL;
11861197}
11871198
11881199
r243390r243391
11951206{
11961207   float size_score, refresh_score, final_score;
11971208   mode_enum_info *einfo = (mode_enum_info *)context;
1198   dd_info *dd = (dd_info *)einfo->window->m_drawdata;
1209   renderer_dd *dd = dynamic_cast<renderer_dd *>(einfo->window->m_renderer);
11991210
12001211   // skip non-32 bit modes
12011212   if (desc->ddpfPixelFormat.dwRGBBitCount != 32)
r243390r243391
12481259//  pick_best_mode
12491260//============================================================
12501261
1251static void pick_best_mode(win_window_info *window)
1262void renderer_dd::pick_best_mode()
12521263{
1253   dd_info *dd = (dd_info *)window->m_drawdata;
12541264   mode_enum_info einfo;
12551265   HRESULT result;
12561266
r243390r243391
12581268   // note: technically we should not be calling this from an alternate window
12591269   // thread; however, it is only done during init time, and the init code on
12601270   // the main thread is waiting for us to finish, so it is safe to do so here
1261   window->m_target->compute_minimum_size(einfo.minimum_width, einfo.minimum_height);
1271   window().m_target->compute_minimum_size(einfo.minimum_width, einfo.minimum_height);
12621272
12631273   // use those as the target for now
12641274   einfo.target_width = einfo.minimum_width * MAX(1, video_config.prescale);
r243390r243391
12661276
12671277   // determine the refresh rate of the primary screen
12681278   einfo.target_refresh = 60.0;
1269   const screen_device *primary_screen = window->machine().config().first_screen();
1279   const screen_device *primary_screen = window().machine().config().first_screen();
12701280   if (primary_screen != NULL)
12711281      einfo.target_refresh = ATTOSECONDS_TO_HZ(primary_screen->refresh_attoseconds());
12721282   printf("Target refresh = %f\n", einfo.target_refresh);
r243390r243391
12861296   }
12871297
12881298   // fill in the rest of the data
1289   einfo.window = window;
1299   einfo.window = &window();
12901300   einfo.best_score = 0.0f;
12911301
12921302   // enumerate the modes
12931303   osd_printf_verbose("DirectDraw: Selecting video mode...\n");
1294   result = IDirectDraw7_EnumDisplayModes(dd->ddraw, DDEDM_REFRESHRATES, NULL, &einfo, enum_modes_callback);
1304   result = IDirectDraw7_EnumDisplayModes(ddraw, DDEDM_REFRESHRATES, NULL, &einfo, enum_modes_callback);
12951305   if (result != DD_OK) osd_printf_verbose("DirectDraw: Error %08X during EnumDisplayModes call\n", (int)result);
1296   osd_printf_verbose("DirectDraw: Mode selected = %4dx%4d@%3dHz\n", dd->width, dd->height, dd->refresh);
1306   osd_printf_verbose("DirectDraw: Mode selected = %4dx%4d@%3dHz\n", width, height, refresh);
12971307}
trunk/src/osd/windows/drawgdi.c
r243390r243391
1818#include "window.h"
1919
2020
21
2221//============================================================
2322//  TYPE DEFINITIONS
2423//============================================================
2524
26/* gdi_info is the information for the current screen */
27struct gdi_info
25class renderer_gdi : public osd_renderer
2826{
27public:
28   renderer_gdi(win_window_info *window)
29   : osd_renderer(window, FLAG_NONE), bmdata(NULL), bmsize(0) { }
30
31   virtual ~renderer_gdi() { }
32
33   virtual int init();
34   virtual render_primitive_list *get_primitives();
35   virtual int draw(HDC dc, int update);
36   virtual void save() {};
37   virtual void record() {};
38   virtual void toggle_fsfx() {};
39   virtual void destroy();
40
41private:
42   /* gdi_info is the information for the current screen */
2943   BITMAPINFO              bminfo;
3044   UINT8 *                 bmdata;
3145   size_t                  bmsize;
3246};
3347
3448
35
3649//============================================================
3750//  PROTOTYPES
3851//============================================================
3952
4053// core functions
4154static void drawgdi_exit(void);
42static int drawgdi_window_init(win_window_info *window);
43static void drawgdi_window_destroy(win_window_info *window);
44static render_primitive_list *drawgdi_window_get_primitives(win_window_info *window);
45static int drawgdi_window_draw(win_window_info *window, HDC dc, int update);
4655
56//============================================================
57//  drawnone_create
58//============================================================
4759
60static osd_renderer *drawgdi_create(win_window_info *window)
61{
62   return global_alloc(renderer_gdi(window));
63}
4864
65
4966//============================================================
5067//  drawgdi_init
5168//============================================================
5269
53int drawgdi_init(running_machine &machine, win_draw_callbacks *callbacks)
70int drawgdi_init(running_machine &machine, osd_draw_callbacks *callbacks)
5471{
5572   // fill in the callbacks
5673   memset(callbacks, 0, sizeof(*callbacks));
5774   callbacks->exit = drawgdi_exit;
58   callbacks->window_init = drawgdi_window_init;
59   callbacks->window_get_primitives = drawgdi_window_get_primitives;
60   callbacks->window_draw = drawgdi_window_draw;
61   callbacks->window_destroy = drawgdi_window_destroy;
75   callbacks->create = drawgdi_create;
6276   return 0;
6377}
6478
r243390r243391
7892//  drawgdi_window_init
7993//============================================================
8094
81static int drawgdi_window_init(win_window_info *window)
95int renderer_gdi::init()
8296{
83   // allocate memory for our structures
84   gdi_info *gdi = global_alloc_clear(gdi_info);
85   window->m_drawdata = gdi;
8697
8798   // fill in the bitmap info header
88   gdi->bminfo.bmiHeader.biSize            = sizeof(gdi->bminfo.bmiHeader);
89   gdi->bminfo.bmiHeader.biPlanes          = 1;
90   gdi->bminfo.bmiHeader.biBitCount        = 32;
91   gdi->bminfo.bmiHeader.biCompression     = BI_RGB;
92   gdi->bminfo.bmiHeader.biSizeImage       = 0;
93   gdi->bminfo.bmiHeader.biXPelsPerMeter   = 0;
94   gdi->bminfo.bmiHeader.biYPelsPerMeter   = 0;
95   gdi->bminfo.bmiHeader.biClrUsed         = 0;
96   gdi->bminfo.bmiHeader.biClrImportant    = 0;
99   bminfo.bmiHeader.biSize            = sizeof(bminfo.bmiHeader);
100   bminfo.bmiHeader.biPlanes          = 1;
101   bminfo.bmiHeader.biBitCount        = 32;
102   bminfo.bmiHeader.biCompression     = BI_RGB;
103   bminfo.bmiHeader.biSizeImage       = 0;
104   bminfo.bmiHeader.biXPelsPerMeter   = 0;
105   bminfo.bmiHeader.biYPelsPerMeter   = 0;
106   bminfo.bmiHeader.biClrUsed         = 0;
107   bminfo.bmiHeader.biClrImportant    = 0;
97108
98109   return 0;
99110}
r243390r243391
104115//  drawgdi_window_destroy
105116//============================================================
106117
107static void drawgdi_window_destroy(win_window_info *window)
118void renderer_gdi::destroy()
108119{
109   gdi_info *gdi = (gdi_info *)window->m_drawdata;
110120
111   // skip if nothing
112   if (gdi == NULL)
113      return;
114
115121   // free the bitmap memory
116   if (gdi->bmdata != NULL)
117      global_free_array(gdi->bmdata);
118   global_free(gdi);
119   window->m_drawdata = NULL;
122   if (bmdata != NULL)
123      global_free_array(bmdata);
120124}
121125
122126
r243390r243391
125129//  drawgdi_window_get_primitives
126130//============================================================
127131
128static render_primitive_list *drawgdi_window_get_primitives(win_window_info *window)
132render_primitive_list *renderer_gdi::get_primitives()
129133{
130134   RECT client;
131   GetClientRect(window->m_hwnd, &client);
132   window->m_target->set_bounds(rect_width(&client), rect_height(&client), window->m_monitor->get_aspect());
133   return &window->m_target->get_primitives();
135   GetClientRect(window().m_hwnd, &client);
136   window().m_target->set_bounds(rect_width(&client), rect_height(&client), window().m_monitor->get_aspect());
137   return &window().m_target->get_primitives();
134138}
135139
136140
r243390r243391
139143//  drawgdi_window_draw
140144//============================================================
141145
142static int drawgdi_window_draw(win_window_info *window, HDC dc, int update)
146int renderer_gdi::draw(HDC dc, int update)
143147{
144   gdi_info *gdi = (gdi_info *)window->m_drawdata;
145148   int width, height, pitch;
146149   RECT bounds;
147150
148151   // we don't have any special resize behaviors
149   if (window->m_resize_state == RESIZE_STATE_PENDING)
150      window->m_resize_state = RESIZE_STATE_NORMAL;
152   if (window().m_resize_state == RESIZE_STATE_PENDING)
153      window().m_resize_state = RESIZE_STATE_NORMAL;
151154
152155   // get the target bounds
153   GetClientRect(window->m_hwnd, &bounds);
156   GetClientRect(window().m_hwnd, &bounds);
154157
155158   // compute width/height/pitch of target
156159   width = rect_width(&bounds);
r243390r243391
158161   pitch = (width + 3) & ~3;
159162
160163   // make sure our temporary bitmap is big enough
161   if (pitch * height * 4 > gdi->bmsize)
164   if (pitch * height * 4 > bmsize)
162165   {
163      gdi->bmsize = pitch * height * 4 * 2;
164      global_free_array(gdi->bmdata);
165      gdi->bmdata = global_alloc_array(UINT8, gdi->bmsize);
166      bmsize = pitch * height * 4 * 2;
167      global_free_array(bmdata);
168      bmdata = global_alloc_array(UINT8, bmsize);
166169   }
167170
168171   // draw the primitives to the bitmap
169   window->m_primlist->acquire_lock();
170   software_renderer<UINT32, 0,0,0, 16,8,0>::draw_primitives(*window->m_primlist, gdi->bmdata, width, height, pitch);
171   window->m_primlist->release_lock();
172   window().m_primlist->acquire_lock();
173   software_renderer<UINT32, 0,0,0, 16,8,0>::draw_primitives(*window().m_primlist, bmdata, width, height, pitch);
174   window().m_primlist->release_lock();
172175
173176   // fill in bitmap-specific info
174   gdi->bminfo.bmiHeader.biWidth = pitch;
175   gdi->bminfo.bmiHeader.biHeight = -height;
177   bminfo.bmiHeader.biWidth = pitch;
178   bminfo.bmiHeader.biHeight = -height;
176179
177180   // blit to the screen
178181   StretchDIBits(dc, 0, 0, width, height,
179182            0, 0, width, height,
180            gdi->bmdata, &gdi->bminfo, DIB_RGB_COLORS, SRCCOPY);
183            bmdata, &bminfo, DIB_RGB_COLORS, SRCCOPY);
181184   return 0;
182185}
trunk/src/osd/windows/drawnone.c
r243390r243391
1717#include "window.h"
1818
1919
20class renderer_none : public osd_renderer
21{
22public:
23   renderer_none(win_window_info *window)
24   : osd_renderer(window, FLAG_NONE) { }
2025
26   virtual ~renderer_none() { }
27
28   virtual int init();
29   virtual render_primitive_list *get_primitives();
30   virtual int draw(HDC dc, int update);
31   virtual void save() { };
32   virtual void record() { };
33   virtual void toggle_fsfx() { };
34   virtual void destroy();
35
36private:
37};
38
2139//============================================================
2240//  PROTOTYPES
2341//============================================================
2442
2543// core functions
2644static void drawnone_exit(void);
27static int drawnone_window_init(win_window_info *window);
28static void drawnone_window_destroy(win_window_info *window);
29static render_primitive_list *drawnone_window_get_primitives(win_window_info *window);
30static int drawnone_window_draw(win_window_info *window, HDC dc, int update);
3145
46//============================================================
47//  drawnone_create
48//============================================================
3249
50osd_renderer *drawnone_create(win_window_info *window)
51{
52   return global_alloc(renderer_none(window));
53}
3354
3455//============================================================
3556//  drawnone_init
3657//============================================================
3758
38int drawnone_init(running_machine &machine, win_draw_callbacks *callbacks)
59int drawnone_init(running_machine &machine, osd_draw_callbacks *callbacks)
3960{
4061   // fill in the callbacks
4162   memset(callbacks, 0, sizeof(*callbacks));
4263   callbacks->exit = drawnone_exit;
43   callbacks->window_init = drawnone_window_init;
44   callbacks->window_get_primitives = drawnone_window_get_primitives;
45   callbacks->window_draw = drawnone_window_draw;
46   callbacks->window_destroy = drawnone_window_destroy;
64   callbacks->create = drawnone_create;
4765   return 0;
4866}
4967
r243390r243391
6381//  drawnone_window_init
6482//============================================================
6583
66static int drawnone_window_init(win_window_info *window)
84int renderer_none::init()
6785{
6886   return 0;
6987}
r243390r243391
7492//  drawnone_window_destroy
7593//============================================================
7694
77static void drawnone_window_destroy(win_window_info *window)
95void renderer_none::destroy()
7896{
7997}
8098
r243390r243391
84102//  drawnone_window_get_primitives
85103//============================================================
86104
87static render_primitive_list *drawnone_window_get_primitives(win_window_info *window)
105render_primitive_list *renderer_none::get_primitives()
88106{
89107   RECT client;
90   GetClientRect(window->m_hwnd, &client);
91   window->m_target->set_bounds(rect_width(&client), rect_height(&client), window->m_monitor->get_aspect());
92   return &window->m_target->get_primitives();
108   GetClientRect(window().m_hwnd, &client);
109   window().m_target->set_bounds(rect_width(&client), rect_height(&client), window().m_monitor->get_aspect());
110   return &window().m_target->get_primitives();
93111}
94112
95113
r243390r243391
98116//  drawnone_window_draw
99117//============================================================
100118
101static int drawnone_window_draw(win_window_info *window, HDC dc, int update)
119int renderer_none::draw(HDC dc, int update)
102120{
103121   return 0;
104122}
trunk/src/osd/windows/window.c
r243390r243391
3535#include "config.h"
3636#include "winutf8.h"
3737
38extern int drawnone_init(running_machine &machine, win_draw_callbacks *callbacks);
39extern int drawgdi_init(running_machine &machine, win_draw_callbacks *callbacks);
40extern int drawdd_init(running_machine &machine, win_draw_callbacks *callbacks);
41extern int drawd3d_init(running_machine &machine, win_draw_callbacks *callbacks);
42extern int drawbgfx_init(running_machine &machine, win_draw_callbacks *callbacks);
38extern int drawnone_init(running_machine &machine, osd_draw_callbacks *callbacks);
39extern int drawgdi_init(running_machine &machine, osd_draw_callbacks *callbacks);
40extern int drawdd_init(running_machine &machine, osd_draw_callbacks *callbacks);
41extern int drawd3d_init(running_machine &machine, osd_draw_callbacks *callbacks);
42extern int drawbgfx_init(running_machine &machine, osd_draw_callbacks *callbacks);
4343
4444
4545//============================================================
r243390r243391
107107
108108static DWORD last_update_time;
109109
110static win_draw_callbacks draw;
110static osd_draw_callbacks draw;
111111
112112static HANDLE ui_pause_event;
113113static HANDLE window_thread_ready_event;
r243390r243391
320320      m_lastclicktime(0),
321321      m_lastclickx(0),
322322      m_lastclicky(0),
323      m_drawdata(NULL),
323      m_renderer(NULL),
324324      m_machine(machine)
325325{
326326   memset(m_title,0,sizeof(m_title));
r243390r243391
504504
505505void winwindow_take_snap(void)
506506{
507   if (draw.window_record == NULL)
508      return;
509
510507   win_window_info *window;
511508
512509   assert(GetCurrentThreadId() == main_threadid);
r243390r243391
514511   // iterate over windows and request a snap
515512   for (window = win_window_list; window != NULL; window = window->m_next)
516513   {
517      (*draw.window_save)(window);
514      window->m_renderer->save();
518515   }
519516}
520517
r243390r243391
527524
528525void winwindow_toggle_fsfx(void)
529526{
530   if (draw.window_toggle_fsfx == NULL)
531      return;
532
533527   win_window_info *window;
534528
535529   assert(GetCurrentThreadId() == main_threadid);
r243390r243391
537531   // iterate over windows and request a snap
538532   for (window = win_window_list; window != NULL; window = window->m_next)
539533   {
540      (*draw.window_toggle_fsfx)(window);
534      window->m_renderer->toggle_fsfx();
541535   }
542536}
543537
r243390r243391
550544
551545void winwindow_take_video(void)
552546{
553   if (draw.window_record == NULL)
554      return;
555
556547   win_window_info *window;
557548
558549   assert(GetCurrentThreadId() == main_threadid);
r243390r243391
560551   // iterate over windows and request a snap
561552   for (window = win_window_list; window != NULL; window = window->m_next)
562553   {
563      (*draw.window_record)(window);
554      window->m_renderer->record();
564555   }
565556}
566557
r243390r243391
812803   }
813804
814805   // if we're visible and running and not in the middle of a resize, draw
815   if (m_hwnd != NULL && m_target != NULL && m_drawdata != NULL)
806   if (m_hwnd != NULL && m_target != NULL)
816807   {
817808      int got_lock = TRUE;
818809
r243390r243391
835826         osd_lock_release(m_render_lock);
836827
837828         // ensure the target bounds are up-to-date, and then get the primitives
838         primlist = (*draw.window_get_primitives)(this);
829         primlist = m_renderer->get_primitives();
839830
840831         // post a redraw request with the primitive list as a parameter
841832         last_update_time = timeGetTime();
r243390r243391
12411232   if (!window->m_fullscreen || window->m_fullscreen_safe)
12421233   {
12431234      // finish off by trying to initialize DirectX; if we fail, ignore it
1244      if ((*draw.window_init)(window))
1235      window->m_renderer = draw.create(window);
1236      if (window->m_renderer->init())
12451237         return 1;
12461238      ShowWindow(window->m_hwnd, SW_SHOW);
12471239   }
r243390r243391
14171409
14181410      // destroy: clean up all attached rendering bits and NULL out our hwnd
14191411      case WM_DESTROY:
1420         (*draw.window_destroy)(window);
1412         window->m_renderer->destroy();
1413         global_free(window->m_renderer);
1414         window->m_renderer = NULL;
14211415         window->m_hwnd = NULL;
14221416         return DefWindowProc(wnd, message, wparam, lparam);
14231417
r243390r243391
15011495      // otherwise, render with our drawing system
15021496      else
15031497      {
1504         (*draw.window_draw)(window, dc, update);
1498         window->m_renderer->draw(dc, update);
15051499         mtlog_add("draw_video_contents: drawing finished");
15061500      }
15071501   }
r243390r243391
18711865   window->m_fullscreen = fullscreen;
18721866
18731867   // kill off the drawers
1874   (*draw.window_destroy)(window);
1868   window->m_renderer->destroy();
1869   global_free(window->m_renderer);
1870   window->m_renderer = NULL;
18751871
18761872   // hide ourself
18771873   ShowWindow(window->m_hwnd, SW_HIDE);
r243390r243391
19271923   {
19281924      if (video_config.mode != VIDEO_MODE_NONE)
19291925         ShowWindow(window->m_hwnd, SW_SHOW);
1930      if ((*draw.window_init)(window))
1926      window->m_renderer = draw.create(window);
1927      if (window->m_renderer->init())
19311928         exit(1);
19321929   }
19331930
trunk/src/osd/windows/window.h
r243390r243391
3232//  TYPE DEFINITIONS
3333//============================================================
3434
35class osd_renderer;
36
3537class win_window_info
3638{
3739public:
r243390r243391
7779   int                 m_lastclicky;
7880
7981   // drawing data
80   void *              m_drawdata;
82   osd_renderer *      m_renderer;
8183
8284private:
8385   running_machine &   m_machine;
8486};
8587
88class osd_renderer
89{
90public:
8691
87struct win_draw_callbacks
92   /* Generic flags */
93   static const int FLAG_NONE                = 0x0000;
94   static const int FLAG_NEEDS_OPENGL          = 0x0001;
95
96   /* SDL 1.2 flags */
97   static const int FLAG_NEEDS_DOUBLEBUF       = 0x0100;
98   static const int FLAG_NEEDS_ASYNCBLIT       = 0x0200;
99
100   osd_renderer(win_window_info *window, const int flags)
101   : m_window(window), m_flags(flags) { }
102
103   virtual ~osd_renderer() { }
104
105   win_window_info &window() { return *m_window; }
106   int flags() const { return m_flags; }
107   bool check_flag(const int flag) { return ((m_flags & flag)) == flag; }
108
109   virtual int init() = 0;
110   virtual render_primitive_list *get_primitives() = 0;
111   virtual int draw(HDC dc, int update) = 0;
112   virtual void save() = 0;
113   virtual void record() = 0;
114   virtual void toggle_fsfx() = 0;
115   virtual void destroy() = 0;
116
117private:
118   win_window_info *m_window;
119   int m_flags;
120};
121
122struct osd_draw_callbacks
88123{
124   osd_renderer *(*create)(win_window_info *window);
89125   void (*exit)(void);
90
91   int (*window_init)(win_window_info *window);
92   render_primitive_list *(*window_get_primitives)(win_window_info *window);
93   int (*window_draw)(win_window_info *window, HDC dc, int update);
94   void (*window_save)(win_window_info *window);
95   void (*window_record)(win_window_info *window);
96   void (*window_toggle_fsfx)(win_window_info *window);
97   void (*window_destroy)(win_window_info *window);
98126};
99127
100128


Previous 199869 Revisions Next


© 1997-2024 The MAME Team