3DS: Reuse screenshot buffer, cleanup

This commit is contained in:
Vicki Pfau 2018-10-12 10:15:59 -07:00
parent 76ccf41c25
commit af1d114f49
1 changed files with 16 additions and 10 deletions

View File

@ -84,7 +84,8 @@ static enum {
} 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 @@ static void _cleanup(void) {
if (outputBuffer) {
linearFree(outputBuffer);
outputBuffer = NULL;
}
if (screenshotBuffer) {
linearFree(screenshotBuffer);
screenshotBuffer = NULL;
}
C3D_RenderTargetDelete(topScreen[0]);
@ -276,7 +282,7 @@ static void _setup(struct mGUIRunner* runner) {
_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 @@ static void _drawFrame(struct mGUIRunner* runner, bool faded) {
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 _drawFrame(struct mGUIRunner* runner, bool faded) {
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);
}