#include "egl_dri2.h"
#include "GL/mesa_glinterop.h"
#include "loader/loader.h"
+#include "util/libsync.h"
#include "util/os_file.h"
#include "util/u_atomic.h"
+#include "util/u_call_once.h"
#include "util/u_vector.h"
#include "mapi/glapi/glapi.h"
#include "util/bitscan.h"
+#include "util/driconf.h"
#include "util/u_math.h"
-/* Additional definitions not yet in the drm_fourcc.h.
- */
-#ifndef DRM_FORMAT_P010
-#define DRM_FORMAT_P010 fourcc_code('P', '0', '1', '0') /* 2x2 subsampled Cb:Cr plane 10 bits per channel */
-#endif
-
-#ifndef DRM_FORMAT_P012
-#define DRM_FORMAT_P012 fourcc_code('P', '0', '1', '2') /* 2x2 subsampled Cb:Cr plane 12 bits per channel */
-#endif
-
-#ifndef DRM_FORMAT_P016
-#define DRM_FORMAT_P016 fourcc_code('P', '0', '1', '6') /* 2x2 subsampled Cb:Cr plane 16 bits per channel */
-#endif
-
#define NUM_ATTRIBS 12
static const struct dri2_pbuffer_visual {
}
static void
+dri2_gl_flush_get(_glapi_proc *glFlush)
+{
+ *glFlush = _glapi_get_proc_address("glFlush");
+}
+
+static void
dri2_gl_flush()
{
static void (*glFlush)(void);
- static mtx_t glFlushMutex = _MTX_INITIALIZER_NP;
+ static util_once_flag once = UTIL_ONCE_FLAG_INIT;
- mtx_lock(&glFlushMutex);
- if (!glFlush)
- glFlush = _glapi_get_proc_address("glFlush");
- mtx_unlock(&glFlushMutex);
+ util_call_once_data(&once,
+ (util_call_once_data_func)dri2_gl_flush_get, &glFlush);
/* if glFlush is not available things are horribly broken */
if (!glFlush) {
}
static GLboolean
-dri_is_thread_safe(void *loaderPrivate)
+dri_is_thread_safe(UNUSED void *loaderPrivate)
{
+#ifdef HAVE_X11_PLATFORM
struct dri2_egl_surface *dri2_surf = loaderPrivate;
- UNUSED _EGLDisplay *display = dri2_surf->base.Resource.Display;
-#ifdef HAVE_X11_PLATFORM
+ /* loader_dri3_blit_context_get creates a context with
+ * loaderPrivate being NULL. Enabling glthread for a blitting
+ * context isn't useful so return false.
+ */
+ if (!loaderPrivate)
+ return false;
+
+ _EGLDisplay *display = dri2_surf->base.Resource.Display;
+
Display *xdpy = (Display*)display->PlatformDisplay;
/* Check Xlib is running in thread safe mode when running on EGL/X11-xlib
return false;
#endif
-#ifdef HAVE_WAYLAND_PLATFORM
- if (display->Platform == _EGL_PLATFORM_WAYLAND)
- return true;
-#endif
-
return true;
}
surface_type &= ~EGL_PIXMAP_BIT;
}
- /* No support for pbuffer + MSAA for now.
- *
- * XXX TODO: pbuffer + MSAA does not work and causes crashes.
- * See QT bugreport: https://bugreports.qt.io/browse/QTBUG-47509
- */
- if (base.Samples) {
- surface_type &= ~EGL_PBUFFER_BIT;
- }
-
if (!surface_type)
return NULL;
return (config_count != 0);
}
-__DRIimage *
-dri2_lookup_egl_image(__DRIscreen *screen, void *image, void *data)
+GLboolean
+dri2_validate_egl_image(void *image, void *data)
{
- _EGLDisplay *disp = data;
- struct dri2_egl_image *dri2_img;
- _EGLImage *img;
+ _EGLDisplay *disp = _eglLockDisplay(data);
+ _EGLImage *img = _eglLookupImage(image, disp);
+ _eglUnlockDisplay(disp);
- (void) screen;
-
- img = _eglLookupImage(image, disp);
if (img == NULL) {
- _eglError(EGL_BAD_PARAMETER, "dri2_lookup_egl_image");
- return NULL;
+ _eglError(EGL_BAD_PARAMETER, "dri2_validate_egl_image");
+ return false;
}
+ return true;
+}
+
+__DRIimage *
+dri2_lookup_egl_image_validated(void *image, void *data)
+{
+ struct dri2_egl_image *dri2_img;
+
+ (void)data;
+
dri2_img = dri2_egl_image(image);
return dri2_img->dri_image;
}
+__DRIimage *
+dri2_lookup_egl_image(__DRIscreen *screen, void *image, void *data)
+{
+ (void) screen;
+
+ if (!dri2_validate_egl_image(image, data))
+ return NULL;
+
+ return dri2_lookup_egl_image_validated(image, data);
+}
+
const __DRIimageLookupExtension image_lookup_extension = {
- .base = { __DRI_IMAGE_LOOKUP, 1 },
+ .base = { __DRI_IMAGE_LOOKUP, 2 },
- .lookupEGLImage = dri2_lookup_egl_image
+ .lookupEGLImage = dri2_lookup_egl_image,
+ .validateEGLImage = dri2_validate_egl_image,
+ .lookupEGLImageValidated = dri2_lookup_egl_image_validated,
};
struct dri2_extension_match {
static const struct dri2_extension_match optional_core_extensions[] = {
{ __DRI2_ROBUSTNESS, 1, offsetof(struct dri2_egl_display, robustness) },
- { __DRI2_NO_ERROR, 1, offsetof(struct dri2_egl_display, no_error) },
{ __DRI2_CONFIG_QUERY, 1, offsetof(struct dri2_egl_display, config) },
{ __DRI2_FENCE, 1, offsetof(struct dri2_egl_display, fence) },
{ __DRI2_BUFFER_DAMAGE, 1, offsetof(struct dri2_egl_display, buffer_damage) },
{ __DRI2_FLUSH_CONTROL, 1, offsetof(struct dri2_egl_display, flush_control) },
{ __DRI2_BLOB, 1, offsetof(struct dri2_egl_display, blob) },
{ __DRI_MUTABLE_RENDER_BUFFER_DRIVER, 1, offsetof(struct dri2_egl_display, mutable_render_buffer) },
+ { __DRI_KOPPER, 1, offsetof(struct dri2_egl_display, kopper) },
{ NULL, 0, 0 }
};
struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
const __DRIextension **extensions;
+ /*This exception only happen in multithread case, when _eglAtExit is *
+ *called and disp is freed in main thread. */
+ if (dri2_dpy == NULL) {
+ _eglLog(_EGL_FATAL, "DRI2: disp is freed");
+ return EGL_FALSE;
+ }
+
extensions = dri2_open_driver(disp);
if (!extensions)
return EGL_FALSE;
static char *
dri2_query_driver_config(_EGLDisplay *disp)
{
- struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+ struct dri2_egl_display *dri2_dpy = dri2_egl_display_lock(disp);
const __DRIconfigOptionsExtension *ext = dri2_dpy->configOptions;
+ char *ret;
+
+ if (ext->base.version >= 2) {
+ ret = ext->getXml(dri2_dpy->driver_name);
+ } else {
+ ret = strdup(ext->xml);
+ }
- if (ext->base.version >= 2)
- return ext->getXml(dri2_dpy->driver_name);
+ mtx_unlock(&dri2_dpy->lock);
- return strdup(ext->xml);
+ return ret;
}
disp->Extensions.EXT_create_context_robustness = EGL_TRUE;
}
- if (dri2_dpy->no_error)
+ if (dri2_renderer_query_integer(dri2_dpy,
+ __DRI2_RENDERER_HAS_NO_ERROR_CONTEXT))
disp->Extensions.KHR_create_context_no_error = EGL_TRUE;
if (dri2_dpy->fence) {
if (dri2_dpy->buffer_damage && dri2_dpy->buffer_damage->set_damage_region)
disp->Extensions.KHR_partial_update = EGL_TRUE;
+
+ disp->Extensions.EXT_protected_surface =
+ dri2_renderer_query_integer(dri2_dpy,
+ __DRI2_RENDERER_HAS_PROTECTED_SURFACE);
+ disp->Extensions.EXT_protected_content =
+ dri2_renderer_query_integer(dri2_dpy,
+ __DRI2_RENDERER_HAS_PROTECTED_CONTEXT);
}
void
}
if (dri2_dpy->dri_screen == NULL) {
- _eglLog(_EGL_WARNING, "DRI2: failed to create dri screen");
+ _eglLog(_EGL_WARNING, "egl: failed to create dri2 screen");
return EGL_FALSE;
}
* to free it up correctly.
*/
if (dri2_dpy) {
- dri2_dpy->ref_count++;
+ p_atomic_inc(&dri2_dpy->ref_count);
return EGL_TRUE;
}
ret = dri2_initialize_device(disp);
break;
case _EGL_PLATFORM_X11:
+ case _EGL_PLATFORM_XCB:
ret = dri2_initialize_x11(disp);
break;
case _EGL_PLATFORM_DRM:
case _EGL_PLATFORM_ANDROID:
ret = dri2_initialize_android(disp);
break;
+
+#ifdef HAVE_TIZEN_PLATFORM
+ case _EGL_PLATFORM_TIZEN:
+ ret = dri2_initialize_tizen(disp);
+ break;
+#endif
default:
unreachable("Callers ensure we cannot get here.");
return EGL_FALSE;
return EGL_FALSE;
dri2_dpy = dri2_egl_display(disp);
- dri2_dpy->ref_count++;
+ p_atomic_inc(&dri2_dpy->ref_count);
+
+ mtx_init(&dri2_dpy->lock, mtx_plain);
return EGL_TRUE;
}
dri2_dpy = dri2_egl_display(disp);
assert(dri2_dpy->ref_count > 0);
- dri2_dpy->ref_count--;
- if (dri2_dpy->ref_count > 0)
+ if (!p_atomic_dec_zero(&dri2_dpy->ref_count))
return;
_eglCleanupDisplay(disp);
}
if (dri2_dpy->fd >= 0)
close(dri2_dpy->fd);
+
+ /* Don't dlclose the driver when building with the address sanitizer, so you
+ * get good symbols from the leak reports.
+ */
+#if !BUILT_WITH_ASAN || defined(NDEBUG)
if (dri2_dpy->driver)
dlclose(dri2_dpy->driver);
+#endif
+
free(dri2_dpy->driver_name);
#ifdef HAVE_WAYLAND_PLATFORM
case _EGL_PLATFORM_WAYLAND:
dri2_teardown_wayland(dri2_dpy);
break;
+
+#ifdef HAVE_TIZEN_PLATFORM
+ case _EGL_PLATFORM_TIZEN:
+ dri2_teardown_tizen(disp);
+ break;
+#endif
default:
/* TODO: add teardown for other platforms */
break;
ctx_attribs[pos++] = __DRI_CTX_ATTRIB_MINOR_VERSION;
ctx_attribs[pos++] = dri2_ctx->base.ClientMinorVersion;
- if (dri2_ctx->base.Flags != 0 || dri2_ctx->base.NoError) {
+ if (dri2_ctx->base.Flags != 0) {
/* If the implementation doesn't support the __DRI2_ROBUSTNESS
* extension, don't even try to send it the robust-access flag.
* It may explode. Instead, generate the required EGL error here.
}
ctx_attribs[pos++] = __DRI_CTX_ATTRIB_FLAGS;
- ctx_attribs[pos++] = dri2_ctx->base.Flags |
- (dri2_ctx->base.NoError ? __DRI_CTX_FLAG_NO_ERROR : 0);
+ ctx_attribs[pos++] = dri2_ctx->base.Flags;
}
if (dri2_ctx->base.ResetNotificationStrategy != EGL_NO_RESET_NOTIFICATION_KHR) {
ctx_attribs[pos++] = __DRI_CTX_RELEASE_BEHAVIOR_NONE;
}
+ if (dri2_ctx->base.NoError) {
+ ctx_attribs[pos++] = __DRI_CTX_ATTRIB_NO_ERROR;
+ ctx_attribs[pos++] = true;
+ }
+
+ if (dri2_ctx->base.Protected) {
+ ctx_attribs[pos++] = __DRI_CTX_ATTRIB_PROTECTED;
+ ctx_attribs[pos++] = true;
+ }
+
*num_attribs = pos;
return true;
_EGLContext *share_list, const EGLint *attrib_list)
{
struct dri2_egl_context *dri2_ctx;
- struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+ struct dri2_egl_display *dri2_dpy = dri2_egl_display_lock(disp);
struct dri2_egl_context *dri2_ctx_shared = dri2_egl_context(share_list);
__DRIcontext *shared =
dri2_ctx_shared ? dri2_ctx_shared->dri_context : NULL;
dri2_ctx = malloc(sizeof *dri2_ctx);
if (!dri2_ctx) {
- _eglError(EGL_BAD_ALLOC, "eglCreateContext");
+ dri2_egl_error_unlock(dri2_dpy, EGL_BAD_ALLOC, "eglCreateContext");
return NULL;
}
break;
default:
_eglError(EGL_BAD_PARAMETER, "eglCreateContext");
- free(dri2_ctx);
- return NULL;
+ goto cleanup;
}
break;
case EGL_OPENGL_API:
break;
default:
_eglError(EGL_BAD_PARAMETER, "eglCreateContext");
- free(dri2_ctx);
- return NULL;
+ goto cleanup;
}
if (conf != NULL) {
if (!dri2_ctx->dri_context)
goto cleanup;
+ mtx_unlock(&dri2_dpy->lock);
+
return &dri2_ctx->base;
cleanup:
+ mtx_unlock(&dri2_dpy->lock);
free(dri2_ctx);
return NULL;
}
dri2_destroy_surface(_EGLDisplay *disp, _EGLSurface *surf)
{
struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+ EGLBoolean ret = EGL_TRUE;
- if (!_eglPutSurface(surf))
- return EGL_TRUE;
+ if (_eglPutSurface(surf))
+ ret = dri2_dpy->vtbl->destroy_surface(disp, surf);
- return dri2_dpy->vtbl->destroy_surface(disp, surf);
+ return ret;
}
static void
struct dri2_egl_surface *dri2_surf,
void *loaderPrivate)
{
- __DRIcreateNewDrawableFunc createNewDrawable;
-
- if (dri2_dpy->image_driver)
- createNewDrawable = dri2_dpy->image_driver->createNewDrawable;
- else if (dri2_dpy->dri2)
- createNewDrawable = dri2_dpy->dri2->createNewDrawable;
- else if (dri2_dpy->swrast)
- createNewDrawable = dri2_dpy->swrast->createNewDrawable;
- else
- return _eglError(EGL_BAD_ALLOC, "no createNewDrawable");
+ if (dri2_dpy->kopper) {
+ dri2_surf->dri_drawable =
+ dri2_dpy->kopper->createNewDrawable(dri2_dpy->dri_screen, config, loaderPrivate,
+ dri2_surf->base.Type == EGL_PBUFFER_BIT ||
+ dri2_surf->base.Type == EGL_PIXMAP_BIT);
+ } else {
+ __DRIcreateNewDrawableFunc createNewDrawable;
+ if (dri2_dpy->image_driver)
+ createNewDrawable = dri2_dpy->image_driver->createNewDrawable;
+ else if (dri2_dpy->dri2)
+ createNewDrawable = dri2_dpy->dri2->createNewDrawable;
+ else if (dri2_dpy->swrast)
+ createNewDrawable = dri2_dpy->swrast->createNewDrawable;
+ else
+ return _eglError(EGL_BAD_ALLOC, "no createNewDrawable");
- dri2_surf->dri_drawable = createNewDrawable(dri2_dpy->dri_screen,
- config, loaderPrivate);
+ dri2_surf->dri_drawable = createNewDrawable(dri2_dpy->dri_screen,
+ config, loaderPrivate);
+ }
if (dri2_surf->dri_drawable == NULL)
return _eglError(EGL_BAD_ALLOC, "createNewDrawable");
if (!_eglBindContext(ctx, dsurf, rsurf, &old_ctx, &old_dsurf, &old_rsurf))
return EGL_FALSE;
+ if (old_ctx == ctx && old_dsurf == dsurf && old_rsurf == rsurf) {
+ _eglPutSurface(old_dsurf);
+ _eglPutSurface(old_rsurf);
+ _eglPutContext(old_ctx);
+ return EGL_TRUE;
+ }
+
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 */
- dri2_gl_flush();
-
- if (old_dsurf)
- dri2_surf_update_fence_fd(old_ctx, disp, old_dsurf);
-
/* Disable shared buffer mode */
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, false);
}
- dri2_dpy->core->unbindContext(old_cctx);
+ old_dri2_dpy->core->unbindContext(old_cctx);
+
+ if (old_dsurf)
+ dri2_surf_update_fence_fd(old_ctx, old_disp, old_dsurf);
}
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 (cctx || ddraw || rdraw) {
+ if (cctx) {
if (!dri2_dpy->core->bindContext(cctx, ddraw, rdraw)) {
_EGLContext *tmp_ctx;
/* dri2_dpy->core->bindContext succeeded, so take a reference on the
* dri2_dpy. This prevents dri2_dpy from being reinitialized when a
* EGLDisplay is terminated and then initialized again while a
- * context is still bound. See dri2_intitialize() for a more in depth
+ * context is still bound. See dri2_initialize() for a more in depth
* explanation. */
- dri2_dpy->ref_count++;
+ p_atomic_inc(&dri2_dpy->ref_count);
}
}
* Called from eglGetProcAddress() via drv->GetProcAddress().
*/
static _EGLProc
-dri2_get_proc_address(const _EGLDriver *drv, const char *procname)
+dri2_get_proc_address(const char *procname)
{
return _glapi_get_proc_address(procname);
}
dri2_create_window_surface(_EGLDisplay *disp, _EGLConfig *conf,
void *native_window, const EGLint *attrib_list)
{
- struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
- return dri2_dpy->vtbl->create_window_surface(disp, conf, native_window,
- attrib_list);
+ struct dri2_egl_display *dri2_dpy = dri2_egl_display_lock(disp);
+ _EGLSurface *ret =
+ dri2_dpy->vtbl->create_window_surface(disp, conf, native_window,
+ attrib_list);
+ mtx_unlock(&dri2_dpy->lock);
+ return ret;
}
static _EGLSurface*
dri2_create_pixmap_surface(_EGLDisplay *disp, _EGLConfig *conf,
void *native_pixmap, 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(disp, conf, native_pixmap,
- attrib_list);
+ struct dri2_egl_display *dri2_dpy = dri2_egl_display_lock(disp);
+ _EGLSurface *ret = NULL;
+
+ if (dri2_dpy->vtbl->create_pixmap_surface)
+ ret = dri2_dpy->vtbl->create_pixmap_surface(disp, conf, native_pixmap,
+ attrib_list);
+
+ mtx_unlock(&dri2_dpy->lock);
+
+ return ret;
}
static _EGLSurface*
dri2_create_pbuffer_surface(_EGLDisplay *disp, _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(disp, conf, attrib_list);
+ struct dri2_egl_display *dri2_dpy = dri2_egl_display_lock(disp);
+ _EGLSurface *ret = NULL;
+
+ if (dri2_dpy->vtbl->create_pbuffer_surface)
+ ret = dri2_dpy->vtbl->create_pbuffer_surface(disp, conf, attrib_list);
+
+ mtx_unlock(&dri2_dpy->lock);
+
+ return ret;
}
static EGLBoolean
dri2_swap_interval(_EGLDisplay *disp, _EGLSurface *surf, EGLint interval)
{
- struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
- if (!dri2_dpy->vtbl->swap_interval)
- return EGL_TRUE;
- return dri2_dpy->vtbl->swap_interval(disp, surf, interval);
+ struct dri2_egl_display *dri2_dpy = dri2_egl_display_lock(disp);
+ EGLBoolean ret = EGL_TRUE;
+
+ if (dri2_dpy->vtbl->swap_interval)
+ ret = dri2_dpy->vtbl->swap_interval(disp, surf, interval);
+
+ mtx_unlock(&dri2_dpy->lock);
+
+ return ret;
}
/**
}
static EGLBoolean
-dri2_swap_buffers(const _EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf)
+dri2_swap_buffers(_EGLDisplay *disp, _EGLSurface *surf)
{
struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
__DRIdrawable *dri_drawable = dri2_dpy->vtbl->get_dri_drawable(surf);
if (ctx && surf)
dri2_surf_update_fence_fd(ctx, disp, surf);
- ret = dri2_dpy->vtbl->swap_buffers(drv, disp, surf);
+ ret = dri2_dpy->vtbl->swap_buffers(disp, surf);
/* SwapBuffers marks the end of the frame; reset the damage region for
* use again next time.
}
static EGLBoolean
-dri2_swap_buffers_with_damage(const _EGLDriver *drv, _EGLDisplay *disp,
- _EGLSurface *surf,
+dri2_swap_buffers_with_damage(_EGLDisplay *disp, _EGLSurface *surf,
const EGLint *rects, EGLint n_rects)
{
struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
if (ctx && surf)
dri2_surf_update_fence_fd(ctx, disp, surf);
if (dri2_dpy->vtbl->swap_buffers_with_damage)
- ret = dri2_dpy->vtbl->swap_buffers_with_damage(drv, disp, surf,
+ ret = dri2_dpy->vtbl->swap_buffers_with_damage(disp, surf,
rects, n_rects);
else
- ret = dri2_dpy->vtbl->swap_buffers(drv, disp, surf);
+ ret = dri2_dpy->vtbl->swap_buffers(disp, surf);
/* SwapBuffers marks the end of the frame; reset the damage region for
* use again next time.
}
static EGLBoolean
-dri2_swap_buffers_region(const _EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf,
+dri2_swap_buffers_region(_EGLDisplay *disp, _EGLSurface *surf,
EGLint numRects, const EGLint *rects)
{
struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
if (!dri2_dpy->vtbl->swap_buffers_region)
return EGL_FALSE;
- ret = dri2_dpy->vtbl->swap_buffers_region(drv, disp, surf, numRects, rects);
+ ret = dri2_dpy->vtbl->swap_buffers_region(disp, surf, numRects, rects);
/* SwapBuffers marks the end of the frame; reset the damage region for
* use again next time.
}
static EGLBoolean
-dri2_set_damage_region(const _EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf,
+dri2_set_damage_region(_EGLDisplay *disp, _EGLSurface *surf,
EGLint *rects, EGLint n_rects)
{
- struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+ struct dri2_egl_display *dri2_dpy = dri2_egl_display_lock(disp);
__DRIdrawable *drawable = dri2_dpy->vtbl->get_dri_drawable(surf);
- if (!dri2_dpy->buffer_damage || !dri2_dpy->buffer_damage->set_damage_region)
+ if (!dri2_dpy->buffer_damage || !dri2_dpy->buffer_damage->set_damage_region) {
+ mtx_unlock(&dri2_dpy->lock);
return EGL_FALSE;
+ }
dri2_dpy->buffer_damage->set_damage_region(drawable, n_rects, rects);
+ mtx_unlock(&dri2_dpy->lock);
return EGL_TRUE;
}
static EGLBoolean
-dri2_post_sub_buffer(const _EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf,
+dri2_post_sub_buffer(_EGLDisplay *disp, _EGLSurface *surf,
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);
+ struct dri2_egl_display *dri2_dpy = dri2_egl_display_lock(disp);
+ EGLBoolean ret = EGL_FALSE;
+
+ if (dri2_dpy->vtbl->post_sub_buffer)
+ ret = dri2_dpy->vtbl->post_sub_buffer(disp, surf, x, y, width, height);
+
+ mtx_unlock(&dri2_dpy->lock);
+
+ return ret;
}
static EGLBoolean
-dri2_copy_buffers(const _EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf,
- void *native_pixmap_target)
+dri2_copy_buffers(_EGLDisplay *disp, _EGLSurface *surf, void *native_pixmap_target)
{
- struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+ struct dri2_egl_display *dri2_dpy = dri2_egl_display_lock(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);
+ return dri2_egl_error_unlock(dri2_dpy, EGL_BAD_NATIVE_PIXMAP, "no support for native pixmaps");
+ EGLBoolean ret = dri2_dpy->vtbl->copy_buffers(disp, surf, native_pixmap_target);
+ mtx_unlock(&dri2_dpy->lock);
+ return ret;
}
static EGLint
-dri2_query_buffer_age(const _EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf)
+dri2_query_buffer_age(_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);
+ return dri2_dpy->vtbl->query_buffer_age(disp, surf);
}
static EGLBoolean
-dri2_wait_client(const _EGLDriver *drv, _EGLDisplay *disp, _EGLContext *ctx)
+dri2_wait_client(_EGLDisplay *disp, _EGLContext *ctx)
{
struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
_EGLSurface *surf = ctx->DrawSurface;
__DRIdrawable *dri_drawable = dri2_dpy->vtbl->get_dri_drawable(surf);
- (void) drv;
-
/* FIXME: If EGL allows frontbuffer rendering for window surfaces,
* we need to copy fake to real here.*/
}
static EGLBoolean
-dri2_wait_native(const _EGLDriver *drv, _EGLDisplay *disp, EGLint engine)
+dri2_wait_native(EGLint engine)
{
- (void) drv;
- (void) disp;
-
if (engine != EGL_CORE_NATIVE_ENGINE)
return _eglError(EGL_BAD_PARAMETER, "eglWaitNative");
/* glXWaitX(); */
static EGLBoolean
dri2_bind_tex_image(_EGLDisplay *disp, _EGLSurface *surf, EGLint buffer)
{
- struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+ struct dri2_egl_display *dri2_dpy = dri2_egl_display_lock(disp);
struct dri2_egl_context *dri2_ctx;
_EGLContext *ctx;
GLint format, target;
ctx = _eglGetCurrentContext();
dri2_ctx = dri2_egl_context(ctx);
- if (!_eglBindTexImage(disp, surf, buffer))
+ if (!_eglBindTexImage(disp, surf, buffer)) {
+ mtx_unlock(&dri2_dpy->lock);
return EGL_FALSE;
+ }
switch (surf->TextureFormat) {
case EGL_TEXTURE_RGB:
target, format,
dri_drawable);
+ mtx_unlock(&dri2_dpy->lock);
+
return EGL_TRUE;
}
static EGLBoolean
dri2_release_tex_image(_EGLDisplay *disp, _EGLSurface *surf, EGLint buffer)
{
- struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+ struct dri2_egl_display *dri2_dpy = dri2_egl_display_lock(disp);
struct dri2_egl_context *dri2_ctx;
_EGLContext *ctx;
GLint target;
ctx = _eglGetCurrentContext();
dri2_ctx = dri2_egl_context(ctx);
- if (!_eglReleaseTexImage(disp, surf, buffer))
+ if (!_eglReleaseTexImage(disp, surf, buffer)) {
+ mtx_unlock(&dri2_dpy->lock);
return EGL_FALSE;
+ }
switch (surf->TextureTarget) {
case EGL_TEXTURE_2D:
target, dri_drawable);
}
+ mtx_unlock(&dri2_dpy->lock);
+
return EGL_TRUE;
}
static _EGLImage*
-dri2_create_image(const _EGLDriver *drv, _EGLDisplay *disp, _EGLContext *ctx,
- EGLenum target, EGLClientBuffer buffer,
- const EGLint *attr_list)
+dri2_create_image(_EGLDisplay *disp, _EGLContext *ctx, EGLenum target,
+ EGLClientBuffer buffer, const EGLint *attr_list)
{
- struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
- return dri2_dpy->vtbl->create_image(drv, disp, ctx, target, buffer,
- attr_list);
+ struct dri2_egl_display *dri2_dpy = dri2_egl_display_lock(disp);
+ _EGLImage *ret = dri2_dpy->vtbl->create_image(disp, ctx, target, buffer,
+ attr_list);
+ mtx_unlock(&dri2_dpy->lock);
+ return ret;
}
-static _EGLImage *
+_EGLImage *
dri2_create_image_from_dri(_EGLDisplay *disp, __DRIimage *dri_image)
{
struct dri2_egl_image *dri2_img;
EGLuint64KHR *sbc)
{
struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
- if (!dri2_dpy->vtbl->get_sync_values)
+ EGLBoolean ret = EGL_FALSE;
+
+ if (dri2_dpy->vtbl->get_sync_values)
+ ret = dri2_dpy->vtbl->get_sync_values(disp, surf, ust, msc, sbc);
+
+ return ret;
+}
+
+static EGLBoolean
+dri2_get_msc_rate_angle(_EGLDisplay *disp, _EGLSurface *surf,
+ EGLint *numerator, EGLint *denominator)
+{
+ struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+ if (!dri2_dpy->vtbl->get_msc_rate)
return EGL_FALSE;
- return dri2_dpy->vtbl->get_sync_values(disp, surf, ust, msc, sbc);
+ return dri2_dpy->vtbl->get_msc_rate(disp, surf, numerator, denominator);
}
/**
depth,
attrs.GLTextureLevel,
&error,
- dri2_img);
+ NULL);
dri2_create_image_khr_texture_error(error);
if (!dri2_img->dri_image) {
EGLint attribute, EGLint *value)
{
struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
- if (!dri2_dpy->vtbl->query_surface)
- return _eglQuerySurface(disp, surf, attribute, value);
- return dri2_dpy->vtbl->query_surface(disp, surf, attribute, value);
+ EGLBoolean ret;
+
+ if (!dri2_dpy->vtbl->query_surface) {
+ ret = _eglQuerySurface(disp, surf, attribute, value);
+ } else {
+ ret = dri2_dpy->vtbl->query_surface(disp, surf, attribute, value);
+ }
+
+ return ret;
}
static struct wl_buffer*
-dri2_create_wayland_buffer_from_image(const _EGLDriver *drv, _EGLDisplay *disp,
- _EGLImage *img)
+dri2_create_wayland_buffer_from_image(_EGLDisplay *disp, _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);
+ struct dri2_egl_display *dri2_dpy = dri2_egl_display_lock(disp);
+ struct wl_buffer *ret = NULL;
+
+ if (dri2_dpy->vtbl->create_wayland_buffer_from_image)
+ ret = dri2_dpy->vtbl->create_wayland_buffer_from_image(disp, img);
+
+ mtx_unlock(&dri2_dpy->lock);
+
+ return ret;
}
#ifdef HAVE_LIBDRM
case DRM_FORMAT_ABGR2101010:
case DRM_FORMAT_RGBA1010102:
case DRM_FORMAT_BGRA1010102:
+ case DRM_FORMAT_ABGR16161616:
+ case DRM_FORMAT_XBGR16161616:
case DRM_FORMAT_XBGR16161616F:
case DRM_FORMAT_ABGR16161616F:
case DRM_FORMAT_YUYV:
case DRM_FORMAT_VYUY:
case DRM_FORMAT_AYUV:
case DRM_FORMAT_XYUV8888:
+ case DRM_FORMAT_Y210:
+ case DRM_FORMAT_Y212:
+ case DRM_FORMAT_Y216:
+ case DRM_FORMAT_Y410:
+ case DRM_FORMAT_Y412:
+ case DRM_FORMAT_Y416:
return 1;
case DRM_FORMAT_NV12:
}
static EGLBoolean
-dri2_query_dma_buf_formats(const _EGLDriver *drv, _EGLDisplay *disp,
- EGLint max, EGLint *formats, EGLint *count)
+dri2_query_dma_buf_formats(_EGLDisplay *disp, EGLint max,
+ EGLint *formats, EGLint *count)
{
- struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
- if (max < 0 || (max > 0 && formats == NULL))
- return _eglError(EGL_BAD_PARAMETER, "invalid value for max count of formats");
+ struct dri2_egl_display *dri2_dpy = dri2_egl_display_lock(disp);
+ if (max < 0 || (max > 0 && formats == NULL)) {
+ _eglError(EGL_BAD_PARAMETER, "invalid value for max count of formats");
+ goto fail;
+ }
if (dri2_dpy->image->base.version < 15 ||
dri2_dpy->image->queryDmaBufFormats == NULL)
- return EGL_FALSE;
+ goto fail;
if (!dri2_dpy->image->queryDmaBufFormats(dri2_dpy->dri_screen, max,
formats, count))
- return EGL_FALSE;
+ goto fail;
if (max > 0) {
/* Assert that all of the formats returned are actually fourcc formats.
}
}
+ mtx_unlock(&dri2_dpy->lock);
+
return EGL_TRUE;
+
+fail:
+ mtx_unlock(&dri2_dpy->lock);
+ return EGL_FALSE;
}
static EGLBoolean
-dri2_query_dma_buf_modifiers(const _EGLDriver *drv, _EGLDisplay *disp, EGLint format,
+dri2_query_dma_buf_modifiers(_EGLDisplay *disp, EGLint format,
EGLint max, EGLuint64KHR *modifiers,
EGLBoolean *external_only, EGLint *count)
{
- struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+ struct dri2_egl_display *dri2_dpy = dri2_egl_display_lock(disp);
if (dri2_num_fourcc_format_planes(format) == 0)
- return _eglError(EGL_BAD_PARAMETER, "invalid fourcc format");
+ return dri2_egl_error_unlock(dri2_dpy, EGL_BAD_PARAMETER, "invalid fourcc format");
if (max < 0)
- return _eglError(EGL_BAD_PARAMETER, "invalid value for max count of formats");
+ return dri2_egl_error_unlock(dri2_dpy, EGL_BAD_PARAMETER, "invalid value for max count of formats");
if (max > 0 && modifiers == NULL)
- return _eglError(EGL_BAD_PARAMETER, "invalid modifiers array");
+ return dri2_egl_error_unlock(dri2_dpy, EGL_BAD_PARAMETER, "invalid modifiers array");
if (dri2_dpy->image->base.version < 15 ||
- dri2_dpy->image->queryDmaBufModifiers == NULL)
+ dri2_dpy->image->queryDmaBufModifiers == NULL) {
+ mtx_unlock(&dri2_dpy->lock);
return EGL_FALSE;
+ }
if (dri2_dpy->image->queryDmaBufModifiers(dri2_dpy->dri_screen, format,
max, modifiers,
(unsigned int *) external_only,
count) == false)
- return _eglError(EGL_BAD_PARAMETER, "invalid format");
+ return dri2_egl_error_unlock(dri2_dpy, EGL_BAD_PARAMETER, "invalid format");
+
+ mtx_unlock(&dri2_dpy->lock);
return EGL_TRUE;
}
uint64_t modifier;
bool has_modifier = false;
unsigned error;
+ EGLint egl_error;
/**
* The spec says:
has_modifier = true;
}
- if (has_modifier) {
+ if (attrs.ProtectedContent) {
+ if (dri2_dpy->image->base.version < 18 ||
+ dri2_dpy->image->createImageFromDmaBufs3 == NULL) {
+ _eglError(EGL_BAD_MATCH, "unsupported protected_content attribute");
+ return EGL_NO_IMAGE_KHR;
+ }
+ if (!has_modifier)
+ modifier = DRM_FORMAT_MOD_INVALID;
+
+ dri_image =
+ dri2_dpy->image->createImageFromDmaBufs3(dri2_dpy->dri_screen,
+ attrs.Width, attrs.Height, attrs.DMABufFourCC.Value,
+ modifier, fds, num_fds, pitches, offsets,
+ attrs.DMABufYuvColorSpaceHint.Value,
+ attrs.DMABufSampleRangeHint.Value,
+ attrs.DMABufChromaHorizontalSiting.Value,
+ attrs.DMABufChromaVerticalSiting.Value,
+ attrs.ProtectedContent ? __DRI_IMAGE_PROTECTED_CONTENT_FLAG : 0,
+ &error,
+ NULL);
+ }
+ else if (has_modifier) {
if (dri2_dpy->image->base.version < 15 ||
dri2_dpy->image->createImageFromDmaBufs2 == NULL) {
_eglError(EGL_BAD_MATCH, "unsupported dma_buf format modifier");
&error,
NULL);
}
- dri2_create_image_khr_texture_error(error);
+
+ egl_error = egl_error_from_dri_image_error(error);
+ if (egl_error != EGL_SUCCESS)
+ _eglError(egl_error, "createImageFromDmaBufs failed");
if (!dri_image)
return EGL_NO_IMAGE_KHR;
return res;
}
static _EGLImage *
-dri2_create_drm_image_mesa(const _EGLDriver *drv, _EGLDisplay *disp,
- const EGLint *attr_list)
+dri2_create_drm_image_mesa(_EGLDisplay *disp, const EGLint *attr_list)
{
- struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+ struct dri2_egl_display *dri2_dpy = dri2_egl_display_lock(disp);
struct dri2_egl_image *dri2_img;
_EGLImageAttribs attrs;
unsigned int dri_use, valid_mask;
int format;
- (void) drv;
-
if (!attr_list) {
_eglError(EGL_BAD_PARAMETER, __func__);
- return EGL_NO_IMAGE_KHR;
+ goto fail;
}
if (!_eglParseImageAttribList(&attrs, disp, attr_list))
- return EGL_NO_IMAGE_KHR;
+ goto fail;
if (attrs.Width <= 0 || attrs.Height <= 0) {
_eglError(EGL_BAD_PARAMETER, __func__);
- return EGL_NO_IMAGE_KHR;
+ goto fail;
}
switch (attrs.DRMBufferFormatMESA) {
break;
default:
_eglError(EGL_BAD_PARAMETER, __func__);
- return EGL_NO_IMAGE_KHR;
+ goto fail;
}
valid_mask =
EGL_DRM_BUFFER_USE_CURSOR_MESA;
if (attrs.DRMBufferUseMESA & ~valid_mask) {
_eglError(EGL_BAD_PARAMETER, __func__);
- return EGL_NO_IMAGE_KHR;
+ goto fail;
}
dri_use = 0;
dri2_img = malloc(sizeof *dri2_img);
if (!dri2_img) {
_eglError(EGL_BAD_ALLOC, "dri2_create_image_khr");
- return EGL_NO_IMAGE_KHR;
+ goto fail;
}
_eglInitImage(&dri2_img->base, disp);
format, dri_use, dri2_img);
if (dri2_img->dri_image == NULL) {
free(dri2_img);
- _eglError(EGL_BAD_ALLOC, "dri2_create_drm_image_mesa");
- return EGL_NO_IMAGE_KHR;
+ _eglError(EGL_BAD_ALLOC, "dri2_create_drm_image_mesa");
+ goto fail;
}
+ mtx_unlock(&dri2_dpy->lock);
+
return &dri2_img->base;
+
+fail:
+ mtx_unlock(&dri2_dpy->lock);
+ return EGL_NO_IMAGE_KHR;
}
static EGLBoolean
-dri2_export_drm_image_mesa(const _EGLDriver *drv, _EGLDisplay *disp, _EGLImage *img,
+dri2_export_drm_image_mesa(_EGLDisplay *disp, _EGLImage *img,
EGLint *name, EGLint *handle, EGLint *stride)
{
- struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+ struct dri2_egl_display *dri2_dpy = dri2_egl_display_lock(disp);
struct dri2_egl_image *dri2_img = dri2_egl_image(img);
- (void) drv;
-
if (name && !dri2_dpy->image->queryImage(dri2_img->dri_image,
__DRI_IMAGE_ATTRIB_NAME, name))
return _eglError(EGL_BAD_ALLOC, "dri2_export_drm_image_mesa");
dri2_dpy->image->queryImage(dri2_img->dri_image,
__DRI_IMAGE_ATTRIB_STRIDE, stride);
+ mtx_unlock(&dri2_dpy->lock);
+
return EGL_TRUE;
}
}
static EGLBoolean
-dri2_export_dma_buf_image_query_mesa(const _EGLDriver *drv, _EGLDisplay *disp,
- _EGLImage *img,
+dri2_export_dma_buf_image_query_mesa(_EGLDisplay *disp, _EGLImage *img,
EGLint *fourcc, EGLint *nplanes,
EGLuint64KHR *modifiers)
{
- struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+ struct dri2_egl_display *dri2_dpy = dri2_egl_display_lock(disp);
struct dri2_egl_image *dri2_img = dri2_egl_image(img);
int num_planes;
- (void) drv;
-
- if (!dri2_can_export_dma_buf_image(disp, img))
+ if (!dri2_can_export_dma_buf_image(disp, img)) {
+ mtx_unlock(&dri2_dpy->lock);
return EGL_FALSE;
+ }
dri2_dpy->image->queryImage(dri2_img->dri_image,
__DRI_IMAGE_ATTRIB_NUM_PLANES, &num_planes);
modifiers[i] = modifier;
}
+ mtx_unlock(&dri2_dpy->lock);
+
return EGL_TRUE;
}
static EGLBoolean
-dri2_export_dma_buf_image_mesa(const _EGLDriver *drv, _EGLDisplay *disp, _EGLImage *img,
+dri2_export_dma_buf_image_mesa(_EGLDisplay *disp, _EGLImage *img,
int *fds, EGLint *strides, EGLint *offsets)
{
- struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+ struct dri2_egl_display *dri2_dpy = dri2_egl_display_lock(disp);
struct dri2_egl_image *dri2_img = dri2_egl_image(img);
EGLint nplanes;
- (void) drv;
-
if (!dri2_can_export_dma_buf_image(disp, img))
return EGL_FALSE;
offsets[0] = 0;
}
+ mtx_unlock(&dri2_dpy->lock);
+
return EGL_TRUE;
}
#endif
_EGLImage *
-dri2_create_image_khr(const _EGLDriver *drv, _EGLDisplay *disp,
- _EGLContext *ctx, EGLenum target,
+dri2_create_image_khr(_EGLDisplay *disp, _EGLContext *ctx, EGLenum target,
EGLClientBuffer buffer, const EGLint *attr_list)
{
- (void) drv;
-
switch (target) {
case EGL_GL_TEXTURE_2D_KHR:
case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X_KHR:
}
static EGLBoolean
-dri2_destroy_image_khr(const _EGLDriver *drv, _EGLDisplay *disp, _EGLImage *image)
+dri2_destroy_image_khr(_EGLDisplay *disp, _EGLImage *image)
{
- struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+ struct dri2_egl_display *dri2_dpy = dri2_egl_display_lock(disp);
struct dri2_egl_image *dri2_img = dri2_egl_image(image);
- (void) drv;
-
dri2_dpy->image->destroyImage(dri2_img->dri_image);
free(dri2_img);
+ mtx_unlock(&dri2_dpy->lock);
+
return EGL_TRUE;
}
}
static EGLBoolean
-dri2_bind_wayland_display_wl(const _EGLDriver *drv, _EGLDisplay *disp,
- struct wl_display *wl_dpy)
+dri2_bind_wayland_display_wl(_EGLDisplay *disp, struct wl_display *wl_dpy)
{
- struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+ struct dri2_egl_display *dri2_dpy = dri2_egl_display_lock(disp);
const struct wayland_drm_callbacks wl_drm_callbacks = {
.authenticate = (int(*)(void *, uint32_t)) dri2_dpy->vtbl->authenticate,
.reference_buffer = dri2_wl_reference_buffer,
.is_format_supported = dri2_wl_is_format_supported
};
int flags = 0;
+ char *device_name;
uint64_t cap;
- (void) drv;
-
if (dri2_dpy->wl_server_drm)
- return EGL_FALSE;
+ goto fail;
+
+ device_name = drmGetRenderDeviceNameFromFd(dri2_dpy->fd);
+ if (!device_name)
+ device_name = strdup(dri2_dpy->device_name);
+ if (!device_name)
+ goto fail;
if (drmGetCap(dri2_dpy->fd, DRM_CAP_PRIME, &cap) == 0 &&
cap == (DRM_PRIME_CAP_IMPORT | DRM_PRIME_CAP_EXPORT) &&
flags |= WAYLAND_DRM_PRIME;
dri2_dpy->wl_server_drm =
- wayland_drm_init(wl_dpy, dri2_dpy->device_name,
+ wayland_drm_init(wl_dpy, device_name,
&wl_drm_callbacks, disp, flags);
+ free(device_name);
+
if (!dri2_dpy->wl_server_drm)
- return EGL_FALSE;
+ goto fail;
#ifdef HAVE_DRM_PLATFORM
/* We have to share the wl_drm instance with gbm, so gbm can convert
dri2_dpy->gbm_dri->wl_drm = dri2_dpy->wl_server_drm;
#endif
+ mtx_unlock(&dri2_dpy->lock);
return EGL_TRUE;
+
+fail:
+ mtx_unlock(&dri2_dpy->lock);
+ return EGL_FALSE;
}
static EGLBoolean
-dri2_unbind_wayland_display_wl(const _EGLDriver *drv, _EGLDisplay *disp,
- struct wl_display *wl_dpy)
+dri2_unbind_wayland_display_wl(_EGLDisplay *disp, struct wl_display *wl_dpy)
{
struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
- (void) drv;
-
if (!dri2_dpy->wl_server_drm)
return EGL_FALSE;
}
static EGLBoolean
-dri2_query_wayland_buffer_wl(const _EGLDriver *drv, _EGLDisplay *disp,
- struct wl_resource *buffer_resource,
+dri2_query_wayland_buffer_wl(_EGLDisplay *disp, struct wl_resource *buffer_resource,
EGLint attribute, EGLint *value)
{
struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
}
#endif
+#ifdef HAVE_TIZEN_PLATFORM
+static EGLBoolean
+tizen_bind_wayland_display_wl(_EGLDisplay *disp,
+ struct wl_display *wl_dpy)
+{
+ struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+
+ (void) wl_dpy;
+
+ if (!dri2_dpy->tpl_display)
+ return EGL_FALSE;
+
+ if (!tpl_display_get_native_handle(dri2_dpy->tpl_display))
+ return EGL_FALSE;
+
+ return EGL_TRUE;
+}
+
+static EGLBoolean
+tizen_unbind_wayland_display_wl(_EGLDisplay *disp,
+ struct wl_display *wl_dpy)
+{
+ struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+
+ (void) wl_dpy;
+
+ if (!dri2_dpy->tpl_display)
+ return EGL_FALSE;
+
+ if (!tpl_display_get_native_handle(dri2_dpy->tpl_display))
+ return EGL_FALSE;
+
+ return EGL_TRUE;
+}
+
+static EGLBoolean
+tizen_query_wayland_buffer_wl(_EGLDisplay *disp,
+ struct wl_resource *buffer_resource,
+ EGLint attribute, EGLint *value)
+{
+ struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+ tbm_format tbm_format = 0;
+ int width = 0, height = 0;
+ tpl_result_t res;
+
+ if (!dri2_dpy->tpl_display)
+ return EGL_FALSE;
+
+ if (!tpl_display_get_native_handle(dri2_dpy->tpl_display))
+ return EGL_FALSE;
+
+ res = tpl_display_get_native_pixmap_info(dri2_dpy->tpl_display,
+ (tpl_handle_t)buffer_resource,
+ &width, &height, &tbm_format);
+ if (res != TPL_ERROR_NONE)
+ return EGL_FALSE;
+
+ switch (attribute) {
+ case EGL_TEXTURE_FORMAT:
+ switch (tbm_format) {
+ case TBM_FORMAT_ARGB8888:
+ *value = EGL_TEXTURE_RGBA;
+ return EGL_TRUE;
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wswitch"
+ case TBM_FORMAT_XRGB8888:
+ case TBM_FORMAT_RGB565:
+#pragma GCC diagnostic pop
+ *value = EGL_TEXTURE_RGB;
+ return EGL_TRUE;
+ default:
+ break;
+ }
+ break;
+ case EGL_WIDTH:
+ *value = width;
+ return EGL_TRUE;
+ case EGL_HEIGHT:
+ *value = height;
+ return EGL_TRUE;
+ default:
+ break;
+ }
+
+ return EGL_FALSE;
+}
+#endif
+
static void
dri2_egl_ref_sync(struct dri2_egl_sync *sync)
{
case EGL_SYNC_REUSABLE_KHR:
cnd_destroy(&dri2_sync->cond);
break;
+#ifdef HAVE_TIZEN_PLATFORM
+ case EGL_SYNC_NATIVE_FENCE_TIZEN:
+ if (dri2_sync->base.SyncFd != EGL_NO_NATIVE_FENCE_FD_TIZEN)
+ close(dri2_sync->base.SyncFd);
+ break;
+#else
case EGL_SYNC_NATIVE_FENCE_ANDROID:
if (dri2_sync->base.SyncFd != EGL_NO_NATIVE_FENCE_FD_ANDROID)
close(dri2_sync->base.SyncFd);
break;
+#endif
default:
break;
}
}
static _EGLSync *
-dri2_create_sync(const _EGLDriver *drv, _EGLDisplay *disp,
- EGLenum type, const EGLAttrib *attrib_list)
+dri2_create_sync(_EGLDisplay *disp, EGLenum type, const EGLAttrib *attrib_list)
{
_EGLContext *ctx = _eglGetCurrentContext();
- struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+ struct dri2_egl_display *dri2_dpy = dri2_egl_display_lock(disp);
struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx);
struct dri2_egl_sync *dri2_sync;
EGLint ret;
dri2_sync = calloc(1, sizeof(struct dri2_egl_sync));
if (!dri2_sync) {
_eglError(EGL_BAD_ALLOC, "eglCreateSyncKHR");
- return NULL;
+ goto fail;
}
if (!_eglInitSync(&dri2_sync->base, disp, type, attrib_list)) {
- free(dri2_sync);
- return NULL;
+ goto fail;
}
switch (type) {
* a generic EGL error that doesn't communicate user error.
*/
_eglError(EGL_BAD_ALLOC, "eglCreateSyncKHR");
- free(dri2_sync);
- return NULL;
+ goto fail;
}
break;
/* this can only happen if the cl_event passed in is invalid. */
if (!dri2_sync->fence) {
_eglError(EGL_BAD_ATTRIBUTE, "eglCreateSyncKHR");
- free(dri2_sync);
- return NULL;
+ goto fail;
}
/* the initial status must be "signaled" if the cl_event is signaled */
if (ret) {
_eglError(EGL_BAD_ACCESS, "eglCreateSyncKHR");
- free(dri2_sync);
- return NULL;
+ goto fail;
}
/* change clock attribute to CLOCK_MONOTONIC */
if (ret) {
_eglError(EGL_BAD_ACCESS, "eglCreateSyncKHR");
- free(dri2_sync);
- return NULL;
+ goto fail;
}
ret = pthread_cond_init(&dri2_sync->cond, &attr);
if (ret) {
_eglError(EGL_BAD_ACCESS, "eglCreateSyncKHR");
- free(dri2_sync);
- return NULL;
+ goto fail;
}
/* initial status of reusable sync must be "unsignaled" */
dri2_sync->base.SyncStatus = EGL_UNSIGNALED_KHR;
break;
+#ifdef HAVE_TIZEN_PLATFORM
+ case EGL_SYNC_NATIVE_FENCE_TIZEN:
+ 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");
+ goto fail;
+ }
+ break;
+ }
+#else
case EGL_SYNC_NATIVE_FENCE_ANDROID:
if (dri2_dpy->fence->create_fence_fd) {
dri2_sync->fence = dri2_dpy->fence->create_fence_fd(
return NULL;
}
break;
- }
+#endif
p_atomic_set(&dri2_sync->refcount, 1);
+ mtx_unlock(&dri2_dpy->lock);
+
return &dri2_sync->base;
+
+fail:
+ free(dri2_sync);
+ mtx_unlock(&dri2_dpy->lock);
+ return NULL;
}
static EGLBoolean
-dri2_destroy_sync(const _EGLDriver *drv, _EGLDisplay *disp, _EGLSync *sync)
+dri2_destroy_sync(_EGLDisplay *disp, _EGLSync *sync)
{
- struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+ struct dri2_egl_display *dri2_dpy = dri2_egl_display_lock(disp);
struct dri2_egl_sync *dri2_sync = dri2_egl_sync(sync);
EGLint ret = EGL_TRUE;
EGLint err;
dri2_egl_unref_sync(dri2_dpy, dri2_sync);
+ mtx_unlock(&dri2_dpy->lock);
+
return ret;
}
static EGLint
-dri2_dup_native_fence_fd(const _EGLDriver *drv, _EGLDisplay *disp, _EGLSync *sync)
+dri2_dup_native_fence_fd(_EGLDisplay *disp, _EGLSync *sync)
{
- struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+ struct dri2_egl_display *dri2_dpy = dri2_egl_display_lock(disp);
struct dri2_egl_sync *dri2_sync = dri2_egl_sync(sync);
assert(sync->Type == EGL_SYNC_NATIVE_FENCE_ANDROID);
dri2_sync->fence);
}
+ mtx_unlock(&dri2_dpy->lock);
+
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;
}
+ assert(sync_valid_fd(sync->SyncFd));
+
return os_dupfd_cloexec(sync->SyncFd);
}
+static EGLint
+dri2_dup_native_fence_fd_tizen(_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_TIZEN);
+
+ if (sync->SyncFd == EGL_NO_NATIVE_FENCE_FD_TIZEN) {
+ /* 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_TIZEN) {
+ /* if native fence fd still not created, return an error: */
+ _eglError(EGL_BAD_PARAMETER, "eglDupNativeFenceFDTIZEN");
+ return EGL_NO_NATIVE_FENCE_FD_TIZEN;
+ }
+
+ return dup(sync->SyncFd);
+}
+
static void
-dri2_set_blob_cache_funcs(const _EGLDriver *drv, _EGLDisplay *disp,
+dri2_set_blob_cache_funcs(_EGLDisplay *disp,
EGLSetBlobFuncANDROID set,
EGLGetBlobFuncANDROID get)
{
- struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
- dri2_dpy->blob->set_cache_funcs(dri2_dpy->dri_screen,
- disp->BlobCacheSet,
- disp->BlobCacheGet);
+ struct dri2_egl_display *dri2_dpy = dri2_egl_display_lock(disp);
+ dri2_dpy->blob->set_cache_funcs(dri2_dpy->dri_screen, set, get);
+ mtx_unlock(&dri2_dpy->lock);
}
static EGLint
-dri2_client_wait_sync(const _EGLDriver *drv, _EGLDisplay *disp, _EGLSync *sync,
+dri2_client_wait_sync(_EGLDisplay *disp, _EGLSync *sync,
EGLint flags, EGLTime timeout)
{
_EGLContext *ctx = _eglGetCurrentContext();
switch (sync->Type) {
case EGL_SYNC_FENCE_KHR:
+#ifdef HAVE_TIZEN_PLATFORM
+ case EGL_SYNC_NATIVE_FENCE_TIZEN:
+#else
case EGL_SYNC_NATIVE_FENCE_ANDROID:
+#endif
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,
ret = cnd_timedwait(&dri2_sync->cond, &dri2_sync->mutex, &expire);
mtx_unlock(&dri2_sync->mutex);
- if (ret == thrd_busy) {
+ if (ret == thrd_timedout) {
if (dri2_sync->base.SyncStatus == EGL_UNSIGNALED_KHR) {
ret = EGL_TIMEOUT_EXPIRED_KHR;
} else {
}
}
break;
- }
- dri2_egl_unref_sync(dri2_dpy, dri2_sync);
+ }
+
+ dri2_egl_unref_sync(dri2_dpy, dri2_sync);
- return ret;
+ return ret;
}
static EGLBoolean
-dri2_signal_sync(const _EGLDriver *drv, _EGLDisplay *disp, _EGLSync *sync,
- EGLenum mode)
+dri2_signal_sync(_EGLDisplay *disp, _EGLSync *sync, EGLenum mode)
{
struct dri2_egl_sync *dri2_sync = dri2_egl_sync(sync);
EGLint ret;
}
static EGLint
-dri2_server_wait_sync(const _EGLDriver *drv, _EGLDisplay *disp, _EGLSync *sync)
+dri2_server_wait_sync(_EGLDisplay *disp, _EGLSync *sync)
{
_EGLContext *ctx = _eglGetCurrentContext();
struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
return dri2_dpy->interop->export_object(dri2_ctx->dri_context, in, out);
}
+static int
+dri2_interop_flush_objects(_EGLDisplay *disp, _EGLContext *ctx,
+ unsigned count, struct mesa_glinterop_export_in *objects,
+ GLsync *sync)
+{
+ struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+ struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx);
+
+ if (!dri2_dpy->interop || dri2_dpy->interop->base.version < 2)
+ return MESA_GLINTEROP_UNSUPPORTED;
+
+ return dri2_dpy->interop->flush_objects(dri2_ctx->dri_context, count, objects, sync);
+}
+
const _EGLDriver _eglDriver = {
.Initialize = dri2_initialize,
.Terminate = dri2_terminate,
.UnbindWaylandDisplayWL = dri2_unbind_wayland_display_wl,
.QueryWaylandBufferWL = dri2_query_wayland_buffer_wl,
#endif
+#ifdef HAVE_TIZEN_PLATFORM
+ .BindWaylandDisplayWL = tizen_bind_wayland_display_wl,
+ .UnbindWaylandDisplayWL = tizen_unbind_wayland_display_wl,
+ .QueryWaylandBufferWL = tizen_query_wayland_buffer_wl,
+ #endif
.GetSyncValuesCHROMIUM = dri2_get_sync_values_chromium,
+ .GetMscRateANGLE = dri2_get_msc_rate_angle,
.CreateSyncKHR = dri2_create_sync,
.ClientWaitSyncKHR = dri2_client_wait_sync,
.SignalSyncKHR = dri2_signal_sync,
.DestroySyncKHR = dri2_destroy_sync,
.GLInteropQueryDeviceInfo = dri2_interop_query_device_info,
.GLInteropExportObject = dri2_interop_export_object,
+ .GLInteropFlushObjects = dri2_interop_flush_objects,
.DupNativeFenceFDANDROID = dri2_dup_native_fence_fd,
+ .DupNativeFenceFDTIZEN = dri2_dup_native_fence_fd_tizen,
.SetBlobCacheFuncsANDROID = dri2_set_blob_cache_funcs,
};