Debian Codegraph @

Source/Core/VideoCommon/FrameDumper.h

raw symbols SCIP
1 // Copyright 2023 Dolphin Emulator Project
2 // SPDX-License-Identifier: GPL-2.0-or-later
3
4 #pragma once
5
6 #include "Common/CommonTypes.h"
7 #include "Common/Event.h"
8 #include "Common/Flag.h"
9 #include "Common/MathUtil.h"
10 #include "Common/Thread.h"
11
12 #include "VideoCommon/FrameDumpFFMpeg.h"
13 #include "VideoCommon/VideoEvents.h"
14
15 class AbstractStagingTexture;
16 class AbstractTexture;
17 class AbstractFramebuffer;
18
19 class FrameDumper
20 {
21 public:
22 FrameDumper();
23 ~FrameDumper();
24
25 // Ensures all rendered frames are queued for encoding.
26 void FlushFrameDump();
27
28 // Fills the frame dump staging texture with the current XFB texture.
29 void DumpCurrentFrame(const AbstractTexture* src_texture,
30 const MathUtil::Rectangle<int>& src_rect,
31 const MathUtil::Rectangle<int>& target_rect, u64 ticks, int frame_number);
32
33 void SaveScreenshot(std::string filename);
34
35 bool IsFrameDumping() const;
36 int GetRequiredResolutionLeastCommonMultiple() const;
37
38 void DoState(PointerWrap& p);
39
40 private:
41 // NOTE: The methods below are called on the framedumping thread.
42 void FrameDumpThreadFunc();
43 bool StartFrameDumpToFFMPEG(const FrameData&);
44 void DumpFrameToFFMPEG(const FrameData&);
45 void StopFrameDumpToFFMPEG();
46 std::string GetFrameDumpNextImageFileName() const;
47 bool StartFrameDumpToImage(const FrameData&);
48 void DumpFrameToImage(const FrameData&);
49
50 void ShutdownFrameDumping();
51
52 // Checks that the frame dump render texture exists and is the correct size.
53 bool CheckFrameDumpRenderTexture(u32 target_width, u32 target_height);
54
55 // Checks that the frame dump readback texture exists and is the correct size.
56 bool CheckFrameDumpReadbackTexture(u32 target_width, u32 target_height);
57
58 // Asynchronously encodes the specified pointer of frame data to the frame dump.
59 void DumpFrameData(const u8* data, int w, int h, int stride);
60
61 // Ensures all encoded frames have been written to the output file.
62 void FinishFrameData();
63
64 std::thread m_frame_dump_thread;
65 Common::Flag m_frame_dump_thread_running;
66
67 // Used to kick frame dump thread.
68 Common::Event m_frame_dump_start;
69
70 // Set by frame dump thread on frame completion.
71 Common::Event m_frame_dump_done;
72
73 // Holds emulation state during the last swap when dumping.
74 FrameState m_last_frame_state;
75
76 // Communication of frame between video and dump threads.
77 FrameData m_frame_dump_data;
78
79 // Texture used for screenshot/frame dumping
80 std::unique_ptr<AbstractTexture> m_frame_dump_render_texture;
81 std::unique_ptr<AbstractFramebuffer> m_frame_dump_render_framebuffer;
82
83 // Double buffer:
84 std::unique_ptr<AbstractStagingTexture> m_frame_dump_readback_texture;
85 std::unique_ptr<AbstractStagingTexture> m_frame_dump_output_texture;
86 // Set when readback texture holds a frame that needs to be dumped.
87 bool m_frame_dump_needs_flush = false;
88 // Set when thread is processing output texture.
89 bool m_frame_dump_frame_running = false;
90
91 // Used to generate screenshot names.
92 u32 m_frame_dump_image_counter = 0;
93
94 FFMpegFrameDump m_ffmpeg_dump;
95
96 // Screenshots
97 Common::Flag m_screenshot_request;
98 Common::Event m_screenshot_completed;
99 std::mutex m_screenshot_lock;
100 std::string m_screenshot_name;
101
102 Common::EventHook m_frame_end_handle;
103 };
104
105 extern std::unique_ptr<FrameDumper> g_frame_dumper;