From c30bcb69489d4382ab75a9979dae3e6607f73d8b Mon Sep 17 00:00:00 2001 From: Aaron Giles Date: Sat, 16 Oct 2010 00:55:11 +0000 Subject: [PATCH] Fix crash when specifying -effect. Moved -effect implementation out of OSD code and into core since the implementations were identical across Windows/SDL and implemented in the core itself. --- docs/config.txt | 17 +++++++++++++++ docs/windows.txt | 17 --------------- src/emu/emuopts.c | 1 + src/emu/emuopts.h | 1 + src/emu/render.c | 7 ++++--- src/emu/video.c | 32 ++++++++++++++++++++++++++-- src/emu/video.h | 2 ++ src/osd/sdl/osdsdl.h | 1 - src/osd/sdl/sdlmain.c | 1 - src/osd/sdl/video.c | 44 --------------------------------------- src/osd/windows/video.c | 44 --------------------------------------- src/osd/windows/winmain.c | 1 - src/osd/windows/winmain.h | 1 - 13 files changed, 55 insertions(+), 114 deletions(-) diff --git a/docs/config.txt b/docs/config.txt index c6935bb1c8f..658cc82e5e5 100644 --- a/docs/config.txt +++ b/docs/config.txt @@ -705,6 +705,23 @@ Core screen options This controls the brightness level when MAME is paused. The default value is 0.65. +-effect + + Specifies a single PNG file that is used as an overlay over any game + screens in the video display. This PNG file is assumed to live in the + root of one of the artpath directories. The pattern in the PNG file is + repeated both horizontally and vertically to cover the entire game + screen areas (but not any external artwork), and is rendered at + the target resolution of the game image. For -video gdi and -video d3d + modes, this means that one pixel in the PNG will map to one pixel on + your output display. For -video ddraw, this means that one pixel in the + PNG will map to one pixel in the prescaled game screen. If you wish to + use an effect that requires mapping n PNG pixels to each game screen + pixel with -video ddraw, you need to specify a -prescale factor of n as + well. The RGB values of each pixel in the PNG are multiplied against the + RGB values of the target screen. The default is 'none', meaning no + effect. + Core vector options diff --git a/docs/windows.txt b/docs/windows.txt index 9fd62312188..e5e19c59527 100644 --- a/docs/windows.txt +++ b/docs/windows.txt @@ -135,23 +135,6 @@ Windows video options increases the effective resolution of non-screen elements such as artwork and fonts. The default is 1. --effect - - Specifies a single PNG file that is used as an overlay over any game - screens in the video display. This PNG file is assumed to live in the - root of one of the artpath directories. The pattern in the PNG file is - repeated both horizontally and vertically to cover the entire game - screen areas (but not any external artwork), and is rendered at - the target resolution of the game image. For -video gdi and -video d3d - modes, this means that one pixel in the PNG will map to one pixel on - your output display. For -video ddraw, this means that one pixel in the - PNG will map to one pixel in the prescaled game screen. If you wish to - use an effect that requires mapping n PNG pixels to each game screen - pixel with -video ddraw, you need to specify a -prescale factor of n as - well. The RGB values of each pixel in the PNG are multiplied against the - RGB values of the target screen. The default is 'none', meaning no - effect. - -[no]waitvsync Waits for the refresh period on your computer's monitor to finish diff --git a/src/emu/emuopts.c b/src/emu/emuopts.c index 3b99d0a02ea..ce880e3d133 100644 --- a/src/emu/emuopts.c +++ b/src/emu/emuopts.c @@ -106,6 +106,7 @@ const options_entry mame_core_options[] = { "contrast(0.1-2.0)", "1.0", 0, "default game screen contrast correction" }, { "gamma(0.1-3.0)", "1.0", 0, "default game screen gamma correction" }, { "pause_brightness(0.0-1.0)", "0.65", 0, "amount to scale the screen brightness when paused" }, + { "effect", "none", 0, "name of a PNG file to use for visual effects, or 'none'" }, /* vector options */ { NULL, NULL, OPTION_HEADER, "CORE VECTOR OPTIONS" }, diff --git a/src/emu/emuopts.h b/src/emu/emuopts.h index 02cbc2e260a..d4355a2009c 100644 --- a/src/emu/emuopts.h +++ b/src/emu/emuopts.h @@ -106,6 +106,7 @@ #define OPTION_CONTRAST "contrast" #define OPTION_GAMMA "gamma" #define OPTION_PAUSE_BRIGHTNESS "pause_brightness" +#define OPTION_EFFECT "effect" /* core vector options */ #define OPTION_ANTIALIAS "antialias" diff --git a/src/emu/render.c b/src/emu/render.c index 7dec7d8e745..f0eee33ae90 100644 --- a/src/emu/render.c +++ b/src/emu/render.c @@ -2370,11 +2370,12 @@ render_manager::render_manager(running_machine &machine) render_manager::~render_manager() { + // free all the containers since they may own textures + container_free(m_ui_container); + m_screen_container_list.reset(); + // better not be any outstanding textures when we die assert(m_live_textures == 0); - - // free the UI container - container_free(m_ui_container); } diff --git a/src/emu/video.c b/src/emu/video.c index 0c1e2c7fe65..c8e42c18f30 100644 --- a/src/emu/video.c +++ b/src/emu/video.c @@ -1903,6 +1903,7 @@ screen_device::screen_device(running_machine &_machine, const screen_device_conf m_texture_format(0), m_changed(true), m_last_partial_scan(0), + m_screen_overlay_bitmap(NULL), m_frame_period(m_config.m_refresh), m_scantime(1), m_pixeltime(1), @@ -1931,6 +1932,7 @@ screen_device::~screen_device() m_machine.render().texture_free(m_texture[1]); if (m_burnin != NULL) finalize_burnin(); + global_free(m_screen_overlay_bitmap); } @@ -1986,6 +1988,11 @@ void screen_device::device_start() bitmap_fill(m_burnin, NULL, 0); } + // load the effect overlay + const char *overname = options_get_string(machine->options(), OPTION_EFFECT); + if (overname != NULL && strcmp(overname, "none") != 0) + load_effect_overlay(overname); + state_save_register_device_item(this, 0, m_width); state_save_register_device_item(this, 0, m_height); state_save_register_device_item(this, 0, m_visarea.min_x); @@ -2552,8 +2559,7 @@ void screen_device::update_burnin() //------------------------------------------------- -// video_finalize_burnin - finalize the burnin -// bitmap +// finalize_burnin - finalize the burnin bitmap //------------------------------------------------- void screen_device::finalize_burnin() @@ -2637,6 +2643,28 @@ void screen_device::finalize_burnin() } +//------------------------------------------------- +// finalize_burnin - finalize the burnin bitmap +//------------------------------------------------- + +void screen_device::load_effect_overlay(const char *filename) +{ + // ensure that there is a .png extension + astring fullname(filename); + int extension = fullname.rchr(0, '.'); + if (extension != -1) + fullname.del(extension, -1); + fullname.cat(".png"); + + // load the file + m_screen_overlay_bitmap = render_load_png(OPTION_ARTPATH, NULL, fullname, NULL, NULL); + if (m_screen_overlay_bitmap != NULL) + m_container->set_overlay(m_screen_overlay_bitmap); + else + mame_printf_warning("Unable to load effect PNG file '%s'\n", fullname.cstr()); +} + + //************************************************************************** // SOFTWARE RENDERING diff --git a/src/emu/video.h b/src/emu/video.h index 7f6cc17c783..3cd0d6142d8 100644 --- a/src/emu/video.h +++ b/src/emu/video.h @@ -216,6 +216,7 @@ private: void scanline_update_callback(int scanline); void finalize_burnin(); + void load_effect_overlay(const char *filename); // internal state const screen_device_config &m_config; @@ -235,6 +236,7 @@ private: INT32 m_texture_format; // texture format of bitmap for this screen bool m_changed; // has this bitmap changed? INT32 m_last_partial_scan; // scanline of last partial update + bitmap_t * m_screen_overlay_bitmap;// screen overlay bitmap // screen timing attoseconds_t m_frame_period; // attoseconds per frame diff --git a/src/osd/sdl/osdsdl.h b/src/osd/sdl/osdsdl.h index 7b07babe193..617987fa14a 100644 --- a/src/osd/sdl/osdsdl.h +++ b/src/osd/sdl/osdsdl.h @@ -48,7 +48,6 @@ #define SDLOPTION_UNEVENSTRETCH "unevenstretch" #define SDLOPTION_USEALLHEADS "useallheads" #define SDLOPTION_MAXIMIZE "maximize" -#define SDLOPTION_EFFECT "effect" #define SDLOPTION_VIDEO "video" #define SDLOPTION_SWITCHRES "switchres" #define SDLOPTION_FILTER "filter" diff --git a/src/osd/sdl/sdlmain.c b/src/osd/sdl/sdlmain.c index 4ec754c198a..011748cd686 100644 --- a/src/osd/sdl/sdlmain.c +++ b/src/osd/sdl/sdlmain.c @@ -94,7 +94,6 @@ static const options_entry mame_sdl_options[] = { SDLOPTION_MAXIMIZE ";max", "1", OPTION_BOOLEAN, "default to maximized windows; otherwise, windows will be minimized" }, { SDLOPTION_KEEPASPECT ";ka", "1", OPTION_BOOLEAN, "constrain to the proper aspect ratio" }, { SDLOPTION_UNEVENSTRETCH ";ues", "1", OPTION_BOOLEAN, "allow non-integer stretch factors" }, - { SDLOPTION_EFFECT, SDLOPTVAL_NONE, 0, "name of a PNG file to use for visual effects, or 'none'" }, { SDLOPTION_CENTERH, "1", OPTION_BOOLEAN, "center horizontally within the view area" }, { SDLOPTION_CENTERV, "1", OPTION_BOOLEAN, "center vertically within the view area" }, #if (SDL_VERSION_ATLEAST(1,2,10)) diff --git a/src/osd/sdl/video.c b/src/osd/sdl/video.c index d34d41fcddc..72ba0067739 100644 --- a/src/osd/sdl/video.c +++ b/src/osd/sdl/video.c @@ -82,8 +82,6 @@ osd_gl_dispatch *gl_dispatch; static sdl_monitor_info *primary_monitor; static sdl_monitor_info *sdl_monitor_list; -static bitmap_t *effect_bitmap; - //============================================================ // PROTOTYPES //============================================================ @@ -96,7 +94,6 @@ static void check_osd_inputs(running_machine *machine); static void extract_video_config(running_machine *machine); static void extract_window_config(running_machine *machine, int index, sdl_window_config *conf); -static void load_effect_overlay(running_machine *machine, const char *filename); static float get_aspect(const char *name, int report_error); static void get_resolution(const char *name, sdl_window_config *config, int report_error); @@ -152,10 +149,6 @@ error: static void video_exit(running_machine &machine) { - // free the overlay effect - global_free(effect_bitmap); - effect_bitmap = NULL; - // free all of our monitor information while (sdl_monitor_list != NULL) { @@ -646,10 +639,6 @@ static void extract_video_config(running_machine *machine) if (machine->debug_flags & DEBUG_FLAG_OSD_ENABLED) video_config.windowed = TRUE; - stemp = options_get_string(machine->options(), SDLOPTION_EFFECT); - if (stemp != NULL && strcmp(stemp, "none") != 0) - load_effect_overlay(machine, stemp); - // default to working video please video_config.novideo = 0; @@ -811,39 +800,6 @@ static void extract_video_config(running_machine *machine) } -//============================================================ -// load_effect_overlay -//============================================================ - -static void load_effect_overlay(running_machine *machine, const char *filename) -{ - char *tempstr = global_alloc_array(char, strlen(filename) + 5); - char *dest; - - // append a .PNG extension - strcpy(tempstr, filename); - dest = strrchr(tempstr, '.'); - if (dest == NULL) - dest = &tempstr[strlen(tempstr)]; - strcpy(dest, ".png"); - - // load the file - effect_bitmap = render_load_png(OPTION_ARTPATH, NULL, tempstr, NULL, NULL); - if (effect_bitmap == NULL) - { - mame_printf_error("Unable to load PNG file '%s'\n", tempstr); - global_free(tempstr); - return; - } - - // set the overlay on all screens - for (screen_device *screen = screen_first(*machine); screen != NULL; screen = screen_next(screen)) - screen->container().set_overlay(effect_bitmap); - - global_free(tempstr); -} - - //============================================================ // get_aspect //============================================================ diff --git a/src/osd/windows/video.c b/src/osd/windows/video.c index 35865870473..05adf542a8f 100644 --- a/src/osd/windows/video.c +++ b/src/osd/windows/video.c @@ -88,8 +88,6 @@ win_video_config video_config; win_monitor_info *win_monitor_list; static win_monitor_info *primary_monitor; -static bitmap_t *effect_bitmap; - //============================================================ @@ -104,7 +102,6 @@ static win_monitor_info *pick_monitor(int index); static void check_osd_inputs(running_machine *machine); static void extract_video_config(running_machine *machine); -static void load_effect_overlay(running_machine *machine, const char *filename); static float get_aspect(const char *name, int report_error); static void get_resolution(const char *name, win_window_config *config, int report_error); @@ -148,10 +145,6 @@ void winvideo_init(running_machine *machine) static void winvideo_exit(running_machine &machine) { - // free the overlay effect - global_free(effect_bitmap); - effect_bitmap = NULL; - // free all of our monitor information while (win_monitor_list != NULL) { @@ -407,9 +400,6 @@ static void extract_video_config(running_machine *machine) // if we are in debug mode, never go full screen if (machine->debug_flags & DEBUG_FLAG_OSD_ENABLED) video_config.windowed = TRUE; - stemp = options_get_string(machine->options(), WINOPTION_EFFECT); - if (strcmp(stemp, "none") != 0) - load_effect_overlay(machine, stemp); // per-window options: extract the data get_resolution(WINOPTION_RESOLUTION0, &video_config.window[0], TRUE); @@ -463,40 +453,6 @@ static void extract_video_config(running_machine *machine) -//============================================================ -// load_effect_overlay -//============================================================ - -static void load_effect_overlay(running_machine *machine, const char *filename) -{ - char *tempstr = global_alloc_array(char, strlen(filename) + 5); - char *dest; - - // append a .PNG extension - strcpy(tempstr, filename); - dest = strrchr(tempstr, '.'); - if (dest == NULL) - dest = &tempstr[strlen(tempstr)]; - strcpy(dest, ".png"); - - // load the file - effect_bitmap = render_load_png(OPTION_ARTPATH, NULL, tempstr, NULL, NULL); - if (effect_bitmap == NULL) - { - mame_printf_error("Unable to load PNG file '%s'\n", tempstr); - global_free(tempstr); - return; - } - - // set the overlay on all screens - for (screen_device *screen = screen_first(*machine); screen != NULL; screen = screen_next(screen)) - screen->container().set_overlay(effect_bitmap); - - global_free(tempstr); -} - - - //============================================================ // get_aspect //============================================================ diff --git a/src/osd/windows/winmain.c b/src/osd/windows/winmain.c index 2d3d3140af8..cd52361a0b3 100644 --- a/src/osd/windows/winmain.c +++ b/src/osd/windows/winmain.c @@ -316,7 +316,6 @@ const options_entry mame_win_options[] = { "maximize;max", "1", OPTION_BOOLEAN, "default to maximized windows; otherwise, windows will be minimized" }, { "keepaspect;ka", "1", OPTION_BOOLEAN, "constrain to the proper aspect ratio" }, { "prescale", "1", 0, "scale screen rendering by this amount in software" }, - { "effect", "none", 0, "name of a PNG file to use for visual effects, or 'none'" }, { "waitvsync", "0", OPTION_BOOLEAN, "enable waiting for the start of VBLANK before flipping screens; reduces tearing effects" }, { "syncrefresh", "0", OPTION_BOOLEAN, "enable using the start of VBLANK for throttling instead of the game time" }, diff --git a/src/osd/windows/winmain.h b/src/osd/windows/winmain.h index 2251d717ec1..2c6dfa5aeb7 100644 --- a/src/osd/windows/winmain.h +++ b/src/osd/windows/winmain.h @@ -66,7 +66,6 @@ #define WINOPTION_MAXIMIZE "maximize" #define WINOPTION_KEEPASPECT "keepaspect" #define WINOPTION_PRESCALE "prescale" -#define WINOPTION_EFFECT "effect" #define WINOPTION_WAITVSYNC "waitvsync" #define WINOPTION_SYNCREFRESH "syncrefresh"