all repos — mgba @ af1d114f49450c39e0253500952a94fe490e6734

mGBA Game Boy Advance Emulator

3DS: Reuse screenshot buffer, cleanup
Vicki Pfau vi@endrift.com
Fri, 12 Oct 2018 10:15:59 -0700
commit

af1d114f49450c39e0253500952a94fe490e6734

parent

76ccf41c25d89de5448883d77b95ef69a341ae78

1 files changed, 16 insertions(+), 10 deletions(-)

jump to
M src/platform/3ds/main.csrc/platform/3ds/main.c

@@ -84,7 +84,8 @@ DSP_SUPPORTED

} hasSound; // TODO: Move into context -static void* outputBuffer; +static color_t* outputBuffer = NULL; +static color_t* screenshotBuffer = NULL; static struct mAVStream stream; static int16_t* audioLeft = 0; static size_t audioPos = 0;

@@ -135,6 +136,11 @@ ctrDeinitGpu();

if (outputBuffer) { linearFree(outputBuffer); + outputBuffer = NULL; + } + if (screenshotBuffer) { + linearFree(screenshotBuffer); + screenshotBuffer = NULL; } C3D_RenderTargetDelete(topScreen[0]);

@@ -276,7 +282,7 @@ _map3DSKey(&runner->core->inputMap, KEY_RIGHT, GBA_KEY_RIGHT);

_map3DSKey(&runner->core->inputMap, KEY_L, GBA_KEY_L); _map3DSKey(&runner->core->inputMap, KEY_R, GBA_KEY_R); - outputBuffer = linearMemAlign(256 * 224 * 2, 0x80); + outputBuffer = linearMemAlign(256 * 224 * sizeof(color_t), 0x80); runner->core->setVideoBuffer(runner->core, outputBuffer, 256); unsigned mode;

@@ -547,7 +553,7 @@ C3D_Tex* tex = &outputTexture;

GSPGPU_FlushDataCache(outputBuffer, 256 * VIDEO_VERTICAL_PIXELS * 2); C3D_SyncDisplayTransfer( - outputBuffer, GX_BUFFER_DIM(256, VIDEO_VERTICAL_PIXELS), + (u32*) outputBuffer, GX_BUFFER_DIM(256, VIDEO_VERTICAL_PIXELS), tex->data, GX_BUFFER_DIM(256, 256), GX_TRANSFER_IN_FORMAT(GX_TRANSFER_FMT_RGB565) | GX_TRANSFER_OUT_FORMAT(GX_TRANSFER_FMT_RGB565) |

@@ -564,22 +570,22 @@

static void _drawScreenshot(struct mGUIRunner* runner, const color_t* pixels, unsigned width, unsigned height, bool faded) { C3D_Tex* tex = &outputTexture; - color_t* newPixels = linearMemAlign(256 * height * sizeof(color_t), 0x100); - + if (!screenshotBuffer) { + screenshotBuffer = linearMemAlign(256 * 224 * sizeof(color_t), 0x80); + } unsigned y; for (y = 0; y < height; ++y) { - memcpy(&newPixels[y * 256], &pixels[y * width], width * sizeof(color_t)); - memset(&newPixels[y * 256 + width], 0, (256 - width) * sizeof(color_t)); + memcpy(&screenshotBuffer[y * 256], &pixels[y * width], width * sizeof(color_t)); + memset(&screenshotBuffer[y * 256 + width], 0, (256 - width) * sizeof(color_t)); } - GSPGPU_FlushDataCache(newPixels, 256 * height * sizeof(u32)); + GSPGPU_FlushDataCache(screenshotBuffer, 256 * height * sizeof(color_t)); C3D_SyncDisplayTransfer( - (u32*) newPixels, GX_BUFFER_DIM(256, height), + (u32*) screenshotBuffer, GX_BUFFER_DIM(256, height), tex->data, GX_BUFFER_DIM(256, 256), GX_TRANSFER_IN_FORMAT(GX_TRANSFER_FMT_RGB565) | GX_TRANSFER_OUT_FORMAT(GX_TRANSFER_FMT_RGB565) | GX_TRANSFER_OUT_TILED(1) | GX_TRANSFER_FLIP_VERT(1)); - linearFree(newPixels); _drawTex(runner->core, faded); }