From 23ccdb23c84b6b3de74d1cd83c83d7ad01431725 Mon Sep 17 00:00:00 2001 From: Dan Gudmundsson Date: Tue, 21 Mar 2023 09:43:49 +0100 Subject: [PATCH] Improve and document wxGLCanvas::CreateSurface() This function must be called to be able to re-create the EGL drawing surface after the window layout have changed, such as after a reparent of the canvas or of it's grandparents. Make it suitable for use in this case by re-creating the surface if there already was one and document this function to make it part of the public API. Closes #23366. --- interface/wx/glcanvas.h | 13 +++++++++++++ src/unix/glegl.cpp | 6 ++++++ 2 files changed, 19 insertions(+) diff --git a/interface/wx/glcanvas.h b/interface/wx/glcanvas.h index 0b0e1f7bd7..20e55b3763 100644 --- a/interface/wx/glcanvas.h +++ b/interface/wx/glcanvas.h @@ -887,6 +887,19 @@ public: const wxString& name = "GLCanvas", const wxPalette& palette = wxNullPalette); + + /** + Re-creates EGLSurface. To be used after a reparent or other + changes that may invalidate the EGL drawing surface. + + Only available when wxUSE_GLCANVAS_EGL is enabled. + + @return @true if surface is successfully recreated + + @since 3.2.3 + */ + bool CreateSurface(); + /** Determines if a canvas having the specified attributes is available. This only applies for visual attributes, not rendering context attributes. diff --git a/src/unix/glegl.cpp b/src/unix/glegl.cpp index 5e94e99876..97e6237ca5 100644 --- a/src/unix/glegl.cpp +++ b/src/unix/glegl.cpp @@ -458,6 +458,12 @@ bool wxGLCanvasEGL::CreateSurface() return false; } + if ( m_surface != EGL_NO_SURFACE ) + { + eglDestroySurface(m_surface, m_display); + m_surface = EGL_NO_SURFACE; + } + GdkWindow *window = GTKGetDrawingWindow(); #ifdef GDK_WINDOWING_X11 if (wxGTKImpl::IsX11(window))