Merge branch 'no-egl-context-ptr'

Stop using EGLContext* and just use EGLContext directly.

See #24404,
This commit is contained in:
Vadim Zeitlin
2024-03-18 14:15:30 +01:00
2 changed files with 26 additions and 48 deletions
+13 -13
View File
@@ -59,7 +59,7 @@ public:
// -----------------------
// default ctor doesn't do anything, InitConfig() must be called
wxGLCanvasEGL();
wxGLCanvasEGL() = default;
// initializes EGLConfig corresponding to the given attributes
bool InitVisual(const wxGLAttributes& dispAttrs);
@@ -100,7 +100,7 @@ public:
// -------------------------------
// get the EGLConfig we use
EGLConfig *GetEGLConfig() const { return m_config; }
EGLConfig GetEGLConfig() const { return m_config; }
EGLDisplay GetEGLDisplay() const { return m_display; }
EGLSurface GetEGLSurface() const { return m_surface; }
@@ -111,7 +111,7 @@ public:
static bool InitDefaultConfig(const int *attribList);
// get the default EGL Config (may be null, shouldn't be freed by caller)
static EGLConfig *GetDefaultConfig() { return ms_glEGLConfig; }
static EGLConfig GetDefaultConfig() { return ms_glEGLConfig; }
// free the global GL visual, called by wxGLApp
static void FreeDefaultConfig();
@@ -120,7 +120,7 @@ public:
//
// returns nullptr if EGLConfig couldn't be initialized, otherwise caller
// is responsible for freeing the pointer
static EGLConfig *InitConfig(const wxGLAttributes& dispAttrs);
static EGLConfig InitConfig(const wxGLAttributes& dispAttrs);
// Only called when using Wayland to indicate that we should be redrawn.
void OnWLFrameCallback();
@@ -132,20 +132,20 @@ public:
private:
EGLConfig *m_config;
EGLDisplay m_display;
EGLSurface m_surface;
EGLConfig m_config = nullptr;
EGLDisplay m_display = nullptr;
EGLSurface m_surface = nullptr;
unsigned long m_xwindow;
wl_surface *m_wlSurface;
wl_region *m_wlRegion;
wl_subsurface *m_wlSubsurface;
unsigned long m_xwindow = 0;
wl_surface *m_wlSurface = nullptr;
wl_region *m_wlRegion = nullptr;
wl_subsurface *m_wlSubsurface = nullptr;
bool m_readyToDraw;
bool m_readyToDraw = false;
bool m_swapIntervalSet = false;
// the global/default versions of the above
static EGLConfig *ms_glEGLConfig;
static EGLConfig ms_glEGLConfig;
friend void wxEGLUpdatePosition(wxGLCanvasEGL* win);
};
+13 -35
View File
@@ -297,10 +297,10 @@ wxGLContext::wxGLContext(wxGLCanvas *win,
m_isOk = false;
EGLConfig *fbc = win->GetEGLConfig();
EGLConfig fbc = win->GetEGLConfig();
wxCHECK_RET( fbc, "Invalid EGLConfig for OpenGL" );
m_glContext = eglCreateContext(wxGLCanvasEGL::GetDisplay(), fbc[0],
m_glContext = eglCreateContext(wxGLCanvasEGL::GetDisplay(), fbc,
other ? other->m_glContext : EGL_NO_CONTEXT,
contextAttribs);
@@ -339,21 +339,6 @@ bool wxGLContext::SetCurrent(const wxGLCanvas& win) const
// initialization methods and dtor
// ----------------------------------------------------------------------------
wxGLCanvasEGL::wxGLCanvasEGL()
{
m_config = nullptr;
m_display = nullptr;
m_surface = EGL_NO_SURFACE;
m_wlCompositor = nullptr;
m_wlSubcompositor = nullptr;
m_wlFrameCallbackHandler = nullptr;
m_wlEGLWindow = nullptr;
m_wlSurface = nullptr;
m_wlRegion = nullptr;
m_wlSubsurface = nullptr;
m_readyToDraw = false;
}
bool wxGLCanvasEGL::InitVisual(const wxGLAttributes& dispAttrs)
{
m_config = InitConfig(dispAttrs);
@@ -534,7 +519,7 @@ bool wxGLCanvasEGL::CreateSurface()
}
m_xwindow = GDK_WINDOW_XID(window);
m_surface = eglCreatePlatformWindowSurface(m_display, *m_config,
m_surface = eglCreatePlatformWindowSurface(m_display, m_config,
&m_xwindow, nullptr);
}
#endif
@@ -566,7 +551,7 @@ bool wxGLCanvasEGL::CreateSurface()
wl_surface_set_buffer_scale(m_wlSurface, scale);
m_wlEGLWindow = wl_egl_window_create(m_wlSurface, w * scale,
h * scale);
m_surface = eglCreatePlatformWindowSurface(m_display, *m_config,
m_surface = eglCreatePlatformWindowSurface(m_display, m_config,
m_wlEGLWindow, nullptr);
// We need to use "map-event" instead of "map" to ensure that the
@@ -596,8 +581,6 @@ bool wxGLCanvasEGL::CreateSurface()
wxGLCanvasEGL::~wxGLCanvasEGL()
{
if ( m_config && m_config != ms_glEGLConfig )
delete m_config;
if ( m_surface )
eglDestroySurface(m_display, m_surface);
#ifdef GDK_WINDOWING_WAYLAND
@@ -664,7 +647,7 @@ bool wxGLCanvasBase::IsExtensionSupported(const char *extension)
/* static */
EGLConfig *wxGLCanvasEGL::InitConfig(const wxGLAttributes& dispAttrs)
EGLConfig wxGLCanvasEGL::InitConfig(const wxGLAttributes& dispAttrs)
{
const int* attrsList = dispAttrs.GetGLAttrs();
if ( !attrsList )
@@ -715,9 +698,9 @@ EGLConfig *wxGLCanvasEGL::InitConfig(const wxGLAttributes& dispAttrs)
{
// We can just get the first config proposed by the driver in
// this case.
std::unique_ptr<EGLConfig> config(new EGLConfig);
EGLConfig config;
if ( !eglChooseConfig(dpy, attrsList, config.get(), 1, &numConfigs)
if ( !eglChooseConfig(dpy, attrsList, &config, 1, &numConfigs)
|| numConfigs != 1 )
{
// This is not necessarily an error, there may just be no
@@ -725,7 +708,7 @@ EGLConfig *wxGLCanvasEGL::InitConfig(const wxGLAttributes& dispAttrs)
return nullptr;
}
return config.release();
return config;
}
}
}
@@ -757,20 +740,19 @@ EGLConfig *wxGLCanvasEGL::InitConfig(const wxGLAttributes& dispAttrs)
if ( alpha == 0 )
{
// We can use this one.
return new EGLConfig(config);
return config;
}
}
// Choose the first config, it's better to return something using alpha
// than nothing at all.
return new EGLConfig(configs.front());
return configs.front();
}
/* static */
bool wxGLCanvasBase::IsDisplaySupported(const wxGLAttributes& dispAttrs)
{
std::unique_ptr<EGLConfig> config(wxGLCanvasEGL::InitConfig(dispAttrs));
return config != nullptr;
return wxGLCanvasEGL::InitConfig(dispAttrs) != nullptr;
}
/* static */
@@ -786,7 +768,7 @@ bool wxGLCanvasBase::IsDisplaySupported(const int *attribList)
// default visual management
// ----------------------------------------------------------------------------
EGLConfig *wxGLCanvasEGL::ms_glEGLConfig = nullptr;
EGLConfig wxGLCanvasEGL::ms_glEGLConfig = nullptr;
/* static */
bool wxGLCanvasEGL::InitDefaultConfig(const int *attribList)
@@ -802,11 +784,7 @@ bool wxGLCanvasEGL::InitDefaultConfig(const int *attribList)
/* static */
void wxGLCanvasEGL::FreeDefaultConfig()
{
if ( ms_glEGLConfig )
{
delete ms_glEGLConfig;
ms_glEGLConfig = nullptr;
}
ms_glEGLConfig = nullptr;
}
// ----------------------------------------------------------------------------