Merge pull request #1052 from VincentVanlaer/egl-damage-khr

Split eglSwapBuffersWithDamage feature detection
This commit is contained in:
Drew DeVault 2018-06-09 10:19:40 -07:00 committed by GitHub
commit 9a1f0e2d5f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 29 deletions

View File

@ -16,12 +16,13 @@ struct wlr_egl {
const char *exts_str; const char *exts_str;
struct { struct {
bool bind_wayland_display; bool bind_wayland_display_wl;
bool buffer_age; bool buffer_age_ext;
bool dmabuf_import_modifiers; bool image_dmabuf_import_modifiers_ext;
bool dmabuf_import; bool image_dmabuf_import_ext;
bool image_base; bool image_base_khr;
bool swap_buffers_with_damage; bool swap_buffers_with_damage_ext;
bool swap_buffers_with_damage_khr;
} exts; } exts;
struct wl_display *wl_display; struct wl_display *wl_display;

View File

@ -77,7 +77,7 @@ static bool check_egl_ext(const char *exts, const char *ext) {
static void print_dmabuf_formats(struct wlr_egl *egl) { static void print_dmabuf_formats(struct wlr_egl *egl) {
/* Avoid log msg if extension is not present */ /* Avoid log msg if extension is not present */
if (!egl->exts.dmabuf_import_modifiers) { if (!egl->exts.image_dmabuf_import_modifiers_ext) {
return; return;
} }
@ -146,26 +146,27 @@ bool wlr_egl_init(struct wlr_egl *egl, EGLenum platform, void *remote_display,
wlr_log(L_INFO, "Supported EGL extensions: %s", egl->exts_str); wlr_log(L_INFO, "Supported EGL extensions: %s", egl->exts_str);
wlr_log(L_INFO, "EGL vendor: %s", eglQueryString(egl->display, EGL_VENDOR)); wlr_log(L_INFO, "EGL vendor: %s", eglQueryString(egl->display, EGL_VENDOR));
egl->exts.image_base = egl->exts.image_base_khr =
check_egl_ext(egl->exts_str, "EGL_KHR_image_base") check_egl_ext(egl->exts_str, "EGL_KHR_image_base")
&& eglCreateImageKHR && eglDestroyImageKHR; && eglCreateImageKHR && eglDestroyImageKHR;
egl->exts.buffer_age = egl->exts.buffer_age_ext =
check_egl_ext(egl->exts_str, "EGL_EXT_buffer_age"); check_egl_ext(egl->exts_str, "EGL_EXT_buffer_age");
egl->exts.swap_buffers_with_damage = egl->exts.swap_buffers_with_damage_ext =
(check_egl_ext(egl->exts_str, "EGL_EXT_swap_buffers_with_damage") && (check_egl_ext(egl->exts_str, "EGL_EXT_swap_buffers_with_damage") &&
eglSwapBuffersWithDamageEXT) || eglSwapBuffersWithDamageEXT);
egl->exts.swap_buffers_with_damage_khr =
(check_egl_ext(egl->exts_str, "EGL_KHR_swap_buffers_with_damage") && (check_egl_ext(egl->exts_str, "EGL_KHR_swap_buffers_with_damage") &&
eglSwapBuffersWithDamageKHR); eglSwapBuffersWithDamageKHR);
egl->exts.dmabuf_import = egl->exts.image_dmabuf_import_ext =
check_egl_ext(egl->exts_str, "EGL_EXT_image_dma_buf_import"); check_egl_ext(egl->exts_str, "EGL_EXT_image_dma_buf_import");
egl->exts.dmabuf_import_modifiers = egl->exts.image_dmabuf_import_modifiers_ext =
check_egl_ext(egl->exts_str, "EGL_EXT_image_dma_buf_import_modifiers") check_egl_ext(egl->exts_str, "EGL_EXT_image_dma_buf_import_modifiers")
&& eglQueryDmaBufFormatsEXT && eglQueryDmaBufModifiersEXT; && eglQueryDmaBufFormatsEXT && eglQueryDmaBufModifiersEXT;
print_dmabuf_formats(egl); print_dmabuf_formats(egl);
egl->exts.bind_wayland_display = egl->exts.bind_wayland_display_wl =
check_egl_ext(egl->exts_str, "EGL_WL_bind_wayland_display") check_egl_ext(egl->exts_str, "EGL_WL_bind_wayland_display")
&& eglBindWaylandDisplayWL && eglUnbindWaylandDisplayWL && eglBindWaylandDisplayWL && eglUnbindWaylandDisplayWL
&& eglQueryWaylandBufferWL; && eglQueryWaylandBufferWL;
@ -234,7 +235,7 @@ void wlr_egl_finish(struct wlr_egl *egl) {
eglMakeCurrent(egl->display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); eglMakeCurrent(egl->display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
if (egl->wl_display) { if (egl->wl_display) {
assert(egl->exts.bind_wayland_display); assert(egl->exts.bind_wayland_display_wl);
eglUnbindWaylandDisplayWL(egl->display, egl->wl_display); eglUnbindWaylandDisplayWL(egl->display, egl->wl_display);
} }
@ -244,7 +245,7 @@ void wlr_egl_finish(struct wlr_egl *egl) {
} }
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 (!egl->exts.bind_wayland_display) { if (!egl->exts.bind_wayland_display_wl) {
return false; return false;
} }
@ -257,7 +258,7 @@ bool wlr_egl_bind_display(struct wlr_egl *egl, struct wl_display *local_display)
} }
bool wlr_egl_destroy_image(struct wlr_egl *egl, EGLImage image) { bool wlr_egl_destroy_image(struct wlr_egl *egl, EGLImage image) {
if (!egl->exts.image_base) { if (!egl->exts.image_base_khr) {
return false; return false;
} }
if (!image) { if (!image) {
@ -278,7 +279,7 @@ EGLSurface wlr_egl_create_surface(struct wlr_egl *egl, void *window) {
} }
static int egl_get_buffer_age(struct wlr_egl *egl, EGLSurface surface) { static int egl_get_buffer_age(struct wlr_egl *egl, EGLSurface surface) {
if (!egl->exts.buffer_age) { if (!egl->exts.buffer_age_ext) {
return -1; return -1;
} }
@ -313,7 +314,8 @@ bool wlr_egl_is_current(struct wlr_egl *egl) {
bool wlr_egl_swap_buffers(struct wlr_egl *egl, EGLSurface surface, bool wlr_egl_swap_buffers(struct wlr_egl *egl, EGLSurface surface,
pixman_region32_t *damage) { pixman_region32_t *damage) {
EGLBoolean ret; EGLBoolean ret;
if (damage != NULL && egl->exts.swap_buffers_with_damage) { if (damage != NULL && (egl->exts.swap_buffers_with_damage_ext ||
egl->exts.swap_buffers_with_damage_khr)) {
int nrects; int nrects;
pixman_box32_t *rects = pixman_box32_t *rects =
pixman_region32_rectangles(damage, &nrects); pixman_region32_rectangles(damage, &nrects);
@ -325,8 +327,7 @@ bool wlr_egl_swap_buffers(struct wlr_egl *egl, EGLSurface surface,
egl_damage[4*i + 3] = rects[i].y2 - rects[i].y1; egl_damage[4*i + 3] = rects[i].y2 - rects[i].y1;
} }
assert(eglSwapBuffersWithDamageEXT || eglSwapBuffersWithDamageKHR); if (egl->exts.swap_buffers_with_damage_ext) {
if (eglSwapBuffersWithDamageEXT) {
ret = eglSwapBuffersWithDamageEXT(egl->display, surface, egl_damage, ret = eglSwapBuffersWithDamageEXT(egl->display, surface, egl_damage,
nrects); nrects);
} else { } else {
@ -347,7 +348,7 @@ bool wlr_egl_swap_buffers(struct wlr_egl *egl, EGLSurface surface,
EGLImageKHR wlr_egl_create_image_from_wl_drm(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, struct wl_resource *data, EGLint *fmt, int *width, int *height,
bool *inverted_y) { bool *inverted_y) {
if (!egl->exts.bind_wayland_display || !egl->exts.image_base) { if (!egl->exts.bind_wayland_display_wl || !egl->exts.image_base_khr) {
return NULL; return NULL;
} }
@ -376,13 +377,13 @@ EGLImageKHR wlr_egl_create_image_from_wl_drm(struct wlr_egl *egl,
EGLImageKHR wlr_egl_create_image_from_dmabuf(struct wlr_egl *egl, EGLImageKHR wlr_egl_create_image_from_dmabuf(struct wlr_egl *egl,
struct wlr_dmabuf_attributes *attributes) { struct wlr_dmabuf_attributes *attributes) {
if (!egl->exts.image_base) { if (!egl->exts.image_base_khr) {
return NULL; return NULL;
} }
bool has_modifier = false; bool has_modifier = false;
if (attributes->modifier != DRM_FORMAT_MOD_INVALID) { if (attributes->modifier != DRM_FORMAT_MOD_INVALID) {
if (!egl->exts.dmabuf_import_modifiers) { if (!egl->exts.image_dmabuf_import_modifiers_ext) {
return NULL; return NULL;
} }
has_modifier = true; has_modifier = true;
@ -454,8 +455,8 @@ EGLImageKHR wlr_egl_create_image_from_dmabuf(struct wlr_egl *egl,
int wlr_egl_get_dmabuf_formats(struct wlr_egl *egl, int wlr_egl_get_dmabuf_formats(struct wlr_egl *egl,
int **formats) { int **formats) {
if (!egl->exts.dmabuf_import || if (!egl->exts.image_dmabuf_import_ext ||
!egl->exts.dmabuf_import_modifiers) { !egl->exts.image_dmabuf_import_modifiers_ext) {
wlr_log(L_DEBUG, "dmabuf extension not present"); wlr_log(L_DEBUG, "dmabuf extension not present");
return -1; return -1;
} }
@ -482,8 +483,8 @@ int wlr_egl_get_dmabuf_formats(struct wlr_egl *egl,
int wlr_egl_get_dmabuf_modifiers(struct wlr_egl *egl, int wlr_egl_get_dmabuf_modifiers(struct wlr_egl *egl,
int format, uint64_t **modifiers) { int format, uint64_t **modifiers) {
if (!egl->exts.dmabuf_import || if (!egl->exts.image_dmabuf_import_ext ||
!egl->exts.dmabuf_import_modifiers) { !egl->exts.image_dmabuf_import_modifiers_ext) {
wlr_log(L_DEBUG, "dmabuf extension not present"); wlr_log(L_DEBUG, "dmabuf extension not present");
return -1; return -1;
} }

View File

@ -210,7 +210,7 @@ struct wlr_texture *wlr_gles2_texture_from_dmabuf(struct wlr_egl *egl,
return NULL; return NULL;
} }
if (!egl->exts.dmabuf_import) { if (!egl->exts.image_dmabuf_import_ext) {
wlr_log(L_ERROR, "Cannot create DMA-BUF texture: EGL extension " wlr_log(L_ERROR, "Cannot create DMA-BUF texture: EGL extension "
"unavailable"); "unavailable");
return NULL; return NULL;