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.
This commit is contained in:
Aaron Giles 2010-10-16 00:55:11 +00:00
parent dbdc1594ff
commit c30bcb6948
13 changed files with 55 additions and 114 deletions

View file

@ -705,6 +705,23 @@ Core screen options
This controls the brightness level when MAME is paused. The default
value is 0.65.
-effect <filename>
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

View file

@ -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 <filename>
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

View file

@ -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" },

View file

@ -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"

View file

@ -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);
}

View file

@ -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

View file

@ -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

View file

@ -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"

View file

@ -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))

View file

@ -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
//============================================================

View file

@ -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
//============================================================

View file

@ -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" },

View file

@ -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"