mirror of https://github.com/stenzek/duckstation
Qt: Refactor render widget state transitions
Recreate widget each time. Fixes fullscreen mode switches on D3D11 and hopefully Wayland.pull/474/head
parent
d7aa514f14
commit
ea3c0b65cf
@ -0,0 +1,130 @@
|
||||
#include "qthostdisplay.h"
|
||||
#include "common/assert.h"
|
||||
#include "frontend-common/imgui_styles.h"
|
||||
#include "imgui.h"
|
||||
#include "qtdisplaywidget.h"
|
||||
#include "qthostinterface.h"
|
||||
#include <cmath>
|
||||
|
||||
QtHostDisplay::QtHostDisplay(QtHostInterface* host_interface) : m_host_interface(host_interface) {}
|
||||
|
||||
QtHostDisplay::~QtHostDisplay() = default;
|
||||
|
||||
QtDisplayWidget* QtHostDisplay::createWidget(QWidget* parent)
|
||||
{
|
||||
Assert(!m_widget);
|
||||
m_widget = new QtDisplayWidget(parent);
|
||||
|
||||
// We want a native window for both D3D and OpenGL.
|
||||
m_widget->setAutoFillBackground(false);
|
||||
m_widget->setAttribute(Qt::WA_NativeWindow, true);
|
||||
m_widget->setAttribute(Qt::WA_NoSystemBackground, true);
|
||||
m_widget->setAttribute(Qt::WA_PaintOnScreen, true);
|
||||
|
||||
return m_widget;
|
||||
}
|
||||
|
||||
void QtHostDisplay::destroyWidget()
|
||||
{
|
||||
Assert(m_widget);
|
||||
|
||||
delete m_widget;
|
||||
m_widget = nullptr;
|
||||
}
|
||||
|
||||
bool QtHostDisplay::hasDeviceContext() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool QtHostDisplay::createDeviceContext(bool debug_device)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool QtHostDisplay::initializeDeviceContext(bool debug_device)
|
||||
{
|
||||
if (!createImGuiContext() || !createDeviceResources())
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool QtHostDisplay::makeDeviceContextCurrent()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void QtHostDisplay::moveContextToThread(QThread* new_thread) {}
|
||||
|
||||
void QtHostDisplay::destroyDeviceContext()
|
||||
{
|
||||
destroyImGuiContext();
|
||||
destroyDeviceResources();
|
||||
}
|
||||
|
||||
bool QtHostDisplay::createSurface()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void QtHostDisplay::destroySurface() {}
|
||||
|
||||
void* QtHostDisplay::GetRenderWindow() const
|
||||
{
|
||||
return m_widget;
|
||||
}
|
||||
|
||||
void QtHostDisplay::ChangeRenderWindow(void* new_window)
|
||||
{
|
||||
Panic("Not implemented");
|
||||
}
|
||||
|
||||
bool QtHostDisplay::createImGuiContext()
|
||||
{
|
||||
ImGui::CreateContext();
|
||||
|
||||
auto& io = ImGui::GetIO();
|
||||
io.IniFilename = nullptr;
|
||||
io.DisplaySize.x = static_cast<float>(m_window_width);
|
||||
io.DisplaySize.y = static_cast<float>(m_window_height);
|
||||
|
||||
const float framebuffer_scale = static_cast<float>(m_widget->devicePixelRatioFromScreen());
|
||||
io.DisplayFramebufferScale.x = framebuffer_scale;
|
||||
io.DisplayFramebufferScale.y = framebuffer_scale;
|
||||
ImGui::GetStyle().ScaleAllSizes(framebuffer_scale);
|
||||
|
||||
ImGui::StyleColorsDarker();
|
||||
ImGui::AddRobotoRegularFont(15.0f * framebuffer_scale);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void QtHostDisplay::destroyImGuiContext()
|
||||
{
|
||||
ImGui::DestroyContext();
|
||||
}
|
||||
|
||||
bool QtHostDisplay::createDeviceResources()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void QtHostDisplay::destroyDeviceResources() {}
|
||||
|
||||
void QtHostDisplay::WindowResized(s32 new_window_width, s32 new_window_height)
|
||||
{
|
||||
HostDisplay::WindowResized(new_window_width, new_window_height);
|
||||
updateImGuiDisplaySize();
|
||||
}
|
||||
|
||||
void QtHostDisplay::updateImGuiDisplaySize()
|
||||
{
|
||||
// imgui may not have been initialized yet
|
||||
if (!ImGui::GetCurrentContext())
|
||||
return;
|
||||
|
||||
auto& io = ImGui::GetIO();
|
||||
io.DisplaySize.x = static_cast<float>(m_window_width);
|
||||
io.DisplaySize.y = static_cast<float>(m_window_height);
|
||||
}
|
||||
@ -0,0 +1,46 @@
|
||||
#pragma once
|
||||
#include "common/types.h"
|
||||
#include "core/host_display.h"
|
||||
|
||||
class QThread;
|
||||
class QWidget;
|
||||
|
||||
class QtHostInterface;
|
||||
class QtDisplayWidget;
|
||||
|
||||
class QtHostDisplay : public HostDisplay
|
||||
{
|
||||
public:
|
||||
QtHostDisplay(QtHostInterface* host_interface);
|
||||
virtual ~QtHostDisplay();
|
||||
|
||||
ALWAYS_INLINE bool hasWidget() const { return (m_widget != nullptr); }
|
||||
ALWAYS_INLINE QtDisplayWidget* getWidget() const { return m_widget; }
|
||||
|
||||
virtual QtDisplayWidget* createWidget(QWidget* parent);
|
||||
virtual void destroyWidget();
|
||||
|
||||
virtual bool hasDeviceContext() const;
|
||||
virtual bool createDeviceContext(bool debug_device);
|
||||
virtual bool initializeDeviceContext(bool debug_device);
|
||||
virtual bool makeDeviceContextCurrent();
|
||||
virtual void moveContextToThread(QThread* new_thread);
|
||||
virtual void destroyDeviceContext();
|
||||
virtual bool createSurface();
|
||||
virtual void destroySurface();
|
||||
|
||||
virtual void* GetRenderWindow() const override;
|
||||
virtual void ChangeRenderWindow(void* new_window) override;
|
||||
virtual void WindowResized(s32 new_window_width, s32 new_window_height) override;
|
||||
|
||||
void updateImGuiDisplaySize();
|
||||
|
||||
protected:
|
||||
virtual bool createImGuiContext();
|
||||
virtual void destroyImGuiContext();
|
||||
virtual bool createDeviceResources();
|
||||
virtual void destroyDeviceResources();
|
||||
|
||||
QtHostInterface* m_host_interface;
|
||||
QtDisplayWidget* m_widget = nullptr;
|
||||
};
|
||||
Loading…
Reference in New Issue