eglGetDisplay returns 0 and EGL_SUCCESS on Wayland ARM

Hello!
I am developing 3d rendering modules for embedded systems.
Due to the nature of the project, I need to render directly onto an AWT canvas. For that I’m using JAWT to get display / surface information from the canvas, and then use EGL to tie in this surface with OpenGL-ES and render.

This method worked fine so far (Tested on x64 PC-based Debian linux as well as ARM-based Debian linux).

Now I got a sudden task to make my stuff running on another hardware that is using Wayland instead of Debian. And for some reason, I run into trouble.

Here’s my simple code:

public class Window 
{
    boolean locked = false;
    
    public Component canvas;
    private JAWTDrawingSurface ds;
    public long display;
    private long eglDisplay;
    public long drawable;
    private long surface;
    GLESCapabilities glesCaps;
    EGLCapabilities eglCaps;
    PointerBuffer fbConfigs;

    public long context = 0;

    public static final JAWT awt;

    static 
    {
        awt = JAWT.calloc();
        awt.version(JAWT_VERSION_1_4);
        if (!JAWT_GetAWT(awt))
            throw new AssertionError("GetAWT failed");
    }


    public Window(Component canvas) 
    {
        this.canvas = canvas;
    }

    synchronized public void lock() throws AWTException 
    {
        int lock = JAWT_DrawingSurface_Lock(ds, ds.Lock());
        if ((lock & JAWT_LOCK_ERROR) != 0)
            throw new AWTException("JAWT_DrawingSurface_Lock() failed");
        locked = true;
    }

    synchronized public void unlock() throws AWTException 
    {
        JAWT_DrawingSurface_Unlock(ds, ds.Unlock());
        locked = false;
    }

    synchronized public void Init() 
    {
        this.ds = JAWT_GetDrawingSurface(canvas, awt.GetDrawingSurface());
        
        try 
        {
            lock();
            try 
            {
                JAWTDrawingSurfaceInfo dsi = JAWT_DrawingSurface_GetDrawingSurfaceInfo(ds, ds.GetDrawingSurfaceInfo());

                JAWTX11DrawingSurfaceInfo dsiWin = JAWTX11DrawingSurfaceInfo.create(dsi.platformInfo());
                
                this.display = dsiWin.display();
                this.drawable = dsiWin.drawable();

                eglDisplay = eglGetDisplay(display);

                try (MemoryStack stack = stackPush()) 
                {
                    IntBuffer major = stack.mallocInt(1);
                    IntBuffer minor = stack.mallocInt(1);

                    boolean bul = eglInitialize(eglDisplay, major, minor);

                    if (!bul) 
                    {
                        throw new IllegalStateException(String.format("-- Failed to initialize EGL [0x%X]", eglGetError()));
                    }

                    eglCaps = EGL.createDisplayCapabilities(eglDisplay, major.get(0), minor.get(0));
                }

                IntBuffer attrib_list = BufferUtils.createIntBuffer(16);
                attrib_list.put(EGL_ALPHA_SIZE).put(4);
                attrib_list.put(EGL_RED_SIZE).put(5);
                attrib_list.put(EGL_GREEN_SIZE).put(6);
                attrib_list.put(EGL_BLUE_SIZE).put(5);
                attrib_list.put(EGL_DEPTH_SIZE).put(24);
                attrib_list.put(EGL_NONE);
                attrib_list.flip();

                fbConfigs = BufferUtils.createPointerBuffer(10);
                IntBuffer numConfigs = BufferUtils.createIntBuffer(1);

                eglChooseConfig(eglDisplay, attrib_list, fbConfigs, numConfigs);

                IntBuffer context_attrib_list = BufferUtils.createIntBuffer(18);
                context_attrib_list.put(EGL_CONTEXT_MAJOR_VERSION).put(3);
                context_attrib_list.put(EGL_CONTEXT_MINOR_VERSION).put(0);
                context_attrib_list.put(EGL_NONE);
                context_attrib_list.flip();

                context = eglCreateContext(eglDisplay, fbConfigs.get(0), EGL_NO_CONTEXT, context_attrib_list);
                
                surface = eglCreateWindowSurface(eglDisplay, fbConfigs.get(0), drawable, (int[]) null);
                
                eglMakeCurrent(eglDisplay, surface, surface, context);
                
                glesCaps = GLES.createCapabilities();

                JAWT_DrawingSurface_FreeDrawingSurfaceInfo(dsi, ds.FreeDrawingSurfaceInfo());
            } 
            finally 
            {
                unlock();
            }

        } 
        catch (Exception e) 
        {
            e.printStackTrace();
            System.err.println("JAWT Failed: " + e.getMessage());
        }

        glClearColor(0f, 0f, 0f, 1f);
    }

    public void update() 
    {
        if (!paused && canvas.isVisible()) 
        {
            try 
            {
                lock();
                eglSwapBuffers(eglDisplay, surface);
                unlock();
            } 
            catch (Exception e) 
            {
                e.printStackTrace();
            }
        }
    }
}

I took a bunch of checks out to make this code more readable here.

This code throws NullPointerException on Wayland ARM device during glInitialize() function.
The reason is that eglGetDisplay returns 0. The interesting thing that if I check eglGetError() after it - it return EGL_SUCCESS, so basically EGL thinks that everything went fine, but returns 0 as a display handle.

I should note that JAWT seems to have worked properly, and returned proper display information as well as the surface.

Another thing is that I can get a good display handle by calling eglGetDisplay(EGL_DEFAULTDISPLAY). If I do that - it goes as far as creating the context, but it then fails on eglCreateWindowSurface because my eglDisplay and drawable that I get from JAWT are incompatible.