Previous 199869 Revisions Next

r34852 Wednesday 4th February, 2015 at 18:03:20 UTC by Couriersud
Window creation now is done in windows.c. (nw)
[src/osd/sdl]draw13.c drawogl.c drawsdl.c window.c window.h

trunk/src/osd/sdl/draw13.c
r243363r243364
163163    texture_info *texture_update(const render_primitive &prim);
164164
165165   INT32           m_blittimer;
166   UINT32          m_extra_flags;
167166
168
169167#if (SDLMAME_SDL2)
170   // Original display_mode
171   SDL_DisplayMode m_original_mode;
172
173168   SDL_GLContext   m_gl_context_id;
174169#else
175170   // SDL surface
r243363r243364
583578
584579int sdl_info13::create(int width, int height)
585580{
586   /* FIXME: On Ubuntu and potentially other Linux OS you should use
587    * to disable panning. This has to be done before every invocation of mame.
588    *
589    * xrandr --output HDMI-0 --panning 0x0+0+0 --fb 0x0
590    *
591    */
592   osd_printf_verbose("Enter sdl_info::create\n");
593
594581#if (SDLMAME_SDL2)
595
596   if (check_flag(FLAG_NEEDS_OPENGL))
597   {
598      SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
599
600      /* FIXME: A reminder that gamma is wrong throughout MAME. Currently, SDL2.0 doesn't seem to
601         * support the following attribute although my hardware lists GL_ARB_framebuffer_sRGB as an extension.
602         *
603         * SDL_GL_SetAttribute( SDL_GL_FRAMEBUFFER_SRGB_CAPABLE, 1 );
604         *
605         */
606      m_extra_flags = SDL_WINDOW_OPENGL;
607   }
608   else
609            m_extra_flags = 0;
610
611   // create the SDL window
612   // soft driver also used | SDL_WINDOW_INPUT_GRABBED | SDL_WINDOW_MOUSE_FOCUS
613   m_extra_flags |= (window().fullscreen() ?
614         SDL_WINDOW_BORDERLESS | SDL_WINDOW_INPUT_FOCUS | SDL_WINDOW_FULLSCREEN : SDL_WINDOW_RESIZABLE);
615
616#if defined(SDLMAME_WIN32)
617   SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, "0");
618#endif
619   // create the SDL window
620   window().m_sdl_window = SDL_CreateWindow(window().m_title,
621         window().monitor()->position_size().x, window().monitor()->position_size().y,
622         width, height, m_extra_flags);
623   //window().m_sdl_window = SDL_CreateWindow(window().m_title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
624   //      width, height, m_extra_flags);
625
626   if  (!window().m_sdl_window )
627   {
628      if (check_flag(FLAG_NEEDS_OPENGL))
629         osd_printf_error("OpenGL not supported on this driver: %s\n", SDL_GetError());
630      else
631      osd_printf_error("Window creation failed: %s\n", SDL_GetError());
632      return 1;
633   }
634
635   if (window().fullscreen() && video_config.switchres)
636   {
637      SDL_DisplayMode mode;
638      //SDL_GetCurrentDisplayMode(window().monitor()->handle, &mode);
639      SDL_GetWindowDisplayMode(window().m_sdl_window, &mode);
640      m_original_mode = mode;
641      mode.w = width;
642      mode.h = height;
643      if (window().m_refresh)
644         mode.refresh_rate = window().m_refresh;
645
646      SDL_SetWindowDisplayMode(window().m_sdl_window, &mode);    // Try to set mode
647#ifndef SDLMAME_WIN32
648      /* FIXME: Warp the mouse to 0,0 in case a virtual desktop resolution
649       * is in place after the mode switch - which will most likely be the case
650       * This is a hack to work around a deficiency in SDL2
651       */
652      SDL_WarpMouseInWindow(window().m_sdl_window, 1, 1);
653#endif
654   }
655   else
656   {
657      //SDL_SetWindowDisplayMode(window().m_sdl_window, NULL); // Use desktop
658   }
659
660   // show window
661
662   SDL_ShowWindow(window().m_sdl_window);
663   //SDL_SetWindowFullscreen(window().m_sdl_window, window().fullscreen);
664   SDL_RaiseWindow(window().m_sdl_window);
665
666   SDL_GetWindowSize(window().m_sdl_window, &window().m_width, &window().m_height);
667
668582   // create renderer
669583
670584   /* Enable bilinear filtering in case it is supported.
r243363r243364
698612   osd_printf_verbose("Leave sdl_info13::create\n");
699613
700614#else
701   m_extra_flags = (window().fullscreen() ?  SDL_FULLSCREEN : SDL_RESIZABLE);
702615
703   if (this->check_flag(FLAG_NEEDS_DOUBLEBUF))
704   m_extra_flags |= SDL_DOUBLEBUF;
705   if (this->check_flag(FLAG_NEEDS_ASYNCBLIT))
706      m_extra_flags |= SDL_ASYNCBLIT;
707
708   if (this->check_flag(FLAG_NEEDS_OPENGL))
709 {
710      m_extra_flags |= SDL_DOUBLEBUF | SDL_OPENGL;
711      SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
712      #if (SDL_VERSION_ATLEAST(1,2,10)) && (!defined(SDLMAME_EMSCRIPTEN))
713      SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, video_config.waitvsync ? 1 : 0);
714      #endif
715         //load_gl_lib(window().machine());
716 }
717
718   // create the SDL surface (which creates the window in windowed mode)
719   m_sdlsurf = SDL_SetVideoMode(width, height,
720                     0, SDL_SWSURFACE  | SDL_ANYFORMAT | m_extra_flags);
721
722   if (!m_sdlsurf)
723      return 1;
724   if ( (video_config.mode  == VIDEO_MODE_OPENGL) && !(m_sdlsurf->flags & SDL_OPENGL) )
725   {
726      osd_printf_error("OpenGL not supported on this driver!\n");
727      return 1;
728   }
729
730   window().m_width = m_sdlsurf->w;
731   window().m_height = m_sdlsurf->h;
732
733   window().m_screen_width = 0;
734   window().m_screen_height = 0;
735
736
737   // set the window title
738   SDL_WM_SetCaption(window().m_title, "SDLMAME");
739
740616#endif
741617   return 0;
742618}
r243363r243364
776652   if (window().fullscreen() && video_config.switchres)
777653   {
778654      SDL_SetWindowFullscreen(window().m_sdl_window, 0);    // Try to set mode
779      SDL_SetWindowDisplayMode(window().m_sdl_window, &m_original_mode);    // Try to set mode
655      SDL_SetWindowDisplayMode(window().m_sdl_window, &window().m_original_mode);    // Try to set mode
780656      SDL_SetWindowFullscreen(window().m_sdl_window, SDL_WINDOW_FULLSCREEN);    // Try to set mode
781657   }
782658
trunk/src/osd/sdl/drawogl.c
r243363r243364
222222{
223223public:
224224   sdl_info_ogl(sdl_window_info *window)
225   : osd_renderer(window, FLAG_NEEDS_OPENGL), m_blittimer(0), m_extra_flags(0),
225   : osd_renderer(window, FLAG_NEEDS_OPENGL), m_blittimer(0),
226226#if (SDLMAME_SDL2)
227227      m_gl_context_id(0),
228228#else
229      m_sdlsurf(NULL),
230229#endif
231230      m_initialized(0),
232231      m_last_blendmode(0),
r243363r243364
278277   void texture_all_disable();
279278
280279   INT32           m_blittimer;
281   UINT32          m_extra_flags;
282280
283
284281#if (SDLMAME_SDL2)
285   // Original display_mode
286   SDL_DisplayMode m_original_mode;
287
288282   SDL_GLContext   m_gl_context_id;
289283#else
290   // SDL surface
291   SDL_Surface         *m_sdlsurf;
292284#endif
293285
294286   int             m_initialized;        // is everything well initialized, i.e. all GL stuff etc.
r243363r243364
716708
717709int sdl_info_ogl::create(int width, int height)
718710{
719   /* FIXME: On Ubuntu and potentially other Linux OS you should use
720    * to disable panning. This has to be done before every invocation of mame.
721    *
722    * xrandr --output HDMI-0 --panning 0x0+0+0 --fb 0x0
723    *
724    */
725   osd_printf_verbose("Enter sdl_info::create\n");
726711
727712#if (SDLMAME_SDL2)
728
729   if (check_flag(FLAG_NEEDS_OPENGL))
730   {
731      SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
732
733      /* FIXME: A reminder that gamma is wrong throughout MAME. Currently, SDL2.0 doesn't seem to
734         * support the following attribute although my hardware lists GL_ARB_framebuffer_sRGB as an extension.
735         *
736         * SDL_GL_SetAttribute( SDL_GL_FRAMEBUFFER_SRGB_CAPABLE, 1 );
737         *
738         */
739      m_extra_flags = SDL_WINDOW_OPENGL;
740   }
741   else
742            m_extra_flags = 0;
743
744   // create the SDL window
745   // soft driver also used | SDL_WINDOW_INPUT_GRABBED | SDL_WINDOW_MOUSE_FOCUS
746   m_extra_flags |= (window().fullscreen() ?
747         SDL_WINDOW_BORDERLESS | SDL_WINDOW_INPUT_FOCUS | SDL_WINDOW_FULLSCREEN : SDL_WINDOW_RESIZABLE);
748
749#if defined(SDLMAME_WIN32)
750   SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, "0");
751#endif
752   // create the SDL window
753   window().m_sdl_window = SDL_CreateWindow(window().m_title,
754         window().monitor()->position_size().x, window().monitor()->position_size().y,
755         width, height, m_extra_flags);
756   //window().m_sdl_window = SDL_CreateWindow(window().m_title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
757   //      width, height, m_extra_flags);
758
759   if  (!window().m_sdl_window )
760   {
761      if (check_flag(FLAG_NEEDS_OPENGL))
762         osd_printf_error("OpenGL not supported on this driver: %s\n", SDL_GetError());
763      else
764         osd_printf_error("Window creation failed: %s\n", SDL_GetError());
765      return 1;
766   }
767
768   if (window().fullscreen() && video_config.switchres)
769   {
770      SDL_DisplayMode mode;
771      //SDL_GetCurrentDisplayMode(window().monitor()->handle, &mode);
772      SDL_GetWindowDisplayMode(window().m_sdl_window, &mode);
773      m_original_mode = mode;
774      mode.w = width;
775      mode.h = height;
776      if (window().m_refresh)
777         mode.refresh_rate = window().m_refresh;
778
779      SDL_SetWindowDisplayMode(window().m_sdl_window, &mode);    // Try to set mode
780#ifndef SDLMAME_WIN32
781      /* FIXME: Warp the mouse to 0,0 in case a virtual desktop resolution
782       * is in place after the mode switch - which will most likely be the case
783       * This is a hack to work around a deficiency in SDL2
784       */
785      SDL_WarpMouseInWindow(window().m_sdl_window, 1, 1);
786#endif
787   }
788   else
789   {
790      //SDL_SetWindowDisplayMode(window().m_sdl_window, NULL); // Use desktop
791   }
792
793   // show window
794
795   SDL_ShowWindow(window().m_sdl_window);
796   //SDL_SetWindowFullscreen(window().m_sdl_window, window().fullscreen);
797   SDL_RaiseWindow(window().m_sdl_window);
798
799   SDL_GetWindowSize(window().m_sdl_window, &window().m_width, &window().m_height);
800
801713   // create renderer
802714
803715   m_gl_context_id = SDL_GL_CreateContext(window().m_sdl_window);
r243363r243364
810722   SDL_GL_SetSwapInterval(video_config.waitvsync ? 2 : 0);
811723
812724#else
813   m_extra_flags = (window().fullscreen() ?  SDL_FULLSCREEN : SDL_RESIZABLE);
814
815   if (this->check_flag(FLAG_NEEDS_DOUBLEBUF))
816   m_extra_flags |= SDL_DOUBLEBUF;
817   if (this->check_flag(FLAG_NEEDS_ASYNCBLIT))
818      m_extra_flags |= SDL_ASYNCBLIT;
819
820   if (this->check_flag(FLAG_NEEDS_OPENGL))
821   {
822      m_extra_flags |= SDL_DOUBLEBUF | SDL_OPENGL;
823      SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
824      #if (SDL_VERSION_ATLEAST(1,2,10)) && (!defined(SDLMAME_EMSCRIPTEN))
825      SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, video_config.waitvsync ? 1 : 0);
826      #endif
827         //load_gl_lib(window().machine());
828   }
829
830   // create the SDL surface (which creates the window in windowed mode)
831   m_sdlsurf = SDL_SetVideoMode(width, height,
832                     0, SDL_SWSURFACE  | SDL_ANYFORMAT | m_extra_flags);
833
834   if (!m_sdlsurf)
835      return 1;
836   if ( (video_config.mode  == VIDEO_MODE_OPENGL) && !(m_sdlsurf->flags & SDL_OPENGL) )
837   {
838      osd_printf_error("OpenGL not supported on this driver!\n");
839      return 1;
840   }
841
842   window().m_width = m_sdlsurf->w;
843   window().m_height = m_sdlsurf->h;
844
845   window().m_screen_width = 0;
846   window().m_screen_height = 0;
847
848
849   // set the window title
850   SDL_WM_SetCaption(window().m_title, "SDLMAME");
851
852725#endif
853726
854727   m_blittimer = 0;
r243363r243364
887760   SDL_GetWindowSize(window().m_sdl_window, &window().m_width, &window().m_height);
888761   m_blittimer = 3;
889762#else
890   SDL_FreeSurface(m_sdlsurf);
763   SDL_FreeSurface(window().m_sdlsurf);
891764
892   m_sdlsurf = SDL_SetVideoMode(width, height, 0,
893         SDL_SWSURFACE | SDL_ANYFORMAT | m_extra_flags);
765   window().m_sdlsurf = SDL_SetVideoMode(width, height, 0,
766         SDL_SWSURFACE | SDL_ANYFORMAT | window().m_extra_flags);
894767
895   window().m_width = m_sdlsurf->w;
896   window().m_height = m_sdlsurf->h;
768   window().m_width = window().m_sdlsurf->w;
769   window().m_height = window().m_sdlsurf->h;
897770#endif
898771   m_init_context = 1;
899772
r243363r243364
917790   if (window().fullscreen() && video_config.switchres)
918791   {
919792      SDL_SetWindowFullscreen(window().m_sdl_window, 0);    // Try to set mode
920      SDL_SetWindowDisplayMode(window().m_sdl_window, &m_original_mode);    // Try to set mode
793      SDL_SetWindowDisplayMode(window().m_sdl_window, &window().m_original_mode);    // Try to set mode
921794      SDL_SetWindowFullscreen(window().m_sdl_window, SDL_WINDOW_FULLSCREEN);    // Try to set mode
922795   }
923796
924797   SDL_DestroyWindow(window().m_sdl_window);
925798#else
926   if (m_sdlsurf)
799   if (window().m_sdlsurf)
927800   {
928      SDL_FreeSurface(m_sdlsurf);
929      m_sdlsurf = NULL;
801      SDL_FreeSurface(window().m_sdlsurf);
802      window().m_sdlsurf = NULL;
930803   }
931804#endif
932805}
trunk/src/osd/sdl/drawsdl.c
r243363r243364
5353   sdl_info(sdl_window_info *w, int extra_flags)
5454   : osd_renderer(w, extra_flags),
5555   m_blittimer(0),
56   m_extra_flags(0),
5756
5857   #if (SDLMAME_SDL2)
5958   m_sdl_renderer(NULL),
6059   m_texture_id(NULL),
6160   #else
62   m_sdlsurf(NULL),
6361   m_yuvsurf(NULL),
6462   #endif
6563   m_yuv_lookup(NULL),
r243363r243364
9290#endif
9391
9492   INT32               m_blittimer;
95   UINT32              m_extra_flags;
9693
9794#if (SDLMAME_SDL2)
98   // Original display_mode
99   SDL_DisplayMode    m_original_mode;
100
10195   SDL_Renderer        *m_sdl_renderer;
10296   SDL_Texture         *m_texture_id;
10397#else
104   // SDL surface
105   SDL_Surface         *m_sdlsurf;
10698   SDL_Overlay         *m_yuvsurf;
10799#endif
108100
r243363r243364
347339   m_yuv_bitmap = global_alloc_array(UINT16, minimum_width*minimum_height);
348340
349341   m_yuvsurf = SDL_CreateYUVOverlay(minimum_width * sdl_sm->mult_w, minimum_height * sdl_sm->mult_h,
350         sdl_sm->pixel_format, m_sdlsurf);
342         sdl_sm->pixel_format, window().m_sdlsurf);
351343
352344   if ( m_yuvsurf == NULL ) {
353345      osd_printf_error("SDL: Couldn't create SDL_yuv_overlay: %s\n", SDL_GetError());
r243363r243364
429421
430422int sdl_info::create(int width, int height)
431423{
432   /* FIXME: On Ubuntu and potentially other Linux OS you should use
433    * to disable panning. This has to be done before every invocation of mame.
434    *
435    * xrandr --output HDMI-0 --panning 0x0+0+0 --fb 0x0
436    *
437    */
438424   const sdl_scale_mode *sm = &scale_modes[video_config.scale_mode];
439425
440   osd_printf_verbose("Enter sdl_info::create\n");
441
442426#if (SDLMAME_SDL2)
443427
444   if (check_flag(FLAG_NEEDS_OPENGL))
445   {
446      SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
447
448      /* FIXME: A reminder that gamma is wrong throughout MAME. Currently, SDL2.0 doesn't seem to
449         * support the following attribute although my hardware lists GL_ARB_framebuffer_sRGB as an extension.
450         *
451         * SDL_GL_SetAttribute( SDL_GL_FRAMEBUFFER_SRGB_CAPABLE, 1 );
452         *
453         */
454      m_extra_flags = SDL_WINDOW_OPENGL;
455   }
456   else
457            m_extra_flags = 0;
458
459   // create the SDL window
460   // soft driver also used | SDL_WINDOW_INPUT_GRABBED | SDL_WINDOW_MOUSE_FOCUS
461   m_extra_flags |= (window().fullscreen() ?
462         SDL_WINDOW_BORDERLESS | SDL_WINDOW_INPUT_FOCUS | SDL_WINDOW_FULLSCREEN : SDL_WINDOW_RESIZABLE);
463
464#if defined(SDLMAME_WIN32)
465   SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, "0");
466#endif
467   // create the SDL window
468   window().m_sdl_window = SDL_CreateWindow(window().m_title,
469         window().monitor()->position_size().x, window().monitor()->position_size().y,
470         width, height, m_extra_flags);
471   //window().m_sdl_window = SDL_CreateWindow(window().m_title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
472   //      width, height, m_extra_flags);
473
474   if  (!window().m_sdl_window )
475   {
476      if (check_flag(FLAG_NEEDS_OPENGL))
477         osd_printf_error("OpenGL not supported on this driver: %s\n", SDL_GetError());
478      else
479      osd_printf_error("Window creation failed: %s\n", SDL_GetError());
480      return 1;
481   }
482
483   if (window().fullscreen() && video_config.switchres)
484   {
485      SDL_DisplayMode mode;
486      //SDL_GetCurrentDisplayMode(window().monitor()->handle, &mode);
487      SDL_GetWindowDisplayMode(window().m_sdl_window, &mode);
488      m_original_mode = mode;
489      mode.w = width;
490      mode.h = height;
491      if (window().m_refresh)
492         mode.refresh_rate = window().m_refresh;
493
494      SDL_SetWindowDisplayMode(window().m_sdl_window, &mode);    // Try to set mode
495#ifndef SDLMAME_WIN32
496      /* FIXME: Warp the mouse to 0,0 in case a virtual desktop resolution
497       * is in place after the mode switch - which will most likely be the case
498       * This is a hack to work around a deficiency in SDL2
499       */
500      SDL_WarpMouseInWindow(window().m_sdl_window, 1, 1);
501#endif
502   }
503   else
504   {
505      //SDL_SetWindowDisplayMode(window().m_sdl_window, NULL); // Use desktop
506   }
507
508   // show window
509
510   SDL_ShowWindow(window().m_sdl_window);
511   //SDL_SetWindowFullscreen(window().m_sdl_window, window().fullscreen);
512   SDL_RaiseWindow(window().m_sdl_window);
513
514   SDL_GetWindowSize(window().m_sdl_window, &window().m_width, &window().m_height);
515
516428   // create renderer
517429
518430   /* set hints ... */
r243363r243364
555467
556468   setup_texture(width, height);
557469#else
558   m_extra_flags = (window().fullscreen() ?  SDL_FULLSCREEN : SDL_RESIZABLE);
559
560   if (this->check_flag(FLAG_NEEDS_DOUBLEBUF))
561      m_extra_flags |= SDL_DOUBLEBUF;
562   if (this->check_flag(FLAG_NEEDS_ASYNCBLIT))
563      m_extra_flags |= SDL_ASYNCBLIT;
564
565   if (this->check_flag(FLAG_NEEDS_OPENGL))
566   {
567      m_extra_flags |= SDL_DOUBLEBUF | SDL_OPENGL;
568      SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
569      #if (SDL_VERSION_ATLEAST(1,2,10)) && (!defined(SDLMAME_EMSCRIPTEN))
570      SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, video_config.waitvsync ? 1 : 0);
571      #endif
572      //load_gl_lib(window().machine());
573   }
574
575   // create the SDL surface (which creates the window in windowed mode)
576   m_sdlsurf = SDL_SetVideoMode(width, height,
577               0, SDL_SWSURFACE | SDL_ANYFORMAT | m_extra_flags);
578
579   if (!m_sdlsurf)
580      return 1;
581   if ( (video_config.mode  == VIDEO_MODE_OPENGL) && !(m_sdlsurf->flags & SDL_OPENGL) )
582   {
583      osd_printf_error("OpenGL not supported on this driver!\n");
584      return 1;
585   }
586
587   window().m_width = m_sdlsurf->w;
588   window().m_height = m_sdlsurf->h;
589   if (sm->is_yuv)
590      yuv_overlay_init();
591
592   // set the window title
593   SDL_WM_SetCaption(window().m_title, "SDLMAME");
594
595470#endif
596471
597472   m_yuv_lookup = NULL;
r243363r243364
621496      SDL_FreeYUVOverlay(m_yuvsurf);
622497      m_yuvsurf = NULL;
623498   }
624   SDL_FreeSurface(m_sdlsurf);
499   SDL_FreeSurface(window().m_sdlsurf);
625500   
626   m_sdlsurf = SDL_SetVideoMode(width, height, 0,
627         SDL_SWSURFACE | SDL_ANYFORMAT | m_extra_flags);
501   window().m_sdlsurf = SDL_SetVideoMode(width, height, 0,
502         SDL_SWSURFACE | SDL_ANYFORMAT | window().m_extra_flags);
628503
629   window().m_width = m_sdlsurf->w;
630   window().m_height = m_sdlsurf->h;
504   window().m_width = window().m_sdlsurf->w;
505   window().m_height = window().m_sdlsurf->h;
631506
632507      if (sdl_sm->is_yuv)
633508   {
r243363r243364
652527   if (window().fullscreen() && video_config.switchres)
653528   {
654529      SDL_SetWindowFullscreen(window().m_sdl_window, 0);    // Try to set mode
655      SDL_SetWindowDisplayMode(window().m_sdl_window, &m_original_mode);    // Try to set mode
530      SDL_SetWindowDisplayMode(window().m_sdl_window, &window().m_original_mode);    // Try to set mode
656531      SDL_SetWindowFullscreen(window().m_sdl_window, SDL_WINDOW_FULLSCREEN);    // Try to set mode
657532   }
658533
r243363r243364
664539      m_yuvsurf = NULL;
665540   }
666541
667   if (m_sdlsurf)
542   if (window().m_sdlsurf)
668543   {
669      SDL_FreeSurface(m_sdlsurf);
670      m_sdlsurf = NULL;
544      SDL_FreeSurface(window().m_sdlsurf);
545      window().m_sdlsurf = NULL;
671546   }
672547#endif
673548   // free the memory in the window
r243363r243364
743618   // lock it if we need it
744619#if (!SDLMAME_SDL2)
745620
746   pitch = m_sdlsurf->pitch;
747   bpp = m_sdlsurf->format->BytesPerPixel;
748   rmask = m_sdlsurf->format->Rmask;
749   gmask = m_sdlsurf->format->Gmask;
750   bmask = m_sdlsurf->format->Bmask;
621   pitch = window().m_sdlsurf->pitch;
622   bpp = window().m_sdlsurf->format->BytesPerPixel;
623   rmask = window().m_sdlsurf->format->Rmask;
624   gmask = window().m_sdlsurf->format->Gmask;
625   bmask = window().m_sdlsurf->format->Bmask;
751626//  amask = sdlsurf->format->Amask;
752627
753628   if (window().m_blitwidth != m_old_blitwidth || window().m_blitheight != m_old_blitheight)
r243363r243364
759634      m_blittimer = 3;
760635   }
761636
762   if (SDL_MUSTLOCK(m_sdlsurf))
763      SDL_LockSurface(m_sdlsurf);
637   if (SDL_MUSTLOCK(window().m_sdlsurf))
638      SDL_LockSurface(window().m_sdlsurf);
764639
765640   // Clear if necessary
766641   if (m_blittimer > 0)
767642   {
768      memset(m_sdlsurf->pixels, 0, window().m_height * m_sdlsurf->pitch);
643      memset(window().m_sdlsurf->pixels, 0, window().m_height * window().m_sdlsurf->pitch);
769644      m_blittimer--;
770645   }
771646
r243363r243364
783658#endif
784659   }
785660   else
786      surfptr = (UINT8 *)m_sdlsurf->pixels;
661      surfptr = (UINT8 *)window().m_sdlsurf->pixels;
787662#else
788663   //SDL_SelectRenderer(window().sdl_window);
789664
r243363r243364
943818
944819   // unlock and flip
945820#if (!SDLMAME_SDL2)
946   if (SDL_MUSTLOCK(m_sdlsurf)) SDL_UnlockSurface(m_sdlsurf);
821   if (SDL_MUSTLOCK(window().m_sdlsurf)) SDL_UnlockSurface(window().m_sdlsurf);
947822   if (!sm->is_yuv)
948823   {
949      SDL_Flip(m_sdlsurf);
824      SDL_Flip(window().m_sdlsurf);
950825   }
951826   else
952827   {
trunk/src/osd/sdl/window.c
r243363r243364
11201120      }
11211121   }
11221122
1123
1124   // create the window .....
1125
1126   /* FIXME: On Ubuntu and potentially other Linux OS you should use
1127    * to disable panning. This has to be done before every invocation of mame.
1128    *
1129    * xrandr --output HDMI-0 --panning 0x0+0+0 --fb 0x0
1130    *
1131    */
1132   osd_printf_verbose("Enter sdl_info::create\n");
1133
1134#if (SDLMAME_SDL2)
1135
1136   if (window->renderer().check_flag(osd_renderer::FLAG_NEEDS_OPENGL))
1137   {
1138      SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
1139
1140      /* FIXME: A reminder that gamma is wrong throughout MAME. Currently, SDL2.0 doesn't seem to
1141         * support the following attribute although my hardware lists GL_ARB_framebuffer_sRGB as an extension.
1142         *
1143         * SDL_GL_SetAttribute( SDL_GL_FRAMEBUFFER_SRGB_CAPABLE, 1 );
1144         *
1145         */
1146      window->m_extra_flags = SDL_WINDOW_OPENGL;
1147   }
1148   else
1149      window->m_extra_flags = 0;
1150
1151   // create the SDL window
1152   // soft driver also used | SDL_WINDOW_INPUT_GRABBED | SDL_WINDOW_MOUSE_FOCUS
1153   window->m_extra_flags |= (window->fullscreen() ?
1154         SDL_WINDOW_BORDERLESS | SDL_WINDOW_INPUT_FOCUS | SDL_WINDOW_FULLSCREEN : SDL_WINDOW_RESIZABLE);
1155
1156#if defined(SDLMAME_WIN32)
1157   SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, "0");
1158#endif
1159   // create the SDL window
1160   window->m_sdl_window = SDL_CreateWindow(window->m_title,
1161         window->monitor()->position_size().x, window->monitor()->position_size().y,
1162         tempwidth, tempheight, window->m_extra_flags);
1163   //window().m_sdl_window = SDL_CreateWindow(window().m_title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
1164   //      width, height, m_extra_flags);
1165
1166   if  ( window->m_sdl_window == NULL )
1167   {
1168      if (window->renderer().check_flag(osd_renderer::FLAG_NEEDS_OPENGL))
1169         osd_printf_error("OpenGL not supported on this driver: %s\n", SDL_GetError());
1170      else
1171         osd_printf_error("Window creation failed: %s\n", SDL_GetError());
1172      return (void *) &result[1];
1173   }
1174
1175   if (window->fullscreen() && video_config.switchres)
1176   {
1177      SDL_DisplayMode mode;
1178      //SDL_GetCurrentDisplayMode(window().monitor()->handle, &mode);
1179      SDL_GetWindowDisplayMode(window->m_sdl_window, &mode);
1180      window->m_original_mode = mode;
1181      mode.w = tempwidth;
1182      mode.h = tempheight;
1183      if (window->m_refresh)
1184         mode.refresh_rate = window->m_refresh;
1185
1186      SDL_SetWindowDisplayMode(window->m_sdl_window, &mode);    // Try to set mode
1187#ifndef SDLMAME_WIN32
1188      /* FIXME: Warp the mouse to 0,0 in case a virtual desktop resolution
1189       * is in place after the mode switch - which will most likely be the case
1190       * This is a hack to work around a deficiency in SDL2
1191       */
1192      SDL_WarpMouseInWindow(window->m_sdl_window, 1, 1);
1193#endif
1194   }
1195   else
1196   {
1197      //SDL_SetWindowDisplayMode(window().m_sdl_window, NULL); // Use desktop
1198   }
1199
1200   // show window
1201
1202   SDL_ShowWindow(window->m_sdl_window);
1203   //SDL_SetWindowFullscreen(window().m_sdl_window, window().fullscreen);
1204   SDL_RaiseWindow(window->m_sdl_window);
1205
1206   SDL_GetWindowSize(window->m_sdl_window, &window->m_width, &window->m_height);
1207
1208#else
1209   window->m_extra_flags = (window->fullscreen() ?  SDL_FULLSCREEN : SDL_RESIZABLE);
1210
1211   if (window->renderer().check_flag(osd_renderer::FLAG_NEEDS_DOUBLEBUF))
1212      window->m_extra_flags |= SDL_DOUBLEBUF;
1213   if (window->renderer().check_flag(osd_renderer::FLAG_NEEDS_ASYNCBLIT))
1214      window->m_extra_flags |= SDL_ASYNCBLIT;
1215
1216   if (window->renderer().check_flag(osd_renderer::FLAG_NEEDS_OPENGL))
1217 {
1218      window->m_extra_flags |= SDL_DOUBLEBUF | SDL_OPENGL;
1219      SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
1220      #if (SDL_VERSION_ATLEAST(1,2,10)) && (!defined(SDLMAME_EMSCRIPTEN))
1221      SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, video_config.waitvsync ? 1 : 0);
1222      #endif
1223         //load_gl_lib(window->machine());
1224 }
1225
1226   // create the SDL surface (which creates the window in windowed mode)
1227   window->m_sdlsurf = SDL_SetVideoMode(tempwidth, tempheight,
1228                     0, SDL_SWSURFACE  | SDL_ANYFORMAT | window->m_extra_flags);
1229
1230   if (!window->m_sdlsurf)
1231      return (void *) &result[1];
1232   if ( (video_config.mode  == VIDEO_MODE_OPENGL) && !(window->m_sdlsurf->flags & SDL_OPENGL) )
1233   {
1234      osd_printf_error("OpenGL not supported on this driver!\n");
1235      return (void *) &result[1];
1236   }
1237
1238   window->m_width = window->m_sdlsurf->w;
1239   window->m_height = window->m_sdlsurf->h;
1240
1241   window->m_screen_width = 0;
1242   window->m_screen_height = 0;
1243
1244   // set the window title
1245   SDL_WM_SetCaption(window->m_title, "SDLMAME");
1246#endif
1247
11231248   // initialize the drawing backend
1124   if (window->renderer().create(tempwidth, tempheight))
1249   if (window->renderer().create(window->m_width, window->m_height))
11251250      return (void *) &result[1];
11261251
11271252   // Make sure we have a consistent state
trunk/src/osd/sdl/window.h
r243363r243364
8888      m_resize_height(0),
8989      m_last_resize(0),
9090#else
91      m_sdlsurf(NULL),
9192      m_screen_width(0), m_screen_height(0),
9293#endif
9394      m_machine(a_machine), m_monitor(a_monitor), m_fullscreen(0), m_index(0)
r243363r243364
169170#if (SDLMAME_SDL2)
170171   // Needs to be here as well so we can identify window
171172   SDL_Window          *m_sdl_window;
173   // Original display_mode
174   SDL_DisplayMode m_original_mode;
172175   // These are used in combine resizing events ... #if SDL13_COMBINE_RESIZE
173176   int                 m_resize_width;
174177   int                 m_resize_height;
175178   osd_ticks_t         m_last_resize;
176179#else
180   // SDL surface
181   SDL_Surface         *m_sdlsurf;
182
177183   int                 m_screen_width;
178184   int                 m_screen_height;
179185#endif
186   int             m_extra_flags;
180187
181188   void set_renderer(osd_renderer *renderer)
182189   {


Previous 199869 Revisions Next


© 1997-2024 The MAME Team