diff options
Diffstat (limited to 'src/osd/modules/render/draw13.cpp')
-rw-r--r-- | src/osd/modules/render/draw13.cpp | 393 |
1 files changed, 93 insertions, 300 deletions
diff --git a/src/osd/modules/render/draw13.cpp b/src/osd/modules/render/draw13.cpp index 320cc9f3a62..7874cd16ea1 100644 --- a/src/osd/modules/render/draw13.cpp +++ b/src/osd/modules/render/draw13.cpp @@ -18,13 +18,11 @@ #include "emu.h" #include "options.h" -// standard SDL headers -#include "sdlinc.h" - // OSD headers #include "osdsdl.h" #include "window.h" +#include "draw13.h" //============================================================ // DEBUGGING @@ -59,196 +57,38 @@ static inline bool is_transparent(const float &a) } //============================================================ -// TYPES -//============================================================ - - -struct quad_setup_data -{ - quad_setup_data() - : dudx(0), dvdx(0), dudy(0), dvdy(0), startu(0), startv(0), - rotwidth(0), rotheight(0) - {} - void compute(const render_primitive &prim, const int prescale); - - INT32 dudx, dvdx, dudy, dvdy; - INT32 startu, startv; - INT32 rotwidth, rotheight; -}; - -//============================================================ -// Textures -//============================================================ - -class sdl_info13; -struct copy_info_t; - -/* texture_info holds information about a texture */ -class texture_info -{ - friend class simple_list<texture_info>; -public: - texture_info(sdl_info13 *renderer, const render_texinfo &texsource, const quad_setup_data &setup, const UINT32 flags); - ~texture_info(); - - void set_data(const render_texinfo &texsource, const UINT32 flags); - void render_quad(const render_primitive *prim, const int x, const int y); - bool matches(const render_primitive &prim, const quad_setup_data &setup); - - copy_info_t *compute_size_type(); - - void *m_pixels; // pixels for the texture - int m_pitch; - - copy_info_t *m_copyinfo; - quad_setup_data m_setup; - - osd_ticks_t m_last_access; - - int raw_width() const { return m_texinfo.width; } - int raw_height() const { return m_texinfo.height; } - - texture_info *next() { return m_next; } - const render_texinfo &texinfo() const { return m_texinfo; } - render_texinfo &texinfo() { return m_texinfo; } - - HashT hash() const { return m_hash; } - UINT32 flags() const { return m_flags; } - // FIXME: - bool is_pixels_owned() const; - -private: - Uint32 m_sdl_access; - sdl_info13 * m_renderer; - render_texinfo m_texinfo; // copy of the texture info - HashT m_hash; // hash value for the texture (must be >= pointer size) - UINT32 m_flags; // rendering flags - - SDL_Texture * m_texture_id; - bool m_is_rotated; - - int m_format; // texture format - SDL_BlendMode m_sdl_blendmode; - - texture_info * m_next; // next texture in the list -}; - -//============================================================ -// TEXCOPY FUNCS +// CONSTRUCTOR & DESTRUCTOR //============================================================ -enum SDL_TEXFORMAT_E +renderer_sdl1::renderer_sdl1(osd_window *window, int extra_flags) + : osd_renderer(window, extra_flags) + , m_sdl_renderer(nullptr) + , m_blittimer(0) + , m_last_hofs(0) + , m_last_vofs(0) + , m_width(0) + , m_height(0) + , m_blit_dim(0, 0) + , m_last_blit_time(0) + , m_last_blit_pixels(0) { - SDL_TEXFORMAT_ARGB32 = 0, - SDL_TEXFORMAT_RGB32, - SDL_TEXFORMAT_RGB32_PALETTED, - SDL_TEXFORMAT_YUY16, - SDL_TEXFORMAT_YUY16_PALETTED, - SDL_TEXFORMAT_PALETTE16, - SDL_TEXFORMAT_RGB15, - SDL_TEXFORMAT_RGB15_PALETTED, - SDL_TEXFORMAT_PALETTE16A, - SDL_TEXFORMAT_PALETTE16_ARGB1555, - SDL_TEXFORMAT_RGB15_ARGB1555, - SDL_TEXFORMAT_RGB15_PALETTED_ARGB1555, - SDL_TEXFORMAT_LAST = SDL_TEXFORMAT_RGB15_PALETTED_ARGB1555 -}; - -#include "blit13.h" - -/* sdl_info is the information about SDL for the current screen */ -class sdl_info13 : public osd_renderer -{ -public: - sdl_info13(osd_window *w, int extra_flags) - : osd_renderer(w, extra_flags), m_sdl_renderer(NULL), m_blittimer(0), - m_last_hofs(0), m_last_vofs(0), - m_width(0), m_height(0), - m_blit_dim(0,0), - m_last_blit_time(0), m_last_blit_pixels(0) + for (int i = 0; i < 30; i++) { - for (int i=0; i < 30; i++) - { - fmt_support[i].format = 0; - fmt_support[i].status = 0; - } + fmt_support[i].format = 0; + fmt_support[i].status = 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 + if (!s_blit_info_initialized) { - 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(); + /* On OSX, calling this from drawsdl2_init will + * prohibit fullscreen toggling. It is than not possible + * to toggle from fullscreen to window mode. + */ + expand_copy_info(s_blit_info_default); + s_blit_info_initialized = true; } - int RendererSupportsFormat(Uint32 format, Uint32 access, const char *sformat); - - SDL_Renderer * m_sdl_renderer; - -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; - - - simple_list<texture_info> m_texlist; // list of active textures - - float m_last_hofs; - float m_last_vofs; - - int m_width; - int m_height; - - osd_dim m_blit_dim; - - struct - { - Uint32 format; - int status; - } fmt_support[30]; - - // Stats - INT64 m_last_blit_time; - INT64 m_last_blit_pixels; -}; - -struct copy_info_t { - int src_fmt; - Uint32 dst_fmt; - const blit_base *blitter; - Uint32 bm_mask; - const char *srcname; - const char *dstname; - /* Statistics */ - UINT64 pixel_count; - INT64 time; - int samples; - int perf; - /* list */ - copy_info_t *next; -}; - - -//============================================================ -// PROTOTYPES -//============================================================ - -// core functions +} -static void drawsdl2_exit(void); //============================================================ // STATIC VARIABLES @@ -261,7 +101,7 @@ static void drawsdl2_exit(void); #define ENTRY_BM(a,b,f,bm) { SDL_TEXFORMAT_ ## a, SDL_PIXELFORMAT_ ## b, &texcopy_ ## f, bm, #a, #b, 0, 0, 0, 0} #define ENTRY_LR(a,b,f) { SDL_TEXFORMAT_ ## a, SDL_PIXELFORMAT_ ## b, &texcopy_ ## f, BM_ALL, #a, #b, 0, 0, 0, -1} -static copy_info_t blit_info_default[] = +const copy_info_t renderer_sdl1::s_blit_info_default[] = { /* no rotation */ ENTRY(ARGB32, ARGB8888, argb32_argb32), @@ -340,8 +180,8 @@ static copy_info_t blit_info_default[] = { -1 }, }; -static copy_info_t *blit_info[SDL_TEXFORMAT_LAST+1] = { NULL }; -static bool blit_info_initialized = false; +copy_info_t* renderer_sdl1::s_blit_info[SDL_TEXFORMAT_LAST+1] = { nullptr }; +bool renderer_sdl1::s_blit_info_initialized = false; //============================================================ // INLINES @@ -376,7 +216,7 @@ static inline SDL_BlendMode map_blendmode(const int blendmode) return SDL_BLENDMODE_NONE; } -static inline void set_coloralphamode(SDL_Texture *texture_id, const render_color *color) +void texture_info::set_coloralphamode(SDL_Texture *texture_id, const render_color *color) { UINT32 sr = (UINT32)(255.0f * color->r); UINT32 sg = (UINT32)(255.0f * color->g); @@ -421,12 +261,12 @@ void texture_info::render_quad(const render_primitive *prim, const int x, const set_coloralphamode(m_texture_id, &prim->color); //printf("%d %d %d %d\n", target_rect.x, target_rect.y, target_rect.w, target_rect.h); // Arghhh .. Just another bug. SDL_RenderCopy has severe issues with scaling ... - SDL_RenderCopy(m_renderer->m_sdl_renderer, m_texture_id, NULL, &target_rect); - //SDL_RenderCopyEx(m_renderer->m_sdl_renderer, m_texture_id, NULL, &target_rect, 0, NULL, SDL_FLIP_NONE); - //SDL_RenderCopyEx(m_renderer->m_sdl_renderer, m_texture_id, NULL, NULL, 0, NULL, SDL_FLIP_NONE); + SDL_RenderCopy(m_renderer->m_sdl_renderer, m_texture_id, nullptr, &target_rect); + //SDL_RenderCopyEx(m_renderer->m_sdl_renderer, m_texture_id, nullptr, &target_rect, 0, nullptr, SDL_FLIP_NONE); + //SDL_RenderCopyEx(m_renderer->m_sdl_renderer, m_texture_id, nullptr, nullptr, 0, nullptr, SDL_FLIP_NONE); } -void sdl_info13::render_quad(texture_info *texture, const render_primitive *prim, const int x, const int y) +void renderer_sdl1::render_quad(texture_info *texture, const render_primitive *prim, const int x, const int y) { SDL_Rect target_rect; @@ -463,11 +303,10 @@ void sdl_info13::render_quad(texture_info *texture, const render_primitive *prim } } -int sdl_info13::RendererSupportsFormat(Uint32 format, Uint32 access, const char *sformat) +int renderer_sdl1::RendererSupportsFormat(Uint32 format, Uint32 access, const char *sformat) { int i; - SDL_Texture *texid; - for (i=0; fmt_support[i].format != 0; i++) + for (i = 0; fmt_support[i].format != 0; i++) { if (format == fmt_support[i].format) { @@ -477,7 +316,7 @@ int sdl_info13::RendererSupportsFormat(Uint32 format, Uint32 access, const char /* not tested yet */ fmt_support[i].format = format; fmt_support[i + 1].format = 0; - texid = SDL_CreateTexture(m_sdl_renderer, format, access, 16, 16); + SDL_Texture *texid = SDL_CreateTexture(m_sdl_renderer, format, access, 16, 16); if (texid) { fmt_support[i].status = 1; @@ -494,7 +333,7 @@ int sdl_info13::RendererSupportsFormat(Uint32 format, Uint32 access, const char // drawsdl_init //============================================================ -static void add_list(copy_info_t **head, copy_info_t *element, Uint32 bm) +void renderer_sdl1::add_list(copy_info_t **head, const copy_info_t *element, Uint32 bm) { copy_info_t *newci = global_alloc(copy_info_t); *newci = *element; @@ -504,96 +343,49 @@ static void add_list(copy_info_t **head, copy_info_t *element, Uint32 bm) *head = newci; } -static void expand_copy_info(copy_info_t *list) +void renderer_sdl1::expand_copy_info(const copy_info_t *list) { - copy_info_t *bi; - - for (bi = list; bi->src_fmt != -1; bi++) + for (const copy_info_t *bi = list; bi->src_fmt != -1; bi++) { if (bi->bm_mask == BM_ALL) { - add_list(&blit_info[bi->src_fmt], bi, SDL_BLENDMODE_NONE); - add_list(&blit_info[bi->src_fmt], bi, SDL_BLENDMODE_ADD); - add_list(&blit_info[bi->src_fmt], bi, SDL_BLENDMODE_MOD); - add_list(&blit_info[bi->src_fmt], bi, SDL_BLENDMODE_BLEND); + add_list(&s_blit_info[bi->src_fmt], bi, SDL_BLENDMODE_NONE); + add_list(&s_blit_info[bi->src_fmt], bi, SDL_BLENDMODE_ADD); + add_list(&s_blit_info[bi->src_fmt], bi, SDL_BLENDMODE_MOD); + add_list(&s_blit_info[bi->src_fmt], bi, SDL_BLENDMODE_BLEND); } else - add_list(&blit_info[bi->src_fmt], bi, bi->bm_mask); - } -} - -static osd_renderer *drawsdl2_create(osd_window *window) -{ - if (!blit_info_initialized) - { - /* On OSX, calling this from drawsdl2_init will - * prohibit fullscreen toggling. It is than not possible - * to toggle from fullscreen to window mode. - */ - expand_copy_info(blit_info_default); - blit_info_initialized = true; - + { + add_list(&s_blit_info[bi->src_fmt], bi, bi->bm_mask); + } } - return global_alloc(sdl_info13(window, osd_renderer::FLAG_NONE)); } // FIXME: machine only used to access options. -int drawsdl2_init(running_machine &machine, osd_draw_callbacks *callbacks) +bool renderer_sdl1::init(running_machine &machine) { - // fill in the callbacks - callbacks->exit = drawsdl2_exit; - callbacks->create = drawsdl2_create; - osd_printf_verbose("Using SDL native texturing driver (SDL 2.0+)\n"); #if USE_OPENGL // Load the GL library now - else MT will fail const char *stemp = downcast<sdl_options &>(machine.options()).gl_lib(); #else - const char *stemp = NULL; + const char *stemp = nullptr; #endif - if (stemp != NULL && strcmp(stemp, OSDOPTVAL_AUTO) == 0) - stemp = NULL; + if (stemp != nullptr && strcmp(stemp, OSDOPTVAL_AUTO) == 0) + stemp = nullptr; // No fatalerror here since not all video drivers support GL ! - if (SDL_GL_LoadLibrary(stemp) != 0) // Load library (default for e==NULL + if (SDL_GL_LoadLibrary(stemp) != 0) // Load library (default for e==nullptr osd_printf_warning("Warning: Unable to load opengl library: %s\n", stemp ? stemp : "<default>"); else osd_printf_verbose("Loaded opengl shared library: %s\n", stemp ? stemp : "<default>"); - return 0; + return false; } //============================================================ -// drawsdl_exit -//============================================================ - -static void drawsdl2_exit(void) -{ - int i; - copy_info_t *bi, *freeme; - if (blit_info_initialized) - { - for (i = 0; i <= SDL_TEXFORMAT_LAST; i++) - { - for (bi = blit_info[i]; bi != NULL; ) - { - if (bi->pixel_count) - osd_printf_verbose("%s -> %s %s blendmode 0x%02x, %d samples: %d KPixel/sec\n", bi->srcname, bi->dstname, - bi->blitter->m_is_rot ? "rot" : "norot", bi->bm_mask, bi->samples, - (int) bi->perf); - freeme = bi; - bi = bi->next; - global_free(freeme); - } - blit_info[i] = NULL; - } - blit_info_initialized = false; - } -} - -//============================================================ // sdl_info::create //============================================================ @@ -616,18 +408,18 @@ static void drawsdl_show_info(struct SDL_RendererInfo *render_info) RF_ENTRY(SDL_RENDERER_PRESENTVSYNC), RF_ENTRY(SDL_RENDERER_ACCELERATED), RF_ENTRY(SDL_RENDERER_TARGETTEXTURE), - {-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 (i = 0; rflist[i].name != nullptr; i++) if (render_info->flags & rflist[i].flag) osd_printf_verbose("renderer: flag %s\n", rflist[i].name); } -int sdl_info13::create() +int renderer_sdl1::create() { // create renderer @@ -659,7 +451,7 @@ int sdl_info13::create() m_blittimer = 3; //SDL_RenderPresent(m_sdl_renderer); - osd_printf_verbose("Leave sdl_info13::create\n"); + osd_printf_verbose("Leave renderer_sdl1::create\n"); struct SDL_RendererInfo render_info; @@ -671,22 +463,10 @@ int sdl_info13::create() //============================================================ -// sdl_info::destroy -//============================================================ - -void sdl_info13::destroy() -{ - destroy_all_textures(); - SDL_DestroyRenderer(m_sdl_renderer); - m_sdl_renderer = NULL; -} - - -//============================================================ // drawsdl_xy_to_render_target //============================================================ -int sdl_info13::xy_to_render_target(int x, int y, int *xt, int *yt) +int renderer_sdl1::xy_to_render_target(int x, int y, int *xt, int *yt) { *xt = x - m_last_hofs; *yt = y - m_last_vofs; @@ -701,7 +481,7 @@ int sdl_info13::xy_to_render_target(int x, int y, int *xt, int *yt) // drawsdl_destroy_all_textures //============================================================ -void sdl_info13::destroy_all_textures() +void renderer_sdl1::destroy_all_textures() { if(window().m_primlist) { @@ -717,10 +497,10 @@ void sdl_info13::destroy_all_textures() // sdl_info::draw //============================================================ -int sdl_info13::draw(int update) +int renderer_sdl1::draw(int update) { render_primitive *prim; - texture_info *texture=NULL; + texture_info *texture=nullptr; float vofs, hofs; int blit_pixels = 0; @@ -736,7 +516,7 @@ int sdl_info13::draw(int update) destroy_all_textures(); m_width = wdim.width(); m_height = wdim.height(); - SDL_RenderSetViewport(m_sdl_renderer, NULL); + SDL_RenderSetViewport(m_sdl_renderer, nullptr); m_blittimer = 3; clear_flags(FI_CHANGED); } @@ -749,7 +529,7 @@ int sdl_info13::draw(int update) SDL_SetRenderDrawBlendMode(m_sdl_renderer, SDL_BLENDMODE_NONE); //SDL_SetRenderDrawColor(0,0,0,255); SDL_SetRenderDrawColor(m_sdl_renderer, 0,0,0,0); - SDL_RenderFillRect(m_sdl_renderer, NULL); + SDL_RenderFillRect(m_sdl_renderer, nullptr); m_blittimer--; } @@ -779,7 +559,7 @@ int sdl_info13::draw(int update) window().m_primlist->acquire_lock(); // now draw - for (prim = window().m_primlist->first(); prim != NULL; prim = prim->next()) + for (prim = window().m_primlist->first(); prim != nullptr; prim = prim->next()) { Uint8 sr, sg, sb, sa; @@ -830,11 +610,10 @@ int sdl_info13::draw(int update) copy_info_t *texture_info::compute_size_type() { - copy_info_t *bi; - copy_info_t *result = NULL; + copy_info_t *result = nullptr; int maxperf = 0; - for (bi = blit_info[m_format]; bi != NULL; bi = bi->next) + for (copy_info_t *bi = renderer_sdl1::s_blit_info[m_format]; bi != nullptr; bi = bi->next) { if ((m_is_rotated == bi->blitter->m_is_rot) && (m_sdl_blendmode == bi->bm_mask)) @@ -852,10 +631,12 @@ copy_info_t *texture_info::compute_size_type() } } } + if (result) return result; + /* try last resort handlers */ - for (bi = blit_info[m_format]; bi != NULL; bi = bi->next) + for (copy_info_t *bi = renderer_sdl1::s_blit_info[m_format]; bi != nullptr; bi = bi->next) { if ((m_is_rotated == bi->blitter->m_is_rot) && (m_sdl_blendmode == bi->bm_mask)) @@ -863,7 +644,7 @@ copy_info_t *texture_info::compute_size_type() return bi; } //FIXME: crash implement a -do nothing handler */ - return NULL; + return nullptr; } // FIXME: @@ -896,7 +677,7 @@ bool texture_info::matches(const render_primitive &prim, const quad_setup_data & // texture_create //============================================================ -texture_info::texture_info(sdl_info13 *renderer, const render_texinfo &texsource, const quad_setup_data &setup, UINT32 flags) +texture_info::texture_info(renderer_sdl1 *renderer, const render_texinfo &texsource, const quad_setup_data &setup, UINT32 flags) { // fill in the core data m_renderer = renderer; @@ -958,7 +739,7 @@ texture_info::texture_info(sdl_info13 *renderer, const render_texinfo &texsource if (m_sdl_access == SDL_TEXTUREACCESS_STATIC) { if (m_copyinfo->blitter->m_is_passthrough) - m_pixels = NULL; + m_pixels = nullptr; else m_pixels = malloc(m_setup.rotwidth * m_setup.rotheight * m_copyinfo->blitter->m_dest_bpp); } @@ -968,7 +749,7 @@ texture_info::texture_info(sdl_info13 *renderer, const render_texinfo &texsource texture_info::~texture_info() { - if ( is_pixels_owned() && (m_pixels != NULL) ) + if ( is_pixels_owned() && (m_pixels != nullptr) ) free(m_pixels); SDL_DestroyTexture(m_texture_id); } @@ -992,11 +773,11 @@ void texture_info::set_data(const render_texinfo &texsource, const UINT32 flags) m_pitch = m_setup.rotwidth * m_copyinfo->blitter->m_dest_bpp; m_copyinfo->blitter->texop(this, &texsource); } - SDL_UpdateTexture(m_texture_id, NULL, m_pixels, m_pitch); + SDL_UpdateTexture(m_texture_id, nullptr, m_pixels, m_pitch); } else { - SDL_LockTexture(m_texture_id, NULL, (void **) &m_pixels, &m_pitch); + SDL_LockTexture(m_texture_id, nullptr, (void **) &m_pixels, &m_pitch); if ( m_copyinfo->blitter->m_is_passthrough ) { UINT8 *src = (UINT8 *) texsource.base; @@ -1084,14 +865,14 @@ void quad_setup_data::compute(const render_primitive &prim, const int prescale) // texture_find //============================================================ -texture_info *sdl_info13::texture_find(const render_primitive &prim, const quad_setup_data &setup) +texture_info *renderer_sdl1::texture_find(const render_primitive &prim, const quad_setup_data &setup) { HashT texhash = texture_compute_hash(prim.texture, prim.flags); texture_info *texture; osd_ticks_t now = osd_ticks(); // find a match - for (texture = m_texlist.first(); texture != NULL; ) + for (texture = m_texlist.first(); texture != nullptr; ) if (texture->hash() == texhash && texture->matches(prim, setup)) { @@ -1099,7 +880,7 @@ texture_info *sdl_info13::texture_find(const render_primitive &prim, const quad_ if ((texture->m_copyinfo->samples & 0x7f) == 0x7f) { if (texture->m_copyinfo != texture->compute_size_type()) - return NULL; + return nullptr; } texture->m_last_access = now; return texture; @@ -1114,14 +895,14 @@ texture_info *sdl_info13::texture_find(const render_primitive &prim, const quad_ } // nothing found - return NULL; + return nullptr; } //============================================================ // texture_update //============================================================ -texture_info * sdl_info13::texture_update(const render_primitive &prim) +texture_info * renderer_sdl1::texture_update(const render_primitive &prim) { quad_setup_data setup; texture_info *texture; @@ -1131,16 +912,16 @@ texture_info * sdl_info13::texture_update(const render_primitive &prim) texture = texture_find(prim, setup); // if we didn't find one, create a new texture - if (texture == NULL && prim.texture.base != NULL) + if (texture == nullptr && prim.texture.base != nullptr) { texture = global_alloc(texture_info(this, prim.texture, setup, prim.flags)); /* add us to the texture list */ m_texlist.prepend(*texture); } - if (texture != NULL) + if (texture != nullptr) { - if (prim.texture.base != NULL && texture->texinfo().seqid != prim.texture.seqid) + if (prim.texture.base != nullptr && texture->texinfo().seqid != prim.texture.seqid) { texture->texinfo().seqid = prim.texture.seqid; // if we found it, but with a different seqid, copy the data @@ -1150,3 +931,15 @@ texture_info * sdl_info13::texture_update(const render_primitive &prim) } return texture; } + +render_primitive_list *renderer_sdl1::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(); +} |