Halve the time necessary to take a screenshot

This commit is contained in:
TuxSH 2017-06-20 16:14:36 +02:00
parent 3f93bc5988
commit 94532e9cea
3 changed files with 42 additions and 32 deletions

View File

@ -82,4 +82,4 @@ void Draw_FlushFramebuffer(void);
u32 Draw_GetCurrentFramebufferAddress(bool top, bool left); u32 Draw_GetCurrentFramebufferAddress(bool top, bool left);
void Draw_CreateBitmapHeader(u8 *dst, u32 width, u32 heigth); void Draw_CreateBitmapHeader(u8 *dst, u32 width, u32 heigth);
u8 *Draw_ConvertFrameBufferLine(bool top, bool left, u32 y); void Draw_ConvertFrameBufferLine(u8 *line, bool top, bool left, u32 y);

View File

@ -33,7 +33,7 @@
#include "menu.h" #include "menu.h"
#include "utils.h" #include "utils.h"
u8 framebuffer_cache[FB_BOTTOM_SIZE]; u8 framebufferCache[FB_BOTTOM_SIZE];
static u32 gpuSavedFramebufferAddr1, gpuSavedFramebufferAddr2, gpuSavedFramebufferFormat, gpuSavedFramebufferStride; static u32 gpuSavedFramebufferAddr1, gpuSavedFramebufferAddr2, gpuSavedFramebufferFormat, gpuSavedFramebufferStride;
@ -127,7 +127,7 @@ void Draw_SetupFramebuffer(void)
while((GPU_PSC0_CNT | GPU_PSC1_CNT | GPU_TRANSFER_CNT | GPU_CMDLIST_CNT) & 1); while((GPU_PSC0_CNT | GPU_PSC1_CNT | GPU_TRANSFER_CNT | GPU_CMDLIST_CNT) & 1);
svcFlushEntireDataCache(); svcFlushEntireDataCache();
memcpy(framebuffer_cache, FB_BOTTOM_VRAM_ADDR, FB_BOTTOM_SIZE); memcpy(framebufferCache, FB_BOTTOM_VRAM_ADDR, FB_BOTTOM_SIZE);
gpuSavedFramebufferAddr1 = GPU_FB_BOTTOM_ADDR_1; gpuSavedFramebufferAddr1 = GPU_FB_BOTTOM_ADDR_1;
gpuSavedFramebufferAddr2 = GPU_FB_BOTTOM_ADDR_2; gpuSavedFramebufferAddr2 = GPU_FB_BOTTOM_ADDR_2;
gpuSavedFramebufferFormat = GPU_FB_BOTTOM_FMT; gpuSavedFramebufferFormat = GPU_FB_BOTTOM_FMT;
@ -142,7 +142,7 @@ void Draw_SetupFramebuffer(void)
void Draw_RestoreFramebuffer(void) void Draw_RestoreFramebuffer(void)
{ {
memcpy(FB_BOTTOM_VRAM_ADDR, framebuffer_cache, FB_BOTTOM_SIZE); memcpy(FB_BOTTOM_VRAM_ADDR, framebufferCache, FB_BOTTOM_SIZE);
GPU_FB_BOTTOM_ADDR_1 = gpuSavedFramebufferAddr1; GPU_FB_BOTTOM_ADDR_1 = gpuSavedFramebufferAddr1;
GPU_FB_BOTTOM_ADDR_2 = gpuSavedFramebufferAddr2; GPU_FB_BOTTOM_ADDR_2 = gpuSavedFramebufferAddr2;
@ -164,14 +164,14 @@ u32 Draw_GetCurrentFramebufferAddress(bool top, bool left)
if(left) if(left)
return top ? GPU_FB_TOP_LEFT_ADDR_2 : GPU_FB_BOTTOM_ADDR_2; return top ? GPU_FB_TOP_LEFT_ADDR_2 : GPU_FB_BOTTOM_ADDR_2;
else else
return top ? GPU_FB_TOP_RIGHT_ADDR_2 : GPU_FB_BOTTOM_ADDR_2; return top ? GPU_FB_TOP_RIGHT_ADDR_2 : GPU_FB_BOTTOM_ADDR_2;
} }
else else
{ {
if(left) if(left)
return top ? GPU_FB_TOP_LEFT_ADDR_1 : GPU_FB_BOTTOM_ADDR_1; return top ? GPU_FB_TOP_LEFT_ADDR_1 : GPU_FB_BOTTOM_ADDR_1;
else else
return top ? GPU_FB_TOP_RIGHT_ADDR_1 : GPU_FB_BOTTOM_ADDR_1; return top ? GPU_FB_TOP_RIGHT_ADDR_1 : GPU_FB_BOTTOM_ADDR_1;
} }
} }
@ -260,9 +260,7 @@ static inline void Draw_ConvertPixelToBGR8(u8 *dst, const u8 *src, GSPGPU_Frameb
} }
} }
static u8 line[3 * 400]; void Draw_ConvertFrameBufferLine(u8 *line, bool top, bool left, u32 y)
u8 *Draw_ConvertFrameBufferLine(bool top, bool left, u32 y)
{ {
GSPGPU_FramebufferFormats fmt = top ? (GSPGPU_FramebufferFormats)(GPU_FB_TOP_FMT & 7) : (GSPGPU_FramebufferFormats)(GPU_FB_BOTTOM_FMT & 7); GSPGPU_FramebufferFormats fmt = top ? (GSPGPU_FramebufferFormats)(GPU_FB_TOP_FMT & 7) : (GSPGPU_FramebufferFormats)(GPU_FB_BOTTOM_FMT & 7);
u32 width = top ? 400 : 320; u32 width = top ? 400 : 320;
@ -273,5 +271,4 @@ u8 *Draw_ConvertFrameBufferLine(bool top, bool left, u32 y)
for(u32 x = 0; x < width; x++) for(u32 x = 0; x < width; x++)
Draw_ConvertPixelToBGR8(line + x * 3 , addr + (x * 240 + y) * formatSizes[(u8)fmt], fmt); Draw_ConvertPixelToBGR8(line + x * 3 , addr + (x * 240 + y) * formatSizes[(u8)fmt], fmt);
return line;
} }

View File

@ -85,13 +85,13 @@ void RosalinaMenu_ShowCredits(void)
while(!(waitInput() & BUTTON_B) && !terminationRequest); while(!(waitInput() & BUTTON_B) && !terminationRequest);
} }
extern u8 framebufferCache[FB_BOTTOM_SIZE];
void RosalinaMenu_TakeScreenshot(void) void RosalinaMenu_TakeScreenshot(void)
{ {
#define TRY(expr) if(R_FAILED(res = (expr))) goto end; #define TRY(expr) if(R_FAILED(res = (expr))) goto end;
u64 total; u64 total;
IFile file; IFile file;
u8 buf[54];
Result res; Result res;
u32 filenum; u32 filenum;
@ -109,6 +109,8 @@ void RosalinaMenu_TakeScreenshot(void)
Draw_Lock(); Draw_Lock();
Draw_RestoreFramebuffer(); Draw_RestoreFramebuffer();
svcFlushEntireDataCache();
res = FSUSER_OpenArchive(&archive, archiveId, fsMakePath(PATH_EMPTY, "")); res = FSUSER_OpenArchive(&archive, archiveId, fsMakePath(PATH_EMPTY, ""));
if(R_SUCCEEDED(res)) if(R_SUCCEEDED(res))
{ {
@ -141,44 +143,55 @@ void RosalinaMenu_TakeScreenshot(void)
sprintf(filename, "/luma/screenshots/top_%04u.bmp", filenum); sprintf(filename, "/luma/screenshots/top_%04u.bmp", filenum);
TRY(IFile_Open(&file, archiveId, fsMakePath(PATH_EMPTY, ""), fsMakePath(PATH_ASCII, filename), FS_OPEN_CREATE | FS_OPEN_WRITE)); TRY(IFile_Open(&file, archiveId, fsMakePath(PATH_EMPTY, ""), fsMakePath(PATH_ASCII, filename), FS_OPEN_CREATE | FS_OPEN_WRITE));
Draw_CreateBitmapHeader(buf, 400, 240); Draw_CreateBitmapHeader(framebufferCache, 400, 240);
TRY(IFile_Write(&file, &total, buf, 54, 0));
for(u32 y = 0; y < 240; y++) for(u32 y = 0; y < 120; y++)
{ Draw_ConvertFrameBufferLine(framebufferCache + 54 + 3 * 400 * y, true, true, y);
u8 *line = Draw_ConvertFrameBufferLine(true, true, y);
TRY(IFile_Write(&file, &total, line, 3 * 400, 0));
}
TRY(IFile_Write(&file, &total, framebufferCache, 54 + 3 * 400 * 120, 0));
for(u32 y = 120; y < 240; y++)
Draw_ConvertFrameBufferLine(framebufferCache + 3 * 400 * (y - 120), true, true, y);
TRY(IFile_Write(&file, &total, framebufferCache, 3 * 400 * 120, 0));
TRY(IFile_Close(&file)); TRY(IFile_Close(&file));
sprintf(filename, "/luma/screenshots/bot_%04u.bmp", filenum); sprintf(filename, "/luma/screenshots/bot_%04u.bmp", filenum);
TRY(IFile_Open(&file, archiveId, fsMakePath(PATH_EMPTY, ""), fsMakePath(PATH_ASCII, filename), FS_OPEN_CREATE | FS_OPEN_WRITE)); TRY(IFile_Open(&file, archiveId, fsMakePath(PATH_EMPTY, ""), fsMakePath(PATH_ASCII, filename), FS_OPEN_CREATE | FS_OPEN_WRITE));
Draw_CreateBitmapHeader(buf, 320, 240); Draw_CreateBitmapHeader(framebufferCache, 320, 240);
TRY(IFile_Write(&file, &total, buf, 54, 0));
for(u32 y = 0; y < 240; y++) for(u32 y = 0; y < 120; y++)
{ Draw_ConvertFrameBufferLine(framebufferCache + 54 + 3 * 320 * y, false, true, y);
u8 *line = Draw_ConvertFrameBufferLine(false, true, y);
TRY(IFile_Write(&file, &total, line, 3 * 320, 0)); TRY(IFile_Write(&file, &total, framebufferCache, 54 + 3 * 320 * 120, 0));
}
for(u32 y = 120; y < 240; y++)
Draw_ConvertFrameBufferLine(framebufferCache + 3 * 320 * (y - 120), false, true, y);
TRY(IFile_Write(&file, &total, framebufferCache, 3 * 320 * 120, 0));
TRY(IFile_Close(&file));
if((GPU_FB_TOP_FMT & 0x20) && (Draw_GetCurrentFramebufferAddress(true, true) != Draw_GetCurrentFramebufferAddress(true, false))) if((GPU_FB_TOP_FMT & 0x20) && (Draw_GetCurrentFramebufferAddress(true, true) != Draw_GetCurrentFramebufferAddress(true, false)))
{ {
sprintf(filename, "/luma/screenshots/top_right_%04u.bmp", filenum); sprintf(filename, "/luma/screenshots/top_right_%04u.bmp", filenum);
TRY(IFile_Open(&file, archiveId, fsMakePath(PATH_EMPTY, ""), fsMakePath(PATH_ASCII, filename), FS_OPEN_CREATE | FS_OPEN_WRITE)); TRY(IFile_Open(&file, archiveId, fsMakePath(PATH_EMPTY, ""), fsMakePath(PATH_ASCII, filename), FS_OPEN_CREATE | FS_OPEN_WRITE));
Draw_CreateBitmapHeader(buf, 400, 240); Draw_CreateBitmapHeader(framebufferCache, 400, 240);
TRY(IFile_Write(&file, &total, buf, 54, 0));
for(u32 y = 0; y < 240; y++) for(u32 y = 0; y < 120; y++)
{ Draw_ConvertFrameBufferLine(framebufferCache + 54 + 3 * 400 * y, true, false, y);
u8 *line = Draw_ConvertFrameBufferLine(true, false, y);
TRY(IFile_Write(&file, &total, line, 3 * 400, 0)); TRY(IFile_Write(&file, &total, framebufferCache, 54 + 3 * 400 * 120, 0));
}
for(u32 y = 120; y < 240; y++)
Draw_ConvertFrameBufferLine(framebufferCache + 3 * 400 * (y - 120), true, false, y);
TRY(IFile_Write(&file, &total, framebufferCache, 3 * 400 * 120, 0));
TRY(IFile_Close(&file));
} }
end: end:
IFile_Close(&file); IFile_Close(&file);
svcFlushEntireDataCache();
Draw_SetupFramebuffer(); Draw_SetupFramebuffer();
Draw_ClearFramebuffer(); Draw_ClearFramebuffer();
Draw_FlushFramebuffer(); Draw_FlushFramebuffer();