all repos — mgba @ 2cf6c73d7d7ebd23e9b94e2082ac9643dd4158ba

mGBA Game Boy Advance Emulator

GUI: Cache savestate icons
Jeffrey Pfau jeffrey@endrift.com
Thu, 03 Sep 2015 02:25:16 -0700
commit

2cf6c73d7d7ebd23e9b94e2082ac9643dd4158ba

parent

cb8d60e21108402b1e50d57787d2c8fa3ea84fe9

2 files changed, 21 insertions(+), 7 deletions(-)

jump to
M src/gba/gui/gui-runner.csrc/gba/gui/gui-runner.c

@@ -44,8 +44,16 @@ static void _drawState(struct GUIBackground* background, void* id) {

struct GBAGUIBackground* gbaBackground = (struct GBAGUIBackground*) background; int stateId = ((int) id) >> 16; if (gbaBackground->p->drawScreenshot) { + if (gbaBackground->screenshot && gbaBackground->screenshotId == (int) id) { + gbaBackground->p->drawScreenshot(gbaBackground->p, gbaBackground->screenshot, true); + return; + } struct VFile* vf = GBAGetState(gbaBackground->p->context.gba, 0, stateId, false); - uint32_t* pixels = anonymousMemoryMap(VIDEO_HORIZONTAL_PIXELS * VIDEO_VERTICAL_PIXELS * 4); + uint32_t* pixels = gbaBackground->screenshot; + if (!pixels) { + pixels = anonymousMemoryMap(VIDEO_HORIZONTAL_PIXELS * VIDEO_VERTICAL_PIXELS * 4); + gbaBackground->screenshot = pixels; + } bool success = false; if (vf && isPNG(vf) && pixels) { png_structp png = PNGReadOpen(vf, PNG_HEADER_BYTES);

@@ -63,12 +71,10 @@ vf->close(vf);

} if (success) { gbaBackground->p->drawScreenshot(gbaBackground->p, pixels, true); + gbaBackground->screenshotId = (int) id; } else if (gbaBackground->p->drawFrame) { gbaBackground->p->drawFrame(gbaBackground->p, true); } - if (pixels) { - mappedMemoryFree(pixels, VIDEO_HORIZONTAL_PIXELS * VIDEO_VERTICAL_PIXELS * 4); - } } }

@@ -111,7 +117,9 @@ struct GBAGUIBackground drawState = {

.d = { .draw = _drawState }, - .p = runner + .p = runner, + .screenshot = 0, + .screenshotId = 0 }; struct GUIMenu pauseMenu = { .title = "Game Paused",

@@ -165,8 +173,7 @@ if (!GUISelectFile(&runner->params, path, sizeof(path), GBAIsROM)) {

if (runner->params.guiFinish) { runner->params.guiFinish(); } - GUIMenuItemListDeinit(&pauseMenu.items); - return; + break; } if (runner->params.guiPrepare) {

@@ -272,6 +279,10 @@ if (runner->gameUnloaded) {

runner->gameUnloaded(runner); } GBAContextUnloadROM(&runner->context); + drawState.screenshotId = 0; + } + if (drawState.screenshot) { + mappedMemoryFree(drawState.screenshot, VIDEO_HORIZONTAL_PIXELS * VIDEO_VERTICAL_PIXELS * 4); } GUIMenuItemListDeinit(&pauseMenu.items); GUIMenuItemListDeinit(&stateSaveMenu.items);
M src/gba/gui/gui-runner.hsrc/gba/gui/gui-runner.h

@@ -17,6 +17,9 @@

struct GBAGUIBackground { struct GUIBackground d; struct GBAGUIRunner* p; + + uint32_t* screenshot; + int screenshotId; }; struct GBAGUIRunnerLux {