Skip to content
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

Closed
wants to merge 2 commits into from

Conversation

swt2c
Copy link
Contributor

@swt2c swt2c commented Aug 28, 2020

Among other things, this enables wxGLCanvas to be used natively on Wayland.

Fixes #17702.

Among other things, this enables wxGLCanvas to be used natively on Wayland.

Fixes wxWidgets#17702.
@swt2c
Copy link
Contributor Author

swt2c commented Aug 28, 2020

Updated to (hopefully) fix some CI errors for GTK2, CMake.

Copy link
Contributor

@vadz vadz left a 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!

include/wx/gtk/glcanvas.h Outdated Show resolved Hide resolved
include/wx/setup_inc.h Show resolved Hide resolved
include/wx/unix/glegl.h Outdated Show resolved Hide resolved
include/wx/unix/glegl.h Outdated Show resolved Hide resolved
include/wx/utils.h Outdated Show resolved Hide resolved
src/unix/glegl.cpp Outdated Show resolved Hide resolved
src/unix/glegl.cpp Outdated Show resolved Hide resolved
src/unix/glegl.cpp Outdated Show resolved Hide resolved
include/wx/unix/glegl.h Outdated Show resolved Hide resolved
src/unix/glegl.cpp Outdated Show resolved Hide resolved
Copy link
Contributor

@paulcor paulcor left a 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.

src/unix/glegl.cpp Outdated Show resolved Hide resolved
#ifdef GDK_WINDOWING_WAYLAND
if ( GDK_IS_WAYLAND_WINDOW(window) ) {
int x, y;
gdk_window_get_origin(window, &x, &y);
Copy link
Contributor

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?

Copy link
Contributor Author

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?

include/wx/unix/glegl.h Outdated Show resolved Hide resolved
@swt2c
Copy link
Contributor Author

swt2c commented Aug 28, 2020

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.

@vadz
Copy link
Contributor

vadz commented Aug 28, 2020

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 git commit --fixup (or --squash) and then rebase them once everything is finalized (or I could rebase them before merging if you prefer). TIA!

@swt2c
Copy link
Contributor Author

swt2c commented Aug 29, 2020

Okay, I think all initial comments are either fixed or at least responded to.

@vadz
Copy link
Contributor

vadz commented Aug 29, 2020

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 gdk_window_get_origin(), unfortunately. @paulcor please let us know if you'd like to change anything here before merging.

@vadz vadz added this to the 3.1.5 milestone Aug 29, 2020
@swt2c
Copy link
Contributor Author

swt2c commented Aug 29, 2020

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 gdk_window_get_origin(), unfortunately. @paulcor please let us know if you'd like to change anything here before merging.

We mention X11 when not running under it too?

@vadz
Copy link
Contributor

vadz commented Aug 29, 2020

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...

@paulcor
Copy link
Contributor

paulcor commented Aug 29, 2020 via email

@vadz
Copy link
Contributor

vadz commented Aug 31, 2020

@paulcor Do you have any objections to merging it? If not, I'll do it soon.

@paulcor
Copy link
Contributor

paulcor commented Aug 31, 2020

No objections.

@vadz vadz closed this in 7cd12a2 Sep 1, 2020
@paulcor
Copy link
Contributor

paulcor commented Sep 1, 2020

I'm getting link errors building the opengl samples:
libwx_gtk3u_gl-3.1.so: error: undefined reference to 'wl_registry_interface'
and 15 more similar.

@swt2c
Copy link
Contributor Author

swt2c commented Sep 1, 2020

I'm getting link errors building the opengl samples:
libwx_gtk3u_gl-3.1.so: error: undefined reference to 'wl_registry_interface'
and 15 more similar.

Is that fixed by your 05a134d?

@paulcor
Copy link
Contributor

paulcor commented Sep 1, 2020 via email

@swt2c
Copy link
Contributor Author

swt2c commented Sep 1, 2020

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.

@swt2c
Copy link
Contributor Author

swt2c commented Sep 1, 2020

I'm getting link errors building the opengl samples:
libwx_gtk3u_gl-3.1.so: error: undefined reference to 'wl_registry_interface'
and 15 more similar.

What environment do you use, BTW?

@paulcor
Copy link
Contributor

paulcor commented Sep 1, 2020 via email

@swt2c
Copy link
Contributor Author

swt2c commented Sep 1, 2020 via email

@paulcor
Copy link
Contributor

paulcor commented Sep 1, 2020 via email

@paulcor
Copy link
Contributor

paulcor commented Sep 2, 2020

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)

@swt2c
Copy link
Contributor Author

swt2c commented Sep 2, 2020

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:

  1. I think we need to ensure that the GTK we're using was built with Wayland support. Although I guess it won't actually hurt to link with wayland-egl even if GTK doesn't have Wayland support?
  2. This will require wayland-egl to get wxUSE_GLCANVAS_EGL, right? I think we should still prefer the EGL backend even without Wayland?

@swt2c
Copy link
Contributor Author

swt2c commented Sep 2, 2020

What do you think about the following instead?

--- a/configure.in
+++ b/configure.in
@@ -3799,6 +3799,14 @@ 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, [gdk-wayland-3.0 wayland-egl],
+                                        [
+                                            OPENGL_LIBS="$OPENGL_LIBS $WAYLAND_EGL_LIBS"
+                                        ],
+                                        [
+                                            AC_MSG_NOTICE([wayland-egl not found.  wxGLCanvas will not have native Wayland support.])
+                                        ]
+                                    )
                                 ],
                                 [
                                     AC_MSG_NOTICE([EGL 1.5+ not available. Will use GLX.])

@paulcor
Copy link
Contributor

paulcor commented Sep 2, 2020

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?

@swt2c
Copy link
Contributor Author

swt2c commented Sep 2, 2020

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.

@paulcor
Copy link
Contributor

paulcor commented Sep 4, 2020

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 gdk-wayland-3.0, pkg-config will still pick up the system one. I propose something like this:

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants