From d685f05949ea2d8dd3c6db06084a7f6bb40e10f7 Mon Sep 17 00:00:00 2001 From: couriersud Date: Sun, 8 Feb 2015 16:07:22 +0100 Subject: [PATCH] sdl render operation moved towards the way window deals with renderers. --- src/osd/sdl/draw13.c | 62 ++++++++++++++---------- src/osd/sdl/drawbgfx.c | 50 +++++++++++--------- src/osd/sdl/drawogl.c | 98 +++++++++++++++++++++----------------- src/osd/sdl/drawsdl.c | 91 +++++++++++++++++++----------------- src/osd/sdl/input.c | 6 +-- src/osd/sdl/window.c | 104 +++++++++++++++++------------------------ src/osd/sdl/window.h | 62 ++++++++++++------------ 7 files changed, 249 insertions(+), 224 deletions(-) diff --git a/src/osd/sdl/draw13.c b/src/osd/sdl/draw13.c index fa8778f393b..42009477dff 100644 --- a/src/osd/sdl/draw13.c +++ b/src/osd/sdl/draw13.c @@ -145,22 +145,36 @@ public: sdl_info13(sdl_window_info *w) : osd_renderer(w, FLAG_NONE), m_blittimer(0), m_sdl_renderer(NULL), m_last_hofs(0), m_last_vofs(0), - m_last_width(0), m_last_height(0), + m_width(0), m_height(0), + m_blitwidth(0), m_blitheight(0), m_last_blit_time(0), m_last_blit_pixels(0) {} /* virtual */ int create(); /* virtual */ int draw(const UINT32 dc, const int update); /* virtual */ int xy_to_render_target(const int x, const int y, int *xt, int *yt); - /* virtual */ void destroy_all_textures(); /* virtual */ void destroy(); - /* virtual */ void clear(); + /* virtual */ render_primitive_list *get_primitives() + { + int nw = 0; int nh = 0; + window().blit_surface_size(nw, nh); + if (nw != m_blitwidth || nh != m_blitheight) + { + m_blitwidth = nw; m_blitheight = nh; + notify_changed(); + } + window().target()->set_bounds(m_blitwidth, m_blitheight, window().monitor()->aspect()); + return &window().target()->get_primitives(); + } +private: void render_quad(texture_info *texture, const render_primitive *prim, const int x, const int y); texture_info *texture_find(const render_primitive &prim, const quad_setup_data &setup); texture_info *texture_update(const render_primitive &prim); + void destroy_all_textures(); + INT32 m_blittimer; #if (SDLMAME_SDL2) @@ -176,8 +190,11 @@ public: float m_last_hofs; float m_last_vofs; - int m_last_width; - int m_last_height; + int m_width; + int m_height; + + int m_blitwidth; + int m_blitheight; // Stats INT64 m_last_blit_time; @@ -490,7 +507,7 @@ static osd_renderer *drawsdl2_create(sdl_window_info *window) } // FIXME: machine only used to access options. -int drawsdl2_init(running_machine &machine, sdl_draw_info *callbacks) +int drawsdl2_init(running_machine &machine, osd_draw_callbacks *callbacks) { const char *stemp; @@ -623,15 +640,6 @@ void sdl_info13::destroy() destroy_all_textures(); } -//============================================================ -// sdl_info::clear -//============================================================ - -void sdl_info13::clear() -{ - m_blittimer = 2; -} - //============================================================ // drawsdl_xy_to_render_target @@ -642,9 +650,9 @@ int sdl_info13::xy_to_render_target(int x, int y, int *xt, int *yt) *xt = x - m_last_hofs; *yt = y - m_last_vofs; - if (*xt<0 || *xt >= window().blitwidth()) + if (*xt<0 || *xt >= m_blitwidth) return 0; - if (*yt<0 || *yt >= window().blitheight()) + if (*yt<0 || *yt >= m_blitheight) return 0; return 1; } @@ -681,13 +689,19 @@ int sdl_info13::draw(UINT32 dc, int update) return 0; } - if ((window().width() != m_last_width) || (window().height() != m_last_height)) + int width = 0; int height = 0; + window().get_size(width,height); + + if (has_flags(FI_CHANGED) || (width != m_width) || (height != m_height)) { - m_last_width = window().width(); - m_last_height = window().height(); + destroy_all_textures(); + m_width = width; + m_height = height; SDL_RenderSetViewport(m_sdl_renderer, NULL); m_blittimer = 3; + clear_flags(FI_CHANGED); } + //SDL_SelectRenderer(window().sdl_window); if (m_blittimer > 0) @@ -714,17 +728,17 @@ int sdl_info13::draw(UINT32 dc, int update) } else { - ch = window().height(); - cw = window().width(); + ch = height; + cw = width; } if (video_config.centerv) { - vofs = (ch - window().blitheight()) / 2.0f; + vofs = (ch - m_blitheight) / 2.0f; } if (video_config.centerh) { - hofs = (cw - window().blitwidth()) / 2.0f; + hofs = (cw - m_blitwidth) / 2.0f; } } diff --git a/src/osd/sdl/drawbgfx.c b/src/osd/sdl/drawbgfx.c index 75729a11184..7bab29dd070 100644 --- a/src/osd/sdl/drawbgfx.c +++ b/src/osd/sdl/drawbgfx.c @@ -75,6 +75,7 @@ class sdl_info_bgfx : public osd_renderer public: sdl_info_bgfx(sdl_window_info *w) : osd_renderer(w, FLAG_NONE), m_blittimer(0), m_renderer(NULL), + m_blitwidth(0), m_blitheight(0), m_last_hofs(0), m_last_vofs(0), m_last_blit_time(0), m_last_blit_pixels(0) {} @@ -82,9 +83,19 @@ public: /* virtual */ int create(); /* virtual */ int draw(const UINT32 dc, const int update); /* virtual */ int xy_to_render_target(const int x, const int y, int *xt, int *yt); - /* virtual */ void destroy_all_textures(); /* virtual */ void destroy(); - /* virtual */ void clear(); + /* virtual */ render_primitive_list *get_primitives() + { + int nw = 0; int nh = 0; + window().blit_surface_size(nw, nh); + if (nw != m_blitwidth || nh != m_blitheight) + { + m_blitwidth = nw; m_blitheight = nh; + notify_changed(); + } + window().target()->set_bounds(m_blitwidth, m_blitheight, window().monitor()->aspect()); + return &window().target()->get_primitives(); + } // void render_quad(texture_info *texture, const render_primitive *prim, const int x, const int y); @@ -96,6 +107,8 @@ public: SDL_Renderer * m_renderer; //simple_list m_texlist; // list of active textures + int m_blitwidth; + int m_blitheight; float m_last_hofs; float m_last_vofs; @@ -121,7 +134,7 @@ static osd_renderer *drawbgfx_create(sdl_window_info *window) } -int drawbgfx_init(running_machine &machine, sdl_draw_info *callbacks) +int drawbgfx_init(running_machine &machine, osd_draw_callbacks *callbacks) { // fill in the callbacks callbacks->exit = drawbgfx_exit; @@ -138,11 +151,14 @@ int sdl_info_bgfx::create() { // create renderer + int width = 0; int height = 0; + + window().get_size(width, height); m_blittimer = 3; bgfx::sdlSetWindow(window().sdl_window()); bgfx::init(); - bgfx::reset(window().width(), window().height(), BGFX_RESET_VSYNC); + bgfx::reset(width, height, BGFX_RESET_VSYNC); // Enable debug text. bgfx::setDebug(BGFX_DEBUG_STATS);// BGFX_DEBUG_TEXT); @@ -158,9 +174,9 @@ int sdl_info_bgfx::xy_to_render_target(int x, int y, int *xt, int *yt) { *xt = x - m_last_hofs; *yt = y - m_last_vofs; - if (*xt<0 || *xt >= window().blitwidth()) + if (*xt<0 || *xt >= m_blitwidth) return 0; - if (*yt<0 || *yt >= window().blitheight()) + if (*yt<0 || *yt >= m_blitheight) return 0; return 1; } @@ -171,6 +187,11 @@ int sdl_info_bgfx::xy_to_render_target(int x, int y, int *xt, int *yt) int sdl_info_bgfx::draw(UINT32 dc, int update) { + + //if (has_flags(FI_CHANGED) || (window().width() != m_last_width) || (window().height() != m_last_height)) + // do something + //clear_flags(FI_CHANGED); + bgfx::setViewClear(0 , BGFX_CLEAR_COLOR|BGFX_CLEAR_DEPTH , 0x000000ff @@ -178,7 +199,7 @@ int sdl_info_bgfx::draw(UINT32 dc, int update) , 0 ); // Set view 0 default viewport. - bgfx::setViewRect(0, 0, 0, window().blitwidth(), window().blitheight()); + bgfx::setViewRect(0, 0, 0, m_blitwidth, m_blitheight); // This dummy draw call is here to make sure that view 0 is cleared // if no other draw calls are submitted to view 0. @@ -209,21 +230,8 @@ void sdl_info_bgfx::destroy() { // free the memory in the window - destroy_all_textures(); + // destroy_all_textures(); // Shutdown bgfx. bgfx::shutdown(); } - -void sdl_info_bgfx::destroy_all_textures() -{ -} - -//============================================================ -// TEXCOPY FUNCS -//============================================================ - -void sdl_info_bgfx::clear() -{ - m_blittimer = 2; -} diff --git a/src/osd/sdl/drawogl.c b/src/osd/sdl/drawogl.c index 135fb1bf69d..c7477a6bedf 100644 --- a/src/osd/sdl/drawogl.c +++ b/src/osd/sdl/drawogl.c @@ -224,7 +224,8 @@ public: sdl_info_ogl(sdl_window_info *window) : osd_renderer(window, FLAG_NEEDS_OPENGL), m_blittimer(0), m_screen_width(0), m_screen_height(0), - m_last_width(0), m_last_height(0), + m_width(0), m_height(0), + m_blitwidth(0), m_blitheight(0), #if (SDLMAME_SDL2) m_gl_context_id(0), #else @@ -255,9 +256,22 @@ public: /* virtual */ int create(); /* virtual */ int draw(const UINT32 dc, const int update); /* virtual */ int xy_to_render_target(const int x, const int y, int *xt, int *yt); - /* virtual */ void destroy_all_textures(); /* virtual */ void destroy(); - /* virtual */ void clear(); + /* virtual */ render_primitive_list *get_primitives() + { + int nw = 0; int nh = 0; + window().blit_surface_size(nw, nh); + if (nw != m_blitwidth || nh != m_blitheight) + { + m_blitwidth = nw; m_blitheight = nh; + notify_changed(); + } + window().target()->set_bounds(m_blitwidth, m_blitheight, window().monitor()->aspect()); + return &window().target()->get_primitives(); + } + +private: + void destroy_all_textures(); void loadGLExtensions(); void initialize_gl(); @@ -280,8 +294,10 @@ public: INT32 m_blittimer; int m_screen_width; int m_screen_height; - int m_last_width; - int m_last_height; + int m_width; + int m_height; + int m_blitwidth; + int m_blitheight; #if (SDLMAME_SDL2) SDL_GLContext m_gl_context_id; @@ -451,7 +467,7 @@ static osd_renderer *drawogl_create(sdl_window_info *window) return global_alloc(sdl_info_ogl(window)); } -int drawogl_init(running_machine &machine, sdl_draw_info *callbacks) +int drawogl_init(running_machine &machine, osd_draw_callbacks *callbacks) { // fill in the callbacks callbacks->exit = drawogl_exit; @@ -774,15 +790,6 @@ void sdl_info_ogl::destroy() } -//============================================================ -// sdl_info::clear -//============================================================ - -void sdl_info_ogl::clear() -{ - //FIXME: Handled in sdl_info::draw as well - m_blittimer = 3; -} //============================================================ // drawsdl_xy_to_render_target @@ -793,9 +800,9 @@ int sdl_info_ogl::xy_to_render_target(int x, int y, int *xt, int *yt) *xt = x - m_last_hofs; *yt = y - m_last_vofs; - if (*xt<0 || *xt >= window().blitwidth()) + if (*xt<0 || *xt >= m_blitwidth) return 0; - if (*yt<0 || *yt >= window().blitheight()) + if (*yt<0 || *yt >= m_blitheight) return 0; return 1; } @@ -1205,20 +1212,23 @@ int sdl_info_ogl::draw(UINT32 dc, int update) float vofs, hofs; int pendingPrimitive=GL_NO_PRIMITIVE, curPrimitive=GL_NO_PRIMITIVE, scrnum, is_vector; const screen_device *screen; + int width = 0; int height = 0; if (video_config.novideo) { return 0; } - if ((window().width() != m_last_width) || (window().height() != m_last_height)) + window().get_size(width, height); + + if (has_flags(FI_CHANGED) || (width != m_width) || (height != m_height)) { - m_last_width = window().width(); - m_last_height = window().height(); -#if (SDLMAME_SDL2) + destroy_all_textures(); + m_width = width; + m_height = height; m_blittimer = 3; -#endif m_init_context = 1; + clear_flags(FI_CHANGED); } #if (SDLMAME_SDL2) @@ -1284,16 +1294,18 @@ int sdl_info_ogl::draw(UINT32 dc, int update) m_blittimer--; } + // FIXME: remove m_surf_w and m_surf_h if ( !m_initialized || - window().width()!= m_surf_w || window().height()!= m_surf_h ) + m_width != m_surf_w || m_height != m_surf_h ) { + // FIXME:: this can be done in create! if ( !m_initialized ) { loadGLExtensions(); } - m_surf_w=window().width(); - m_surf_h=window().height(); + m_surf_w = m_width; + m_surf_h = m_height; // we're doing nothing 3d, so the Z-buffer is currently not interesting glDisable(GL_DEPTH_TEST); @@ -1334,10 +1346,10 @@ int sdl_info_ogl::draw(UINT32 dc, int update) // |_________| // (0,h) (w,h) - glViewport(0.0, 0.0, (GLsizei)window().width(), (GLsizei)window().height()); + glViewport(0.0, 0.0, (GLsizei) m_width, (GLsizei) m_height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); - glOrtho(0.0, (GLdouble)window().width(), (GLdouble)window().height(), 0.0, 0.0, -1.0); + glOrtho(0.0, (GLdouble) m_width, (GLdouble) m_height, 0.0, 0.0, -1.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); @@ -1364,17 +1376,17 @@ int sdl_info_ogl::draw(UINT32 dc, int update) } else { - ch = window().height(); - cw = window().width(); + ch = m_height; + cw = m_width; } if (video_config.centerv) { - vofs = (ch - window().blitheight()) / 2.0f; + vofs = (ch - m_blitheight) / 2.0f; } if (video_config.centerh) { - hofs = (cw - window().blitwidth()) / 2.0f; + hofs = (cw - m_blitwidth) / 2.0f; } } @@ -1555,12 +1567,12 @@ int sdl_info_ogl::draw(UINT32 dc, int update) // 1:1 tex coord CCW (0/0) (1/0) (1/1) (0/1) on texture dimensions m_texVerticex[0]=(GLfloat)0.0; m_texVerticex[1]=(GLfloat)0.0; - m_texVerticex[2]=(GLfloat)window().width(); + m_texVerticex[2]=(GLfloat)m_width; m_texVerticex[3]=(GLfloat)0.0; - m_texVerticex[4]=(GLfloat)window().width(); - m_texVerticex[5]=(GLfloat)window().height(); + m_texVerticex[4]=(GLfloat)m_width; + m_texVerticex[5]=(GLfloat)m_height; m_texVerticex[6]=(GLfloat)0.0; - m_texVerticex[7]=(GLfloat)window().height(); + m_texVerticex[7]=(GLfloat)m_height; } if(i>0) // first fetch already done @@ -1944,8 +1956,8 @@ int sdl_info_ogl::texture_shader_create(const render_texinfo *texsource, texture { int uniform_location; int i; - int surf_w_pow2 = get_valid_pow2_value (window().blitwidth(), texture->texpow2); - int surf_h_pow2 = get_valid_pow2_value (window().blitheight(), texture->texpow2); + int surf_w_pow2 = get_valid_pow2_value (m_blitwidth, texture->texpow2); + int surf_h_pow2 = get_valid_pow2_value (m_blitheight, texture->texpow2); assert ( texture->type==TEXTURE_TYPE_SHADER ); @@ -1992,7 +2004,7 @@ int sdl_info_ogl::texture_shader_create(const render_texinfo *texsource, texture pfn_glUniform2fvARB(uniform_location, 1, &(color_texture_pow2_sz[0])); GL_CHECK_ERROR_NORMAL(); - GLfloat screen_texture_sz[2] = { (GLfloat)window().blitwidth(), (GLfloat)window().blitheight() }; + GLfloat screen_texture_sz[2] = { (GLfloat) m_blitwidth, (GLfloat) m_blitheight }; uniform_location = pfn_glGetUniformLocationARB(m_glsl_program[i], "screen_texture_sz"); pfn_glUniform2fvARB(uniform_location, 1, &(screen_texture_sz[0])); GL_CHECK_ERROR_NORMAL(); @@ -2048,7 +2060,7 @@ int sdl_info_ogl::texture_shader_create(const render_texinfo *texsource, texture } osd_printf_verbose("GL texture: mpass screen-bmp 2x %dx%d (pow2 %dx%d)\n", - window().width(), window().height(), surf_w_pow2, surf_h_pow2); + m_width, m_height, surf_w_pow2, surf_h_pow2); } // GL_TEXTURE0 @@ -2758,11 +2770,11 @@ void sdl_info_ogl::texture_coord_update(texture_info *texture, const render_prim } else if ( texture->type == TEXTURE_TYPE_SHADER && shaderIdx>m_glsl_program_mb2sc ) { - int surf_w_pow2 = get_valid_pow2_value (window().width(), texture->texpow2); - int surf_h_pow2 = get_valid_pow2_value (window().height(), texture->texpow2); + int surf_w_pow2 = get_valid_pow2_value (m_width, texture->texpow2); + int surf_h_pow2 = get_valid_pow2_value (m_height, texture->texpow2); - ustop = (float)(window().width()) / (float)surf_w_pow2; - vstop = (float)(window().height()) / (float)surf_h_pow2; + ustop = (float)(m_width) / (float)surf_w_pow2; + vstop = (float)(m_height) / (float)surf_h_pow2; } else { diff --git a/src/osd/sdl/drawsdl.c b/src/osd/sdl/drawsdl.c index 3207391715c..222b2b0fc20 100644 --- a/src/osd/sdl/drawsdl.c +++ b/src/osd/sdl/drawsdl.c @@ -64,8 +64,8 @@ public: //m_hw_scale_height(0), m_last_hofs(0), m_last_vofs(0), - m_old_blitwidth(0), - m_old_blitheight(0), + m_blitwidth(0), + m_blitheight(0), m_last_width(0), m_last_height(0) { } @@ -73,10 +73,22 @@ public: /* virtual */ int create(); /* virtual */ int draw(const UINT32 dc, const int update); /* virtual */ int xy_to_render_target(const int x, const int y, int *xt, int *yt); - /* virtual */ void destroy_all_textures(); /* virtual */ void destroy(); - /* virtual */ void clear(); + /* virtual */ render_primitive_list *get_primitives() + { + int nw = 0; int nh = 0; + window().blit_surface_size(nw, nh); + if (nw != m_blitwidth || nh != m_blitheight) + { + m_blitwidth = nw; m_blitheight = nh; + notify_changed(); + } + window().target()->set_bounds(m_blitwidth, m_blitheight, window().monitor()->aspect()); + return &window().target()->get_primitives(); + } +private: + void destroy_all_textures(); void yuv_init(); #if (SDLMAME_SDL2) void setup_texture(int tempwidth, int tempheight); @@ -106,8 +118,8 @@ public: int m_last_hofs; int m_last_vofs; - int m_old_blitwidth; - int m_old_blitheight; + int m_blitwidth; + int m_blitheight; int m_last_width; int m_last_height; }; @@ -230,7 +242,7 @@ static osd_renderer *drawsdl_create(sdl_window_info *window) // drawsdl_init //============================================================ -int drawsdl_init(sdl_draw_info *callbacks) +int drawsdl_init(osd_draw_callbacks *callbacks) { // fill in the callbacks callbacks->create = drawsdl_create; @@ -419,6 +431,7 @@ static void drawsdl_show_info(struct SDL_RendererInfo *render_info) // a //============================================================ + int sdl_info::create() { @@ -465,7 +478,11 @@ int sdl_info::create() } } - setup_texture(window().width(), window().height()); +#if 0 + int w = 0, h = 0; + window().get_size(w, h); + setup_texture(w, h); +#endif #else #endif @@ -500,16 +517,6 @@ void sdl_info::destroy() } } -//============================================================ -// sdl_info::clear -//============================================================ - -void sdl_info::clear() -{ - //FIXME: Handled in sdl_info::draw as well - m_blittimer = 3; -} - //============================================================ // drawsdl_xy_to_render_target //============================================================ @@ -518,9 +525,9 @@ int sdl_info::xy_to_render_target(int x, int y, int *xt, int *yt) { *xt = x - m_last_hofs; *yt = y - m_last_vofs; - if (*xt<0 || *xt >= window().blitwidth()) + if (*xt<0 || *xt >= m_blitwidth) return 0; - if (*yt<0 || *yt >= window().blitheight()) + if (*yt<0 || *yt >= m_blitheight) return 0; return 1; } @@ -554,6 +561,7 @@ int sdl_info::draw(UINT32 dc, int update) UINT8 *surfptr; INT32 pitch; Uint32 rmask, gmask, bmask; + int width = 0; int height = 0; #if (SDLMAME_SDL2) Uint32 amask; #endif @@ -565,12 +573,20 @@ int sdl_info::draw(UINT32 dc, int update) return 0; } - if ((window().width() != m_last_width) || (window().height() != m_last_height)) + window().get_size(width, height); + if (has_flags(FI_CHANGED) || (width != m_last_width) || (height != m_last_height)) { - m_last_width = window().width(); - m_last_height = window().height(); + destroy_all_textures(); + clear_flags(FI_CHANGED); + m_blittimer = 3; + m_last_width = width; + m_last_height = height; #if (SDLMAME_SDL2) SDL_RenderSetViewport(m_sdl_renderer, NULL); + if (m_texture_id != NULL) + SDL_DestroyTexture(m_texture_id); + setup_texture(m_blitwidth, m_blitheight); + m_blittimer = 3; #else const sdl_scale_mode *sdl_sm = &scale_modes[video_config.scale_mode]; if (sdl_sm->is_yuv) @@ -589,7 +605,7 @@ int sdl_info::draw(UINT32 dc, int update) gmask = window().sdl_surface()->format->Gmask; bmask = window().sdl_surface()->format->Bmask; // amask = sdlsurf->format->Amask; - +#if 0 if (window().blitwidth() != m_old_blitwidth || window().blitheight() != m_old_blitheight) { if (sm->is_yuv) @@ -598,14 +614,14 @@ int sdl_info::draw(UINT32 dc, int update) m_old_blitheight = window().blitheight(); m_blittimer = 3; } - +#endif if (SDL_MUSTLOCK(window().sdl_surface())) SDL_LockSurface(window().sdl_surface()); // Clear if necessary if (m_blittimer > 0) { - memset(window().sdl_surface()->pixels, 0, window().height() * window().sdl_surface()->pitch); + memset(window().sdl_surface()->pixels, 0, height * window().sdl_surface()->pitch); m_blittimer--; } @@ -627,17 +643,6 @@ int sdl_info::draw(UINT32 dc, int update) #else //SDL_SelectRenderer(window().sdl_window); - if (window().blitwidth() != m_old_blitwidth || window().blitheight() != m_old_blitheight) - { - //SDL_RenderSetViewport(m_sdl_renderer, NULL); - - if (m_texture_id != NULL) - SDL_DestroyTexture(m_texture_id); - setup_texture(window().blitwidth(), window().blitheight()); - m_old_blitwidth = window().blitwidth(); - m_old_blitheight = window().blitheight(); - m_blittimer = 3; - } { Uint32 format; @@ -663,8 +668,8 @@ int sdl_info::draw(UINT32 dc, int update) #endif // get ready to center the image vofs = hofs = 0; - blitwidth = window().blitwidth(); - blitheight = window().blitheight(); + blitwidth = m_blitwidth; + blitheight = m_blitheight; // figure out what coordinate system to use for centering - in window mode it's always the // SDL surface size. in fullscreen the surface covers all monitors, so center according to @@ -676,8 +681,8 @@ int sdl_info::draw(UINT32 dc, int update) } else { - ch = window().height(); - cw = window().width(); + ch = height; + cw = width; } // do not crash if the window's smaller than the blit area @@ -687,7 +692,7 @@ int sdl_info::draw(UINT32 dc, int update) } else if (video_config.centerv) { - vofs = (ch - window().blitheight()) / 2; + vofs = (ch - m_blitheight) / 2; } if (blitwidth > cw) @@ -696,7 +701,7 @@ int sdl_info::draw(UINT32 dc, int update) } else if (video_config.centerh) { - hofs = (cw - window().blitwidth()) / 2; + hofs = (cw - m_blitwidth) / 2; } m_last_hofs = hofs; diff --git a/src/osd/sdl/input.c b/src/osd/sdl/input.c index 32b98f45be3..015e55b0df3 100644 --- a/src/osd/sdl/input.c +++ b/src/osd/sdl/input.c @@ -1938,6 +1938,7 @@ void sdlinput_poll(running_machine &machine) if (*event.text.text) { sdl_window_info *window = GET_FOCUS_WINDOW(&event.text); + //printf("Focus window is %p - wl %p\n", window, sdl_window_list); unicode_char result; if (window != NULL ) { @@ -1963,7 +1964,7 @@ void sdlinput_poll(running_machine &machine) app_has_mouse_focus = 0; break; case SDL_WINDOWEVENT_MOVED: - window->clear(); + window->notify_changed(); focus_window = window; break; case SDL_WINDOWEVENT_RESIZED: @@ -1983,8 +1984,7 @@ void sdlinput_poll(running_machine &machine) #endif { //printf("event data1,data2 %d x %d %ld\n", event.window.data1, event.window.data2, sizeof(SDL_Event)); - if (event.window.data1 != window->width() || event.window.data2 != window->height()) - window->resize(event.window.data1, event.window.data2); + window->resize(event.window.data1, event.window.data2); } } focus_window = window; diff --git a/src/osd/sdl/window.c b/src/osd/sdl/window.c index f075d2334d7..5cc6c06a05d 100644 --- a/src/osd/sdl/window.c +++ b/src/osd/sdl/window.c @@ -96,7 +96,7 @@ static SDL_threadID window_threadid; // debugger //static int in_background; -static sdl_draw_info draw; +static osd_draw_callbacks draw; struct worker_param { worker_param() @@ -382,8 +382,20 @@ INLINE int better_mode(int width0, int height0, int width1, int height1, float d return (fabs(desired_aspect - aspect0) < fabs(desired_aspect - aspect1)) ? 0 : 1; } -void sdl_window_info::blit_surface_size(int window_width, int window_height) +void sdl_window_info::blit_surface_size(int &blitwidth, int &blitheight) { + int window_width, window_height; + if ((!fullscreen()) || (video_config.switchres)) + { + get_size(window_width, window_height); + } + else + { + window_width = monitor()->center_width(); + window_height = monitor()->center_height(); + } + + INT32 newwidth, newheight; int xscale = 1, yscale = 1; float desired_aspect = 1.0f; @@ -453,11 +465,13 @@ void sdl_window_info::blit_surface_size(int window_width, int window_height) && (video_config.scale_mode == VIDEO_SCALE_MODE_NONE )) newwidth = window_width; - if ((m_blitwidth != newwidth) || (m_blitheight != newheight)) - clear(); - - m_blitwidth = newwidth; - m_blitheight = newheight; +#if 0 + // Fixme: notify_changed really necessary ? + if ((blitwidth != newwidth) || (blitheight != newheight)) + notify_changed(); +#endif + blitwidth = newwidth; + blitheight = newheight; } @@ -475,24 +489,15 @@ OSDWORK_CALLBACK( sdl_window_info::sdlwindow_resize_wt ) ASSERT_WINDOW_THREAD(); - window->renderer().destroy_all_textures(); - #if (SDLMAME_SDL2) SDL_SetWindowSize(window->sdl_window(), width, height); - SDL_GetWindowSize(window->sdl_window(), &window->m_width, &window->m_height); #else SDL_FreeSurface(window->m_sdlsurf); window->m_sdlsurf = SDL_SetVideoMode(width, height, 0, SDL_SWSURFACE | SDL_ANYFORMAT | window->m_extra_flags); - - window->m_width = window->m_sdlsurf->w; - window->m_height = window->m_sdlsurf->h; #endif - - window->blit_surface_size(window->m_width, window->m_height); - - window->clear(); + window->renderer().notify_changed(); osd_free(wp); return NULL; @@ -502,10 +507,11 @@ void sdl_window_info::resize(INT32 width, INT32 height) { ASSERT_MAIN_THREAD(); - if (width == this->width() && height == this->height()) - return; + int cw=0; int ch=0; + get_size(cw, ch); - execute_async_wait(&sdlwindow_resize_wt, worker_param(this, width, height)); + if (width != cw || height != ch) + execute_async_wait(&sdlwindow_resize_wt, worker_param(this, width, height)); } @@ -514,28 +520,28 @@ void sdl_window_info::resize(INT32 width, INT32 height) // (window thread) //============================================================ -OSDWORK_CALLBACK( sdl_window_info::sdlwindow_clear_surface_wt ) +OSDWORK_CALLBACK( sdl_window_info::notify_changed_wt ) { worker_param *wp = (worker_param *) param; sdl_window_info *window = wp->window(); ASSERT_WINDOW_THREAD(); - window->renderer().clear(); + window->renderer().notify_changed(); osd_free(wp); return NULL; } -void sdl_window_info::clear() +void sdl_window_info::notify_changed() { worker_param wp; if (SDL_ThreadID() == main_threadid) { - execute_async_wait(&sdlwindow_clear_surface_wt, worker_param(this)); + execute_async_wait(¬ify_changed_wt, worker_param(this)); } else - execute_sync(&sdlwindow_clear_surface_wt, worker_param(this)); + execute_sync(¬ify_changed_wt, worker_param(this)); } @@ -558,8 +564,7 @@ OSDWORK_CALLBACK( sdl_window_info::sdlwindow_toggle_full_screen_wt ) // If we are going fullscreen (leaving windowed) remember our windowed size if (!window->fullscreen()) { - window->m_windowed_width = window->width(); - window->m_windowed_height = window->height(); + window->get_size(window->m_windowed_width, window->m_windowed_height); } window->renderer().destroy(); @@ -598,18 +603,6 @@ void sdl_window_info::toggle_full_screen() execute_async_wait(&sdlwindow_toggle_full_screen_wt, worker_param(this)); } -OSDWORK_CALLBACK( sdl_window_info::destroy_all_textures_wt ) -{ - worker_param *wp = (worker_param *) param; - - sdl_window_info *window = wp->window(); - - window->renderer().destroy_all_textures(); - - osd_free(wp); - return NULL; -} - void sdl_window_info::modify_prescale(int dir) { worker_param wp = worker_param(this); @@ -633,7 +626,7 @@ void sdl_window_info::modify_prescale(int dir) } else { - execute_async_wait(destroy_all_textures_wt, wp); + notify_changed(); m_prescale = new_prescale; } machine().ui().popup_time(1, "Prescale %d", prescale()); @@ -1035,7 +1028,6 @@ void sdl_window_info::update() if (!this->m_fullscreen) { - blit_surface_size(width(), height()); //Don't resize window without user interaction; //window_resize(blitwidth, blitheight); } @@ -1053,20 +1045,10 @@ void sdl_window_info::update() if (osd_event_wait(m_rendered_event, event_wait_ticks)) { - if ((!fullscreen()) || (video_config.switchres)) - { - blit_surface_size(m_width, m_height); - } - else - { - blit_surface_size(monitor()->center_width(), monitor()->center_height()); - } // ensure the target bounds are up-to-date, and then get the primitives - m_target->set_bounds(m_blitwidth, m_blitheight, monitor()->aspect()); - - render_primitive_list &primlist = m_target->get_primitives(); + render_primitive_list &primlist = *m_renderer->get_primitives(); // and redraw now @@ -1165,7 +1147,7 @@ OSDWORK_CALLBACK( sdl_window_info::complete_create_wt ) #if (SDLMAME_SDL2) - if (window->renderer().check_flag(osd_renderer::FLAG_NEEDS_OPENGL)) + if (window->renderer().has_flags(osd_renderer::FLAG_NEEDS_OPENGL)) { SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); @@ -1197,7 +1179,7 @@ OSDWORK_CALLBACK( sdl_window_info::complete_create_wt ) if ( window->m_sdl_window == NULL ) { - if (window->renderer().check_flag(osd_renderer::FLAG_NEEDS_OPENGL)) + if (window->renderer().has_flags(osd_renderer::FLAG_NEEDS_OPENGL)) osd_printf_error("OpenGL not supported on this driver: %s\n", SDL_GetError()); else osd_printf_error("Window creation failed: %s\n", SDL_GetError()); @@ -1235,17 +1217,20 @@ OSDWORK_CALLBACK( sdl_window_info::complete_create_wt ) //SDL_SetWindowFullscreen(window().sdl_window(), window().fullscreen); SDL_RaiseWindow(window->sdl_window()); - SDL_GetWindowSize(window->sdl_window(), &window->m_width, &window->m_height); +#ifdef SDLMAME_WIN32 + if (window->fullscreen()) + SDL_SetWindowGrab(window->sdl_window(), SDL_TRUE); +#endif #else window->m_extra_flags = (window->fullscreen() ? SDL_FULLSCREEN : SDL_RESIZABLE); - if (window->renderer().check_flag(osd_renderer::FLAG_NEEDS_DOUBLEBUF)) + if (window->renderer().has_flags(osd_renderer::FLAG_NEEDS_DOUBLEBUF)) window->m_extra_flags |= SDL_DOUBLEBUF; - if (window->renderer().check_flag(osd_renderer::FLAG_NEEDS_ASYNCBLIT)) + if (window->renderer().has_flags(osd_renderer::FLAG_NEEDS_ASYNCBLIT)) window->m_extra_flags |= SDL_ASYNCBLIT; - if (window->renderer().check_flag(osd_renderer::FLAG_NEEDS_OPENGL)) + if (window->renderer().has_flags(osd_renderer::FLAG_NEEDS_OPENGL)) { window->m_extra_flags |= SDL_DOUBLEBUF | SDL_OPENGL; SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); @@ -1267,9 +1252,6 @@ OSDWORK_CALLBACK( sdl_window_info::complete_create_wt ) return (void *) &result[1]; } - window->m_width = window->m_sdlsurf->w; - window->m_height = window->m_sdlsurf->h; - // set the window title SDL_WM_SetCaption(window->m_title, "SDLMAME"); #endif diff --git a/src/osd/sdl/window.h b/src/osd/sdl/window.h index bc30b7b371c..4adeb6a960e 100644 --- a/src/osd/sdl/window.h +++ b/src/osd/sdl/window.h @@ -55,16 +55,27 @@ public: sdl_window_info &window() { return *m_window; } int flags() const { return m_flags; } - bool check_flag(const int flag) { return ((m_flags & flag)) == flag; } + bool has_flags(const int flag) { return ((m_flags & flag)) == flag; } + + void notify_changed() { set_flags(FI_CHANGED); } + + /* Interface to be implemented by render code */ virtual int create() = 0; virtual int draw(const UINT32 dc, const int update) = 0; + virtual render_primitive_list *get_primitives() = 0; virtual int xy_to_render_target(const int x, const int y, int *xt, int *yt) = 0; - virtual void destroy_all_textures() = 0; virtual void destroy() = 0; - virtual void clear() = 0; + +protected: + /* Internal flags */ + static const int FI_CHANGED = 0x010000; + + void set_flags(int aflag) { m_flags |= aflag; } + void clear_flags(int aflag) { m_flags &= ~aflag; } private: + sdl_window_info *m_window; int m_flags; }; @@ -86,7 +97,6 @@ public: #endif m_minwidth(0), m_minheight(0), m_rendered_event(0), m_target(0), - m_width(0), m_height(0), m_blitwidth(0), m_blitheight(0), #if (SDLMAME_SDL2) m_sdl_window(NULL), @@ -121,7 +131,18 @@ public: void modify_prescale(int dir); void resize(INT32 width, INT32 height); void destroy(); - void clear(); + + void notify_changed(); + + void get_size(int &w, int &h) + { +#if (SDLMAME_SDL2) + SDL_GetWindowSize(m_sdl_window, &w, &h); +#else + w = m_sdlsurf->w; h = m_sdlsurf->h; +#endif + } + int xy_to_render_target(int x, int y, int *xt, int *yt); running_machine &machine() const { return m_machine; } @@ -136,11 +157,8 @@ public: #else SDL_Surface *sdl_surface() { return m_sdlsurf; } #endif - int width() const { return m_width; } - int height() const { return m_height; } - int blitwidth() const { return m_blitwidth; } - int blitheight() const { return m_blitheight; } + void blit_surface_size(int &blitwidth, int &blitheight); int prescale() const { return m_prescale; } // Pointer to next window @@ -173,15 +191,6 @@ private: osd_event * m_rendered_event; render_target * m_target; - // cache of physical width() and height() - int m_width; - int m_height; - - // current m_blitwidth and height() - int m_blitwidth; - int m_blitheight; - - int m_prescale; #if (SDLMAME_SDL2) @@ -207,16 +216,12 @@ protected: private: void constrain_to_aspect_ratio(int *window_width, int *window_height, int adjustment); void update_cursor_state(); - void blit_surface_size(int window_width, int window_height); void pick_best_mode(int *fswidth, int *fsheight); void set_starting_view(running_machine &machine, int index, const char *defview, const char *view); void get_min_bounds(int *window_width, int *window_height, int constrain); void get_max_bounds(int *window_width, int *window_height, int constrain); void set_fullscreen(int afullscreen) { m_fullscreen = afullscreen; } - - - // Pointer to machine running_machine & m_machine; // monitor info @@ -231,15 +236,14 @@ private: static OSDWORK_CALLBACK( draw_video_contents_wt ); static OSDWORK_CALLBACK( sdlwindow_video_window_destroy_wt ); static OSDWORK_CALLBACK( sdlwindow_toggle_full_screen_wt ); - static OSDWORK_CALLBACK( sdlwindow_clear_surface_wt ); - static OSDWORK_CALLBACK( destroy_all_textures_wt ); + static OSDWORK_CALLBACK( notify_changed_wt ); static OSDWORK_CALLBACK( update_cursor_state_wt ); void measure_fps(UINT32 dc, int update); }; -struct sdl_draw_info +struct osd_draw_callbacks { osd_renderer *(*create)(sdl_window_info *window); void (*exit)(void); @@ -260,7 +264,7 @@ extern sdl_window_info *sdl_window_list; // PROTOTYPES - drawsdl.c //============================================================ -int drawsdl_init(sdl_draw_info *callbacks); +int drawsdl_init(osd_draw_callbacks *callbacks); const char *drawsdl_scale_mode_str(int index); int drawsdl_scale_mode(const char *s); @@ -268,18 +272,18 @@ int drawsdl_scale_mode(const char *s); // PROTOTYPES - drawogl.c //============================================================ -int drawogl_init(running_machine &machine, sdl_draw_info *callbacks); +int drawogl_init(running_machine &machine, osd_draw_callbacks *callbacks); //============================================================ // PROTOTYPES - draw13.c //============================================================ -int drawsdl2_init(running_machine &machine, sdl_draw_info *callbacks); +int drawsdl2_init(running_machine &machine, osd_draw_callbacks *callbacks); //============================================================ // PROTOTYPES - drawbgfx.c //============================================================ -int drawbgfx_init(running_machine &machine, sdl_draw_info *callbacks); +int drawbgfx_init(running_machine &machine, osd_draw_callbacks *callbacks); #endif /* __SDLWINDOW__ */