Previous 199869 Revisions Next

r34857 Thursday 5th February, 2015 at 00:58:55 UTC by Couriersud
Remove some passing around of running_machine where it is not needed.
(nw)
[src/osd/sdl]input.c input.h video.c window.c window.h

trunk/src/osd/sdl/input.c
r243368r243369
14731473//  sdlinput_get_focus_window
14741474//============================================================
14751475
1476sdl_window_info *sdlinput_get_focus_window(running_machine &machine)
1476sdl_window_info *sdlinput_get_focus_window()
14771477{
14781478   if (focus_window)  // only be set on SDL >= 1.3
14791479      return focus_window;
r243368r243369
15661566      {
15671567         if (w->m_resize_width && w->m_resize_height && ((now - w->m_last_resize) > osd_ticks_per_second() / 10))
15681568         {
1569            w->window_resize(w->m_resize_width, w->m_resize_height);
1569            w->resize(w->m_resize_width, w->m_resize_height);
15701570            w->m_resize_width = 0;
15711571            w->m_resize_height = 0;
15721572         }
r243368r243369
15761576
15771577#endif
15781578
1579void sdlinput_process_events_buf(running_machine &machine)
1579void sdlinput_process_events_buf()
15801580{
15811581   SDL_Event event;
15821582
r243368r243369
19441944         machine.schedule_exit();
19451945         break;
19461946      case SDL_VIDEORESIZE:
1947         sdl_window_list->window_resize(event.resize.w, event.resize.h);
1947         sdl_window_list->resize(event.resize.w, event.resize.h);
19481948         break;
19491949#else
19501950      case SDL_TEXTINPUT:
r243368r243369
19771977            app_has_mouse_focus = 0;
19781978            break;
19791979         case SDL_WINDOWEVENT_MOVED:
1980            window->window_clear();
1980            window->clear();
19811981            focus_window = window;
19821982            break;
19831983         case SDL_WINDOWEVENT_RESIZED:
r243368r243369
19981998               {
19991999                  //printf("event data1,data2 %d x %d %ld\n", event.window.data1, event.window.data2, sizeof(SDL_Event));
20002000                  if (event.window.data1 != window->width() || event.window.data2 != window->height())
2001                     window->window_resize(event.window.data1, event.window.data2);
2001                     window->resize(event.window.data1, event.window.data2);
20022002               }
20032003            }
20042004            focus_window = window;
r243368r243369
20292029//============================================================
20302030
20312031
2032void  sdlinput_release_keys(running_machine &machine)
2032void  sdlinput_release_keys()
20332033{
20342034   // FIXME: SDL >= 1.3 will nuke the window event buffer when
20352035   // a window is closed. This will leave keys in a pressed
r243368r243369
20532053//  sdlinput_should_hide_mouse
20542054//============================================================
20552055
2056int sdlinput_should_hide_mouse(running_machine &machine)
2056int sdlinput_should_hide_mouse()
20572057{
20582058   // if we are paused, no
20592059   if (input_paused)
trunk/src/osd/sdl/input.h
r243368r243369
1919//============================================================
2020
2121void sdlinput_poll(running_machine &machine);
22int  sdlinput_should_hide_mouse(running_machine &machine);
22int  sdlinput_should_hide_mouse();
2323
24sdl_window_info *sdlinput_get_focus_window(running_machine &machine);
24sdl_window_info *sdlinput_get_focus_window();
2525
26void  sdlinput_process_events_buf(running_machine &machine);
27void  sdlinput_release_keys(running_machine &machine);
26void  sdlinput_process_events_buf();
27void  sdlinput_release_keys();
2828
2929#endif /* __SDLINPUT_H__ */
trunk/src/osd/sdl/video.c
r243368r243369
312312   {
313313//      profiler_mark(PROFILER_BLIT);
314314      for (window = sdl_window_list; window != NULL; window = window->m_next)
315         window->video_window_update(machine());
315         window->update();
316316//      profiler_mark(PROFILER_END);
317317   }
318318
r243368r243369
544544
545545static void check_osd_inputs(running_machine &machine)
546546{
547   sdl_window_info *window = sdlinput_get_focus_window(machine);
547   sdl_window_info *window = sdlinput_get_focus_window();
548548
549549   // check for toggling fullscreen mode
550550   if (ui_input_pressed(machine, IPT_OSD_1))
r243368r243369
553553
554554      while (curwin != (sdl_window_info *)NULL)
555555      {
556         curwin->toggle_full_screen(machine);
556         curwin->toggle_full_screen();
557557         curwin = curwin->m_next;
558558      }
559559   }
r243368r243369
582582   #endif
583583
584584   if (ui_input_pressed(machine, IPT_OSD_6))
585      window->modify_prescale(machine, -1);
585      window->modify_prescale(-1);
586586
587587   if (ui_input_pressed(machine, IPT_OSD_7))
588      window->modify_prescale(machine, 1);
588      window->modify_prescale(1);
589589}
590590
591591//============================================================
trunk/src/osd/sdl/window.c
r243368r243369
100100
101101struct worker_param {
102102   worker_param()
103   : m_window(NULL), m_list(NULL), m_machine(NULL), m_resize_new_width(0), m_resize_new_height(0)
103   : m_window(NULL), m_list(NULL), m_resize_new_width(0), m_resize_new_height(0)
104104   {
105105   }
106   worker_param(running_machine &amachine, sdl_window_info *awindow)
107   : m_window(awindow), m_list(NULL), m_machine(&amachine), m_resize_new_width(0), m_resize_new_height(0)
106   worker_param(sdl_window_info *awindow, render_primitive_list &alist)
107   : m_window(awindow), m_list(&alist), m_resize_new_width(0), m_resize_new_height(0)
108108   {
109109   }
110   worker_param(running_machine &amachine, sdl_window_info *awindow, render_primitive_list &alist)
111   : m_window(awindow), m_list(&alist), m_machine(&amachine), m_resize_new_width(0), m_resize_new_height(0)
112   {
113   }
114110   worker_param(sdl_window_info *awindow, int anew_width, int anew_height)
115   : m_window(awindow), m_list(NULL), m_machine(NULL), m_resize_new_width(anew_width), m_resize_new_height(anew_height)
111   : m_window(awindow), m_list(NULL), m_resize_new_width(anew_width), m_resize_new_height(anew_height)
116112   {
117113   }
118114   worker_param(sdl_window_info *awindow)
119   : m_window(awindow), m_list(NULL), m_machine(NULL), m_resize_new_width(0), m_resize_new_height(0)
115   : m_window(awindow), m_list(NULL), m_resize_new_width(0), m_resize_new_height(0)
120116   {
121117   }
122   running_machine &machine() const { assert(m_machine != NULL); return *m_machine; }
123118   sdl_window_info *window() const { assert(m_window != NULL); return m_window; }
124119   render_primitive_list *list() const { return m_list; }
125120   int new_width() const { return m_resize_new_width; }
r243368r243369
129124private:
130125   sdl_window_info *m_window;
131126   render_primitive_list *m_list;
132   running_machine *m_machine;
133127   int m_resize_new_width;
134128   int m_resize_new_height;
135129};
r243368r243369
139133//  PROTOTYPES
140134//============================================================
141135
142static void sdlwindow_update_cursor_state(running_machine &machine, sdl_window_info *window);
143136static void sdlwindow_sync(void);
144137
145138//============================================================
r243368r243369
353346   {
354347      sdl_window_info *temp = sdl_window_list;
355348      sdl_window_list = temp->m_next;
356      temp->video_window_destroy(machine());
349      temp->destroy();
357350      // free the window itself
358351      global_free(temp);
359352   }
r243368r243369
462455      newwidth = window_width;
463456
464457   if ((m_blitwidth != newwidth) || (m_blitheight != newheight))
465      window_clear();
458      clear();
466459
467460   m_blitwidth = newwidth;
468461   m_blitheight = newheight;
r243368r243369
503496
504497   window->blit_surface_size(window->m_width, window->m_height);
505498
506   window->window_clear();
499   window->clear();
507500
508501   osd_free(wp);
509502   return NULL;
510503}
511504
512void sdl_window_info::window_resize(INT32 width, INT32 height)
505void sdl_window_info::resize(INT32 width, INT32 height)
513506{
514507   ASSERT_MAIN_THREAD();
515508
r243368r243369
537530   return NULL;
538531}
539532
540void sdl_window_info::window_clear()
533void sdl_window_info::clear()
541534{
542535   worker_param wp;
543536
r243368r243369
592585#endif
593586
594587
595   sdlinput_release_keys(wp->machine());
588   sdlinput_release_keys();
596589
597590   // toggle the window mode
598591   window->set_fullscreen(!window->fullscreen());
r243368r243369
602595   return NULL;
603596}
604597
605void sdl_window_info::toggle_full_screen(running_machine &machine)
598void sdl_window_info::toggle_full_screen()
606599{
607600   ASSERT_MAIN_THREAD();
608601
609   execute_async_wait(&sdlwindow_toggle_full_screen_wt, worker_param(machine, this));
602   execute_async_wait(&sdlwindow_toggle_full_screen_wt, worker_param(this));
610603}
611604
612605OSDWORK_CALLBACK( sdl_window_info::destroy_all_textures_wt )
r243368r243369
621614   return NULL;
622615}
623616
624void sdl_window_info::modify_prescale(running_machine &machine, int dir)
617void sdl_window_info::modify_prescale(int dir)
625618{
626   worker_param wp = worker_param(machine, this);
619   worker_param wp = worker_param(this);
627620   int new_prescale = prescale();
628621
629622   if (dir > 0 && prescale() < 3)
r243368r243369
647640         execute_async_wait(destroy_all_textures_wt, wp);
648641         m_prescale = new_prescale;
649642      }
650      machine.ui().popup_time(1, "Prescale %d", prescale());
643      machine().ui().popup_time(1, "Prescale %d", prescale());
651644   }
652645}
653646
r243368r243369
656649//  (main or window thread)
657650//============================================================
658651
659static void sdlwindow_update_cursor_state(running_machine &machine, sdl_window_info *window)
652void sdl_window_info::update_cursor_state()
660653{
661654#if (USE_XINPUT)
662655   // Hack for wii-lightguns:
r243368r243369
671664#if (SDLMAME_SDL2)
672665   // do not do mouse capture if the debugger's enabled to avoid
673666   // the possibility of losing control
674   if (!(machine.debug_flags & DEBUG_FLAG_OSD_ENABLED))
667   if (!(machine().debug_flags & DEBUG_FLAG_OSD_ENABLED))
675668   {
676669      //FIXME: SDL1.3: really broken: the whole SDL code
677670      //       will only work correct with relative mouse movements ...
678      if (!window->fullscreen() && !sdlinput_should_hide_mouse(machine))
671      if (!fullscreen() && !sdlinput_should_hide_mouse())
679672      {
680673         SDL_ShowCursor(SDL_ENABLE);
681         if (SDL_GetWindowGrab(window->sdl_window() ))
682            SDL_SetWindowGrab(window->sdl_window(), SDL_FALSE);
674         if (SDL_GetWindowGrab(sdl_window() ))
675            SDL_SetWindowGrab(sdl_window(), SDL_FALSE);
683676         SDL_SetRelativeMouseMode(SDL_FALSE);
684677      }
685678      else
686679      {
687680         SDL_ShowCursor(SDL_DISABLE);
688         if (!SDL_GetWindowGrab(window->sdl_window()))
689            SDL_SetWindowGrab(window->sdl_window(), SDL_TRUE);
681         if (!SDL_GetWindowGrab(sdl_window()))
682            SDL_SetWindowGrab(sdl_window(), SDL_TRUE);
690683         SDL_SetRelativeMouseMode(SDL_TRUE);
691684      }
692685      SDL_SetCursor(NULL); // Force an update in case the underlying driver has changed visibility
r243368r243369
695688#else
696689   // do not do mouse capture if the debugger's enabled to avoid
697690   // the possibility of losing control
698   if (!(machine.debug_flags & DEBUG_FLAG_OSD_ENABLED))
691   if (!(machine().debug_flags & DEBUG_FLAG_OSD_ENABLED))
699692   {
700      if ( window->fullscreen() || sdlinput_should_hide_mouse(machine) )
693      if ( fullscreen() || sdlinput_should_hide_mouse() )
701694      {
702695         SDL_ShowCursor(SDL_DISABLE);
703696         if (!SDL_WM_GrabInput(SDL_GRAB_QUERY))
r243368r243369
721714static OSDWORK_CALLBACK( sdlwindow_update_cursor_state_wt )
722715{
723716   worker_param *      wp = (worker_param *) param;
724   //sdl_window_info *   window = wp->window;
717   sdl_window_info *   window = wp->window();
725718
726   sdlwindow_update_cursor_state(wp->machine(), wp->window());
719   window->update_cursor_state();
727720
728721   osd_free(wp);
729722   return NULL;
r243368r243369
794787   return 0;
795788
796789error:
797   video_window_destroy(m_machine);
798   // free the window itself
790   destroy();
799791   return 1;
800792}
801793
r243368r243369
832824#endif
833825
834826   // release all keys ...
835   sdlinput_release_keys(wp->machine());
827   sdlinput_release_keys();
836828
837829
838830   osd_free(wp);
839831   return NULL;
840832}
841833
842void sdl_window_info::video_window_destroy(running_machine &machine)
834void sdl_window_info::destroy()
843835{
844836   sdl_window_info **prevptr;
845837
r243368r243369
860852      }
861853
862854   // free the textures etc
863   execute_async_wait(&sdlwindow_video_window_destroy_wt, worker_param(machine, this));
855   execute_async_wait(&sdlwindow_video_window_destroy_wt, worker_param(this));
864856
865857   // free the render target, after the textures!
866858   this->machine().render().target_free(m_target);
r243368r243369
10231015//  (main thread)
10241016//============================================================
10251017
1026void sdl_window_info::video_window_update(running_machine &machine)
1018void sdl_window_info::update()
10271019{
10281020   osd_ticks_t     event_wait_ticks;
10291021   ASSERT_MAIN_THREAD();
r243368r243369
10311023   // adjust the cursor state
10321024   //sdlwindow_update_cursor_state(machine, window);
10331025
1034   execute_async(&sdlwindow_update_cursor_state_wt, worker_param(machine, this));
1026   execute_async(&sdlwindow_update_cursor_state_wt, worker_param(this));
10351027
10361028   // if we're visible and running and not in the middle of a resize, draw
10371029   if (m_target != NULL)
r243368r243369
10541046         else if (video_config.switchres)
10551047         {
10561048            this->pick_best_mode(&tempwidth, &tempheight);
1057            window_resize(tempwidth, tempheight);
1049            resize(tempwidth, tempheight);
10581050         }
10591051      }
10601052
r243368r243369
10821074
10831075         // and redraw now
10841076
1085         execute_async(&draw_video_contents_wt, worker_param(machine, this, primlist));
1077         execute_async(&draw_video_contents_wt, worker_param(this, primlist));
10861078      }
10871079   }
10881080}
r243368r243369
13551347   ASSERT_REDRAW_THREAD();
13561348
13571349   // Some configurations require events to be polled in the worker thread
1358   sdlinput_process_events_buf(wp->machine());
1350   sdlinput_process_events_buf();
13591351
13601352   window->m_primlist = wp->list();
13611353
trunk/src/osd/sdl/window.h
r243368r243369
116116   }
117117
118118   int window_init();
119   void destroy();
119120
120   void video_window_update(running_machine &machine);
121   void toggle_full_screen(running_machine &machine);
122   void modify_prescale(running_machine &machine, int dir);
123   void window_resize(INT32 width, INT32 height);
124   void window_clear();
121   void update();
122   void toggle_full_screen();
123   void modify_prescale(int dir);
124   void resize(INT32 width, INT32 height);
125   void clear();
126   int xy_to_render_target(int x, int y, int *xt, int *yt);
125127
126   void video_window_destroy(running_machine &machine);
127128   void get_min_bounds(int *window_width, int *window_height, int constrain);
128129   void get_max_bounds(int *window_width, int *window_height, int constrain);
129130
r243368r243369
132133   int fullscreen() const { return m_fullscreen; }
133134
134135   void set_fullscreen(int afullscreen) { m_fullscreen = afullscreen; }
136   void update_cursor_state();
135137
136138   void blit_surface_size(int window_width, int window_height);
137139   void pick_best_mode(int *fswidth, int *fsheight);
r243368r243369
139141
140142   int index() const { return m_index; }
141143
142   int xy_to_render_target(int x, int y, int *xt, int *yt);
143144
144145
145146   render_target *target() { return m_target; }


Previous 199869 Revisions Next


© 1997-2024 The MAME Team