From ceab44b9ab32341f132933ad1a17c7b24862205e Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Thu, 8 Oct 2015 02:44:57 +0200 Subject: [PATCH] d3d12: Remove D3DGSFrame --- rpcs3/Emu/RSX/D3D12/D3D12GSRender.cpp | 37 +-------- rpcs3/Emu/RSX/D3D12/D3D12GSRender.h | 26 ------- rpcs3/Emu/RSX/GL/GLGSRender.cpp | 30 +------- rpcs3/Emu/RSX/GL/GLGSRender.h | 25 +------ rpcs3/Emu/RSX/GSManager.cpp | 2 +- rpcs3/Emu/RSX/GSManager.h | 2 +- rpcs3/Emu/RSX/GSRender.cpp | 56 ++++++++++++++ rpcs3/Emu/RSX/GSRender.h | 56 ++++++++++++-- rpcs3/Emu/RSX/Null/NullGSRender.h | 14 +--- rpcs3/Emu/RSX/RSXThread.cpp | 4 +- rpcs3/Emu/RSX/RSXThread.h | 4 +- rpcs3/Emu/System.h | 2 +- rpcs3/Gui/D3DGSFrame.cpp | 103 -------------------------- rpcs3/Gui/D3DGSFrame.h | 36 --------- rpcs3/Gui/GLGSFrame.cpp | 81 ++++---------------- rpcs3/Gui/GLGSFrame.h | 24 ++---- rpcs3/Gui/GSFrame.cpp | 89 +++++++++++++++------- rpcs3/Gui/GSFrame.h | 30 +++++--- rpcs3/rpcs3.cpp | 23 +++--- rpcs3/rpcs3.vcxproj | 2 - rpcs3/rpcs3.vcxproj.filters | 6 -- 21 files changed, 244 insertions(+), 408 deletions(-) delete mode 100644 rpcs3/Gui/D3DGSFrame.cpp delete mode 100644 rpcs3/Gui/D3DGSFrame.h diff --git a/rpcs3/Emu/RSX/D3D12/D3D12GSRender.cpp b/rpcs3/Emu/RSX/D3D12/D3D12GSRender.cpp index 41f73ac502..a26b0187d7 100644 --- a/rpcs3/Emu/RSX/D3D12/D3D12GSRender.cpp +++ b/rpcs3/Emu/RSX/D3D12/D3D12GSRender.cpp @@ -33,13 +33,6 @@ static void unloadD3D12FunctionPointers() FreeLibrary(D3D11Module); } -GetGSFrameCb2 GetGSFrame = nullptr; - -void SetGetD3DGSFrameCallback(GetGSFrameCb2 value) -{ - GetGSFrame = value; -} - void D3D12GSRender::ResourceStorage::Reset() { m_constantsBufferIndex = 0; @@ -136,7 +129,7 @@ D3D12DLLManagement::~D3D12DLLManagement() } D3D12GSRender::D3D12GSRender() - : GSRender(), m_D3D12Lib(), m_PSO(nullptr) + : GSRender(frame_type::DX12), m_D3D12Lib(), m_PSO(nullptr) { m_previous_address_a = 0; m_previous_address_b = 0; @@ -174,13 +167,11 @@ D3D12GSRender::D3D12GSRender() g_descriptorStrideRTV = m_device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_RTV); g_descriptorStrideSamplers = m_device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER); - m_frame = GetGSFrame(); - // Create swap chain and put them in a descriptor heap as rendertarget DXGI_SWAP_CHAIN_DESC swapChain = {}; swapChain.BufferCount = 2; swapChain.Windowed = true; - swapChain.OutputWindow = m_frame->getHandle(); + swapChain.OutputWindow = (HWND)m_frame->handle(); swapChain.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; swapChain.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; swapChain.SampleDesc.Count = 1; @@ -297,28 +288,6 @@ D3D12GSRender::~D3D12GSRender() ReleaseD2DStructures(); } -void D3D12GSRender::Close() -{ - if (joinable()) - { - join(); - } - - if (m_frame->IsShown()) - { - m_frame->Hide(); - } -} - -void D3D12GSRender::OnInit() -{ - m_frame->Show(); -} - -void D3D12GSRender::OnInitThread() -{ -} - void D3D12GSRender::OnExitThread() { } @@ -841,7 +810,7 @@ void D3D12GSRender::Flip() m_UAVHeap.m_getPos = newStorage.m_getPosUAVHeap; } - m_frame->Flip(nullptr); + m_frame->flip(nullptr); std::chrono::time_point flipEnd = std::chrono::system_clock::now(); diff --git a/rpcs3/Emu/RSX/D3D12/D3D12GSRender.h b/rpcs3/Emu/RSX/D3D12/D3D12GSRender.h index a571b2fadc..bd1734f48d 100644 --- a/rpcs3/Emu/RSX/D3D12/D3D12GSRender.h +++ b/rpcs3/Emu/RSX/D3D12/D3D12GSRender.h @@ -41,28 +41,6 @@ * are not currently correctly signaled which leads to deadlock. */ -class GSFrameBase2 -{ -public: - GSFrameBase2() {} - GSFrameBase2(const GSFrameBase2&) = delete; - virtual void Close() = 0; - - virtual bool IsShown() = 0; - virtual void Hide() = 0; - virtual void Show() = 0; - - virtual void* GetNewContext() = 0; - virtual void SetCurrent(void* ctx) = 0; - virtual void DeleteContext(void* ctx) = 0; - virtual void Flip(void* ctx) = 0; - virtual HWND getHandle() const = 0; -}; - -typedef GSFrameBase2*(*GetGSFrameCb2)(); - -void SetGetD3DGSFrameCallback(GetGSFrameCb2 value); - template struct InitHeap { @@ -470,7 +448,6 @@ private: u32 m_previous_address_d; u32 m_previous_address_z; public: - GSFrameBase2 *m_frame; u32 m_draw_frames; u32 m_skip_frames; @@ -491,7 +468,6 @@ private: void InitD2DStructures(); void ReleaseD2DStructures(); ID3D12Resource *writeColorBuffer(ID3D12Resource *RTT, ID3D12GraphicsCommandList *cmdlist); - virtual void Close() override; bool LoadProgram(); @@ -534,8 +510,6 @@ private: void renderOverlay(); protected: - virtual void OnInit() override; - virtual void OnInitThread() override; virtual void OnExitThread() override; virtual void OnReset() override; virtual void Clear(u32 cmd) override; diff --git a/rpcs3/Emu/RSX/GL/GLGSRender.cpp b/rpcs3/Emu/RSX/GL/GLGSRender.cpp index 34b86825cd..30c8ad7da3 100644 --- a/rpcs3/Emu/RSX/GL/GLGSRender.cpp +++ b/rpcs3/Emu/RSX/GL/GLGSRender.cpp @@ -777,19 +777,15 @@ void DrawCursorObj::InitializeLocations() } GLGSRender::GLGSRender() - : GSRender() - , m_frame(nullptr) + : GSRender(frame_type::OpenGL) , m_fp_buf_num(-1) , m_vp_buf_num(-1) , m_context(nullptr) { - m_frame = Emu.GetCallbacks().get_gs_frame().release(); } GLGSRender::~GLGSRender() { - m_frame->Close(); - m_frame->DeleteContext(m_context); } void GLGSRender::Enable(bool enable, const u32 cap) @@ -806,20 +802,6 @@ void GLGSRender::Enable(bool enable, const u32 cap) extern CellGcmContextData current_context; -void GLGSRender::Close() -{ - if (joinable()) - { - join(); - } - - if (m_frame->IsShown()) - { - m_frame->Hide(); - } - m_ctrl = nullptr; -} - void GLGSRender::EnableVertexData(bool indexed_draw) { static u32 offset_list[m_vertex_count]; @@ -1365,7 +1347,7 @@ void GLGSRender::WriteColorBuffers() } } -void GLGSRender::OnInit() +void GLGSRender::oninit() { m_draw_frames = 1; m_skip_frames = 0; @@ -1378,14 +1360,10 @@ void GLGSRender::OnInit() last_height = 0; last_depth_format = 0; - m_frame->Show(); } -void GLGSRender::OnInitThread() +void GLGSRender::oninit_thread() { - m_context = m_frame->GetNewContext(); - - m_frame->SetCurrent(m_context); InitProcTable(); @@ -2129,7 +2107,7 @@ void GLGSRender::Flip() m_post_draw_objs[i].Draw(); } - m_frame->Flip(m_context); + // m_frame->Flip(m_context); // Restore scissor if (m_set_scissor_horizontal && m_set_scissor_vertical) diff --git a/rpcs3/Emu/RSX/GL/GLGSRender.h b/rpcs3/Emu/RSX/GL/GLGSRender.h index 31e6ac6a93..e98e3021ab 100644 --- a/rpcs3/Emu/RSX/GL/GLGSRender.h +++ b/rpcs3/Emu/RSX/GL/GLGSRender.h @@ -111,24 +111,6 @@ public: void InitializeLocations(); }; -class GSFrameBase -{ -public: - GSFrameBase() {} - GSFrameBase(const GSFrameBase&) = delete; - virtual void Close() = 0; - - virtual bool IsShown() = 0; - virtual void Hide() = 0; - virtual void Show() = 0; - - virtual void* GetNewContext() = 0; - virtual void SetCurrent(void* ctx) = 0; - virtual void DeleteContext(void* ctx) = 0; - virtual void Flip(void* ctx) = 0; - -}; - class GLGSRender final : public GSRender { private: @@ -154,7 +136,6 @@ private: void* m_context; public: - GSFrameBase* m_frame; u32 m_draw_frames; u32 m_skip_frames; bool is_intel_vendor; @@ -169,7 +150,7 @@ private: void InitFragmentData(); void Enable(bool enable, const u32 cap); - virtual void Close() override; + bool LoadProgram(); void WriteBuffers(); void WriteDepthBuffer(); @@ -183,8 +164,8 @@ private: void InitDrawBuffers(); protected: - virtual void OnInit() override; - virtual void OnInitThread() override; + virtual void oninit() override; + virtual void oninit_thread() override; virtual void OnExitThread() override; virtual void OnReset() override; virtual void Clear(u32 cmd) override; diff --git a/rpcs3/Emu/RSX/GSManager.cpp b/rpcs3/Emu/RSX/GSManager.cpp index cbddef535a..592ead2c2d 100644 --- a/rpcs3/Emu/RSX/GSManager.cpp +++ b/rpcs3/Emu/RSX/GSManager.cpp @@ -48,7 +48,7 @@ void GSManager::Close() { if(m_render) { - m_render->Close(); + m_render->close(); delete m_render; m_render = nullptr; } diff --git a/rpcs3/Emu/RSX/GSManager.h b/rpcs3/Emu/RSX/GSManager.h index 7d8a185364..fc6d73e97b 100644 --- a/rpcs3/Emu/RSX/GSManager.h +++ b/rpcs3/Emu/RSX/GSManager.h @@ -1,6 +1,6 @@ #pragma once -struct GSRender; +class GSRender; struct GSInfo { diff --git a/rpcs3/Emu/RSX/GSRender.cpp b/rpcs3/Emu/RSX/GSRender.cpp index cebc2d08a8..e44dff40b6 100644 --- a/rpcs3/Emu/RSX/GSRender.cpp +++ b/rpcs3/Emu/RSX/GSRender.cpp @@ -5,6 +5,62 @@ #include "GSManager.h" #include "GSRender.h" +draw_context_t GSFrameBase::new_context() +{ + return std::shared_ptr(make_context(), [this](void* ctxt) { delete_context(ctxt); }); +} + +GSRender::GSRender(frame_type type) : m_frame(Emu.GetCallbacks().get_gs_frame(type).release()) +{ +} + +GSRender::~GSRender() +{ + m_context = nullptr; + + if (m_frame) + { + m_frame->close(); + } +} + +void GSRender::oninit() +{ + if (m_frame) + { + m_frame->show(); + } +} + +void GSRender::oninit_thread() +{ + if (m_frame) + { + m_context = m_frame->new_context(); + m_frame->set_current(m_context); + } +} + +void GSRender::close() +{ + if (m_frame && m_frame->shown()) + { + m_frame->hide(); + } + + if (joinable()) + { + join(); + } +} + +void GSRender::Flip() +{ + if (m_frame) + m_frame->flip(m_context); +} + + GSLock::GSLock(GSRender& renderer, GSLockType type) : m_renderer(renderer) , m_type(type) diff --git a/rpcs3/Emu/RSX/GSRender.h b/rpcs3/Emu/RSX/GSRender.h index 0aae3944df..8d7b24588a 100644 --- a/rpcs3/Emu/RSX/GSRender.h +++ b/rpcs3/Emu/RSX/GSRender.h @@ -1,13 +1,57 @@ #pragma once #include "Emu/RSX/RSXThread.h" -struct GSRender : public RSXThread -{ - virtual ~GSRender() override - { - } +using draw_context_t = std::shared_ptr; - virtual void Close()=0; +class GSFrameBase +{ +protected: + std::wstring m_title_message; + +public: + GSFrameBase() = default; + GSFrameBase(const GSFrameBase&) = delete; + + virtual void close() = 0; + virtual bool shown() = 0; + virtual void hide() = 0; + virtual void show() = 0; + + draw_context_t new_context(); + + virtual void set_current(draw_context_t ctx) = 0; + virtual void flip(draw_context_t ctx) = 0; + + virtual void* handle() const = 0; + void title_message(const std::wstring&); + +protected: + virtual void delete_context(void* ctx) = 0; + virtual void* make_context() = 0; +}; + +enum class frame_type +{ + Null, + OpenGL, + DX12 +}; + +class GSRender : public RSXThread +{ +protected: + GSFrameBase* m_frame; + draw_context_t m_context; + +public: + GSRender(frame_type type); + virtual ~GSRender(); + + void oninit() override; + void oninit_thread() override; + + void close(); + void Flip() override; }; enum GSLockType diff --git a/rpcs3/Emu/RSX/Null/NullGSRender.h b/rpcs3/Emu/RSX/Null/NullGSRender.h index d25815fd50..7ba199b8a2 100644 --- a/rpcs3/Emu/RSX/Null/NullGSRender.h +++ b/rpcs3/Emu/RSX/Null/NullGSRender.h @@ -5,7 +5,7 @@ class NullGSRender final : public GSRender { public: - NullGSRender() + NullGSRender() : GSRender(frame_type::Null) { } @@ -14,11 +14,11 @@ public: } private: - virtual void OnInit() override + virtual void oninit() override { } - virtual void OnInitThread() override + virtual void oninit_thread() override { } @@ -42,14 +42,6 @@ private: { } - virtual void Close() override - { - if (joinable()) - { - join(); - } - } - virtual void semaphorePGRAPHTextureReadRelease(u32 offset, u32 value) override { } diff --git a/rpcs3/Emu/RSX/RSXThread.cpp b/rpcs3/Emu/RSX/RSXThread.cpp index 74fdae4aff..3c83a2b611 100644 --- a/rpcs3/Emu/RSX/RSXThread.cpp +++ b/rpcs3/Emu/RSX/RSXThread.cpp @@ -2493,7 +2493,7 @@ void RSXThread::Task() u8 inc; LOG_NOTICE(RSX, "RSX thread started"); - OnInitThread(); + oninit_thread(); m_last_flip_time = get_system_time() - 1000000; @@ -2613,7 +2613,7 @@ void RSXThread::Init(const u32 ioAddress, const u32 ioSize, const u32 ctrlAddres m_used_gcm_commands.clear(); - OnInit(); + oninit(); start(WRAP_EXPR("RSXThread"), WRAP_EXPR(Task())); } diff --git a/rpcs3/Emu/RSX/RSXThread.h b/rpcs3/Emu/RSX/RSXThread.h index b94127afc0..5d99d37cbb 100644 --- a/rpcs3/Emu/RSX/RSXThread.h +++ b/rpcs3/Emu/RSX/RSXThread.h @@ -642,8 +642,8 @@ protected: u32 OutOfArgsCount(const uint x, const u32 cmd, const u32 count, const u32 args_addr); void DoCmd(const u32 fcmd, const u32 cmd, const u32 args_addr, const u32 count); - virtual void OnInit() = 0; - virtual void OnInitThread() = 0; + virtual void oninit() = 0; + virtual void oninit_thread() = 0; virtual void OnExitThread() = 0; virtual void OnReset() = 0; diff --git a/rpcs3/Emu/System.h b/rpcs3/Emu/System.h index 1afd964ddc..0c3b730a08 100644 --- a/rpcs3/Emu/System.h +++ b/rpcs3/Emu/System.h @@ -11,7 +11,7 @@ struct EmuCallbacks std::function()> get_kb_handler; std::function()> get_mouse_handler; std::function()> get_pad_handler; - std::function()> get_gs_frame; + std::function(enum class frame_type)> get_gs_frame; std::function()> get_msg_dialog; std::function()> get_save_dialog; }; diff --git a/rpcs3/Gui/D3DGSFrame.cpp b/rpcs3/Gui/D3DGSFrame.cpp deleted file mode 100644 index f4327da252..0000000000 --- a/rpcs3/Gui/D3DGSFrame.cpp +++ /dev/null @@ -1,103 +0,0 @@ -#include "stdafx_gui.h" -#if defined(DX12_SUPPORT) -#include "Emu/Memory/Memory.h" -#include "Emu/System.h" -#include "D3DGSFrame.h" -#include "Utilities/Timer.h" - -D3DGSFrame::D3DGSFrame() - : GSFrame(nullptr, "GSFrame[DirectX 12]") - , m_frames(0) -{ - SetIcon(wxICON(frame_icon)); - canvas = new wxWindow(this, wxID_ANY); - canvas->SetSize(GetClientSize()); - - canvas->Bind(wxEVT_LEFT_DCLICK, &GSFrame::OnLeftDclick, this); -} - -D3DGSFrame::~D3DGSFrame() -{ -} - -void D3DGSFrame::Close() -{ - GSFrame::Close(); -} - -bool D3DGSFrame::IsShown() -{ - return GSFrame::IsShown(); -} - -void D3DGSFrame::Hide() -{ - GSFrame::Hide(); -} - -void D3DGSFrame::Show() -{ - GSFrame::Show(); -} - -void* D3DGSFrame::GetNewContext() -{ - return nullptr;//new wxGLContext(GetCanvas()); -} - -void D3DGSFrame::SetCurrent(void* ctx) -{ -// GetCanvas()->SetCurrent(*(wxGLContext*)ctx); -} - -void D3DGSFrame::DeleteContext(void* ctx) -{ -// delete (wxGLContext*)ctx; -} - -void D3DGSFrame::Flip(void* context) -{ - if (!canvas) return; -// canvas->SetCurrent(*(wxGLContext*)context); - - static Timer fps_t; -// canvas->SwapBuffers(); - m_frames++; - - const std::string sub_title = Emu.GetTitle() + (Emu.GetTitleID().length() ? " [" + Emu.GetTitleID() + "] | " : " | ") + " | "; - - if (fps_t.GetElapsedTimeInSec() >= 0.5) - { - // can freeze on exit - SetTitle(wxString(sub_title.c_str(), wxConvUTF8) + wxString::Format("FPS: %.2f", (double)m_frames / fps_t.GetElapsedTimeInSec())); - m_frames = 0; - fps_t.Start(); - } -} - -void D3DGSFrame::OnSize(wxSizeEvent& event) -{ - if (canvas) canvas->SetSize(GetClientSize()); - event.Skip(); -} - -void D3DGSFrame::SetViewport(int x, int y, u32 w, u32 h) -{ - /* - //ConLog.Warning("SetViewport(x=%d, y=%d, w=%d, h=%d)", x, y, w, h); - - const wxSize client = GetClientSize(); - const wxSize viewport = AspectRatio(client, wxSize(w, h)); - - const int vx = (client.GetX() - viewport.GetX()) / 2; - const int vy = (client.GetY() - viewport.GetY()) / 2; - - glViewport(vx + x, vy + y, viewport.GetWidth(), viewport.GetHeight()); - */ -} - -HWND D3DGSFrame::getHandle() const -{ - return canvas->GetHandle(); -} -#endif \ No newline at end of file diff --git a/rpcs3/Gui/D3DGSFrame.h b/rpcs3/Gui/D3DGSFrame.h deleted file mode 100644 index 47de197d0a..0000000000 --- a/rpcs3/Gui/D3DGSFrame.h +++ /dev/null @@ -1,36 +0,0 @@ -#pragma once - -#if defined(DX12_SUPPORT) -#include "Emu/RSX/D3D12/D3D12GSRender.h" -#include "Gui/GSFrame.h" -#include "wx/window.h" - -struct D3DGSFrame : public GSFrame, public GSFrameBase2 -{ - wxWindow* canvas; - u32 m_frames; - - D3DGSFrame(); - ~D3DGSFrame(); - - virtual void Close() override; - - virtual bool IsShown() override; - virtual void Hide() override; - virtual void Show() override; - - virtual void* GetNewContext() override; - virtual void SetCurrent(void* ctx) override; - virtual void DeleteContext(void* ctx) override; - virtual void Flip(void* context) override; - - wxWindow* GetCanvas() const { return canvas; } - - virtual void SetViewport(int x, int y, u32 w, u32 h) override; - virtual HWND getHandle() const override; - -private: - virtual void OnSize(wxSizeEvent& event); -}; - -#endif \ No newline at end of file diff --git a/rpcs3/Gui/GLGSFrame.cpp b/rpcs3/Gui/GLGSFrame.cpp index def20179f3..adc3b2327f 100644 --- a/rpcs3/Gui/GLGSFrame.cpp +++ b/rpcs3/Gui/GLGSFrame.cpp @@ -3,100 +3,51 @@ #include "Emu/Memory/Memory.h" #include "Emu/System.h" #include "GLGSFrame.h" -#include "D3DGSFrame.h" #include "Utilities/Timer.h" #ifndef _WIN32 #include "frame_icon.xpm" #endif -GLGSFrame::GLGSFrame() - : GSFrame(nullptr, "GSFrame[OpenGL]") - , m_frames(0) +GLGSFrame::GLGSFrame() : GSFrame("OpenGL") { SetIcon(wxICON(frame_icon)); - canvas = new wxGLCanvas(this, wxID_ANY, NULL); - canvas->SetSize(GetClientSize()); + m_canvas = new wxGLCanvas(this, wxID_ANY, NULL); + m_canvas->SetSize(GetClientSize()); - canvas->Bind(wxEVT_LEFT_DCLICK, &GSFrame::OnLeftDclick, this); + m_canvas->Bind(wxEVT_LEFT_DCLICK, &GSFrame::OnLeftDclick, this); } GLGSFrame::~GLGSFrame() { } -void GLGSFrame::Close() +void* GLGSFrame::make_context() { - GSFrame::Close(); + return new wxGLContext(m_canvas); } -bool GLGSFrame::IsShown() +void GLGSFrame::set_current(draw_context_t ctx) { - return GSFrame::IsShown(); + m_canvas->SetCurrent(*(wxGLContext*)ctx.get()); } -void GLGSFrame::Hide() -{ - GSFrame::Hide(); -} - -void GLGSFrame::Show() -{ - GSFrame::Show(); -} - -void* GLGSFrame::GetNewContext() -{ - return new wxGLContext(GetCanvas()); -} - -void GLGSFrame::SetCurrent(void* ctx) -{ - GetCanvas()->SetCurrent(*(wxGLContext*)ctx); -} - -void GLGSFrame::DeleteContext(void* ctx) +void GLGSFrame::delete_context(void* ctx) { delete (wxGLContext*)ctx; } -void GLGSFrame::Flip(void* context) +void GLGSFrame::flip(draw_context_t context) { - if (!canvas) return; - canvas->SetCurrent(*(wxGLContext*)context); - - static Timer fps_t; - canvas->SwapBuffers(); - m_frames++; - - const std::string sub_title = Emu.GetTitle() + (Emu.GetTitleID().length() ? " [" + Emu.GetTitleID() + "] | " : " | "); - - if (fps_t.GetElapsedTimeInSec() >= 0.5) - { - // can freeze on exit - SetTitle(wxString(sub_title.c_str(), wxConvUTF8) + wxString::Format("FPS: %.2f", (double)m_frames / fps_t.GetElapsedTimeInSec())); - m_frames = 0; - fps_t.Start(); - } + GSFrame::flip(context); + if (!m_canvas) return; + m_canvas->SetCurrent(*(wxGLContext*)context.get()); + m_canvas->SwapBuffers(); } void GLGSFrame::OnSize(wxSizeEvent& event) { - if (canvas) canvas->SetSize(GetClientSize()); + if (m_canvas) + m_canvas->SetSize(GetClientSize()); event.Skip(); -} - -void GLGSFrame::SetViewport(int x, int y, u32 w, u32 h) -{ - /* - //ConLog.Warning("SetViewport(x=%d, y=%d, w=%d, h=%d)", x, y, w, h); - - const wxSize client = GetClientSize(); - const wxSize viewport = AspectRatio(client, wxSize(w, h)); - - const int vx = (client.GetX() - viewport.GetX()) / 2; - const int vy = (client.GetY() - viewport.GetY()) / 2; - - glViewport(vx + x, vy + y, viewport.GetWidth(), viewport.GetHeight()); - */ } \ No newline at end of file diff --git a/rpcs3/Gui/GLGSFrame.h b/rpcs3/Gui/GLGSFrame.h index ace40928e4..1c250cc7ff 100644 --- a/rpcs3/Gui/GLGSFrame.h +++ b/rpcs3/Gui/GLGSFrame.h @@ -3,28 +3,18 @@ #include "Gui/GSFrame.h" #include "wx/glcanvas.h" -struct GLGSFrame : public GSFrame, public GSFrameBase +class GLGSFrame : public GSFrame { - wxGLCanvas* canvas; + wxGLCanvas* m_canvas; u32 m_frames; - +public: GLGSFrame(); ~GLGSFrame(); - virtual void Close() override; - - virtual bool IsShown() override; - virtual void Hide() override; - virtual void Show() override; - - virtual void* GetNewContext() override; - virtual void SetCurrent(void* ctx) override; - virtual void DeleteContext(void* ctx) override; - virtual void Flip(void* context) override; - - wxGLCanvas* GetCanvas() const { return canvas; } - - virtual void SetViewport(int x, int y, u32 w, u32 h) override; + virtual void* make_context() override; + virtual void set_current(draw_context_t context) override; + virtual void delete_context(void* ctx) override; + virtual void flip(draw_context_t context) override; private: virtual void OnSize(wxSizeEvent& event); diff --git a/rpcs3/Gui/GSFrame.cpp b/rpcs3/Gui/GSFrame.cpp index c34509bb3e..613f1b35b8 100644 --- a/rpcs3/Gui/GSFrame.cpp +++ b/rpcs3/Gui/GSFrame.cpp @@ -9,25 +9,7 @@ BEGIN_EVENT_TABLE(GSFrame, wxFrame) EVT_SIZE(GSFrame::OnSize) END_EVENT_TABLE() -wxSize AspectRatio(wxSize rs, const wxSize as) -{ - const double aq = (double)as.x / as.y; - const double rq = (double)rs.x / rs.y; - const double q = aq / rq; - - if (q > 1.0) - { - rs.y /= q; - } - else if (q < 1.0) - { - rs.x *= q; - } - - return rs; -} - -GSFrame::GSFrame(wxWindow* parent, const wxString& title) : wxFrame(parent, wxID_ANY, title) +GSFrame::GSFrame(const wxString& title) : wxFrame(nullptr, wxID_ANY, title) { CellVideoOutResolution res = ResolutionTable[ResolutionIdToNum(Ini.GSResolution.GetValue())]; SetClientSize(res.width, res.height); @@ -73,13 +55,66 @@ void GSFrame::OnFullScreen() ShowFullScreen(!IsFullScreen()); } - -/* -void GSFrame::SetSize(int width, int height) +void GSFrame::close() { -m_size.SetWidth(width); -m_size.SetHeight(height); -//wxFrame::SetSize(width, height); -OnSize(wxSizeEvent()); + wxFrame::Close(); } -*/ + +bool GSFrame::shown() +{ + return wxFrame::IsShown(); +} + +void GSFrame::hide() +{ + wxFrame::Hide(); +} + +void GSFrame::show() +{ + wxFrame::Show(); +} + +void* GSFrame::handle() const +{ + return GetHandle(); +} + +void* GSFrame::make_context() +{ + return nullptr; +} + +void GSFrame::set_current(draw_context_t ctx) +{ +} + +void GSFrame::delete_context(void* ctx) +{ +} + +void GSFrame::flip(draw_context_t) +{ + ++m_frames; + + static Timer fps_t; + + if (fps_t.GetElapsedTimeInSec() >= 0.5) + { + std::string title = fmt::format("FPS: %.2f", (double)m_frames / fps_t.GetElapsedTimeInSec()); + + if (!m_title_message.empty()) + title += " | " + m_title_message; + + if (!Emu.GetTitle().empty()) + title += " | " + Emu.GetTitle(); + + if (!Emu.GetTitleID().empty()) + title += " | [" + Emu.GetTitleID() + "]"; + + // can freeze on exit + SetTitle(wxString(title.c_str(), wxConvUTF8)); + m_frames = 0; + fps_t.Start(); + } +} \ No newline at end of file diff --git a/rpcs3/Gui/GSFrame.h b/rpcs3/Gui/GSFrame.h index 83601a00cf..5c5db3de84 100644 --- a/rpcs3/Gui/GSFrame.h +++ b/rpcs3/Gui/GSFrame.h @@ -1,21 +1,33 @@ -#pragma once +#pragma once +#include "Emu/Memory/vm.h" +#include "Emu/RSX/GSRender.h" -wxSize AspectRatio(wxSize rs, const wxSize as); - -class GSFrame : public wxFrame +class GSFrame : public wxFrame, public GSFrameBase { -protected: - GSFrame(wxWindow* parent, const wxString& title); + u64 m_frames; +public: + GSFrame(const wxString& title); - virtual void SetViewport(int x, int y, u32 w, u32 h) {} +protected: virtual void OnPaint(wxPaintEvent& event); virtual void OnClose(wxCloseEvent& event); - //virtual void OnSize(wxSizeEvent&); - void OnKeyDown(wxKeyEvent& event); void OnFullScreen(); + void close() override; + + bool shown() override; + void hide() override; + void show() override; + + void* handle() const override; + + void* make_context() override; + void set_current(draw_context_t context) override; + void delete_context(void* context) override; + void flip(draw_context_t context) override; + public: void OnLeftDclick(wxMouseEvent&) { diff --git a/rpcs3/rpcs3.cpp b/rpcs3/rpcs3.cpp index e0e8865b0d..5751c3a0d7 100644 --- a/rpcs3/rpcs3.cpp +++ b/rpcs3/rpcs3.cpp @@ -26,7 +26,6 @@ #include "Gui/SaveDataDialog.h" #include "Gui/GLGSFrame.h" -#include "Gui/D3DGSFrame.h" #include #ifdef _WIN32 @@ -112,18 +111,20 @@ bool Rpcs3App::OnInit() } }; - callbacks.get_gs_frame = []() -> std::unique_ptr + callbacks.get_gs_frame = [](frame_type type) -> std::unique_ptr { - return std::make_unique(); - }; + switch (type) + { + case frame_type::OpenGL: + return std::make_unique(); - // TODO: unify with get_gs_frame callback -#if defined(DX12_SUPPORT) - SetGetD3DGSFrameCallback([]() ->GSFrameBase2* - { - return new D3DGSFrame(); - }); -#endif + case frame_type::DX12: + return std::make_unique("DirectX 12"); + + case frame_type::Null: + return std::make_unique("Null"); + } + }; callbacks.get_msg_dialog = []() -> std::unique_ptr { diff --git a/rpcs3/rpcs3.vcxproj b/rpcs3/rpcs3.vcxproj index 37f0b8b2f2..12224c80d4 100644 --- a/rpcs3/rpcs3.vcxproj +++ b/rpcs3/rpcs3.vcxproj @@ -511,7 +511,6 @@ - @@ -561,7 +560,6 @@ - diff --git a/rpcs3/rpcs3.vcxproj.filters b/rpcs3/rpcs3.vcxproj.filters index b97b3b1f86..14de4716da 100644 --- a/rpcs3/rpcs3.vcxproj.filters +++ b/rpcs3/rpcs3.vcxproj.filters @@ -102,9 +102,6 @@ Gui - - Gui - Gui @@ -216,9 +213,6 @@ Gui - - Gui - Gui