Some more code alignment. (nw)

This commit is contained in:
couriersud 2015-02-04 18:16:42 +01:00
parent 2ef1f9aed0
commit 07bae39a05
4 changed files with 203 additions and 145 deletions

View File

@ -165,6 +165,17 @@ public:
INT32 m_blittimer;
UINT32 m_extra_flags;
#if (SDLMAME_SDL2)
// Original display_mode
SDL_DisplayMode m_original_mode;
SDL_GLContext m_gl_context_id;
#else
// SDL surface
SDL_Surface *m_sdlsurf;
#endif
SDL_Renderer * m_renderer;
simple_list<texture_info> m_texlist; // list of active textures
@ -180,9 +191,6 @@ public:
// Stats
INT64 m_last_blit_time;
INT64 m_last_blit_pixels;
// Original display_mode
SDL_DisplayMode m_original_mode;
};
struct copy_info_t {
@ -201,6 +209,7 @@ struct copy_info_t {
copy_info_t *next;
};
//============================================================
// PROTOTYPES
//============================================================
@ -453,7 +462,7 @@ static int RendererSupportsFormat(SDL_Renderer *renderer, Uint32 format, Uint32
}
//============================================================
// drawsdl2_init
// drawsdl_init
//============================================================
static void add_list(copy_info_t **head, copy_info_t *element, Uint32 bm)
@ -517,25 +526,12 @@ int drawsdl2_init(running_machine &machine, sdl_draw_info *callbacks)
else
osd_printf_verbose("Loaded opengl shared library: %s\n", stemp ? stemp : "<default>");
/* Enable bilinear filtering in case it is supported.
* This applies to all texture operations. However, artwort is pre-scaled
* and thus shouldn't be affected.
*/
if (video_config.filter)
{
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "1");
}
else
{
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "0");
}
return 0;
}
//============================================================
// drawsdl2_exit
// drawsdl_exit
//============================================================
static void drawsdl2_exit(void)
@ -671,6 +667,19 @@ int sdl_info13::create(int width, int height)
// create renderer
/* Enable bilinear filtering in case it is supported.
* This applies to all texture operations. However, artwort is pre-scaled
* and thus shouldn't be affected.
*/
if (video_config.filter)
{
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "1");
}
else
{
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "0");
}
if (video_config.waitvsync)
m_renderer = SDL_CreateRenderer(window().m_sdl_window, -1, SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED);
else
@ -690,11 +699,15 @@ int sdl_info13::create(int width, int height)
#else
m_extra_flags = (window().fullscreen() ? SDL_FULLSCREEN : SDL_RESIZABLE);
m_extra_flags |= SDL_DOUBLEBUF;
if (check_flag(FLAG_NEEDS_OPENGL))
if (this->check_flag(FLAG_NEEDS_DOUBLEBUF))
m_extra_flags |= SDL_DOUBLEBUF;
if (this->check_flag(FLAG_NEEDS_ASYNCBLIT))
m_extra_flags |= SDL_ASYNCBLIT;
if (this->check_flag(FLAG_NEEDS_OPENGL))
{
m_extra_flags |= SDL_OPENGL;
m_extra_flags |= SDL_DOUBLEBUF | SDL_OPENGL;
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
#if (SDL_VERSION_ATLEAST(1,2,10)) && (!defined(SDLMAME_EMSCRIPTEN))
SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, video_config.waitvsync ? 1 : 0);
@ -752,10 +765,14 @@ void sdl_info13::resize(int width, int height)
void sdl_info13::destroy()
{
// free the memory in the window
destroy_all_textures();
#if (SDLMAME_SDL2)
if (check_flag(FLAG_NEEDS_OPENGL))
SDL_GL_DeleteContext(m_gl_context_id);
if (window().fullscreen() && video_config.switchres)
{
SDL_SetWindowFullscreen(window().m_sdl_window, 0); // Try to set mode
@ -764,7 +781,13 @@ void sdl_info13::destroy()
}
SDL_DestroyWindow(window().m_sdl_window);
#else
if (m_sdlsurf)
{
SDL_FreeSurface(m_sdlsurf);
m_sdlsurf = NULL;
}
#endif
}
//============================================================
@ -793,6 +816,22 @@ int sdl_info13::xy_to_render_target(int x, int y, int *xt, int *yt)
return 1;
}
//============================================================
// drawsdl_destroy_all_textures
//============================================================
void sdl_info13::destroy_all_textures()
{
if(window().m_primlist)
{
window().m_primlist->acquire_lock();
m_texlist.reset();
window().m_primlist->release_lock();
}
else
m_texlist.reset();
}
//============================================================
// sdl_info::draw
//============================================================
@ -1224,15 +1263,3 @@ texture_info * sdl_info13::texture_update(const render_primitive &prim)
return texture;
}
void sdl_info13::destroy_all_textures()
{
if(window().m_primlist)
{
window().m_primlist->acquire_lock();
m_texlist.reset();
window().m_primlist->release_lock();
}
else
m_texlist.reset();
}

View File

@ -811,11 +811,15 @@ int sdl_info_ogl::create(int width, int height)
#else
m_extra_flags = (window().fullscreen() ? SDL_FULLSCREEN : SDL_RESIZABLE);
m_extra_flags |= SDL_DOUBLEBUF;
if (check_flag(FLAG_NEEDS_OPENGL))
if (this->check_flag(FLAG_NEEDS_DOUBLEBUF))
m_extra_flags |= SDL_DOUBLEBUF;
if (this->check_flag(FLAG_NEEDS_ASYNCBLIT))
m_extra_flags |= SDL_ASYNCBLIT;
if (this->check_flag(FLAG_NEEDS_OPENGL))
{
m_extra_flags |= SDL_OPENGL;
m_extra_flags |= SDL_DOUBLEBUF | SDL_OPENGL;
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
#if (SDL_VERSION_ATLEAST(1,2,10)) && (!defined(SDLMAME_EMSCRIPTEN))
SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, video_config.waitvsync ? 1 : 0);
@ -908,7 +912,8 @@ void sdl_info_ogl::destroy()
destroy_all_textures();
#if (SDLMAME_SDL2)
SDL_GL_DeleteContext(m_gl_context_id);
if (check_flag(FLAG_NEEDS_OPENGL))
SDL_GL_DeleteContext(m_gl_context_id);
if (window().fullscreen() && video_config.switchres)
{
SDL_SetWindowFullscreen(window().m_sdl_window, 0); // Try to set mode
@ -942,6 +947,7 @@ void sdl_info_ogl::clear()
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().m_blitwidth)
@ -951,6 +957,90 @@ int sdl_info_ogl::xy_to_render_target(int x, int y, int *xt, int *yt)
return 1;
}
//============================================================
// drawsdl_destroy_all_textures
//============================================================
void sdl_info_ogl::destroy_all_textures()
{
texture_info *texture = NULL;
int lock=FALSE;
int i;
if ( !m_initialized )
return;
#if (SDLMAME_SDL2)
SDL_GL_MakeCurrent(window().m_sdl_window, m_gl_context_id);
#endif
if(window().m_primlist)
{
lock=TRUE;
window().m_primlist->acquire_lock();
}
glFinish();
texture_all_disable();
glFinish();
glDisableClientState(GL_VERTEX_ARRAY);
i=0;
while (i<HASH_SIZE+OVERFLOW_SIZE)
{
texture = m_texhash[i];
m_texhash[i] = NULL;
if (texture != NULL)
{
if(m_usevbo)
{
pfn_glDeleteBuffers( 1, &(texture->texCoordBufferName) );
texture->texCoordBufferName=0;
}
if(m_usepbo && texture->pbo)
{
pfn_glDeleteBuffers( 1, (GLuint *)&(texture->pbo) );
texture->pbo=0;
}
if( m_glsl_program_num > 1 )
{
assert(m_usefbo);
pfn_glDeleteFramebuffers(2, (GLuint *)&texture->mpass_fbo_mamebm[0]);
glDeleteTextures(2, (GLuint *)&texture->mpass_texture_mamebm[0]);
}
if ( m_glsl_program_mb2sc < m_glsl_program_num - 1 )
{
assert(m_usefbo);
pfn_glDeleteFramebuffers(2, (GLuint *)&texture->mpass_fbo_scrn[0]);
glDeleteTextures(2, (GLuint *)&texture->mpass_texture_scrn[0]);
}
glDeleteTextures(1, (GLuint *)&texture->texture);
if ( texture->data_own )
{
free(texture->data);
texture->data=NULL;
texture->data_own=FALSE;
}
global_free(texture);
}
i++;
}
if ( m_useglsl )
{
glsl_shader_free(m_glsl);
m_glsl = NULL;
}
m_initialized = 0;
if (lock)
window().m_primlist->release_lock();
}
//============================================================
// loadGLExtensions
//============================================================
@ -3107,84 +3197,5 @@ void sdl_info_ogl::texture_all_disable()
}
}
void sdl_info_ogl::destroy_all_textures()
{
texture_info *texture = NULL;
int lock=FALSE;
int i;
if ( !m_initialized )
return;
#if (SDLMAME_SDL2)
SDL_GL_MakeCurrent(window().m_sdl_window, m_gl_context_id);
#endif
if(window().m_primlist)
{
lock=TRUE;
window().m_primlist->acquire_lock();
}
glFinish();
texture_all_disable();
glFinish();
glDisableClientState(GL_VERTEX_ARRAY);
i=0;
while (i<HASH_SIZE+OVERFLOW_SIZE)
{
texture = m_texhash[i];
m_texhash[i] = NULL;
if (texture != NULL)
{
if(m_usevbo)
{
pfn_glDeleteBuffers( 1, &(texture->texCoordBufferName) );
texture->texCoordBufferName=0;
}
if(m_usepbo && texture->pbo)
{
pfn_glDeleteBuffers( 1, (GLuint *)&(texture->pbo) );
texture->pbo=0;
}
if( m_glsl_program_num > 1 )
{
assert(m_usefbo);
pfn_glDeleteFramebuffers(2, (GLuint *)&texture->mpass_fbo_mamebm[0]);
glDeleteTextures(2, (GLuint *)&texture->mpass_texture_mamebm[0]);
}
if ( m_glsl_program_mb2sc < m_glsl_program_num - 1 )
{
assert(m_usefbo);
pfn_glDeleteFramebuffers(2, (GLuint *)&texture->mpass_fbo_scrn[0]);
glDeleteTextures(2, (GLuint *)&texture->mpass_texture_scrn[0]);
}
glDeleteTextures(1, (GLuint *)&texture->texture);
if ( texture->data_own )
{
free(texture->data);
texture->data=NULL;
texture->data_own=FALSE;
}
global_free(texture);
}
i++;
}
if ( m_useglsl )
{
glsl_shader_free(m_glsl);
m_glsl = NULL;
}
m_initialized = 0;
if (lock)
window().m_primlist->release_lock();
}

View File

@ -50,8 +50,8 @@ class sdl_info : public osd_renderer
{
public:
sdl_info(sdl_window_info *w)
: osd_renderer(w, FLAG_NONE),
sdl_info(sdl_window_info *w, int extra_flags)
: osd_renderer(w, extra_flags),
m_blittimer(0),
m_extra_flags(0),
@ -164,8 +164,8 @@ static int shown_video_info = 0;
static const sdl_scale_mode scale_modes[] =
{
{ "none", 0, 0, 1, 1, SDL_DOUBLEBUF, 0, 0 },
{ "async", 0, 0, 1, 1, SDL_DOUBLEBUF | SDL_ASYNCBLIT, 0, 0 },
{ "none", 0, 0, 1, 1, osd_renderer::FLAG_NEEDS_DOUBLEBUF, 0, 0 },
{ "async", 0, 0, 1, 1, osd_renderer::FLAG_NEEDS_DOUBLEBUF | osd_renderer::FLAG_NEEDS_ASYNCBLIT, 0, 0 },
{ "yv12", 1, 1, 1, 1, 0, SDL_YV12_OVERLAY, yuv_RGB_to_YV12 },
{ "yv12x2", 1, 1, 2, 2, 0, SDL_YV12_OVERLAY, yuv_RGB_to_YV12X2 },
{ "yuy2", 1, 1, 1, 1, 0, SDL_YUY2_OVERLAY, yuv_RGB_to_YUY2 },
@ -178,10 +178,11 @@ static const sdl_scale_mode scale_modes[] =
{ "none", 0, 0, 1, 1, DRAW2_SCALEMODE_NEAREST, 0, 0 },
{ "hwblit", 1, 0, 1, 1, DRAW2_SCALEMODE_LINEAR, 0, 0 },
{ "hwbest", 1, 0, 1, 1, DRAW2_SCALEMODE_BEST, 0, 0 },
{ "yv12", 1, 1, 1, 1, DRAW2_SCALEMODE_NEAREST, SDL_PIXELFORMAT_YV12, yuv_RGB_to_YV12 },
{ "yv12x2", 1, 1, 2, 2, DRAW2_SCALEMODE_NEAREST, SDL_PIXELFORMAT_YV12, yuv_RGB_to_YV12X2 },
{ "yuy2", 1, 1, 1, 1, DRAW2_SCALEMODE_NEAREST, SDL_PIXELFORMAT_YUY2, yuv_RGB_to_YUY2 },
{ "yuy2x2", 1, 1, 2, 1, DRAW2_SCALEMODE_NEAREST, SDL_PIXELFORMAT_YUY2, yuv_RGB_to_YUY2X2 },
/* SDL1.2 uses interpolation as well */
{ "yv12", 1, 1, 1, 1, DRAW2_SCALEMODE_BEST, SDL_PIXELFORMAT_YV12, yuv_RGB_to_YV12 },
{ "yv12x2", 1, 1, 2, 2, DRAW2_SCALEMODE_BEST, SDL_PIXELFORMAT_YV12, yuv_RGB_to_YV12X2 },
{ "yuy2", 1, 1, 1, 1, DRAW2_SCALEMODE_BEST, SDL_PIXELFORMAT_YUY2, yuv_RGB_to_YUY2 },
{ "yuy2x2", 1, 1, 2, 1, DRAW2_SCALEMODE_BEST, SDL_PIXELFORMAT_YUY2, yuv_RGB_to_YUY2X2 },
{ NULL }
};
#endif
@ -220,15 +221,22 @@ int drawsdl_scale_mode(const char *s)
return -1;
}
//============================================================
// drawsdl_init
//============================================================
static osd_renderer *drawsdl_create(sdl_window_info *window)
{
return global_alloc(sdl_info(window));
const sdl_scale_mode *sm = &scale_modes[video_config.scale_mode];
// FIXME: QUALITY HINTS
#if (SDLMAME_SDL2)
return global_alloc(sdl_info(window, osd_renderer::FLAG_NONE));
#else
return global_alloc(sdl_info(window, sm->m_extra_flags));
#endif
}
//============================================================
// drawsdl_init
//============================================================
int drawsdl_init(sdl_draw_info *callbacks)
{
@ -252,15 +260,6 @@ static void drawsdl_exit(void)
{
}
//============================================================
// drawsdl_destroy_all_textures
//============================================================
void sdl_info::destroy_all_textures()
{
/* nothing to be done in soft mode */
}
//============================================================
// setup_texture for window
//============================================================
@ -457,9 +456,6 @@ int sdl_info::create(int width, int height)
else
m_extra_flags = 0;
/* set hints ... */
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, sm->sdl_scale_mode);
// create the SDL window
// soft driver also used | SDL_WINDOW_INPUT_GRABBED | SDL_WINDOW_MOUSE_FOCUS
m_extra_flags |= (window().fullscreen() ?
@ -519,6 +515,10 @@ int sdl_info::create(int width, int height)
// create renderer
/* set hints ... */
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, sm->sdl_scale_mode);
if (video_config.waitvsync)
m_sdl_renderer = SDL_CreateRenderer(window().m_sdl_window, -1, SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED);
else
@ -557,9 +557,12 @@ int sdl_info::create(int width, int height)
#else
m_extra_flags = (window().fullscreen() ? SDL_FULLSCREEN : SDL_RESIZABLE);
m_extra_flags |= sm->m_extra_flags;
if (this->check_flag(FLAG_NEEDS_DOUBLEBUF))
m_extra_flags |= SDL_DOUBLEBUF;
if (this->check_flag(FLAG_NEEDS_ASYNCBLIT))
m_extra_flags |= SDL_ASYNCBLIT;
if (check_flag(FLAG_NEEDS_OPENGL))
if (this->check_flag(FLAG_NEEDS_OPENGL))
{
m_extra_flags |= SDL_DOUBLEBUF | SDL_OPENGL;
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
@ -706,6 +709,16 @@ int sdl_info::xy_to_render_target(int x, int y, int *xt, int *yt)
return 1;
}
//============================================================
// drawsdl_destroy_all_textures
//============================================================
void sdl_info::destroy_all_textures()
{
/* nothing to be done in soft mode */
}
//============================================================
// sdl_info::draw
//============================================================

View File

@ -38,8 +38,15 @@ class osd_renderer
{
public:
static const int FLAG_NONE = 0;
static const int FLAG_NEEDS_OPENGL = 1;
/* Generic flags */
static const int FLAG_NONE = 0x0000;
static const int FLAG_NEEDS_OPENGL = 0x0001;
#if (!(SDLMAME_SDL2))
/* SDL 1.2 flags */
static const int FLAG_NEEDS_DOUBLEBUF = 0x0100;
static const int FLAG_NEEDS_ASYNCBLIT = 0x0200;
#endif
osd_renderer(sdl_window_info *window, const int flags)
: m_window(window), m_flags(flags) { }