diff options
Diffstat (limited to 'src/osd/modules/render/drawsdl.cpp')
-rw-r--r-- | src/osd/modules/render/drawsdl.cpp | 482 |
1 files changed, 68 insertions, 414 deletions
diff --git a/src/osd/modules/render/drawsdl.cpp b/src/osd/modules/render/drawsdl.cpp index 221ac79ef4d..005d523cf9a 100644 --- a/src/osd/modules/render/drawsdl.cpp +++ b/src/osd/modules/render/drawsdl.cpp @@ -26,6 +26,8 @@ #include "osdsdl.h" #include "window.h" +#include "drawsdl.h" + //============================================================ // DEBUGGING //============================================================ @@ -34,119 +36,14 @@ // CONSTANTS //============================================================ -//============================================================ -// TYPES -//============================================================ - -struct sdl_scale_mode; - -#if (SDLMAME_SDL2) #define DRAW2_SCALEMODE_NEAREST "0" #define DRAW2_SCALEMODE_LINEAR "1" #define DRAW2_SCALEMODE_BEST "2" -#endif - -/* sdl_info is the information about SDL for the current screen */ -class sdl_info : public osd_renderer -{ -public: - - sdl_info(osd_window *w, int extra_flags) - : osd_renderer(w, extra_flags), - #if (SDLMAME_SDL2) - m_sdl_renderer(NULL), - m_texture_id(NULL), - #else - m_yuvsurf(NULL), - #endif - m_yuv_lookup(NULL), - m_yuv_bitmap(NULL), - //m_hw_scale_width(0), - //m_hw_scale_height(0), - m_last_hofs(0), - m_last_vofs(0), - m_blit_dim(0, 0), - m_last_dim(0, 0) - { } - - /* virtual */ int create() override; - /* virtual */ int draw(const int update) override; - /* virtual */ int xy_to_render_target(const int x, const int y, int *xt, int *yt) override; - /* virtual */ void destroy() override; - /* virtual */ render_primitive_list *get_primitives() override - { - osd_dim nd = window().blit_surface_size(); - if (nd != m_blit_dim) - { - m_blit_dim = nd; - notify_changed(); - } - window().target()->set_bounds(m_blit_dim.width(), m_blit_dim.height(), window().aspect()); - return &window().target()->get_primitives(); - } - -private: - void destroy_all_textures(); - void yuv_init(); -#if (SDLMAME_SDL2) - void setup_texture(const osd_dim &size); -#endif - void yuv_lookup_set(unsigned int pen, unsigned char red, - unsigned char green, unsigned char blue); - -#if (!SDLMAME_SDL2) - void yuv_overlay_init(); -#endif - - INT32 m_blittimer; - -#if (SDLMAME_SDL2) - SDL_Renderer *m_sdl_renderer; - SDL_Texture *m_texture_id; -#else - SDL_Overlay *m_yuvsurf; -#endif - - // YUV overlay - UINT32 *m_yuv_lookup; - UINT16 *m_yuv_bitmap; - - // if we leave scaling to SDL and the underlying driver, this - // is the render_target_width/height to use - - int m_last_hofs; - int m_last_vofs; - osd_dim m_blit_dim; - osd_dim m_last_dim; -}; - -struct sdl_scale_mode -{ - const char *name; - int is_scale; /* Scale mode? */ - int is_yuv; /* Yuv mode? */ - int mult_w; /* Width multiplier */ - int mult_h; /* Height multiplier */ -#if (!SDLMAME_SDL2) - int m_extra_flags; /* Texture/surface flags */ -#else - const char *sdl_scale_mode_hint; /* what to use as a hint ? */ -#endif - int pixel_format; /* Pixel/Overlay format */ - void (*yuv_blit)(const UINT16 *bitmap, UINT8 *ptr, const int pitch, const UINT32 *lookup, const int width, const int height); -}; - -//============================================================ -// INLINES -//============================================================ //============================================================ // PROTOTYPES //============================================================ -// core functions -static void drawsdl_exit(void); - // YUV overlays static void yuv_RGB_to_YV12(const UINT16 *bitmap, UINT8 *ptr, const int pitch, \ @@ -160,20 +57,6 @@ static void yuv_RGB_to_YUY2X2(const UINT16 *bitmap, UINT8 *ptr, const int pitch, // Static declarations -#if (!SDLMAME_SDL2) -static int shown_video_info = 0; - -static const sdl_scale_mode scale_modes[] = -{ - { "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 }, - { "yuy2x2", 1, 1, 2, 1, 0, SDL_YUY2_OVERLAY, yuv_RGB_to_YUY2X2 }, - { NULL } -}; -#else static const sdl_scale_mode scale_modes[] = { { "none", 0, 0, 1, 1, DRAW2_SCALEMODE_NEAREST, 0, 0 }, @@ -184,26 +67,7 @@ static const sdl_scale_mode scale_modes[] = { "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 - -//============================================================ -// drawsdl_scale_mode -//============================================================ - -const char *drawsdl_scale_mode_str(int index) -{ - const sdl_scale_mode *sm = scale_modes; - - while (index>0) - { - if (sm->name == NULL) - return NULL; - index--; - sm++; - } - return sm->name; + { nullptr } }; int drawsdl_scale_mode(const char *s) @@ -212,7 +76,7 @@ int drawsdl_scale_mode(const char *s) int index; index = 0; - while (sm->name != NULL) + while (sm->name != nullptr) { if (strcmp(sm->name, s) == 0) return index; @@ -222,50 +86,21 @@ int drawsdl_scale_mode(const char *s) return -1; } - -static osd_renderer *drawsdl_create(osd_window *window) -{ - // FIXME: QUALITY HINTS -#if (SDLMAME_SDL2) - return global_alloc(sdl_info(window, osd_renderer::FLAG_NONE)); -#else - const sdl_scale_mode *sm = &scale_modes[video_config.scale_mode]; - return global_alloc(sdl_info(window, sm->m_extra_flags)); -#endif -} - //============================================================ // drawsdl_init //============================================================ -int drawsdl_init(osd_draw_callbacks *callbacks) -{ - // fill in the callbacks - callbacks->create = drawsdl_create; - callbacks->exit = drawsdl_exit; - - if (SDLMAME_SDL2) - osd_printf_verbose("Using SDL multi-window soft driver (SDL 2.0+)\n"); - else - osd_printf_verbose("Using SDL single-window soft driver (SDL 1.2)\n"); - - return 0; -} - -//============================================================ -// drawsdl_exit -//============================================================ - -static void drawsdl_exit(void) +bool renderer_sdl2::init(running_machine &machine) { + osd_printf_verbose("Using SDL multi-window soft driver (SDL 2.0+)\n"); + return false; } //============================================================ // setup_texture for window //============================================================ -#if (SDLMAME_SDL2) -void sdl_info::setup_texture(const osd_dim &size) +void renderer_sdl2::setup_texture(const osd_dim &size) { const sdl_scale_mode *sdl_sm = &scale_modes[video_config.scale_mode]; SDL_DisplayMode mode; @@ -277,7 +112,7 @@ void sdl_info::setup_texture(const osd_dim &size) if (m_yuv_bitmap) { global_free_array(m_yuv_bitmap); - m_yuv_bitmap = NULL; + m_yuv_bitmap = nullptr; } fmt = (sdl_sm->pixel_format ? sdl_sm->pixel_format : mode.format); @@ -311,68 +146,16 @@ void sdl_info::setup_texture(const osd_dim &size) size.width(), size.height()); } } -#endif - -//============================================================ -// yuv_overlay_init -//============================================================ - -#if (!SDLMAME_SDL2) -void sdl_info::yuv_overlay_init() -{ - const sdl_scale_mode *sdl_sm = &scale_modes[video_config.scale_mode]; - int minimum_width, minimum_height; - - window().target()->compute_minimum_size(minimum_width, minimum_height); - - if (window().prescale()) - { - minimum_width *= window().prescale(); - minimum_height *= window().prescale(); - } - - if (m_yuvsurf != NULL) - { - SDL_FreeYUVOverlay(m_yuvsurf); - m_yuvsurf = NULL; - } - - if (m_yuv_bitmap != NULL) - { - global_free_array(m_yuv_bitmap); - } - - osd_printf_verbose("SDL: Creating %d x %d YUV-Overlay ...\n", minimum_width, minimum_height); - - m_yuv_bitmap = global_alloc_array(UINT16, minimum_width*minimum_height); - - m_yuvsurf = SDL_CreateYUVOverlay(minimum_width * sdl_sm->mult_w, minimum_height * sdl_sm->mult_h, - sdl_sm->pixel_format, window().sdl_surface()); - - if ( m_yuvsurf == NULL ) { - osd_printf_error("SDL: Couldn't create SDL_yuv_overlay: %s\n", SDL_GetError()); - //return 1; - } - - if (!shown_video_info) - { - osd_printf_verbose("YUV Mode : %s\n", sdl_sm->name); - osd_printf_verbose("YUV Overlay Size : %d x %d\n", minimum_width, minimum_height); - osd_printf_verbose("YUV Acceleration : %s\n", m_yuvsurf->hw_overlay ? "Hardware" : "Software"); - shown_video_info = 1; - } -} -#endif //============================================================ // drawsdl_show_info //============================================================ -#if (SDLMAME_SDL2) -static void drawsdl_show_info(struct SDL_RendererInfo *render_info) +void renderer_sdl2::show_info(struct SDL_RendererInfo *render_info) { #define RF_ENTRY(x) {x, #x } - static struct { + static struct + { int flag; const char *name; } rflist[] = @@ -386,51 +169,21 @@ static void drawsdl_show_info(struct SDL_RendererInfo *render_info) #endif RF_ENTRY(SDL_RENDERER_PRESENTVSYNC), RF_ENTRY(SDL_RENDERER_ACCELERATED), - {-1, NULL} + {-1, nullptr} }; - int i; osd_printf_verbose("window: using renderer %s\n", render_info->name ? render_info->name : "<unknown>"); - for (i = 0; rflist[i].name != NULL; i++) + for (int i = 0; rflist[i].name != nullptr; i++) if (render_info->flags & rflist[i].flag) osd_printf_verbose("renderer: flag %s\n", rflist[i].name); } -#endif //============================================================ -// sdl_info::create -// a -// a -// a -// a -// a -// a -// a -// a -// a -// a -// a -// a -// a -// a -// a -// a -// a -// a -// a -// a -// a -// a -// a -// a -// a -// a +// renderer_sdl2::create //============================================================ - -int sdl_info::create() +int renderer_sdl2::create() { -#if (SDLMAME_SDL2) const sdl_scale_mode *sm = &scale_modes[video_config.scale_mode]; // create renderer @@ -457,27 +210,25 @@ int sdl_info::create() fatalerror("Error on creating renderer: %s\n", SDL_GetError()); } - { - struct SDL_RendererInfo render_info; + struct SDL_RendererInfo render_info; - SDL_GetRendererInfo(m_sdl_renderer, &render_info); - drawsdl_show_info(&render_info); + SDL_GetRendererInfo(m_sdl_renderer, &render_info); + show_info(&render_info); - // Check scale mode + // Check scale mode - if (sm->pixel_format) - { - int i; - int found = 0; + if (sm->pixel_format) + { + int i; + int found = 0; - for (i=0; i < render_info.num_texture_formats; i++) - if (sm->pixel_format == render_info.texture_formats[i]) - found = 1; + for (i=0; i < render_info.num_texture_formats; i++) + if (sm->pixel_format == render_info.texture_formats[i]) + found = 1; - if (!found) - { - fatalerror("window: Scale mode %s not supported!", sm->name); - } + if (!found) + { + fatalerror("window: Scale mode %s not supported!", sm->name); } } @@ -486,47 +237,41 @@ int sdl_info::create() window().get_size(w, h); setup_texture(w, h); #endif -#else -#endif - m_yuv_lookup = NULL; + m_yuv_lookup = nullptr; m_blittimer = 0; yuv_init(); - osd_printf_verbose("Leave sdl_info::create\n"); + osd_printf_verbose("Leave renderer_sdl2::create\n"); return 0; } //============================================================ -// sdl_info::destroy +// DESTRUCTOR //============================================================ -void sdl_info::destroy() +renderer_sdl2::~renderer_sdl2() { - // free the memory in the window - destroy_all_textures(); - if (m_yuv_lookup != NULL) + if (m_yuv_lookup != nullptr) { global_free_array(m_yuv_lookup); - m_yuv_lookup = NULL; + m_yuv_lookup = nullptr; } - if (m_yuv_bitmap != NULL) + if (m_yuv_bitmap != nullptr) { global_free_array(m_yuv_bitmap); - m_yuv_bitmap = NULL; + m_yuv_bitmap = nullptr; } -#if (SDLMAME_SDL2) SDL_DestroyRenderer(m_sdl_renderer); -#endif } //============================================================ // drawsdl_xy_to_render_target //============================================================ -int sdl_info::xy_to_render_target(int x, int y, int *xt, int *yt) +int renderer_sdl2::xy_to_render_target(int x, int y, int *xt, int *yt) { *xt = x - m_last_hofs; *yt = y - m_last_vofs; @@ -541,34 +286,24 @@ int sdl_info::xy_to_render_target(int x, int y, int *xt, int *yt) // drawsdl_destroy_all_textures //============================================================ -void sdl_info::destroy_all_textures() +void renderer_sdl2::destroy_all_textures() { -#if (SDLMAME_SDL2) SDL_DestroyTexture(m_texture_id); - m_texture_id = NULL; -#else - if (m_yuvsurf != NULL) - { - SDL_FreeYUVOverlay(m_yuvsurf); - m_yuvsurf = NULL; - } -#endif + m_texture_id = nullptr; } //============================================================ -// sdl_info::draw +// renderer_sdl2::draw //============================================================ -int sdl_info::draw(int update) +int renderer_sdl2::draw(int update) { const sdl_scale_mode *sm = &scale_modes[video_config.scale_mode]; UINT8 *surfptr; INT32 pitch; Uint32 rmask, gmask, bmask; -#if (SDLMAME_SDL2) Uint32 amask; -#endif INT32 vofs, hofs, blitwidth, blitheight, ch, cw; int bpp; @@ -584,68 +319,14 @@ int sdl_info::draw(int update) clear_flags(FI_CHANGED); m_blittimer = 3; m_last_dim = wdim; -#if (SDLMAME_SDL2) - SDL_RenderSetViewport(m_sdl_renderer, NULL); - if (m_texture_id != NULL) + SDL_RenderSetViewport(m_sdl_renderer, nullptr); + if (m_texture_id != nullptr) SDL_DestroyTexture(m_texture_id); setup_texture(m_blit_dim); m_blittimer = 3; -#else - const sdl_scale_mode *sdl_sm = &scale_modes[video_config.scale_mode]; - if (sdl_sm->is_yuv) - { - yuv_overlay_init(); - } -#endif } // lock it if we need it -#if (!SDLMAME_SDL2) - - pitch = window().sdl_surface()->pitch; - bpp = window().sdl_surface()->format->BytesPerPixel; - rmask = window().sdl_surface()->format->Rmask; - 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) - yuv_overlay_init(); - m_old_blitwidth = window().blitwidth(); - 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, wdim.height() * window().sdl_surface()->pitch); - m_blittimer--; - } - - - if (sm->is_yuv) - { - SDL_LockYUVOverlay(m_yuvsurf); - surfptr = m_yuvsurf->pixels[0]; // (UINT8 *) m_yuv_bitmap; - pitch = m_yuvsurf->pitches[0]; // (UINT8 *) m_yuv_bitmap; -#if 0 - printf("abcd %d\n", m_yuvsurf->h); - printf("abcd %d %d %d\n", m_yuvsurf->pitches[0], m_yuvsurf->pitches[1], m_yuvsurf->pitches[2]); - printf("abcd %p %p %p\n", m_yuvsurf->pixels[0], m_yuvsurf->pixels[1], m_yuvsurf->pixels[2]); - printf("abcd %ld %ld\n", m_yuvsurf->pixels[1] - m_yuvsurf->pixels[0], m_yuvsurf->pixels[2] - m_yuvsurf->pixels[1]); -#endif - } - else - surfptr = (UINT8 *)window().sdl_surface()->pixels; -#else - //SDL_SelectRenderer(window().sdl_window); - { Uint32 format; @@ -661,14 +342,13 @@ int sdl_info::draw(int update) { /* SDL Underlays need alpha = 0 ! */ SDL_SetRenderDrawColor(m_sdl_renderer,0,0,0,0); - SDL_RenderFillRect(m_sdl_renderer,NULL); - //SDL_RenderFill(0,0,0,0 /*255*/,NULL); + SDL_RenderFillRect(m_sdl_renderer,nullptr); + //SDL_RenderFill(0,0,0,0 /*255*/,nullptr); m_blittimer--; } - SDL_LockTexture(m_texture_id, NULL, (void **) &surfptr, &pitch); + SDL_LockTexture(m_texture_id, nullptr, (void **) &surfptr, &pitch); -#endif // get ready to center the image vofs = hofs = 0; blitwidth = m_blit_dim.width(); @@ -703,25 +383,11 @@ int sdl_info::draw(int update) int mamewidth, mameheight; -#if !SDLMAME_SDL2 - if (!sm->is_yuv) - { - surfptr += ((vofs * pitch) + (hofs * bpp)); - mamewidth = blitwidth; //sdl_surface()->w; - mameheight = blitheight; //sdl_surface()->h; - } - else - { - mamewidth = m_yuvsurf->w / sm->mult_w; - mameheight = m_yuvsurf->h / sm->mult_h; - } -#else Uint32 fmt = 0; int access = 0; SDL_QueryTexture(m_texture_id, &fmt, &access, &mamewidth, &mameheight); mamewidth /= sm->mult_w; mameheight /= sm->mult_h; -#endif //printf("w h %d %d %d %d\n", mamewidth, mameheight, blitwidth, blitheight); // rescale bounds @@ -731,7 +397,7 @@ int sdl_info::draw(int update) // FIXME: this could be a lot easier if we get the primlist here! // Bounds would be set fit for purpose and done! - for (render_primitive *prim = window().m_primlist->first(); prim != NULL; prim = prim->next()) + for (render_primitive *prim = window().m_primlist->first(); prim != nullptr; prim = prim->next()) { prim->bounds.x0 = floor(fw * prim->bounds.x0 + 0.5f); prim->bounds.x1 = floor(fw * prim->bounds.x1 + 0.5f); @@ -771,8 +437,8 @@ int sdl_info::draw(int update) } else { - assert (m_yuv_bitmap != NULL); - assert (surfptr != NULL); + assert (m_yuv_bitmap != nullptr); + assert (surfptr != nullptr); software_renderer<UINT16, 3,3,3, 10,5,0>::draw_primitives(*window().m_primlist, m_yuv_bitmap, mamewidth, mameheight, mamewidth); sm->yuv_blit((UINT16 *)m_yuv_bitmap, surfptr, pitch, m_yuv_lookup, mamewidth, mameheight); } @@ -780,24 +446,6 @@ int sdl_info::draw(int update) window().m_primlist->release_lock(); // unlock and flip -#if (!SDLMAME_SDL2) - if (SDL_MUSTLOCK(window().sdl_surface())) SDL_UnlockSurface(window().sdl_surface()); - if (!sm->is_yuv) - { - SDL_Flip(window().sdl_surface()); - } - else - { - SDL_Rect r; - - SDL_UnlockYUVOverlay(m_yuvsurf); - r.x = hofs; - r.y = vofs; - r.w = blitwidth; - r.h = blitheight; - SDL_DisplayYUVOverlay(m_yuvsurf, &r); - } -#else SDL_UnlockTexture(m_texture_id); { SDL_Rect r; @@ -807,11 +455,10 @@ int sdl_info::draw(int update) r.w=blitwidth; r.h=blitheight; //printf("blitwidth %d %d - %d %d\n", blitwidth, blitheight, window().width, window().height); - //SDL_UpdateTexture(sdltex, NULL, sdlsurf->pixels, pitch); - SDL_RenderCopy(m_sdl_renderer,m_texture_id, NULL, &r); + //SDL_UpdateTexture(sdltex, nullptr, sdlsurf->pixels, pitch); + SDL_RenderCopy(m_sdl_renderer,m_texture_id, nullptr, &r); SDL_RenderPresent(m_sdl_renderer); } -#endif return 0; } //============================================================ @@ -855,7 +502,7 @@ int sdl_info::draw(int update) #define YMASK (Y1MASK|Y2MASK) #define UVMASK (UMASK|VMASK) -void sdl_info::yuv_lookup_set(unsigned int pen, unsigned char red, +void renderer_sdl2::yuv_lookup_set(unsigned int pen, unsigned char red, unsigned char green, unsigned char blue) { UINT32 y,u,v; @@ -867,10 +514,10 @@ void sdl_info::yuv_lookup_set(unsigned int pen, unsigned char red, m_yuv_lookup[pen]=(y<<Y1SHIFT)|(u<<USHIFT)|(y<<Y2SHIFT)|(v<<VSHIFT); } -void sdl_info::yuv_init() +void renderer_sdl2::yuv_init() { unsigned char r,g,b; - if (m_yuv_lookup == NULL) + if (m_yuv_lookup == nullptr) m_yuv_lookup = global_alloc_array(UINT32, 65536); for (r = 0; r < 32; r++) for (g = 0; g < 32; g++) @@ -950,12 +597,7 @@ static void yuv_RGB_to_YV12X2(const UINT16 *bitmap, UINT8 *ptr, const int pitch, pixels[0] = ptr; pixels[1] = ptr + pitch * height * 2; -#if (SDLMAME_SDL2) int p2 = (pitch >> 1); -#else - int p2 = (pitch + 7) & ~ 7;; - p2 = (p2 >> 1); -#endif pixels[2] = pixels[1] + p2 * height; for(y=0;y<height;y++) @@ -1027,3 +669,15 @@ static void yuv_RGB_to_YUY2X2(const UINT16 *bitmap, UINT8 *ptr, const int pitch, } } } + +render_primitive_list *renderer_sdl2::get_primitives() +{ + osd_dim nd = window().blit_surface_size(); + if (nd != m_blit_dim) + { + m_blit_dim = nd; + notify_changed(); + } + window().target()->set_bounds(m_blit_dim.width(), m_blit_dim.height(), window().aspect()); + return &window().target()->get_primitives(); +} |