Skip to content

Commit

Permalink
Merge pull request #17156 from hrydgard/more-cleanup
Browse files Browse the repository at this point in the history
Remove graphics init/shutdown stuff from "Host"
  • Loading branch information
hrydgard committed Mar 21, 2023
2 parents e7f1716 + 47f0635 commit ceaaaae
Show file tree
Hide file tree
Showing 17 changed files with 52 additions and 98 deletions.
5 changes: 1 addition & 4 deletions Core/Host.h
Expand Up @@ -27,10 +27,7 @@ class Host {
public:
virtual ~Host() {}

virtual bool InitGraphics(std::string *error_string, GraphicsContext **ctx) = 0;
virtual void ShutdownGraphics() = 0;

virtual void UpdateSound() {}
virtual void UpdateSound() {} // still needed for libretro, will need a proper effort.
virtual void PollControllers() {}
virtual void ToggleDebugConsoleVisibility() {}

Expand Down
3 changes: 0 additions & 3 deletions Qt/QtHost.h
Expand Up @@ -31,9 +31,6 @@ class QtHost : public Host {
mainWindow = mainWindow_;
}

bool InitGraphics(std::string *error_message, GraphicsContext **ctx) override { return true; }
void ShutdownGraphics() override {}

void UpdateSound() override {}

bool AttemptLoadSymbolMap() override {
Expand Down
3 changes: 0 additions & 3 deletions UI/HostTypes.h
Expand Up @@ -24,9 +24,6 @@ class NativeHost : public Host {
public:
NativeHost() {}

bool InitGraphics(std::string *error_message, GraphicsContext **ctx) override { return true; }
void ShutdownGraphics() override {}

void UpdateSound() override {}

bool AttemptLoadSymbolMap() override {return false;}
Expand Down
6 changes: 0 additions & 6 deletions UI/NativeApp.cpp
Expand Up @@ -1426,12 +1426,6 @@ void NativeShutdown() {
screenManager = nullptr;
}

if (host) {
host->ShutdownGraphics();
delete host;
host = nullptr;
}

#if !PPSSPP_PLATFORM(UWP)
#endif
g_Config.Save("NativeShutdown");
Expand Down
9 changes: 0 additions & 9 deletions UWP/UWPHost.cpp
Expand Up @@ -54,15 +54,6 @@ void UWPHost::SetConsolePosition() {
void UWPHost::UpdateConsolePosition() {
}

bool UWPHost::InitGraphics(std::string *error_message, GraphicsContext **ctx) {
// Done elsewhere
return true;
}

void UWPHost::ShutdownGraphics() {
// Done elsewhere
}

void UWPHost::SetWindowTitle(const char *message) {
}

Expand Down
3 changes: 0 additions & 3 deletions UWP/UWPHost.h
Expand Up @@ -12,10 +12,7 @@ class UWPHost : public Host {
UWPHost();
~UWPHost();

// If returns false, will return a null context
bool InitGraphics(std::string *error_message, GraphicsContext **ctx) override;
void PollControllers() override;
void ShutdownGraphics() override;

void UpdateSound() override;

Expand Down
43 changes: 41 additions & 2 deletions Windows/EmuThread.cpp
Expand Up @@ -26,6 +26,13 @@
#include "Core/Config.h"
#include "Core/ConfigValues.h"

#if PPSSPP_API(ANY_GL)
#include "Windows/GPU/WindowsGLContext.h"
#endif
#include "Windows/GPU/WindowsVulkanContext.h"
#include "Windows/GPU/D3D9Context.h"
#include "Windows/GPU/D3D11Context.h"

enum class EmuThreadState {
DISABLED,
START_REQUESTED,
Expand Down Expand Up @@ -112,6 +119,37 @@ static void EmuThreadJoin() {
INFO_LOG(SYSTEM, "EmuThreadJoin - joined");
}

bool CreateGraphicsBackend(std::string *error_message, GraphicsContext **ctx) {
WindowsGraphicsContext *graphicsContext = nullptr;
switch (g_Config.iGPUBackend) {
#if PPSSPP_API(ANY_GL)
case (int)GPUBackend::OPENGL:
graphicsContext = new WindowsGLContext();
break;
#endif
case (int)GPUBackend::DIRECT3D9:
graphicsContext = new D3D9Context();
break;
case (int)GPUBackend::DIRECT3D11:
graphicsContext = new D3D11Context();
break;
case (int)GPUBackend::VULKAN:
graphicsContext = new WindowsVulkanContext();
break;
default:
return false;
}

if (graphicsContext->Init(MainWindow::GetHInstance(), MainWindow::GetDisplayHWND(), error_message)) {
*ctx = graphicsContext;
return true;
} else {
delete graphicsContext;
*ctx = nullptr;
return false;
}
}

void MainThreadFunc() {
if (useEmuThread) {
// We'll start up a separate thread we'll call Emu
Expand Down Expand Up @@ -164,7 +202,7 @@ void MainThreadFunc() {
System_Notify(SystemNotification::UI);

std::string error_string;
bool success = host->InitGraphics(&error_string, &g_graphicsContext);
bool success = CreateGraphicsBackend(&error_string, &g_graphicsContext);

if (success) {
// Main thread is the render thread.
Expand Down Expand Up @@ -299,7 +337,8 @@ void MainThreadFunc() {
g_graphicsContext->ThreadEnd();
g_graphicsContext->ShutdownFromRenderThread();

// NativeShutdown deletes the graphics context through host->ShutdownGraphics().
g_graphicsContext->Shutdown();

NativeShutdown();

PostMessage(MainWindow::GetHWND(), MainWindow::WM_USER_UPDATE_UI, 0, 0);
Expand Down
46 changes: 0 additions & 46 deletions Windows/WindowsHost.cpp
Expand Up @@ -53,13 +53,6 @@
#include "Windows/WindowsHost.h"
#include "Windows/MainWindow.h"

#if PPSSPP_API(ANY_GL)
#include "Windows/GPU/WindowsGLContext.h"
#endif
#include "Windows/GPU/WindowsVulkanContext.h"
#include "Windows/GPU/D3D9Context.h"
#include "Windows/GPU/D3D11Context.h"

#include "Windows/Debugger/DebuggerShared.h"
#include "Windows/Debugger/Debugger_Disasm.h"
#include "Windows/Debugger/Debugger_MemoryDlg.h"
Expand Down Expand Up @@ -116,45 +109,6 @@ void WindowsHost::UpdateConsolePosition() {
}
}

bool WindowsHost::InitGraphics(std::string *error_message, GraphicsContext **ctx) {
WindowsGraphicsContext *graphicsContext = nullptr;
switch (g_Config.iGPUBackend) {
#if PPSSPP_API(ANY_GL)
case (int)GPUBackend::OPENGL:
graphicsContext = new WindowsGLContext();
break;
#endif
case (int)GPUBackend::DIRECT3D9:
graphicsContext = new D3D9Context();
break;
case (int)GPUBackend::DIRECT3D11:
graphicsContext = new D3D11Context();
break;
case (int)GPUBackend::VULKAN:
graphicsContext = new WindowsVulkanContext();
break;
default:
return false;
}

if (graphicsContext->Init(hInstance_, displayWindow_, error_message)) {
*ctx = graphicsContext;
gfx_ = graphicsContext;
return true;
} else {
delete graphicsContext;
*ctx = nullptr;
gfx_ = nullptr;
return false;
}
}

void WindowsHost::ShutdownGraphics() {
gfx_->Shutdown();
delete gfx_;
gfx_ = nullptr;
}

void WindowsHost::SetWindowTitle(const char *message) {
#ifdef GOLD
const char *name = "PPSSPP Gold ";
Expand Down
8 changes: 0 additions & 8 deletions Windows/WindowsHost.h
Expand Up @@ -24,8 +24,6 @@
extern float g_mouseDeltaX;
extern float g_mouseDeltaY;

class GraphicsContext;

class WindowsHost : public Host {
public:
WindowsHost(HINSTANCE hInstance, HWND mainWindow, HWND displayWindow);
Expand All @@ -34,10 +32,7 @@ class WindowsHost : public Host {
UpdateConsolePosition();
}

// If returns false, will return a null context
bool InitGraphics(std::string *error_message, GraphicsContext **ctx) override;
void PollControllers() override;
void ShutdownGraphics() override;

void UpdateSound() override;

Expand All @@ -52,16 +47,13 @@ class WindowsHost : public Host {
void NotifyUserMessage(const std::string &message, float duration = 1.0f, u32 color = 0x00FFFFFF, const char *id = nullptr) override;
void SendUIMessage(const std::string &message, const std::string &value) override;

GraphicsContext *GetGraphicsContext() { return gfx_; }

private:
void SetConsolePosition();
void UpdateConsolePosition();

HINSTANCE hInstance_;
HWND displayWindow_;
HWND mainWindow_;
GraphicsContext *gfx_ = nullptr;
size_t numDinputDevices_ = 0;
std::wstring lastTitle_;

Expand Down
2 changes: 1 addition & 1 deletion ext/glslang
Submodule glslang updated 109 files
5 changes: 2 additions & 3 deletions headless/Headless.cpp
Expand Up @@ -409,12 +409,11 @@ int main(int argc, const char* argv[])
g_threadManager.Init(cpu_info.num_cores, cpu_info.logical_cpu_count);

HeadlessHost *headlessHost = getHost(gpuCore);
headlessHost->SetGraphicsCore(gpuCore);
host = headlessHost;

std::string error_string;
GraphicsContext *graphicsContext = nullptr;
bool glWorking = host->InitGraphics(&error_string, &graphicsContext);
bool glWorking = ((HeadlessHost *)host)->InitGraphics(&error_string, &graphicsContext, gpuCore);

CoreParameter coreParameter;
coreParameter.cpuCore = cpuCore;
Expand Down Expand Up @@ -578,7 +577,7 @@ int main(int argc, const char* argv[])
ShutdownWebServer();
}

host->ShutdownGraphics();
((HeadlessHost *)host)->ShutdownGraphics();
delete host;
host = nullptr;
headlessHost = nullptr;
Expand Down
2 changes: 1 addition & 1 deletion headless/SDLHeadlessHost.cpp
Expand Up @@ -165,7 +165,7 @@ bool GLDummyGraphicsContext::InitFromRenderThread(std::string *errorMessage) {
return success;
}

bool SDLHeadlessHost::InitGraphics(std::string *error_message, GraphicsContext **ctx) {
bool SDLHeadlessHost::InitGraphics(std::string *error_message, GraphicsContext **ctx, GPUCore core) {
GraphicsContext *graphicsContext = new GLDummyGraphicsContext();
*ctx = graphicsContext;
gfx_ = graphicsContext;
Expand Down
2 changes: 1 addition & 1 deletion headless/SDLHeadlessHost.h
Expand Up @@ -30,7 +30,7 @@ typedef void *SDL_GLContext;
class SDLHeadlessHost : public HeadlessHost
{
public:
bool InitGraphics(std::string *error_message, GraphicsContext **ctx) override;
bool InitGraphics(std::string *error_message, GraphicsContext **ctx, GPUCore core) override;
void ShutdownGraphics() override;

void SwapBuffers() override;
Expand Down
6 changes: 2 additions & 4 deletions headless/StubHost.h
Expand Up @@ -23,12 +23,10 @@
#include "Core/Host.h"
#include "Core/Debugger/SymbolMap.h"

// TODO: Get rid of this junk
class HeadlessHost : public Host {
public:
void SetGraphicsCore(GPUCore core) { gpuCore_ = core; }
bool InitGraphics(std::string *error_message, GraphicsContext **ctx) override {return false;}
void ShutdownGraphics() override {}
virtual bool InitGraphics(std::string *error_message, GraphicsContext **ctx, GPUCore core) {return false;}
virtual void ShutdownGraphics() {}

void UpdateSound() override {}

Expand Down
3 changes: 2 additions & 1 deletion headless/WindowsHeadlessHost.cpp
Expand Up @@ -72,8 +72,9 @@ void WindowsHeadlessHost::SendDebugOutput(const std::string &output)
OutputDebugStringUTF8(output.c_str());
}

bool WindowsHeadlessHost::InitGraphics(std::string *error_message, GraphicsContext **ctx) {
bool WindowsHeadlessHost::InitGraphics(std::string *error_message, GraphicsContext **ctx, GPUCore core) {
hWnd = CreateHiddenWindow();
gpuCore_ = core;

if (WINDOW_VISIBLE) {
ShowWindow(hWnd, TRUE);
Expand Down
2 changes: 1 addition & 1 deletion headless/WindowsHeadlessHost.h
Expand Up @@ -29,7 +29,7 @@
class WindowsHeadlessHost : public HeadlessHost
{
public:
bool InitGraphics(std::string *error_message, GraphicsContext **ctx) override;
bool InitGraphics(std::string *error_message, GraphicsContext **ctx, GPUCore core) override;
void ShutdownGraphics() override;

void SwapBuffers() override;
Expand Down
2 changes: 0 additions & 2 deletions libretro/libretro.cpp
Expand Up @@ -386,8 +386,6 @@ class LibretroHost : public Host
{
public:
LibretroHost() {}
bool InitGraphics(std::string *error_message, GraphicsContext **ctx) override { return true; }
void ShutdownGraphics() override {}
void UpdateSound() override
{
int hostAttemptBlockSize = __AudioGetHostAttemptBlockSize();
Expand Down

0 comments on commit ceaaaae

Please sign in to comment.