|
|
@ -4,14 +4,12 @@
|
|
|
|
#include <gbm.h> // GBM_FORMAT_XRGB8888
|
|
|
|
#include <gbm.h> // GBM_FORMAT_XRGB8888
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <wlr/util/log.h>
|
|
|
|
#include <wlr/util/log.h>
|
|
|
|
#include "backend/egl.h"
|
|
|
|
#include <wlr/egl.h>
|
|
|
|
|
|
|
|
|
|
|
|
// Extension documentation
|
|
|
|
// Extension documentation
|
|
|
|
// https://www.khronos.org/registry/EGL/extensions/KHR/EGL_KHR_image_base.txt.
|
|
|
|
// https://www.khronos.org/registry/EGL/extensions/KHR/EGL_KHR_image_base.txt.
|
|
|
|
// https://cgit.freedesktop.org/mesa/mesa/tree/docs/specs/WL_bind_wayland_display.spec
|
|
|
|
// https://cgit.freedesktop.org/mesa/mesa/tree/docs/specs/WL_bind_wayland_display.spec
|
|
|
|
|
|
|
|
|
|
|
|
struct wlr_egl *egl_global;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const char *egl_error(void) {
|
|
|
|
const char *egl_error(void) {
|
|
|
|
switch (eglGetError()) {
|
|
|
|
switch (eglGetError()) {
|
|
|
|
case EGL_SUCCESS:
|
|
|
|
case EGL_SUCCESS:
|
|
|
@ -49,29 +47,19 @@ const char *egl_error(void) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// EGL extensions
|
|
|
|
static bool egl_exts(struct wlr_egl *egl) {
|
|
|
|
PFNEGLGETPLATFORMDISPLAYEXTPROC get_platform_display;
|
|
|
|
egl->get_platform_display = (PFNEGLGETPLATFORMDISPLAYEXTPROC)
|
|
|
|
PFNEGLCREATEPLATFORMWINDOWSURFACEEXTPROC create_platform_window_surface;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PFNEGLCREATEIMAGEKHRPROC eglCreateImageKHR;
|
|
|
|
|
|
|
|
PFNEGLDESTROYIMAGEKHRPROC eglDestroyImageKHR;
|
|
|
|
|
|
|
|
PFNEGLQUERYWAYLANDBUFFERWL eglQueryWaylandBufferWL;
|
|
|
|
|
|
|
|
PFNEGLBINDWAYLANDDISPLAYWL eglBindWaylandDisplayWL;
|
|
|
|
|
|
|
|
PFNEGLUNBINDWAYLANDDISPLAYWL eglUnbindWaylandDisplayWL;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static bool egl_exts() {
|
|
|
|
|
|
|
|
get_platform_display = (PFNEGLGETPLATFORMDISPLAYEXTPROC)
|
|
|
|
|
|
|
|
eglGetProcAddress("eglGetPlatformDisplayEXT");
|
|
|
|
eglGetProcAddress("eglGetPlatformDisplayEXT");
|
|
|
|
|
|
|
|
|
|
|
|
if (!get_platform_display) {
|
|
|
|
if (!egl->get_platform_display) {
|
|
|
|
wlr_log(L_ERROR, "Failed to load EGL extension 'eglGetPlatformDisplayEXT'");
|
|
|
|
wlr_log(L_ERROR, "Failed to load EGL extension 'eglGetPlatformDisplayEXT'");
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
create_platform_window_surface = (PFNEGLCREATEPLATFORMWINDOWSURFACEEXTPROC)
|
|
|
|
egl->create_platform_window_surface = (PFNEGLCREATEPLATFORMWINDOWSURFACEEXTPROC)
|
|
|
|
eglGetProcAddress("eglCreatePlatformWindowSurfaceEXT");
|
|
|
|
eglGetProcAddress("eglCreatePlatformWindowSurfaceEXT");
|
|
|
|
|
|
|
|
|
|
|
|
if (!get_platform_display) {
|
|
|
|
if (!egl->get_platform_display) {
|
|
|
|
wlr_log(L_ERROR,
|
|
|
|
wlr_log(L_ERROR,
|
|
|
|
"Failed to load EGL extension 'eglCreatePlatformWindowSurfaceEXT'");
|
|
|
|
"Failed to load EGL extension 'eglCreatePlatformWindowSurfaceEXT'");
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
@ -124,7 +112,7 @@ static bool egl_get_config(EGLDisplay disp, EGLConfig *out, EGLenum platform) {
|
|
|
|
|
|
|
|
|
|
|
|
bool wlr_egl_init(struct wlr_egl *egl, EGLenum platform,
|
|
|
|
bool wlr_egl_init(struct wlr_egl *egl, EGLenum platform,
|
|
|
|
void *remote_display) {
|
|
|
|
void *remote_display) {
|
|
|
|
if (!egl_exts()) {
|
|
|
|
if (!egl_exts(egl)) {
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -133,7 +121,7 @@ bool wlr_egl_init(struct wlr_egl *egl, EGLenum platform,
|
|
|
|
goto error;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
egl->display = get_platform_display(platform, remote_display, NULL);
|
|
|
|
egl->display = egl->get_platform_display(platform, remote_display, NULL);
|
|
|
|
if (egl->display == EGL_NO_DISPLAY) {
|
|
|
|
if (egl->display == EGL_NO_DISPLAY) {
|
|
|
|
wlr_log(L_ERROR, "Failed to create EGL display: %s", egl_error());
|
|
|
|
wlr_log(L_ERROR, "Failed to create EGL display: %s", egl_error());
|
|
|
|
goto error;
|
|
|
|
goto error;
|
|
|
@ -168,19 +156,17 @@ bool wlr_egl_init(struct wlr_egl *egl, EGLenum platform,
|
|
|
|
goto error;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
eglCreateImageKHR = (PFNEGLCREATEIMAGEKHRPROC)
|
|
|
|
egl->eglCreateImageKHR = (PFNEGLCREATEIMAGEKHRPROC)
|
|
|
|
eglGetProcAddress("eglCreateImageKHR");
|
|
|
|
eglGetProcAddress("eglCreateImageKHR");
|
|
|
|
eglDestroyImageKHR = (PFNEGLDESTROYIMAGEKHRPROC)
|
|
|
|
egl->eglDestroyImageKHR = (PFNEGLDESTROYIMAGEKHRPROC)
|
|
|
|
eglGetProcAddress("eglDestroyImageKHR");
|
|
|
|
eglGetProcAddress("eglDestroyImageKHR");
|
|
|
|
eglQueryWaylandBufferWL = (PFNEGLQUERYWAYLANDBUFFERWL)
|
|
|
|
egl->eglQueryWaylandBufferWL = (PFNEGLQUERYWAYLANDBUFFERWL)
|
|
|
|
(void*) eglGetProcAddress("eglQueryWaylandBufferWL");
|
|
|
|
(void*) eglGetProcAddress("eglQueryWaylandBufferWL");
|
|
|
|
eglBindWaylandDisplayWL = (PFNEGLBINDWAYLANDDISPLAYWL)
|
|
|
|
egl->eglBindWaylandDisplayWL = (PFNEGLBINDWAYLANDDISPLAYWL)
|
|
|
|
(void*) eglGetProcAddress("eglBindWaylandDisplayWL");
|
|
|
|
(void*) eglGetProcAddress("eglBindWaylandDisplayWL");
|
|
|
|
eglUnbindWaylandDisplayWL = (PFNEGLUNBINDWAYLANDDISPLAYWL)
|
|
|
|
egl->eglUnbindWaylandDisplayWL = (PFNEGLUNBINDWAYLANDDISPLAYWL)
|
|
|
|
(void*) eglGetProcAddress("eglUnbindWaylandDisplayWL");
|
|
|
|
(void*) eglGetProcAddress("eglUnbindWaylandDisplayWL");
|
|
|
|
|
|
|
|
|
|
|
|
egl_global = egl;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
egl->gl_exts = (const char*) glGetString(GL_EXTENSIONS);
|
|
|
|
egl->gl_exts = (const char*) glGetString(GL_EXTENSIONS);
|
|
|
|
wlr_log(L_INFO, "Using EGL %d.%d", (int)major, (int)minor);
|
|
|
|
wlr_log(L_INFO, "Using EGL %d.%d", (int)major, (int)minor);
|
|
|
|
wlr_log(L_INFO, "Supported EGL extensions: %s", egl->egl_exts);
|
|
|
|
wlr_log(L_INFO, "Supported EGL extensions: %s", egl->egl_exts);
|
|
|
@ -196,25 +182,22 @@ error:
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void wlr_egl_free(struct wlr_egl *egl) {
|
|
|
|
void wlr_egl_free(struct wlr_egl *egl) {
|
|
|
|
if (egl->wl_display && eglUnbindWaylandDisplayWL) {
|
|
|
|
if (egl->wl_display && egl->eglUnbindWaylandDisplayWL) {
|
|
|
|
eglUnbindWaylandDisplayWL(egl->display, egl->wl_display);
|
|
|
|
egl->eglUnbindWaylandDisplayWL(egl->display, egl->wl_display);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
eglDestroyContext(egl->display, egl->context);
|
|
|
|
eglDestroyContext(egl->display, egl->context);
|
|
|
|
eglTerminate(egl->display);
|
|
|
|
eglTerminate(egl->display);
|
|
|
|
eglReleaseThread();
|
|
|
|
eglReleaseThread();
|
|
|
|
eglMakeCurrent(EGL_NO_DISPLAY, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
|
|
|
eglMakeCurrent(EGL_NO_DISPLAY, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
|
|
|
|
|
|
|
|
|
|
|
if (egl_global == egl)
|
|
|
|
|
|
|
|
egl_global = NULL;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool wlr_egl_bind_display(struct wlr_egl *egl, struct wl_display *local_display) {
|
|
|
|
bool wlr_egl_bind_display(struct wlr_egl *egl, struct wl_display *local_display) {
|
|
|
|
if (!eglBindWaylandDisplayWL) {
|
|
|
|
if (!egl->eglBindWaylandDisplayWL) {
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (eglBindWaylandDisplayWL(egl->display, local_display)) {
|
|
|
|
if (egl->eglBindWaylandDisplayWL(egl->display, local_display)) {
|
|
|
|
egl->wl_display = local_display;
|
|
|
|
egl->wl_display = local_display;
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -222,35 +205,35 @@ bool wlr_egl_bind_display(struct wlr_egl *egl, struct wl_display *local_display)
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool wlr_egl_query_buffer(struct wl_resource *buf, int attrib, int *value) {
|
|
|
|
bool wlr_egl_query_buffer(struct wlr_egl *egl, struct wl_resource *buf,
|
|
|
|
if (!egl_global || !eglQueryWaylandBufferWL) {
|
|
|
|
int attrib, int *value) {
|
|
|
|
|
|
|
|
if (!egl->eglQueryWaylandBufferWL) {
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return egl->eglQueryWaylandBufferWL(egl->display, buf, attrib, value);
|
|
|
|
return eglQueryWaylandBufferWL(egl_global->display, buf, attrib, value);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
EGLImage wlr_egl_create_image(EGLenum target,
|
|
|
|
EGLImage wlr_egl_create_image(struct wlr_egl *egl, EGLenum target,
|
|
|
|
EGLClientBuffer buffer, const EGLint *attribs) {
|
|
|
|
EGLClientBuffer buffer, const EGLint *attribs) {
|
|
|
|
if (!egl_global || !eglCreateImageKHR) {
|
|
|
|
if (!egl->eglCreateImageKHR) {
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return eglCreateImageKHR(egl_global->display, egl_global->context, target,
|
|
|
|
return egl->eglCreateImageKHR(egl->display, egl->context, target,
|
|
|
|
buffer, attribs);
|
|
|
|
buffer, attribs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool wlr_egl_destroy_image(EGLImage image) {
|
|
|
|
bool wlr_egl_destroy_image(struct wlr_egl *egl, EGLImage image) {
|
|
|
|
if (!egl_global || !eglDestroyImageKHR) {
|
|
|
|
if (!egl->eglDestroyImageKHR) {
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
eglDestroyImageKHR(egl_global->display, image);
|
|
|
|
egl->eglDestroyImageKHR(egl->display, image);
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
EGLSurface wlr_egl_create_surface(struct wlr_egl *egl, void *window) {
|
|
|
|
EGLSurface wlr_egl_create_surface(struct wlr_egl *egl, void *window) {
|
|
|
|
EGLSurface surf = create_platform_window_surface(egl->display, egl->config,
|
|
|
|
EGLSurface surf = egl->create_platform_window_surface(egl->display, egl->config,
|
|
|
|
window, NULL);
|
|
|
|
window, NULL);
|
|
|
|
if (surf == EGL_NO_SURFACE) {
|
|
|
|
if (surf == EGL_NO_SURFACE) {
|
|
|
|
wlr_log(L_ERROR, "Failed to create EGL surface: %s", egl_error());
|
|
|
|
wlr_log(L_ERROR, "Failed to create EGL surface: %s", egl_error());
|