GS/Qt: Represent the current frame on resize when paused

Stops the frame displayed with incorrect proportions.
This commit is contained in:
Connor McLaughlin 2022-05-20 23:09:24 +10:00 committed by refractionpcsx2
parent 0a667bf18a
commit 28795e549b
8 changed files with 55 additions and 0 deletions

View File

@ -744,6 +744,10 @@ void Host::ResizeHostDisplay(u32 new_window_width, u32 new_window_height, float
{
s_host_display->ResizeRenderWindow(new_window_width, new_window_height, new_window_scale);
ImGuiManager::WindowResized();
// if we're paused, re-present the current frame at the new window size.
if (VMManager::GetState() == VMState::Paused)
GetMTGS().PresentCurrentFrame();
}
void Host::RequestResizeHostDisplay(s32 width, s32 height)
@ -755,6 +759,10 @@ void Host::UpdateHostDisplay()
{
g_emu_thread->updateDisplay();
ImGuiManager::WindowResized();
// if we're paused, re-present the current frame at the new window size.
if (VMManager::GetState() == VMState::Paused)
GetMTGS().PresentCurrentFrame();
}
void Host::OnVMStarting()

View File

@ -117,6 +117,10 @@ void ImGuiManager::WindowResized()
ImGui::GetIO().DisplaySize = ImVec2(static_cast<float>(new_width), static_cast<float>(new_height));
UpdateScale();
// restart imgui frame on the new window size to pick it up, otherwise we draw to the old size
ImGui::EndFrame();
NewFrame();
}
void ImGuiManager::UpdateScale()

View File

@ -383,6 +383,10 @@ public:
/// Fully stops the thread, closing in the process if needed.
void ShutdownThread();
/// Re-presents the current frame. Call when things like window resizes happen to re-display
/// the current frame with the correct proportions. Should only be called on the GS thread.
void PresentCurrentFrame();
// Waits for the GS to empty out the entire ring buffer contents.
void WaitGS(bool syncRegs=true, bool weakWait=false, bool isMTVU=false);
void ResetGS(bool hardware_reset);

View File

@ -527,6 +527,11 @@ void GSStopGSDump()
g_gs_renderer->StopGSDump();
}
void GSPresentCurrentFrame()
{
g_gs_renderer->PresentCurrentFrame();
}
#ifndef PCSX2_CORE
void GSkeyEvent(const HostKeyEvent& e)

View File

@ -71,6 +71,7 @@ void GSvsync(u32 field, bool registers_written);
int GSfreeze(FreezeAction mode, freezeData* data);
void GSQueueSnapshot(const std::string& path, u32 gsdump_frames = 0);
void GSStopGSDump();
void GSPresentCurrentFrame();
#ifndef PCSX2_CORE
void GSkeyEvent(const HostKeyEvent& e);
void GSconfigure();

View File

@ -745,6 +745,30 @@ void GSRenderer::StopGSDump()
m_dump_frames = 0;
}
void GSRenderer::PresentCurrentFrame()
{
g_gs_device->ResetAPIState();
if (Host::BeginPresentFrame(false))
{
GSTexture* current = g_gs_device->GetCurrent();
if (current)
{
HostDisplay* const display = g_gs_device->GetDisplay();
const GSVector4 draw_rect(CalculateDrawRect(display->GetWindowWidth(), display->GetWindowHeight(),
current->GetWidth(), current->GetHeight(), display->GetDisplayAlignment(), display->UsesLowerLeftOrigin(), GetVideoMode() == GSVideoMode::SDTV_480P));
static constexpr ShaderConvert s_shader[5] = { ShaderConvert::COPY, ShaderConvert::SCANLINE,
ShaderConvert::DIAGONAL_FILTER, ShaderConvert::TRIANGULAR_FILTER,
ShaderConvert::COMPLEX_FILTER }; // FIXME
g_gs_device->StretchRect(current, nullptr, draw_rect, s_shader[GSConfig.TVShader], GSConfig.LinearPresent);
}
Host::EndPresentFrame();
}
g_gs_device->RestoreAPIState();
}
#ifndef PCSX2_CORE
bool GSRenderer::BeginCapture(std::string& filename)

View File

@ -68,6 +68,7 @@ public:
void QueueSnapshot(const std::string& path, u32 gsdump_frames);
void StopGSDump();
void PresentCurrentFrame();
#ifndef PCSX2_CORE
bool BeginCapture(std::string& filename);

View File

@ -911,6 +911,9 @@ void SysMtgsThread::Freeze(FreezeAction mode, MTGS_FreezeData& data)
void SysMtgsThread::RunOnGSThread(AsyncCallType func)
{
SendPointerPacket(GS_RINGTYPE_ASYNC_CALL, 0, new AsyncCallType(std::move(func)));
// wake the gs thread in case it's sleeping
SetEvent();
}
void SysMtgsThread::ApplySettings()
@ -993,3 +996,8 @@ bool SysMtgsThread::SaveMemorySnapshot(u32 width, u32 height, std::vector<u32>*
WaitGS(false, false, false);
return result;
}
void SysMtgsThread::PresentCurrentFrame()
{
GSPresentCurrentFrame();
}