Refactor TakeGameScreenshot a bit.

This commit is contained in:
Henrik Rydgård 2025-03-20 17:41:44 +01:00
parent cb1df4056c
commit ae8f8c4abd
7 changed files with 28 additions and 40 deletions

View file

@ -483,7 +483,7 @@ void PSPModule::GetLongInfo(char *ptr, int bufSize) const {
StringWriter w(ptr, bufSize);
w.F("%s: Version %d.%d. %d segments", nm.name, nm.version[1], nm.version[0], nm.nsegment).endl();
w.F("Memory block: %08x (%08x/%d bytes)", memoryBlockAddr, memoryBlockSize, memoryBlockSize).endl();
for (int i = 0; i < nm.nsegment; i++) {
for (int i = 0; i < (int)nm.nsegment; i++) {
w.F(" %08x (%08x bytes)\n", nm.segmentaddr[i], nm.segmentsize[i]);
}
w.F("Text: %08x (%08x bytes)\n", nm.text_addr, nm.text_size);

View file

@ -1094,7 +1094,7 @@ double g_lastSaveTime = -1.0;
case SAVESTATE_SAVE_SCREENSHOT:
{
int maxResMultiplier = 2;
tempResult = TakeGameScreenshot(nullptr, op.filename, ScreenshotFormat::JPG, SCREENSHOT_DISPLAY, nullptr, nullptr, maxResMultiplier);
tempResult = TakeGameScreenshot(nullptr, op.filename, ScreenshotFormat::JPG, SCREENSHOT_DISPLAY, maxResMultiplier);
callbackResult = tempResult ? Status::SUCCESS : Status::FAILURE;
if (!tempResult) {
WARN_LOG(Log::SaveState, "Failed to take a screenshot for the savestate! (%s) The savestate will lack an icon.", op.filename.c_str());

View file

@ -328,9 +328,8 @@ static GPUDebugBuffer ApplyRotation(const GPUDebugBuffer &buf, DisplayRotation r
return rotated;
}
bool TakeGameScreenshot(Draw::DrawContext *draw, const Path &filename, ScreenshotFormat fmt, ScreenshotType type, int *width, int *height, int maxRes) {
bool TakeGameScreenshot(Draw::DrawContext *draw, const Path &filename, ScreenshotFormat fmt, ScreenshotType type, int maxRes) {
GPUDebugBuffer buf;
bool success = false;
u32 w = (u32)-1;
u32 h = (u32)-1;
@ -339,45 +338,34 @@ bool TakeGameScreenshot(Draw::DrawContext *draw, const Path &filename, Screensho
ERROR_LOG(Log::System, "Can't take screenshots when GPU not running");
return false;
}
success = gpuDebug->GetCurrentFramebuffer(buf, type == SCREENSHOT_RENDER ? GPU_DBG_FRAMEBUF_RENDER : GPU_DBG_FRAMEBUF_DISPLAY, maxRes);
if (!gpuDebug->GetCurrentFramebuffer(buf, type == SCREENSHOT_RENDER ? GPU_DBG_FRAMEBUF_RENDER : GPU_DBG_FRAMEBUF_DISPLAY, maxRes)) {
return false;
}
w = maxRes > 0 ? 480 * maxRes : PSP_CoreParameter().renderWidth;
h = maxRes > 0 ? 272 * maxRes : PSP_CoreParameter().renderHeight;
} else if (g_display.rotation != DisplayRotation::ROTATE_0) {
_dbg_assert_(draw);
GPUDebugBuffer temp;
success = ::GetOutputFramebuffer(draw, temp);
if (success) {
buf = ApplyRotation(temp, g_display.rotation);
if (!::GetOutputFramebuffer(draw, temp)) {
return false;
}
buf = ApplyRotation(temp, g_display.rotation);
} else {
_dbg_assert_(draw);
success = ::GetOutputFramebuffer(draw, buf);
if (!GetOutputFramebuffer(draw, buf)) {
return false;
}
}
if (!success) {
u8 *flipbuffer = nullptr;
const u8 *buffer = ConvertBufferToScreenshot(buf, false, flipbuffer, w, h);
if (!buffer) {
return false;
}
if (success) {
u8 *flipbuffer = nullptr;
const u8 *buffer = ConvertBufferToScreenshot(buf, false, flipbuffer, w, h);
success = buffer != nullptr;
if (success) {
if (width)
*width = w;
if (height)
*height = h;
success = Save888RGBScreenshot(filename, fmt, buffer, w, h);
}
delete[] flipbuffer;
}
if (!success) {
ERROR_LOG(Log::IO, "Failed to write screenshot.");
}
return success;
bool success = Save888RGBScreenshot(filename, fmt, buffer, w, h);
delete[] flipbuffer;
return true;
}
bool Save888RGBScreenshot(const Path &filename, ScreenshotFormat fmt, const u8 *bufferRGB888, int w, int h) {

View file

@ -41,7 +41,7 @@ enum ScreenshotType {
const u8 *ConvertBufferToScreenshot(const GPUDebugBuffer &buf, bool alpha, u8 *&temp, u32 &w, u32 &h);
// Can only be used while in game.
bool TakeGameScreenshot(Draw::DrawContext *draw, const Path &filename, ScreenshotFormat fmt, ScreenshotType type, int *width = nullptr, int *height = nullptr, int maxRes = -1);
bool TakeGameScreenshot(Draw::DrawContext *draw, const Path &filename, ScreenshotFormat fmt, ScreenshotType type, int maxRes = -1);
bool Save888RGBScreenshot(const Path &filename, ScreenshotFormat fmt, const u8 *bufferRGB888, int w, int h);
bool Save8888RGBAScreenshot(const Path &filename, const u8 *bufferRGBA8888, int w, int h);

View file

@ -153,13 +153,13 @@ struct GPUDebugBuffer {
void ZeroBytes();
u8 *GetData() {
return data_;
}
u32 GetRawPixel(int x, int y) const;
void SetRawPixel(int x, int y, u32 c);
u8 *GetDataWrite() {
return data_;
}
const u8 *GetData() const {
return data_;
}

View file

@ -1384,7 +1384,7 @@ bool SoftGPU::GetCurrentFramebuffer(GPUDebugBuffer &buffer, GPUDebugFramebufferT
buffer.Allocate(size.x, size.y, fmt);
const int depth = fmt == GE_FORMAT_8888 ? 4 : 2;
u8 *dst = buffer.GetData();
u8 *dst = buffer.GetDataWrite();
const int byteWidth = size.x * depth;
for (int16_t y = 0; y < size.y; ++y) {
memcpy(dst, src, byteWidth);
@ -1404,7 +1404,7 @@ bool SoftGPU::GetCurrentDepthbuffer(GPUDebugBuffer &buffer) {
const int depth = 2;
const u8 *src = depthbuf.data;
u8 *dst = buffer.GetData();
u8 *dst = buffer.GetDataWrite();
for (int16_t y = 0; y < size.y; ++y) {
memcpy(dst, src, size.x * depth);
dst += size.x * depth;
@ -1430,7 +1430,7 @@ bool SoftGPU::GetCurrentStencilbuffer(GPUDebugBuffer &buffer) {
DrawingCoords size = GetTargetSize(gstate.FrameBufStride());
buffer.Allocate(size.x, size.y, GPU_DBG_FORMAT_8BIT);
u8 *row = buffer.GetData();
u8 *row = buffer.GetDataWrite();
for (int16_t y = 0; y < size.y; ++y) {
for (int16_t x = 0; x < size.x; ++x) {
row[x] = GetPixelStencil(gstate.FrameBufFormat(), gstate.FrameBufStride(), x, y);
@ -1451,7 +1451,7 @@ bool SoftGPU::GetCurrentClut(GPUDebugBuffer &buffer)
const u32 pixels = 1024 / bpp;
buffer.Allocate(pixels, 1, (GEBufferFormat)gstate.getClutPaletteFormat());
memcpy(buffer.GetData(), clut, 1024);
memcpy(buffer.GetDataWrite(), clut, 1024);
return true;
}

View file

@ -182,7 +182,7 @@ ScreenRenderFlags ReportScreen::render(ScreenRenderMode mode) {
File::CreateDir(path);
}
screenshotFilename_ = path / ".reporting.jpg";
if (TakeGameScreenshot(screenManager()->getDrawContext(), screenshotFilename_, ScreenshotFormat::JPG, SCREENSHOT_DISPLAY, nullptr, nullptr, 4)) {
if (TakeGameScreenshot(screenManager()->getDrawContext(), screenshotFilename_, ScreenshotFormat::JPG, SCREENSHOT_DISPLAY, 4)) {
// Redo the views already, now with a screenshot included.
RecreateViews();
} else {