mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 14:19:46 -06:00
Merge pull request #4326 from degasus/framedump
Framedump: Merge screenshot code with framedumping.
This commit is contained in:
@ -47,7 +47,6 @@ static u64 s_last_pts;
|
||||
static int s_current_width;
|
||||
static int s_current_height;
|
||||
static int s_file_index = 0;
|
||||
static AVIDump::DumpFormat s_current_format;
|
||||
static const u8* s_stored_frame_data;
|
||||
static int s_stored_frame_width;
|
||||
static int s_stored_frame_height;
|
||||
@ -63,18 +62,9 @@ static void InitAVCodec()
|
||||
}
|
||||
}
|
||||
|
||||
bool AVIDump::Start(int w, int h, DumpFormat format)
|
||||
bool AVIDump::Start(int w, int h)
|
||||
{
|
||||
if (format == DumpFormat::FORMAT_BGR)
|
||||
{
|
||||
s_pix_fmt = AV_PIX_FMT_BGR24;
|
||||
}
|
||||
else
|
||||
{
|
||||
s_pix_fmt = AV_PIX_FMT_RGBA;
|
||||
}
|
||||
|
||||
s_current_format = format;
|
||||
s_pix_fmt = AV_PIX_FMT_RGBA;
|
||||
|
||||
s_width = w;
|
||||
s_height = h;
|
||||
@ -320,7 +310,7 @@ void AVIDump::CheckResolution(int width, int height)
|
||||
int temp_file_index = s_file_index;
|
||||
Stop();
|
||||
s_file_index = temp_file_index + 1;
|
||||
Start(width, height, s_current_format);
|
||||
Start(width, height);
|
||||
s_current_width = width;
|
||||
s_current_height = height;
|
||||
}
|
||||
|
@ -15,13 +15,7 @@ private:
|
||||
static void StoreFrameData(const u8* data, int width, int height, int stride);
|
||||
|
||||
public:
|
||||
enum class DumpFormat
|
||||
{
|
||||
FORMAT_BGR,
|
||||
FORMAT_RGBA
|
||||
};
|
||||
|
||||
static bool Start(int w, int h, DumpFormat format);
|
||||
static bool Start(int w, int h);
|
||||
static void AddFrame(const u8* data, int width, int height, int stride);
|
||||
static void Stop();
|
||||
static void DoState();
|
||||
|
@ -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;
|
||||
@ -546,7 +550,6 @@ bool Renderer::IsFrameDumping()
|
||||
{
|
||||
AVIDump::Stop();
|
||||
std::vector<u8>().swap(m_frame_data);
|
||||
m_last_framedump_width = m_last_framedump_height = 0;
|
||||
m_AVI_dumping = false;
|
||||
OSD::AddMessage("Stop dumping frames", 2000);
|
||||
}
|
||||
@ -555,43 +558,54 @@ bool Renderer::IsFrameDumping()
|
||||
return false;
|
||||
}
|
||||
|
||||
void Renderer::DumpFrameData(const u8* data, int w, int h, int stride, AVIDump::DumpFormat format,
|
||||
bool swap_upside_down)
|
||||
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;
|
||||
|
||||
m_last_framedump_width = w;
|
||||
m_last_framedump_height = h;
|
||||
m_last_framedump_format = format;
|
||||
m_last_framedump_stride = stride;
|
||||
|
||||
// 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, format);
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -127,8 +127,6 @@ public:
|
||||
virtual void SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbStride, u32 fbHeight,
|
||||
const EFBRectangle& rc, float Gamma = 1.0f) = 0;
|
||||
|
||||
virtual bool SaveScreenshot(const std::string& filename, const TargetRectangle& rc) = 0;
|
||||
|
||||
static PEControl::PixelFormat GetPrevPixelFormat() { return prev_efb_format; }
|
||||
static void StorePixelFormat(PEControl::PixelFormat new_format) { prev_efb_format = new_format; }
|
||||
PostProcessingShaderImplementation* GetPostProcessor() { return m_post_processor.get(); }
|
||||
@ -148,8 +146,7 @@ protected:
|
||||
static void RecordVideoMemory();
|
||||
|
||||
bool IsFrameDumping();
|
||||
void DumpFrameData(const u8* data, int w, int h, int stride, AVIDump::DumpFormat format,
|
||||
bool swap_upside_down = false);
|
||||
void DumpFrameData(const u8* data, int w, int h, int stride, bool swap_upside_down = false);
|
||||
void FinishFrameData();
|
||||
|
||||
static volatile bool s_bScreenshot;
|
||||
@ -192,10 +189,6 @@ private:
|
||||
std::vector<u8> m_frame_data;
|
||||
bool m_AVI_dumping = false;
|
||||
bool m_last_frame_dumped = false;
|
||||
int m_last_framedump_width = 0;
|
||||
int m_last_framedump_height = 0;
|
||||
int m_last_framedump_stride = 0;
|
||||
AVIDump::DumpFormat m_last_framedump_format;
|
||||
};
|
||||
|
||||
extern std::unique_ptr<Renderer> g_renderer;
|
||||
|
Reference in New Issue
Block a user