render/egl: add wlr_egl_create_image_from_wl_drm

This allows external renderers and potential future GL-based
renderers to re-use this function.
This commit is contained in:
emersion 2018-03-31 23:20:00 -04:00
parent b60e31e5c0
commit a7bb48b404
No known key found for this signature in database
GPG key ID: 0FDE7BE0E88F5E48
4 changed files with 64 additions and 47 deletions

View file

@ -93,7 +93,8 @@ static void print_dmabuf_formats(struct wlr_egl *egl) {
char str_formats[num * 5 + 1];
for (int i = 0; i < num; i++) {
snprintf(&str_formats[i*5], (num - i) * 5 + 1, "%.4s ", (char*)&formats[i]);
snprintf(&str_formats[i*5], (num - i) * 5 + 1, "%.4s ",
(char*)&formats[i]);
}
wlr_log(L_DEBUG, "Supported dmabuf buffer formats: %s", str_formats);
free(formats);
@ -230,8 +231,9 @@ bool wlr_egl_destroy_image(struct wlr_egl *egl, EGLImage image) {
}
EGLSurface wlr_egl_create_surface(struct wlr_egl *egl, void *window) {
EGLSurface surf = eglCreatePlatformWindowSurfaceEXT(egl->display, egl->config,
window, NULL);
assert(eglCreatePlatformWindowSurfaceEXT);
EGLSurface surf = eglCreatePlatformWindowSurfaceEXT(egl->display,
egl->config, window, NULL);
if (surf == EGL_NO_SURFACE) {
wlr_log(L_ERROR, "Failed to create EGL surface");
return EGL_NO_SURFACE;
@ -302,7 +304,37 @@ bool wlr_egl_swap_buffers(struct wlr_egl *egl, EGLSurface surface,
return true;
}
EGLImage wlr_egl_create_image_from_dmabuf(struct wlr_egl *egl,
EGLImageKHR wlr_egl_create_image_from_wl_drm(struct wlr_egl *egl,
struct wl_resource *data, EGLint *fmt, int *width, int *height,
bool *inverted_y) {
if (!eglQueryWaylandBufferWL || !eglCreateImageKHR) {
return NULL;
}
if (!eglQueryWaylandBufferWL(egl->display, data, EGL_TEXTURE_FORMAT, fmt)) {
return NULL;
}
eglQueryWaylandBufferWL(egl->display, data, EGL_WIDTH, width);
eglQueryWaylandBufferWL(egl->display, data, EGL_HEIGHT, height);
EGLint _inverted_y;
if (eglQueryWaylandBufferWL(egl->display, data, EGL_WAYLAND_Y_INVERTED_WL,
&_inverted_y)) {
*inverted_y = !!_inverted_y;
} else {
*inverted_y = false;
}
const EGLint attribs[] = {
EGL_WAYLAND_PLANE_WL, 0,
EGL_NONE,
};
return eglCreateImageKHR(egl->display, egl->context, EGL_WAYLAND_BUFFER_WL,
data, attribs);
}
EGLImageKHR wlr_egl_create_image_from_dmabuf(struct wlr_egl *egl,
struct wlr_dmabuf_buffer_attribs *attributes) {
bool has_modifier = false;
if (attributes->modifier[0] != DRM_FORMAT_MOD_INVALID) {