Skip to content

Commit

Permalink
Drop Host_GetRenderSurface and pass display to backend
Browse files Browse the repository at this point in the history
  • Loading branch information
stenzek committed Oct 20, 2018
1 parent 134d967 commit a396175
Show file tree
Hide file tree
Showing 35 changed files with 129 additions and 124 deletions.
5 changes: 0 additions & 5 deletions Source/Android/jni/MainAndroid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,6 @@ void Host_Message(HostMessageID id)
}
}

void* Host_GetRenderHandle()
{
return s_surf;
}

void Host_UpdateTitle(const std::string& title)
{
__android_log_write(ANDROID_LOG_INFO, DOLPHIN_TAG, title.c_str());
Expand Down
8 changes: 8 additions & 0 deletions Source/Core/Core/Boot/Boot.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ struct BootParameters
Parameters parameters;
std::optional<std::string> savestate_path;
bool delete_savestate = false;

// Connection to a display server. This is used on X11 and Wayland platforms.
void* display_connection = nullptr;

// Render surface. This is a pointer to the native window handle, which depends
// on the platform. e.g. HWND for Windows, Window for X11. If the surface is
// set to nullptr, the video backend will run in headless mode.
void* render_surface = nullptr;
};

class CBoot
Expand Down
9 changes: 3 additions & 6 deletions Source/Core/Core/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ static bool s_is_stopping = false;
static bool s_hardware_initialized = false;
static bool s_is_started = false;
static Common::Flag s_is_booting;
static void* s_window_handle = nullptr;
static std::thread s_emu_thread;
static StateChangedCallbackFunc s_on_state_changed_callback;

Expand Down Expand Up @@ -215,8 +214,6 @@ bool Init(std::unique_ptr<BootParameters> boot)

Host_UpdateMainFrame(); // Disable any menus or buttons at boot

s_window_handle = Host_GetRenderHandle();

// Start the emu thread
s_emu_thread = std::thread(EmuThread, std::move(boot));
return true;
Expand Down Expand Up @@ -441,7 +438,7 @@ static void EmuThread(std::unique_ptr<BootParameters> boot)
g_video_backend->InitBackendInfo();
g_Config.Refresh();

if (!g_video_backend->Initialize(s_window_handle))
if (!g_video_backend->Initialize(boot->display_connection, boot->render_surface))
{
PanicAlert("Failed to initialize video backend!");
return;
Expand All @@ -462,7 +459,7 @@ static void EmuThread(std::unique_ptr<BootParameters> boot)
bool init_controllers = false;
if (!g_controller_interface.IsInit())
{
g_controller_interface.Initialize(s_window_handle);
g_controller_interface.Initialize(boot->render_surface);
Pad::Initialize();
Keyboard::Initialize();
init_controllers = true;
Expand Down Expand Up @@ -958,4 +955,4 @@ void DoFrameStep()
}
}

} // Core
} // namespace Core
3 changes: 0 additions & 3 deletions Source/Core/Core/Host.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,3 @@ void Host_UpdateMainFrame();
void Host_UpdateTitle(const std::string& title);
void Host_YieldToUI();
void Host_UpdateProgressDialog(const char* caption, int position, int total);

// TODO (neobrain): Remove this from host!
void* Host_GetRenderHandle();
17 changes: 10 additions & 7 deletions Source/Core/DolphinNoGUI/MainNoGUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ class Platform
}
virtual void Shutdown() {}
virtual ~Platform() {}

virtual void* GetDisplayHandle() { return nullptr; }
virtual void* GetWindowHandle() { return nullptr; }
};

static Platform* platform;
Expand All @@ -91,12 +94,6 @@ void Host_Message(HostMessageID id)
updateMainFrameEvent.Set();
}

static void* s_window_handle = nullptr;
void* Host_GetRenderHandle()
{
return s_window_handle;
}

void Host_UpdateTitle(const std::string& title)
{
platform->SetTitle(title);
Expand Down Expand Up @@ -187,7 +184,6 @@ class PlatformX11 : public Platform
}
XMapRaised(dpy, win);
XFlush(dpy);
s_window_handle = (void*)win;

if (SConfig::GetInstance().bDisableScreenSaver)
X11Utils::InhibitScreensaver(win, true);
Expand Down Expand Up @@ -354,6 +350,10 @@ class PlatformX11 : public Platform

XCloseDisplay(dpy);
}

void* GetDisplayHandle() override { return static_cast<void*>(dpy); }

void* GetWindowHandle() override { return reinterpret_cast<void*>(win); }
};
#endif

Expand Down Expand Up @@ -433,6 +433,9 @@ int main(int argc, char* argv[])

DolphinAnalytics::Instance()->ReportDolphinStart("nogui");

boot->display_connection = platform->GetDisplayHandle();
boot->render_surface = platform->GetWindowHandle();

if (!BootManager::BootCore(std::move(boot)))
{
fprintf(stderr, "Could not boot the specified file\n");
Expand Down
13 changes: 2 additions & 11 deletions Source/Core/DolphinQt/Host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,10 @@ Host* Host::GetInstance()
return s_instance;
}

void* Host::GetRenderHandle()
{
return m_render_handle;
}

void Host::SetRenderHandle(void* handle)
{
m_render_handle = handle;
if (g_renderer)
g_renderer->ChangeSurface(handle);
}

bool Host::GetRenderFocus()
Expand Down Expand Up @@ -94,11 +90,6 @@ void Host_UpdateTitle(const std::string& title)
emit Host::GetInstance()->RequestTitle(QString::fromStdString(title));
}

void* Host_GetRenderHandle()
{
return Host::GetInstance()->GetRenderHandle();
}

bool Host_RendererHasFocus()
{
return Host::GetInstance()->GetRenderFocus();
Expand Down
1 change: 0 additions & 1 deletion Source/Core/DolphinQt/Host.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class Host final : public QObject
public:
static Host* GetInstance();

void* GetRenderHandle();
bool GetRenderFocus();
bool GetRenderFullscreen();

Expand Down
19 changes: 17 additions & 2 deletions Source/Core/DolphinQt/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
#include "QtUtils/SignalDaemon.h"
#endif

#ifndef WIN32
#include <qpa/qplatformnativeinterface.h>
#endif

#include "Common/Version.h"

#include "Core/Boot/Boot.h"
Expand Down Expand Up @@ -98,7 +102,6 @@
#include "VideoCommon/VideoConfig.h"

#if defined(HAVE_XRANDR) && HAVE_XRANDR
#include <qpa/qplatformnativeinterface.h>
#include "UICommon/X11Utils.h"
#endif

Expand Down Expand Up @@ -797,14 +800,26 @@ void MainWindow::StartGame(std::unique_ptr<BootParameters>&& parameters)
m_pending_boot = std::move(parameters);
return;
}

// We need the render widget before booting.
ShowRenderWidget();

// Populate the video backend fields of the boot parameters.
parameters->render_surface = reinterpret_cast<void*>(m_render_widget->winId());
#ifndef WIN32
parameters->display_connection =
QGuiApplication::platformNativeInterface()->nativeResourceForWindow("display",
windowHandle());
#endif

// Boot up, show an error if it fails to load the game.
if (!BootManager::BootCore(std::move(parameters)))
{
QMessageBox::critical(this, tr("Error"), tr("Failed to init core"), QMessageBox::Ok);
HideRenderWidget();
return;
}

ShowRenderWidget();
#ifdef USE_DISCORD_PRESENCE
if (!NetPlay::IsNetPlayRunning())
Discord::UpdateDiscordPresence();
Expand Down
4 changes: 1 addition & 3 deletions Source/Core/DolphinQt/RenderWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ RenderWidget::RenderWidget(QWidget* parent) : QWidget(parent)
connect(this, &RenderWidget::FocusChanged, Host::GetInstance(), &Host::SetRenderFocus,
Qt::DirectConnection);

emit HandleChanged((void*)winId());

m_mouse_timer = new QTimer(this);
connect(m_mouse_timer, &QTimer::timeout, this, &RenderWidget::HandleCursorTimer);
m_mouse_timer->setSingleShot(true);
Expand Down Expand Up @@ -144,7 +142,7 @@ bool RenderWidget::event(QEvent* event)
}
break;
case QEvent::WinIdChange:
emit HandleChanged((void*)winId());
emit HandleChanged(reinterpret_cast<void*>(winId()));
break;
case QEvent::WindowActivate:
if (SConfig::GetInstance().m_PauseOnFocusLost && Core::GetState() == Core::State::Paused)
Expand Down
11 changes: 8 additions & 3 deletions Source/Core/VideoBackends/D3D/Render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,11 @@ void Renderer::Create3DVisionTexture(int width, int height)
DXGI_FORMAT_R8G8B8A8_UNORM, 1, 1, &sys_data);
}

bool Renderer::IsHeadless() const
{
return D3D::swapchain == nullptr;
}

std::unique_ptr<AbstractTexture> Renderer::CreateTexture(const TextureConfig& config)
{
return std::make_unique<DXTexture>(config);
Expand Down Expand Up @@ -698,12 +703,12 @@ void Renderer::CheckForSurfaceChange()
if (!m_surface_changed.TestAndClear())
return;

m_surface_handle = m_new_surface_handle;
m_new_surface_handle = nullptr;

SAFE_RELEASE(m_screenshot_texture);
SAFE_RELEASE(m_3d_vision_texture);

D3D::Reset(reinterpret_cast<HWND>(m_new_surface_handle));
m_new_surface_handle = nullptr;

UpdateBackbufferSize();
}

Expand Down
3 changes: 3 additions & 0 deletions Source/Core/VideoBackends/D3D/Render.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ class Renderer : public ::Renderer
~Renderer() override;

StateCache& GetStateCache() { return m_state_cache; }

bool IsHeadless() const override;

std::unique_ptr<AbstractTexture> CreateTexture(const TextureConfig& config) override;
std::unique_ptr<AbstractStagingTexture>
CreateStagingTexture(StagingTextureType type, const TextureConfig& config) override;
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/VideoBackends/D3D/VideoBackend.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ namespace DX11
{
class VideoBackend : public VideoBackendBase
{
bool Initialize(void*) override;
bool Initialize(void* display_handle, void* window_handle) override;
void Shutdown() override;

std::string GetName() const override;
std::string GetDisplayName() const override;

void InitBackendInfo() override;
};
}
} // namespace DX11
4 changes: 2 additions & 2 deletions Source/Core/VideoBackends/D3D/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ void VideoBackend::InitBackendInfo()
DX11::D3D::UnloadD3D();
}

bool VideoBackend::Initialize(void* window_handle)
bool VideoBackend::Initialize(void* display_handle, void* window_handle)
{
if (window_handle == nullptr)
return false;
Expand Down Expand Up @@ -188,4 +188,4 @@ void VideoBackend::Shutdown()

D3D::Close();
}
}
} // namespace DX11
4 changes: 2 additions & 2 deletions Source/Core/VideoBackends/Null/NullBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void VideoBackend::InitBackendInfo()
g_Config.backend_info.AAModes = {1};
}

bool VideoBackend::Initialize(void* window_handle)
bool VideoBackend::Initialize(void* display_handle, void* window_handle)
{
InitializeShared();

Expand All @@ -80,4 +80,4 @@ void VideoBackend::Shutdown()

ShutdownShared();
}
}
} // namespace Null
5 changes: 5 additions & 0 deletions Source/Core/VideoBackends/Null/Render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ Renderer::~Renderer()
UpdateActiveConfig();
}

bool Renderer::IsHeadless() const
{
return true;
}

std::unique_ptr<AbstractTexture> Renderer::CreateTexture(const TextureConfig& config)
{
return std::make_unique<NullTexture>(config);
Expand Down
2 changes: 2 additions & 0 deletions Source/Core/VideoBackends/Null/Render.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class Renderer : public ::Renderer
Renderer();
~Renderer() override;

bool IsHeadless() const override;

std::unique_ptr<AbstractTexture> CreateTexture(const TextureConfig& config) override;
std::unique_ptr<AbstractStagingTexture>
CreateStagingTexture(StagingTextureType type, const TextureConfig& config) override;
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/VideoBackends/Null/VideoBackend.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Null
{
class VideoBackend : public VideoBackendBase
{
bool Initialize(void* window_handle) override;
bool Initialize(void* display_handle, void* window_handle) override;
void Shutdown() override;

std::string GetName() const override { return "Null"; }
Expand All @@ -22,4 +22,4 @@ class VideoBackend : public VideoBackendBase
}
void InitBackendInfo() override;
};
}
} // namespace Null
8 changes: 6 additions & 2 deletions Source/Core/VideoBackends/OGL/Render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,11 @@ Renderer::Renderer()

Renderer::~Renderer() = default;

bool Renderer::IsHeadless() const
{
return g_main_gl_context->IsHeadless();
}

void Renderer::Shutdown()
{
::Renderer::Shutdown();
Expand Down Expand Up @@ -1499,9 +1504,8 @@ void Renderer::CheckForSurfaceChange()
if (!m_surface_changed.TestAndClear())
return;

m_surface_handle = m_new_surface_handle;
g_main_gl_context->UpdateSurface(m_new_surface_handle);
m_new_surface_handle = nullptr;
g_main_gl_context->UpdateSurface(m_surface_handle);

// With a surface change, the window likely has new dimensions.
m_backbuffer_width = g_main_gl_context->GetBackBufferWidth();
Expand Down
2 changes: 2 additions & 0 deletions Source/Core/VideoBackends/OGL/Render.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ class Renderer : public ::Renderer
Renderer();
~Renderer() override;

bool IsHeadless() const override;

void Init();
void Shutdown() override;

Expand Down
4 changes: 2 additions & 2 deletions Source/Core/VideoBackends/OGL/VideoBackend.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace OGL
{
class VideoBackend : public VideoBackendBase
{
bool Initialize(void*) override;
bool Initialize(void* display_handle, void* window_handle) override;
void Shutdown() override;

std::string GetName() const override;
Expand All @@ -23,4 +23,4 @@ class VideoBackend : public VideoBackendBase
bool InitializeGLExtensions();
bool FillBackendInfo();
};
}
} // namespace OGL
Loading

0 comments on commit a396175

Please sign in to comment.