Previous 15994 Revisions Next

r2960 Thursday 17th July, 2008 at 16:49:50 UTC by R. Belmont
[SDLMESS] Sync with SDLMAME 0.126u1.
[src/osd/sdl]debugosx.c drawogl.c drawsdl.c gl_shader_mgr.c gl_shader_mgr.h input.c input.h keybled.c osdsdl.h sdl.mak sdlmain.c sound.c testkeys.c video.c video.h window.c window.h

src/osd/sdl/drawogl.c
r2959r2960
152152#define GL_NO_PRIMITIVE -1
153153
154154//============================================================
155//  TYPES
156//============================================================
157
158/* sdl_info is the information about SDL for the current screen */
159typedef struct _sdl_info sdl_info;
160struct _sdl_info
161{
162   INT32          blittimer;
163
164#if (SDL_VERSION_ATLEAST(1,3,0))
165   SDL_GLContext   gl_context_id;
166#else
167   // SDL surface
168   SDL_Surface       *sdlsurf;
169#endif
170
171   int            initialized;      // is everything well initialized, i.e. all GL stuff etc.
172   // 3D info (GL mode only)
173   texture_info *   texlist;      // list of active textures
174   int            last_blendmode;      // previous blendmode
175   INT32            texture_max_width;        // texture maximum width
176   INT32            texture_max_height;       // texture maximum height
177   int            texpoweroftwo;           // must textures be power-of-2 sized?
178   int            usevbo;         // runtime check if VBO is available
179   int            usepbo;         // runtime check if PBO is available
180   int            usefbo;         // runtime check if FBO is available
181   int            useglsl;      // runtime check if GLSL is available
182   
183   glsl_shader_info *glsl;            // glsl_shader_info
184   
185   GLhandleARB      glsl_program[2*GLSL_SHADER_MAX];  // GLSL programs, or 0
186   int            glsl_program_num;   // number of GLSL programs
187   int            glsl_program_mb2sc;   // GLSL program idx, which transforms
188                                     // the mame-bitmap -> screen-bitmap (size/rotation/..)
189                              // All progs <= glsl_program_mb2sc using the mame bitmap
190                              // as input, otherwise the screen bitmap.
191                              // All progs >= glsl_program_mb2sc using the screen bitmap
192                              // as output, otherwise the mame bitmap.
193   int            glsl_vid_attributes;// glsl brightness, contrast and gamma for RGB bitmaps
194   int            usetexturerect;      // use ARB_texture_rectangle for non-power-of-2, general use
195
196   int            init_context;      // initialize context before next draw
197
198   int            totalColors;      // total colors from machine/sdl_window_config/sdl_window_info
199
200   // Static vars from draogl_window_dra
201   INT32          old_blitwidth;
202   INT32          old_blitheight;
203   INT32          surf_w;
204   INT32          surf_h;
205    GLfloat       texVerticex[8];
206};
207
208
209//============================================================
155210//  INLINES
156211//============================================================
157212
r2959r2960
188243   }
189244}
190245
191#if 0
192INLINE int better_mode(int width0, int height0, int width1, int height1, float desired_aspect)
193{
194   float aspect0 = (float)width0 / (float)height0;
195   float aspect1 = (float)width1 / (float)height1;
196   return (fabs(desired_aspect - aspect0) < fabs(desired_aspect - aspect1)) ? 0 : 1;
197}
198#endif
199
200246INLINE UINT32 ycc_to_rgb(UINT8 y, UINT8 cb, UINT8 cr)
201247{
202248   /* original equations:
r2959r2960
246292// core functions
247293
248294static void drawogl_exit(void);
249static int drawogl_window_init(sdl_window_info *window);
295static int drawogl_window_create(sdl_window_info *window, int width, int height);
296static void drawogl_window_resize(sdl_window_info *window, int width, int height);
250297static void drawogl_window_destroy(sdl_window_info *window);
251298static int drawogl_window_draw(sdl_window_info *window, UINT32 dc, int update);
252299static const render_primitive_list *drawogl_window_get_primitives(sdl_window_info *window);
253300static void drawogl_destroy_all_textures(sdl_window_info *window);
301static void drawogl_window_clear(sdl_window_info *window);
254302
303
304
255305// OGL 1.3
256306static PFNGLACTIVETEXTUREPROC pfn_glActiveTexture   = NULL;
257307
r2959r2960
333383//============================================================
334384
335385static int shown_video_info = 0;
386static int dll_loaded = 0;
336387
337388//============================================================
338389//  drawogl_init
r2959r2960
342393{
343394   // fill in the callbacks
344395   callbacks->exit = drawogl_exit;
345   callbacks->window_init = drawogl_window_init;
396   callbacks->window_create = drawogl_window_create;
397   callbacks->window_resize = drawogl_window_resize;
346398   callbacks->window_get_primitives = drawogl_window_get_primitives;
347399   callbacks->window_draw = drawogl_window_draw;
348400   callbacks->window_destroy = drawogl_window_destroy;
349401   callbacks->window_destroy_all_textures = drawogl_destroy_all_textures;
402   callbacks->window_clear = drawogl_window_clear;
350403
351   #if SDL_MULTIMON
404   dll_loaded = 0;
405
406   #if SDL_VERSION_ATLEAST(1,3,0)
352407   mame_printf_verbose("Using SDL multi-window OpenGL driver (SDL 1.3+)\n");
353408   #else
354409   mame_printf_verbose("Using SDL single-window OpenGL driver (SDL 1.2)\n");
r2959r2960
386441#endif     
387442}
388443
389void drawogl_init_ogl_context(void)
444//============================================================
445// Load GL library
446//============================================================
447
448static void load_gl_lib(void)
390449{
391   // do some one-time OpenGL setup
392   glShadeModel(GL_SMOOTH);
393   glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
394   glClearDepth(1.0f);
395   glEnable(GL_DEPTH_TEST);
396   glDepthFunc(GL_LEQUAL);
397   glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
450#ifdef USE_DISPATCH_GL
451   if (!dll_loaded)
452   {
453      /*
454       *  directfb and and x11 use this env var
455       *   SDL_VIDEO_GL_DRIVER
456       */
457      const char *e;
458
459      e=getenv(SDLENV_GL_LIB);
460     
461#ifdef SDLMAME_MACOSX
462      /* Vas Crabb: Default GL-lib for MACOSX */
463      if (!e)
464         e = "/System/Library/Frameworks/OpenGL.framework/Libraries/libGL.dylib";
465#endif
466      if (SDL_GL_LoadLibrary(e) != 0) // Load library (default for e==NULL
467      {
468         fatalerror("Unable to load default library: %s\n", e);
469      }
470          mame_printf_verbose("Loaded opengl shared library: %s\n", e ? e : "<default>");
471       gl_dispatch = auto_malloc(sizeof(osd_gl_dispatch));
472        dll_loaded=1;
473   }
474#endif
398475}
399476
400477//============================================================
401//  drawogl_window_init
478//  drawogl_window_create
402479//============================================================
403480
404static int drawogl_window_init(sdl_window_info *window)
481static int drawogl_window_create(sdl_window_info *window, int width, int height)
405482{
406   sdl_info *sdl;
483   sdl_info *sdl = window->dxdata;
407484   char *extstr;
408485   char *vendor;
409486   int has_and_allow_texturerect = 0;
410   
487
411488   // allocate memory for our structures
412489   sdl = malloc(sizeof(*sdl));
413490   memset(sdl, 0, sizeof(*sdl));
414   sdl->totalColors = window->totalColors;
415491
416492   window->dxdata = sdl;
417   window->initialized = 0;
418493
494#if (SDL_VERSION_ATLEAST(1,3,0))
495   window->extra_flags = (window->fullscreen ?
496         SDL_WINDOW_BORDERLESS | SDL_WINDOW_INPUT_FOCUS : SDL_WINDOW_RESIZABLE);
497   window->extra_flags |= SDL_WINDOW_OPENGL;
498
499   SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
500   load_gl_lib();
501
502   // create the SDL window
503   SDL_SelectVideoDisplay(window->monitor->handle);
504   SDL_SetFullscreenDisplayMode(NULL);   // Use desktop
505   window->window_id = SDL_CreateWindow(window->title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
506         width, height, window->extra_flags);
507#if 0
508   if ( (video_config.mode  == VIDEO_MODE_OPENGL) && !(sdl->sdlsurf->flags & SDL_OPENGL) )
509   {
510      fprintf(stderr, "OpenGL not supported on this driver!\n");
511      return 1;
512   }
513#endif
514   SDL_ShowWindow(window->window_id);
515   SDL_SetWindowFullscreen(window->window_id, window->fullscreen);
516   SDL_RaiseWindow(window->window_id);
517   SDL_GetWindowSize(window->window_id, &window->width, &window->height);
518   
519   sdl->gl_context_id = SDL_GL_CreateContext(window->window_id);
520
521#else
522   window->extra_flags = (window->fullscreen ?  SDL_FULLSCREEN : SDL_RESIZABLE);
523   window->extra_flags |= SDL_OPENGL | SDL_DOUBLEBUF;
524
525   SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
526   #if (SDL_VERSION_ATLEAST(1,2,10))
527   SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL,
528         options_get_bool(mame_options(), SDLOPTION_WAITVSYNC) ? 1 : 0);
529   #endif
530   
531   load_gl_lib();
532
533   // create the SDL surface (which creates the window in windowed mode)
534   sdl->sdlsurf = SDL_SetVideoMode(width, height,
535                     0, SDL_SWSURFACE  | SDL_ANYFORMAT | window->extra_flags);
536
537   if (!sdl->sdlsurf)
538      return 1;
539
540   window->width = sdl->sdlsurf->w;
541   window->height = sdl->sdlsurf->h;
542   
543   if ( (video_config.mode  == VIDEO_MODE_OPENGL) && !(sdl->sdlsurf->flags & SDL_OPENGL) )
544   {
545      fprintf(stderr, "OpenGL not supported on this driver!\n");
546      return 1;
547   }
548
549   // set the window title
550   SDL_WM_SetCaption(window->title, "SDLMAME");
551
552#endif   
553   sdl->totalColors = window->totalColors;
554   sdl->old_blitwidth = 0;
555   sdl->old_blitheight = 0;
556   sdl->blittimer = 0;
557   sdl->surf_w = 0;
558   sdl->surf_h = 0;
559
560   sdl->initialized = 0;
561
419562   // in case any textures try to come up before these are validated,
420563   // OpenGL guarantees all implementations can handle something this size.
421564   sdl->texture_max_width = 64;
r2959r2960
523666   
524667   if (strstr(extstr, "GL_EXT_framebuffer_object"))
525668   {
526                    sdl->usefbo = 1;
669        sdl->usefbo = 1;
527670      if (!shown_video_info)
528671      {
529672         if(sdl->usefbo)
r2959r2960
570713
571714   shown_video_info = 1;
572715
573   drawogl_init_ogl_context();
716   sdl->init_context = 0;
574717   
575718   return 0;
576719}
577720
578721//============================================================
722//  drawogl_window_resize
723//============================================================
724
725static void drawogl_window_resize(sdl_window_info *window, int width, int height)
726{
727   sdl_info *sdl = window->dxdata;
728
729#if (SDL_VERSION_ATLEAST(1,3,0))
730   SDL_SetWindowSize(window->window_id, width, height);
731   SDL_GetWindowSize(window->window_id, &window->width, &window->height);
732
733   //FIXME: no idea why, but this is necessary to avoid crashes with numscreen>1
734   SDL_GL_DeleteContext(sdl->gl_context_id);
735   sdl->gl_context_id = SDL_GL_CreateContext(window->window_id);
736#else
737   SDL_FreeSurface(sdl->sdlsurf);
738
739   sdl->sdlsurf = SDL_SetVideoMode(width, height, 0,
740         SDL_SWSURFACE | SDL_ANYFORMAT | window->extra_flags);
741   window->width = sdl->sdlsurf->w;
742   window->height = sdl->sdlsurf->h;
743
744#endif
745   sdl->init_context = 0;
746   
747}
748
749//============================================================
579750//  drawogl_window_get_primitives
580751//============================================================
581752
582753static const render_primitive_list *drawogl_window_get_primitives(sdl_window_info *window)
583754{
584   sdl_info *sdl = window->dxdata;
585   if ((video_config.windowed) || (video_config.switchres))
755   if ((!window->fullscreen) || (video_config.switchres))
586756   {
587      sdlwindow_blit_surface_size(window, window->sdlsurf->w, window->sdlsurf->h);
757      sdlwindow_blit_surface_size(window, window->width, window->height);
588758   }
589759   else
590760   {
591761      sdlwindow_blit_surface_size(window, window->monitor->center_width, window->monitor->center_height);
592762   }
593   render_target_set_bounds(window->target, sdl->blitwidth, sdl->blitheight, sdlvideo_monitor_get_aspect(window->monitor));
763   render_target_set_bounds(window->target, window->blitwidth, window->blitheight, sdlvideo_monitor_get_aspect(window->monitor));
594764   return render_target_get_primitives(window->target);
595765}
596766
r2959r2960
794964
795965   if ( sdl->useglsl )
796966   {
797      sdl->useglsl = !glsl_shader_init(sdl);
967      sdl->glsl = glsl_shader_init();
968      sdl->useglsl = (sdl->glsl != NULL ? 1 : 0);
798969
799970      if ( ! sdl->useglsl )
800971      {
r2959r2960
8441015            break;
8451016         }
8461017
847         if ( glsl_shader_add_mamebm(sdl, video_config.glsl_shader_mamebm[i], sdl->glsl_program_num) )
1018         if ( glsl_shader_add_mamebm(sdl->glsl, video_config.glsl_shader_mamebm[i], sdl->glsl_program_num) )
8481019         {
8491020            mame_printf_error("OpenGL: GLSL loading mame bitmap shader %d failed (%s)\n",
8501021               i, video_config.glsl_shader_mamebm[i]);
r2959r2960
8671038
8681039      for(i=0; sdl->usefbo && sdl->glsl_program_num>0 && i<video_config.glsl_shader_scrn_num; i++)
8691040      {
870         if ( glsl_shader_add_scrn(sdl, video_config.glsl_shader_scrn[i],
1041         if ( glsl_shader_add_scrn(sdl->glsl, video_config.glsl_shader_scrn[i],
8711042                                       sdl->glsl_program_num-1-sdl->glsl_program_mb2sc) )
8721043         {
8731044            mame_printf_error("OpenGL: GLSL loading screen bitmap shader %d failed (%s)\n",
r2959r2960
9281099   render_primitive *prim;
9291100   texture_info *texture=NULL;
9301101   float vofs, hofs;
931   static INT32 old_blitwidth = 0, old_blitheight = 0;
932   static INT32 blittimer = 0;
933   static INT32 surf_w = 0, surf_h = 0;
934        static GLfloat texVerticex[8];
935        int  pendingPrimitive=GL_NO_PRIMITIVE, curPrimitive=GL_NO_PRIMITIVE;
1102    int  pendingPrimitive=GL_NO_PRIMITIVE, curPrimitive=GL_NO_PRIMITIVE;
9361103
9371104   if (video_config.novideo)
9381105   {
9391106      return 0;
9401107   }
9411108
1109#if (SDL_VERSION_ATLEAST(1,3,0))
1110   //SDL_SelectRenderer(window->window_id);
1111   SDL_GL_MakeCurrent(window->window_id, sdl->gl_context_id);
1112#endif
1113   if (sdl->init_context)
1114   {
1115      // do some one-time OpenGL setup
1116      glShadeModel(GL_SMOOTH);
1117      glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
1118      glClearDepth(1.0f);
1119      glEnable(GL_DEPTH_TEST);
1120      glDepthFunc(GL_LEQUAL);
1121      glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
1122   }
9421123   // only clear if the geometry changes (and for 2 frames afterward to clear double and triple buffers)
943   if ((blittimer > 0) || (video_config.isvector))
1124   if ((sdl->blittimer > 0) || (video_config.isvector))
9441125   {
9451126      glClear(GL_COLOR_BUFFER_BIT);
946      blittimer--;
1127      sdl->blittimer--;
9471128   }
9481129
949   if ((old_blitwidth != sdl->blitwidth) || (old_blitheight != sdl->blitheight))
1130   if (sdl->init_context || (sdl->old_blitwidth != window->blitwidth) || (sdl->old_blitheight != window->blitheight))
9501131   {
9511132      glClear(GL_COLOR_BUFFER_BIT);
9521133
953      old_blitwidth  = sdl->blitwidth;
954      old_blitheight = sdl->blitheight;
1134      sdl->old_blitwidth  = window->blitwidth;
1135      sdl->old_blitheight = window->blitheight;
9551136
956      blittimer = 2;
1137      sdl->blittimer = 2;
9571138   }
9581139
959   if ( !window->initialized ||
960         window->sdlsurf->w!= surf_w || window->sdlsurf->h!= surf_h )
1140   if ( !sdl->initialized ||
1141         window->width!= sdl->surf_w || window->height!= sdl->surf_h )
9611142   {
962      if ( !window->initialized )
1143      if ( !sdl->initialized )
9631144      {
9641145         loadGLExtensions(sdl);
9651146      }
9661147     
967      surf_w=window->sdlsurf->w;
968      surf_h=window->sdlsurf->h;
1148      sdl->surf_w=window->width;
1149      sdl->surf_h=window->height;
9691150
9701151      // we're doing nothing 3d, so the Z-buffer is currently not interesting
9711152      glDisable(GL_DEPTH_TEST);
r2959r2960
10061187      //   |_________|
10071188      // (0,h)     (w,h)
10081189     
1009      glViewport(0.0, 0.0, (GLsizei)window->sdlsurf->w, (GLsizei)window->sdlsurf->h);
1190      glViewport(0.0, 0.0, (GLsizei)window->width, (GLsizei)window->height);
10101191      glMatrixMode(GL_PROJECTION);
10111192      glLoadIdentity();
1012      glOrtho(0.0, (GLdouble)window->sdlsurf->w, (GLdouble)window->sdlsurf->h, 0.0, 0.0, -1.0);
1193      glOrtho(0.0, (GLdouble)window->width, (GLdouble)window->height, 0.0, 0.0, -1.0);
10131194      glMatrixMode(GL_MODELVIEW);
10141195      glLoadIdentity();
10151196           
1016      if ( ! window->initialized )
1197      if ( ! sdl->initialized )
10171198      {
10181199         glEnableClientState(GL_VERTEX_ARRAY);
1019         glVertexPointer(2, GL_FLOAT, 0, texVerticex); // no VBO, since it's too volatile
1200         glVertexPointer(2, GL_FLOAT, 0, sdl->texVerticex); // no VBO, since it's too volatile
10201201         
1021         window->initialized = 1;
1202         sdl->initialized = 1;
10221203      }
10231204   }
10241205
r2959r2960
10291210   {
10301211      int ch, cw;
10311212
1032      if ((!video_config.windowed) && (!video_config.switchres))
1213      if ((window->fullscreen) && (!video_config.switchres))
10331214      {
10341215         ch = window->monitor->center_height;
10351216         cw = window->monitor->center_width;
10361217      }
10371218      else
10381219      {
1039         ch = window->sdlsurf->h;
1040         cw = window->sdlsurf->w;
1220         ch = window->height;
1221         cw = window->width;
10411222      }
10421223
10431224      if (video_config.centerv)
10441225      {
1045         vofs = (ch - sdl->blitheight) / 2.0f;
1226         vofs = (ch - window->blitheight) / 2.0f;
10461227      }
10471228      if (video_config.centerh)
10481229      {
1049         hofs = (cw - sdl->blitwidth) / 2.0f;
1230         hofs = (cw - window->blitwidth) / 2.0f;
10501231      }
10511232   }
10521233
r2959r2960
11221303                  if ( i==sdl->glsl_program_mb2sc )
11231304                  {
11241305                     // i==sdl->glsl_program_mb2sc -> transformation mamebm->scrn
1125                     texVerticex[0]=prim->bounds.x0 + hofs;
1126                     texVerticex[1]=prim->bounds.y0 + vofs;
1127                     texVerticex[2]=prim->bounds.x1 + hofs;
1128                     texVerticex[3]=prim->bounds.y0 + vofs;
1129                     texVerticex[4]=prim->bounds.x1 + hofs;
1130                     texVerticex[5]=prim->bounds.y1 + vofs;
1131                     texVerticex[6]=prim->bounds.x0 + hofs;
1132                     texVerticex[7]=prim->bounds.y1 + vofs;
1306                     sdl->texVerticex[0]=prim->bounds.x0 + hofs;
1307                     sdl->texVerticex[1]=prim->bounds.y0 + vofs;
1308                     sdl->texVerticex[2]=prim->bounds.x1 + hofs;
1309                     sdl->texVerticex[3]=prim->bounds.y0 + vofs;
1310                     sdl->texVerticex[4]=prim->bounds.x1 + hofs;
1311                     sdl->texVerticex[5]=prim->bounds.y1 + vofs;
1312                     sdl->texVerticex[6]=prim->bounds.x0 + hofs;
1313                     sdl->texVerticex[7]=prim->bounds.y1 + vofs;
11331314                  } else {
11341315                     // 1:1 tex coord CCW (0/0) (1/0) (1/1) (0/1) on texture dimensions
1135                     texVerticex[0]=(GLfloat)0.0;
1136                     texVerticex[1]=(GLfloat)0.0;
1137                     texVerticex[2]=(GLfloat)window->sdlsurf->w;
1138                     texVerticex[3]=(GLfloat)0.0;
1139                     texVerticex[4]=(GLfloat)window->sdlsurf->w;
1140                     texVerticex[5]=(GLfloat)window->sdlsurf->h;
1141                     texVerticex[6]=(GLfloat)0.0;
1142                     texVerticex[7]=(GLfloat)window->sdlsurf->h;
1316                     sdl->texVerticex[0]=(GLfloat)0.0;
1317                     sdl->texVerticex[1]=(GLfloat)0.0;
1318                     sdl->texVerticex[2]=(GLfloat)window->width;
1319                     sdl->texVerticex[3]=(GLfloat)0.0;
1320                     sdl->texVerticex[4]=(GLfloat)window->width;
1321                     sdl->texVerticex[5]=(GLfloat)window->height;
1322                     sdl->texVerticex[6]=(GLfloat)0.0;
1323                     sdl->texVerticex[7]=(GLfloat)window->height;
11431324                  }
11441325
11451326                  if(i>0) // first fetch already done
r2959r2960
11491330                  glDrawArrays(GL_QUADS, 0, 4);
11501331               }
11511332            } else {
1152               texVerticex[0]=prim->bounds.x0 + hofs;
1153               texVerticex[1]=prim->bounds.y0 + vofs;
1154               texVerticex[2]=prim->bounds.x1 + hofs;
1155               texVerticex[3]=prim->bounds.y0 + vofs;
1156               texVerticex[4]=prim->bounds.x1 + hofs;
1157               texVerticex[5]=prim->bounds.y1 + vofs;
1158               texVerticex[6]=prim->bounds.x0 + hofs;
1159               texVerticex[7]=prim->bounds.y1 + vofs;
1333               sdl->texVerticex[0]=prim->bounds.x0 + hofs;
1334               sdl->texVerticex[1]=prim->bounds.y0 + vofs;
1335               sdl->texVerticex[2]=prim->bounds.x1 + hofs;
1336               sdl->texVerticex[3]=prim->bounds.y0 + vofs;
1337               sdl->texVerticex[4]=prim->bounds.x1 + hofs;
1338               sdl->texVerticex[5]=prim->bounds.y1 + vofs;
1339               sdl->texVerticex[6]=prim->bounds.x0 + hofs;
1340               sdl->texVerticex[7]=prim->bounds.y1 + vofs;
11601341
11611342               glDrawArrays(GL_QUADS, 0, 4);
11621343            }
r2959r2960
11771358   }
11781359
11791360   osd_lock_release(window->primlist->lock);
1361   sdl->init_context = 0;
11801362
1363#if (!SDL_VERSION_ATLEAST(1,3,0))
11811364   SDL_GL_SwapBuffers();
1365#else
1366   SDL_GL_SwapWindow(window->window_id);
1367#endif
11821368   return 0;
11831369}
11841370
r2959r2960
13691555   if (sdl == NULL)
13701556      return;
13711557
1558#if (SDL_VERSION_ATLEAST(1,3,0))
1559   SDL_GL_DeleteContext(sdl->gl_context_id);
1560   SDL_DestroyWindow(window->window_id);
1561#else
1562   if (sdl->sdlsurf)
1563   {
1564      SDL_FreeSurface(sdl->sdlsurf);
1565      sdl->sdlsurf = NULL;
1566   }
1567#endif
1568
13721569   // free the memory in the window
13731570
13741571   drawogl_destroy_all_textures(window);
r2959r2960
16801877   int glsl_shader_type_rgb32 = ( sdl->glsl_vid_attributes ) ? GLSL_SHADER_TYPE_RGB32_DIRECT : GLSL_SHADER_TYPE_RGB32_LUT;
16811878   int glsl_shader_type, i;
16821879   int lut_texture_width;
1683   int surf_w_pow2  = get_valid_pow2_value (window->sdlsurf->w, texture->texpow2);
1684   int surf_h_pow2  = get_valid_pow2_value (window->sdlsurf->h, texture->texpow2);
1880   int surf_w_pow2  = get_valid_pow2_value (window->width, texture->texpow2);
1881   int surf_h_pow2  = get_valid_pow2_value (window->height, texture->texpow2);
16851882
16861883   assert ( texture->type==TEXTURE_TYPE_SHADER );
16871884
r2959r2960
17031900
17041901      case SDL_TEXFORMAT_PALETTE16:
17051902         glsl_shader_type          = GLSL_SHADER_TYPE_IDX16;
1706              texture->lut_table_width  = sdl->totalColors;
1903          texture->lut_table_width  = sdl->totalColors;
17071904         break;
17081905
17091906      default:
r2959r2960
18292026      if ( i>sdl->glsl_program_mb2sc )
18302027      {
18312028         {
1832            GLfloat screen_texture_sz[2] = { (GLfloat)window->sdlsurf->w, (GLfloat)window->sdlsurf->h };
2029            GLfloat screen_texture_sz[2] = { (GLfloat)window->width, (GLfloat)window->height };
18332030            uniform_location = pfn_glGetUniformLocationARB(sdl->glsl_program[i], "screen_texture_sz");
18342031            pfn_glUniform2fvARB(uniform_location, 1, &(screen_texture_sz[0]));
18352032            GL_CHECK_ERROR_NORMAL();
r2959r2960
18892086      }
18902087
18912088      mame_printf_verbose("GL texture: mpass screen-bmp 2x %dx%d (pow2 %dx%d)\n",
1892         window->sdlsurf->w, window->sdlsurf->h, surf_w_pow2, surf_h_pow2);
2089         window->width, window->height, surf_w_pow2, surf_h_pow2);
18932090   }
18942091
18952092   if ( !(sdl->glsl_vid_attributes && texture->format!=SDL_TEXFORMAT_PALETTE16) )
r2959r2960
23742571      }
23752572   } else if ( texture->type == TEXTURE_TYPE_SHADER && shaderIdx>sdl->glsl_program_mb2sc )
23762573   {
2377      int surf_w_pow2  = get_valid_pow2_value (window->sdlsurf->w, texture->texpow2);
2378      int surf_h_pow2  = get_valid_pow2_value (window->sdlsurf->h, texture->texpow2);
2574      int surf_w_pow2  = get_valid_pow2_value (window->width, texture->texpow2);
2575      int surf_h_pow2  = get_valid_pow2_value (window->height, texture->texpow2);
23792576
23802577      ustart = 0.0f;
2381      ustop  = (float)(window->sdlsurf->w) / (float)surf_w_pow2;
2578      ustop  = (float)(window->width) / (float)surf_w_pow2;
23822579      vstart = 0.0f;
2383      vstop  = (float)(window->sdlsurf->h) / (float)surf_h_pow2;
2580      vstop  = (float)(window->height) / (float)surf_h_pow2;
23842581   } else {
23852582      assert(0); // ??
23862583   }
r2959r2960
24662663      } else if ( shaderIdx==sdl->glsl_program_mb2sc )
24672664      {
24682665         assert ( sdl->glsl_program_mb2sc < sdl->glsl_program_num-1 );
2469         glPopAttrib(); // glViewport(0.0, 0.0, (GLsizei)window->sdlsurf->w, (GLsizei)window->sdlsurf->h)
2666         glPopAttrib(); // glViewport(0.0, 0.0, (GLsizei)window->width, (GLsizei)window->height)
24702667         GL_CHECK_ERROR_NORMAL();
24712668      }
24722669      glClear(GL_COLOR_BUFFER_BIT); // make sure the whole texture is redrawn ..
r2959r2960
24762673
24772674      if ( sdl->glsl_program_mb2sc == sdl->glsl_program_num-1 )
24782675      {
2479         glPopAttrib(); // glViewport(0.0, 0.0, (GLsizei)window->sdlsurf->w, (GLsizei)window->sdlsurf->h)
2676         glPopAttrib(); // glViewport(0.0, 0.0, (GLsizei)window->width, (GLsizei)window->height)
24802677         GL_CHECK_ERROR_NORMAL();
24812678      }
24822679
r2959r2960
25102707
25112708      if (container!=NULL)
25122709      {
2513         vid_attributes[0] = render_container_get_gamma(container);
2514         vid_attributes[1] = render_container_get_contrast(container);
2515         vid_attributes[2] = render_container_get_brightness(container);
2710         render_container_user_settings settings;
2711
2712         render_container_get_user_settings(container, &settings);
2713
2714         vid_attributes[0] = options_get_float(mame_options(), OPTION_GAMMA);
2715         vid_attributes[1] = options_get_float(mame_options(), OPTION_CONTRAST);
2716         vid_attributes[2] = options_get_float(mame_options(), OPTION_BRIGHTNESS);
25162717         vid_attributes[3] = 0.0f;
25172718         uniform_location = pfn_glGetUniformLocationARB(sdl->glsl_program[shaderIdx], "vid_attributes");
25182719         pfn_glUniform4fvARB(uniform_location, 1, &(vid_attributes[shaderIdx]));
r2959r2960
26482849
26492850static void drawogl_destroy_all_textures(sdl_window_info *window)
26502851{
2852   sdl_info *sdl = window->dxdata;
26512853    int lock=FALSE;
26522854
2653   if ( ! window->initialized )
2855   if ( ! sdl->initialized )
26542856   {
26552857      return;
26562858   }
r2959r2960
27242926
27252927      if ( sdl->useglsl )
27262928      {
2727         glsl_shader_free(sdl);
2929         glsl_shader_free(sdl->glsl);
2930         sdl->glsl = NULL;
27282931      }
27292932
2730      window->initialized = 0;
2933      sdl->initialized = 0;
27312934        }
27322935exit:
27332936        if(lock) { osd_lock_release(window->primlist->lock); }
r2959r2960
27372940//  TEXCOPY FUNCS
27382941//============================================================
27392942
2943static void drawogl_window_clear(sdl_window_info *window)
2944{
2945   sdl_info *sdl = window->dxdata;
2946
2947   //FIXME: Handled in drawogl_window_draw as well
2948   sdl->blittimer = 2;
2949}
2950
2951
2952//============================================================
2953//  TEXCOPY FUNCS
2954//============================================================
2955
27402956#include "texcopy.c"
27412957
27422958//============================================================
src/osd/sdl/gl_shader_mgr.h
r2959r2960
2929   GLSL_SHADER_FEAT_MAX_NUMBER,
3030} GLSL_SHADER_FEATURE;
3131
32// old code passed sdl_info * to functions here
33// however the parameter was not used
34// changed interface to more generic one.
35typedef struct _glsl_shader_info glsl_shader_info;
36struct _glsl_shader_info
37{
38   int dummy; // avoid compiler breakage
39};
40
41
3242/**
33 * returns 0 if ok, otherwise an error value
43 * returns pointer if ok, otherwise NULL
3444 */
35int glsl_shader_init(sdl_info *sdl);
45glsl_shader_info *glsl_shader_init(void);
3646
3747/**
3848 * returns 0 if ok, otherwise an error value
3949 */
40int glsl_shader_free(sdl_info *sdl);
50int glsl_shader_free(glsl_shader_info *shinfo);
4151
4252/**
4353 * returns the GLSL program if ok/available, otherwise 0
r2959r2960
4656
4757const char * glsl_shader_get_filter_name_mamebm(int glslShaderFeature);
4858
49int glsl_shader_add_mamebm(sdl_info *sdl, const char * custShaderPrefix, int idx);
59int glsl_shader_add_mamebm(glsl_shader_info *shinfo, const char * custShaderPrefix, int idx);
5060
5161GLhandleARB glsl_shader_get_program_scrn(int idx);
52int glsl_shader_add_scrn(sdl_info *sdl, const char * custShaderPrefix, int idx);
62int glsl_shader_add_scrn(glsl_shader_info *shinfo, const char * custShaderPrefix, int idx);
5363
5464#endif // GL_SHADER_MGR_H
src/osd/sdl/sdl.mak
r2959r2960
4444# There is no need to play with this option unless you are doing
4545# active development on sdlmame or SDL.
4646
47# SDL_INSTALL_ROOT = /usr/local/sdl13
47#SDL_INSTALL_ROOT = /usr/local/sdl13
4848
4949###########################################################################
5050##################   END USER-CONFIGURABLE OPTIONS   ######################
r2959r2960
243243SDLMAIN = $(SDLOBJ)/main.o
244244
245245# at least compile some stubs to link it
246ifdef DEBUG
247OSDOBJS += $(SDLOBJ)/debugwin.o
248endif
246OSDCOREOBJS += $(SDLOBJ)/debugwin.o
249247
250248LIBS += -lmingw32 -lSDL -lopengl32
251249endif   # Win32
src/osd/sdl/sound.c
r2959r2960
6464static int            buffer_overflows;
6565
6666// debugging
67#if LOG_SOUND
68#define sound_log stderr
69#endif
67static FILE *sound_log;
7068
69
7170// sound enable
7271static int snd_enabled;
7372
r2959r2960
8988//============================================================
9089void sdlaudio_init(running_machine *machine)
9190{
92#if LOG_SOUND
93   sound_log = fopen(SDL_SOUND_LOG, "w");
94#endif
91   if (LOG_SOUND)
92      sound_log = fopen(SDL_SOUND_LOG, "w");
9593
9694   // skip if sound disabled
9795   if (machine->sample_rate != 0)
r2959r2960
127125   if (buffer_overflows || buffer_underflows)
128126      mame_printf_verbose("Sound buffer: overflows=%d underflows=%d\n", buffer_overflows, buffer_underflows);
129127
130#if LOG_SOUND
131   if (sound_log)
128   if (LOG_SOUND)
129   {
132130      fprintf(sound_log, "Sound buffer: overflows=%d underflows=%d\n", buffer_overflows, buffer_underflows);
133   fclose(sound_log);
134#endif
131      fclose(sound_log);
132   }
135133}
136134
137135//============================================================
r2959r2960
152150         while (((pstart >= lstart) && (pstart <= lend)) ||
153151                ((pend >= lstart) && (pend <= lend)))
154152         {
155/*            #ifdef SDLMAME_WIN32
156            Sleep(0);
157            #else
158            sleep(0);
159            #endif*/
160
161153            pstart = stream_playpos;
162154            pend = pstart + sdl_xfer_samples;
163155         }
r2959r2960
185177      *buffer1 = &stream_buffer[offset];
186178   }
187179
188#if LOG_SOUND
189   fprintf(sound_log, "locking %ld bytes at offset %ld (total %d, playpos %d): len1 %ld len2 %ld\n",
180   if (LOG_SOUND)
181      fprintf(sound_log, "locking %ld bytes at offset %ld (total %d, playpos %d): len1 %ld len2 %ld\n",
190182           size, offset, stream_buffer_size, stream_playpos, *length1, *length2);
191#endif
192183
193184   return 0;
194185}
r2959r2960
202193   if (!buf_locked)
203194      SDL_UnlockAudio();
204195
205#if LOG_SOUND
206   fprintf(sound_log, "unlocking\n");
207#endif
196   if (LOG_SOUND)
197      fprintf(sound_log, "unlocking\n");
198
208199}
209200
210201//============================================================
r2959r2960
246237   {
247238      stream_buffer_in -= stream_buffer_size;
248239      stream_loop = 1;
249#if LOG_SOUND
250      fprintf(sound_log, "stream_loop set to 1 (stream_buffer_in looped)\n");
251#endif
240
241      if (LOG_SOUND)
242         fprintf(sound_log, "stream_loop set to 1 (stream_buffer_in looped)\n");
252243   }
253244
254245   // copy the first chunk
r2959r2960
282273   {
283274      int bytes_this_frame = samples_this_frame * sizeof(INT16) * 2;
284275      int play_position, write_position, stream_in;
285#if LOG_SOUND
286      int orig_write;
287#endif
276      int orig_write; // used in LOG
277     
288278      play_position = stream_playpos;
289279
290280      write_position = stream_playpos + ((machine->sample_rate / 50) * sizeof(INT16) * 2);
291#if LOG_SOUND
292281      orig_write = write_position;
293#endif
294282
295283      if (!stream_in_initialized)
296284      {
297285         stream_in = stream_buffer_in = (write_position + stream_buffer_size) / 2;
298286
299#if LOG_SOUND
300         fprintf(sound_log, "stream_in = %d\n", (int)stream_in);
301         fprintf(sound_log, "stream_playpos = %d\n", (int)stream_playpos);
302         fprintf(sound_log, "write_position = %d\n", (int)write_position);
303#endif
304
287         if (LOG_SOUND)
288         {
289            fprintf(sound_log, "stream_in = %d\n", (int)stream_in);
290            fprintf(sound_log, "stream_playpos = %d\n", (int)stream_playpos);
291            fprintf(sound_log, "write_position = %d\n", (int)write_position);
292         }
305293         // start playing
306294         SDL_PauseAudio(0);
307295
r2959r2960
320308         // if we're between play and write positions, then bump forward, but only in full chunks
321309         while (stream_in < write_position)
322310         {
323#if LOG_SOUND
324            fprintf(sound_log, "Underflow: PP=%d  WP=%d(%d)  SI=%d(%d)  BTF=%d\n", (int)play_position, (int)write_position, (int)orig_write, (int)stream_in, (int)stream_buffer_in, (int)bytes_this_frame);
325#endif
311            if (LOG_SOUND)
312               fprintf(sound_log, "Underflow: PP=%d  WP=%d(%d)  SI=%d(%d)  BTF=%d\n", (int)play_position, (int)write_position, (int)orig_write, (int)stream_in, (int)stream_buffer_in, (int)bytes_this_frame);
313
326314            buffer_underflows++;
327315            stream_in += samples_this_frame;
328316         }
r2959r2960
330318         // if we're going to overlap the play position, just skip this chunk
331319         if (stream_in + bytes_this_frame > play_position + stream_buffer_size)
332320         {
333#if LOG_SOUND
334            fprintf(sound_log, "Overflow: PP=%d  WP=%d(%d)  SI=%d(%d)  BTF=%d\n", (int)play_position, (int)write_position, (int)orig_write, (int)stream_in, (int)stream_buffer_in, (int)bytes_this_frame);
335#endif
321            if (LOG_SOUND)
322               fprintf(sound_log, "Overflow: PP=%d  WP=%d(%d)  SI=%d(%d)  BTF=%d\n", (int)play_position, (int)write_position, (int)orig_write, (int)stream_in, (int)stream_buffer_in, (int)bytes_this_frame);
323
336324            buffer_overflows++;
337325            return;
338326         }
r2959r2960
342330      {
343331         stream_in -= stream_buffer_size;
344332         stream_loop = 1;
345#if LOG_SOUND
346         fprintf(sound_log, "stream_loop set to 1 (stream_in looped)\n");
347#endif
333         
334         if (LOG_SOUND)
335            fprintf(sound_log, "stream_loop set to 1 (stream_in looped)\n");
336
348337      }
349338
350339      // now we know where to copy; let's do it
r2959r2960
383372
384373   if (sb_in < (stream_playpos+len))
385374   {
386#if LOG_SOUND
387      fprintf(sound_log, "Underflow at sdl_callback: SPP=%d SBI=%d(%d) Len=%d\n", (int)stream_playpos, (int)sb_in, (int)stream_buffer_in, (int)len);
388#endif
375      if (LOG_SOUND)
376         fprintf(sound_log, "Underflow at sdl_callback: SPP=%d SBI=%d(%d) Len=%d\n", (int)stream_playpos, (int)sb_in, (int)stream_buffer_in, (int)len);
377
389378      return;
390379   }
391380   else if ((stream_playpos+len) > stream_buffer_size)
r2959r2960
421410   {
422411      stream_playpos -= stream_buffer_size;
423412      stream_loop = 0;
424#if LOG_SOUND
425      fprintf(sound_log, "stream_loop set to 0 (stream_playpos looped)\n");
426#endif
413     
414      if (LOG_SOUND)
415         fprintf(sound_log, "stream_loop set to 0 (stream_playpos looped)\n");
427416   }
428417
429#if LOG_SOUND
430   fprintf(sound_log, "callback: xfer len1 %d len2 %d, playpos %d\n",
431           len1, len2, stream_playpos);
432#endif
418   if (LOG_SOUND)
419      fprintf(sound_log, "callback: xfer len1 %d len2 %d, playpos %d\n",
420            len1, len2, stream_playpos);
433421}
434422
435423
r2959r2960
468456   initialized_audio = 1;
469457   snd_enabled = 1;
470458
459#if (SDL_VERSION_ATLEAST(1,3,0))
460   strncpy(audio_driver, SDL_GetCurrentAudioDriver(), sizeof(audio_driver));
461#else
471462   SDL_AudioDriverName(audio_driver, sizeof(audio_driver));
463#endif
472464   mame_printf_verbose("Audio initialized - driver: %s, frequency: %d, "
473465                       "channels: %d, samples: %d\n", audio_driver,
474466                       obtained.freq, obtained.channels, obtained.samples);
src/osd/sdl/input.c
r2959r2960
3232#include "inputx.h"
3333#endif
3434
35#include "uiinput.h"
36
3537// winnt.h defines this
3638#ifdef DELETE
3739#undef DELETE
r2959r2960
129131static osd_lock *         input_lock;
130132static UINT8            input_paused;
131133
132#ifdef SDLMAME_WIN32
134static sdl_window_info *   focus_window = NULL;
135
136#if SDLMAME_EVENTS_IN_WORKER_THREAD
133137// input buffer
134#define MAX_BUF_EVENTS          (100)
138#define MAX_BUF_EVENTS       (100)
135139static SDL_Event         event_buf[MAX_BUF_EVENTS];
136static int            event_buf_count;
140static int               event_buf_count;
137141#endif
138142
139143// keyboard states
140static device_info *         keyboard_list;
144static device_info *      keyboard_list;
141145
142146// mouse states
143147static UINT8            mouse_enabled;
144static device_info *         mouse_list;
148static device_info *      mouse_list;
145149
146150// lightgun states
147151static UINT8            lightgun_enabled;
148static device_info *         lightgun_list;
152static device_info *      lightgun_list;
149153
150154// joystick states
151static device_info *         joystick_list;
155static device_info *      joystick_list;
152156
153157// joystick mapper
154158static struct
r2959r2960
895899   kt_table *key_trans_table;
896900   kt_table *ktt_alloc = NULL;
897901
902   // we want unicode keyboard characters
903   SDL_EnableUNICODE(1);
904
898905   keyboard_list = NULL;
899906   joystick_list = NULL;
900907   mouse_list = NULL;
r2959r2960
10571064
10581065
10591066//============================================================
1067//  sdlinput_get_focus_window
1068//============================================================
1069
1070sdl_window_info *sdlinput_get_focus_window(running_machine *machine)
1071{
1072   if (focus_window)  // only be set on SDL >= 1.3
1073      return focus_window;
1074   else
1075      return sdl_window_list;
1076}
1077
1078//============================================================
10601079//  sdlinput_poll
10611080//============================================================
10621081
1063#ifdef SDLMAME_WIN32
1064void sdlinput_process_events_buf(void)
1082#if (SDL_VERSION_ATLEAST(1,3,0))
1083INLINE sdl_window_info * window_from_id(SDL_WindowID windowID)
10651084{
1085   sdl_window_info *w;
1086   
1087   for (w = sdl_window_list; w != NULL; w = w->next)
1088   {
1089      if (w->window_id == windowID)
1090      {
1091         return w;
1092      }
1093   }
1094   // deliberately crash
1095   printf("Window %d not found\n", windowID);
1096   return NULL;
1097}
1098#endif
1099
1100void sdlinput_process_events_buf(running_machine *machine)
1101{
1102#if SDLMAME_EVENTS_IN_WORKER_THREAD
10661103   SDL_Event event;
10671104
10681105   osd_lock_acquire(input_lock);
r2959r2960
10741111         mame_printf_warning("Event Buffer Overflow!\n");   
10751112   }
10761113   osd_lock_release(input_lock);
1114#endif
10771115}
1078#endif
10791116
10801117void sdlinput_poll(running_machine *machine)
10811118{
10821119   device_info *devinfo;
10831120   SDL_Event event;
1084#ifdef SDLMAME_WIN32
1121#if SDLMAME_EVENTS_IN_WORKER_THREAD
10851122   SDL_Event         loc_event_buf[MAX_BUF_EVENTS];
10861123   int               loc_event_buf_count;
10871124   int bufp;
r2959r2960
10911128   devinfo->mouse.lX = 0;
10921129   devinfo->mouse.lY = 0;
10931130
1094#ifdef SDLMAME_WIN32
1131#if SDLMAME_EVENTS_IN_WORKER_THREAD
10951132   osd_lock_acquire(input_lock);
10961133   memcpy(loc_event_buf, event_buf, sizeof(event_buf));
10971134   loc_event_buf_count = event_buf_count;
r2959r2960
11111148         event.type = SDL_KEYDOWN;
11121149      }
11131150      switch(event.type) {
1114      case SDL_QUIT:
1115         mame_schedule_exit(machine);
1116         break;
11171151      case SDL_KEYDOWN:
11181152         #ifdef MESS
11191153         if (win_use_natural_keyboard)
r2959r2960
11361170         }
11371171         #endif
11381172
1173         #if (SDL_VERSION_ATLEAST(1,3,0))
1174         ui_input_push_char_event(machine, window_from_id(event.window.windowID)->target, (unicode_char)event.key.keysym.unicode);
1175         #else
1176         ui_input_push_char_event(machine, sdl_window_list->target, (unicode_char)event.key.keysym.unicode);
1177         #endif
1178
11391179         devinfo = keyboard_list;
11401180#if (SDL_VERSION_ATLEAST(1,3,0))
11411181         devinfo->keyboard.state[OSD_SDL_INDEX(event.key.keysym.scancode)] = 0x80;
r2959r2960
12231263      case SDL_MOUSEBUTTONDOWN:
12241264         devinfo = mouse_list;
12251265         devinfo->mouse.buttons[event.button.button-1] = 0x80;
1266
1267         #if (SDL_VERSION_ATLEAST(1,3,0))
1268         ui_input_push_mouse_click_event(machine, window_from_id(event.window.windowID)->target, event.button.x, event.button.y);
1269         #else
1270         ui_input_push_mouse_click_event(machine, sdl_window_list->target, event.button.x, event.button.y);
1271         #endif
1272
12261273         break;
12271274      case SDL_MOUSEBUTTONUP:
12281275         devinfo = mouse_list;
r2959r2960
12321279         devinfo = mouse_list;
12331280         devinfo->mouse.lX = event.motion.xrel * INPUT_RELATIVE_PER_PIXEL;
12341281         devinfo->mouse.lY = event.motion.yrel * INPUT_RELATIVE_PER_PIXEL;
1282
1283         #if (SDL_VERSION_ATLEAST(1,3,0))
1284         ui_input_push_mouse_move_event(machine, window_from_id(event.window.windowID)->target, event.motion.xrel * INPUT_RELATIVE_PER_PIXEL, event.motion.yrel * INPUT_RELATIVE_PER_PIXEL);
1285         #else
1286         ui_input_push_mouse_move_event(machine, sdl_window_list->target, event.motion.xrel * INPUT_RELATIVE_PER_PIXEL, event.motion.yrel * INPUT_RELATIVE_PER_PIXEL);
1287         #endif
12351288         break;
1289#if (!SDL_VERSION_ATLEAST(1,3,0))
1290      case SDL_QUIT:
1291         mame_schedule_exit(machine);
1292         break;
12361293      case SDL_VIDEORESIZE:
12371294         sdlwindow_resize(sdl_window_list, event.resize.w, event.resize.h);
12381295         break;
1296#else
1297      case SDL_WINDOWEVENT:
1298         switch (event.window.event)
1299         {
1300         case SDL_WINDOWEVENT_CLOSE:
1301            mame_schedule_exit(machine);
1302            break;
1303         case SDL_WINDOWEVENT_RESIZED:
1304            sdlwindow_resize(window_from_id(event.window.windowID), event.window.data1, event.window.data2);
1305            /* fall through break; */
1306         case SDL_WINDOWEVENT_FOCUS_GAINED:
1307         case SDL_WINDOWEVENT_ENTER:
1308         case SDL_WINDOWEVENT_EXPOSED:
1309         case SDL_WINDOWEVENT_MAXIMIZED: 
1310         case SDL_WINDOWEVENT_RESTORED:
1311            focus_window = window_from_id(event.window.windowID);
1312            break;
1313         }
1314         break;
1315#endif
12391316      }
12401317   }
12411318}
r2959r2960
12451322//  sdlinput_should_hide_mouse
12461323//============================================================
12471324
1248int sdlinput_should_hide_mouse(void)
1325int sdlinput_should_hide_mouse(running_machine *machine)
12491326{
12501327   // if we are paused, no
12511328   if (input_paused)
src/osd/sdl/drawsdl.c
r2959r2960
3838//  MACROS
3939//============================================================
4040
41
4142//============================================================
43//  TYPES
44//============================================================
45
46/* sdl_info is the information about SDL for the current screen */
47typedef struct _sdl_info sdl_info;
48struct _sdl_info
49{
50   INT32             blittimer;
51
52#if (SDL_VERSION_ATLEAST(1,3,0))
53   SDL_TextureID      texture_id;
54#else
55   // SDL surface
56   SDL_Surface       *sdlsurf;
57   SDL_Overlay       *yuvsurf;
58#endif
59
60   // YUV overlay
61   UINT32             *yuv_lookup;
62   UINT16            *yuv_bitmap;
63   int               yuv_ovl_width;
64   int               yuv_ovl_height;
65};
66
67//============================================================
4268//  INLINES
4369//============================================================
4470
r2959r2960
4874
4975// core functions
5076static void drawsdl_exit(void);
51static int drawsdl_window_init(sdl_window_info *window);
77static int drawsdl_window_create(sdl_window_info *window, int width, int height);
78static void drawsdl_window_resize(sdl_window_info *window, int width, int height);
5279static void drawsdl_window_destroy(sdl_window_info *window);
5380static const render_primitive_list *drawsdl_window_get_primitives(sdl_window_info *window);
5481static int drawsdl_window_draw(sdl_window_info *window, UINT32 dc, int update);
5582static void drawsdl_destroy_all_textures(sdl_window_info *window);
83static void drawsdl_window_clear(sdl_window_info *window);
84#if (SDL_VERSION_ATLEAST(1,3,0))
85static void setup_texture(sdl_window_info *window, int tempwidth, int tempheight);
86#endif
5687
5788// soft rendering
5889static void drawsdl_rgb888_draw_primitives(const render_primitive *primlist, void *dstdata, UINT32 width, UINT32 height, UINT32 pitch);
r2959r2960
6293
6394// YUV overlays
6495
65static void drawsdl_yuv_init(sdl_window_info *window);
66static void yuv_RGB_to_YV12(UINT16 *bitmap, int bw, sdl_window_info *window);
67static void yuv_RGB_to_YV12X2(UINT16 *bitmap, int bw, sdl_window_info *window);
68static void yuv_RGB_to_YUY2(UINT16 *bitmap, int bw, sdl_window_info *window);
69static void yuv_RGB_to_YUY2X2(UINT16 *bitmap, int bw, sdl_window_info *window);
96static void drawsdl_yuv_init(sdl_info *sdl);
97static void yuv_RGB_to_YV12(UINT16 *bitmap, sdl_info *sdl, UINT8 *ptr, int pitch);
98static void yuv_RGB_to_YV12X2(UINT16 *bitmap, sdl_info *sdl, UINT8 *ptr, int pitch);
99static void yuv_RGB_to_YUY2(UINT16 *bitmap, sdl_info *sdl, UINT8 *ptr, int pitch);
100static void yuv_RGB_to_YUY2X2(UINT16 *bitmap, sdl_info *sdl, UINT8 *ptr, int pitch);
70101
102// Static declarations
71103
104#if (!SDL_VERSION_ATLEAST(1,3,0))
105static int shown_video_info = 0;
106static const char *yuv_mode_names[] = { "none", "yv12", "yv12x2", "yuy2", "yuy2x2" };
107#endif
108
72109//============================================================
73110//  drawsdl_init
74111//============================================================
r2959r2960
77114{
78115   // fill in the callbacks
79116   callbacks->exit = drawsdl_exit;
80   callbacks->window_init = drawsdl_window_init;
117   callbacks->window_create = drawsdl_window_create;
118   callbacks->window_resize = drawsdl_window_resize;
81119   callbacks->window_get_primitives = drawsdl_window_get_primitives;
82120   callbacks->window_draw = drawsdl_window_draw;
83121   callbacks->window_destroy = drawsdl_window_destroy;
84122   callbacks->window_destroy_all_textures = drawsdl_destroy_all_textures;
123   callbacks->window_clear = drawsdl_window_clear;
85124
86   #if SDL_MULTIMON
125   #if SDL_VERSION_ATLEAST(1,3,0)
87126   mame_printf_verbose("Using SDL multi-window soft driver (SDL 1.3+)\n");
88127   #else
89128   mame_printf_verbose("Using SDL single-window soft driver (SDL 1.2)\n");
r2959r2960
109148}
110149
111150//============================================================
112//  drawsdl_window_init
151//  setup_texture for window
113152//============================================================
114153
115static int drawsdl_window_init(sdl_window_info *window)
154#if (SDL_VERSION_ATLEAST(1,3,0))
155static void setup_texture(sdl_window_info *window, int tempwidth, int tempheight)
116156{
117   sdl_info *sdl;
157   sdl_info *   sdl = window->dxdata;
158   // Determine preferred pixelformat and set up yuv if necessary
159   
160   if (sdl->yuv_bitmap)
161   {
162      free(sdl->yuv_bitmap);
163      sdl->yuv_bitmap = NULL;   
164   }
165   
166   switch (video_config.yuv_mode)
167   {
168      case VIDEO_YUV_MODE_NONE:
169         sdl->texture_id = SDL_CreateTexture(SDL_PIXELFORMAT_RGB888, SDL_TEXTUREACCESS_STREAMING,
170               tempwidth, tempheight);
171         SDL_SetTextureScaleMode(sdl->texture_id, SDL_TEXTURESCALEMODE_NONE);
172         break;
173      case VIDEO_YUV_MODE_YV12:
174         render_target_get_minimum_size(window->target, &sdl->yuv_ovl_width, &sdl->yuv_ovl_height);
175         sdl->yuv_bitmap = malloc_or_die(sdl->yuv_ovl_width * sdl->yuv_ovl_height * sizeof(UINT16));
176         sdl->texture_id = SDL_CreateTexture(SDL_PIXELFORMAT_YV12, SDL_TEXTUREACCESS_STREAMING,
177               sdl->yuv_ovl_width, sdl->yuv_ovl_height);
178         //SDL_SetTextureScaleMode(sdl->sdltex, SDL_TEXTURESCALEMODE_FAST);
179         break;
180      case VIDEO_YUV_MODE_YV12X2:
181         render_target_get_minimum_size(window->target, &sdl->yuv_ovl_width, &sdl->yuv_ovl_height);
182         sdl->yuv_bitmap = malloc_or_die(sdl->yuv_ovl_width * sdl->yuv_ovl_height * sizeof(UINT16));
183         sdl->texture_id = SDL_CreateTexture(SDL_PIXELFORMAT_YV12, SDL_TEXTUREACCESS_STREAMING,
184               sdl->yuv_ovl_width * 2, sdl->yuv_ovl_height * 2);
185         break;
186      case VIDEO_YUV_MODE_YUY2:
187         render_target_get_minimum_size(window->target, &sdl->yuv_ovl_width, &sdl->yuv_ovl_height);
188         sdl->yuv_bitmap = malloc_or_die(sdl->yuv_ovl_width * sdl->yuv_ovl_height * sizeof(UINT16));
189         sdl->texture_id = SDL_CreateTexture(SDL_PIXELFORMAT_YUY2, SDL_TEXTUREACCESS_STREAMING,
190               sdl->yuv_ovl_width, sdl->yuv_ovl_height);
191         break;
192      case VIDEO_YUV_MODE_YUY2X2:
193         render_target_get_minimum_size(window->target, &sdl->yuv_ovl_width, &sdl->yuv_ovl_height);
194         sdl->yuv_bitmap = malloc_or_die(sdl->yuv_ovl_width * sdl->yuv_ovl_height * sizeof(UINT16));
195         sdl->texture_id = SDL_CreateTexture(SDL_PIXELFORMAT_YUY2, SDL_TEXTUREACCESS_STREAMING,
196               sdl->yuv_ovl_width * 2, sdl->yuv_ovl_height);
197         break;
198   }
199}
200#endif
118201
202//============================================================
203//  yuv_overlay_init
204//============================================================
205
206#if (!SDL_VERSION_ATLEAST(1,3,0))
207static void yuv_overlay_init(sdl_window_info *window)
208{
209   sdl_info *sdl = window->dxdata;
210   int minimum_width, minimum_height;
211
212   render_target_get_minimum_size(window->target, &minimum_width, &minimum_height);
213   if (sdl->yuvsurf != NULL)
214      SDL_FreeYUVOverlay(sdl->yuvsurf);
215   if (sdl->yuv_bitmap != NULL)
216   {
217      free(sdl->yuv_bitmap);   
218   }
219   sdl->yuv_bitmap = malloc_or_die(minimum_width*minimum_height*sizeof(UINT16));
220
221   mame_printf_verbose("SDL: Creating YUV-Overlay ...\n");
222   switch (video_config.yuv_mode)
223   {
224      case VIDEO_YUV_MODE_YV12:
225         sdl->yuvsurf = SDL_CreateYUVOverlay(minimum_width, minimum_height,
226                 SDL_YV12_OVERLAY, sdl->sdlsurf);
227         break;
228      case VIDEO_YUV_MODE_YV12X2:
229         sdl->yuvsurf = SDL_CreateYUVOverlay(minimum_width*2, minimum_height*2,
230                  SDL_YV12_OVERLAY, sdl->sdlsurf);
231         break;
232      case VIDEO_YUV_MODE_YUY2:
233         sdl->yuvsurf = SDL_CreateYUVOverlay(minimum_width, minimum_height,
234                  SDL_YUY2_OVERLAY, sdl->sdlsurf);
235         break;
236      case VIDEO_YUV_MODE_YUY2X2:
237         sdl->yuvsurf = SDL_CreateYUVOverlay(minimum_width*2, minimum_height,
238                  SDL_YUY2_OVERLAY, sdl->sdlsurf);
239         break;
240   }
241   if ( sdl->yuvsurf == NULL ) {
242      mame_printf_error("SDL: Couldn't create SDL_yuv_overlay: %s\n", SDL_GetError());
243      //return 1;
244   }
245   sdl->yuv_ovl_width = minimum_width;
246   sdl->yuv_ovl_height = minimum_height;
247
248   if (!shown_video_info)
249   {
250      mame_printf_verbose("YUV Mode         : %s\n", yuv_mode_names[video_config.yuv_mode]);
251      mame_printf_verbose("YUV Overlay Size : %d x %d\n", minimum_width, minimum_height);
252      mame_printf_verbose("YUV Acceleration : %s\n", sdl->yuvsurf->hw_overlay ? "Hardware" : "Software");
253      shown_video_info = 1;
254   }
255}
256#endif
257
258//============================================================
259//  drawsdl_window_create
260//============================================================
261
262static int drawsdl_window_create(sdl_window_info *window, int width, int height)
263{
264   sdl_info *sdl = window->dxdata;
265
119266   // allocate memory for our structures
120267   sdl = malloc(sizeof(*sdl));
121268   memset(sdl, 0, sizeof(*sdl));
269
122270   window->dxdata = sdl;
123   window->yuv_lookup = NULL;
124   window->yuv_bitmap = NULL;
125   window->initialized = 0;
126   sdl->totalColors = window->totalColors;
271   
272#if (SDL_VERSION_ATLEAST(1,3,0))
273   window->extra_flags = (window->fullscreen ? 
274         SDL_WINDOW_BORDERLESS | SDL_WINDOW_INPUT_FOCUS : SDL_WINDOW_RESIZABLE);
275   //FIXME: OpenGL in Software
276   /* the following is a workaround for a bug in SDL 1.3
277    * where creating a renderer will loose keyboard focus
278    * This happens only if one window is present.
279    */
280   window->extra_flags |= SDL_WINDOW_OPENGL;
127281
128   drawsdl_yuv_init(window);
282   SDL_SelectVideoDisplay(window->monitor->handle);
283   SDL_SetFullscreenDisplayMode(NULL);   // Use desktop
284   window->window_id = SDL_CreateWindow(window->title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
285         width, height, window->extra_flags);
286   SDL_ShowWindow(window->window_id);
287   SDL_SetWindowFullscreen(window->window_id, window->fullscreen);
288   SDL_RaiseWindow(window->window_id);
289   SDL_GetWindowSize(window->window_id, &window->width, &window->height);
290   
291   // create a texture
292   SDL_CreateRenderer(window->window_id, -1, SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTDISCARD);
293    SDL_SelectRenderer(window->window_id);
294   setup_texture(window, width, height);
295#else
296   window->extra_flags = (window->fullscreen ?  SDL_FULLSCREEN : SDL_RESIZABLE);
297   // create the SDL surface (which creates the window in windowed mode)
298   if (video_config.yuv_mode == VIDEO_YUV_MODE_NONE)
299      window->extra_flags |= SDL_DOUBLEBUF;
300
301   sdl->sdlsurf = SDL_SetVideoMode(width, height,
302               0, SDL_SWSURFACE | SDL_ANYFORMAT | window->extra_flags);
303
304   if (!sdl->sdlsurf)
305      return 1;
306
307   window->width = sdl->sdlsurf->w;
308   window->height = sdl->sdlsurf->h;
309   
310   if (video_config.yuv_mode != VIDEO_YUV_MODE_NONE)
311   {
312      yuv_overlay_init(window);
313   }
314
315   // set the window title
316   SDL_WM_SetCaption(window->title, "SDLMAME");
317#endif
318   sdl->yuv_lookup = NULL;
319   sdl->blittimer = 0;
320   
321   drawsdl_yuv_init(sdl);
129322   return 0;
130323}
131324
132325//============================================================
326//  drawsdl_window_resize
327//============================================================
328
329static void drawsdl_window_resize(sdl_window_info *window, int width, int height)
330{
331   sdl_info *sdl = window->dxdata;
332
333#if (SDL_VERSION_ATLEAST(1,3,0))
334   SDL_SetWindowSize(window->window_id, width, height);
335   SDL_GetWindowSize(window->window_id, &window->width, &window->height);
336
337   // create a texture
338   SDL_SelectRenderer(window->window_id);
339   SDL_DestroyTexture(sdl->texture_id);
340
341   setup_texture(window, window->width, window->height);
342#else
343   SDL_FreeSurface(sdl->sdlsurf);
344   //printf("SetVideoMode %d %d\n", wp->resize_new_width, wp->resize_new_height);
345
346   sdl->sdlsurf = SDL_SetVideoMode(width, height, 0,
347         SDL_SWSURFACE | SDL_ANYFORMAT | window->extra_flags);
348   window->width = sdl->sdlsurf->w;
349   window->height = sdl->sdlsurf->h;
350
351   if (video_config.yuv_mode != VIDEO_YUV_MODE_NONE)
352   {
353      yuv_overlay_init(window);
354   }
355   
356#endif
357}
358
359
360//============================================================
133361//  drawsdl_window_destroy
134362//============================================================
135363
r2959r2960
141369   if (sdl == NULL)
142370      return;
143371
372#if (SDL_VERSION_ATLEAST(1,3,0))
373   SDL_SelectRenderer(window->window_id);
374   SDL_DestroyTexture(sdl->texture_id);
375   //SDL_DestroyRenderer(window->window_id);
376   SDL_DestroyWindow(window->window_id);
377#else
378   if (sdl->sdlsurf)
379   {
380      SDL_FreeSurface(sdl->sdlsurf);
381      sdl->sdlsurf = NULL;
382   }
383#endif
144384   // free the memory in the window
145385
146   free(sdl);
147   window->dxdata = NULL;
148   if (window->yuv_lookup != NULL)
386   if (sdl->yuv_lookup != NULL)
149387   {
150      free(window->yuv_lookup);
151      window->yuv_lookup = NULL;
388      free(sdl->yuv_lookup);
389      sdl->yuv_lookup = NULL;
152390   }
153   if (window->yuv_bitmap != NULL)
391   if (sdl->yuv_bitmap != NULL)
154392   {
155      free(window->yuv_bitmap);   
156      window->yuv_bitmap = NULL;
393      free(sdl->yuv_bitmap);   
394      sdl->yuv_bitmap = NULL;
157395   }
396   window->dxdata = NULL;
397   free(sdl);
158398}
159399
160400//============================================================
401//  drawsdl_window_clear
402//============================================================
403
404static void drawsdl_window_clear(sdl_window_info *window)
405{
406   sdl_info *sdl = window->dxdata;
407   
408   sdl->blittimer = 3;
409}
410
411//============================================================
161412//  drawsdl_window_get_primitives
162413//============================================================
163414
164415static const render_primitive_list *drawsdl_window_get_primitives(sdl_window_info *window)
165416{
166417   sdl_info *sdl = window->dxdata;
167   if ((video_config.windowed) || (video_config.switchres))
418   if ((!window->fullscreen) || (video_config.switchres))
168419   {
169      sdlwindow_blit_surface_size(window, window->sdlsurf->w, window->sdlsurf->h);
420      sdlwindow_blit_surface_size(window, window->width, window->height);
170421   }
171422   else
172423   {
173424      sdlwindow_blit_surface_size(window, window->monitor->center_width, window->monitor->center_height);
174425   }
175426   if (video_config.yuv_mode == VIDEO_YUV_MODE_NONE)
176      render_target_set_bounds(window->target, sdl->blitwidth, sdl->blitheight, sdlvideo_monitor_get_aspect(window->monitor));
427      render_target_set_bounds(window->target, window->blitwidth, window->blitheight, sdlvideo_monitor_get_aspect(window->monitor));
177428   else
178      render_target_set_bounds(window->target, window->yuv_ovl_width, window->yuv_ovl_height, 0);
429      render_target_set_bounds(window->target, sdl->yuv_ovl_width, sdl->yuv_ovl_height, 0);
179430   return render_target_get_primitives(window->target);
180431}
181432
r2959r2960
187438{
188439   sdl_info *sdl = window->dxdata;
189440   UINT8 *surfptr;
441   INT32 pitch;
442   int bpp;
443   Uint32 rmask, gmask, bmask, amask;
190444   INT32 vofs, hofs, blitwidth, blitheight, ch, cw;
191   SDL_Rect r;
192445
193446   if (video_config.novideo)
194447   {
r2959r2960
200453      return 1;
201454
202455   // lock it if we need it
203   if (SDL_MUSTLOCK(window->sdlsurf)) SDL_LockSurface(window->sdlsurf);
456#if (!SDL_VERSION_ATLEAST(1,3,0))
457
458   pitch = sdl->sdlsurf->pitch;
459   bpp = sdl->sdlsurf->format->BytesPerPixel;
460   rmask = sdl->sdlsurf->format->Rmask;
461   gmask = sdl->sdlsurf->format->Gmask;
462   bmask = sdl->sdlsurf->format->Bmask;
463   amask = sdl->sdlsurf->format->Amask;
464   
465   if (SDL_MUSTLOCK(sdl->sdlsurf)) SDL_LockSurface(sdl->sdlsurf);
466   // Clear if necessary
467
468   if (sdl->blittimer > 0)
469   {
470      memset(sdl->sdlsurf->pixels, 0, window->height * sdl->sdlsurf->pitch);
471      sdl->blittimer--;
472   }
473
474   
204475   if (video_config.yuv_mode != VIDEO_YUV_MODE_NONE)
205476   {
206      SDL_LockYUVOverlay(window->yuvsurf);
207      surfptr = (UINT8 *) window->yuv_bitmap;
477      SDL_LockYUVOverlay(sdl->yuvsurf);
478      surfptr = sdl->yuvsurf->pixels[0]; // (UINT8 *) sdl->yuv_bitmap;
479      pitch = sdl->yuvsurf->pitches[0]; // (UINT8 *) sdl->yuv_bitmap;
208480   }
209481   else
210      surfptr = (UINT8 *)window->sdlsurf->pixels;
482      surfptr = (UINT8 *)sdl->sdlsurf->pixels;
483#else
484   SDL_SelectRenderer(window->window_id);
485   {
486        Uint32 format;
487        int access, w, h;
488     
489        SDL_QueryTexture(sdl->texture_id, &format, &access, &w, &h);
490      SDL_PixelFormatEnumToMasks(format, &bpp, &rmask, &gmask, &bmask, &amask);
491      bpp = bpp / 8; /* convert to bytes per pixels */
492   }
493
494   SDL_LockTexture(sdl->texture_id, NULL, 1, (void **) &surfptr, &pitch);
495   // Clear if necessary
496   if (video_config.yuv_mode == VIDEO_YUV_MODE_NONE)
497      if (sdl->blittimer > 0)
498      {   
499         memset(surfptr, 0, window->height * pitch);
500         sdl->blittimer--;
501      }
502
503#endif
211504   // get ready to center the image
212505   vofs = hofs = 0;
213   blitwidth = sdl->blitwidth;
214   blitheight = sdl->blitheight;
506   blitwidth = window->blitwidth;
507   blitheight = window->blitheight;
215508
216509   // figure out what coordinate system to use for centering - in window mode it's always the
217510   // SDL surface size.  in fullscreen the surface covers all monitors, so center according to
218511   // the first one only
219   if ((!video_config.windowed) && (!video_config.switchres))
512   if ((window->fullscreen) && (!video_config.switchres))
220513   {
221514      ch = window->monitor->center_height;
222515      cw = window->monitor->center_width;
223516   }
224517   else
225518   {
226      ch = window->sdlsurf->h;
227      cw = window->sdlsurf->w;
519      ch = window->height;
520      cw = window->width;
228521   }
229522
230523   // do not crash if the window's smaller than the blit area
r2959r2960
234527   }
235528   else if (video_config.centerv)
236529   {
237      vofs = (ch - sdl->blitheight) / 2;
530      vofs = (ch - window->blitheight) / 2;
238531   }
239532
240533   if (blitwidth > cw)
r2959r2960
243536   }
244537   else if (video_config.centerh)
245538   {
246      hofs = (cw - sdl->blitwidth) / 2;
539      hofs = (cw - window->blitwidth) / 2;
247540   }
248541
249542   osd_lock_acquire(window->primlist->lock);
r2959r2960
251544   // render to it
252545   if (video_config.yuv_mode == VIDEO_YUV_MODE_NONE)
253546   {
254      surfptr += ((vofs * window->sdlsurf->pitch) + (hofs * window->sdlsurf->format->BytesPerPixel));
255      switch (window->sdlsurf->format->Rmask)
547      surfptr += ((vofs * pitch) + (hofs * bpp));
548      switch (rmask)
256549      {
257550         case 0x00ff0000:
258            drawsdl_rgb888_draw_primitives(window->primlist->head, surfptr, blitwidth, blitheight, window->sdlsurf->pitch / 4);
551            drawsdl_rgb888_draw_primitives(window->primlist->head, surfptr, blitwidth, blitheight, pitch / 4);
259552            break;
260553
261554         case 0x000000ff:
262            drawsdl_bgr888_draw_primitives(window->primlist->head, surfptr, blitwidth, blitheight, window->sdlsurf->pitch / 4);
555            drawsdl_bgr888_draw_primitives(window->primlist->head, surfptr, blitwidth, blitheight, pitch / 4);
263556            break;
264557
265558         case 0xf800:
266            drawsdl_rgb565_draw_primitives(window->primlist->head, surfptr, blitwidth, blitheight, window->sdlsurf->pitch / 2);
559            drawsdl_rgb565_draw_primitives(window->primlist->head, surfptr, blitwidth, blitheight, pitch / 2);
267560            break;
268561
269562         case 0x7c00:
270            drawsdl_rgb555_draw_primitives(window->primlist->head, surfptr, blitwidth, blitheight, window->sdlsurf->pitch / 2);
563            drawsdl_rgb555_draw_primitives(window->primlist->head, surfptr, blitwidth, blitheight, pitch / 2);
271564            break;
272565
273566         default:
274            mame_printf_error("SDL: ERROR! Unknown video mode: R=%08X G=%08X B=%08X\n", window->sdlsurf->format->Rmask, window->sdlsurf->format->Gmask, window->sdlsurf->format->Bmask);
567            mame_printf_error("SDL: ERROR! Unknown video mode: R=%08X G=%08X B=%08X\n", rmask, gmask, bmask);
275568            break;
276569      }
277570   }
278571   else
279572   {
280      drawsdl_rgb555_draw_primitives(window->primlist->head, surfptr, window->yuv_ovl_width, window->yuv_ovl_height, window->yuv_ovl_width);
573      assert (sdl->yuv_bitmap != NULL);
574      assert (surfptr != NULL);
575      drawsdl_rgb555_draw_primitives(window->primlist->head, sdl->yuv_bitmap, sdl->yuv_ovl_width, sdl->yuv_ovl_height, sdl->yuv_ovl_width);
281576      switch (video_config.yuv_mode)
282577      {
283578         case VIDEO_YUV_MODE_YV12:
284            yuv_RGB_to_YV12((UINT16 *)surfptr, window->yuv_ovl_width, window);
579            yuv_RGB_to_YV12((UINT16 *)sdl->yuv_bitmap, sdl, surfptr, pitch);
285580            break;
286581         case VIDEO_YUV_MODE_YV12X2:
287            yuv_RGB_to_YV12X2((UINT16 *)surfptr, window->yuv_ovl_width, window);
582            yuv_RGB_to_YV12X2((UINT16 *)sdl->yuv_bitmap, sdl, surfptr, pitch);
288583            break;
289584         case VIDEO_YUV_MODE_YUY2:
290            yuv_RGB_to_YUY2((UINT16 *)surfptr, window->yuv_ovl_width, window);
585            yuv_RGB_to_YUY2((UINT16 *)sdl->yuv_bitmap, sdl, surfptr, pitch);
291586            break;
292587         case VIDEO_YUV_MODE_YUY2X2:
293            yuv_RGB_to_YUY2X2((UINT16 *)surfptr, window->yuv_ovl_width, window);
588            yuv_RGB_to_YUY2X2((UINT16 *)sdl->yuv_bitmap, sdl, surfptr, pitch);
294589            break;
295590      }
296591   }
592
297593   osd_lock_release(window->primlist->lock);
298594
299595   // unlock and flip
300   if (SDL_MUSTLOCK(window->sdlsurf)) SDL_UnlockSurface(window->sdlsurf);
596#if (!SDL_VERSION_ATLEAST(1,3,0))
597   if (SDL_MUSTLOCK(sdl->sdlsurf)) SDL_UnlockSurface(sdl->sdlsurf);
598   if (video_config.yuv_mode == VIDEO_YUV_MODE_NONE)
599   {
600      SDL_Flip(sdl->sdlsurf);
601   }
602   else
603   {
604      SDL_Rect r;
301605
606      SDL_UnlockYUVOverlay(sdl->yuvsurf);
607      r.x=hofs;
608      r.y=vofs;
609      r.w=blitwidth;
610      r.h=blitheight;
611      SDL_DisplayYUVOverlay(sdl->yuvsurf, &r);
612   }
613#else
614   SDL_UnlockTexture(sdl->texture_id);
302615   if (video_config.yuv_mode == VIDEO_YUV_MODE_NONE)
303      SDL_Flip(window->sdlsurf);
616   {
617      //SDL_UpdateTexture(sdl->sdltex, NULL, sdl->sdlsurf->pixels, pitch);
618      SDL_RenderCopy(sdl->texture_id, NULL, NULL);
619      SDL_RenderPresent();
620   }
304621   else
305622   {
306      SDL_UnlockYUVOverlay(window->yuvsurf);
623      SDL_Rect r;
307624      r.x=hofs;
308625      r.y=vofs;
309626      r.w=blitwidth;
310627      r.h=blitheight;
311      SDL_DisplayYUVOverlay(window->yuvsurf, &r);
628      //SDL_UpdateTexture(sdl->sdltex, NULL, sdl->sdlsurf->pixels, pitch);
629      SDL_RenderCopy(sdl->texture_id, NULL, &r);
630      SDL_RenderPresent();
312631   }
632#endif
313633   return 0;
314634}
315635
316
317636//============================================================
318637//  SOFTWARE RENDERING
319638//============================================================
r2959r2960
403722#define YMASK  (Y1MASK|Y2MASK)
404723#define UVMASK (UMASK|VMASK)
405724
406static void yuv_lookup_set(sdl_window_info *window, unsigned int pen, unsigned char red,
725static void yuv_lookup_set(sdl_info *sdl, unsigned int pen, unsigned char red,
407726         unsigned char green, unsigned char blue)
408727{
409728   UINT32 y,u,v;
r2959r2960
412731
413732   /* Storing this data in YUYV order simplifies using the data for
414733      YUY2, both with and without smoothing... */
415   window->yuv_lookup[pen]=(y<<Y1SHIFT)|(u<<USHIFT)|(y<<Y2SHIFT)|(v<<VSHIFT);
734   sdl->yuv_lookup[pen]=(y<<Y1SHIFT)|(u<<USHIFT)|(y<<Y2SHIFT)|(v<<VSHIFT);
416735}
417736
418static void drawsdl_yuv_init(sdl_window_info *window)
737static void drawsdl_yuv_init(sdl_info *sdl)
419738{
420739   unsigned char r,g,b;
421   if (window->yuv_lookup == NULL)
422      window->yuv_lookup = malloc_or_die(65536*sizeof(UINT32));
740   if (sdl->yuv_lookup == NULL)
741      sdl->yuv_lookup = malloc_or_die(65536*sizeof(UINT32));
423742   for (r = 0; r < 32; r++)
424743      for (g = 0; g < 32; g++)
425744         for (b = 0; b < 32; b++)
426745         {
427746            int idx = (r << 10) | (g << 5) | b;
428            yuv_lookup_set(window, idx,
747            yuv_lookup_set(sdl, idx,
429748               (r << 3) | (r >> 2),
430749               (g << 3) | (g >> 2),
431750               (b << 3) | (b >> 2));
432751         }
433752}
434753
435static void yuv_RGB_to_YV12(UINT16 *bitmap, int bw, sdl_window_info *window)
754static void yuv_RGB_to_YV12(UINT16 *bitmap, sdl_info *sdl, UINT8 *ptr, int pitch)
436755{
437756   int x, y;
438757   UINT8 *dest_y;
r2959r2960
440759   UINT8 *dest_v;
441760   UINT16 *src;
442761   UINT16 *src2;
443   UINT32 *lookup = window->yuv_lookup;
444   int yuv_pitch = window->yuvsurf->pitches[0];
762   UINT32 *lookup = sdl->yuv_lookup;
763   UINT8 *pixels[3];
445764   int u1,v1,y1,u2,v2,y2,u3,v3,y3,u4,v4,y4;     /* 12 */
446     
447   for(y=0;y<window->yuv_ovl_height;y+=2)
765   
766   pixels[0] = ptr;
767   pixels[1] = ptr + pitch * sdl->yuv_ovl_height;
768   pixels[2] = pixels[1] + pitch * sdl->yuv_ovl_height / 4;
769     
770   for(y=0;y<sdl->yuv_ovl_height;y+=2)
448771   {
449      src=bitmap + (y * bw) ;
450      src2=src + bw;
772      src=bitmap + (y * sdl->yuv_ovl_width) ;
773      src2=src + sdl->yuv_ovl_width;
451774
452      dest_y = window->yuvsurf->pixels[0] + y * window->yuvsurf->pitches[0];
453      dest_v = window->yuvsurf->pixels[1] + (y>>1) * window->yuvsurf->pitches[1];
454      dest_u = window->yuvsurf->pixels[2] + (y>>1) * window->yuvsurf->pitches[2];
775      dest_y = pixels[0] + y * pitch;
776      dest_v = pixels[1] + (y>>1) * pitch / 2;
777      dest_u = pixels[2] + (y>>1) * pitch / 2;
455778
456      for(x=0;x<window->yuv_ovl_width;x+=2)
779      for(x=0;x<sdl->yuv_ovl_width;x+=2)
457780      {
458781         v1 = lookup[src[x]];
459782         y1 = (v1>>Y1SHIFT) & 0xff;
r2959r2960
476799         v4 = (v4>>VSHIFT)  & 0xff;
477800
478801         dest_y[x] = y1;
479         dest_y[x+yuv_pitch] = y3;
802         dest_y[x+pitch] = y3;
480803         dest_y[x+1] = y2;
481         dest_y[x+yuv_pitch+1] = y4;
804         dest_y[x+pitch+1] = y4;
482805
483806         dest_u[x>>1] = (u1+u2+u3+u4)/4;
484807         dest_v[x>>1] = (v1+v2+v3+v4)/4;
r2959r2960
487810   }
488811}
489812
490static void yuv_RGB_to_YV12X2(UINT16 *bitmap, int bw, sdl_window_info *window)
813static void yuv_RGB_to_YV12X2(UINT16 *bitmap, sdl_info *sdl, UINT8 *ptr, int pitch)
491814{     
492815   /* this one is used when scale==2 */
493816   unsigned int x,y;
r2959r2960
495818   UINT8 *dest_u;
496819   UINT8 *dest_v;
497820   UINT16 *src;
498   int yuv_pitch = window->yuvsurf->pitches[0];
499821   int u1,v1,y1;
822   UINT8 *pixels[3];
500823
501   for(y=0;y<window->yuv_ovl_height;y++)
824   pixels[0] = ptr;
825   pixels[1] = ptr + pitch * sdl->yuv_ovl_height * 2;
826   pixels[2] = pixels[1] + pitch * sdl->yuv_ovl_height / 2;
827
828   for(y=0;y<sdl->yuv_ovl_height;y++)
502829   {
503      src=bitmap + (y * bw) ;
830      src = bitmap + (y * sdl->yuv_ovl_width) ;
504831
505      dest_y = (UINT16 *)(window->yuvsurf->pixels[0] + 2*y * window->yuvsurf->pitches[0]);
506      dest_v = window->yuvsurf->pixels[1] + y * window->yuvsurf->pitches[1];
507      dest_u = window->yuvsurf->pixels[2] + y * window->yuvsurf->pitches[2];
508      for(x=0;x<window->yuv_ovl_width;x++)
832      dest_y = (UINT16 *)(pixels[0] + 2 * y * pitch);
833      dest_v = pixels[1] + y * pitch / 2;
834      dest_u = pixels[2] + y * pitch / 2;
835      for(x=0;x<sdl->yuv_ovl_width;x++)
509836      {
510         v1 = window->yuv_lookup[src[x]];
511         y1 = (v1>>Y1SHIFT) & 0xff;
512         u1 = (v1>>USHIFT)  & 0xff;
513         v1 = (v1>>VSHIFT)  & 0xff;
837         v1 = sdl->yuv_lookup[src[x]];
838         y1 = (v1 >> Y1SHIFT) & 0xff;
839         u1 = (v1 >> USHIFT)  & 0xff;
840         v1 = (v1 >> VSHIFT)  & 0xff;
514841
515         dest_y[x+yuv_pitch/2]=y1<<8|y1;
516         dest_y[x]=y1<<8|y1;
842         dest_y[x + pitch/2] = y1 << 8 | y1;
843         dest_y[x] = y1 << 8 | y1;
517844         dest_u[x] = u1;
518845         dest_v[x] = v1;
519846      }
520847   }
521848}
522849
523static void yuv_RGB_to_YUY2(UINT16 *bitmap, int bw, sdl_window_info *window)
850static void yuv_RGB_to_YUY2(UINT16 *bitmap, sdl_info *sdl, UINT8 *ptr, int pitch)
524851{     
525852   /* this one is used when scale==2 */
526853   unsigned int y;
r2959r2960
528855   UINT16 *src;
529856   UINT16 *end;
530857   UINT32 p1,p2,uv;
531   UINT32 *lookup = window->yuv_lookup;
532   int yuv_pitch = window->yuvsurf->pitches[0]/4;
858   UINT32 *lookup = sdl->yuv_lookup;
859   int yuv_pitch = pitch/4;
533860
534   for(y=0;y<window->yuv_ovl_height;y++)
861   for(y=0;y<sdl->yuv_ovl_height;y++)
535862   {
536      src=bitmap + (y * bw) ;
537      end=src+window->yuv_ovl_width;
863      src=bitmap + (y * sdl->yuv_ovl_width) ;
864      end=src+sdl->yuv_ovl_width;
538865
539      dest = (UINT32 *) window->yuvsurf->pixels[0];
866      dest = (UINT32 *) ptr;
540867      dest += y * yuv_pitch;
541868      for(; src<end; src+=2)
542869      {
r2959r2960
549876   }
550877}
551878
552static void yuv_RGB_to_YUY2X2(UINT16 *bitmap, int bw, sdl_window_info *window)
879static void yuv_RGB_to_YUY2X2(UINT16 *bitmap, sdl_info *sdl, UINT8 *ptr, int pitch)
553880{     
554881   /* this one is used when scale==2 */
555882   unsigned int y;
556883   UINT32 *dest;
557884   UINT16 *src;
558885   UINT16 *end;
559   UINT32 *lookup = window->yuv_lookup;
560   int yuv_pitch = window->yuvsurf->pitches[0]/4;
886   UINT32 *lookup = sdl->yuv_lookup;
887   int yuv_pitch = pitch / 4;
561888
562   for(y=0;y<window->yuv_ovl_height;y++)
889   for(y=0;y<sdl->yuv_ovl_height;y++)
563890   {
564      src=bitmap + (y * bw) ;
565      end=src+window->yuv_ovl_width;
891      src=bitmap + (y * sdl->yuv_ovl_width) ;
892      end=src+sdl->yuv_ovl_width;
566893
567      dest = (UINT32 *) window->yuvsurf->pixels[0];
894      dest = (UINT32 *) ptr;
568895      dest += (y * yuv_pitch);
569896      for(; src<end; src++)
570897      {
src/osd/sdl/input.h
r2959r2960
1212#ifndef __INPUT_H
1313#define __INPUT_H
1414
15#include "window.h"
1516
1617//============================================================
1718//  PROTOTYPES
r2959r2960
1920
2021void sdlinput_init(running_machine *machine);
2122void sdlinput_poll(running_machine *machine);
22int  sdlinput_should_hide_mouse(void);
23int  sdlinput_should_hide_mouse(running_machine *machine);
2324
24#ifdef SDLMAME_WIN32
25void  sdlinput_process_events_buf(void);
26#endif
25sdl_window_info *sdlinput_get_focus_window(running_machine *machine);
2726
27void  sdlinput_process_events_buf(running_machine *machine);
28
2829#endif /* __INPUT_H */
src/osd/sdl/video.c
r2959r2960
5454
5555#include "osd_opengl.h"
5656
57#include "uiinput.h"
58
5759#ifdef MESS
5860#include "menu.h"
5961#endif
r2959r2960
186188   #if defined(SDLMAME_WIN32)   // Win32 version
187189   MONITORINFOEX info;
188190   info.cbSize = sizeof(info);   
189        GetMonitorInfo((HMONITOR)monitor->handle, (LPMONITORINFO)&info);
191    GetMonitorInfo((HMONITOR)monitor->handle, (LPMONITORINFO)&info);
190192   monitor->center_width = monitor->monitor_width = info.rcMonitor.right - info.rcMonitor.left;
191193   monitor->center_height = monitor->monitor_height = info.rcMonitor.bottom - info.rcMonitor.top;
192194   strcpy(monitor->monitor_device, info.szDevice);
195   #elif (SDL_VERSION_ATLEAST(1,3,0))
196   SDL_DisplayMode dmode;
197   
198   SDL_SelectVideoDisplay(monitor->handle);
199   SDL_GetDesktopDisplayMode(&dmode);
200   monitor->monitor_width = dmode.w;
201   monitor->monitor_height = dmode.h;
202   monitor->center_width = dmode.w;
203   monitor->center_height = dmode.h;
193204   #elif defined(SDLMAME_MACOSX)   // Mac OS X Core Imaging version
194205   CGDirectDisplayID primary;
195206   CGRect dbounds;
r2959r2960
204215    #elif defined(SDLMAME_X11) || defined(SDLMAME_NO_X11)       // X11 version
205216   {
206217      #if defined(SDLMAME_X11)
207      //FIXME: The code below fails for SDL1.3
208      #if (!SDL_VERSION_ATLEAST(1,3,0))
209218      // X11 version
210219      int screen;
211220      SDL_SysWMinfo info;
r2959r2960
237246         }
238247      }
239248       else
240      #endif
241       #endif
249      #endif // defined(SDLMAME_X11)
242250      {
243251         static int first_call=0;
244252         static int cw, ch;
r2959r2960
251259           
252260            sdl_vi = SDL_GetVideoInfo();
253261            #if (SDL_VERSION_ATLEAST(1,2,10))
254            //FIXME: File a bug for SDL 1.3
255            #if (SDL_VERSION_ATLEAST(1,3,0))
256            cw = 0;
257            ch = 0;
258            #else
259262            cw = sdl_vi->current_w;
260263            ch = sdl_vi->current_h;
261264            #endif
262            #endif
263265            first_call=1;
264266            if ((cw==0) || (ch==0))
265267            {
r2959r2960
293295   #endif
294296
295297   {
298      //FIXME: Code not really suitable for multiple monitors
296299      static int info_shown=0;
297300      if (!info_shown)
298301      {
r2959r2960
350353   {
351354      profiler_mark(PROFILER_BLIT);
352355      for (window = sdl_window_list; window != NULL; window = window->next)
353         sdlwindow_video_window_update(window);
356         sdlwindow_video_window_update(machine, window);
354357      profiler_mark(PROFILER_END);
355358   }
356359
r2959r2960
365368//============================================================
366369//  add_primary_monitor
367370//============================================================
368#ifndef SDLMAME_WIN32
371#if !defined(SDLMAME_WIN32) && !(SDL_VERSION_ATLEAST(1,3,0))
369372static void add_primary_monitor(void *data)
370373{
371374   sdl_monitor_info ***tailptr = (sdl_monitor_info ***)data;
r2959r2960
448451
449452   #ifdef SDLMAME_WIN32
450453   EnumDisplayMonitors(NULL, NULL, monitor_enum_callback, (LPARAM)&tailptr);
454   #elif (SDL_VERSION_ATLEAST(1,3,0))
455   {
456      int i;
457
458      for (i = 0; i < SDL_GetNumVideoDisplays(); i++)
459      {
460         sdl_monitor_info *monitor;
461          SDL_DisplayMode dmode;
462
463         // allocate a new monitor info
464         monitor = malloc_or_die(sizeof(*monitor));
465         memset(monitor, 0, sizeof(*monitor));
466
467         snprintf(monitor->monitor_device, sizeof(monitor->monitor_device)-1, "%s%d", SDLOPTION_SCREEN(""),i);
468       
469         SDL_GetDesktopDisplayMode(&dmode);
470         monitor->monitor_width = dmode.w;
471         monitor->monitor_height = dmode.h;
472         monitor->center_width = dmode.w;
473         monitor->center_height = dmode.h;
474           monitor->handle = i;
475           // guess the aspect ratio assuming square pixels
476           monitor->aspect = (float)(dmode.w) / (float)(dmode.h);
477           mame_printf_verbose("Adding monitor %s (%d x %d)\n", monitor->monitor_device, dmode.w, dmode.h);
478           
479           // save the primary monitor handle
480           if (i == 0)
481              primary_monitor = monitor;
482
483         // hook us into the list
484         *tailptr = monitor;
485         tailptr = &monitor->next;
486      }
487   }
451488   #else
452489   add_primary_monitor((void *)&tailptr);
453490   #endif
r2959r2960
457494//  pick_monitor
458495//============================================================
459496
497#if (SDL_VERSION_ATLEAST(1,3,0)) || defined(SDLMAME_WIN32)
460498static sdl_monitor_info *pick_monitor(int index)
461499{
462500   sdl_monitor_info *monitor;
463   #if SDL_MULTIMON || defined(SDLMAME_WIN32)
464501   const char *scrname;
465502   int moncount = 0;
466   #endif
467503   char option[20];
468504   float aspect;
469505
470506   // get the screen option
471   #if SDL_MULTIMON || defined(SDLMAME_WIN32)
472507   sprintf(option, SDLOPTION_SCREEN("%d"), index);
473508   scrname = options_get_string(mame_options(), option);
474   #endif
475509
476510   // get the aspect ratio
477511   sprintf(option, SDLOPTION_ASPECT("%d"), index);
478512   aspect = get_aspect(option, TRUE);
479513
480514   // look for a match in the name first
481   #if SDL_MULTIMON || defined(SDLMAME_WIN32)
482515   if (scrname != NULL)
483                for (monitor = sdl_monitor_list; monitor != NULL; monitor = monitor->next)
484      {
516      for (monitor = sdl_monitor_list; monitor != NULL; monitor = monitor->next)
517      {   
485518         moncount++;
486519         if (strcmp(scrname, monitor->monitor_device) == 0)
487520            goto finishit;
r2959r2960
489522
490523   // didn't find it; alternate monitors until we hit the jackpot
491524   index %= moncount;
492        for (monitor = sdl_monitor_list; monitor != NULL; monitor = monitor->next)
525    for (monitor = sdl_monitor_list; monitor != NULL; monitor = monitor->next)
493526      if (index-- == 0)
494527         goto finishit;
495   #endif
496528
497529   // return the primary just in case all else fails
498530   monitor = primary_monitor;
499531
500#if SDL_MULTIMON || defined(SDLMAME_WIN32)
501532finishit:
502#endif
503533   if (aspect != 0)
504534   {
505535      monitor->aspect = aspect;
506536   }
507537   return monitor;
508538}
539#else
540static sdl_monitor_info *pick_monitor(int index)
541{
542   sdl_monitor_info *monitor;
543   char option[20];
544   float aspect;
509545
546   // get the aspect ratio
547   sprintf(option, SDLOPTION_ASPECT("%d"), index);
548   aspect = get_aspect(option, TRUE);
549
550   // return the primary just in case all else fails
551   monitor = primary_monitor;
552
553   if (aspect != 0)
554   {
555      monitor->aspect = aspect;
556   }
557   return monitor;
558}
559#endif
560
510561//============================================================
511562//  check_osd_inputs
512563//============================================================
513564
514565static void check_osd_inputs(running_machine *machine)
515566{
516   sdl_window_info *window = sdl_window_list;
567   sdl_window_info *window = sdlinput_get_focus_window(machine);
517568
518569   // check for toggling fullscreen mode
519   if (input_ui_pressed(machine, IPT_OSD_1))
520      sdlwindow_toggle_full_screen(window);
570   if (ui_input_pressed(machine, IPT_OSD_1))
571      sdlwindow_toggle_full_screen(machine, window);
521572   
522   if (input_ui_pressed(machine, IPT_OSD_2))
573   if (ui_input_pressed(machine, IPT_OSD_2))
523574   {
524575      video_config.fullstretch = !video_config.fullstretch;
525576      ui_popup_time(1, "Uneven stretch %s", video_config.fullstretch? "enabled":"disabled");
526577   }
527578   
528   if (input_ui_pressed(machine, IPT_OSD_4))
579   if (ui_input_pressed(machine, IPT_OSD_4))
529580   {
530581      video_config.keepaspect = !video_config.keepaspect;
531582      ui_popup_time(1, "Keepaspect %s", video_config.keepaspect? "enabled":"disabled");
532583   }
533584   
534#if USE_OPENGL
535   if (input_ui_pressed(machine, IPT_OSD_5))
585   if (USE_OPENGL)
536586   {
537      video_config.filter = !video_config.filter;
538      ui_popup_time(1, "Filter %s", video_config.filter? "enabled":"disabled");
587      if (ui_input_pressed(machine, IPT_OSD_5))
588      {
589         video_config.filter = !video_config.filter;
590         ui_popup_time(1, "Filter %s", video_config.filter? "enabled":"disabled");
591      }
539592   }
540#endif
541593
542   if (input_ui_pressed(machine, IPT_OSD_6))
543      sdlwindow_modify_prescale(window, -1);
594   if (ui_input_pressed(machine, IPT_OSD_6))
595      sdlwindow_modify_prescale(machine, window, -1);
544596
545   if (input_ui_pressed(machine, IPT_OSD_7))
546      sdlwindow_modify_prescale(window, 1);
597   if (ui_input_pressed(machine, IPT_OSD_7))
598      sdlwindow_modify_prescale(machine, window, 1);
547599
548   if (input_ui_pressed(machine, IPT_OSD_8))
549      sdlwindow_modify_effect(window, -1);
600   if (ui_input_pressed(machine, IPT_OSD_8))
601      sdlwindow_modify_effect(machine, window, -1);
550602
551   if (input_ui_pressed(machine, IPT_OSD_9))
552      sdlwindow_modify_effect(window, 1);
603   if (ui_input_pressed(machine, IPT_OSD_9))
604      sdlwindow_modify_effect(machine, window, 1);
553605
554   if (input_ui_pressed(machine, IPT_OSD_10))
555      sdlwindow_toggle_draw(window);
606   if (ui_input_pressed(machine, IPT_OSD_10))
607      sdlwindow_toggle_draw(machine, window);
556608}
557609
558610
r2959r2960
605657      if (options_get_int(mame_options(), OPTION_SECONDS_TO_RUN) == 0)
606658         mame_printf_warning("Warning: -video none doesn't make much sense without -seconds_to_run\n");
607659   }
608#if USE_OPENGL
609   else if (strcmp(stemp, SDLOPTVAL_OPENGL) == 0)
660   else if (USE_OPENGL && (strcmp(stemp, SDLOPTVAL_OPENGL) == 0))
610661      video_config.mode = VIDEO_MODE_OPENGL;
611   else if (strcmp(stemp, SDLOPTVAL_OPENGL16) == 0)
662   else if (USE_OPENGL && (strcmp(stemp, SDLOPTVAL_OPENGL16) == 0))
612663   {
613664       video_config.mode = VIDEO_MODE_OPENGL;
614665       video_config.prefer16bpp_tex = 1;
615666   }
616#endif
617667   else
618668   {
619669      mame_printf_warning("Invalid video value %s; reverting to software\n", stemp);
r2959r2960
717767   // misc options: sanity check values
718768
719769   // global options: sanity check values
770#if (!SDL_VERSION_ATLEAST(1,3,0))
720771   if (video_config.numscreens < 1 || video_config.numscreens > 1) //MAX_VIDEO_WINDOWS)
721772   {
722773      mame_printf_warning("Invalid numscreens value %d; reverting to 1\n", video_config.numscreens);
723774      video_config.numscreens = 1;
724775   }
725
776#else
777   if (video_config.numscreens < 1 || video_config.numscreens > MAX_VIDEO_WINDOWS)
778   {
779      mame_printf_warning("Invalid numscreens value %d; reverting to 1\n", video_config.numscreens);
780      video_config.numscreens = 1;
781   }
782#endif
726783   // yuv settings ...
727784   stemp = options_get_string(mame_options(), SDLOPTION_YUVMODE);
728785   if (strcmp(stemp, SDLOPTVAL_NONE) == 0)
src/osd/sdl/window.c
r2959r2960
9191//============================================================
9292
9393static sdl_window_info **last_window_ptr;
94static int shown_video_info = 0;
9594
9695// event handling
9796static int multithreading_enabled;
9897static osd_work_queue *work_queue;
9998static int main_threadid;
10099static int window_threadid;
101static int dll_loaded;
102100
103101static const char *yuv_mode_names[] = { "none", "yv12", "yv12x2", "yuy2", "yuy2x2" };
104102
r2959r2960
111109struct _worker_param {
112110   sdl_window_info *window;
113111   const render_primitive_list *list;
112   running_machine *machine;
114113   int resize_new_width;
115114   int resize_new_height;
116   int times;
117115};
118116
119117
r2959r2960
127125static OSDWORK_CALLBACK( sdlwindow_video_window_destroy_wt );
128126static OSDWORK_CALLBACK( sdlwindow_resize_wt );
129127static OSDWORK_CALLBACK( sdlwindow_toggle_full_screen_wt );
130static void sdlwindow_clear_surface(sdl_window_info *window, int times);
131static void sdlwindow_update_cursor_state(void);
128static void sdlwindow_clear_surface(sdl_window_info *window);
129static void sdlwindow_update_cursor_state(running_machine *machine, sdl_window_info *window);
132130static void sdlwindow_sync(void);
133131
134
135132static void get_min_bounds(sdl_window_info *window, int *window_width, int *window_height, int constrain);
136133static void get_max_bounds(sdl_window_info *window, int *window_width, int *window_height, int constrain);
137134
r2959r2960
146143{
147144   wp->window=NULL;
148145   wp->list=NULL;
146   wp->machine=NULL;
149147   wp->resize_new_width=0;
150148   wp->resize_new_height=0;
151   wp->times=0;
152149}
153150
154151//============================================================
r2959r2960
190187{
191188   window_threadid = SDL_ThreadID();
192189
193   #ifdef SDLMAME_WIN32
194   if (SDL_Init(SDL_INIT_TIMER|SDL_INIT_AUDIO| SDL_INIT_VIDEO| SDL_INIT_JOYSTICK|SDL_INIT_NOPARACHUTE)) {
195      mame_printf_error("Could not initialize SDL: %s.\n", SDL_GetError());
196      exit(-1);
190   if (SDLMAME_INIT_IN_WORKER_THREAD)
191   {
192      if (SDL_Init(SDL_INIT_TIMER|SDL_INIT_AUDIO| SDL_INIT_VIDEO| SDL_INIT_JOYSTICK|SDL_INIT_NOPARACHUTE))
193      {
194         mame_printf_error("Could not initialize SDL: %s.\n", SDL_GetError());
195         exit(-1);
196      }
197197   }
198   #endif
199198   return NULL;
200199}
201200
r2959r2960
251250
252251   // set up the window list
253252   last_window_ptr = &sdl_window_list;
254   dll_loaded = 0;
255253   return 0;
256254}
257255
r2959r2960
274272//  (main thread)
275273//============================================================
276274
277#ifdef SDLMAME_WIN32
278275static OSDWORK_CALLBACK( sdlwindow_exit_wt )
279276{
280   SDL_Quit();
277   if (SDLMAME_INIT_IN_WORKER_THREAD)
278      SDL_Quit();
279   
280   free(param);
281281   return NULL;
282282}
283#endif
284283
285284static void sdlwindow_exit(running_machine *machine)
286285{
r2959r2960
303302   // kill the drawers
304303   (*draw.exit)();
305304
306   #ifdef SDLMAME_WIN32
307305   execute_async_wait(&sdlwindow_exit_wt, NULL);
308   #endif
306
309307   if (multithreading_enabled)
310308   {
311309      osd_work_queue_wait(work_queue, 100000);
r2959r2960
327325
328326void sdlwindow_blit_surface_size(sdl_window_info *window, int window_width, int window_height)
329327{
330   sdl_info *sdl = window->dxdata;
331328   INT32 newwidth, newheight;
332   int xscale, yscale;
329   int xscale = 1, yscale = 1;
333330   float desired_aspect = 1.0f;
334331   INT32 target_width = window_width;
335332   INT32 target_height = window_height;
r2959r2960
346343      desired_aspect = (float)target_width / (float)target_height;
347344   }
348345
349//   logerror("Render target wants %d x %d, minimum is %d x %d\n", target_width, target_height, newwidth, newheight);
350
351        // don't allow below 1:1 size - this prevents the OutRunners "death spiral"
352        // that would occur if you kept rotating it with fullstretch on in SDLMAME u10 test 2.
353        if ((target_width >= newwidth) && (target_height >= newheight))
354   {
355                newwidth = target_width;
356                newheight = target_height;
357   }
358
359346        // non-integer scaling - often gives more pleasing results in full screen
360347        if (!video_config.fullstretch)
361348   {
r2959r2960
397384      newwidth *= xscale;
398385      newheight *= yscale;
399386   }
387   else
388   {
389      newwidth = target_width;
390      newheight = target_height;
391   }
400392
401393   if ((render_target_get_layer_config(window->target) & LAYER_CONFIG_ZOOM_TO_SCREEN)
402394      && video_config.yuv_mode == VIDEO_YUV_MODE_NONE)
403395      newwidth = window_width;
404396
405   if (((sdl->blitwidth != newwidth) || (sdl->blitheight != newheight)) && !(video_config.mode == VIDEO_MODE_OPENGL) && (window->sdlsurf))
406   {
407      sdlwindow_clear_surface(window, 3);
408   }
409
410   sdl->blitwidth = newwidth;
411   sdl->blitheight = newheight;
397   if ((window->blitwidth != newwidth) || (window->blitheight != newheight))
398      sdlwindow_clear_surface(window);
399   
400   window->blitwidth = newwidth;
401   window->blitheight = newheight;
412402}
413403
414//============================================================
415//  yuv_overlay_init
416//============================================================
417404
418static void yuv_overlay_init(sdl_window_info *window)
419{
420   int minimum_width, minimum_height;
421
422   render_target_get_minimum_size(window->target, &minimum_width, &minimum_height);
423   if (window->yuvsurf != NULL)
424      SDL_FreeYUVOverlay(window->yuvsurf);
425   if (window->yuv_bitmap != NULL)
426   {
427      free(window->yuv_bitmap);   
428   }
429   window->yuv_bitmap = malloc_or_die(minimum_width*minimum_height*sizeof(UINT16));
430
431   mame_printf_verbose("SDL: Creating YUV-Overlay ...\n");
432   switch (video_config.yuv_mode)
433   {
434      case VIDEO_YUV_MODE_YV12:
435         window->yuvsurf = SDL_CreateYUVOverlay(minimum_width, minimum_height,
436                 SDL_YV12_OVERLAY, window->sdlsurf);
437         break;
438      case VIDEO_YUV_MODE_YV12X2:
439         window->yuvsurf = SDL_CreateYUVOverlay(minimum_width*2, minimum_height*2,
440                  SDL_YV12_OVERLAY, window->sdlsurf);
441         break;
442      case VIDEO_YUV_MODE_YUY2:
443         window->yuvsurf = SDL_CreateYUVOverlay(minimum_width, minimum_height,
444                  SDL_YUY2_OVERLAY, window->sdlsurf);
445         break;
446      case VIDEO_YUV_MODE_YUY2X2:
447         window->yuvsurf = SDL_CreateYUVOverlay(minimum_width*2, minimum_height,
448                  SDL_YUY2_OVERLAY, window->sdlsurf);
449         break;
450   }
451   if ( window->yuvsurf == NULL ) {
452      mame_printf_error("SDL: Couldn't create SDL_yuv_overlay: %s\n", SDL_GetError());
453      //return 1;
454   }
455   window->yuv_ovl_width = minimum_width;
456   window->yuv_ovl_height = minimum_height;
457
458   if (!shown_video_info)
459   {
460      mame_printf_verbose("YUV Mode         : %s\n", yuv_mode_names[video_config.yuv_mode]);
461      mame_printf_verbose("YUV Overlay Size : %d x %d\n", minimum_width, minimum_height);
462      mame_printf_verbose("YUV Acceleration : %s\n", window->yuvsurf->hw_overlay ? "Hardware" : "Software");
463      shown_video_info = 1;
464   }
465}
466
467405//============================================================
468406//  sdlwindow_resize
469407//  (main thread)
r2959r2960
471409
472410static OSDWORK_CALLBACK( sdlwindow_resize_wt )
473411{
474   sdl_window_info *window = sdl_window_list;
475   worker_param *wp = (worker_param *) param;
412   worker_param *      wp = (worker_param *) param;
413   sdl_window_info *   window = wp->window;
476414
477415   ASSERT_WINDOW_THREAD();
478416   
479417   draw.window_destroy_all_textures(window);
418   draw.window_resize(window, wp->resize_new_width, wp->resize_new_height);
480419
481#if (!SDL_VERSION_ATLEAST(1,3,0))
482   SDL_FreeSurface(window->sdlsurf);
483#endif
484   //printf("SetVideoMode %d %d\n", wp->resize_new_width, wp->resize_new_height);
485   if (video_config.yuv_mode == VIDEO_YUV_MODE_NONE)
486      window->sdlsurf = SDL_SetVideoMode(wp->resize_new_width, wp->resize_new_height, 0, SDL_SWSURFACE |
487         SDL_DOUBLEBUF | SDL_ANYFORMAT | window->extra_flags);
488   else
489   {
490      window->sdlsurf = SDL_SetVideoMode(wp->resize_new_width, wp->resize_new_height, 0, SDL_HWSURFACE |
491         SDL_DOUBLEBUF | SDL_ANYFORMAT | window->extra_flags);
492      yuv_overlay_init(window);
493   }
494#if USE_OPENGL
495   if (video_config.mode == VIDEO_MODE_OPENGL)
496      drawogl_init_ogl_context();
497#endif
498420   sdlwindow_blit_surface_size(window, wp->resize_new_width, wp->resize_new_height);
421   
422   sdlwindow_clear_surface(window);
423
499424   free(wp);
500425   return NULL;
501426}
r2959r2960
506431
507432   ASSERT_MAIN_THREAD();
508433
509   if (width == window->sdlsurf->w && height == window->sdlsurf->h)
434   if (width == window->width && height == window->height)
510435      return;
511436   
512437   clear_worker_param(&wp);
513438   wp.resize_new_width = width;
514439   wp.resize_new_height = height;
440   wp.window = window;
515441   
516442   execute_async_wait(&sdlwindow_resize_wt, &wp);
517443}
r2959r2960
524450static OSDWORK_CALLBACK( sdlwindow_clear_surface_wt )
525451{
526452   worker_param *wp = (worker_param *) param;
527   //sdl_window_info *window = sdl_window_list;
528453   sdl_window_info *window = wp->window;
529   int i;
530454
531455   ASSERT_WINDOW_THREAD();
532456
533   for (i=0;i < wp->times; i++)
534   {
535      if (SDL_MUSTLOCK(window->sdlsurf)) SDL_LockSurface(window->sdlsurf);
536
537      memset(window->sdlsurf->pixels, 0, window->sdlsurf->h * window->sdlsurf->pitch);
538      if (SDL_MUSTLOCK(window->sdlsurf)) SDL_UnlockSurface(window->sdlsurf);
539
540      SDL_Flip(window->sdlsurf);
541   }
542
457   draw.window_clear(window);
543458   free(wp);
544459   return NULL;
545460}
546461
547static void sdlwindow_clear_surface(sdl_window_info *window, int times)
462static void sdlwindow_clear_surface(sdl_window_info *window)
548463{
549464   worker_param *wp = malloc(sizeof(worker_param));
550465
551466   clear_worker_param(wp);
552467   wp->window = window;
553   wp->times = times;
554468   
555469   if (SDL_ThreadID() == main_threadid)
556470   {
r2959r2960
580494   // If we are going fullscreen (leaving windowed) remember our windowed size
581495   if (!window->fullscreen)
582496   {
583      window->windowed_width = window->sdlsurf->w;
584      window->windowed_height = window->sdlsurf->h;
497      window->windowed_width = window->width;
498      window->windowed_height = window->height;
585499   }
586500
587   // toggle the window mode
588   video_config.windowed ^= 1;
589
590501   (*draw.window_destroy)(window);
591502
592   window->fullscreen = !video_config.windowed;
503   // toggle the window mode
504   window->fullscreen = !window->fullscreen;   
593505
594506   complete_create_wt(param, 0);
595507
596508   return NULL;
597509}
598510
599void sdlwindow_toggle_full_screen(sdl_window_info *window)
511void sdlwindow_toggle_full_screen(running_machine *machine, sdl_window_info *window)
600512{
601513   worker_param wp;
602514
r2959r2960
608520   execute_async_wait(&sdlwindow_toggle_full_screen_wt, &wp);
609521}
610522
611static void sdlwindow_modify_yuv(int dir)
523static void sdlwindow_modify_yuv(running_machine *machine, int dir)
612524{
613   sdl_window_info *window = sdl_window_list;
614525   int new_yuv_mode = video_config.yuv_mode;
526   sdl_window_info *window = sdlinput_get_focus_window(machine);
615527
616528   if (dir > 0 && video_config.yuv_mode < VIDEO_YUV_MODE_MAX)
617529      new_yuv_mode = video_config.yuv_mode + 1;
r2959r2960
623535      worker_param wp;
624536
625537      clear_worker_param(&wp);
626
627538      wp.window = window;
628
629539      execute_async_wait(&sdlwindow_video_window_destroy_wt, &wp);
630540         
631541      video_config.yuv_mode = new_yuv_mode;
632
633542      execute_async_wait(&complete_create_wt, &wp);
634543
635544      ui_popup_time(1, "YUV mode %s", yuv_mode_names[video_config.yuv_mode]);
r2959r2960
648557   return NULL;
649558}
650559
651void sdlwindow_modify_prescale(sdl_window_info *window, int dir)
560void sdlwindow_modify_prescale(running_machine *machine, sdl_window_info *window, int dir)
652561{
653562   worker_param wp;
654563   int new_prescale = video_config.prescale;
r2959r2960
664573   
665574   if (new_prescale != video_config.prescale)
666575   {
667      if (!video_config.windowed && video_config.switchres)
576      if (window->fullscreen && video_config.switchres)
668577      {
669578         execute_async_wait(&sdlwindow_video_window_destroy_wt, &wp);
670579         
r2959r2960
682591   }
683592}
684593
685void sdlwindow_modify_effect(sdl_window_info *window, int dir)
594void sdlwindow_modify_effect(running_machine *machine, sdl_window_info *window, int dir)
686595{
687596
688597   if (video_config.mode == VIDEO_MODE_SOFT)
689598   {
690      sdlwindow_modify_yuv(dir);
599      sdlwindow_modify_yuv(machine, dir);
691600      return;
692601   }
693602#if USE_OPENGL
r2959r2960
716625#endif
717626}
718627
719void sdlwindow_toggle_draw(sdl_window_info *window)
628void sdlwindow_toggle_draw(running_machine *machine, sdl_window_info *window)
720629{
721630#if USE_OPENGL
722631   worker_param wp;
r2959r2960
724633   // If we are not fullscreen (windowed) remember our windowed size
725634   if (!window->fullscreen)
726635   {
727      window->windowed_width = window->sdlsurf->w;
728      window->windowed_height = window->sdlsurf->h;
636      window->windowed_width = window->width;
637      window->windowed_height = window->height;
729638   }
730639
731640   clear_worker_param(&wp);
r2959r2960
757666//  (main or window thread)
758667//============================================================
759668
760static void sdlwindow_update_cursor_state(void)
669static void sdlwindow_update_cursor_state(running_machine *machine, sdl_window_info *window)
761670{
671#if (SDL_VERSION_ATLEAST(1,3,0))
762672   // do not do mouse capture if the debugger's enabled to avoid
763673   // the possibility of losing control
764674   if (!options_get_bool(mame_options(), OPTION_DEBUG))
765675   {
766      if (video_config.windowed && !sdlinput_should_hide_mouse())
676      if (!window->fullscreen && !sdlinput_should_hide_mouse(machine))
767677      {
768678         SDL_ShowCursor(SDL_ENABLE);
679         if (SDL_GetWindowGrab(window->window_id ))
680            SDL_SetWindowGrab(window->window_id, 0);
681      }
682      else
683      {
684         SDL_ShowCursor(SDL_DISABLE);
685         if (!SDL_GetWindowGrab(window->window_id))
686            SDL_SetWindowGrab(window->window_id, 1);
687      }
688   }
689#else
690   // do not do mouse capture if the debugger's enabled to avoid
691   // the possibility of losing control
692   if (!options_get_bool(mame_options(), OPTION_DEBUG))
693   {
694      if (!window->fullscreen && !sdlinput_should_hide_mouse(machine))
695      {
696         SDL_ShowCursor(SDL_ENABLE);
769697         if (SDL_WM_GrabInput(SDL_GRAB_QUERY))
770698         {
771699            SDL_WM_GrabInput(SDL_GRAB_OFF);
r2959r2960
780708         }
781709      }
782710   }
711#endif
783712}
784713
785714//============================================================
r2959r2960
871800
872801static OSDWORK_CALLBACK( sdlwindow_video_window_destroy_wt )
873802{
874   worker_param *wp = (worker_param *) param;
875   sdl_window_info *window = wp->window;
803   worker_param *      wp = (worker_param *) param;
804   sdl_window_info *   window = wp->window;
876805
877806   ASSERT_WINDOW_THREAD();
878807
879   if (window->sdlsurf)
880   {
881#if (!SDL_VERSION_ATLEAST(1,3,0))
882      // Will be done by SDL on next call to SetVideoMode
883      SDL_FreeSurface(window->sdlsurf);
884#endif
885      window->sdlsurf = NULL;
886   }
887
888808   // free the textures etc
889809   (*draw.window_destroy)(window);
890810
r2959r2960
953873      minimum_height -= 4;
954874   }
955875
876#if (SDL_VERSION_ATLEAST(1,3,0))
877   // FIXME: Mode switching not supported!
878   modes = NULL;
879#else
956880   modes = SDL_ListModes(NULL, SDL_FULLSCREEN | SDL_DOUBLEBUF);
957
881#endif
882   
958883   if (modes == (SDL_Rect **)0)
959884   {
960885      mame_printf_error("SDL: No modes available?!\n");
r2959r2960
999924}
1000925
1001926
1002
1003927//============================================================
1004928//  sdlwindow_video_window_update
1005929//  (main thread)
1006930//============================================================
1007931
1008void sdlwindow_video_window_update(sdl_window_info *window)
932void sdlwindow_video_window_update(running_machine *machine, sdl_window_info *window)
1009933{
1010934
1011935   ASSERT_MAIN_THREAD();
1012936
1013937   // adjust the cursor state
1014   sdlwindow_update_cursor_state();
938   sdlwindow_update_cursor_state(machine, window);
1015939
1016940   // if we're visible and running and not in the middle of a resize, draw
1017941   if (window->target != NULL)
r2959r2960
1027951         window->minheight = tempheight;
1028952         if (!window->fullscreen)
1029953         {
1030            sdl_info *sdl = window->dxdata;
1031            sdlwindow_blit_surface_size(window, window->sdlsurf->w, window->sdlsurf->h);
1032            sdlwindow_resize(window, sdl->blitwidth, sdl->blitheight);
954            sdlwindow_blit_surface_size(window, window->width, window->height);
955            sdlwindow_resize(window, window->blitwidth, window->blitheight);
1033956         }
1034957         else if (video_config.switchres)
1035958         {
1036959            pick_best_mode(window, &tempwidth, &tempheight);
1037960            sdlwindow_resize(window, tempwidth, tempheight);
1038961         }
1039
1040         if (video_config.yuv_mode != VIDEO_YUV_MODE_NONE)
1041         {
1042            yuv_overlay_init(window);
1043         }
1044962      }
1045
963     
1046964// this: 'osd_lock_acquire', just to 'see' if rendering was still happening
1047965// is invalid.
1048966// 'osd_lock_acquire' puts us to the waiting queue and we will miss to be in sync with real-time
r2959r2960
1068986         osd_lock_release(window->render_lock);
1069987
1070988         // ensure the target bounds are up-to-date, and then get the primitives
1071         primlist = (*draw.window_get_primitives)(window);
989         primlist = draw.window_get_primitives(window);
1072990
1073991         // and redraw now
1074992
1075993         wp.list = primlist;
1076994         wp.window = window;
995         wp.machine = machine;
1077996
1078997         execute_async(&draw_video_contents_wt, &wp);
1079998      }
r2959r2960
11051024   window->start_viewscreen=viewindex;
11061025}
11071026
1108
11091027//============================================================
11101028//  complete_create
11111029//  (window thread)
r2959r2960
11131031
11141032static OSDWORK_CALLBACK( complete_create_wt )
11151033{
1116   worker_param *wp = (worker_param *) param;
1117   sdl_window_info *window = wp->window;
1034   worker_param *      wp = (worker_param *) param;
1035   sdl_window_info *   window = wp->window;
1036   
11181037   int tempwidth, tempheight;
11191038   static int result[2] = {0,1};
11201039
r2959r2960
11231042
11241043   if (window->fullscreen)
11251044   {
1126
1127      window->extra_flags = SDL_FULLSCREEN;
11281045      // default to the current mode exactly
11291046      tempwidth = window->monitor->monitor_width;
11301047      tempheight = window->monitor->monitor_height;
r2959r2960
11351052   }
11361053   else if (window->windowed_width)
11371054   {
1138      window->extra_flags = SDL_RESIZABLE;
11391055      // if we have a remembered size force the new window size to it
11401056      tempwidth = window->windowed_width;
11411057      tempheight = window->windowed_height;
11421058   }
11431059   else
11441060   {
1145      window->extra_flags = SDL_RESIZABLE;
1146
11471061      if (window->startmaximized)
11481062      {
11491063         tempwidth = tempheight = 0;
r2959r2960
11621076      }
11631077   }
11641078
1165#ifndef NO_OPENGL
1166   if (video_config.mode  == VIDEO_MODE_OPENGL)
1167   {
1168      window->extra_flags |= SDL_OPENGL;
1169
1170       SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
1171     
1172      #if (SDL_VERSION_ATLEAST(1,2,10))
1173       #if (!SDL_VERSION_ATLEAST(1,3,0))
1174      if (options_get_bool(mame_options(), SDLOPTION_WAITVSYNC))
1175      {
1176         SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 1);
1177      }
1178      else
1179      {
1180         SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 0);
1181      }
1182      #endif
1183      #endif
1184   }
1185
1186#ifdef USE_DISPATCH_GL
1187   if ((video_config.mode  == VIDEO_MODE_OPENGL) && !dll_loaded)
1188   {
1189      /*
1190       *  directfb and and x11 use this env var
1191       *   SDL_VIDEO_GL_DRIVER
1192       */
1193      const char *e;
1194
1195      e=getenv(SDLENV_GL_LIB);
1196     
1197#ifdef SDLMAME_MACOSX
1198      /* Vas Crabb: Default GL-lib for MACOSX */
1199      if (!e)
1200         e = "/System/Library/Frameworks/OpenGL.framework/Libraries/libGL.dylib";
1201#endif
1202      if (SDL_GL_LoadLibrary(e) != 0) // Load library (default for e==NULL
1203      {
1204         fatalerror("Unable to load default library: %s\n", e);
1205      }
1206          mame_printf_verbose("Loaded opengl shared library: %s\n", e ? e : "<default>");
1207       gl_dispatch = auto_malloc(sizeof(osd_gl_dispatch));
1208        dll_loaded=1;
1209   }
1210#endif
1211#endif
1212   // create the SDL surface (which creates the window in windowed mode)
1213   if (video_config.yuv_mode == VIDEO_YUV_MODE_NONE)
1214      window->sdlsurf = SDL_SetVideoMode(tempwidth, tempheight,
1215                     0, SDL_SWSURFACE | SDL_DOUBLEBUF | SDL_ANYFORMAT | window->extra_flags);
1216   else
1217      window->sdlsurf = SDL_SetVideoMode(tempwidth, tempheight,
1218                  0, SDL_SWSURFACE | SDL_ANYFORMAT |window->extra_flags);
1219
1220   if (!window->sdlsurf)
1221      return (void *) &result[1];
1222     
1223   if ( (video_config.mode  == VIDEO_MODE_OPENGL) && !(window->sdlsurf->flags & SDL_OPENGL) )
1224   {
1225      fprintf(stderr, "OpenGL not supported on this driver!\n");
1226      return (void *) &result[1];
1227   }
1228
12291079   // initialize the drawing backend
1230   if ((*draw.window_init)(window))
1080   if ((*draw.window_create)(window, tempwidth, tempheight))
12311081      return (void *) &result[1];
12321082
1233   if (video_config.yuv_mode != VIDEO_YUV_MODE_NONE)
1234   {
1235      yuv_overlay_init(window);
1236   }
1237
1238   // set the window title
1239   SDL_WM_SetCaption(window->title, "SDLMAME");
1240
12411083   return (void *) &result[0];
12421084}
12431085
r2959r2960
12611103
12621104    return res;
12631105}
1264#endif
12651106
1266static OSDWORK_CALLBACK( draw_video_contents_wt )
1107static void measure_fps(sdl_window_info *window, UINT32 dc, int update)
12671108{
1268   #ifndef SDLMAME_WIN32
12691109   const unsigned long frames_skip4fps = 100;
12701110   static int64_t lastTime=0, sumdt=0, startTime=0;
12711111   static unsigned long frames = 0;
12721112   int64_t currentTime, t0;
12731113   double dt;
1274   #endif
1114   
1115   t0 = getusecs();
1116
1117   (*draw.window_draw)(window, dc, update);
1118
1119   frames++;
1120   currentTime = getusecs();
1121   if(startTime==0||frames==frames_skip4fps)
1122      startTime=currentTime;
1123   if( frames>=frames_skip4fps )
1124      sumdt+=currentTime-t0;
1125   if( (currentTime-lastTime)>1L*1000000L && frames>frames_skip4fps )
1126   {
1127      dt = (double)( ((currentTime-startTime)/10000L) ) / 100.0 ; // in decimale sec.
1128      mame_printf_info("%6.2lfs, %4lu F, "
1129             "avrg game: %5.2lf FPS %.2lf ms/f, "
1130             "avrg video: %5.2lf FPS %.2lf ms/f, "
1131             "last video: %5.2lf FPS %.2lf ms/f\n",
1132        dt, frames-frames_skip4fps,
1133        (double)(frames-frames_skip4fps)/dt,                             // avrg game fps
1134        ( (currentTime-startTime) / ((frames-frames_skip4fps)) ) /1000.0,
1135        (double)(frames-frames_skip4fps)/((double)(sumdt/10000L)/100.0), // avrg vid fps
1136        ( sumdt / ((frames-frames_skip4fps)) ) /1000.0,
1137        1.0/((currentTime-t0) / 1000000.0), // this vid fps
1138        (currentTime-t0) / 1000.0
1139      );
1140      lastTime = currentTime;
1141   }
1142}
1143#else
1144static void measure_fps(sdl_window_info *window, UINT32 dc, int update)
1145{
1146   (*draw.window_draw)(window, dc, update);
1147}
1148#endif
1149
1150static OSDWORK_CALLBACK( draw_video_contents_wt )
1151{
12751152   UINT32    dc =      0;
12761153   int    update =    1;
12771154   worker_param *wp = (worker_param *) param;
12781155   sdl_window_info *window = wp->window;
12791156   
12801157   ASSERT_REDRAW_THREAD();
1281   #ifdef SDLMAME_WIN32
1282   sdlinput_process_events_buf();
1283   #endif
1158   
1159   // Some configurations require events to be polled in the worker thread
1160   sdlinput_process_events_buf(wp->machine);
12841161
12851162   window->primlist = wp->list;
12861163   osd_lock_acquire(window->render_lock);
1287   if (window->sdlsurf)
1288   {
1289      // if no bitmap, just fill
1290      if (window->primlist == NULL)
1291      {
1292      }
12931164
1294      // otherwise, render with our drawing system
1295      else
1296      {
1297         #ifndef SDLMAME_WIN32
1298         if( video_config.perftest )
1299         {
1300            t0 = getusecs();
1301
1302            (*draw.window_draw)(window, dc, update);
1303
1304            frames++;
1305            currentTime = getusecs();
1306            if(startTime==0||frames==frames_skip4fps)
1307               startTime=currentTime;
1308            if( frames>=frames_skip4fps )
1309               sumdt+=currentTime-t0;
1310            if( (currentTime-lastTime)>1L*1000000L && frames>frames_skip4fps )
1311            {
1312               dt = (double)( ((currentTime-startTime)/10000L) ) / 100.0 ; // in decimale sec.
1313               mame_printf_info("%6.2lfs, %4lu F, "
1314                      "avrg game: %5.2lf FPS %.2lf ms/f, "
1315                      "avrg video: %5.2lf FPS %.2lf ms/f, "
1316                      "last video: %5.2lf FPS %.2lf ms/f\n",
1317                 dt, frames-frames_skip4fps,
1318                 (double)(frames-frames_skip4fps)/dt,                             // avrg game fps
1319                 ( (currentTime-startTime) / ((frames-frames_skip4fps)) ) /1000.0,
1320                 (double)(frames-frames_skip4fps)/((double)(sumdt/10000L)/100.0), // avrg vid fps
1321                 ( sumdt / ((frames-frames_skip4fps)) ) /1000.0,
1322                 1.0/((currentTime-t0) / 1000000.0), // this vid fps
1323                 (currentTime-t0) / 1000.0
1324               );
1325               lastTime = currentTime;
1326            }
1327         }
1328         else
1329         #endif
1330         {
1331            (*draw.window_draw)(window, dc, update);
1332         }
1333      }
1165   // if no bitmap, just fill
1166   if (window->primlist == NULL)
1167   {
13341168   }
1169   // otherwise, render with our drawing system
1170   else
1171   {
1172      if( video_config.perftest )
1173         measure_fps(window, dc, update);
1174      else
1175         (*draw.window_draw)(window, dc, update);
1176   }
13351177   osd_lock_release(window->render_lock);
13361178   free(wp);
13371179   
src/osd/sdl/testkeys.c
r2959r2960
2020
2121#include "unicode.h"
2222
23// Check whether SDL has compat interface
24#if defined(SDL_AllocSurface) || (!SDL_VERSION_ATLEAST(1,3,0))
25#define SDL_HAS_COMPAT       1
26#else
27#define SDL_HAS_COMPAT       0
28#endif
29
2330typedef struct _key_lookup_table key_lookup_table;
2431
2532struct _key_lookup_table
r2959r2960
2835   const char *name;
2936};
3037
38#if SDL_HAS_COMPAT
3139#if (SDL_VERSION_ATLEAST(1,3,0))
3240#define KE(x) { SDL_SCANCODE_ ## x, "SDL_SCANCODE_" #x },
3341#define KE8(A, B, C, D, E, F, G, H) KE(A) KE(B) KE(C) KE(D) KE(E) KE(F) KE(G) KE(H)
r2959r2960
3543#define KE5(A, B, C, D, E) KE(A) KE(B) KE(C) KE(D) KE(E)
3644#define KE3(A, B, C) KE(A) KE(B) KE(C)
3745
46
3847static key_lookup_table sdl_lookup[] =
3948{
4049   KE7(UNKNOWN,   BACKSPACE,   TAB,      CLEAR,      RETURN,      PAUSE,      ESCAPE      )
r2959r2960
110119   }
111120   return NULL;
112121}
122#endif // SDL_HAS_COMPAT
113123
114124#ifdef SDLMAME_WIN32
115125int utf8_main(int argc, char *argv[])
r2959r2960
117127int main(int argc, char *argv[])
118128#endif
119129{
130#if SDL_HAS_COMPAT
120131   SDL_Event event;
121132   int quit = 0;
122133   char buf[20];
r2959r2960
160171   }
161172   SDL_Quit();
162173   return(0);
174#else
175   printf("This SDL Version does not support 1.2 compatibility interface.\n");
176   return(1);
177#endif
163178}
164179
src/osd/sdl/video.h
r2959r2960
2121#define VIDEO_MODE_SOFT            (0)
2222#define VIDEO_MODE_OPENGL         (1)
2323
24#define SDL_MULTIMON            (0)
25
2624#define VIDEO_YUV_MODE_NONE         (0)
2725#define VIDEO_YUV_MODE_YV12         (1)
2826#define VIDEO_YUV_MODE_YV12X2      (2)
src/osd/sdl/window.h
r2959r2960
120120   // drawing data
121121   void *            dxdata;
122122
123   // SDL surface
124   SDL_Surface       *sdlsurf;
123   // cache of physical width and height
124   int               width;
125   int               height;
125126
126   // YUV overlay
127   SDL_Overlay       *yuvsurf;
128   int               yuv_ovl_width;
129   int               yuv_ovl_height;
130   UINT32             *yuv_lookup;
131   UINT16            *yuv_bitmap;
127   // current blitwidth and height
128   int               blitwidth;
129   int               blitheight;
132130
133131   int               totalColors;      // total colors from machine/sdl_window_config
134   int               initialized;      // is everything well initialized, i.e. all GL stuff etc.
135132   int               start_viewscreen;
136
137};
138
139/* sdl_info is the information about SDL for the current screen */
140typedef struct _sdl_info sdl_info;
141struct _sdl_info
142{
143   INT32            blitwidth, blitheight;   // current blit width/height values
144
145#if USE_OPENGL
146   // 3D info (GL mode only)
147   texture_info *   texlist;      // list of active textures
148   int            last_blendmode;      // previous blendmode
149   INT32            texture_max_width;        // texture maximum width
150   INT32            texture_max_height;       // texture maximum height
151   int            texpoweroftwo;           // must textures be power-of-2 sized?
152   int            usevbo;         // runtime check if VBO is available
153   int            usepbo;         // runtime check if PBO is available
154   int            usefbo;         // runtime check if FBO is available
155   int            useglsl;      // runtime check if GLSL is available
156   GLhandleARB      glsl_program[2*GLSL_SHADER_MAX];  // GLSL programs, or 0
157   int            glsl_program_num;   // number of GLSL programs
158   int            glsl_program_mb2sc;   // GLSL program idx, which transforms
159                                     // the mame-bitmap -> screen-bitmap (size/rotation/..)
160                              // All progs <= glsl_program_mb2sc using the mame bitmap
161                              // as input, otherwise the screen bitmap.
162                              // All progs >= glsl_program_mb2sc using the screen bitmap
163                              // as output, otherwise the mame bitmap.
164   int            glsl_vid_attributes;// glsl brightness, contrast and gamma for RGB bitmaps
165   int            usetexturerect;      // use ARB_texture_rectangle for non-power-of-2, general use
133#if (SDL_VERSION_ATLEAST(1,3,0))
134   // Needs to be here as well so we can identify window
135   SDL_WindowID      window_id;
166136#endif
167
168   int            totalColors;      // total colors from machine/sdl_window_config/sdl_window_info
169137};
170138
171139typedef struct _sdl_draw_callbacks sdl_draw_callbacks;
r2959r2960
173141{
174142   void (*exit)(void);
175143
176   int (*window_init)(sdl_window_info *window);
177   const render_primitive_list *(*window_get_primitives)(sdl_window_info *window);
144   int (*window_create)(sdl_window_info *window, int width, int height);
145   void (*window_resize)(sdl_window_info *window, int width, int height);
178146   int (*window_draw)(sdl_window_info *window, UINT32 dc, int update);
147   const render_primitive_list *(*window_get_primitives)(sdl_window_info *window);
179148   void (*window_destroy_all_textures)(sdl_window_info *window);
180149   void (*window_destroy)(sdl_window_info *window);
150   void (*window_clear)(sdl_window_info *window);
181151};
182152
183153//============================================================
r2959r2960
197167// creation/deletion of windows
198168int sdlwindow_video_window_create(running_machine *machine, int index, sdl_monitor_info *monitor, const sdl_window_config *config);
199169
200void sdlwindow_video_window_update(sdl_window_info *window);
170void sdlwindow_video_window_update(running_machine *machine, sdl_window_info *window);
201171
202172void sdlwindow_blit_surface_size(sdl_window_info *window, int window_width, int window_height);
203173
204void sdlwindow_toggle_full_screen(sdl_window_info *window);
205void sdlwindow_modify_prescale(sdl_window_info *window, int dir);
206void sdlwindow_modify_effect(sdl_window_info *window, int dir);
207void sdlwindow_toggle_draw(sdl_window_info *window);
174void sdlwindow_toggle_full_screen(running_machine *machine, sdl_window_info *window);
175void sdlwindow_modify_prescale(running_machine *machine, sdl_window_info *window, int dir);
176void sdlwindow_modify_effect(running_machine *machine, sdl_window_info *window, int dir);
177void sdlwindow_toggle_draw(running_machine *machine, sdl_window_info *window);
208178void sdlwindow_resize(sdl_window_info *window, INT32 width, INT32 height);
209179
210180#if HAS_WINDOW_MENU
r2959r2960
218188int drawsdl_init(sdl_draw_callbacks *callbacks);
219189int drawogl_init(sdl_draw_callbacks *callbacks);
220190
221//FIXME: This should go into callback!
222void drawogl_init_ogl_context(void);
223
224191#endif /* __SDL_WINDOW__ */
src/osd/sdl/keybled.c
r2959r2960
44#include "output.h"
55#include "osdsdl.h"
66
7#if defined(SDLMAME_X11)
7// FIXME: LED support for SDL >= 1.3
8#define LED_SUPPORTED   (defined(SDLMAME_X11) && (!SDL_VERSION_ATLEAST(1,3,0)))   
9
10#if LED_SUPPORTED
811static void led_change_notify(const char *outname, INT32 value, void *param);
912#endif
1013
1114void sdlled_init(void)
1215{
13   #if defined(SDLMAME_X11)
16   #if LED_SUPPORTED
1417   SDL_SysWMinfo info;
1518   SDL_VERSION(&info.version);
1619     
r2959r2960
2427   #endif
2528}
2629
27#if defined(SDLMAME_X11)
30#if LED_SUPPORTED
2831static void led_change_notify(const char *outname, INT32 value, void *param)
2932{
3033   XKeyboardControl values;
src/osd/sdl/debugosx.c
r2959r2960
3333#include "debug/debugcon.h"
3434#include "debug/debugcpu.h"
3535#include "debugger.h"
36#include "uiinput.h"
3637
3738// MAMEOS headers
3839#include "debugwin.h"
r2959r2960
489490   {
490491      // see if the interrupt key is pressed and break if it is
491492      temporarily_fake_that_we_are_not_visible = TRUE;
492      if (input_ui_pressed(Machine, IPT_UI_DEBUG_BREAK))
493      if (ui_input_pressed(Machine, IPT_UI_DEBUG_BREAK))
493494      {
494495         debugwin_info *info;
495496         HIViewRef   focuswnd;
r2959r2960
12011202      // fill out the scroll info struct for the vertical scrollbar
12021203      if ( show_vscroll )
12031204      {
1205#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
12041206         HIViewSetMinimum(info->vscroll,0);
12051207         HIViewSetMaximum(info->vscroll,total_rows-visible_rows);
12061208         HIViewSetValue(info->vscroll,top_row);
12071209         HIViewSetViewSize(info->vscroll,visible_rows);
1210#else // MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
1211         SetControl32BitMinimum(info->vscroll,0);
1212         SetControl32BitMaximum(info->vscroll,total_rows-visible_rows);
1213         SetControl32BitValue(info->vscroll,top_row);
1214#endif // MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
12081215      }
12091216     
12101217      // fill out the scroll info struct for the horizontal scrollbar
12111218      if ( show_hscroll )
12121219      {
1220#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
12131221         HIViewSetMinimum(info->hscroll,0);
12141222         HIViewSetMaximum(info->hscroll,total_cols-visible_cols);
12151223         HIViewSetValue(info->hscroll,left_col);
12161224         HIViewSetViewSize(info->hscroll,visible_cols);
1225#else // MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
1226         SetControl32BitMinimum(info->hscroll,0);
1227         SetControl32BitMaximum(info->hscroll,total_cols-visible_cols);
1228         SetControl32BitValue(info->hscroll,left_col);
1229#endif // MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
12171230      }
12181231
12191232      // update window info
r2959r2960
13001313   
13011314   isHorz = (inView == info->hscroll) ? 1 : 0;
13021315     
1316#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
13031317   maxval = HIViewGetMaximum(inView);
13041318   result = HIViewGetValue(inView);
1319#else // MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
1320   maxval = GetControl32BitMaximum(inView);
1321   result = GetControl32BitValue(inView);
1322#endif // MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
13051323   
13061324   switch( partCode )
13071325   {
r2959r2960
15631581           
15641582            if ( axis == kEventMouseWheelAxisX && info->hscroll != NULL )
15651583            {
1584#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
15661585               maxval = HIViewGetMaximum(info->hscroll);
15671586               result = HIViewGetValue(info->hscroll);
1587#else // MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
1588               maxval = GetControl32BitMaximum(info->hscroll);
1589               result = GetControl32BitValue(info->hscroll);
1590#endif // MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
15681591            }
15691592            else if ( axis == kEventMouseWheelAxisY && info->vscroll != NULL )
15701593            {
1594#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
15711595               maxval = HIViewGetMaximum(info->vscroll);
15721596               result = HIViewGetValue(info->vscroll);
1597#else // MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
1598               maxval = GetControl32BitMaximum(info->vscroll);
1599               result = GetControl32BitValue(info->vscroll);
1600#endif // MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
15731601            }
15741602           
15751603            result -= delta;
r2959r2960
21982226   }
21992227   
22002228   SetControlData(info->otherwnd[0], kControlEntireControl, kControlPopupButtonOwnedMenuRefTag, sizeof(popupmenu),&popupmenu);
2229#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
22012230   HIViewSetMinimum(info->otherwnd[0], 1);
22022231   HIViewSetMaximum(info->otherwnd[0], CountMenuItems(popupmenu));
22032232   HIViewSetValue(info->otherwnd[0],cursel);
2233#else // MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
2234   SetControl32BitMinimum(info->otherwnd[0], 1);
2235   SetControl32BitMaximum(info->otherwnd[0], CountMenuItems(popupmenu));
2236   SetControl32BitValue(info->otherwnd[0],cursel);
2237#endif // MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
22042238
22052239   // set the child functions
22062240   info->recompute_children = memory_recompute_children;
r2959r2960
23702404   {
23712405      case OSX_POPUP_COMMAND:
23722406      {
2407#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
23732408         int   sel = HIViewGetValue(info->otherwnd[0]);
2409#else // MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
2410         int   sel = GetControl32BitValue(info->otherwnd[0]);
2411#endif // MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
23742412         
23752413         if ( sel > 0 )
23762414         {
r2959r2960
26922730   }
26932731   
26942732   SetControlData(info->otherwnd[0], kControlEntireControl, kControlPopupButtonOwnedMenuRefTag, sizeof(popupmenu),&popupmenu);
2733#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
26952734   HIViewSetMinimum(info->otherwnd[0], 1);
26962735   HIViewSetMaximum(info->otherwnd[0], CountMenuItems(popupmenu));
26972736   HIViewSetValue(info->otherwnd[0],cursel);
2737#else // MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
2738   SetControl32BitMinimum(info->otherwnd[0], 1);
2739   SetControl32BitMaximum(info->otherwnd[0], CountMenuItems(popupmenu));
2740   SetControl32BitValue(info->otherwnd[0],cursel);
2741#endif // MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
26982742   
26992743   // set the child functions
27002744   info->recompute_children = disasm_recompute_children;
r2959r2960
28612905   {
28622906      case OSX_POPUP_COMMAND:
28632907      {
2908#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
28642909         int   sel = HIViewGetValue(info->otherwnd[0]);
2910#else // MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
2911         int   sel = GetControl32BitValue(info->otherwnd[0]);
2912#endif // MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
28652913         
28662914         if ( sel > 0 )
28672915         {
r2959r2960
35373585   int ignoreme;
35383586
35393587   /* ignore any keys that are received while the debug key is down */
3540   ignoreme = input_ui_pressed(Machine, IPT_UI_DEBUG_BREAK);
3588   ignoreme = ui_input_pressed(Machine, IPT_UI_DEBUG_BREAK);
35413589   if (ignoreme)
35423590      return 1;
35433591
src/osd/sdl/sdlmain.c
r2959r2960
352352static void osd_exit(running_machine *machine)
353353{
354354
355   #ifndef SDLMAME_WIN32
356   SDL_Quit();
357   #endif
355   if (!SDLMAME_INIT_IN_WORKER_THREAD)
356      SDL_Quit();
358357}
359358
360359//============================================================
r2959r2960
419418//============================================================
420419void osd_init(running_machine *machine)
421420{
422   #ifndef SDLMAME_WIN32
423   if (SDL_Init(SDL_INIT_TIMER|SDL_INIT_AUDIO| SDL_INIT_VIDEO| SDL_INIT_JOYSTICK|SDL_INIT_NOPARACHUTE)) {
424      /* mame_printf_* not fully initialized yet */
425      ShowError("Could not initialize SDL: %s.\n", SDL_GetError());
426      exit(-1);
421   if (!SDLMAME_INIT_IN_WORKER_THREAD)
422   {
423      if (SDL_Init(SDL_INIT_TIMER|SDL_INIT_AUDIO| SDL_INIT_VIDEO| SDL_INIT_JOYSTICK|SDL_INIT_NOPARACHUTE)) {
424         /* mame_printf_* not fully initialized yet */
425         ShowError("Could not initialize SDL: %s.\n", SDL_GetError());
426         exit(-1);
427      }
427428   }
428   #endif
429429   // must be before sdlvideo_init!
430430   add_exit_callback(machine, osd_exit);
431431
432432   defines_verbose();
433433
434#ifdef SDLMAME_NO_X11
434#if defined(SDLMAME_NO_X11) || defined(SDLMAME_WIN32)
435435   if (options_get_bool(mame_options(), OPTION_DEBUG))
436436   {
437437      osd_exit(machine);
438      ShowError("sdlmame", "-debug not supported on X11-less build\n\n");
438      ShowError("sdlmame", "-debug not supported on X11-less builds\n\n");
439439      exit(-1);     
440440   }
441441#endif
src/osd/sdl/osdsdl.h
r2959r2960
9393*/
9494
9595//============================================================
96//   System dependent defines
97//============================================================
98
99// Process events in worker thread
100#if defined(SDLMAME_WIN32) || (SDL_VERSION_ATLEAST(1,3,0))
101#define SDLMAME_EVENTS_IN_WORKER_THREAD   (1)
102#else
103#define SDLMAME_EVENTS_IN_WORKER_THREAD   (0)
104#endif
105
106#if defined(SDLMAME_WIN32)
107#define SDLMAME_INIT_IN_WORKER_THREAD   (1)
108#else
109#define SDLMAME_INIT_IN_WORKER_THREAD   (0)
110#endif
111
112
113//============================================================
96114//   Defines
97115//============================================================
98116
src/osd/sdl/gl_shader_mgr.c
r2959r2960
137137   return glsl_scrn_programs[idx];
138138}
139139
140int glsl_shader_init(sdl_info *sdl)
140glsl_shader_info *glsl_shader_init(void)
141141{
142142   int i,j, err;
143143
144144        err = gl_shader_loadExtention((PFNGLGETPROCADDRESSOS)SDL_GL_GetProcAddress);
145   if(err) return err;
145   if(err) return NULL;
146146   
147147   for (i=0; !err && i<GLSL_VERTEX_SHADER_INT_NUMBER; i++)
148148   {
r2959r2960
157157   #endif
158158   }
159159
160   if(err) return err;
160   if(err) return NULL;
161161
162162   for (i=0; !err && i<GLSL_SHADER_TYPE_NUMBER; i++)
163163   {
r2959r2960
178178      #endif
179179      }
180180   }
181   return err;
181   if (err) return NULL;
182   return malloc(sizeof(glsl_shader_info *));
182183}
183184
184int glsl_shader_free(sdl_info *sdl)
185int glsl_shader_free(glsl_shader_info *shinfo)
185186{
186187   int i,j;
187188
r2959r2960
222223         (void) gl_delete_shader( &glsl_scrn_programs[i], NULL, NULL);
223224   }
224225
226   free(shinfo);
225227   return 0;
226228}
227229
228int glsl_shader_add_mamebm(sdl_info *sdl, const char * custShaderPrefix, int idx)
230int glsl_shader_add_mamebm(glsl_shader_info *shinfo, const char * custShaderPrefix, int idx)
229231{
230232   int i, err;
231233   static char fname[8192];
r2959r2960
258260   return err;
259261}
260262
261int glsl_shader_add_scrn(sdl_info *sdl, const char * custShaderPrefix, int idx)
263int glsl_shader_add_scrn(glsl_shader_info *shinfo, const char * custShaderPrefix, int idx)
262264{
263265   int err;
264266   static char fname[8192];

Previous 15994 Revisions Next


© 1998-2018 The MESS Team