mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-04-09 18:45:40 +00:00
GLContext: Get size using eglQuerySurface()
Also no longer assumes that a nullptr display is not headless (needed for fbdev)
This commit is contained in:
parent
5ea4f998c0
commit
43fe02ee9b
@ -30,7 +30,7 @@ const std::array<std::pair<int, int>, 9> GLContext::s_desktop_opengl_versions =
|
|||||||
|
|
||||||
GLContext::~GLContext() = default;
|
GLContext::~GLContext() = default;
|
||||||
|
|
||||||
bool GLContext::Initialize(void* display_handle, void* window_handle, bool stereo, bool core)
|
bool GLContext::Initialize(const WindowSystemInfo& wsi, bool stereo, bool core)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -119,7 +119,7 @@ std::unique_ptr<GLContext> GLContext::Create(const WindowSystemInfo& wsi, bool s
|
|||||||
if (prefer_gles)
|
if (prefer_gles)
|
||||||
context->m_opengl_mode = Mode::OpenGLES;
|
context->m_opengl_mode = Mode::OpenGLES;
|
||||||
|
|
||||||
if (!context->Initialize(wsi.display_connection, wsi.render_surface, stereo, core))
|
if (!context->Initialize(wsi, stereo, core))
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
return context;
|
return context;
|
||||||
|
@ -52,7 +52,7 @@ public:
|
|||||||
bool prefer_gles = false);
|
bool prefer_gles = false);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual bool Initialize(void* display_handle, void* window_handle, bool stereo, bool core);
|
virtual bool Initialize(const WindowSystemInfo& wsi, bool stereo, bool core);
|
||||||
|
|
||||||
Mode m_opengl_mode = Mode::Detect;
|
Mode m_opengl_mode = Mode::Detect;
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ public:
|
|||||||
void SwapInterval(int interval) override;
|
void SwapInterval(int interval) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool Initialize(void* display_handle, void* window_handle, bool stereo, bool core) override;
|
bool Initialize(const WindowSystemInfo& wsi, bool stereo, bool core) override;
|
||||||
|
|
||||||
NSView* m_view = nullptr;
|
NSView* m_view = nullptr;
|
||||||
NSOpenGLContext* m_context = nullptr;
|
NSOpenGLContext* m_context = nullptr;
|
||||||
|
@ -69,7 +69,7 @@ void GLContextAGL::Swap()
|
|||||||
|
|
||||||
// Create rendering window.
|
// Create rendering window.
|
||||||
// Call browser: Core.cpp:EmuThread() > main.cpp:Video_Initialize()
|
// Call browser: Core.cpp:EmuThread() > main.cpp:Video_Initialize()
|
||||||
bool GLContextAGL::Initialize(void* display_handle, void* window_handle, bool stereo, bool core)
|
bool GLContextAGL::Initialize(const WindowSystemInfo& wsi, bool stereo, bool core)
|
||||||
{
|
{
|
||||||
NSOpenGLPixelFormatAttribute attr[] = {
|
NSOpenGLPixelFormatAttribute attr[] = {
|
||||||
NSOpenGLPFADoubleBuffer,
|
NSOpenGLPFADoubleBuffer,
|
||||||
@ -92,10 +92,10 @@ bool GLContextAGL::Initialize(void* display_handle, void* window_handle, bool st
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!window_handle)
|
if (!wsi.render_surface)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
m_view = static_cast<NSView*>(window_handle);
|
m_view = static_cast<NSView*>(wsi.render_surface);
|
||||||
m_opengl_mode = Mode::OpenGL;
|
m_opengl_mode = Mode::OpenGL;
|
||||||
if (!AttachContextToView(m_context, m_view, &m_backbuffer_width, &m_backbuffer_height))
|
if (!AttachContextToView(m_context, m_view, &m_backbuffer_width, &m_backbuffer_height))
|
||||||
return false;
|
return false;
|
||||||
|
@ -35,7 +35,7 @@ GLContextEGL::~GLContextEGL()
|
|||||||
|
|
||||||
bool GLContextEGL::IsHeadless() const
|
bool GLContextEGL::IsHeadless() const
|
||||||
{
|
{
|
||||||
return m_host_window == nullptr;
|
return m_wsi.type == WindowSystemType::Headless;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLContextEGL::Swap()
|
void GLContextEGL::Swap()
|
||||||
@ -53,7 +53,7 @@ void* GLContextEGL::GetFuncAddress(const std::string& name)
|
|||||||
return (void*)eglGetProcAddress(name.c_str());
|
return (void*)eglGetProcAddress(name.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLContextEGL::DetectMode(bool has_handle)
|
void GLContextEGL::DetectMode()
|
||||||
{
|
{
|
||||||
EGLint num_configs;
|
EGLint num_configs;
|
||||||
bool supportsGL = false, supportsGLES3 = false;
|
bool supportsGL = false, supportsGLES3 = false;
|
||||||
@ -72,7 +72,7 @@ void GLContextEGL::DetectMode(bool has_handle)
|
|||||||
EGL_RENDERABLE_TYPE,
|
EGL_RENDERABLE_TYPE,
|
||||||
renderable_type,
|
renderable_type,
|
||||||
EGL_SURFACE_TYPE,
|
EGL_SURFACE_TYPE,
|
||||||
has_handle ? EGL_WINDOW_BIT : 0,
|
IsHeadless() ? 0 : EGL_WINDOW_BIT,
|
||||||
EGL_NONE};
|
EGL_NONE};
|
||||||
|
|
||||||
// Get how many configs there are
|
// Get how many configs there are
|
||||||
@ -130,27 +130,23 @@ void GLContextEGL::DetectMode(bool has_handle)
|
|||||||
|
|
||||||
EGLDisplay GLContextEGL::OpenEGLDisplay()
|
EGLDisplay GLContextEGL::OpenEGLDisplay()
|
||||||
{
|
{
|
||||||
return eglGetDisplay(EGL_DEFAULT_DISPLAY);
|
return eglGetDisplay(static_cast<EGLNativeDisplayType>(m_wsi.render_surface));
|
||||||
}
|
}
|
||||||
|
|
||||||
EGLNativeWindowType GLContextEGL::GetEGLNativeWindow(EGLConfig config)
|
EGLNativeWindowType GLContextEGL::GetEGLNativeWindow(EGLConfig config)
|
||||||
{
|
{
|
||||||
return reinterpret_cast<EGLNativeWindowType>(EGL_DEFAULT_DISPLAY);
|
return reinterpret_cast<EGLNativeWindowType>(m_wsi.display_connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create rendering window.
|
// Create rendering window.
|
||||||
// Call browser: Core.cpp:EmuThread() > main.cpp:Video_Initialize()
|
// Call browser: Core.cpp:EmuThread() > main.cpp:Video_Initialize()
|
||||||
bool GLContextEGL::Initialize(void* display_handle, void* window_handle, bool stereo, bool core)
|
bool GLContextEGL::Initialize(const WindowSystemInfo& wsi, bool stereo, bool core)
|
||||||
{
|
{
|
||||||
const bool has_handle = !!window_handle;
|
|
||||||
|
|
||||||
EGLint egl_major, egl_minor;
|
EGLint egl_major, egl_minor;
|
||||||
bool supports_core_profile = false;
|
bool supports_core_profile = false;
|
||||||
|
|
||||||
m_host_display = display_handle;
|
m_wsi = wsi;
|
||||||
m_host_window = window_handle;
|
|
||||||
m_egl_display = OpenEGLDisplay();
|
m_egl_display = OpenEGLDisplay();
|
||||||
|
|
||||||
if (!m_egl_display)
|
if (!m_egl_display)
|
||||||
{
|
{
|
||||||
INFO_LOG(VIDEO, "Error: eglGetDisplay() failed");
|
INFO_LOG(VIDEO, "Error: eglGetDisplay() failed");
|
||||||
@ -167,7 +163,7 @@ bool GLContextEGL::Initialize(void* display_handle, void* window_handle, bool st
|
|||||||
EGLint num_configs;
|
EGLint num_configs;
|
||||||
|
|
||||||
if (m_opengl_mode == Mode::Detect)
|
if (m_opengl_mode == Mode::Detect)
|
||||||
DetectMode(has_handle);
|
DetectMode();
|
||||||
|
|
||||||
// attributes for a visual in RGBA format with at least
|
// attributes for a visual in RGBA format with at least
|
||||||
// 8 bits per color
|
// 8 bits per color
|
||||||
@ -180,7 +176,7 @@ bool GLContextEGL::Initialize(void* display_handle, void* window_handle, bool st
|
|||||||
EGL_BLUE_SIZE,
|
EGL_BLUE_SIZE,
|
||||||
8,
|
8,
|
||||||
EGL_SURFACE_TYPE,
|
EGL_SURFACE_TYPE,
|
||||||
has_handle ? EGL_WINDOW_BIT : 0,
|
IsHeadless() ? 0 : EGL_WINDOW_BIT,
|
||||||
EGL_NONE};
|
EGL_NONE};
|
||||||
|
|
||||||
std::vector<EGLint> ctx_attribs;
|
std::vector<EGLint> ctx_attribs;
|
||||||
@ -278,7 +274,7 @@ std::unique_ptr<GLContext> GLContextEGL::CreateSharedContext()
|
|||||||
std::unique_ptr<GLContextEGL> new_context = std::make_unique<GLContextEGL>();
|
std::unique_ptr<GLContextEGL> new_context = std::make_unique<GLContextEGL>();
|
||||||
new_context->m_opengl_mode = m_opengl_mode;
|
new_context->m_opengl_mode = m_opengl_mode;
|
||||||
new_context->m_egl_context = new_egl_context;
|
new_context->m_egl_context = new_egl_context;
|
||||||
new_context->m_host_display = m_host_display;
|
new_context->m_wsi.display_connection = m_wsi.display_connection;
|
||||||
new_context->m_egl_display = m_egl_display;
|
new_context->m_egl_display = m_egl_display;
|
||||||
new_context->m_config = m_config;
|
new_context->m_config = m_config;
|
||||||
new_context->m_supports_surfaceless = m_supports_surfaceless;
|
new_context->m_supports_surfaceless = m_supports_surfaceless;
|
||||||
@ -294,7 +290,7 @@ std::unique_ptr<GLContext> GLContextEGL::CreateSharedContext()
|
|||||||
|
|
||||||
bool GLContextEGL::CreateWindowSurface()
|
bool GLContextEGL::CreateWindowSurface()
|
||||||
{
|
{
|
||||||
if (m_host_window)
|
if (!IsHeadless())
|
||||||
{
|
{
|
||||||
EGLNativeWindowType native_window = GetEGLNativeWindow(m_config);
|
EGLNativeWindowType native_window = GetEGLNativeWindow(m_config);
|
||||||
m_egl_surface = eglCreateWindowSurface(m_egl_display, m_config, native_window, nullptr);
|
m_egl_surface = eglCreateWindowSurface(m_egl_display, m_config, native_window, nullptr);
|
||||||
@ -303,6 +299,17 @@ bool GLContextEGL::CreateWindowSurface()
|
|||||||
INFO_LOG(VIDEO, "Error: eglCreateWindowSurface failed");
|
INFO_LOG(VIDEO, "Error: eglCreateWindowSurface failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get dimensions from the surface.
|
||||||
|
EGLint surface_width = 1, surface_height = 1;
|
||||||
|
if (!eglQuerySurface(m_egl_display, m_egl_surface, EGL_WIDTH, &surface_width) ||
|
||||||
|
!eglQuerySurface(m_egl_display, m_egl_surface, EGL_HEIGHT, &surface_height))
|
||||||
|
{
|
||||||
|
WARN_LOG(VIDEO,
|
||||||
|
"Failed to get surface dimensions via eglQuerySurface. Size may be incorrect.");
|
||||||
|
}
|
||||||
|
m_backbuffer_width = static_cast<int>(surface_width);
|
||||||
|
m_backbuffer_height = static_cast<int>(surface_height);
|
||||||
}
|
}
|
||||||
else if (!m_supports_surfaceless)
|
else if (!m_supports_surfaceless)
|
||||||
{
|
{
|
||||||
@ -342,7 +349,7 @@ bool GLContextEGL::MakeCurrent()
|
|||||||
|
|
||||||
void GLContextEGL::UpdateSurface(void* window_handle)
|
void GLContextEGL::UpdateSurface(void* window_handle)
|
||||||
{
|
{
|
||||||
m_host_window = window_handle;
|
m_wsi.render_surface = window_handle;
|
||||||
ClearCurrent();
|
ClearCurrent();
|
||||||
DestroyWindowSurface();
|
DestroyWindowSurface();
|
||||||
CreateWindowSurface();
|
CreateWindowSurface();
|
||||||
|
@ -34,15 +34,14 @@ protected:
|
|||||||
virtual EGLDisplay OpenEGLDisplay();
|
virtual EGLDisplay OpenEGLDisplay();
|
||||||
virtual EGLNativeWindowType GetEGLNativeWindow(EGLConfig config);
|
virtual EGLNativeWindowType GetEGLNativeWindow(EGLConfig config);
|
||||||
|
|
||||||
bool Initialize(void* display_handle, void* window_handle, bool stereo, bool core) override;
|
bool Initialize(const WindowSystemInfo& wsi, bool stereo, bool core) override;
|
||||||
|
|
||||||
bool CreateWindowSurface();
|
bool CreateWindowSurface();
|
||||||
void DestroyWindowSurface();
|
void DestroyWindowSurface();
|
||||||
void DetectMode(bool has_handle);
|
void DetectMode();
|
||||||
void DestroyContext();
|
void DestroyContext();
|
||||||
|
|
||||||
void* m_host_display = nullptr;
|
WindowSystemInfo m_wsi = {};
|
||||||
void* m_host_window = nullptr;
|
|
||||||
|
|
||||||
EGLConfig m_config;
|
EGLConfig m_config;
|
||||||
bool m_supports_surfaceless = false;
|
bool m_supports_surfaceless = false;
|
||||||
|
@ -14,8 +14,8 @@ EGLNativeWindowType GLContextEGLAndroid::GetEGLNativeWindow(EGLConfig config)
|
|||||||
{
|
{
|
||||||
EGLint format;
|
EGLint format;
|
||||||
eglGetConfigAttrib(m_egl_display, config, EGL_NATIVE_VISUAL_ID, &format);
|
eglGetConfigAttrib(m_egl_display, config, EGL_NATIVE_VISUAL_ID, &format);
|
||||||
ANativeWindow_setBuffersGeometry(static_cast<ANativeWindow*>(m_host_window), 0, 0, format);
|
ANativeWindow_setBuffersGeometry(static_cast<ANativeWindow*>(m_wsi.render_surface), 0, 0, format);
|
||||||
m_backbuffer_width = ANativeWindow_getWidth(static_cast<ANativeWindow*>(m_host_window));
|
m_backbuffer_width = ANativeWindow_getWidth(static_cast<ANativeWindow*>(m_wsi.render_surface));
|
||||||
m_backbuffer_height = ANativeWindow_getHeight(static_cast<ANativeWindow*>(m_host_window));
|
m_backbuffer_height = ANativeWindow_getHeight(static_cast<ANativeWindow*>(m_wsi.render_surface));
|
||||||
return static_cast<EGLNativeWindowType>(m_host_window);
|
return static_cast<EGLNativeWindowType>(m_wsi.render_surface);
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ void GLContextEGLX11::Update()
|
|||||||
|
|
||||||
EGLDisplay GLContextEGLX11::OpenEGLDisplay()
|
EGLDisplay GLContextEGLX11::OpenEGLDisplay()
|
||||||
{
|
{
|
||||||
return eglGetDisplay(static_cast<Display*>(m_host_display));
|
return eglGetDisplay(static_cast<Display*>(m_wsi.display_connection));
|
||||||
}
|
}
|
||||||
|
|
||||||
EGLNativeWindowType GLContextEGLX11::GetEGLNativeWindow(EGLConfig config)
|
EGLNativeWindowType GLContextEGLX11::GetEGLNativeWindow(EGLConfig config)
|
||||||
@ -33,14 +33,14 @@ EGLNativeWindowType GLContextEGLX11::GetEGLNativeWindow(EGLConfig config)
|
|||||||
visTemplate.visualid = vid;
|
visTemplate.visualid = vid;
|
||||||
|
|
||||||
int nVisuals;
|
int nVisuals;
|
||||||
XVisualInfo* vi =
|
XVisualInfo* vi = XGetVisualInfo(static_cast<Display*>(m_wsi.display_connection), VisualIDMask,
|
||||||
XGetVisualInfo(static_cast<Display*>(m_host_display), VisualIDMask, &visTemplate, &nVisuals);
|
&visTemplate, &nVisuals);
|
||||||
|
|
||||||
if (m_render_window)
|
if (m_render_window)
|
||||||
m_render_window.reset();
|
m_render_window.reset();
|
||||||
|
|
||||||
m_render_window = GLX11Window::Create(static_cast<Display*>(m_host_display),
|
m_render_window = GLX11Window::Create(static_cast<Display*>(m_wsi.display_connection),
|
||||||
reinterpret_cast<Window>(m_host_window), vi);
|
reinterpret_cast<Window>(m_wsi.render_surface), vi);
|
||||||
m_backbuffer_width = m_render_window->GetWidth();
|
m_backbuffer_width = m_render_window->GetWidth();
|
||||||
m_backbuffer_height = m_render_window->GetHeight();
|
m_backbuffer_height = m_render_window->GetHeight();
|
||||||
|
|
||||||
|
@ -73,9 +73,9 @@ void GLContextGLX::Swap()
|
|||||||
|
|
||||||
// Create rendering window.
|
// Create rendering window.
|
||||||
// Call browser: Core.cpp:EmuThread() > main.cpp:Video_Initialize()
|
// Call browser: Core.cpp:EmuThread() > main.cpp:Video_Initialize()
|
||||||
bool GLContextGLX::Initialize(void* display_handle, void* window_handle, bool stereo, bool core)
|
bool GLContextGLX::Initialize(const WindowSystemInfo& wsi, bool stereo, bool core)
|
||||||
{
|
{
|
||||||
m_display = static_cast<Display*>(display_handle);
|
m_display = static_cast<Display*>(wsi.display_connection);
|
||||||
int screen = DefaultScreen(m_display);
|
int screen = DefaultScreen(m_display);
|
||||||
|
|
||||||
// checking glx version
|
// checking glx version
|
||||||
@ -204,7 +204,7 @@ bool GLContextGLX::Initialize(void* display_handle, void* window_handle, bool st
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!CreateWindowSurface(reinterpret_cast<Window>(window_handle)))
|
if (!CreateWindowSurface(reinterpret_cast<Window>(wsi.render_surface)))
|
||||||
{
|
{
|
||||||
ERROR_LOG(VIDEO, "Error: CreateWindowSurface failed\n");
|
ERROR_LOG(VIDEO, "Error: CreateWindowSurface failed\n");
|
||||||
XSetErrorHandler(oldHandler);
|
XSetErrorHandler(oldHandler);
|
||||||
|
@ -33,7 +33,7 @@ public:
|
|||||||
void* GetFuncAddress(const std::string& name) override;
|
void* GetFuncAddress(const std::string& name) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool Initialize(void* display_handle, void* window_handle, bool stereo, bool core) override;
|
bool Initialize(const WindowSystemInfo& wsi, bool stereo, bool core) override;
|
||||||
|
|
||||||
Display* m_display = nullptr;
|
Display* m_display = nullptr;
|
||||||
std::unique_ptr<GLX11Window> m_render_window;
|
std::unique_ptr<GLX11Window> m_render_window;
|
||||||
|
@ -223,13 +223,13 @@ void* GLContextWGL::GetFuncAddress(const std::string& name)
|
|||||||
|
|
||||||
// Create rendering window.
|
// Create rendering window.
|
||||||
// Call browser: Core.cpp:EmuThread() > main.cpp:Video_Initialize()
|
// Call browser: Core.cpp:EmuThread() > main.cpp:Video_Initialize()
|
||||||
bool GLContextWGL::Initialize(void* display_handle, void* window_handle, bool stereo, bool core)
|
bool GLContextWGL::Initialize(const WindowSystemInfo& wsi, bool stereo, bool core)
|
||||||
{
|
{
|
||||||
if (!window_handle)
|
if (!wsi.render_surface)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
RECT window_rect = {};
|
RECT window_rect = {};
|
||||||
m_window_handle = reinterpret_cast<HWND>(window_handle);
|
m_window_handle = reinterpret_cast<HWND>(wsi.render_surface);
|
||||||
if (!GetClientRect(m_window_handle, &window_rect))
|
if (!GetClientRect(m_window_handle, &window_rect))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ public:
|
|||||||
void* GetFuncAddress(const std::string& name) override;
|
void* GetFuncAddress(const std::string& name) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool Initialize(void* display_handle, void* window_handle, bool stereo, bool core) override;
|
bool Initialize(const WindowSystemInfo& wsi, bool stereo, bool core) override;
|
||||||
|
|
||||||
static HGLRC CreateCoreContext(HDC dc, HGLRC share_context);
|
static HGLRC CreateCoreContext(HDC dc, HGLRC share_context);
|
||||||
static bool CreatePBuffer(HDC onscreen_dc, int width, int height, HANDLE* pbuffer_handle,
|
static bool CreatePBuffer(HDC onscreen_dc, int width, int height, HANDLE* pbuffer_handle,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user