[vlc-commits] [Git][videolan/vlc][master] 20 commits: egl: reorder code

Rémi Denis-Courmont (@Courmisch) gitlab at videolan.org
Tue May 31 19:04:35 UTC 2022



Rémi Denis-Courmont pushed to branch master at VideoLAN / VLC


Commits:
cb4f1288 by Rémi Denis-Courmont at 2022-05-31T18:41:12+00:00
egl: reorder code

No functional changes.

- - - - -
0b2820e9 by Rémi Denis-Courmont at 2022-05-31T18:41:12+00:00
egl: move platform-specific display release code

This introduces a proper ReleaseDisplay() function to release
platform-specific resources.

No functional changes.

- - - - -
51b7447e by Rémi Denis-Courmont at 2022-05-31T18:41:12+00:00
egl: move platform-specific surface creation code

This introduces an internal CreateSurface() to allocate the EGL surface
in whatever platform-specific mean.

- - - - -
81b73415 by Rémi Denis-Courmont at 2022-05-31T18:41:12+00:00
egl/xcb: do not needlessly map window

If creating the EGL display fails, we really should not map a window
for naught.

- - - - -
8d8f1954 by Rémi Denis-Courmont at 2022-05-31T18:41:12+00:00
egl/x11: do not map window on error

- - - - -
ca8350f7 by Rémi Denis-Courmont at 2022-05-31T18:41:12+00:00
egl/wayland: create WL-EGL window after display

- - - - -
5cab577f by Rémi Denis-Courmont at 2022-05-31T18:41:12+00:00
egl/x11: introduce OpenDisplay()

This gathers all the Xlib-specific display creation code into a
dedicated function. This also creates (but does not map) the
intermediate window as that operation also requires the geometry data.

- - - - -
1c0824a4 by Rémi Denis-Courmont at 2022-05-31T18:41:12+00:00
egl/xcb: remove unused request/response

- - - - -
07925aa6 by Rémi Denis-Courmont at 2022-05-31T18:41:12+00:00
egl/xcb: implement OpenDisplay()

Also create the intermediate window only if the EGL display was created
successfully.

- - - - -
62d85090 by Rémi Denis-Courmont at 2022-05-31T18:41:12+00:00
egl/wayland: implement OpenDisplay()

- - - - -
a9040edd by Rémi Denis-Courmont at 2022-05-31T18:41:12+00:00
egl/wayland: request a reference counted display

This actually requests that the EGL display be reference-counted if the
EGL implementation supports it.

- - - - -
bb655ccf by Rémi Denis-Courmont at 2022-05-31T18:41:12+00:00
Revert "egl: negotiate reference counting"

This applied the attribute to surface objects, but this is an attribute
for display objects.

This reverts commit 64f2e3b4aa43fd8ac7773bb22f572441b64e22eb.

- - - - -
e9e9e0b2 by Rémi Denis-Courmont at 2022-05-31T18:41:12+00:00
egl/win32: implement OpenDisplay()

- - - - -
32ffe633 by Rémi Denis-Courmont at 2022-05-31T18:41:12+00:00
egl/android: implement OpenDisplay()

- - - - -
23488f7a by Rémi Denis-Courmont at 2022-05-31T18:41:12+00:00
egl: remove dead code

- - - - -
0bf6bf52 by Rémi Denis-Courmont at 2022-05-31T18:41:12+00:00
egl: remove tautology

- - - - -
343bad05 by Rémi Denis-Courmont at 2022-05-31T18:41:12+00:00
egl: split DestroySurface() from ReleaseDisplay()

- - - - -
aded95ed by Rémi Denis-Courmont at 2022-05-31T18:41:12+00:00
egl/android: fix invalid free

Only release the window if it was actually referenced.

- - - - -
5d330a5f by Rémi Denis-Courmont at 2022-05-31T18:41:12+00:00
egl: cache client API properties

Client extensions and function pointers are independent of the display
and will never change during run-time, so cache them once and for all.

- - - - -
8ff0e626 by Rémi Denis-Courmont at 2022-05-31T18:41:12+00:00
egl: ensure version 1.4

The code implicitly assumes that EGL version is 1.4 or later, which is
required for client extensions. Rather than crash, fail safe in the
unlikely event that the EGL client run-time is older.

- - - - -


1 changed file:

- modules/video_output/opengl/egl.c


Changes:

=====================================
modules/video_output/opengl/egl.c
=====================================
@@ -47,6 +47,12 @@
 # include "../android/utils.h"
 #endif
 
+static const char *clientExts;
+#ifdef EGL_EXT_platform_base
+static PFNEGLGETPLATFORMDISPLAYEXTPROC getPlatformDisplayEXT;
+static PFNEGLCREATEPLATFORMWINDOWSURFACEEXTPROC createPlatformWindowSurfaceEXT;
+#endif
+
 typedef struct vlc_gl_sys_t
 {
     EGLDisplay display;
@@ -66,6 +72,26 @@ typedef struct vlc_gl_sys_t
     bool is_current;
 } vlc_gl_sys_t;
 
+static bool CheckAPI(EGLDisplay dpy, const char *api)
+{
+    const char *apis = eglQueryString(dpy, EGL_CLIENT_APIS);
+    return vlc_gl_StrHasToken(apis, api);
+}
+
+static bool CheckClientExt(const char *name)
+{
+    return vlc_gl_StrHasToken(clientExts, name);
+}
+
+struct gl_api
+{
+   const char name[10];
+   EGLenum    api;
+   EGLint     min_minor;
+   EGLint     render_bit;
+   EGLint     attr[3];
+};
+
 static int MakeCurrent (vlc_gl_t *gl)
 {
     vlc_gl_sys_t *sys = gl->sys;
@@ -86,27 +112,74 @@ static void ReleaseCurrent (vlc_gl_t *gl)
     sys->is_current = false;
 }
 
-#ifdef USE_PLATFORM_XCB
-static int GetScreenNum(xcb_connection_t *conn, const xcb_screen_t *scr)
+#ifdef USE_PLATFORM_WAYLAND
+static void Resize (vlc_gl_t *gl, unsigned width, unsigned height)
 {
-    xcb_screen_iterator_t i = xcb_setup_roots_iterator(xcb_get_setup(conn));
-    int n = 0;
+    vlc_gl_sys_t *sys = gl->sys;
 
-    while (scr != i.data) {
-         xcb_screen_next(&i);
-         n++;
-    }
-    return n;
+    wl_egl_window_resize(sys->window, width, height, 0, 0);
 }
-#endif
 
-#ifdef USE_PLATFORM_WAYLAND
-static void Resize (vlc_gl_t *gl, unsigned width, unsigned height)
+static void DestroySurface(vlc_gl_t *gl)
 {
     vlc_gl_sys_t *sys = gl->sys;
 
-    wl_egl_window_resize(sys->window, width, height, 0, 0);
+    wl_egl_window_destroy(sys->window);
+}
+
+static EGLSurface CreateSurface(vlc_gl_t *gl, EGLDisplay dpy, EGLConfig config,
+                                unsigned int width, unsigned int height)
+{
+# ifdef EGL_EXT_platform_base
+    vlc_gl_sys_t *sys = gl->sys;
+    EGLSurface surface;
+
+    sys->window = wl_egl_window_create(gl->surface->handle.wl, width, height);
+    if (sys->window == NULL)
+        return EGL_NO_SURFACE;
+
+    assert(CheckClientExt("EGL_EXT_platform_wayland"));
+    surface = createPlatformWindowSurfaceEXT(dpy, config, sys->window, NULL);
+
+    if (surface == EGL_NO_SURFACE)
+        wl_egl_window_destroy(sys->window);
+
+    return surface;
+# else
+    return EGL_NO_SURFACE;
+# endif
+}
+
+static void ReleaseDisplay(vlc_gl_t *gl)
+{
+    (void) gl;
 }
+
+static EGLDisplay OpenDisplay(vlc_gl_t *gl)
+{
+# ifdef EGL_EXT_platform_wayland
+    vlc_window_t *surface = gl->surface;
+    EGLint attrs[] = {
+        EGL_NONE, EGL_TRUE,
+        EGL_NONE
+    };
+
+#  ifdef EGL_KHR_display_reference
+    if (CheckClientExt("EGL_KHR_display_reference"))
+        attrs[0] = EGL_TRACK_REFERENCES_KHR;
+#  endif
+
+    if (surface->type != VLC_WINDOW_TYPE_WAYLAND)
+        return EGL_NO_DISPLAY;
+    if (!CheckClientExt("EGL_EXT_platform_wayland"))
+        return EGL_NO_DISPLAY;
+    return getPlatformDisplayEXT(EGL_PLATFORM_WAYLAND_EXT, surface->display.wl,
+                                 attrs);
+# else
+    return EGL_NO_DISPLAY;
+# endif
+}
+
 #elif defined(USE_PLATFORM_X11)
 static void Resize (vlc_gl_t *gl, unsigned width, unsigned height)
 {
@@ -125,7 +198,110 @@ static void Resize (vlc_gl_t *gl, unsigned width, unsigned height)
         ReleaseCurrent(gl);
     }
 }
+
+static void DestroySurface(vlc_gl_t *gl)
+{
+    vlc_gl_sys_t *sys = gl->sys;
+
+    XUnmapWindow(sys->x11, sys->x11_win);
+}
+
+static EGLSurface CreateSurface(vlc_gl_t *gl, EGLDisplay dpy, EGLConfig config,
+                                unsigned int width, unsigned int height)
+{
+    vlc_gl_sys_t *sys = gl->sys;
+    Window win = sys->x11_win;
+
+    XResizeWindow(sys->x11, win, width, height);
+    XMapWindow(sys->x11, win);
+
+# ifdef EGL_EXT_platform_base
+    if (CheckClientExt("EGL_EXT_platform_x11"))
+        return createPlatformWindowSurfaceEXT(dpy, config, &win, NULL);
+# endif
+    return eglCreateWindowSurface(dpy, config, win, NULL);
+}
+
+static void ReleaseDisplay(vlc_gl_t *gl)
+{
+    vlc_gl_sys_t *sys = gl->sys;
+
+    XCloseDisplay(sys->x11);
+}
+
+static EGLDisplay OpenDisplay(vlc_gl_t *gl)
+{
+    vlc_window_t *surface = gl->surface;
+    vlc_gl_sys_t *sys = gl->sys;
+
+    if (surface->type != VLC_WINDOW_TYPE_XID || !vlc_xlib_init(VLC_OBJECT(gl)))
+        return EGL_NO_DISPLAY;
+
+    Display *x11 = XOpenDisplay(surface->display.x11);
+    if (x11 == NULL)
+        return EGL_NO_DISPLAY;
+
+    XWindowAttributes wa;
+
+    if (!XGetWindowAttributes(x11, surface->handle.xid, &wa))
+        goto error;
+
+    EGLDisplay display;
+    int snum = XScreenNumberOfScreen(wa.screen);
+
+# ifdef EGL_EXT_platform_x11
+    if (CheckClientExt("EGL_EXT_platform_x11")) {
+        const EGLint attrs[] = {
+            EGL_PLATFORM_X11_SCREEN_EXT, snum,
+            EGL_NONE
+        };
+
+        display = getPlatformDisplayEXT(EGL_PLATFORM_X11_EXT, x11, attrs);
+    } else
+# endif
+# ifdef __unix__
+    if (snum == XDefaultScreen(x11))
+        display = eglGetDisplay(x11);
+    else
+# endif
+        display = EGL_NO_DISPLAY;
+
+    if (display == EGL_NO_DISPLAY)
+        goto error;
+
+    unsigned long mask =
+        CWBackPixel | CWBorderPixel | CWBitGravity | CWColormap;
+    XSetWindowAttributes swa = {
+        .background_pixel = BlackPixelOfScreen(wa.screen),
+        .border_pixel = BlackPixelOfScreen(wa.screen),
+        .bit_gravity = NorthWestGravity,
+        .colormap = DefaultColormapOfScreen(wa.screen),
+    };
+
+    sys->x11 = x11;
+    sys->x11_win = XCreateWindow(x11, surface->handle.xid, 0, 0, wa.width,
+                                 wa.height, 0, DefaultDepthOfScreen(wa.screen),
+                                 InputOutput, DefaultVisualOfScreen(wa.screen),
+                                 mask, &swa);
+    return display;
+error:
+    XCloseDisplay(x11);
+    return EGL_NO_DISPLAY;
+}
+
 #elif defined(USE_PLATFORM_XCB)
+static int GetScreenNum(xcb_connection_t *conn, const xcb_screen_t *scr)
+{
+    xcb_screen_iterator_t i = xcb_setup_roots_iterator(xcb_get_setup(conn));
+    int n = 0;
+
+    while (scr != i.data) {
+         xcb_screen_next(&i);
+         n++;
+    }
+    return n;
+}
+
 static void Resize (vlc_gl_t *gl, unsigned width, unsigned height)
 {
     vlc_gl_sys_t *sys = gl->sys;
@@ -142,131 +318,238 @@ static void Resize (vlc_gl_t *gl, unsigned width, unsigned height)
         ReleaseCurrent(gl);
     }
 }
-#else
-# define Resize (NULL)
-#endif
 
-static void SwapBuffers (vlc_gl_t *gl)
+static void DestroySurface(vlc_gl_t *gl)
 {
     vlc_gl_sys_t *sys = gl->sys;
 
-    if (!sys->is_current)
-    {
-        EGLSurface s_read = eglGetCurrentSurface(EGL_READ);
-        EGLSurface s_draw = eglGetCurrentSurface(EGL_DRAW);
-        EGLContext previous_context = eglGetCurrentContext();
+    xcb_unmap_window(sys->conn, sys->xcb_win);
+}
 
-        eglMakeCurrent(sys->display, sys->surface, sys->surface, sys->context);
-        eglSwapBuffers (sys->display, sys->surface);
-        eglMakeCurrent(sys->display, s_read, s_draw, previous_context);
+static EGLSurface CreateSurface(vlc_gl_t *gl, EGLDisplay dpy, EGLConfig config,
+                                unsigned int width, unsigned int height)
+{
+# ifdef EGL_EXT_platform_base
+    vlc_gl_sys_t *sys = gl->sys;
+    xcb_connection_t *conn = sys->conn;
+    xcb_window_t win = sys->xcb_win;
+    uint32_t mask = XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT;
+    const uint32_t values[] = { width, height, };
+
+    xcb_configure_window(conn, win, mask, values);
+    xcb_map_window(conn, win);
+
+    assert(CheckClientExt("EGL_EXT_platform_xcb"));
+    return createPlatformWindowSurfaceEXT(dpy, config, &win, NULL);
+# else
+    return EGL_NO_SURFACE;
+# endif
+}
+
+static void ReleaseDisplay(vlc_gl_t *gl)
+{
+    vlc_gl_sys_t *sys = gl->sys;
+
+    xcb_disconnect(sys->conn);
+}
+
+static EGLDisplay OpenDisplay(vlc_gl_t *gl)
+{
+# ifdef EGL_EXT_platform_xcb
+    vlc_window_t *surface = gl->surface;
+    vlc_gl_sys_t *sys = gl->sys;
+    xcb_connection_t *conn;
+    const xcb_screen_t *scr;
+
+    if (surface->type != VLC_WINDOW_TYPE_XID)
+        return EGL_NO_DISPLAY;
+    if (!CheckClientExt("EGL_EXT_platform_xcb"))
+        return EGL_NO_DISPLAY;
+    if (vlc_xcb_parent_Create(gl->obj.logger, surface, &conn,
+                              &scr) != VLC_SUCCESS)
+        return EGL_NO_DISPLAY;
+
+    const EGLint attrs[] = {
+        EGL_PLATFORM_XCB_SCREEN_EXT, GetScreenNum(conn, scr),
+        EGL_NONE
+    };
+
+    EGLDisplay display = getPlatformDisplayEXT(EGL_PLATFORM_XCB_EXT, conn,
+                                               attrs);
+    if (display == EGL_NO_DISPLAY) {
+        xcb_disconnect(conn);
+        goto out;
     }
-    else
-        eglSwapBuffers (sys->display, sys->surface);
+
+    xcb_window_t win = xcb_generate_id(conn);
+    uint32_t mask =
+        XCB_CW_BACK_PIXEL |
+        XCB_CW_BORDER_PIXEL |
+        XCB_CW_BIT_GRAVITY |
+        XCB_CW_COLORMAP;
+    const uint32_t values[] = {
+        /* XCB_CW_BACK_PIXEL */
+        scr->black_pixel,
+        /* XCB_CW_BORDER_PIXEL */
+        scr->black_pixel,
+        /* XCB_CW_BIT_GRAVITY */
+        XCB_GRAVITY_NORTH_WEST,
+        /* XCB_CW_COLORMAP */
+        scr->default_colormap,
+    };
+
+    xcb_create_window(conn, scr->root_depth, win, surface->handle.xid, 0, 0, 1,
+                      1, 0, XCB_WINDOW_CLASS_INPUT_OUTPUT, scr->root_visual,
+                      mask, values);
+    sys->conn = conn;
+    sys->xcb_win = win;
+out:
+    return display;
+# else
+    return EGL_NO_DISPLAY;
+# endif
 }
 
-static void *GetSymbol(vlc_gl_t *gl, const char *procname)
+#elif defined (USE_PLATFORM_ANDROID)
+# define Resize (NULL)
+
+static void DestroySurface(vlc_gl_t *gl)
 {
-    (void) gl;
-    return (void *)eglGetProcAddress (procname);
+    AWindowHandler_releaseANativeWindow(gl->surface->handle.anativewindow,
+                                        AWindow_Video);
 }
 
-static bool CheckAPI (EGLDisplay dpy, const char *api)
+static EGLSurface CreateSurface(vlc_gl_t *gl, EGLDisplay dpy, EGLConfig config,
+                                unsigned int width, unsigned int height)
 {
-    const char *apis = eglQueryString (dpy, EGL_CLIENT_APIS);
-    return vlc_gl_StrHasToken(apis, api);
+    ANativeWindow *anw =
+        AWindowHandler_getANativeWindow(gl->surface->handle.anativewindow,
+                                        AWindow_Video);
+
+    (void) width; (void) height;
+    return (anw != NULL) ? eglCreateWindowSurface(dpy, config, anw, NULL)
+                         : EGL_NO_SURFACE;
 }
 
-static bool CheckClientExt(const char *name)
+static void ReleaseDisplay(vlc_gl_t *gl)
 {
-    const char *exts = eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS);
-    return vlc_gl_StrHasToken(exts, name);
+    (void) gl;
 }
 
-struct gl_api
+static EGLDisplay OpenDisplay(vlc_gl_t *gl)
 {
-   const char name[10];
-   EGLenum    api;
-   EGLint     min_minor;
-   EGLint     render_bit;
-   EGLint     attr[3];
-};
+# if defined (__ANDROID__) || defined (ANDROID)
+    if (gl->surface->type == VLC_WINDOW_TYPE_ANDROID_NATIVE)
+        return eglGetDisplay(EGL_DEFAULT_DISPLAY);
+# endif
+    return EGL_NO_DISPLAY;
+}
 
-#ifdef EGL_EXT_platform_base
-static EGLDisplay GetDisplayEXT(EGLenum plat, void *dpy, const EGLint *attrs)
+#else
+# define Resize (NULL)
+
+static void DestroySurface(vlc_gl_t *gl)
+{
+    (void) gl;
+}
+
+static EGLSurface CreateSurface(vlc_gl_t *gl, EGLDisplay dpy, EGLConfig config,
+                                unsigned int width, unsigned int height)
 {
-    PFNEGLGETPLATFORMDISPLAYEXTPROC getDisplay =
-        (PFNEGLGETPLATFORMDISPLAYEXTPROC)
-        eglGetProcAddress("eglGetPlatformDisplayEXT");
+    HWND window = gl->surface->handle.hwnd;
 
-    assert(getDisplay != NULL);
-    return getDisplay(plat, dpy, attrs);
+    (void) width; (void) height;
+    return eglCreateWindowSurface(dpy, config, window, NULL);
 }
 
-static EGLSurface CreateWindowSurfaceEXT(EGLDisplay dpy, EGLConfig config,
-                                         void *window, const EGLint *attrs)
+static void ReleaseDisplay(vlc_gl_t *gl)
 {
-    PFNEGLCREATEPLATFORMWINDOWSURFACEEXTPROC createSurface =
-        (PFNEGLCREATEPLATFORMWINDOWSURFACEEXTPROC)
-        eglGetProcAddress("eglCreatePlatformWindowSurfaceEXT");
+    (void) gl;
+}
 
-    assert(createSurface != NULL);
-    return createSurface(dpy, config, window, attrs);
+static EGLDisplay OpenDisplay(vlc_gl_t *gl)
+{
+# if defined (_WIN32) || defined (__VC32__) \
+  && !defined (__CYGWIN__) && !defined (__SCITECH_SNAP__)
+    if (gl->surface->type == VLC_WINDOW_TYPE_HWND)
+        return eglGetDisplay(EGL_DEFAULT_DISPLAY);
+# endif
+    return EGL_NO_DISPLAY;
 }
 #endif
 
-static EGLSurface CreateWindowSurface(EGLDisplay dpy, EGLConfig config,
-                                      void *window, const EGLint *attrs)
+static void SwapBuffers (vlc_gl_t *gl)
 {
-    EGLNativeWindowType *native = window;
+    vlc_gl_sys_t *sys = gl->sys;
 
-    return eglCreateWindowSurface(dpy, config, *native, attrs);
+    if (!sys->is_current)
+    {
+        EGLSurface s_read = eglGetCurrentSurface(EGL_READ);
+        EGLSurface s_draw = eglGetCurrentSurface(EGL_DRAW);
+        EGLContext previous_context = eglGetCurrentContext();
+
+        eglMakeCurrent(sys->display, sys->surface, sys->surface, sys->context);
+        eglSwapBuffers (sys->display, sys->surface);
+        eglMakeCurrent(sys->display, s_read, s_draw, previous_context);
+    }
+    else
+        eglSwapBuffers (sys->display, sys->surface);
+}
+
+static void *GetSymbol(vlc_gl_t *gl, const char *procname)
+{
+    (void) gl;
+    return (void *)eglGetProcAddress (procname);
 }
 
 static void Close(vlc_gl_t *gl)
 {
     vlc_gl_sys_t *sys = gl->sys;
 
-    if (sys->display != EGL_NO_DISPLAY)
-    {
-        if (sys->context != EGL_NO_CONTEXT)
-            eglDestroyContext(sys->display, sys->context);
-        if (sys->surface != EGL_NO_SURFACE)
-            eglDestroySurface(sys->display, sys->surface);
-        eglTerminate(sys->display);
+    if (sys->context != EGL_NO_CONTEXT)
+        eglDestroyContext(sys->display, sys->context);
+    if (sys->surface != EGL_NO_SURFACE) {
+        eglDestroySurface(sys->display, sys->surface);
+        DestroySurface(gl);
     }
-#ifdef USE_PLATFORM_X11
-    if (sys->x11 != NULL)
-        XCloseDisplay(sys->x11);
-#elif defined (USE_PLATFORM_XCB)
-    if (sys->conn != NULL)
-        xcb_disconnect(sys->conn);
-#endif
-#ifdef USE_PLATFORM_WAYLAND
-    if (sys->window != NULL)
-        wl_egl_window_destroy(sys->window);
-#endif
-#ifdef USE_PLATFORM_ANDROID
-    AWindowHandler_releaseANativeWindow(gl->surface->handle.anativewindow,
-                                        AWindow_Video);
-#endif
+    eglTerminate(sys->display);
+    ReleaseDisplay(gl);
     free (sys);
 }
 
+static bool InitEGL(void)
+{
+    static vlc_once_t once = VLC_STATIC_ONCE;
+
+    if (unlikely(!vlc_once_begin(&once))) {
+        clientExts = eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS);
+#ifdef EGL_EXT_platform_base
+        getPlatformDisplayEXT =
+            (void *) eglGetProcAddress("eglGetPlatformDisplayEXT");
+        createPlatformWindowSurfaceEXT =
+            (void *) eglGetProcAddress("eglCreatePlatformWindowSurfaceEXT");
+#endif
+        vlc_once_complete(&once);
+    }
+    return clientExts != NULL; /* check if EGL version is 1.4 or later */
+}
+
 /**
  * Probe EGL display availability
  */
 static int Open(vlc_gl_t *gl, const struct gl_api *api,
                 unsigned width, unsigned height)
 {
+    if (!InitEGL())
+        return VLC_ENOTSUP;
+
     int ret = VLC_EGENERIC;
     vlc_object_t *obj = VLC_OBJECT(gl);
     vlc_gl_sys_t *sys = malloc(sizeof (*sys));
     if (unlikely(sys == NULL))
         return VLC_ENOMEM;
 
-    const char *ext = eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS);
-    if (*ext)
-        msg_Dbg(obj, "EGL client extensions: %s", ext);
+    msg_Dbg(obj, "EGL client extensions: %s", clientExts);
 
     gl->sys = sys;
     sys->display = EGL_NO_DISPLAY;
@@ -274,186 +557,11 @@ static int Open(vlc_gl_t *gl, const struct gl_api *api,
     sys->context = EGL_NO_CONTEXT;
     sys->is_current = false;
 
-    vlc_window_t *wnd = gl->surface;
-    EGLSurface (*createSurface)(EGLDisplay, EGLConfig, void *, const EGLint *)
-        = CreateWindowSurface;
-    void *window;
-    EGLAttrib refs_name = EGL_NONE;
-    EGLAttrib refs_value = EGL_FALSE;
-
-#ifdef EGL_KHR_display_reference
-    if (CheckClientExt("EGL_KHR_display_reference"))
-    {
-        refs_name = EGL_TRACK_REFERENCES_KHR;
-        refs_value = EGL_TRUE;
+    sys->display = OpenDisplay(gl);
+    if (sys->display == EGL_NO_DISPLAY) {
+        free(sys);
+        return VLC_ENOTSUP;
     }
-#endif
-
-#ifdef USE_PLATFORM_X11
-    sys->x11 = NULL;
-
-    if (wnd->type != VLC_WINDOW_TYPE_XID || !vlc_xlib_init(obj))
-        goto error;
-
-    sys->x11 = XOpenDisplay(wnd->display.x11);
-    if (sys->x11 == NULL)
-        goto error;
-
-    int snum;
-    {
-        XWindowAttributes wa;
-        XSetWindowAttributes swa;
-
-        if (!XGetWindowAttributes(sys->x11, wnd->handle.xid, &wa))
-            goto error;
-        snum = XScreenNumberOfScreen(wa.screen);
-        unsigned long mask =
-            CWBackPixel |
-            CWBorderPixel |
-            CWBitGravity |
-            CWColormap;
-        swa.background_pixel = BlackPixelOfScreen(wa.screen);
-        swa.border_pixel = BlackPixelOfScreen(wa.screen);
-        swa.bit_gravity = NorthWestGravity;
-        swa.colormap = DefaultColormapOfScreen(wa.screen);
-        sys->x11_win = XCreateWindow(
-                sys->x11, wnd->handle.xid, 0, 0, width, height, 0,
-                DefaultDepthOfScreen(wa.screen), InputOutput,
-                DefaultVisualOfScreen(wa.screen), mask, &swa);
-        XMapWindow(sys->x11, sys->x11_win);
-    }
-    window = &sys->x11_win;
-# ifdef EGL_EXT_platform_x11
-    if (CheckClientExt("EGL_EXT_platform_x11"))
-    {
-        const EGLint attrs[] = {
-            EGL_PLATFORM_X11_SCREEN_EXT, snum,
-            EGL_NONE
-        };
-        sys->display = GetDisplayEXT(EGL_PLATFORM_X11_EXT, sys->x11, attrs);
-        createSurface = CreateWindowSurfaceEXT;
-    }
-    else
-# endif
-    {
-# ifdef __unix__
-        if (snum == XDefaultScreen(sys->x11))
-            sys->display = eglGetDisplay(sys->x11);
-# endif
-    }
-
-#elif defined (USE_PLATFORM_XCB)
-    xcb_connection_t *conn;
-    const xcb_screen_t *scr;
-
-    sys->conn = NULL;
-
-    if (wnd->type != VLC_WINDOW_TYPE_XID)
-        goto error;
-
-# ifdef EGL_EXT_platform_xcb
-    if (!CheckClientExt("EGL_EXT_platform_xcb"))
-        goto error;
-
-    ret = vlc_xcb_parent_Create(gl->obj.logger, wnd, &conn, &scr);
-    if (ret == VLC_SUCCESS)
-    {
-        sys->xcb_win = xcb_generate_id(conn);
-        xcb_get_window_attributes_reply_t *r =
-            xcb_get_window_attributes_reply(conn,
-                xcb_get_window_attributes(conn, wnd->handle.xid), NULL);
-
-        if (r != NULL) {
-            uint32_t mask =
-                XCB_CW_BACK_PIXEL |
-                XCB_CW_BORDER_PIXEL |
-                XCB_CW_BIT_GRAVITY |
-                XCB_CW_COLORMAP;
-            const uint32_t values[] = {
-                /* XCB_CW_BACK_PIXEL */
-                scr->black_pixel,
-                /* XCB_CW_BORDER_PIXEL */
-                scr->black_pixel,
-                /* XCB_CW_BIT_GRAVITY */
-                XCB_GRAVITY_NORTH_WEST,
-                /* XCB_CW_COLORMAP */
-                scr->default_colormap,
-            };
-            xcb_create_window(conn, scr->root_depth, sys->xcb_win,
-                              wnd->handle.xid, 0, 0, width, height, 0,
-                              XCB_WINDOW_CLASS_INPUT_OUTPUT, scr->root_visual,
-                              mask, values);
-            xcb_map_window(conn, sys->xcb_win);
-        }
-        free(r);
-    }
-    else
-        goto error;
-
-    sys->conn = conn;
-    window = &sys->xcb_win;
-
-    {
-        const EGLint attrs[] = {
-            EGL_PLATFORM_XCB_SCREEN_EXT, GetScreenNum(sys->conn, scr),
-            EGL_NONE
-        };
-        sys->display = GetDisplayEXT(EGL_PLATFORM_XCB_EXT, sys->conn, attrs);
-        createSurface = CreateWindowSurfaceEXT;
-    }
-# endif
-
-#elif defined (USE_PLATFORM_WAYLAND)
-    sys->window = NULL;
-
-    if (wnd->type != VLC_WINDOW_TYPE_WAYLAND)
-        goto error;
-
-# ifdef EGL_EXT_platform_wayland
-    if (!CheckClientExt("EGL_EXT_platform_wayland"))
-        goto error;
-
-    window = wl_egl_window_create(wnd->handle.wl, width, height);
-    if (window == NULL)
-        goto error;
-    sys->window = window;
-
-    sys->display = GetDisplayEXT(EGL_PLATFORM_WAYLAND_EXT, wnd->display.wl,
-                                 NULL);
-    createSurface = CreateWindowSurfaceEXT;
-
-# endif
-
-#elif defined (USE_PLATFORM_WIN32)
-    if (wnd->type != VLC_WINDOW_TYPE_HWND)
-        goto error;
-
-    window = &wnd->handle.hwnd;
-# if defined (_WIN32) || defined (__VC32__) \
-  && !defined (__CYGWIN__) && !defined (__SCITECH_SNAP__)
-    sys->display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
-# endif
-    (void) width; (void) height;
-
-#elif defined (USE_PLATFORM_ANDROID)
-    if (wnd->type != VLC_WINDOW_TYPE_ANDROID_NATIVE)
-        goto error;
-
-    ANativeWindow *anw =
-        AWindowHandler_getANativeWindow(wnd->handle.anativewindow,
-                                        AWindow_Video);
-    if (anw == NULL)
-        goto error;
-    window = &anw;
-# if defined (__ANDROID__) || defined (ANDROID)
-    sys->display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
-# endif
-    (void) width; (void) height;
-
-#endif
-
-    if (sys->display == EGL_NO_DISPLAY)
-        goto error;
 
     /* Initialize EGL display */
     EGLint major, minor;
@@ -463,7 +571,7 @@ static int Open(vlc_gl_t *gl, const struct gl_api *api,
             eglQueryString(sys->display, EGL_VERSION),
             eglQueryString(sys->display, EGL_VENDOR));
 
-    ext = eglQueryString(sys->display, EGL_EXTENSIONS);
+    const char *ext = eglQueryString(sys->display, EGL_EXTENSIONS);
     if (*ext)
         msg_Dbg(obj, "EGL display extensions: %s", ext);
 
@@ -479,7 +587,6 @@ static int Open(vlc_gl_t *gl, const struct gl_api *api,
         EGL_GREEN_SIZE, 5,
         EGL_BLUE_SIZE, 5,
         EGL_RENDERABLE_TYPE, api->render_bit,
-        refs_name, refs_value,
         EGL_NONE
     };
     EGLConfig cfgv[1];
@@ -493,7 +600,7 @@ static int Open(vlc_gl_t *gl, const struct gl_api *api,
     }
 
     /* Create a drawing surface */
-    sys->surface = createSurface(sys->display, cfgv[0], window, NULL);
+    sys->surface = CreateSurface(gl, sys->display, cfgv[0], width, height);
     if (sys->surface == EGL_NO_SURFACE)
     {
         msg_Err (obj, "cannot create EGL window surface");



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/549c6c725a31ea873d3683399bf279c00089ae83...8ff0e6267b4f3b76e2526192a98af68fcd6aa953

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/549c6c725a31ea873d3683399bf279c00089ae83...8ff0e6267b4f3b76e2526192a98af68fcd6aa953
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list