mirror of
				https://github.com/PabloMK7/citra.git
				synced 2025-10-31 05:40:04 +00:00 
			
		
		
		
	frame_dumper: Use jthread (#6855)
This commit is contained in:
		
							parent
							
								
									ac78b74c45
								
							
						
					
					
						commit
						f76165d848
					
				
					 2 changed files with 18 additions and 16 deletions
				
			
		|  | @ -5,6 +5,9 @@ | |||
| #include <glad/glad.h> | ||||
| 
 | ||||
| #include <utility> | ||||
| 
 | ||||
| #include "core/core.h" | ||||
| #include "core/dumping/backend.h" | ||||
| #include "core/frontend/emu_window.h" | ||||
| #include "video_core/renderer_opengl/frame_dumper_opengl.h" | ||||
| #include "video_core/renderer_opengl/gl_texture_mailbox.h" | ||||
|  | @ -12,13 +15,9 @@ | |||
| namespace OpenGL { | ||||
| 
 | ||||
| FrameDumperOpenGL::FrameDumperOpenGL(Core::System& system_, Frontend::EmuWindow& emu_window) | ||||
|     : system(system_), context(emu_window.CreateSharedContext()) {} | ||||
|     : system{system_}, context{emu_window.CreateSharedContext()} {} | ||||
| 
 | ||||
| FrameDumperOpenGL::~FrameDumperOpenGL() { | ||||
|     if (present_thread.joinable()) { | ||||
|         present_thread.join(); | ||||
|     } | ||||
| } | ||||
| FrameDumperOpenGL::~FrameDumperOpenGL() = default; | ||||
| 
 | ||||
| bool FrameDumperOpenGL::IsDumping() const { | ||||
|     auto video_dumper = system.GetVideoDumper(); | ||||
|  | @ -35,19 +34,19 @@ void FrameDumperOpenGL::StartDumping() { | |||
|         present_thread.join(); | ||||
|     } | ||||
| 
 | ||||
|     present_thread = std::thread(&FrameDumperOpenGL::PresentLoop, this); | ||||
|     present_thread = std::jthread([this](std::stop_token stop_token) { PresentLoop(stop_token); }); | ||||
| } | ||||
| 
 | ||||
| void FrameDumperOpenGL::StopDumping() { | ||||
|     stop_requested.store(true, std::memory_order_relaxed); | ||||
|     present_thread.request_stop(); | ||||
| } | ||||
| 
 | ||||
| void FrameDumperOpenGL::PresentLoop() { | ||||
| void FrameDumperOpenGL::PresentLoop(std::stop_token stop_token) { | ||||
|     const auto scope = context->Acquire(); | ||||
|     InitializeOpenGLObjects(); | ||||
| 
 | ||||
|     const auto& layout = GetLayout(); | ||||
|     while (!stop_requested.exchange(false)) { | ||||
|     while (!stop_token.stop_requested()) { | ||||
|         auto frame = mailbox->TryGetPresentFrame(200); | ||||
|         if (!frame) { | ||||
|             continue; | ||||
|  |  | |||
|  | @ -6,9 +6,8 @@ | |||
| 
 | ||||
| #include <atomic> | ||||
| #include <memory> | ||||
| #include <thread> | ||||
| #include "core/core.h" | ||||
| #include "core/dumping/backend.h" | ||||
| 
 | ||||
| #include "common/polyfill_thread.h" | ||||
| #include "core/frontend/framebuffer_layout.h" | ||||
| #include "video_core/renderer_opengl/gl_resource_manager.h" | ||||
| 
 | ||||
|  | @ -18,6 +17,10 @@ class GraphicsContext; | |||
| class TextureMailbox; | ||||
| } // namespace Frontend
 | ||||
| 
 | ||||
| namespace Core { | ||||
| class System; | ||||
| } | ||||
| 
 | ||||
| namespace OpenGL { | ||||
| 
 | ||||
| class RendererOpenGL; | ||||
|  | @ -42,12 +45,12 @@ public: | |||
| private: | ||||
|     void InitializeOpenGLObjects(); | ||||
|     void CleanupOpenGLObjects(); | ||||
|     void PresentLoop(); | ||||
|     void PresentLoop(std::stop_token stop_token); | ||||
| 
 | ||||
| private: | ||||
|     Core::System& system; | ||||
|     std::unique_ptr<Frontend::GraphicsContext> context; | ||||
|     std::thread present_thread; | ||||
|     std::atomic_bool stop_requested{false}; | ||||
|     std::jthread present_thread; | ||||
| 
 | ||||
|     // PBOs used to dump frames faster
 | ||||
|     std::array<OGLBuffer, 2> pbos; | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue