New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add EGL-based backend for wxGLCanvas #2038
Conversation
Among other things, this enables wxGLCanvas to be used natively on Wayland. Fixes wxWidgets#17702.
Updated to (hopefully) fix some CI errors for GTK2, CMake. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot, it's great that you could have finished it!
I don't know anything about neither EGL nor Wayland, so I can't meaningfully review it, and I'm not sure if anybody else can, so let's merge it and see how it works in practice.
If you can fix the various minor comments, it would be great, but if not I could do it myself a bit later (once I deal with the other "in progress" PRs).
Thanks again!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, thanks, we really need this. I've taken a quick look and made a few comments.
#ifdef GDK_WINDOWING_WAYLAND | ||
if ( GDK_IS_WAYLAND_WINDOW(window) ) { | ||
int x, y; | ||
gdk_window_get_origin(window, &x, &y); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gdk_window_get_origin()
is documented as returning root window coordinates, but Wayland won't give you those, so aren't x
and y
always zero here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I was hoping to discuss that with you. I was originally using gdk_window_get_geometry()
which did always return zero for x
and y
. However, that resulted in the Wayland surface being incorrectly positioned by about 26x70 pixels (can't remember the exact value). gdk_window_get_origin()
does not return zero on Wayland and it seems to return the correct offset that is needed. The only case where it seems not to work is if you maximize the window.
All of the examples of doing Wayland EGL on top of a GTK window I could find always use gdk_window_get_geometry()
for positioning the wl_subsurface
, though, so I wonder if something isn't right with the positioning of the underlying GdkWindow on Wayland?
Thank you both for your comments. I'll send some fixes, but do you have a preference about whether you'd rather see fixes in new commits (with a squash later) vice just amending the original commit? My personal preference is to just keep amending the original commit, but I don't know if that makes it harder to see what I fixed. |
Please don't amend the existing commits if possible, this makes it difficult/impossible to see the changes in the latest versions. Rather make your commits with |
Okay, I think all initial comments are either fixed or at least responded to. |
Thanks a lot for the fixes! I'm still not totally sure about the error message (should we really mention Wayland when not running under it?), but this can be tweaked later and I'm fine with merging this right now. I don't know about what's going on with |
We mention X11 when not running under it too? |
Yes, but this makes sense because we advise to switch to it to make OpenGL work. Switching to Wayland may not be possible and, worse, even if it is, OpenGL might still not work there if EGL is not available in this build. Which is why I think this might be misleading/aggravating to the user, if we send them on a wild goose chase... |
Scott Talbert wrote:
@swt2c commented on this pull request.
> +}
+
+/* static */
+EGLDisplay wxGLCanvasEGL::GetDisplay()
+{
+ wxDisplayType type = wxDisplayNone;
+ void *display = wxGetDisplayAndType(&type);
+ EGLenum platform;
+ if (type == wxDisplayX11)
+ platform = EGL_PLATFORM_X11_EXT;
+ else if (type == wxDisplayWayland)
+ platform = EGL_PLATFORM_WAYLAND_EXT;
+ else
+ return EGL_NO_DISPLAY;
+
+ return eglGetPlatformDisplay(platform, display, NULL);
Actually, it isn't. :-)
Oops. Sorry. Well, I did say it was a quick look...
|
@paulcor Do you have any objections to merging it? If not, I'll do it soon. |
No objections. |
I'm getting link errors building the opengl samples: |
Is that fixed by your 05a134d? |
Scott Talbert wrote:
Is that fixed by your 05a134d?
No.
|
Okay, I'll look into it. I guess we need to link the gl library against the wayland libraries, but detecting when to do so may be tricky. |
What environment do you use, BTW? |
Scott Talbert wrote:
What environment do you use, BTW?
My DE is XFCE, using X11. But I have Wayland devel packages installed,
and can run clients under weston.
|
On Tue, 1 Sep 2020, paulcor wrote:
My DE is XFCE, using X11. But I have Wayland devel packages installed,
and can run clients under weston.
What distribution?
|
Scott Talbert wrote:
What distribution?
Fedora 32
|
This works for me: diff --git a/configure.in b/configure.in
index fd7d7d9caf..61b6bf266b 100644
--- a/configure.in
+++ b/configure.in
@@ -3795,7 +3795,7 @@ if test "$wxUSE_OPENGL" = "yes" -o "$wxUSE_OPENGL" = "auto"; then
OPENGL_LIBS="-lGL -lGLU"
if test "$WXGTK3" = 1; then
- PKG_CHECK_MODULES(EGL, [egl >= 1.5],
+ PKG_CHECK_MODULES(EGL, [egl >= 1.5 wayland-egl],
[
OPENGL_LIBS="$OPENGL_LIBS $EGL_LIBS"
AC_DEFINE(wxUSE_GLCANVAS_EGL) |
A couple things with that:
|
What do you think about the following instead?
|
I'm wondering if EGL should be used when the GTK Wayland backend is not available at compile time. Is there an advantage to using EGL instead of GLX? |
AFAIK GLX is basically deprecated so IMO we should use EGL even for X11-only. |
Although it's uglier, I'd rather check for the Wayland backend with a compile test. I have multiple custom builds of GTK, in addition to the distribution packages, for testing purposes. If I'm building against one that doesn't have diff --git a/configure.in b/configure.in
index fd7d7d9caf..4905283d4e 100644
--- a/configure.in
+++ b/configure.in
@@ -3799,11 +3799,38 @@ if test "$wxUSE_OPENGL" = "yes" -o "$wxUSE_OPENGL" = "auto"; then
[
OPENGL_LIBS="$OPENGL_LIBS $EGL_LIBS"
AC_DEFINE(wxUSE_GLCANVAS_EGL)
+ PKG_CHECK_MODULES(WAYLAND_EGL, [wayland-egl],
+ [
+ AC_CACHE_CHECK([for GDK Wayland backend], wx_cv_wayland_backend,
+ [
+ save_CFLAGS=$CFLAGS
+ CFLAGS="$CFLAGS $TOOLKIT_INCLUDE"
+ AC_TRY_COMPILE([#include <gdk/gdk.h>],
+ [
+ #ifndef GDK_WINDOWING_WAYLAND
+ choke me
+ #endif
+ ],
+ wx_cv_wayland_backend=yes,
+ wx_cv_wayland_backend=no)
+ CFLAGS=$save_CFLAGS
+ ]
+ )
+ if test $wx_cv_wayland_backend = "yes"; then
+ OPENGL_LIBS="$OPENGL_LIBS $WAYLAND_EGL_LIBS"
+ have_wayland=1
+ fi
+ ],
+ [:]
+ )
],
[
AC_MSG_NOTICE([EGL 1.5+ not available. Will use GLX.])
]
)
+ if test "$have_wayland" != 1; then
+ AC_MSG_NOTICE([wxGLCanvas will not have Wayland support])
+ fi
fi
fi
fi |
Among other things, this enables wxGLCanvas to be used natively on Wayland.
Fixes #17702.