selmenu.cpp: Don't use auto_alloc for temporary bitmaps (nw)

This commit is contained in:
AJR 2017-09-15 20:25:44 -04:00
parent e71705f57f
commit 489d68f57f
2 changed files with 66 additions and 78 deletions

View File

@ -1113,19 +1113,19 @@ float menu_select_launch::draw_icon(int linenum, void *selectedref, float x0, fl
while (path.next(curpath)) while (path.next(curpath))
searchstr.append(";").append(curpath.c_str()).append(PATH_SEPARATOR).append("icons"); searchstr.append(";").append(curpath.c_str()).append(PATH_SEPARATOR).append("icons");
bitmap_argb32 *tmp = auto_alloc(machine(), bitmap_argb32); bitmap_argb32 tmp;
emu_file snapfile(searchstr.c_str(), OPEN_FLAG_READ); emu_file snapfile(searchstr.c_str(), OPEN_FLAG_READ);
std::string fullname = std::string(driver->name).append(".ico"); std::string fullname = std::string(driver->name).append(".ico");
render_load_ico(*tmp, snapfile, nullptr, fullname.c_str()); render_load_ico(tmp, snapfile, nullptr, fullname.c_str());
if (!tmp->valid() && cloneof) if (!tmp.valid() && cloneof)
{ {
fullname.assign(driver->parent).append(".ico"); fullname.assign(driver->parent).append(".ico");
render_load_ico(*tmp, snapfile, nullptr, fullname.c_str()); render_load_ico(tmp, snapfile, nullptr, fullname.c_str());
} }
bitmap_argb32 &bitmap(icon->second.second); bitmap_argb32 &bitmap(icon->second.second);
if (tmp->valid()) if (tmp.valid())
{ {
float panel_width = x1 - x0; float panel_width = x1 - x0;
float panel_height = y1 - y0; float panel_height = y1 - y0;
@ -1139,38 +1139,35 @@ float menu_select_launch::draw_icon(int linenum, void *selectedref, float x0, fl
int panel_height_pixel = panel_height * screen_height; int panel_height_pixel = panel_height * screen_height;
// Calculate resize ratios for resizing // Calculate resize ratios for resizing
auto ratioW = (float)panel_width_pixel / tmp->width(); auto ratioW = (float)panel_width_pixel / tmp.width();
auto ratioH = (float)panel_height_pixel / tmp->height(); auto ratioH = (float)panel_height_pixel / tmp.height();
auto dest_xPixel = tmp->width(); auto dest_xPixel = tmp.width();
auto dest_yPixel = tmp->height(); auto dest_yPixel = tmp.height();
if (ratioW < 1 || ratioH < 1) if (ratioW < 1 || ratioH < 1)
{ {
// smaller ratio will ensure that the image fits in the view // smaller ratio will ensure that the image fits in the view
float ratio = std::min(ratioW, ratioH); float ratio = std::min(ratioW, ratioH);
dest_xPixel = tmp->width() * ratio; dest_xPixel = tmp.width() * ratio;
dest_yPixel = tmp->height() * ratio; dest_yPixel = tmp.height() * ratio;
} }
bitmap_argb32 *dest_bitmap; bitmap_argb32 dest_bitmap;
dest_bitmap = auto_alloc(machine(), bitmap_argb32);
// resample if necessary // resample if necessary
if (dest_xPixel != tmp->width() || dest_yPixel != tmp->height()) if (dest_xPixel != tmp.width() || dest_yPixel != tmp.height())
{ {
dest_bitmap->allocate(dest_xPixel, dest_yPixel); dest_bitmap.allocate(dest_xPixel, dest_yPixel);
render_color color = { 1.0f, 1.0f, 1.0f, 1.0f }; render_color color = { 1.0f, 1.0f, 1.0f, 1.0f };
render_resample_argb_bitmap_hq(*dest_bitmap, *tmp, color, true); render_resample_argb_bitmap_hq(dest_bitmap, tmp, color, true);
} }
else else
dest_bitmap = tmp; dest_bitmap = std::move(tmp);
bitmap.allocate(panel_width_pixel, panel_height_pixel); bitmap.allocate(panel_width_pixel, panel_height_pixel);
for (int x = 0; x < dest_xPixel; x++) for (int x = 0; x < dest_xPixel; x++)
for (int y = 0; y < dest_yPixel; y++) for (int y = 0; y < dest_yPixel; y++)
bitmap.pix32(y, x) = dest_bitmap->pix32(y, x); bitmap.pix32(y, x) = dest_bitmap.pix32(y, x);
auto_free(machine(), dest_bitmap);
icon->second.first->set_bitmap(bitmap, bitmap.cliprect(), TEXFORMAT_ARGB32); icon->second.first->set_bitmap(bitmap, bitmap.cliprect(), TEXFORMAT_ARGB32);
} }
@ -1178,8 +1175,6 @@ float menu_select_launch::draw_icon(int linenum, void *selectedref, float x0, fl
{ {
bitmap.reset(); bitmap.reset();
} }
auto_free(machine(), tmp);
} }
if (icon->second.second.valid()) if (icon->second.second.valid())
@ -2073,19 +2068,18 @@ void menu_select_launch::arts_render(float origx1, float origy1, float origx2, f
if (!m_cache->snapx_software_is(software) || !snapx_valid() || ui_globals::switch_image) if (!m_cache->snapx_software_is(software) || !snapx_valid() || ui_globals::switch_image)
{ {
emu_file snapfile(searchstr.c_str(), OPEN_FLAG_READ); emu_file snapfile(searchstr.c_str(), OPEN_FLAG_READ);
bitmap_argb32 *tmp_bitmap; bitmap_argb32 tmp_bitmap;
tmp_bitmap = auto_alloc(machine(), bitmap_argb32);
if (software->startempty == 1) if (software->startempty == 1)
{ {
// Load driver snapshot // Load driver snapshot
std::string fullname = std::string(software->driver->name) + ".png"; std::string fullname = std::string(software->driver->name) + ".png";
render_load_png(*tmp_bitmap, snapfile, nullptr, fullname.c_str()); render_load_png(tmp_bitmap, snapfile, nullptr, fullname.c_str());
if (!tmp_bitmap->valid()) if (!tmp_bitmap.valid())
{ {
fullname.assign(software->driver->name).append(".jpg"); fullname.assign(software->driver->name).append(".jpg");
render_load_jpeg(*tmp_bitmap, snapfile, nullptr, fullname.c_str()); render_load_jpeg(tmp_bitmap, snapfile, nullptr, fullname.c_str());
} }
} }
else if (ui_globals::curimage_view == TITLES_VIEW) else if (ui_globals::curimage_view == TITLES_VIEW)
@ -2093,12 +2087,12 @@ void menu_select_launch::arts_render(float origx1, float origy1, float origx2, f
// First attempt from name list // First attempt from name list
std::string const pathname = software->listname + "_titles"; std::string const pathname = software->listname + "_titles";
std::string fullname = software->shortname + ".png"; std::string fullname = software->shortname + ".png";
render_load_png(*tmp_bitmap, snapfile, pathname.c_str(), fullname.c_str()); render_load_png(tmp_bitmap, snapfile, pathname.c_str(), fullname.c_str());
if (!tmp_bitmap->valid()) if (!tmp_bitmap.valid())
{ {
fullname.assign(software->shortname).append(".jpg"); fullname.assign(software->shortname).append(".jpg");
render_load_jpeg(*tmp_bitmap, snapfile, pathname.c_str(), fullname.c_str()); render_load_jpeg(tmp_bitmap, snapfile, pathname.c_str(), fullname.c_str());
} }
} }
else else
@ -2106,33 +2100,32 @@ void menu_select_launch::arts_render(float origx1, float origy1, float origx2, f
// First attempt from name list // First attempt from name list
std::string pathname = software->listname; std::string pathname = software->listname;
std::string fullname = software->shortname + ".png"; std::string fullname = software->shortname + ".png";
render_load_png(*tmp_bitmap, snapfile, pathname.c_str(), fullname.c_str()); render_load_png(tmp_bitmap, snapfile, pathname.c_str(), fullname.c_str());
if (!tmp_bitmap->valid()) if (!tmp_bitmap.valid())
{ {
fullname.assign(software->shortname).append(".jpg"); fullname.assign(software->shortname).append(".jpg");
render_load_jpeg(*tmp_bitmap, snapfile, pathname.c_str(), fullname.c_str()); render_load_jpeg(tmp_bitmap, snapfile, pathname.c_str(), fullname.c_str());
} }
if (!tmp_bitmap->valid()) if (!tmp_bitmap.valid())
{ {
// Second attempt from driver name + part name // Second attempt from driver name + part name
pathname.assign(software->driver->name).append(software->part); pathname.assign(software->driver->name).append(software->part);
fullname.assign(software->shortname).append(".png"); fullname.assign(software->shortname).append(".png");
render_load_png(*tmp_bitmap, snapfile, pathname.c_str(), fullname.c_str()); render_load_png(tmp_bitmap, snapfile, pathname.c_str(), fullname.c_str());
if (!tmp_bitmap->valid()) if (!tmp_bitmap.valid())
{ {
fullname.assign(software->shortname).append(".jpg"); fullname.assign(software->shortname).append(".jpg");
render_load_jpeg(*tmp_bitmap, snapfile, pathname.c_str(), fullname.c_str()); render_load_jpeg(tmp_bitmap, snapfile, pathname.c_str(), fullname.c_str());
} }
} }
} }
m_cache->set_snapx_software(software); m_cache->set_snapx_software(software);
ui_globals::switch_image = false; ui_globals::switch_image = false;
arts_render_images(tmp_bitmap, origx1, origy1, origx2, origy2); arts_render_images(std::move(tmp_bitmap), origx1, origy1, origx2, origy2);
auto_free(machine(), tmp_bitmap);
} }
// if the image is available, loaded and valid, display it // if the image is available, loaded and valid, display it
@ -2152,31 +2145,30 @@ void menu_select_launch::arts_render(float origx1, float origy1, float origx2, f
{ {
emu_file snapfile(searchstr.c_str(), OPEN_FLAG_READ); emu_file snapfile(searchstr.c_str(), OPEN_FLAG_READ);
snapfile.set_restrict_to_mediapath(true); snapfile.set_restrict_to_mediapath(true);
bitmap_argb32 *tmp_bitmap; bitmap_argb32 tmp_bitmap;
tmp_bitmap = auto_alloc(machine(), bitmap_argb32);
// try to load snapshot first from saved "0000.png" file // try to load snapshot first from saved "0000.png" file
std::string fullname(driver->name); std::string fullname(driver->name);
render_load_png(*tmp_bitmap, snapfile, fullname.c_str(), "0000.png"); render_load_png(tmp_bitmap, snapfile, fullname.c_str(), "0000.png");
if (!tmp_bitmap->valid()) if (!tmp_bitmap.valid())
render_load_jpeg(*tmp_bitmap, snapfile, fullname.c_str(), "0000.jpg"); render_load_jpeg(tmp_bitmap, snapfile, fullname.c_str(), "0000.jpg");
// if fail, attemp to load from standard file // if fail, attemp to load from standard file
if (!tmp_bitmap->valid()) if (!tmp_bitmap.valid())
{ {
fullname.assign(driver->name).append(".png"); fullname.assign(driver->name).append(".png");
render_load_png(*tmp_bitmap, snapfile, nullptr, fullname.c_str()); render_load_png(tmp_bitmap, snapfile, nullptr, fullname.c_str());
if (!tmp_bitmap->valid()) if (!tmp_bitmap.valid())
{ {
fullname.assign(driver->name).append(".jpg"); fullname.assign(driver->name).append(".jpg");
render_load_jpeg(*tmp_bitmap, snapfile, nullptr, fullname.c_str()); render_load_jpeg(tmp_bitmap, snapfile, nullptr, fullname.c_str());
} }
} }
// if fail again, attemp to load from parent file // if fail again, attemp to load from parent file
if (!tmp_bitmap->valid()) if (!tmp_bitmap.valid())
{ {
// set clone status // set clone status
bool cloneof = strcmp(driver->parent, "0"); bool cloneof = strcmp(driver->parent, "0");
@ -2190,20 +2182,19 @@ void menu_select_launch::arts_render(float origx1, float origy1, float origx2, f
if (cloneof) if (cloneof)
{ {
fullname.assign(driver->parent).append(".png"); fullname.assign(driver->parent).append(".png");
render_load_png(*tmp_bitmap, snapfile, nullptr, fullname.c_str()); render_load_png(tmp_bitmap, snapfile, nullptr, fullname.c_str());
if (!tmp_bitmap->valid()) if (!tmp_bitmap.valid())
{ {
fullname.assign(driver->parent).append(".jpg"); fullname.assign(driver->parent).append(".jpg");
render_load_jpeg(*tmp_bitmap, snapfile, nullptr, fullname.c_str()); render_load_jpeg(tmp_bitmap, snapfile, nullptr, fullname.c_str());
} }
} }
} }
m_cache->set_snapx_driver(driver); m_cache->set_snapx_driver(driver);
ui_globals::switch_image = false; ui_globals::switch_image = false;
arts_render_images(tmp_bitmap, origx1, origy1, origx2, origy2); arts_render_images(std::move(tmp_bitmap), origx1, origy1, origx2, origy2);
auto_free(machine(), tmp_bitmap);
} }
// if the image is available, loaded and valid, display it // if the image is available, loaded and valid, display it
@ -2270,26 +2261,26 @@ std::string menu_select_launch::arts_render_common(float origx1, float origy1, f
// perform rendering of image // perform rendering of image
//------------------------------------------------- //-------------------------------------------------
void menu_select_launch::arts_render_images(bitmap_argb32 *tmp_bitmap, float origx1, float origy1, float origx2, float origy2) void menu_select_launch::arts_render_images(bitmap_argb32 &&tmp_bitmap, float origx1, float origy1, float origx2, float origy2)
{ {
bool no_available = false; bool no_available = false;
float line_height = ui().get_line_height(); float line_height = ui().get_line_height();
// if it fails, use the default image // if it fails, use the default image
if (!tmp_bitmap->valid()) if (!tmp_bitmap.valid())
{ {
tmp_bitmap->allocate(256, 256); tmp_bitmap.allocate(256, 256);
const bitmap_argb32 &src(m_cache->no_avail_bitmap()); const bitmap_argb32 &src(m_cache->no_avail_bitmap());
for (int x = 0; x < 256; x++) for (int x = 0; x < 256; x++)
{ {
for (int y = 0; y < 256; y++) for (int y = 0; y < 256; y++)
tmp_bitmap->pix32(y, x) = src.pix32(y, x); tmp_bitmap.pix32(y, x) = src.pix32(y, x);
} }
no_available = true; no_available = true;
} }
bitmap_argb32 &snapx_bitmap(m_cache->snapx_bitmap()); bitmap_argb32 &snapx_bitmap(m_cache->snapx_bitmap());
if (tmp_bitmap->valid()) if (tmp_bitmap.valid())
{ {
float panel_width = origx2 - origx1 - 0.02f; float panel_width = origx2 - origx1 - 0.02f;
float panel_height = origy2 - origy1 - 0.02f - (3.0f * UI_BOX_TB_BORDER) - (2.0f * line_height); float panel_height = origy2 - origy1 - 0.02f - (3.0f * UI_BOX_TB_BORDER) - (2.0f * line_height);
@ -2303,20 +2294,20 @@ void menu_select_launch::arts_render_images(bitmap_argb32 *tmp_bitmap, float ori
int panel_height_pixel = panel_height * screen_height; int panel_height_pixel = panel_height * screen_height;
// Calculate resize ratios for resizing // Calculate resize ratios for resizing
auto ratioW = (float)panel_width_pixel / tmp_bitmap->width(); auto ratioW = (float)panel_width_pixel / tmp_bitmap.width();
auto ratioH = (float)panel_height_pixel / tmp_bitmap->height(); auto ratioH = (float)panel_height_pixel / tmp_bitmap.height();
auto ratioI = (float)tmp_bitmap->height() / tmp_bitmap->width(); auto ratioI = (float)tmp_bitmap.height() / tmp_bitmap.width();
auto dest_xPixel = tmp_bitmap->width(); auto dest_xPixel = tmp_bitmap.width();
auto dest_yPixel = tmp_bitmap->height(); auto dest_yPixel = tmp_bitmap.height();
// force 4:3 ratio min // force 4:3 ratio min
if (ui().options().forced_4x3_snapshot() && ratioI < 0.75f && ui_globals::curimage_view == SNAPSHOT_VIEW) if (ui().options().forced_4x3_snapshot() && ratioI < 0.75f && ui_globals::curimage_view == SNAPSHOT_VIEW)
{ {
// smaller ratio will ensure that the image fits in the view // smaller ratio will ensure that the image fits in the view
dest_yPixel = tmp_bitmap->width() * 0.75f; dest_yPixel = tmp_bitmap.width() * 0.75f;
ratioH = (float)panel_height_pixel / dest_yPixel; ratioH = (float)panel_height_pixel / dest_yPixel;
float ratio = std::min(ratioW, ratioH); float ratio = std::min(ratioW, ratioH);
dest_xPixel = tmp_bitmap->width() * ratio; dest_xPixel = tmp_bitmap.width() * ratio;
dest_yPixel *= ratio; dest_yPixel *= ratio;
} }
// resize the bitmap if necessary // resize the bitmap if necessary
@ -2324,22 +2315,21 @@ void menu_select_launch::arts_render_images(bitmap_argb32 *tmp_bitmap, float ori
{ {
// smaller ratio will ensure that the image fits in the view // smaller ratio will ensure that the image fits in the view
float ratio = std::min(ratioW, ratioH); float ratio = std::min(ratioW, ratioH);
dest_xPixel = tmp_bitmap->width() * ratio; dest_xPixel = tmp_bitmap.width() * ratio;
dest_yPixel = tmp_bitmap->height() * ratio; dest_yPixel = tmp_bitmap.height() * ratio;
} }
bitmap_argb32 *dest_bitmap; bitmap_argb32 dest_bitmap;
// resample if necessary // resample if necessary
if (dest_xPixel != tmp_bitmap->width() || dest_yPixel != tmp_bitmap->height()) if (dest_xPixel != tmp_bitmap.width() || dest_yPixel != tmp_bitmap.height())
{ {
dest_bitmap = auto_alloc(machine(), bitmap_argb32); dest_bitmap.allocate(dest_xPixel, dest_yPixel);
dest_bitmap->allocate(dest_xPixel, dest_yPixel);
render_color color = { 1.0f, 1.0f, 1.0f, 1.0f }; render_color color = { 1.0f, 1.0f, 1.0f, 1.0f };
render_resample_argb_bitmap_hq(*dest_bitmap, *tmp_bitmap, color, true); render_resample_argb_bitmap_hq(dest_bitmap, tmp_bitmap, color, true);
} }
else else
dest_bitmap = tmp_bitmap; dest_bitmap = std::move(tmp_bitmap);
snapx_bitmap.allocate(panel_width_pixel, panel_height_pixel); snapx_bitmap.allocate(panel_width_pixel, panel_height_pixel);
int x1 = (0.5f * panel_width_pixel) - (0.5f * dest_xPixel); int x1 = (0.5f * panel_width_pixel) - (0.5f * dest_xPixel);
@ -2347,9 +2337,7 @@ void menu_select_launch::arts_render_images(bitmap_argb32 *tmp_bitmap, float ori
for (int x = 0; x < dest_xPixel; x++) for (int x = 0; x < dest_xPixel; x++)
for (int y = 0; y < dest_yPixel; y++) for (int y = 0; y < dest_yPixel; y++)
snapx_bitmap.pix32(y + y1, x + x1) = dest_bitmap->pix32(y, x); snapx_bitmap.pix32(y + y1, x + x1) = dest_bitmap.pix32(y, x);
auto_free(machine(), dest_bitmap);
// apply bitmap // apply bitmap
m_cache->snapx_texture()->set_bitmap(snapx_bitmap, snapx_bitmap.cliprect(), TEXFORMAT_ARGB32); m_cache->snapx_texture()->set_bitmap(snapx_bitmap, snapx_bitmap.cliprect(), TEXFORMAT_ARGB32);

View File

@ -255,7 +255,7 @@ private:
// images render // images render
void arts_render(float origx1, float origy1, float origx2, float origy2); void arts_render(float origx1, float origy1, float origx2, float origy2);
std::string arts_render_common(float origx1, float origy1, float origx2, float origy2); std::string arts_render_common(float origx1, float origy1, float origx2, float origy2);
void arts_render_images(bitmap_argb32 *bitmap, float origx1, float origy1, float origx2, float origy2); void arts_render_images(bitmap_argb32 &&bitmap, float origx1, float origy1, float origx2, float origy2);
void draw_snapx(float origx1, float origy1, float origx2, float origy2); void draw_snapx(float origx1, float origy1, float origx2, float origy2);
// text for main top/bottom panels // text for main top/bottom panels