From f45ddddf1cf5ec7904a83924614161e00bc10d21 Mon Sep 17 00:00:00 2001 From: degasus Date: Fri, 7 Oct 2016 20:31:51 +0200 Subject: VideoCommon: Add shared framedumping code. --- Source/Core/VideoCommon/RenderBase.cpp | 96 +++++++++++++++++++++++++++++++--- 1 file changed, 89 insertions(+), 7 deletions(-) (limited to 'Source/Core/VideoCommon/RenderBase.cpp') diff --git a/Source/Core/VideoCommon/RenderBase.cpp b/Source/Core/VideoCommon/RenderBase.cpp index 60375a43db..1ba81ecf2b 100644 --- a/Source/Core/VideoCommon/RenderBase.cpp +++ b/Source/Core/VideoCommon/RenderBase.cpp @@ -20,6 +20,7 @@ #include "Common/CommonTypes.h" #include "Common/Event.h" +#include "Common/FileUtil.h" #include "Common/Flag.h" #include "Common/Profiler.h" #include "Common/StringUtil.h" @@ -97,14 +98,10 @@ static float AspectToWidescreen(float aspect) return aspect * ((16.0f / 9.0f) / (4.0f / 3.0f)); } -Renderer::Renderer() : frame_data(), bLastFrameDumped(false) +Renderer::Renderer() { UpdateActiveConfig(); TextureCacheBase::OnConfigChanged(g_ActiveConfig); - -#if defined _WIN32 || defined HAVE_LIBAV - bAVIDumping = false; -#endif } Renderer::~Renderer() @@ -113,9 +110,14 @@ Renderer::~Renderer() prev_efb_format = PEControl::INVALID_FMT; efb_scale_numeratorX = efb_scale_numeratorY = efb_scale_denominatorX = efb_scale_denominatorY = 1; -#if defined _WIN32 || defined HAVE_LIBAV - if (SConfig::GetInstance().m_DumpFrames && bLastFrameDumped && bAVIDumping) + +#if defined(HAVE_LIBAV) || defined(_WIN32) + // Stop frame dumping if it was left enabled at shutdown time. + if (bAVIDumping) + { AVIDump::Stop(); + bAVIDumping = false; + } #endif } @@ -534,6 +536,86 @@ void Renderer::Swap(u32 xfbAddr, u32 fbWidth, u32 fbStride, u32 fbHeight, const XFBWrited = false; } +bool Renderer::IsFrameDumping() +{ +#if defined(HAVE_LIBAV) || defined(_WIN32) + if (SConfig::GetInstance().m_DumpFrames) + return true; + + if (bLastFrameDumped && bAVIDumping) + { + AVIDump::Stop(); + std::vector().swap(frame_data); + m_last_framedump_width = m_last_framedump_height = 0; + bAVIDumping = false; + OSD::AddMessage("Stop dumping frames", 2000); + } + bLastFrameDumped = false; +#endif + return false; +} + +void Renderer::DumpFrameData(const u8* data, int w, int h, AVIDump::DumpFormat format, + bool swap_upside_down) +{ +#if defined(HAVE_LIBAV) || defined(_WIN32) + if (w == 0 || h == 0) + return; + + size_t image_size; + switch (format) + { + case AVIDump::DumpFormat::FORMAT_BGR: + image_size = 3 * w * h; + break; + case AVIDump::DumpFormat::FORMAT_RGBA: + image_size = 4 * w * h; + break; + } + + m_last_framedump_width = w; + m_last_framedump_height = h; + m_last_framedump_format = format; + + // TODO: Refactor this. Right now it's needed for the implace flipping of the image. + // It's also used to repeat the last frame. + frame_data.assign(data, data + image_size); + + if (!bLastFrameDumped) + { + bAVIDumping = AVIDump::Start(w, h, format); + if (!bAVIDumping) + { + 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 (bAVIDumping) + { + if (swap_upside_down) + FlipImageData(&frame_data[0], w, h, 4); + AVIDump::AddFrame(&frame_data[0], w, h); + } + + bLastFrameDumped = true; +#endif +} + +void Renderer::RepeatFrameDumpFrame() +{ +#if defined(HAVE_LIBAV) || defined(_WIN32) + if (SConfig::GetInstance().m_DumpFrames && bAVIDumping && !frame_data.empty()) + { + AVIDump::AddFrame(&frame_data[0], m_last_framedump_width, m_last_framedump_height); + } +#endif +} + void Renderer::FlipImageData(u8* data, int w, int h, int pixel_width) { for (int y = 0; y < h / 2; ++y) -- cgit v1.2.3 From 8c999f9ee801116e723381432b96d8a9ae6ddc68 Mon Sep 17 00:00:00 2001 From: degasus Date: Fri, 7 Oct 2016 21:39:23 +0200 Subject: VideoCommon: Mark framedump variables as private. And rename them to the new naming scheme. --- Source/Core/VideoCommon/RenderBase.cpp | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'Source/Core/VideoCommon/RenderBase.cpp') diff --git a/Source/Core/VideoCommon/RenderBase.cpp b/Source/Core/VideoCommon/RenderBase.cpp index 1ba81ecf2b..1dd07c905b 100644 --- a/Source/Core/VideoCommon/RenderBase.cpp +++ b/Source/Core/VideoCommon/RenderBase.cpp @@ -113,10 +113,10 @@ Renderer::~Renderer() #if defined(HAVE_LIBAV) || defined(_WIN32) // Stop frame dumping if it was left enabled at shutdown time. - if (bAVIDumping) + if (m_AVI_dumping) { AVIDump::Stop(); - bAVIDumping = false; + m_AVI_dumping = false; } #endif } @@ -542,15 +542,15 @@ bool Renderer::IsFrameDumping() if (SConfig::GetInstance().m_DumpFrames) return true; - if (bLastFrameDumped && bAVIDumping) + if (m_last_frame_dumped && m_AVI_dumping) { AVIDump::Stop(); - std::vector().swap(frame_data); + std::vector().swap(m_frame_data); m_last_framedump_width = m_last_framedump_height = 0; - bAVIDumping = false; + m_AVI_dumping = false; OSD::AddMessage("Stop dumping frames", 2000); } - bLastFrameDumped = false; + m_last_frame_dumped = false; #endif return false; } @@ -579,12 +579,12 @@ void Renderer::DumpFrameData(const u8* data, int w, int h, AVIDump::DumpFormat f // TODO: Refactor this. Right now it's needed for the implace flipping of the image. // It's also used to repeat the last frame. - frame_data.assign(data, data + image_size); + m_frame_data.assign(data, data + image_size); - if (!bLastFrameDumped) + if (!m_last_frame_dumped) { - bAVIDumping = AVIDump::Start(w, h, format); - if (!bAVIDumping) + m_AVI_dumping = AVIDump::Start(w, h, format); + if (!m_AVI_dumping) { OSD::AddMessage("AVIDump Start failed", 2000); } @@ -595,23 +595,23 @@ void Renderer::DumpFrameData(const u8* data, int w, int h, AVIDump::DumpFormat f 2000); } } - if (bAVIDumping) + if (m_AVI_dumping) { if (swap_upside_down) - FlipImageData(&frame_data[0], w, h, 4); - AVIDump::AddFrame(&frame_data[0], w, h); + FlipImageData(m_frame_data.data(), w, h, 4); + AVIDump::AddFrame(m_frame_data.data(), w, h); } - bLastFrameDumped = true; + m_last_frame_dumped = true; #endif } void Renderer::RepeatFrameDumpFrame() { #if defined(HAVE_LIBAV) || defined(_WIN32) - if (SConfig::GetInstance().m_DumpFrames && bAVIDumping && !frame_data.empty()) + if (SConfig::GetInstance().m_DumpFrames && m_AVI_dumping && !m_frame_data.empty()) { - AVIDump::AddFrame(&frame_data[0], m_last_framedump_width, m_last_framedump_height); + AVIDump::AddFrame(m_frame_data.data(), m_last_framedump_width, m_last_framedump_height); } #endif } -- cgit v1.2.3