From 64927a2f81fe64503060c949ead525995fd63a2a Mon Sep 17 00:00:00 2001 From: degasus Date: Sat, 8 Oct 2016 18:23:57 +0200 Subject: Renderer: Merge screenshot logic into VideoCommon. --- Source/Core/VideoCommon/RenderBase.cpp | 55 +++++++++++++++++++++++----------- 1 file changed, 38 insertions(+), 17 deletions(-) (limited to 'Source/Core/VideoCommon/RenderBase.cpp') diff --git a/Source/Core/VideoCommon/RenderBase.cpp b/Source/Core/VideoCommon/RenderBase.cpp index 21bf1eeb54..9a81fa5e4d 100644 --- a/Source/Core/VideoCommon/RenderBase.cpp +++ b/Source/Core/VideoCommon/RenderBase.cpp @@ -41,6 +41,7 @@ #include "VideoCommon/Debugger.h" #include "VideoCommon/FPSCounter.h" #include "VideoCommon/FramebufferManagerBase.h" +#include "VideoCommon/ImageWrite.h" #include "VideoCommon/PostProcessing.h" #include "VideoCommon/RenderBase.h" #include "VideoCommon/Statistics.h" @@ -538,6 +539,9 @@ void Renderer::Swap(u32 xfbAddr, u32 fbWidth, u32 fbStride, u32 fbHeight, const bool Renderer::IsFrameDumping() { + if (s_bScreenshot) + return true; + #if defined(HAVE_LIBAV) || defined(_WIN32) if (SConfig::GetInstance().m_DumpFrames) return true; @@ -556,35 +560,52 @@ bool Renderer::IsFrameDumping() void Renderer::DumpFrameData(const u8* data, int w, int h, int stride, bool swap_upside_down) { -#if defined(HAVE_LIBAV) || defined(_WIN32) if (w == 0 || h == 0) return; // TODO: Refactor this. Right now it's needed for the implace flipping of the image. m_frame_data.assign(data, data + stride * h); + if (swap_upside_down) + FlipImageData(m_frame_data.data(), w, h, 4); + + // Save screenshot + if (s_bScreenshot) + { + std::lock_guard lk(s_criticalScreenshot); + + if (TextureToPng(m_frame_data.data(), stride, s_sScreenshotName, w, h, false)) + OSD::AddMessage("Screenshot saved to " + s_sScreenshotName); + + // Reset settings + s_sScreenshotName.clear(); + s_bScreenshot = false; + s_screenshotCompleted.Set(); + } - if (!m_last_frame_dumped) +#if defined(HAVE_LIBAV) || defined(_WIN32) + if (SConfig::GetInstance().m_DumpFrames) { - m_AVI_dumping = AVIDump::Start(w, h); - if (!m_AVI_dumping) + if (!m_last_frame_dumped) { - OSD::AddMessage("AVIDump Start failed", 2000); + m_AVI_dumping = AVIDump::Start(w, h); + if (!m_AVI_dumping) + { + OSD::AddMessage("AVIDump Start failed", 2000); + } + else + { + OSD::AddMessage(StringFromFormat("Dumping Frames to \"%sframedump0.avi\" (%dx%d RGB24)", + File::GetUserPath(D_DUMPFRAMES_IDX).c_str(), w, h), + 2000); + } } - else + if (m_AVI_dumping) { - OSD::AddMessage(StringFromFormat("Dumping Frames to \"%sframedump0.avi\" (%dx%d RGB24)", - File::GetUserPath(D_DUMPFRAMES_IDX).c_str(), w, h), - 2000); + AVIDump::AddFrame(m_frame_data.data(), w, h, stride); } - } - if (m_AVI_dumping) - { - if (swap_upside_down) - FlipImageData(m_frame_data.data(), w, h, 4); - AVIDump::AddFrame(m_frame_data.data(), w, h, stride); - } - m_last_frame_dumped = true; + m_last_frame_dumped = true; + } #endif } -- cgit v1.2.3