Renderer: Merge screenshot logic into VideoCommon.

This commit is contained in:
degasus
2016-10-08 18:23:57 +02:00
parent 21e42c68c4
commit 64927a2f81
13 changed files with 47 additions and 234 deletions

View File

@ -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);
if (!m_last_frame_dumped)
// Save screenshot
if (s_bScreenshot)
{
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);
}
}
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);
std::lock_guard<std::mutex> 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();
}
m_last_frame_dumped = true;
#if defined(HAVE_LIBAV) || defined(_WIN32)
if (SConfig::GetInstance().m_DumpFrames)
{
if (!m_last_frame_dumped)
{
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);
}
}
if (m_AVI_dumping)
{
AVIDump::AddFrame(m_frame_data.data(), w, h, stride);
}
m_last_frame_dumped = true;
}
#endif
}