GDK/Win32: Use wgl* functions directly as needed (fix #5685)

Chun-wei Fan requested to merge alternative-fix-5685 into main


Since it will not likely be soon if libepoxy can be fixed to not require epoxy_handle_external_wglMakeCurrent(), plus there are some small other Windows-specific items that are involved when using WGL in the GStreamer media backend (as we need to use make things work across different threads between GTK/GDK and GstGL), this is another approach to make things more readable and easier to maintain, at least for the time being.

This attempts to sub-class GtkGstSink for Windows (i.e. GDK_IS_WIN32_DISPLAY), where we move the Windows GL initialization items in gtk_gst_sink_initialize_gl() into a new vfunc initialize_gl for the new sub-class, which we add in the GtkGstSink class, so that we can get rid of the macro calls that we need to sprinkle within gtk_gst_sink_initialize_gl() to accommodate Windows support and instead just call the needed items accordingly in the subclass. Also, for the subclass, make sure we also call epoxy_handle_external_wglMakeCurrent() as we dispose of it, before proceeding to dispose items in the GtkGstSink as we did before.

This attempts to create wrapper functions for wglGetCurrentContext(), wglMakeCurrent() and wglDeleteContext() that we do not call via libepoxy, but instead directly through opengl32.dll by linking to opengl32.lib, so that we are assured that we call them correctly in GDK even if wglMakeCurrent() has been called outside of GTK/GDK (for example, GstGL), which may render the function pointers kept by libepoxy to be invalid.

This however, needs a source file of its own and we must ensure that the libepoxy headers are not included in any way in that source file, and one cannot include GL/gl.h together with epoxy/(w)gl.h in the same compilation unit.

If this is deemed acceptable, I will try to see whether we can clean up modules/media/gtkgstsink.c a bit--the existing REACTIVATE_WGL_CONTEXT() and DEACTIVATE_WGL_CONTEXT() calls are still needed, sadly, and must be called from the media-gstreamer.dll side 1.

Comments are welcome for this.

With blessings, thank you!

Edited by Chun-wei Fan

Merge request reports