diff --git a/Source/Android/jni/MainAndroid.cpp b/Source/Android/jni/MainAndroid.cpp index 720a96c5af..4ca2f9c3f9 100644 --- a/Source/Android/jni/MainAndroid.cpp +++ b/Source/Android/jni/MainAndroid.cpp @@ -484,8 +484,7 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_StopEmulatio jobject obj) { std::lock_guard guard(s_host_identity_lock); - Core::SaveScreenShot("thumb"); - g_renderer->s_screenshot_completed.WaitFor(std::chrono::seconds(2)); + Core::SaveScreenShot("thumb", true); Core::Stop(); updateMainFrameEvent.Set(); // Kick the waiting event } diff --git a/Source/Core/Core/Core.cpp b/Source/Core/Core/Core.cpp index 98699a784f..dc4399fb63 100644 --- a/Source/Core/Core/Core.cpp +++ b/Source/Core/Core/Core.cpp @@ -732,19 +732,19 @@ static std::string GenerateScreenshotName() return name; } -void SaveScreenShot() +void SaveScreenShot(bool wait_for_completion) { const bool bPaused = GetState() == State::Paused; SetState(State::Paused); - g_renderer->SetScreenshot(GenerateScreenshotName()); + g_renderer->SaveScreenshot(GenerateScreenshotName(), wait_for_completion); if (!bPaused) SetState(State::Running); } -void SaveScreenShot(const std::string& name) +void SaveScreenShot(const std::string& name, bool wait_for_completion) { const bool bPaused = GetState() == State::Paused; @@ -752,7 +752,7 @@ void SaveScreenShot(const std::string& name) std::string filePath = GenerateScreenshotFolderPath() + name + ".png"; - g_renderer->SetScreenshot(filePath); + g_renderer->SaveScreenshot(filePath, wait_for_completion); if (!bPaused) SetState(State::Running); diff --git a/Source/Core/Core/Core.h b/Source/Core/Core/Core.h index 7b94844f87..ace543a153 100644 --- a/Source/Core/Core/Core.h +++ b/Source/Core/Core/Core.h @@ -55,8 +55,8 @@ bool IsGPUThread(); void SetState(State state); State GetState(); -void SaveScreenShot(); -void SaveScreenShot(const std::string& name); +void SaveScreenShot(bool wait_for_completion = false); +void SaveScreenShot(const std::string& name, bool wait_for_completion = false); void Callback_WiimoteInterruptChannel(int _number, u16 _channelID, const void* _pData, u32 _Size); diff --git a/Source/Core/VideoCommon/RenderBase.cpp b/Source/Core/VideoCommon/RenderBase.cpp index 990f01d53d..7e598e2373 100644 --- a/Source/Core/VideoCommon/RenderBase.cpp +++ b/Source/Core/VideoCommon/RenderBase.cpp @@ -276,11 +276,20 @@ void Renderer::ConvertStereoRectangle(const TargetRectangle& rc, TargetRectangle } } -void Renderer::SetScreenshot(const std::string& filename) +void Renderer::SaveScreenshot(const std::string& filename, bool wait_for_completion) { - std::lock_guard lk(m_screenshot_lock); - m_screenshot_name = filename; - m_screenshot_request.Set(); + // We must not hold the lock while waiting for the screenshot to complete. + { + std::lock_guard lk(m_screenshot_lock); + m_screenshot_name = filename; + m_screenshot_request.Set(); + } + + if (wait_for_completion) + { + // This is currently only used by Android, and it was using a wait time of 2 seconds. + m_screenshot_completed.WaitFor(std::chrono::seconds(2)); + } } // Create On-Screen-Messages @@ -814,7 +823,7 @@ void Renderer::RunFrameDumps() // Reset settings m_screenshot_name.clear(); - s_screenshot_completed.Set(); + m_screenshot_completed.Set(); } if (SConfig::GetInstance().m_DumpFrames) diff --git a/Source/Core/VideoCommon/RenderBase.h b/Source/Core/VideoCommon/RenderBase.h index a8323c27a2..79c174e28c 100644 --- a/Source/Core/VideoCommon/RenderBase.h +++ b/Source/Core/VideoCommon/RenderBase.h @@ -111,7 +111,7 @@ public: float EFBToScaledXf(float x) { return x * ((float)GetTargetWidth() / (float)EFB_WIDTH); } float EFBToScaledYf(float y) { return y * ((float)GetTargetHeight() / (float)EFB_HEIGHT); } // Random utilities - void SetScreenshot(const std::string& filename); + void SaveScreenshot(const std::string& filename, bool wait_for_completion); void DrawDebugText(); virtual void RenderText(const std::string& text, int left, int top, u32 color) = 0; @@ -140,8 +140,6 @@ public: // Max height/width virtual u32 GetMaxTextureSize() = 0; - Common::Event s_screenshot_completed; - // Final surface changing // This is called when the surface is resized (WX) or the window changes (Android). virtual void ChangeSurface(void* new_surface_handle) {} @@ -158,6 +156,7 @@ protected: void FinishFrameData(); Common::Flag m_screenshot_request; + Common::Event m_screenshot_completed; std::mutex m_screenshot_lock; std::string m_screenshot_name;