#include "glapi/glapi.h" /* for glapi functions */
#include "eglconfig.h"
+#include "eglconfigutil.h"
#include "eglcontext.h"
#include "egldisplay.h"
#include "egldriver.h"
-#include "eglglobals.h"
+#include "eglcurrent.h"
#include "egllog.h"
#include "eglsurface.h"
struct xdri_egl_driver
{
_EGLDriver Base; /**< base class */
+ void (*FlushCurrentContext)(void);
};
Display *dpy;
__GLXdisplayPrivate *dpyPriv;
__GLXDRIdisplay *driDisplay;
+ int driVersion;
__GLXscreenConfigs *psc;
EGLint scr;
_EGLConfig Base; /**< base class */
const __GLcontextModes *mode; /**< corresponding GLX mode */
+ EGLint window_render_buffer;
};
-/** cast wrapper */
-static INLINE struct xdri_egl_driver *
-xdri_egl_driver(_EGLDriver *drv)
-{
- return (struct xdri_egl_driver *) drv;
-}
-
-
-static INLINE struct xdri_egl_display *
-lookup_display(_EGLDisplay *dpy)
-{
- return (struct xdri_egl_display *) dpy->DriverData;
-}
+/* standard typecasts */
+_EGL_DRIVER_STANDARD_TYPECASTS(xdri_egl)
-
-/** Map EGLSurface handle to xdri_egl_surface object */
-static INLINE struct xdri_egl_surface *
-lookup_surface(_EGLSurface *surface)
-{
- return (struct xdri_egl_surface *) surface;
-}
-
-
-/** Map EGLContext handle to xdri_egl_context object */
-static INLINE struct xdri_egl_context *
-lookup_context(_EGLContext *context)
-{
- return (struct xdri_egl_context *) context;
-}
-
-
-/** Map EGLConfig handle to xdri_egl_config object */
-static INLINE struct xdri_egl_config *
-lookup_config(_EGLConfig *conf)
-{
- return (struct xdri_egl_config *) conf;
-}
+#define lookup_display(dpy) xdri_egl_display(dpy)
+#define lookup_context(ctx) xdri_egl_context(ctx)
+#define lookup_surface(surf) xdri_egl_surface(surf)
+#define lookup_config(conf) xdri_egl_config(conf)
/** Get size of given window */
}
+static EGLBoolean
+convert_config(_EGLConfig *conf, EGLint id, const __GLcontextModes *m)
+{
+ EGLint val;
+
+ if (!_eglConfigFromContextModesRec(conf, m, EGL_OPENGL_BIT, EGL_OPENGL_BIT))
+ return EGL_FALSE;
+
+ if (m->doubleBufferMode) {
+ /* pixmap and pbuffer surfaces are always single-buffered */
+ val = GET_CONFIG_ATTRIB(conf, EGL_SURFACE_TYPE);
+ val &= ~(EGL_PIXMAP_BIT | EGL_PBUFFER_BIT);
+ SET_CONFIG_ATTRIB(conf, EGL_SURFACE_TYPE, val);
+ }
+ else {
+ /* EGL requires OpenGL ES context to be double-buffered */
+ val = GET_CONFIG_ATTRIB(conf, EGL_RENDERABLE_TYPE);
+ val &= ~(EGL_OPENGL_ES_BIT | EGL_OPENGL_ES2_BIT);
+ SET_CONFIG_ATTRIB(conf, EGL_RENDERABLE_TYPE, val);
+ }
+ /* skip "empty" config */
+ if (!val)
+ return EGL_FALSE;
+
+ val = GET_CONFIG_ATTRIB(conf, EGL_SURFACE_TYPE);
+ if (!(val & EGL_PBUFFER_BIT)) {
+ /* bind-to-texture cannot be EGL_TRUE without pbuffer bit */
+ SET_CONFIG_ATTRIB(conf, EGL_BIND_TO_TEXTURE_RGB, EGL_FALSE);
+ SET_CONFIG_ATTRIB(conf, EGL_BIND_TO_TEXTURE_RGBA, EGL_FALSE);
+ }
+
+ /* EGL_NATIVE_RENDERABLE is a boolean */
+ val = GET_CONFIG_ATTRIB(conf, EGL_NATIVE_RENDERABLE);
+ if (val != EGL_TRUE)
+ SET_CONFIG_ATTRIB(conf, EGL_NATIVE_RENDERABLE, EGL_FALSE);
+
+ return _eglValidateConfig(conf, EGL_FALSE);
+}
+
+
/**
* Produce a set of EGL configs.
*/
static EGLint
create_configs(_EGLDisplay *disp, const __GLcontextModes *m, EGLint first_id)
{
- static const EGLint all_apis = (EGL_OPENGL_ES_BIT |
- EGL_OPENGL_ES2_BIT |
- EGL_OPENVG_BIT |
- EGL_OPENGL_BIT);
+ struct xdri_egl_display *xdri_dpy = lookup_display(disp);
int id = first_id;
for (; m; m = m->next) {
- /* add double buffered visual */
+ struct xdri_egl_config *xdri_conf;
+ _EGLConfig conf;
+ EGLint rb;
+
+ _eglInitConfig(&conf, disp, id);
+ if (!convert_config(&conf, id, m))
+ continue;
if (m->doubleBufferMode) {
- struct xdri_egl_config *config = CALLOC_STRUCT(xdri_egl_config);
-
- _eglInitConfig(&config->Base, id++);
-
- SET_CONFIG_ATTRIB(&config->Base, EGL_BUFFER_SIZE, m->rgbBits);
- SET_CONFIG_ATTRIB(&config->Base, EGL_RED_SIZE, m->redBits);
- SET_CONFIG_ATTRIB(&config->Base, EGL_GREEN_SIZE, m->greenBits);
- SET_CONFIG_ATTRIB(&config->Base, EGL_BLUE_SIZE, m->blueBits);
- SET_CONFIG_ATTRIB(&config->Base, EGL_ALPHA_SIZE, m->alphaBits);
- SET_CONFIG_ATTRIB(&config->Base, EGL_DEPTH_SIZE, m->depthBits);
- SET_CONFIG_ATTRIB(&config->Base, EGL_STENCIL_SIZE, m->stencilBits);
- SET_CONFIG_ATTRIB(&config->Base, EGL_SAMPLES, m->samples);
- SET_CONFIG_ATTRIB(&config->Base, EGL_SAMPLE_BUFFERS, m->sampleBuffers);
- SET_CONFIG_ATTRIB(&config->Base, EGL_NATIVE_VISUAL_ID, m->visualID);
- SET_CONFIG_ATTRIB(&config->Base, EGL_NATIVE_VISUAL_TYPE, m->visualType);
- SET_CONFIG_ATTRIB(&config->Base, EGL_CONFORMANT, all_apis);
- SET_CONFIG_ATTRIB(&config->Base, EGL_RENDERABLE_TYPE, all_apis);
- SET_CONFIG_ATTRIB(&config->Base, EGL_SURFACE_TYPE, EGL_WINDOW_BIT);
-
- /* XXX possibly other things to init... */
-
- /* Ptr from EGL config to GLcontextMode. Used in CreateContext(). */
- config->mode = m;
-
- _eglAddConfig(disp, &config->Base);
+ rb = EGL_BACK_BUFFER;
+ }
+ else {
+ /* ignore single-buffered mode for DRISW */
+ if (xdri_dpy->driVersion == 0)
+ continue;
+ rb = EGL_SINGLE_BUFFER;
+ }
+
+ xdri_conf = CALLOC_STRUCT(xdri_egl_config);
+ if (xdri_conf) {
+ memcpy(&xdri_conf->Base, &conf, sizeof(conf));
+ xdri_conf->mode = m;
+ xdri_conf->window_render_buffer = rb;
+ _eglAddConfig(disp, &xdri_conf->Base);
+ id++;
}
}
return _eglError(EGL_NOT_INITIALIZED, "eglInitialize");
}
- driDisplay = __driCreateDisplay(dpyPriv, NULL);
+ driDisplay = __driCreateDisplay(dpyPriv, &xdri_dpy->driVersion);
if (!driDisplay) {
_eglLog(_EGL_WARNING, "failed to create DRI display");
free(xdri_dpy);
return _eglError(EGL_NOT_INITIALIZED, "eglInitialize");
}
+ dpy->DriverData = xdri_dpy;
+ dpy->ClientAPIsMask = EGL_OPENGL_BIT;
+
/* add visuals and fbconfigs */
first_id = create_configs(dpy, psc->visuals, first_id);
create_configs(dpy, psc->configs, first_id);
- dpy->DriverData = xdri_dpy;
- dpy->ClientAPIsMask = (EGL_OPENGL_BIT |
- EGL_OPENGL_ES_BIT |
- EGL_OPENGL_ES2_BIT |
- EGL_OPENVG_BIT);
-
/* we're supporting EGL 1.4 */
*minor = 1;
*major = 4;
}
xdri_dpy->driDisplay->destroyDisplay(xdri_dpy->driDisplay);
- __glXRelease(xdri_dpy->dpyPriv);
free(xdri_dpy);
dpy->DriverData = NULL;
* Called from eglGetProcAddress() via drv->API.GetProcAddress().
*/
static _EGLProc
-xdri_eglGetProcAddress(const char *procname)
+xdri_eglGetProcAddress(_EGLDriver *drv, const char *procname)
{
/* the symbol is defined in libGL.so */
return (_EGLProc) _glapi_get_proc_address(procname);
return NULL;
}
- if (!_eglInitContext(drv, &xdri_ctx->Base, &xdri_config->Base, attrib_list)) {
+ if (!_eglInitContext(&xdri_ctx->Base, dpy, &xdri_config->Base, attrib_list)) {
free(xdri_ctx->dummy_gc);
free(xdri_ctx);
return NULL;
}
+ /* the config decides the render buffer for the context */
+ xdri_ctx->Base.WindowRenderBuffer = xdri_config->window_render_buffer;
+
xdri_ctx->driContext =
psc->driScreen->createContext(psc,
xdri_config->mode,
}
-static EGLBoolean
-xdri_eglDestroyContext(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx)
+/**
+ * Destroy a context.
+ */
+static void
+destroy_context(_EGLDisplay *dpy, _EGLContext *ctx)
{
struct xdri_egl_display *xdri_dpy = lookup_display(dpy);
struct xdri_egl_context *xdri_ctx = lookup_context(ctx);
- if (!_eglIsContextBound(ctx)) {
- xdri_ctx->driContext->destroyContext(xdri_ctx->driContext,
- xdri_dpy->psc, xdri_dpy->dpy);
- free(xdri_ctx->dummy_gc);
- free(xdri_ctx);
- }
+ /* FIXME a context might live longer than its display */
+ if (!dpy->Initialized)
+ _eglLog(_EGL_FATAL, "destroy a context with an unitialized display");
+
+ xdri_ctx->driContext->destroyContext(xdri_ctx->driContext,
+ xdri_dpy->psc, xdri_dpy->dpy);
+ free(xdri_ctx->dummy_gc);
+ free(xdri_ctx);
+}
+
+/**
+ * Destroy a surface.
+ */
+static void
+destroy_surface(_EGLDisplay *dpy, _EGLSurface *surf)
+{
+ struct xdri_egl_surface *xdri_surf = lookup_surface(surf);
+
+ if (!dpy->Initialized)
+ _eglLog(_EGL_FATAL, "destroy a surface with an unitialized display");
+
+ xdri_surf->driDrawable->destroyDrawable(xdri_surf->driDrawable);
+ free(xdri_surf);
+}
+
+
+static EGLBoolean
+xdri_eglDestroyContext(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx)
+{
+ if (!_eglIsContextBound(ctx))
+ destroy_context(dpy, ctx);
return EGL_TRUE;
}
xdri_eglMakeCurrent(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *d,
_EGLSurface *r, _EGLContext *context)
{
+ struct xdri_egl_driver *xdri_driver = xdri_egl_driver(drv);
struct xdri_egl_context *xdri_ctx = lookup_context(context);
struct xdri_egl_surface *draw = lookup_surface(d);
struct xdri_egl_surface *read = lookup_surface(r);
- if (!_eglMakeCurrent(drv, dpy, d, r, context))
+ /* bind the new context and return the "orphaned" one */
+ if (!_eglBindContext(&context, &d, &r))
return EGL_FALSE;
+ /* flush before context switch */
+ if (context && xdri_driver->FlushCurrentContext)
+ xdri_driver->FlushCurrentContext();
+
/* the symbol is defined in libGL.so */
_glapi_check_multithread();
return EGL_FALSE;
}
}
- else {
- _EGLContext *old = _eglGetCurrentContext();
- if (old) {
- xdri_ctx = lookup_context(old);
- xdri_ctx->driContext->unbindContext(xdri_ctx->driContext);
- }
+ else if (context) {
+ xdri_ctx = lookup_context(context);
+ xdri_ctx->driContext->unbindContext(xdri_ctx->driContext);
}
+ if (context && !_eglIsContextLinked(context))
+ destroy_context(dpy, context);
+ if (d && !_eglIsSurfaceLinked(d))
+ destroy_surface(dpy, d);
+ if (r && r != d && !_eglIsSurfaceLinked(r))
+ destroy_surface(dpy, r);
+
return EGL_TRUE;
}
*/
static _EGLSurface *
xdri_eglCreateWindowSurface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf,
- NativeWindowType window, const EGLint *attrib_list)
+ EGLNativeWindowType window,
+ const EGLint *attrib_list)
{
struct xdri_egl_display *xdri_dpy = lookup_display(dpy);
struct xdri_egl_config *xdri_config = lookup_config(conf);
return NULL;
}
- if (!_eglInitSurface(drv, &xdri_surf->Base, EGL_WINDOW_BIT,
+ if (!_eglInitSurface(&xdri_surf->Base, dpy, EGL_WINDOW_BIT,
&xdri_config->Base, attrib_list)) {
free(xdri_surf);
return NULL;
static EGLBoolean
xdri_eglDestroySurface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surface)
{
- struct xdri_egl_surface *xdri_surf = lookup_surface(surface);
-
- if (!_eglIsSurfaceBound(&xdri_surf->Base)) {
- xdri_surf->driDrawable->destroyDrawable(xdri_surf->driDrawable);
- free(xdri_surf);
- }
-
+ if (!_eglIsSurfaceBound(surface))
+ destroy_surface(dpy, surface);
return EGL_TRUE;
}
static EGLBoolean
xdri_eglSwapBuffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *draw)
{
+ struct xdri_egl_driver *xdri_driver = xdri_egl_driver(drv);
struct xdri_egl_display *xdri_dpy = lookup_display(dpy);
struct xdri_egl_surface *xdri_surf = lookup_surface(draw);
- xdri_dpy->psc->driScreen->swapBuffers(xdri_surf->driDrawable);
+ /* swapBuffers does not flush commands */
+ if (draw->CurrentContext && xdri_driver->FlushCurrentContext)
+ xdri_driver->FlushCurrentContext();
+
+ xdri_dpy->psc->driScreen->swapBuffers(xdri_surf->driDrawable, 0, 0, 0);
return EGL_TRUE;
}
xdri_drv->Base.Name = "X/DRI";
xdri_drv->Base.Unload = xdri_Unload;
+ /* we need a way to flush commands */
+ xdri_drv->FlushCurrentContext =
+ (void (*)(void)) xdri_eglGetProcAddress(&xdri_drv->Base, "glFlush");
+
return &xdri_drv->Base;
}