#include "egl_dri2.h"
#include "GL/mesa_glinterop.h"
#include "loader/loader.h"
+#include "util/os_file.h"
#include "util/u_atomic.h"
#include "util/u_vector.h"
#include "mapi/glapi/glapi.h"
#define NUM_ATTRIBS 12
static const struct dri2_pbuffer_visual {
+ const char *format_name;
unsigned int dri_image_format;
int rgba_shifts[4];
unsigned int rgba_sizes[4];
} dri2_pbuffer_visuals[] = {
{
+ "ABGR16F",
__DRI_IMAGE_FORMAT_ABGR16161616F,
{ 0, 16, 32, 48 },
{ 16, 16, 16, 16 }
},
{
+ "XBGR16F",
__DRI_IMAGE_FORMAT_XBGR16161616F,
{ 0, 16, 32, -1 },
{ 16, 16, 16, 0 }
},
{
+ "A2RGB10",
__DRI_IMAGE_FORMAT_ARGB2101010,
{ 20, 10, 0, 30 },
{ 10, 10, 10, 2 }
},
{
+ "X2RGB10",
__DRI_IMAGE_FORMAT_XRGB2101010,
{ 20, 10, 0, -1 },
{ 10, 10, 10, 0 }
},
{
+ "ARGB8888",
__DRI_IMAGE_FORMAT_ARGB8888,
{ 16, 8, 0, 24 },
{ 8, 8, 8, 8 }
},
{
+ "RGB888",
__DRI_IMAGE_FORMAT_XRGB8888,
{ 16, 8, 0, -1 },
{ 8, 8, 8, 0 }
},
{
+ "RGB565",
__DRI_IMAGE_FORMAT_RGB565,
{ 11, 5, 0, -1 },
{ 5, 6, 5, 0 }
return conf;
}
+EGLBoolean
+dri2_add_pbuffer_configs_for_visuals(_EGLDriver *drv, _EGLDisplay *disp)
+{
+ struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+ unsigned int format_count[ARRAY_SIZE(dri2_pbuffer_visuals)] = { 0 };
+ unsigned int config_count = 0;
+
+ for (unsigned i = 0; dri2_dpy->driver_configs[i] != NULL; i++) {
+ for (unsigned j = 0; j < ARRAY_SIZE(dri2_pbuffer_visuals); j++) {
+ struct dri2_egl_config *dri2_conf;
+
+ dri2_conf = dri2_add_config(disp, dri2_dpy->driver_configs[i],
+ config_count + 1, EGL_PBUFFER_BIT, NULL,
+ dri2_pbuffer_visuals[j].rgba_shifts, dri2_pbuffer_visuals[j].rgba_sizes);
+
+ if (dri2_conf) {
+ if (dri2_conf->base.ConfigID == config_count + 1)
+ config_count++;
+ format_count[j]++;
+ }
+ }
+ }
+
+ for (unsigned i = 0; i < ARRAY_SIZE(format_count); i++) {
+ if (!format_count[i]) {
+ _eglLog(_EGL_DEBUG, "No DRI config supports native format %s",
+ dri2_pbuffer_visuals[i].format_name);
+ }
+ }
+
+ return (config_count != 0);
+}
+
__DRIimage *
dri2_lookup_egl_image(__DRIscreen *screen, void *image, void *data)
{
if (!extensions)
return EGL_FALSE;
- if (!dri2_bind_extensions(dri2_dpy, driver_extensions, extensions, false))
+ if (!dri2_bind_extensions(dri2_dpy, driver_extensions, extensions, false)) {
+ dlclose(dri2_dpy->driver);
+ dri2_dpy->driver = NULL;
return EGL_FALSE;
-
+ }
dri2_dpy->driver_extensions = extensions;
dri2_bind_extensions(dri2_dpy, optional_driver_extensions, extensions, true);
if (dri2_dpy->image->base.version >= 8 &&
dri2_dpy->image->createImageFromDmaBufs) {
disp->Extensions.EXT_image_dma_buf_import = EGL_TRUE;
- }
- if (dri2_dpy->image->base.version >= 15 &&
- dri2_dpy->image->createImageFromDmaBufs2 &&
- dri2_dpy->image->queryDmaBufFormats &&
- dri2_dpy->image->queryDmaBufModifiers) {
disp->Extensions.EXT_image_dma_buf_import_modifiers = EGL_TRUE;
}
#endif
}
/**
- * Called via eglInitialize(), GLX_drv->API.Initialize().
+ * Called via eglInitialize(), drv->Initialize().
*
* This must be guaranteed to be called exactly once, even if eglInitialize is
* called many times (without a eglTerminate in between).
}
/**
- * Called via eglTerminate(), drv->API.Terminate().
+ * Called via eglTerminate(), drv->Terminate().
*
* This must be guaranteed to be called exactly once, even if eglTerminate is
* called many times (without a eglInitialize in between).
}
/**
- * Called via eglCreateContext(), drv->API.CreateContext().
+ * Called via eglCreateContext(), drv->CreateContext().
*/
static _EGLContext *
dri2_create_context(_EGLDriver *drv, _EGLDisplay *disp, _EGLConfig *conf,
}
/**
- * Called via eglDestroyContext(), drv->API.DestroyContext().
+ * Called via eglDestroyContext(), drv->DestroyContext().
*/
static EGLBoolean
dri2_destroy_context(_EGLDriver *drv, _EGLDisplay *disp, _EGLContext *ctx)
}
/**
- * Called via eglMakeCurrent(), drv->API.MakeCurrent().
+ * Called via eglMakeCurrent(), drv->MakeCurrent().
*/
static EGLBoolean
dri2_make_current(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *dsurf,
_EGLSurface *tmp_dsurf, *tmp_rsurf;
__DRIdrawable *ddraw, *rdraw;
__DRIcontext *cctx;
- EGLBoolean unbind;
if (!dri2_dpy)
return _eglError(EGL_NOT_INITIALIZED, "eglMakeCurrent");
- /* make new bindings */
- if (!_eglBindContext(ctx, dsurf, rsurf, &old_ctx, &old_dsurf, &old_rsurf)) {
- /* _eglBindContext already sets the EGL error (in _eglCheckMakeCurrent) */
+ /* make new bindings, set the EGL error otherwise */
+ if (!_eglBindContext(ctx, dsurf, rsurf, &old_ctx, &old_dsurf, &old_rsurf))
return EGL_FALSE;
- }
if (old_ctx) {
+ __DRIcontext *old_cctx = dri2_egl_context(old_ctx)->dri_context;
old_disp = old_ctx->Resource.Display;
old_dri2_dpy = dri2_egl_display(old_disp);
- }
- /* flush before context switch */
- if (old_ctx)
+ /* flush before context switch */
dri2_gl_flush();
- ddraw = (dsurf) ? dri2_dpy->vtbl->get_dri_drawable(dsurf) : NULL;
- rdraw = (rsurf) ? dri2_dpy->vtbl->get_dri_drawable(rsurf) : NULL;
- cctx = (dri2_ctx) ? dri2_ctx->dri_context : NULL;
-
- if (old_ctx) {
- __DRIcontext *old_cctx = dri2_egl_context(old_ctx)->dri_context;
-
if (old_dsurf)
dri2_surf_update_fence_fd(old_ctx, disp, old_dsurf);
dri2_dpy->core->unbindContext(old_cctx);
}
- unbind = (cctx == NULL && ddraw == NULL && rdraw == NULL);
+ ddraw = (dsurf) ? dri2_dpy->vtbl->get_dri_drawable(dsurf) : NULL;
+ rdraw = (rsurf) ? dri2_dpy->vtbl->get_dri_drawable(rsurf) : NULL;
+ cctx = (dri2_ctx) ? dri2_ctx->dri_context : NULL;
- if (!unbind && !dri2_dpy->core->bindContext(cctx, ddraw, rdraw)) {
- /* undo the previous _eglBindContext */
- _eglBindContext(old_ctx, old_dsurf, old_rsurf, &ctx, &tmp_dsurf, &tmp_rsurf);
- assert(&dri2_ctx->base == ctx &&
- tmp_dsurf == dsurf &&
- tmp_rsurf == rsurf);
+ if (cctx || ddraw || rdraw) {
+ if (!dri2_dpy->core->bindContext(cctx, ddraw, rdraw)) {
+ /* undo the previous _eglBindContext */
+ _eglBindContext(old_ctx, old_dsurf, old_rsurf, &ctx, &tmp_dsurf, &tmp_rsurf);
+ assert(&dri2_ctx->base == ctx &&
+ tmp_dsurf == dsurf &&
+ tmp_rsurf == rsurf);
+
+ if (old_dsurf && _eglSurfaceInSharedBufferMode(old_dsurf) &&
+ old_dri2_dpy->vtbl->set_shared_buffer_mode) {
+ old_dri2_dpy->vtbl->set_shared_buffer_mode(old_disp, old_dsurf, true);
+ }
- if (old_dsurf && _eglSurfaceInSharedBufferMode(old_dsurf) &&
- old_dri2_dpy->vtbl->set_shared_buffer_mode) {
- old_dri2_dpy->vtbl->set_shared_buffer_mode(old_disp, old_dsurf, true);
- }
+ _eglPutSurface(dsurf);
+ _eglPutSurface(rsurf);
+ _eglPutContext(ctx);
- _eglPutSurface(dsurf);
- _eglPutSurface(rsurf);
- _eglPutContext(ctx);
+ _eglPutSurface(old_dsurf);
+ _eglPutSurface(old_rsurf);
+ _eglPutContext(old_ctx);
- _eglPutSurface(old_dsurf);
- _eglPutSurface(old_rsurf);
- _eglPutContext(old_ctx);
+ /* dri2_dpy->core->bindContext failed. We cannot tell for sure why, but
+ * setting the error to EGL_BAD_MATCH is surely better than leaving it
+ * as EGL_SUCCESS.
+ */
+ return _eglError(EGL_BAD_MATCH, "eglMakeCurrent");
+ }
- /* dri2_dpy->core->bindContext failed. We cannot tell for sure why, but
- * setting the error to EGL_BAD_MATCH is surely better than leaving it
- * as EGL_SUCCESS.
- */
- return _eglError(EGL_BAD_MATCH, "eglMakeCurrent");
+ dri2_dpy->ref_count++;
}
dri2_destroy_surface(drv, disp, old_dsurf);
dri2_destroy_surface(drv, disp, old_rsurf);
- if (!unbind)
- dri2_dpy->ref_count++;
-
if (old_ctx) {
dri2_destroy_context(drv, disp, old_ctx);
dri2_display_release(old_disp);
}
/*
- * Called from eglGetProcAddress() via drv->API.GetProcAddress().
+ * Called from eglGetProcAddress() via drv->GetProcAddress().
*/
static _EGLProc
dri2_get_proc_address(_EGLDriver *drv, const char *procname)
const EGLint *attrib_list)
{
struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+ if (!dri2_dpy->vtbl->create_pixmap_surface)
+ return NULL;
return dri2_dpy->vtbl->create_pixmap_surface(drv, disp, conf, native_pixmap,
attrib_list);
}
_EGLConfig *conf, const EGLint *attrib_list)
{
struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+ if (!dri2_dpy->vtbl->create_pbuffer_surface)
+ return NULL;
return dri2_dpy->vtbl->create_pbuffer_surface(drv, disp, conf, attrib_list);
}
if (ctx && surf)
dri2_surf_update_fence_fd(ctx, disp, surf);
- ret = dri2_dpy->vtbl->swap_buffers_with_damage(drv, disp, surf,
- rects, n_rects);
+ if (dri2_dpy->vtbl->swap_buffers_with_damage)
+ ret = dri2_dpy->vtbl->swap_buffers_with_damage(drv, disp, surf,
+ rects, n_rects);
+ else
+ ret = dri2_dpy->vtbl->swap_buffers(drv, disp, surf);
/* SwapBuffers marks the end of the frame; reset the damage region for
* use again next time.
__DRIdrawable *dri_drawable = dri2_dpy->vtbl->get_dri_drawable(surf);
EGLBoolean ret;
+ if (!dri2_dpy->vtbl->swap_buffers_region)
+ return EGL_FALSE;
ret = dri2_dpy->vtbl->swap_buffers_region(drv, disp, surf, numRects, rects);
/* SwapBuffers marks the end of the frame; reset the damage region for
EGLint x, EGLint y, EGLint width, EGLint height)
{
struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+ if (!dri2_dpy->vtbl->post_sub_buffer)
+ return EGL_FALSE;
return dri2_dpy->vtbl->post_sub_buffer(drv, disp, surf, x, y, width, height);
}
void *native_pixmap_target)
{
struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+ if (!dri2_dpy->vtbl->copy_buffers)
+ return _eglError(EGL_BAD_NATIVE_PIXMAP, "no support for native pixmaps");
return dri2_dpy->vtbl->copy_buffers(drv, disp, surf, native_pixmap_target);
}
dri2_query_buffer_age(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf)
{
struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+ if (!dri2_dpy->vtbl->query_buffer_age)
+ return 0;
return dri2_dpy->vtbl->query_buffer_age(drv, disp, surf);
}
EGLuint64KHR *sbc)
{
struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+ if (!dri2_dpy->vtbl->get_sync_values)
+ return EGL_FALSE;
return dri2_dpy->vtbl->get_sync_values(disp, surf, ust, msc, sbc);
}
_EGLImage *img)
{
struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+ if (!dri2_dpy->vtbl->create_wayland_buffer_from_image)
+ return NULL;
return dri2_dpy->vtbl->create_wayland_buffer_from_image(drv, disp, img);
}
return EGL_NO_NATIVE_FENCE_FD_ANDROID;
}
- return dup(sync->SyncFd);
+ return os_dupfd_cloexec(sync->SyncFd);
}
static void
void
_eglInitDriver(_EGLDriver *dri2_drv)
{
- dri2_drv->API.Initialize = dri2_initialize;
- dri2_drv->API.Terminate = dri2_terminate;
- dri2_drv->API.CreateContext = dri2_create_context;
- dri2_drv->API.DestroyContext = dri2_destroy_context;
- dri2_drv->API.MakeCurrent = dri2_make_current;
- dri2_drv->API.CreateWindowSurface = dri2_create_window_surface;
- dri2_drv->API.CreatePixmapSurface = dri2_create_pixmap_surface;
- dri2_drv->API.CreatePbufferSurface = dri2_create_pbuffer_surface;
- dri2_drv->API.DestroySurface = dri2_destroy_surface;
- dri2_drv->API.GetProcAddress = dri2_get_proc_address;
- dri2_drv->API.WaitClient = dri2_wait_client;
- dri2_drv->API.WaitNative = dri2_wait_native;
- dri2_drv->API.BindTexImage = dri2_bind_tex_image;
- dri2_drv->API.ReleaseTexImage = dri2_release_tex_image;
- dri2_drv->API.SwapInterval = dri2_swap_interval;
- dri2_drv->API.SwapBuffers = dri2_swap_buffers;
- dri2_drv->API.SwapBuffersWithDamageEXT = dri2_swap_buffers_with_damage;
- dri2_drv->API.SwapBuffersRegionNOK = dri2_swap_buffers_region;
- dri2_drv->API.SetDamageRegion = dri2_set_damage_region;
- dri2_drv->API.PostSubBufferNV = dri2_post_sub_buffer;
- dri2_drv->API.CopyBuffers = dri2_copy_buffers,
- dri2_drv->API.QueryBufferAge = dri2_query_buffer_age;
- dri2_drv->API.CreateImageKHR = dri2_create_image;
- dri2_drv->API.DestroyImageKHR = dri2_destroy_image_khr;
- dri2_drv->API.CreateWaylandBufferFromImageWL = dri2_create_wayland_buffer_from_image;
- dri2_drv->API.QuerySurface = dri2_query_surface;
- dri2_drv->API.QueryDriverName = dri2_query_driver_name;
- dri2_drv->API.QueryDriverConfig = dri2_query_driver_config;
+ dri2_drv->Initialize = dri2_initialize;
+ dri2_drv->Terminate = dri2_terminate;
+ dri2_drv->CreateContext = dri2_create_context;
+ dri2_drv->DestroyContext = dri2_destroy_context;
+ dri2_drv->MakeCurrent = dri2_make_current;
+ dri2_drv->CreateWindowSurface = dri2_create_window_surface;
+ dri2_drv->CreatePixmapSurface = dri2_create_pixmap_surface;
+ dri2_drv->CreatePbufferSurface = dri2_create_pbuffer_surface;
+ dri2_drv->DestroySurface = dri2_destroy_surface;
+ dri2_drv->GetProcAddress = dri2_get_proc_address;
+ dri2_drv->WaitClient = dri2_wait_client;
+ dri2_drv->WaitNative = dri2_wait_native;
+ dri2_drv->BindTexImage = dri2_bind_tex_image;
+ dri2_drv->ReleaseTexImage = dri2_release_tex_image;
+ dri2_drv->SwapInterval = dri2_swap_interval;
+ dri2_drv->SwapBuffers = dri2_swap_buffers;
+ dri2_drv->SwapBuffersWithDamageEXT = dri2_swap_buffers_with_damage;
+ dri2_drv->SwapBuffersRegionNOK = dri2_swap_buffers_region;
+ dri2_drv->SetDamageRegion = dri2_set_damage_region;
+ dri2_drv->PostSubBufferNV = dri2_post_sub_buffer;
+ dri2_drv->CopyBuffers = dri2_copy_buffers,
+ dri2_drv->QueryBufferAge = dri2_query_buffer_age;
+ dri2_drv->CreateImageKHR = dri2_create_image;
+ dri2_drv->DestroyImageKHR = dri2_destroy_image_khr;
+ dri2_drv->CreateWaylandBufferFromImageWL = dri2_create_wayland_buffer_from_image;
+ dri2_drv->QuerySurface = dri2_query_surface;
+ dri2_drv->QueryDriverName = dri2_query_driver_name;
+ dri2_drv->QueryDriverConfig = dri2_query_driver_config;
#ifdef HAVE_LIBDRM
- dri2_drv->API.CreateDRMImageMESA = dri2_create_drm_image_mesa;
- dri2_drv->API.ExportDRMImageMESA = dri2_export_drm_image_mesa;
- dri2_drv->API.ExportDMABUFImageQueryMESA = dri2_export_dma_buf_image_query_mesa;
- dri2_drv->API.ExportDMABUFImageMESA = dri2_export_dma_buf_image_mesa;
- dri2_drv->API.QueryDmaBufFormatsEXT = dri2_query_dma_buf_formats;
- dri2_drv->API.QueryDmaBufModifiersEXT = dri2_query_dma_buf_modifiers;
+ dri2_drv->CreateDRMImageMESA = dri2_create_drm_image_mesa;
+ dri2_drv->ExportDRMImageMESA = dri2_export_drm_image_mesa;
+ dri2_drv->ExportDMABUFImageQueryMESA = dri2_export_dma_buf_image_query_mesa;
+ dri2_drv->ExportDMABUFImageMESA = dri2_export_dma_buf_image_mesa;
+ dri2_drv->QueryDmaBufFormatsEXT = dri2_query_dma_buf_formats;
+ dri2_drv->QueryDmaBufModifiersEXT = dri2_query_dma_buf_modifiers;
#endif
#ifdef HAVE_WAYLAND_PLATFORM
- dri2_drv->API.BindWaylandDisplayWL = dri2_bind_wayland_display_wl;
- dri2_drv->API.UnbindWaylandDisplayWL = dri2_unbind_wayland_display_wl;
- dri2_drv->API.QueryWaylandBufferWL = dri2_query_wayland_buffer_wl;
+ dri2_drv->BindWaylandDisplayWL = dri2_bind_wayland_display_wl;
+ dri2_drv->UnbindWaylandDisplayWL = dri2_unbind_wayland_display_wl;
+ dri2_drv->QueryWaylandBufferWL = dri2_query_wayland_buffer_wl;
#endif
- dri2_drv->API.GetSyncValuesCHROMIUM = dri2_get_sync_values_chromium;
- dri2_drv->API.CreateSyncKHR = dri2_create_sync;
- dri2_drv->API.ClientWaitSyncKHR = dri2_client_wait_sync;
- dri2_drv->API.SignalSyncKHR = dri2_signal_sync;
- dri2_drv->API.WaitSyncKHR = dri2_server_wait_sync;
- dri2_drv->API.DestroySyncKHR = dri2_destroy_sync;
- dri2_drv->API.GLInteropQueryDeviceInfo = dri2_interop_query_device_info;
- dri2_drv->API.GLInteropExportObject = dri2_interop_export_object;
- dri2_drv->API.DupNativeFenceFDANDROID = dri2_dup_native_fence_fd;
- dri2_drv->API.SetBlobCacheFuncsANDROID = dri2_set_blob_cache_funcs;
+ dri2_drv->GetSyncValuesCHROMIUM = dri2_get_sync_values_chromium;
+ dri2_drv->CreateSyncKHR = dri2_create_sync;
+ dri2_drv->ClientWaitSyncKHR = dri2_client_wait_sync;
+ dri2_drv->SignalSyncKHR = dri2_signal_sync;
+ dri2_drv->WaitSyncKHR = dri2_server_wait_sync;
+ dri2_drv->DestroySyncKHR = dri2_destroy_sync;
+ dri2_drv->GLInteropQueryDeviceInfo = dri2_interop_query_device_info;
+ dri2_drv->GLInteropExportObject = dri2_interop_export_object;
+ dri2_drv->DupNativeFenceFDANDROID = dri2_dup_native_fence_fd;
+ dri2_drv->SetBlobCacheFuncsANDROID = dri2_set_blob_cache_funcs;
}