Previous 199869 Revisions Next

r34855 Thursday 5th February, 2015 at 00:06:37 UTC by Couriersud
Moved all window related code to window.c. (nw)
[src/osd/sdl]draw13.c drawbgfx.c drawogl.c drawsdl.c input.c video.c window.c window.h

trunk/src/osd/sdl/draw13.c
r243366r243367
118118
119119private:
120120    Uint32              m_sdl_access;
121    SDL_Renderer *      m_renderer;
121    SDL_Renderer *      m_sdl_renderer;
122122    render_texinfo      m_texinfo;            // copy of the texture info
123123    HashT               m_hash;               // hash value for the texture (must be >= pointer size)
124124    UINT32              m_flags;              // rendering flags
r243366r243367
143143{
144144public:
145145    sdl_info13(sdl_window_info *w)
146    : osd_renderer(w, FLAG_NONE), m_blittimer(0), m_renderer(NULL),
146    : osd_renderer(w, FLAG_NONE), m_blittimer(0), m_sdl_renderer(NULL),
147147      m_last_hofs(0), m_last_vofs(0),
148148      m_resize_pending(0), m_resize_width(0), m_resize_height(0),
149149      m_last_blit_time(0), m_last_blit_pixels(0)
r243366r243367
171171   SDL_Surface         *m_sdlsurf;
172172#endif
173173
174   SDL_Renderer *  m_renderer;
174   SDL_Renderer *  m_sdl_renderer;
175175   simple_list<texture_info>  m_texlist;                // list of active textures
176176
177177   float           m_last_hofs;
r243366r243367
389389
390390   SDL_SetTextureBlendMode(m_texture_id, m_sdl_blendmode);
391391   set_coloralphamode(m_texture_id, &prim->color);
392   SDL_RenderCopy(m_renderer,  m_texture_id, NULL, &target_rect);
392   SDL_RenderCopy(m_sdl_renderer,  m_texture_id, NULL, &target_rect);
393393}
394394
395395void sdl_info13::render_quad(texture_info *texture, const render_primitive *prim, const int x, const int y)
r243366r243367
423423      UINT32 sb = (UINT32)(255.0f * prim->color.b);
424424      UINT32 sa = (UINT32)(255.0f * prim->color.a);
425425
426      SDL_SetRenderDrawBlendMode(m_renderer, map_blendmode(PRIMFLAG_GET_BLENDMODE(prim->flags)));
427      SDL_SetRenderDrawColor(m_renderer, sr, sg, sb, sa);
428      SDL_RenderFillRect(m_renderer, &target_rect);
426      SDL_SetRenderDrawBlendMode(m_sdl_renderer, map_blendmode(PRIMFLAG_GET_BLENDMODE(prim->flags)));
427      SDL_SetRenderDrawColor(m_sdl_renderer, sr, sg, sb, sa);
428      SDL_RenderFillRect(m_sdl_renderer, &target_rect);
429429   }
430430}
431431
r243366r243367
595595   }
596596
597597   if (video_config.waitvsync)
598      m_renderer = SDL_CreateRenderer(window().m_sdl_window, -1, SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED);
598      m_sdl_renderer = SDL_CreateRenderer(window().sdl_window(), -1, SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED);
599599   else
600      m_renderer = SDL_CreateRenderer(window().m_sdl_window, -1, SDL_RENDERER_ACCELERATED);
600      m_sdl_renderer = SDL_CreateRenderer(window().sdl_window(), -1, SDL_RENDERER_ACCELERATED);
601601
602   if (!m_renderer)
602   if (!m_sdl_renderer)
603603   {
604604      fatalerror("Error on creating renderer: %s\n", SDL_GetError());
605605   }
r243366r243367
608608
609609   m_blittimer = 3;
610610
611   SDL_RenderPresent(m_renderer);
611   SDL_RenderPresent(m_sdl_renderer);
612612   osd_printf_verbose("Leave sdl_info13::create\n");
613613
614614#else
r243366r243367
623623
624624void sdl_info13::resize(int width, int height)
625625{
626   m_resize_pending = 1;
627   m_resize_height = height;
628   m_resize_width = width;
629
630   window().m_width = width;
631   window().m_height = height;
632
626   SDL_RenderSetViewport(m_sdl_renderer, NULL);
633627   m_blittimer = 3;
634
635628}
636629
637630
r243366r243367
641634
642635void sdl_info13::destroy()
643636{
644
645   // free the memory in the window
646
647637   destroy_all_textures();
648
649#if (SDLMAME_SDL2)
650   if (check_flag(FLAG_NEEDS_OPENGL))
651      SDL_GL_DeleteContext(m_gl_context_id);
652   if (window().fullscreen() && video_config.switchres)
653   {
654      SDL_SetWindowFullscreen(window().m_sdl_window, 0);    // Try to set mode
655      SDL_SetWindowDisplayMode(window().m_sdl_window, &window().m_original_mode);    // Try to set mode
656      SDL_SetWindowFullscreen(window().m_sdl_window, SDL_WINDOW_FULLSCREEN);    // Try to set mode
657   }
658
659   SDL_DestroyWindow(window().m_sdl_window);
660#else
661   if (m_sdlsurf)
662   {
663      SDL_FreeSurface(m_sdlsurf);
664      m_sdlsurf = NULL;
665   }
666#endif
667638}
668639
669640//============================================================
r243366r243367
685656
686657   *xt = x - m_last_hofs;
687658   *yt = y - m_last_vofs;
688   if (*xt<0 || *xt >= window().m_blitwidth)
659   if (*xt<0 || *xt >= window().blitwidth())
689660      return 0;
690   if (*yt<0 || *yt >= window().m_blitheight)
661   if (*yt<0 || *yt >= window().blitheight())
691662      return 0;
692663   return 1;
693664}
r243366r243367
724695      return 0;
725696   }
726697
698#if 0
727699   if (m_resize_pending)
728700   {
729701      SDL_SetWindowSize(window().m_sdl_window, m_resize_width, m_resize_height);
730      SDL_GetWindowSize(window().m_sdl_window, &window().m_width, &window().m_height);
702      SDL_GetWindowSize(window().m_sdl_window, &window().width(), &window().height());
731703      m_resize_pending = 0;
732      SDL_RenderSetViewport(m_renderer, NULL);
704      SDL_RenderSetViewport(m_sdl_renderer, NULL);
733705      //sdlvideo_monitor_refresh(window().monitor());
734706
735707   }
736
708#endif
737709   //SDL_SelectRenderer(window().sdl_window);
738710
739711   if (m_blittimer > 0)
740712   {
741713      /* SDL Underlays need alpha = 0 ! */
742      SDL_SetRenderDrawBlendMode(m_renderer, SDL_BLENDMODE_NONE);
714      SDL_SetRenderDrawBlendMode(m_sdl_renderer, SDL_BLENDMODE_NONE);
743715      //SDL_SetRenderDrawColor(0,0,0,255);
744      SDL_SetRenderDrawColor(m_renderer, 0,0,0,0);
745      SDL_RenderFillRect(m_renderer, NULL);
716      SDL_SetRenderDrawColor(m_sdl_renderer, 0,0,0,0);
717      SDL_RenderFillRect(m_sdl_renderer, NULL);
746718      m_blittimer--;
747719   }
748720
r243366r243367
760732      }
761733      else
762734      {
763         ch = window().m_height;
764         cw = window().m_width;
735         ch = window().height();
736         cw = window().width();
765737      }
766738
767739      if (video_config.centerv)
768740      {
769         vofs = (ch - window().m_blitheight) / 2.0f;
741         vofs = (ch - window().blitheight()) / 2.0f;
770742      }
771743      if (video_config.centerh)
772744      {
773         hofs = (cw - window().m_blitwidth) / 2.0f;
745         hofs = (cw - window().blitwidth()) / 2.0f;
774746      }
775747   }
776748
r243366r243367
792764            sb = (int)(255.0f * prim->color.b);
793765            sa = (int)(255.0f * prim->color.a);
794766
795            SDL_SetRenderDrawBlendMode(m_renderer, map_blendmode(PRIMFLAG_GET_BLENDMODE(prim->flags)));
796            SDL_SetRenderDrawColor(m_renderer, sr, sg, sb, sa);
797            SDL_RenderDrawLine(m_renderer, prim->bounds.x0 + hofs, prim->bounds.y0 + vofs,
767            SDL_SetRenderDrawBlendMode(m_sdl_renderer, map_blendmode(PRIMFLAG_GET_BLENDMODE(prim->flags)));
768            SDL_SetRenderDrawColor(m_sdl_renderer, sr, sg, sb, sa);
769            SDL_RenderDrawLine(m_sdl_renderer, prim->bounds.x0 + hofs, prim->bounds.y0 + vofs,
798770                  prim->bounds.x1 + hofs, prim->bounds.y1 + vofs);
799771            break;
800772         case render_primitive::QUAD:
r243366r243367
814786
815787   m_last_blit_pixels = blit_pixels;
816788   m_last_blit_time = -osd_ticks();
817   SDL_RenderPresent(m_renderer);
789   SDL_RenderPresent(m_sdl_renderer);
818790   m_last_blit_time += osd_ticks();
819791
820792   return 0;
r243366r243367
840812      if ((m_is_rotated == bi->blitter->m_is_rot)
841813            && (m_sdl_blendmode == bi->bm_mask))
842814      {
843         if (RendererSupportsFormat(m_renderer, bi->dst_fmt, m_sdl_access, bi->dstname))
815         if (RendererSupportsFormat(m_sdl_renderer, bi->dst_fmt, m_sdl_access, bi->dstname))
844816         {
845817            int perf = bi->perf;
846818            if (perf == 0)
r243366r243367
860832   {
861833      if ((m_is_rotated == bi->blitter->m_is_rot)
862834         && (m_sdl_blendmode == bi->bm_mask))
863         if (RendererSupportsFormat(m_renderer, bi->dst_fmt, m_sdl_access, bi->dstname))
835         if (RendererSupportsFormat(m_sdl_renderer, bi->dst_fmt, m_sdl_access, bi->dstname))
864836            return bi;
865837   }
866838   //FIXME: crash implement a -do nothing handler */
r243366r243367
898870texture_info::texture_info(SDL_Renderer *renderer, const render_texinfo &texsource, const quad_setup_data &setup, UINT32 flags)
899871{
900872   // fill in the core data
901   m_renderer = renderer;
873   m_sdl_renderer = renderer;
902874   m_hash = texture_compute_hash(texsource, flags);
903875   m_flags = flags;
904876   m_texinfo = texsource;
r243366r243367
947919
948920   m_copyinfo = compute_size_type();
949921
950   m_texture_id = SDL_CreateTexture(m_renderer, m_copyinfo->dst_fmt, m_sdl_access,
922   m_texture_id = SDL_CreateTexture(m_sdl_renderer, m_copyinfo->dst_fmt, m_sdl_access,
951923         m_setup.rotwidth, m_setup.rotheight);
952924
953925   if (!m_texture_id)
r243366r243367
11201092   // if we didn't find one, create a new texture
11211093   if (texture == NULL && prim.texture.base != NULL)
11221094   {
1123      texture = global_alloc(texture_info(m_renderer, prim.texture, setup, prim.flags));
1095      texture = global_alloc(texture_info(m_sdl_renderer, prim.texture, setup, prim.flags));
11241096      /* add us to the texture list */
11251097      m_texlist.prepend(*texture);
11261098
trunk/src/osd/sdl/drawbgfx.c
r243366r243367
7676    sdl_info_bgfx(sdl_window_info *w)
7777    : osd_renderer(w, FLAG_NONE), m_blittimer(0), m_renderer(NULL),
7878      m_last_hofs(0), m_last_vofs(0),
79      m_resize_pending(0), m_resize_width(0), m_resize_height(0),
8079      m_last_blit_time(0), m_last_blit_pixels(0)
8180    {}
8281
r243366r243367
101100   float           m_last_hofs;
102101   float           m_last_vofs;
103102
104   // resize information
105
106   UINT8           m_resize_pending;
107   UINT32          m_resize_width;
108   UINT32          m_resize_height;
109
110103   // Stats
111104   INT64           m_last_blit_time;
112105   INT64           m_last_blit_pixels;
r243366r243367
144137
145138int sdl_info_bgfx::create(int width, int height)
146139{
147   /* FIXME: On Ubuntu and potentially other Linux OS you should use
148    * to disable panning. This has to be done before every invocation of mame.
149    *
150    * xrandr --output HDMI-0 --panning 0x0+0+0 --fb 0x0
151    *
152    */
153
154   osd_printf_verbose("Enter drawsdl2_window_create\n");
155
156   UINT32 extra_flags = (window().fullscreen() ?
157         SDL_WINDOW_BORDERLESS | SDL_WINDOW_INPUT_FOCUS | SDL_WINDOW_FULLSCREEN : SDL_WINDOW_RESIZABLE);
158
159#if defined(SDLMAME_WIN32)
160   SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, "0");
161#endif
162   // create the SDL window
163   window().m_sdl_window = SDL_CreateWindow(window().m_title,
164         window().monitor()->position_size().x, window().monitor()->position_size().y,
165         width, height, extra_flags);
166
167   if (window().fullscreen() && video_config.switchres)
168   {
169      SDL_DisplayMode mode;
170      //SDL_GetCurrentDisplayMode(window().monitor()->handle, &mode);
171      SDL_GetWindowDisplayMode(window().m_sdl_window, &mode);
172      m_original_mode = mode;
173      mode.w = width;
174      mode.h = height;
175      if (window().m_refresh)
176         mode.refresh_rate = window().m_refresh;
177
178      SDL_SetWindowDisplayMode(window().m_sdl_window, &mode);    // Try to set mode
179#ifndef SDLMAME_WIN32
180      /* FIXME: Warp the mouse to 0,0 in case a virtual desktop resolution
181       * is in place after the mode switch - which will most likely be the case
182       * This is a hack to work around a deficiency in SDL2
183       */
184      SDL_WarpMouseInWindow(window().m_sdl_window, 1, 1);
185#endif
186   }
187   else
188   {
189      //SDL_SetWindowDisplayMode(window().m_sdl_window, NULL); // Use desktop
190   }
191140   // create renderer
192141
193   if (video_config.waitvsync)
194      m_renderer = SDL_CreateRenderer(window().m_sdl_window, -1, SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED);
195   else
196      m_renderer = SDL_CreateRenderer(window().m_sdl_window, -1, SDL_RENDERER_ACCELERATED);
197
198   if (!m_renderer)
199   {
200      fatalerror("Error on creating renderer: %s\n", SDL_GetError());
201   }
202
203   //SDL_SelectRenderer(window().m_sdl_window);
204   SDL_ShowWindow(window().m_sdl_window);
205   //SDL_SetWindowFullscreen(window().window_id, window().fullscreen);
206   SDL_RaiseWindow(window().m_sdl_window);
207
208   SDL_GetWindowSize(window().m_sdl_window, &window().m_width, &window().m_height);
209
210142   m_blittimer = 3;
211143
212   SDL_RenderPresent(m_renderer);
213   
214144   bgfx::sdlSetWindow(window().m_sdl_window);
215145   bgfx::init();
216   bgfx::reset(window().m_width, window().m_height, BGFX_RESET_VSYNC);
146   bgfx::reset(window().width(), window().height(), BGFX_RESET_VSYNC);
217147   
218148   // Enable debug text.
219149   bgfx::setDebug(BGFX_DEBUG_STATS);// BGFX_DEBUG_TEXT);
r243366r243367
227157
228158void sdl_info_bgfx::resize(int width, int height)
229159{
230   m_resize_pending = 1;
231   m_resize_height = height;
232   m_resize_width = width;
233
234   window().m_width = width;
235   window().m_height = height;
236
237160   m_blittimer = 3;
238161}
239162
r243366r243367
245168{
246169   *xt = x - m_last_hofs;
247170   *yt = y - m_last_vofs;
248   if (*xt<0 || *xt >= window().m_blitwidth)
171   if (*xt<0 || *xt >= window().blitwidth())
249172      return 0;
250   if (*yt<0 || *yt >= window().m_blitheight)
173   if (*yt<0 || *yt >= window().blitheight())
251174      return 0;
252175   return 1;
253176}
r243366r243367
265188      , 0
266189      );
267190   // Set view 0 default viewport.
268   bgfx::setViewRect(0, 0, 0, window().m_blitwidth, window().m_blitheight);
191   bgfx::setViewRect(0, 0, 0, window().blitwidth(), window().blitheight());
269192
270193   // This dummy draw call is here to make sure that view 0 is cleared
271194   // if no other draw calls are submitted to view 0.
r243366r243367
298221
299222   destroy_all_textures();
300223
301   if (window().fullscreen() && video_config.switchres)
302   {
303      SDL_SetWindowFullscreen(window().m_sdl_window, 0);    // Try to set mode
304      SDL_SetWindowDisplayMode(window().m_sdl_window, &m_original_mode);    // Try to set mode
305      SDL_SetWindowFullscreen(window().m_sdl_window, SDL_WINDOW_FULLSCREEN);    // Try to set mode
306   }
307
308   SDL_DestroyWindow(window().m_sdl_window);
309   
310224   // Shutdown bgfx.
311225   bgfx::shutdown();
312226}
trunk/src/osd/sdl/drawogl.c
r243366r243367
5858typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURE2DEXTPROC) (GLenum m_target, GLenum attachment, GLenum textarget, GLuint texture, GLint level);
5959typedef void (APIENTRYP PFNGLGENRENDERBUFFERSEXTPROC) (GLsizei n, GLuint *renderbuffers);
6060typedef void (APIENTRYP PFNGLBINDRENDERBUFFEREXTPROC) (GLenum m_target, GLuint renderbuffer);
61typedef void (APIENTRYP PFNGLRENDERBUFFERSTORAGEEXTPROC) (GLenum m_target, GLenum internalformat, GLsizei m_width, GLsizei m_height);
61typedef void (APIENTRYP PFNGLRENDERBUFFERSTORAGEEXTPROC) (GLenum m_target, GLenum internalformat, GLsizei width, GLsizei height);
6262typedef void (APIENTRYP PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC) (GLenum m_target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer);
6363typedef void (APIENTRYP PFNGLDELETERENDERBUFFERSEXTPROC) (GLsizei n, const GLuint *renderbuffers);
6464#endif
r243366r243367
165165{
166166public:
167167   texture_info()
168   : hash(0), flags(0), rawwidth(0), rawheight(0),
168   :    hash(0), flags(0), rawwidth(0), rawheight(0),
169169      rawwidth_create(0), rawheight_create(0),
170170      type(0), format(0), borderpix(0), xprescale(0), yprescale(0), nocopy(0),
171171      texture(0), texTarget(0), texpow2(0), mpass_dest_idx(0), pbo(0), data(NULL),
r243366r243367
223223public:
224224   sdl_info_ogl(sdl_window_info *window)
225225   : osd_renderer(window, FLAG_NEEDS_OPENGL), m_blittimer(0),
226      m_screen_width(0), m_screen_height(0),
226227#if (SDLMAME_SDL2)
227228      m_gl_context_id(0),
228229#else
r243366r243367
277278   void texture_all_disable();
278279
279280   INT32           m_blittimer;
281   int             m_screen_width;
282   int             m_screen_height;
280283
281284#if (SDLMAME_SDL2)
282285   SDL_GLContext   m_gl_context_id;
r243366r243367
712715#if (SDLMAME_SDL2)
713716   // create renderer
714717
715   m_gl_context_id = SDL_GL_CreateContext(window().m_sdl_window);
718   m_gl_context_id = SDL_GL_CreateContext(window().sdl_window());
716719   if  (!m_gl_context_id)
717720   {
718721      osd_printf_error("OpenGL not supported on this driver: %s\n", SDL_GetError());
r243366r243367
724727#else
725728#endif
726729
730   m_screen_width = 0;
731   m_screen_height = 0;
732
727733   m_blittimer = 0;
728734   m_surf_w = 0;
729735   m_surf_h = 0;
r243366r243367
755761void sdl_info_ogl::resize(int width, int height)
756762{
757763#if (SDLMAME_SDL2)
758   //SDL_GL_MakeCurrent(window().sdl_window, gl_context_id);
759   SDL_SetWindowSize(window().m_sdl_window, width, height);
760   SDL_GetWindowSize(window().m_sdl_window, &window().m_width, &window().m_height);
761764   m_blittimer = 3;
762#else
763   SDL_FreeSurface(window().m_sdlsurf);
764
765   window().m_sdlsurf = SDL_SetVideoMode(width, height, 0,
766         SDL_SWSURFACE | SDL_ANYFORMAT | window().m_extra_flags);
767
768   window().m_width = window().m_sdlsurf->w;
769   window().m_height = window().m_sdlsurf->h;
770765#endif
771766   m_init_context = 1;
772
773767}
774768
775769
r243366r243367
785779   destroy_all_textures();
786780
787781#if (SDLMAME_SDL2)
788   if (check_flag(FLAG_NEEDS_OPENGL))
789      SDL_GL_DeleteContext(m_gl_context_id);
790   if (window().fullscreen() && video_config.switchres)
791   {
792      SDL_SetWindowFullscreen(window().m_sdl_window, 0);    // Try to set mode
793      SDL_SetWindowDisplayMode(window().m_sdl_window, &window().m_original_mode);    // Try to set mode
794      SDL_SetWindowFullscreen(window().m_sdl_window, SDL_WINDOW_FULLSCREEN);    // Try to set mode
795   }
796
797   SDL_DestroyWindow(window().m_sdl_window);
798#else
799   if (window().m_sdlsurf)
800   {
801      SDL_FreeSurface(window().m_sdlsurf);
802      window().m_sdlsurf = NULL;
803   }
782   SDL_GL_DeleteContext(m_gl_context_id);
804783#endif
784
805785}
806786
807787//============================================================
r243366r243367
823803
824804   *xt = x - m_last_hofs;
825805   *yt = y - m_last_vofs;
826   if (*xt<0 || *xt >= window().m_blitwidth)
806   if (*xt<0 || *xt >= window().blitwidth())
827807      return 0;
828   if (*yt<0 || *yt >= window().m_blitheight)
808   if (*yt<0 || *yt >= window().blitheight())
829809      return 0;
830810   return 1;
831811}
r243366r243367
844824      return;
845825
846826#if (SDLMAME_SDL2)
847   SDL_GL_MakeCurrent(window().m_sdl_window, m_gl_context_id);
827   SDL_GL_MakeCurrent(window().sdl_window(), m_gl_context_id);
848828#endif
849829
850830   if(window().m_primlist)
r243366r243367
11321112
11331113   if ( m_useglsl )
11341114   {
1135      if ( window().m_prescale != 1 )
1115      if ( window().prescale() != 1 )
11361116      {
11371117         m_useglsl = 0;
11381118         if (_once)
r243366r243367
12421222   }
12431223
12441224#if (SDLMAME_SDL2)
1245   SDL_GL_MakeCurrent(window().m_sdl_window, m_gl_context_id);
1225   SDL_GL_MakeCurrent(window().sdl_window(), m_gl_context_id);
12461226#else
12471227   if (!m_init_context)
12481228   {
r243366r243367
12511231      {
12521232         if (window().index() == 0)
12531233         {
1254            if ((screen->width() != window().m_screen_width) || (screen->height() != window().m_screen_height))
1234            if ((screen->width() != m_screen_width) || (screen->height() != m_screen_height))
12551235            {
1256               window().m_screen_width = screen->width();
1257               window().m_screen_height = screen->height();
1236               m_screen_width = screen->width();
1237               m_screen_height = screen->height();
12581238
12591239               // force all textures to be regenerated
12601240               destroy_all_textures();
r243366r243367
13051285   }
13061286
13071287   if ( !m_initialized ||
1308         window().m_width!= m_surf_w || window().m_height!= m_surf_h )
1288         window().width()!= m_surf_w || window().height()!= m_surf_h )
13091289   {
13101290      if ( !m_initialized )
13111291      {
13121292         loadGLExtensions();
13131293      }
13141294
1315      m_surf_w=window().m_width;
1316      m_surf_h=window().m_height;
1295      m_surf_w=window().width();
1296      m_surf_h=window().height();
13171297
13181298      // we're doing nothing 3d, so the Z-buffer is currently not interesting
13191299      glDisable(GL_DEPTH_TEST);
r243366r243367
13541334      //   |_________|
13551335      // (0,h)     (w,h)
13561336
1357      glViewport(0.0, 0.0, (GLsizei)window().m_width, (GLsizei)window().m_height);
1337      glViewport(0.0, 0.0, (GLsizei)window().width(), (GLsizei)window().height());
13581338      glMatrixMode(GL_PROJECTION);
13591339      glLoadIdentity();
1360      glOrtho(0.0, (GLdouble)window().m_width, (GLdouble)window().m_height, 0.0, 0.0, -1.0);
1340      glOrtho(0.0, (GLdouble)window().width(), (GLdouble)window().height(), 0.0, 0.0, -1.0);
13611341      glMatrixMode(GL_MODELVIEW);
13621342      glLoadIdentity();
13631343
r243366r243367
13841364      }
13851365      else
13861366      {
1387         ch = window().m_height;
1388         cw = window().m_width;
1367         ch = window().height();
1368         cw = window().width();
13891369      }
13901370
13911371      if (video_config.centerv)
13921372      {
1393         vofs = (ch - window().m_blitheight) / 2.0f;
1373         vofs = (ch - window().blitheight()) / 2.0f;
13941374      }
13951375      if (video_config.centerh)
13961376      {
1397         hofs = (cw - window().m_blitwidth) / 2.0f;
1377         hofs = (cw - window().blitwidth()) / 2.0f;
13981378      }
13991379   }
14001380
r243366r243367
14701450               set_blendmode(sdl, PRIMFLAG_GET_BLENDMODE(prim->flags));
14711451
14721452               // compute the effective width based on the direction of the line
1473               effwidth = prim->m_width;
1453               effwidth = prim->width();
14741454               if (effwidth < 0.5f)
14751455                  effwidth = 0.5f;
14761456
r243366r243367
15751555                     // 1:1 tex coord CCW (0/0) (1/0) (1/1) (0/1) on texture dimensions
15761556                     m_texVerticex[0]=(GLfloat)0.0;
15771557                     m_texVerticex[1]=(GLfloat)0.0;
1578                     m_texVerticex[2]=(GLfloat)window().m_width;
1558                     m_texVerticex[2]=(GLfloat)window().width();
15791559                     m_texVerticex[3]=(GLfloat)0.0;
1580                     m_texVerticex[4]=(GLfloat)window().m_width;
1581                     m_texVerticex[5]=(GLfloat)window().m_height;
1560                     m_texVerticex[4]=(GLfloat)window().width();
1561                     m_texVerticex[5]=(GLfloat)window().height();
15821562                     m_texVerticex[6]=(GLfloat)0.0;
1583                     m_texVerticex[7]=(GLfloat)window().m_height;
1563                     m_texVerticex[7]=(GLfloat)window().height();
15841564                  }
15851565
15861566                  if(i>0) // first fetch already done
r243366r243367
16261606#if (!SDLMAME_SDL2)
16271607   SDL_GL_SwapBuffers();
16281608#else
1629   SDL_GL_SwapWindow(window().m_sdl_window);
1609   SDL_GL_SwapWindow(window().sdl_window());
16301610#endif
16311611   return 0;
16321612}
r243366r243367
17841764      texture->xprescale--;
17851765   while (texture->yprescale > 1 && height_create * texture->yprescale > m_texture_max_height)
17861766      texture->yprescale--;
1787   if (PRIMFLAG_GET_SCREENTEX(flags) && (texture->xprescale != window().m_prescale || texture->yprescale != window().m_prescale))
1788      osd_printf_warning("SDL: adjusting prescale from %dx%d to %dx%d\n", window().m_prescale, window().m_prescale, texture->xprescale, texture->yprescale);
1767   if (PRIMFLAG_GET_SCREENTEX(flags) && (texture->xprescale != window().prescale() || texture->yprescale != window().prescale()))
1768      osd_printf_warning("SDL: adjusting prescale from %dx%d to %dx%d\n", window().prescale(), window().prescale(), texture->xprescale, texture->yprescale);
17891769
17901770   width  *= texture->xprescale;
17911771   height *= texture->yprescale;
r243366r243367
19641944{
19651945   int uniform_location;
19661946   int i;
1967   int surf_w_pow2  = get_valid_pow2_value (window().m_blitwidth, texture->texpow2);
1968   int surf_h_pow2  = get_valid_pow2_value (window().m_blitheight, texture->texpow2);
1947   int surf_w_pow2  = get_valid_pow2_value (window().blitwidth(), texture->texpow2);
1948   int surf_h_pow2  = get_valid_pow2_value (window().blitheight(), texture->texpow2);
19691949
19701950   assert ( texture->type==TEXTURE_TYPE_SHADER );
19711951
r243366r243367
20121992      pfn_glUniform2fvARB(uniform_location, 1, &(color_texture_pow2_sz[0]));
20131993      GL_CHECK_ERROR_NORMAL();
20141994
2015      GLfloat screen_texture_sz[2] = { (GLfloat)window().m_blitwidth, (GLfloat)window().m_blitheight };
1995      GLfloat screen_texture_sz[2] = { (GLfloat)window().blitwidth(), (GLfloat)window().blitheight() };
20161996      uniform_location = pfn_glGetUniformLocationARB(m_glsl_program[i], "screen_texture_sz");
20171997      pfn_glUniform2fvARB(uniform_location, 1, &(screen_texture_sz[0]));
20181998      GL_CHECK_ERROR_NORMAL();
r243366r243367
20682048      }
20692049
20702050      osd_printf_verbose("GL texture: mpass screen-bmp 2x %dx%d (pow2 %dx%d)\n",
2071         window().m_width, window().m_height, surf_w_pow2, surf_h_pow2);
2051         window().width(), window().height(), surf_w_pow2, surf_h_pow2);
20722052   }
20732053
20742054   // GL_TEXTURE0
r243366r243367
21472127   texture->texinfo.seqid = -1; // force set data
21482128   if (PRIMFLAG_GET_SCREENTEX(flags))
21492129   {
2150      texture->xprescale = window().m_prescale;
2151      texture->yprescale = window().m_prescale;
2130      texture->xprescale = window().prescale();
2131      texture->yprescale = window().prescale();
21522132   }
21532133   else
21542134   {
r243366r243367
27782758   }
27792759   else if ( texture->type == TEXTURE_TYPE_SHADER && shaderIdx>m_glsl_program_mb2sc )
27802760   {
2781      int surf_w_pow2  = get_valid_pow2_value (window().m_width, texture->texpow2);
2782      int surf_h_pow2  = get_valid_pow2_value (window().m_height, texture->texpow2);
2761      int surf_w_pow2  = get_valid_pow2_value (window().width(), texture->texpow2);
2762      int surf_h_pow2  = get_valid_pow2_value (window().height(), texture->texpow2);
27832763
2784      ustop  = (float)(window().m_width) / (float)surf_w_pow2;
2785      vstop  = (float)(window().m_height) / (float)surf_h_pow2;
2764      ustop  = (float)(window().width()) / (float)surf_w_pow2;
2765      vstop  = (float)(window().height()) / (float)surf_h_pow2;
27862766   }
27872767   else
27882768   {
trunk/src/osd/sdl/drawsdl.c
r243366r243367
5252
5353   sdl_info(sdl_window_info *w, int extra_flags)
5454   : osd_renderer(w, extra_flags),
55   m_blittimer(0),
56
5755   #if (SDLMAME_SDL2)
5856   m_sdl_renderer(NULL),
5957   m_texture_id(NULL),
r243366r243367
216214
217215static osd_renderer *drawsdl_create(sdl_window_info *window)
218216{
219   const sdl_scale_mode *sm = &scale_modes[video_config.scale_mode];
220
221217   // FIXME: QUALITY HINTS
222218#if (SDLMAME_SDL2)
223219   return global_alloc(sdl_info(window, osd_renderer::FLAG_NONE));
224220#else
221   const sdl_scale_mode *sm = &scale_modes[video_config.scale_mode];
225222   return global_alloc(sdl_info(window, sm->m_extra_flags));
226223#endif
227224}
r243366r243367
279276      int m_hw_scale_width =0;
280277      int m_hw_scale_height = 0;
281278
282      window().m_target->compute_minimum_size(m_hw_scale_width, m_hw_scale_height);
279      window().target()->compute_minimum_size(m_hw_scale_width, m_hw_scale_height);
283280      if (video_config.prescale)
284281      {
285282         m_hw_scale_width *= video_config.prescale;
r243366r243367
315312   const sdl_scale_mode *sdl_sm = &scale_modes[video_config.scale_mode];
316313   int minimum_width, minimum_height;
317314
318   window().m_target->compute_minimum_size(minimum_width, minimum_height);
315   window().target()->compute_minimum_size(minimum_width, minimum_height);
319316
320317   if (video_config.prescale)
321318   {
r243366r243367
339336   m_yuv_bitmap = global_alloc_array(UINT16, minimum_width*minimum_height);
340337
341338   m_yuvsurf = SDL_CreateYUVOverlay(minimum_width * sdl_sm->mult_w, minimum_height * sdl_sm->mult_h,
342         sdl_sm->pixel_format, window().m_sdlsurf);
339         sdl_sm->pixel_format, window().sdl_surface());
343340
344341   if ( m_yuvsurf == NULL ) {
345342      osd_printf_error("SDL: Couldn't create SDL_yuv_overlay: %s\n", SDL_GetError());
r243366r243367
421418
422419int sdl_info::create(int width, int height)
423420{
424   const sdl_scale_mode *sm = &scale_modes[video_config.scale_mode];
425421
426422#if (SDLMAME_SDL2)
423   const sdl_scale_mode *sm = &scale_modes[video_config.scale_mode];
427424
428425   // create renderer
429426
r243366r243367
432429
433430
434431   if (video_config.waitvsync)
435      m_sdl_renderer = SDL_CreateRenderer(window().m_sdl_window, -1, SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED);
432      m_sdl_renderer = SDL_CreateRenderer(window().sdl_window(), -1, SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED);
436433   else
437      m_sdl_renderer = SDL_CreateRenderer(window().m_sdl_window, -1, SDL_RENDERER_ACCELERATED);
434      m_sdl_renderer = SDL_CreateRenderer(window().sdl_window(), -1, SDL_RENDERER_ACCELERATED);
438435
439436   if (!m_sdl_renderer)
440437   {
r243366r243367
483480
484481void sdl_info::resize(int width, int height)
485482{
486#if (!SDLMAME_SDL2)
487   const sdl_scale_mode *sdl_sm = &scale_modes[video_config.scale_mode];
488#endif
489483#if (SDLMAME_SDL2)
490   SDL_SetWindowSize(window().m_sdl_window, width, height);
491   SDL_GetWindowSize(window().m_sdl_window, &window().m_width, &window().m_height);
492
484   SDL_RenderSetViewport(m_sdl_renderer, NULL);
493485#else
494   if (m_yuvsurf != NULL)
486   const sdl_scale_mode *sdl_sm = &scale_modes[video_config.scale_mode];
487   if (sdl_sm->is_yuv)
495488   {
496      SDL_FreeYUVOverlay(m_yuvsurf);
497      m_yuvsurf = NULL;
498   }
499   SDL_FreeSurface(window().m_sdlsurf);
500   
501   window().m_sdlsurf = SDL_SetVideoMode(width, height, 0,
502         SDL_SWSURFACE | SDL_ANYFORMAT | window().m_extra_flags);
503
504   window().m_width = window().m_sdlsurf->w;
505   window().m_height = window().m_sdlsurf->h;
506
507      if (sdl_sm->is_yuv)
508   {
509489      yuv_overlay_init();
510490   }
511
512491#endif
513492}
514493
r243366r243367
520499void sdl_info::destroy()
521500{
522501
523#if (SDLMAME_SDL2)
524   //SDL_SelectRenderer(window().sdl_window);
525   SDL_DestroyTexture(m_texture_id);
526   //SDL_DestroyRenderer(window().sdl_window);
527   if (window().fullscreen() && video_config.switchres)
528   {
529      SDL_SetWindowFullscreen(window().m_sdl_window, 0);    // Try to set mode
530      SDL_SetWindowDisplayMode(window().m_sdl_window, &window().m_original_mode);    // Try to set mode
531      SDL_SetWindowFullscreen(window().m_sdl_window, SDL_WINDOW_FULLSCREEN);    // Try to set mode
532   }
533
534   SDL_DestroyWindow(window().m_sdl_window);
535#else
536   if (m_yuvsurf != NULL)
537   {
538      SDL_FreeYUVOverlay(m_yuvsurf);
539      m_yuvsurf = NULL;
540   }
541
542   if (window().m_sdlsurf)
543   {
544      SDL_FreeSurface(window().m_sdlsurf);
545      window().m_sdlsurf = NULL;
546   }
547#endif
548502   // free the memory in the window
549503
504   destroy_all_textures();
505
550506   if (m_yuv_lookup != NULL)
551507   {
552508      global_free_array(m_yuv_lookup);
r243366r243367
577533{
578534   *xt = x - m_last_hofs;
579535   *yt = y - m_last_vofs;
580   if (*xt<0 || *xt >= window().m_blitwidth)
536   if (*xt<0 || *xt >= window().blitwidth())
581537      return 0;
582   if (*yt<0 || *yt >= window().m_blitheight)
538   if (*yt<0 || *yt >= window().blitheight())
583539      return 0;
584540   return 1;
585541}
r243366r243367
590546
591547void sdl_info::destroy_all_textures()
592548{
593   /* nothing to be done in soft mode */
549#if (SDLMAME_SDL2)
550   SDL_DestroyTexture(m_texture_id);
551   m_texture_id = NULL;
552#else
553   if (m_yuvsurf != NULL)
554   {
555      SDL_FreeYUVOverlay(m_yuvsurf);
556      m_yuvsurf = NULL;
557   }
558#endif
594559}
595560
596561
r243366r243367
618583   // lock it if we need it
619584#if (!SDLMAME_SDL2)
620585
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;
586   pitch = window().sdl_surface()->pitch;
587   bpp = window().sdl_surface()->format->BytesPerPixel;
588   rmask = window().sdl_surface()->format->Rmask;
589   gmask = window().sdl_surface()->format->Gmask;
590   bmask = window().sdl_surface()->format->Bmask;
626591//  amask = sdlsurf->format->Amask;
627592
628   if (window().m_blitwidth != m_old_blitwidth || window().m_blitheight != m_old_blitheight)
593   if (window().blitwidth() != m_old_blitwidth || window().blitheight() != m_old_blitheight)
629594   {
630595      if (sm->is_yuv)
631596         yuv_overlay_init();
632      m_old_blitwidth = window().m_blitwidth;
633      m_old_blitheight = window().m_blitheight;
597      m_old_blitwidth = window().blitwidth();
598      m_old_blitheight = window().blitheight();
634599      m_blittimer = 3;
635600   }
636601
637   if (SDL_MUSTLOCK(window().m_sdlsurf))
638      SDL_LockSurface(window().m_sdlsurf);
602   if (SDL_MUSTLOCK(window().sdl_surface()))
603      SDL_LockSurface(window().sdl_surface());
639604
640605   // Clear if necessary
641606   if (m_blittimer > 0)
642607   {
643      memset(window().m_sdlsurf->pixels, 0, window().m_height * window().m_sdlsurf->pitch);
608      memset(window().sdl_surface()->pixels, 0, window().height() * window().sdl_surface()->pitch);
644609      m_blittimer--;
645610   }
646611
r243366r243367
658623#endif
659624   }
660625   else
661      surfptr = (UINT8 *)window().m_sdlsurf->pixels;
626      surfptr = (UINT8 *)window().sdl_surface()->pixels;
662627#else
663628   //SDL_SelectRenderer(window().sdl_window);
664629
665   if (window().m_blitwidth != m_old_blitwidth || window().m_blitheight != m_old_blitheight)
630   if (window().blitwidth() != m_old_blitwidth || window().blitheight() != m_old_blitheight)
666631   {
667      SDL_RenderSetViewport(m_sdl_renderer, NULL);
632      //SDL_RenderSetViewport(m_sdl_renderer, NULL);
668633
669      SDL_DestroyTexture(m_texture_id);
670      setup_texture(window().m_blitwidth, window().m_blitheight);
671      m_old_blitwidth = window().m_blitwidth;
672      m_old_blitheight = window().m_blitheight;
634      if (m_texture_id != NULL)
635         SDL_DestroyTexture(m_texture_id);
636      setup_texture(window().blitwidth(), window().blitheight());
637      m_old_blitwidth = window().blitwidth();
638      m_old_blitheight = window().blitheight();
673639      m_blittimer = 3;
674640   }
675641
r243366r243367
697663#endif
698664   // get ready to center the image
699665   vofs = hofs = 0;
700   blitwidth = window().m_blitwidth;
701   blitheight = window().m_blitheight;
666   blitwidth = window().blitwidth();
667   blitheight = window().blitheight();
702668
703669   // figure out what coordinate system to use for centering - in window mode it's always the
704670   // SDL surface size.  in fullscreen the surface covers all monitors, so center according to
r243366r243367
710676   }
711677   else
712678   {
713      ch = window().m_height;
714      cw = window().m_width;
679      ch = window().height();
680      cw = window().width();
715681   }
716682
717683   // do not crash if the window's smaller than the blit area
r243366r243367
721687   }
722688   else if (video_config.centerv)
723689   {
724      vofs = (ch - window().m_blitheight) / 2;
690      vofs = (ch - window().blitheight()) / 2;
725691   }
726692
727693   if (blitwidth > cw)
r243366r243367
730696   }
731697   else if (video_config.centerh)
732698   {
733      hofs = (cw - window().m_blitwidth) / 2;
699      hofs = (cw - window().blitwidth()) / 2;
734700   }
735701
736702   m_last_hofs = hofs;
r243366r243367
744710      if (!sm->is_yuv)
745711      {
746712         surfptr += ((vofs * pitch) + (hofs * bpp));
747         mamewidth = blitwidth; //m_sdlsurf->w;
748         mameheight = blitheight; //m_sdlsurf->h;
713         mamewidth = blitwidth; //sdl_surface()->w;
714         mameheight = blitheight; //sdl_surface()->h;
749715      }
750716      else
751717      {
r243366r243367
770736
771737   for (render_primitive *prim = window().m_primlist->first(); prim != NULL; prim = prim->next())
772738   {
773      prim->bounds.x0 *= fw;
774      prim->bounds.x1 *= fw;
775      prim->bounds.y0 *= fh;
776      prim->bounds.y1 *= fh;
739      prim->bounds.x0 = floor(fw * prim->bounds.x0 + 0.5f);
740      prim->bounds.x1 = floor(fw * prim->bounds.x1 + 0.5f);
741      prim->bounds.y0 = floor(fh * prim->bounds.y0 + 0.5f);
742      prim->bounds.y1 = floor(fh * prim->bounds.y1 + 0.5f);
777743   }
778744
779745   // render to it
r243366r243367
818784
819785   // unlock and flip
820786#if (!SDLMAME_SDL2)
821   if (SDL_MUSTLOCK(window().m_sdlsurf)) SDL_UnlockSurface(window().m_sdlsurf);
787   if (SDL_MUSTLOCK(window().sdl_surface())) SDL_UnlockSurface(window().sdl_surface());
822788   if (!sm->is_yuv)
823789   {
824      SDL_Flip(window().m_sdlsurf);
790      SDL_Flip(window().sdl_surface());
825791   }
826792   else
827793   {
trunk/src/osd/sdl/input.c
r243366r243367
15471547   for (w = sdl_window_list; w != NULL; w = w->m_next)
15481548   {
15491549      //printf("w->window_id: %d\n", w->window_id);
1550      if (w->m_sdl_window == window)
1550      if (w->sdl_window() == window)
15511551      {
15521552         return w;
15531553      }
r243366r243367
17601760         devinfo->keyboard.state[OSD_SDL_INDEX_KEYSYM(&event.key.keysym)] = 0x80;
17611761#if (SDLMAME_SDL2)
17621762         if (event.key.keysym.sym < 0x20)
1763            ui_input_push_char_event(machine, sdl_window_list->m_target, event.key.keysym.sym);
1763            ui_input_push_char_event(machine, sdl_window_list->target(), event.key.keysym.sym);
17641764#else
1765         ui_input_push_char_event(machine, sdl_window_list->m_target, (unicode_char) event.key.keysym.unicode);
1765         ui_input_push_char_event(machine, sdl_window_list->target(), (unicode_char) event.key.keysym.unicode);
17661766#endif
17671767         break;
17681768      case SDL_KEYUP:
r243366r243367
18641864            sdl_window_info *window = GET_FOCUS_WINDOW(&event.button);
18651865            if (window != NULL && window->xy_to_render_target(event.button.x,event.button.y, &cx, &cy) )
18661866            {
1867               ui_input_push_mouse_down_event(machine, window->m_target, cx, cy);
1867               ui_input_push_mouse_down_event(machine, window->target(), cx, cy);
18681868               // FIXME Parameter ?
18691869               if ((click-last_click < 250)
18701870                     && (cx >= last_x - 4 && cx <= last_x  + 4)
18711871                     && (cy >= last_y - 4 && cy <= last_y  + 4) )
18721872               {
18731873                  last_click = 0;
1874                  ui_input_push_mouse_double_click_event(machine, window->m_target, cx, cy);
1874                  ui_input_push_mouse_double_click_event(machine, window->target(), cx, cy);
18751875               }
18761876               else
18771877               {
r243366r243367
18981898
18991899            if (window != NULL && window->xy_to_render_target(event.button.x,event.button.y, &cx, &cy) )
19001900            {
1901               ui_input_push_mouse_up_event(machine, window->m_target, cx, cy);
1901               ui_input_push_mouse_up_event(machine, window->target(), cx, cy);
19021902            }
19031903         }
19041904         break;
r243366r243367
19221922            sdl_window_info *window = GET_FOCUS_WINDOW(&event.motion);
19231923
19241924            if (window != NULL && window->xy_to_render_target(event.motion.x, event.motion.y, &cx, &cy) )
1925               ui_input_push_mouse_move_event(machine, window->m_target, cx, cy);
1925               ui_input_push_mouse_move_event(machine, window->target(), cx, cy);
19261926         }
19271927         break;
19281928      case SDL_JOYBALLMOTION:
r243366r243367
19371937         if (!event.active.gain)
19381938         {
19391939            sdl_window_info *window = GET_FOCUS_WINDOW(&event.motion);
1940            ui_input_push_mouse_leave_event(machine, window->m_target);
1940            ui_input_push_mouse_leave_event(machine, window->target());
19411941         }
19421942         break;
19431943      case SDL_QUIT:
r243366r243367
19561956            if (window != NULL )
19571957            {
19581958               osd_uchar_from_osdchar(&result, event.text.text, 1);
1959               ui_input_push_char_event(machine, window->m_target, result);
1959               ui_input_push_char_event(machine, window->target(), result);
19601960            }
19611961         }
19621962         break;
r243366r243367
19731973            machine.schedule_exit();
19741974            break;
19751975         case  SDL_WINDOWEVENT_LEAVE:
1976            ui_input_push_mouse_leave_event(machine, window->m_target);
1976            ui_input_push_mouse_leave_event(machine, window->target());
19771977            app_has_mouse_focus = 0;
19781978            break;
19791979         case SDL_WINDOWEVENT_MOVED:
r243366r243367
19971997#endif
19981998               {
19991999                  //printf("event data1,data2 %d x %d %ld\n", event.window.data1, event.window.data2, sizeof(SDL_Event));
2000                  if (event.window.data1 != window->m_width || event.window.data2 != window->m_height)
2000                  if (event.window.data1 != window->width() || event.window.data2 != window->height())
20012001                     window->window_resize(event.window.data1, event.window.data2);
20022002               }
20032003            }
trunk/src/osd/sdl/video.c
r243366r243367
113113      sdl_window_config conf;
114114      memset(&conf, 0, sizeof(conf));
115115      get_resolution(options().resolution(), options().resolution(index), &conf, TRUE);
116      if (sdlwindow_video_window_create(machine(), index, sdl_monitor_info::pick_monitor(options(), index), &conf))
116
117      // create window ...
118      sdl_window_info *win = global_alloc(sdl_window_info(machine(), index, sdl_monitor_info::pick_monitor(options(), index), &conf));
119
120      if (win->window_init())
117121         return false;
118122   }
119123
trunk/src/osd/sdl/window.c
r243366r243367
142142static void sdlwindow_update_cursor_state(running_machine &machine, sdl_window_info *window);
143143static void sdlwindow_sync(void);
144144
145static void set_starting_view(running_machine &machine, int index, sdl_window_info *window, const char *defview, const char *view);
146
147145//============================================================
148146//  execute_async
149147//============================================================
r243366r243367
480478{
481479   worker_param *      wp = (worker_param *) param;
482480   sdl_window_info *   window = wp->window();
481   int width = wp->new_width();
482   int height = wp->new_height();
483483
484484   ASSERT_WINDOW_THREAD();
485485
486486   window->renderer().destroy_all_textures();
487   window->renderer().resize(wp->new_width(), wp->new_height());
488487
489   window->blit_surface_size(wp->new_width(), wp->new_height());
488#if (SDLMAME_SDL2)
489   SDL_SetWindowSize(window->sdl_window(), width, height);
490   SDL_GetWindowSize(window->sdl_window(), &window->m_width, &window->m_height);
491#else
492   SDL_FreeSurface(window->m_sdlsurf);
490493
494   window->m_sdlsurf = SDL_SetVideoMode(width, height, 0,
495         SDL_SWSURFACE | SDL_ANYFORMAT | window->m_extra_flags);
496
497   window->m_width = window->m_sdlsurf->w;
498   window->m_height = window->m_sdlsurf->h;
499#endif
500
501
502   window->renderer().resize(window->m_width, window->m_height);
503
504   window->blit_surface_size(window->m_width, window->m_height);
505
491506   window->window_clear();
492507
493508   osd_free(wp);
r243366r243367
498513{
499514   ASSERT_MAIN_THREAD();
500515
501   if (width == this->m_width && height == this->m_height)
516   if (width == this->width() && height == this->height())
502517      return;
503518
504519   execute_async_wait(&sdlwindow_resize_wt, worker_param(this, width, height));
r243366r243367
554569   // If we are going fullscreen (leaving windowed) remember our windowed size
555570   if (!window->fullscreen())
556571   {
557      window->m_windowed_width = window->m_width;
558      window->m_windowed_height = window->m_height;
572      window->m_windowed_width = window->width();
573      window->m_windowed_height = window->height();
559574   }
560575
561576   window->renderer().destroy();
577
578#if (SDLMAME_SDL2)
579   if (window->fullscreen() && video_config.switchres)
580   {
581      SDL_SetWindowFullscreen(window->sdl_window(), 0);    // Try to set mode
582      SDL_SetWindowDisplayMode(window->sdl_window(), &window->m_original_mode);    // Try to set mode
583      SDL_SetWindowFullscreen(window->sdl_window(), SDL_WINDOW_FULLSCREEN);    // Try to set mode
584   }
585   SDL_DestroyWindow(window->sdl_window());
586#else
587   if (window->m_sdlsurf)
588   {
589      SDL_FreeSurface(window->m_sdlsurf);
590      window->m_sdlsurf = NULL;
591   }
592#endif
593
594
562595   sdlinput_release_keys(wp->machine());
563596
564597   // toggle the window mode
r243366r243367
591624void sdl_window_info::modify_prescale(running_machine &machine, int dir)
592625{
593626   worker_param wp = worker_param(machine, this);
594   int new_prescale = m_prescale;
627   int new_prescale = prescale();
595628
596   if (dir > 0 && m_prescale < 3)
597      new_prescale = m_prescale + 1;
598   if (dir < 0 && m_prescale > 1)
599      new_prescale = m_prescale - 1;
629   if (dir > 0 && prescale() < 3)
630      new_prescale = prescale() + 1;
631   if (dir < 0 && prescale() > 1)
632      new_prescale = prescale() - 1;
600633
601   if (new_prescale != m_prescale)
634   if (new_prescale != prescale())
602635   {
603636      if (m_fullscreen && video_config.switchres)
604637      {
r243366r243367
614647         execute_async_wait(destroy_all_textures_wt, wp);
615648         m_prescale = new_prescale;
616649      }
617      machine.ui().popup_time(1, "Prescale %d", m_prescale);
650      machine.ui().popup_time(1, "Prescale %d", prescale());
618651   }
619652}
620653
r243366r243367
645678      if (!window->fullscreen() && !sdlinput_should_hide_mouse(machine))
646679      {
647680         SDL_ShowCursor(SDL_ENABLE);
648         if (SDL_GetWindowGrab(window->m_sdl_window ))
649            SDL_SetWindowGrab(window->m_sdl_window, SDL_FALSE);
681         if (SDL_GetWindowGrab(window->sdl_window() ))
682            SDL_SetWindowGrab(window->sdl_window(), SDL_FALSE);
650683         SDL_SetRelativeMouseMode(SDL_FALSE);
651684      }
652685      else
653686      {
654687         SDL_ShowCursor(SDL_DISABLE);
655         if (!SDL_GetWindowGrab(window->m_sdl_window))
656            SDL_SetWindowGrab(window->m_sdl_window, SDL_TRUE);
688         if (!SDL_GetWindowGrab(window->sdl_window()))
689            SDL_SetWindowGrab(window->sdl_window(), SDL_TRUE);
657690         SDL_SetRelativeMouseMode(SDL_TRUE);
658691      }
659692      SDL_SetCursor(NULL); // Force an update in case the underlying driver has changed visibility
r243366r243367
706739//  (main thread)
707740//============================================================
708741
709int sdlwindow_video_window_create(running_machine &machine, int index, sdl_monitor_info *monitor, const sdl_window_config *config)
742int sdl_window_info::window_init()
710743{
711   sdl_window_info *window;
712744   worker_param *wp = (worker_param *) osd_malloc(sizeof(worker_param));
713745   int result;
714746
715747   ASSERT_MAIN_THREAD();
716748
717   // allocate a new window object
718   window = global_alloc(sdl_window_info(&machine, monitor, index, config));
719
720749   // set the initial maximized state
721750   // FIXME: Does not belong here
722   sdl_options &options = downcast<sdl_options &>(machine.options());
723   window->m_startmaximized = options.maximize();
751   sdl_options &options = downcast<sdl_options &>(m_machine.options());
752   m_startmaximized = options.maximize();
724753
725754   // add us to the list
726   *last_window_ptr = window;
727   last_window_ptr = &window->m_next;
755   *last_window_ptr = this;
756   last_window_ptr = &this->m_next;
728757
729   window->set_renderer(draw.create(window));
758   set_renderer(draw.create(this));
730759
731760   // create an event that we can use to skip blitting
732   window->m_rendered_event = osd_event_alloc(FALSE, TRUE);
761   m_rendered_event = osd_event_alloc(FALSE, TRUE);
733762
734763   // load the layout
735   window->m_target = machine.render().target_alloc();
764   m_target = m_machine.render().target_alloc();
736765
737766   // set the specific view
738   set_starting_view(machine, index, window, options.view(), options.view(index));
767   set_starting_view(m_machine, m_index, options.view(), options.view(m_index));
739768
740769   // make the window title
741770   if (video_config.numscreens == 1)
742      sprintf(window->m_title, "%s: %s [%s]", emulator_info::get_appname(), machine.system().description, machine.system().name);
771      sprintf(m_title, "%s: %s [%s]", emulator_info::get_appname(), m_machine.system().description, m_machine.system().name);
743772   else
744      sprintf(window->m_title, "%s: %s [%s] - Screen %d", emulator_info::get_appname(), machine.system().description, machine.system().name, index);
773      sprintf(m_title, "%s: %s [%s] - Screen %d", emulator_info::get_appname(), m_machine.system().description, m_machine.system().name, m_index);
745774
746   wp->set_window(window);
775   wp->set_window(this);
747776
748777   // FIXME: pass error back in a different way
749778   if (multithreading_enabled)
r243366r243367
765794   return 0;
766795
767796error:
768   window->video_window_destroy(machine);
797   video_window_destroy(m_machine);
769798   // free the window itself
770   global_free(window);
771799   return 1;
772800}
773801
r243366r243367
787815   // free the textures etc
788816   window->renderer().destroy();
789817
818#if (SDLMAME_SDL2)
819   if (window->fullscreen() && video_config.switchres)
820   {
821      SDL_SetWindowFullscreen(window->sdl_window(), 0);    // Try to set mode
822      SDL_SetWindowDisplayMode(window->sdl_window(), &window->m_original_mode);    // Try to set mode
823      SDL_SetWindowFullscreen(window->sdl_window(), SDL_WINDOW_FULLSCREEN);    // Try to set mode
824   }
825   SDL_DestroyWindow(window->sdl_window());
826#else
827   if (window->m_sdlsurf)
828   {
829      SDL_FreeSurface(window->m_sdlsurf);
830      window->m_sdlsurf = NULL;
831   }
832#endif
833
790834   // release all keys ...
791835   sdlinput_release_keys(wp->machine());
792836
r243366r243367
843887   m_target->compute_minimum_size(minimum_width, minimum_height);
844888
845889   // use those as the target for now
846   target_width = minimum_width * MAX(1, m_prescale);
847   target_height = minimum_height * MAX(1, m_prescale);
890   target_width = minimum_width * MAX(1, prescale());
891   target_height = minimum_height * MAX(1, prescale());
848892
849893   // if we're not stretching, allow some slop on the minimum since we can handle it
850894   {
r243366r243367
910954   m_target->compute_minimum_size(minimum_width, minimum_height);
911955
912956   // use those as the target for now
913   target_width = minimum_width * MAX(1, m_prescale);
914   target_height = minimum_height * MAX(1, m_prescale);
957   target_width = minimum_width * MAX(1, prescale());
958   target_height = minimum_height * MAX(1, prescale());
915959
916960   // if we're not stretching, allow some slop on the minimum since we can handle it
917961   {
r243366r243367
10031047
10041048         if (!this->m_fullscreen)
10051049         {
1006            blit_surface_size(m_width, m_height);
1050            blit_surface_size(width(), height());
10071051            //Don't resize window without user interaction;
10081052            //window_resize(blitwidth, blitheight);
10091053         }
r243366r243367
10491093//  (main thread)
10501094//============================================================
10511095
1052static void set_starting_view(running_machine &machine, int index, sdl_window_info *window, const char *defview, const char *view)
1096void sdl_window_info::set_starting_view(running_machine &machine, int index, const char *defview, const char *view)
10531097{
10541098   int viewindex;
10551099
r243366r243367
10601104      view = defview;
10611105
10621106   // query the video system to help us pick a view
1063   viewindex = window->m_target->configured_view(view, index, video_config.numscreens);
1107   viewindex = target()->configured_view(view, index, video_config.numscreens);
10641108
10651109   // set the view
1066   window->m_target->set_view(viewindex);
1067   window->m_start_viewscreen=viewindex;
1110   target()->set_view(viewindex);
1111   m_start_viewscreen=viewindex;
10681112}
10691113
10701114
r243366r243367
11601204   window->m_sdl_window = SDL_CreateWindow(window->m_title,
11611205         window->monitor()->position_size().x, window->monitor()->position_size().y,
11621206         tempwidth, tempheight, window->m_extra_flags);
1163   //window().m_sdl_window = SDL_CreateWindow(window().m_title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
1207   //window().sdl_window() = SDL_CreateWindow(window().m_title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
11641208   //      width, height, m_extra_flags);
11651209
11661210   if  ( window->m_sdl_window == NULL )
r243366r243367
11761220   {
11771221      SDL_DisplayMode mode;
11781222      //SDL_GetCurrentDisplayMode(window().monitor()->handle, &mode);
1179      SDL_GetWindowDisplayMode(window->m_sdl_window, &mode);
1223      SDL_GetWindowDisplayMode(window->sdl_window(), &mode);
11801224      window->m_original_mode = mode;
11811225      mode.w = tempwidth;
11821226      mode.h = tempheight;
11831227      if (window->m_refresh)
11841228         mode.refresh_rate = window->m_refresh;
11851229
1186      SDL_SetWindowDisplayMode(window->m_sdl_window, &mode);    // Try to set mode
1230      SDL_SetWindowDisplayMode(window->sdl_window(), &mode);    // Try to set mode
11871231#ifndef SDLMAME_WIN32
11881232      /* FIXME: Warp the mouse to 0,0 in case a virtual desktop resolution
11891233       * is in place after the mode switch - which will most likely be the case
11901234       * This is a hack to work around a deficiency in SDL2
11911235       */
1192      SDL_WarpMouseInWindow(window->m_sdl_window, 1, 1);
1236      SDL_WarpMouseInWindow(window->sdl_window(), 1, 1);
11931237#endif
11941238   }
11951239   else
11961240   {
1197      //SDL_SetWindowDisplayMode(window().m_sdl_window, NULL); // Use desktop
1241      //SDL_SetWindowDisplayMode(window().sdl_window(), NULL); // Use desktop
11981242   }
11991243
12001244   // show window
12011245
1202   SDL_ShowWindow(window->m_sdl_window);
1203   //SDL_SetWindowFullscreen(window().m_sdl_window, window().fullscreen);
1204   SDL_RaiseWindow(window->m_sdl_window);
1246   SDL_ShowWindow(window->sdl_window());
1247   //SDL_SetWindowFullscreen(window().sdl_window(), window().fullscreen);
1248   SDL_RaiseWindow(window->sdl_window());
12051249
1206   SDL_GetWindowSize(window->m_sdl_window, &window->m_width, &window->m_height);
1250   SDL_GetWindowSize(window->sdl_window(), &window->m_width, &window->m_height);
12071251
12081252#else
12091253   window->m_extra_flags = (window->fullscreen() ?  SDL_FULLSCREEN : SDL_RESIZABLE);
r243366r243367
12381282   window->m_width = window->m_sdlsurf->w;
12391283   window->m_height = window->m_sdlsurf->h;
12401284
1241   window->m_screen_width = 0;
1242   window->m_screen_height = 0;
1243
12441285   // set the window title
12451286   SDL_WM_SetCaption(window->m_title, "SDLMAME");
12461287#endif
12471288
12481289   // initialize the drawing backend
1249   if (window->renderer().create(window->m_width, window->m_height))
1290   if (window->renderer().create(window->width(), window->height()))
12501291      return (void *) &result[1];
12511292
12521293   // Make sure we have a consistent state
trunk/src/osd/sdl/window.h
r243366r243367
7575class sdl_window_info
7676{
7777public:
78   sdl_window_info(running_machine *a_machine, sdl_monitor_info *a_monitor,
79         int index, const sdl_window_config *config)
80   : m_next(NULL), m_minwidth(0), m_minheight(0),
81      m_startmaximized(0),
82      m_rendered_event(0), m_target(0), m_primlist(NULL),
83      m_width(0), m_height(0), m_blitwidth(0), m_blitheight(0),
78   sdl_window_info(running_machine &a_machine, int index, sdl_monitor_info *a_monitor,
79         const sdl_window_config *config)
80   : m_next(NULL), m_primlist(NULL),
8481      m_start_viewscreen(0),
82      // Following three are used by input code to defer resizes
8583#if (SDLMAME_SDL2)
86      m_sdl_window(NULL),
8784      m_resize_width(0),
8885      m_resize_height(0),
8986      m_last_resize(0),
87#endif
88       m_minwidth(0), m_minheight(0),
89      m_rendered_event(0), m_target(0),
90      m_width(0), m_height(0), m_blitwidth(0), m_blitheight(0),
91#if (SDLMAME_SDL2)
92      m_sdl_window(NULL),
93
9094#else
9195      m_sdlsurf(NULL),
92      m_screen_width(0), m_screen_height(0),
9396#endif
9497      m_machine(a_machine), m_monitor(a_monitor), m_fullscreen(0), m_index(0)
9598   {
r243366r243367
112115      global_free(m_renderer);
113116   }
114117
118   int window_init();
119
115120   void video_window_update(running_machine &machine);
116121   void toggle_full_screen(running_machine &machine);
117122   void modify_prescale(running_machine &machine, int dir);
r243366r243367
122127   void get_min_bounds(int *window_width, int *window_height, int constrain);
123128   void get_max_bounds(int *window_width, int *window_height, int constrain);
124129
125   running_machine &machine() const { assert(m_machine != NULL); return *m_machine; }
130   running_machine &machine() const { return m_machine; }
126131   sdl_monitor_info *monitor() const { return m_monitor; }
127132   int fullscreen() const { return m_fullscreen; }
128133
r243366r243367
130135
131136   void blit_surface_size(int window_width, int window_height);
132137   void pick_best_mode(int *fswidth, int *fsheight);
138   void set_starting_view(running_machine &machine, int index, const char *defview, const char *view);
139
133140   int index() const { return m_index; }
134141
135142   int xy_to_render_target(int x, int y, int *xt, int *yt);
136143
144
145   render_target *target() { return m_target; }
146#if (SDLMAME_SDL2)
147   SDL_Window *sdl_window() { return m_sdl_window; }
148#else
149   SDL_Surface *sdl_surface() { return m_sdlsurf; }
150#endif
151   int   width() const { return m_width; }
152   int height() const { return m_height; }
153
154   int   blitwidth() const { return m_blitwidth; }
155   int blitheight() const { return m_blitheight; }
156   int prescale() const { return m_prescale; }
157
137158   // Pointer to next window
138159   sdl_window_info *   m_next;
139160
161   // FIXME: renderer should deal with this
162   render_primitive_list *m_primlist;
163   int                 m_start_viewscreen;
164#if (SDLMAME_SDL2)
165   // These are used in combine resizing events ... #if SDL13_COMBINE_RESIZE
166   int                 m_resize_width;
167   int                 m_resize_height;
168   osd_ticks_t         m_last_resize;
169#endif
170
171private:
140172   // window handle and info
141173   char                m_title[256];
142174
r243366r243367
152184   // rendering info
153185   osd_event *         m_rendered_event;
154186   render_target *     m_target;
155   render_primitive_list *m_primlist;
156187
157   // cache of physical m_width and m_height
188   // cache of physical width() and height()
158189   int                 m_width;
159190   int                 m_height;
160191
161   // current m_blitwidth and m_height
192   // current m_blitwidth and height()
162193   int                 m_blitwidth;
163194   int                 m_blitheight;
164195
165   int                 m_start_viewscreen;
166196
167   // GL specific
168197   int                 m_prescale;
169198
170199#if (SDLMAME_SDL2)
r243366r243367
172201   SDL_Window          *m_sdl_window;
173202   // Original display_mode
174203   SDL_DisplayMode m_original_mode;
175   // These are used in combine resizing events ... #if SDL13_COMBINE_RESIZE
176   int                 m_resize_width;
177   int                 m_resize_height;
178   osd_ticks_t         m_last_resize;
179204#else
180205   // SDL surface
181206   SDL_Surface         *m_sdlsurf;
207#endif
182208
183   int                 m_screen_width;
184   int                 m_screen_height;
185#endif
186209   int             m_extra_flags;
187210
188211   void set_renderer(osd_renderer *renderer)
r243366r243367
197220   void constrain_to_aspect_ratio(int *window_width, int *window_height, int adjustment);
198221
199222   // Pointer to machine
200   running_machine *   m_machine;
223   running_machine &   m_machine;
201224   // monitor info
202225   sdl_monitor_info *  m_monitor;
203226   int                 m_fullscreen;
r243366r243367
234257//  PROTOTYPES
235258//============================================================
236259
237// creation/deletion of windows
238int sdlwindow_video_window_create(running_machine &machine, int index, sdl_monitor_info *monitor, const sdl_window_config *config);
239
240260//============================================================
241261// PROTOTYPES - drawsdl.c
242262//============================================================


Previous 199869 Revisions Next


© 1997-2024 The MAME Team