OpenGLHostDisplay: Support fullscreen mode enumeration (DRM only)

This commit is contained in:
Connor McLaughlin 2021-02-14 00:52:34 +10:00
parent 748e2e9a70
commit d4143399eb
8 changed files with 54 additions and 4 deletions

View file

@ -67,6 +67,11 @@ Context::Context(const WindowInfo& wi) : m_wi(wi) {}
Context::~Context() = default;
std::vector<Context::FullscreenModeInfo> Context::EnumerateFullscreenModes()
{
return {};
}
std::unique_ptr<GL::Context> Context::Create(const WindowInfo& wi, const Version* versions_to_try,
size_t num_versions_to_try)
{

View file

@ -3,6 +3,7 @@
#include "../window_info.h"
#include <array>
#include <memory>
#include <vector>
namespace GL {
class Context
@ -25,6 +26,13 @@ public:
int minor_version;
};
struct FullscreenModeInfo
{
u32 width;
u32 height;
float refresh_rate;
};
ALWAYS_INLINE const WindowInfo& GetWindowInfo() const { return m_wi; }
ALWAYS_INLINE bool IsGLES() const { return (m_version.profile == Profile::ES); }
ALWAYS_INLINE u32 GetSurfaceWidth() const { return m_wi.surface_width; }
@ -40,6 +48,8 @@ public:
virtual bool SetSwapInterval(s32 interval) = 0;
virtual std::unique_ptr<Context> CreateSharedContext(const WindowInfo& wi) = 0;
virtual std::vector<FullscreenModeInfo> EnumerateFullscreenModes();
static std::unique_ptr<Context> Create(const WindowInfo& wi, const Version* versions_to_try,
size_t num_versions_to_try);

View file

@ -206,6 +206,18 @@ bool ContextEGLGBM::SetSwapInterval(s32 interval)
return true;
}
std::vector<Context::FullscreenModeInfo> ContextEGLGBM::EnumerateFullscreenModes()
{
std::vector<Context::FullscreenModeInfo> modes;
modes.reserve(m_drm_display.GetModeCount());
for (u32 i = 0; i < m_drm_display.GetModeCount(); i++)
{
modes.push_back(FullscreenModeInfo{m_drm_display.GetModeWidth(i), m_drm_display.GetModeHeight(i),
m_drm_display.GetModeRefreshRate(i)});
}
return modes;
}
#ifdef CONTEXT_EGL_GBM_USE_PRESENT_THREAD
void ContextEGLGBM::StartPresentThread()

View file

@ -26,6 +26,8 @@ public:
bool SwapBuffers() override;
bool SetSwapInterval(s32 interval) override;
std::vector<FullscreenModeInfo> EnumerateFullscreenModes() override;
protected:
bool SetDisplay() override;
EGLNativeWindowType GetNativeWindow(EGLConfig config) override;

View file

@ -2870,6 +2870,11 @@ bool CommonHostInterface::ParseFullscreenMode(const std::string_view& mode, u32*
return false;
}
std::string CommonHostInterface::GetFullscreenModeString(u32 width, u32 height, float refresh_rate)
{
return StringUtil::StdStringFromFormat("%u x %u @ %f hz", width, height, refresh_rate);
}
bool CommonHostInterface::RequestRenderWindowSize(s32 new_window_width, s32 new_window_height)
{
return false;

View file

@ -241,6 +241,9 @@ public:
/// Parses a fullscreen mode into its components (width * height @ refresh hz)
static bool ParseFullscreenMode(const std::string_view& mode, u32* width, u32* height, float* refresh_rate);
/// Converts a fullscreen mode to a string.
static std::string GetFullscreenModeString(u32 width, u32 height, float refresh_rate);
/// Returns true if fast forwarding or slow motion is currently active.
bool IsRunningAtNonStandardSpeed() const;

View file

@ -4,14 +4,15 @@
#include "common/d3d11/shader_compiler.h"
#include "common/log.h"
#include "common/string_util.h"
#include "common_host_interface.h"
#include "core/host_interface.h"
#include "core/settings.h"
#include "core/shader_cache_version.h"
#include "display_ps.hlsl.h"
#include "display_vs.hlsl.h"
#include "frontend-common/postprocessing_shadergen.h"
#include "imgui.h"
#include "imgui_impl_dx11.h"
#include "postprocessing_shadergen.h"
#include <array>
#include <dxgi1_5.h>
Log_SetChannel(D3D11HostDisplay);
@ -843,8 +844,8 @@ HostDisplay::AdapterAndModeList D3D11HostDisplay::GetAdapterAndModeList(IDXGIFac
{
for (const DXGI_MODE_DESC& mode : modes)
{
adapter_info.fullscreen_modes.push_back(StringUtil::StdStringFromFormat(
"%u x %u @ %f hz", mode.Width, mode.Height,
adapter_info.fullscreen_modes.push_back(CommonHostInterface::GetFullscreenModeString(
mode.Width, mode.Height,
static_cast<float>(mode.RefreshRate.Numerator) / static_cast<float>(mode.RefreshRate.Denominator)));
}
}

View file

@ -3,6 +3,7 @@
#include "common/assert.h"
#include "common/log.h"
#include "common/string_util.h"
#include "common_host_interface.h"
#include "imgui.h"
#include "imgui_impl_opengl3.h"
#include "postprocessing_shadergen.h"
@ -512,7 +513,18 @@ bool OpenGLHostDisplay::SetFullscreen(bool fullscreen, u32 width, u32 height, fl
HostDisplay::AdapterAndModeList OpenGLHostDisplay::GetAdapterAndModeList()
{
return {};
AdapterAndModeList aml;
if (m_gl_context)
{
for (const GL::Context::FullscreenModeInfo& fmi : m_gl_context->EnumerateFullscreenModes())
{
aml.fullscreen_modes.push_back(
CommonHostInterface::GetFullscreenModeString(fmi.width, fmi.height, fmi.refresh_rate));
}
}
return aml;
}
void OpenGLHostDisplay::DestroyRenderSurface()