#endif
#include "egl_dri2.h"
+#include "loader/loader.h"
#include "util/u_atomic.h"
/* The kernel header drm_fourcc.h defines the DRM formats below. We duplicate
return NULL;
break;
+ case __DRI_ATTRIB_MAX_PBUFFER_WIDTH:
+ _eglSetConfigKey(&base, EGL_MAX_PBUFFER_WIDTH,
+ _EGL_MAX_PBUFFER_WIDTH);
+ break;
+ case __DRI_ATTRIB_MAX_PBUFFER_HEIGHT:
+ _eglSetConfigKey(&base, EGL_MAX_PBUFFER_HEIGHT,
+ _EGL_MAX_PBUFFER_HEIGHT);
+ break;
+
default:
key = dri2_to_egl_attribute_map[attrib];
if (key != 0)
*(const __DRIextension **) field = extensions[i];
_eglLog(_EGL_INFO, "found extension %s version %d",
extensions[i]->name, extensions[i]->version);
+ break;
}
}
}
_eglLog(_EGL_DEBUG, "DRI2: dlopen(%s)", path);
- if (asprintf(&get_extensions_name, "%s_%s",
- __DRI_DRIVER_GET_EXTENSIONS, dri2_dpy->driver_name) != -1) {
+ get_extensions_name = loader_get_extensions_name(dri2_dpy->driver_name);
+ if (get_extensions_name) {
get_extensions = dlsym(dri2_dpy->driver, get_extensions_name);
if (get_extensions) {
extensions = get_extensions();
disp->Extensions.KHR_wait_sync = EGL_TRUE;
if (dri2_dpy->fence->get_fence_from_cl_event)
disp->Extensions.KHR_cl_event2 = EGL_TRUE;
+ if (dri2_dpy->fence->base.version >= 2) {
+ unsigned capabilities =
+ dri2_dpy->fence->get_capabilities(dri2_dpy->dri_screen);
+ disp->Extensions.ANDROID_native_fence_sync =
+ (capabilities & __DRI_FENCE_CAP_NATIVE_FD) != 0;
+ }
}
disp->Extensions.KHR_reusable_sync = EGL_TRUE;
struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx);
_EGLContext *old_ctx;
- _EGLDisplay *old_disp = NULL;
_EGLSurface *old_dsurf, *old_rsurf;
_EGLSurface *tmp_dsurf, *tmp_rsurf;
__DRIdrawable *ddraw, *rdraw;
__DRIcontext *cctx;
+ EGLBoolean unbind;
if (!dri2_dpy)
return _eglError(EGL_NOT_INITIALIZED, "eglMakeCurrent");
return EGL_FALSE;
}
+ /* flush before context switch */
+ if (old_ctx)
+ dri2_drv->glFlush();
+
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;
-
- /* flush before context switch */
- dri2_drv->glFlush();
dri2_dpy->core->unbindContext(old_cctx);
-
- /* Keep track of the old dpy as we'll need it for resource cleanup */
- old_disp = old_ctx->Resource.Display;
}
- /* Bind if at least one of the primitives is valid ... */
- 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);
+ unbind = (cctx == NULL && ddraw == NULL && rdraw == NULL);
- _eglPutSurface(dsurf);
- _eglPutSurface(rsurf);
- _eglPutContext(ctx);
+ if (unbind || dri2_dpy->core->bindContext(cctx, ddraw, rdraw)) {
+ dri2_destroy_surface(drv, disp, old_dsurf);
+ dri2_destroy_surface(drv, disp, old_rsurf);
- _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");
+ if (!unbind)
+ dri2_dpy->ref_count++;
+ if (old_ctx) {
+ EGLDisplay old_disp = _eglGetDisplayHandle(old_ctx->Resource.Display);
+ dri2_destroy_context(drv, disp, old_ctx);
+ dri2_display_release(old_disp);
}
- /* ... and refcount the dpy when successful. */
- dri2_dpy->ref_count++;
+ return EGL_TRUE;
+ } else {
+ /* 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);
+
+ _eglPutSurface(dsurf);
+ _eglPutSurface(rsurf);
+ _eglPutContext(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_destroy_surface(drv, disp, old_dsurf);
- dri2_destroy_surface(drv, disp, old_rsurf);
- dri2_destroy_context(drv, disp, old_ctx);
- dri2_display_release(old_disp);
-
- return EGL_TRUE;
}
__DRIdrawable *
struct dri2_egl_sync *dri2_sync)
{
if (p_atomic_dec_zero(&dri2_sync->refcount)) {
- if (dri2_sync->base.Type == EGL_SYNC_REUSABLE_KHR)
+ switch (dri2_sync->base.Type) {
+ case EGL_SYNC_REUSABLE_KHR:
cnd_destroy(&dri2_sync->cond);
+ break;
+ case EGL_SYNC_NATIVE_FENCE_ANDROID:
+ if (dri2_sync->base.SyncFd != EGL_NO_NATIVE_FENCE_FD_ANDROID)
+ close(dri2_sync->base.SyncFd);
+ break;
+ default:
+ break;
+ }
if (dri2_sync->fence)
dri2_dpy->fence->destroy_fence(dri2_dpy->dri_screen, dri2_sync->fence);
/* initial status of reusable sync must be "unsignaled" */
dri2_sync->base.SyncStatus = EGL_UNSIGNALED_KHR;
break;
+
+ case EGL_SYNC_NATIVE_FENCE_ANDROID:
+ if (dri2_dpy->fence->create_fence_fd) {
+ dri2_sync->fence = dri2_dpy->fence->create_fence_fd(
+ dri2_ctx->dri_context,
+ dri2_sync->base.SyncFd);
+ }
+ if (!dri2_sync->fence) {
+ _eglError(EGL_BAD_ATTRIBUTE, "eglCreateSyncKHR");
+ free(dri2_sync);
+ return NULL;
+ }
+ break;
}
p_atomic_set(&dri2_sync->refcount, 1);
ret = EGL_FALSE;
}
}
+
dri2_egl_unref_sync(dri2_dpy, dri2_sync);
return ret;
}
+static EGLint
+dri2_dup_native_fence_fd(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSync *sync)
+{
+ struct dri2_egl_display *dri2_dpy = dri2_egl_display(dpy);
+ struct dri2_egl_sync *dri2_sync = dri2_egl_sync(sync);
+
+ assert(sync->Type == EGL_SYNC_NATIVE_FENCE_ANDROID);
+
+ if (sync->SyncFd == EGL_NO_NATIVE_FENCE_FD_ANDROID) {
+ /* try to retrieve the actual native fence fd.. if rendering is
+ * not flushed this will just return -1, aka NO_NATIVE_FENCE_FD:
+ */
+ sync->SyncFd = dri2_dpy->fence->get_fence_fd(dri2_dpy->dri_screen,
+ dri2_sync->fence);
+ }
+
+ if (sync->SyncFd == EGL_NO_NATIVE_FENCE_FD_ANDROID) {
+ /* if native fence fd still not created, return an error: */
+ _eglError(EGL_BAD_PARAMETER, "eglDupNativeFenceFDANDROID");
+ return EGL_NO_NATIVE_FENCE_FD_ANDROID;
+ }
+
+ return dup(sync->SyncFd);
+}
+
static EGLint
dri2_client_wait_sync(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSync *sync,
EGLint flags, EGLTime timeout)
switch (sync->Type) {
case EGL_SYNC_FENCE_KHR:
+ case EGL_SYNC_NATIVE_FENCE_ANDROID:
case EGL_SYNC_CL_EVENT_KHR:
if (dri2_dpy->fence->client_wait_sync(dri2_ctx ? dri2_ctx->dri_context : NULL,
dri2_sync->fence, wait_flags,
const char *libname = "libglapi.0.dylib";
#elif defined(__CYGWIN__)
const char *libname = "cygglapi-0.dll";
-#elif defined(__linux__)
- const char *libname = "libglapi.so.0";
#else
-#error Unknown glapi provider for this platform
+ const char *libname = "libglapi.so.0";
#endif
void *handle;
dri2_drv->base.API.DestroySyncKHR = dri2_destroy_sync;
dri2_drv->base.API.GLInteropQueryDeviceInfo = dri2_interop_query_device_info;
dri2_drv->base.API.GLInteropExportObject = dri2_interop_export_object;
+ dri2_drv->base.API.DupNativeFenceFDANDROID = dri2_dup_native_fence_fd;
dri2_drv->base.Name = "DRI2";
dri2_drv->base.Unload = dri2_unload;