2008-11-02 08:26:08 -07:00
|
|
|
/*
|
|
|
|
* Copyright © 2007 Red Hat, Inc
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, distribute, and sell this software
|
|
|
|
* and its documentation for any purpose is hereby granted without
|
|
|
|
* fee, provided that the above copyright notice appear in all copies
|
|
|
|
* and that both that copyright notice and this permission notice
|
|
|
|
* appear in supporting documentation, and that the name of Red Hat,
|
|
|
|
* Inc not be used in advertising or publicity pertaining to
|
|
|
|
* distribution of the software without specific, written prior
|
|
|
|
* permission. Red Hat, Inc makes no representations about the
|
|
|
|
* suitability of this software for any purpose. It is provided "as
|
|
|
|
* is" without express or implied warranty.
|
|
|
|
*
|
|
|
|
* RED HAT, INC DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
|
|
|
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
|
|
|
|
* NO EVENT SHALL RED HAT, INC BE LIABLE FOR ANY SPECIAL, INDIRECT OR
|
|
|
|
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
|
|
|
|
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
|
|
|
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_DIX_CONFIG_H
|
|
|
|
#include <dix-config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <dlfcn.h>
|
|
|
|
|
|
|
|
#include <drm.h>
|
|
|
|
#include <GL/gl.h>
|
|
|
|
#include <GL/internal/dri_interface.h>
|
|
|
|
#include <GL/glxtokens.h>
|
|
|
|
|
|
|
|
#include <windowstr.h>
|
|
|
|
#include <os.h>
|
|
|
|
|
|
|
|
#define _XF86DRI_SERVER_
|
|
|
|
#include <xf86drm.h>
|
|
|
|
#include <xf86.h>
|
|
|
|
#include <dri2.h>
|
|
|
|
|
|
|
|
#include "glxserver.h"
|
|
|
|
#include "glxutil.h"
|
|
|
|
#include "glxdricommon.h"
|
2013-06-07 11:28:45 -06:00
|
|
|
#include <GL/glxtokens.h>
|
2008-11-02 08:26:08 -07:00
|
|
|
|
|
|
|
#include "extension_string.h"
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
typedef struct __GLXDRIscreen __GLXDRIscreen;
|
|
|
|
typedef struct __GLXDRIcontext __GLXDRIcontext;
|
2008-11-02 08:26:08 -07:00
|
|
|
typedef struct __GLXDRIdrawable __GLXDRIdrawable;
|
|
|
|
|
2013-06-07 11:28:45 -06:00
|
|
|
#define ALL_DRI_CTX_FLAGS (__DRI_CTX_FLAG_DEBUG \
|
|
|
|
| __DRI_CTX_FLAG_FORWARD_COMPATIBLE \
|
|
|
|
| __DRI_CTX_FLAG_ROBUST_BUFFER_ACCESS)
|
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
struct __GLXDRIscreen {
|
2012-06-10 07:21:05 -06:00
|
|
|
__GLXscreen base;
|
|
|
|
__DRIscreen *driScreen;
|
|
|
|
void *driver;
|
|
|
|
int fd;
|
2008-11-02 08:26:08 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
xf86EnterVTProc *enterVT;
|
|
|
|
xf86LeaveVTProc *leaveVT;
|
2008-11-02 08:26:08 -07:00
|
|
|
|
|
|
|
const __DRIcoreExtension *core;
|
2009-09-06 13:44:18 -06:00
|
|
|
const __DRIdri2Extension *dri2;
|
2010-07-27 13:02:24 -06:00
|
|
|
const __DRI2flushExtension *flush;
|
2008-11-02 08:26:08 -07:00
|
|
|
const __DRIcopySubBufferExtension *copySubBuffer;
|
|
|
|
const __DRIswapControlExtension *swapControl;
|
|
|
|
const __DRItexBufferExtension *texBuffer;
|
2012-06-10 07:21:05 -06:00
|
|
|
const __DRIconfig **driConfigs;
|
2008-11-02 08:26:08 -07:00
|
|
|
|
|
|
|
unsigned char glx_enable_bits[__GLX_EXT_BYTES];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct __GLXDRIcontext {
|
2012-06-10 07:21:05 -06:00
|
|
|
__GLXcontext base;
|
|
|
|
__DRIcontext *driContext;
|
2008-11-02 08:26:08 -07:00
|
|
|
};
|
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
#define MAX_DRAWABLE_BUFFERS 5
|
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
struct __GLXDRIdrawable {
|
2012-06-10 07:21:05 -06:00
|
|
|
__GLXdrawable base;
|
|
|
|
__DRIdrawable *driDrawable;
|
|
|
|
__GLXDRIscreen *screen;
|
2009-09-06 13:44:18 -06:00
|
|
|
|
|
|
|
/* Dimensions as last reported by DRI2GetBuffers. */
|
|
|
|
int width;
|
|
|
|
int height;
|
|
|
|
__DRIbuffer buffers[MAX_DRAWABLE_BUFFERS];
|
|
|
|
int count;
|
2013-06-07 11:28:45 -06:00
|
|
|
XID dri2_id;
|
2008-11-02 08:26:08 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2012-06-10 07:21:05 -06:00
|
|
|
__glXDRIdrawableDestroy(__GLXdrawable * drawable)
|
2008-11-02 08:26:08 -07:00
|
|
|
{
|
|
|
|
__GLXDRIdrawable *private = (__GLXDRIdrawable *) drawable;
|
|
|
|
const __DRIcoreExtension *core = private->screen->core;
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2013-06-07 11:28:45 -06:00
|
|
|
FreeResource(private->dri2_id, FALSE);
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
(*core->destroyDrawable) (private->driDrawable);
|
2008-11-02 08:26:08 -07:00
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
__glXDrawableRelease(drawable);
|
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
free(private);
|
2008-11-02 08:26:08 -07:00
|
|
|
}
|
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
static void
|
2014-09-27 11:52:59 -06:00
|
|
|
copy_box(__GLXdrawable * drawable,
|
|
|
|
int dst, int src,
|
|
|
|
int x, int y, int w, int h)
|
2008-11-02 08:26:08 -07:00
|
|
|
{
|
2009-09-06 13:44:18 -06:00
|
|
|
BoxRec box;
|
|
|
|
RegionRec region;
|
2014-09-27 11:52:59 -06:00
|
|
|
__GLXcontext *cx = lastGLContext;
|
2008-11-02 08:26:08 -07:00
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
box.x1 = x;
|
2014-09-27 11:52:59 -06:00
|
|
|
box.y1 = y;
|
2009-09-06 13:44:18 -06:00
|
|
|
box.x2 = x + w;
|
2014-09-27 11:52:59 -06:00
|
|
|
box.y2 = y + h;
|
2010-12-05 08:36:02 -07:00
|
|
|
RegionInit(®ion, &box, 0);
|
2009-09-06 13:44:18 -06:00
|
|
|
|
2014-09-27 11:52:59 -06:00
|
|
|
DRI2CopyRegion(drawable->pDraw, ®ion, dst, src);
|
|
|
|
if (cx != lastGLContext) {
|
|
|
|
lastGLContext = cx;
|
|
|
|
cx->makeCurrent(cx);
|
|
|
|
}
|
2008-11-02 08:26:08 -07:00
|
|
|
}
|
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
static void
|
2014-09-27 11:52:59 -06:00
|
|
|
__glXDRIdrawableCopySubBuffer(__GLXdrawable * drawable,
|
|
|
|
int x, int y, int w, int h)
|
2008-11-02 08:26:08 -07:00
|
|
|
{
|
|
|
|
__GLXDRIdrawable *private = (__GLXDRIdrawable *) drawable;
|
|
|
|
|
2014-09-27 11:52:59 -06:00
|
|
|
copy_box(drawable, x, private->height - y - h,
|
|
|
|
w, h,
|
|
|
|
DRI2BufferFrontLeft, DRI2BufferBackLeft);
|
|
|
|
}
|
2008-11-02 08:26:08 -07:00
|
|
|
|
2014-09-27 11:52:59 -06:00
|
|
|
static void
|
|
|
|
__glXDRIdrawableWaitX(__GLXdrawable * drawable)
|
|
|
|
{
|
|
|
|
__GLXDRIdrawable *private = (__GLXDRIdrawable *) drawable;
|
|
|
|
|
|
|
|
copy_box(drawable, DRI2BufferFakeFrontLeft, DRI2BufferFrontLeft,
|
|
|
|
0, 0, private->width, private->height);
|
2008-11-02 08:26:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-06-10 07:21:05 -06:00
|
|
|
__glXDRIdrawableWaitGL(__GLXdrawable * drawable)
|
2008-11-02 08:26:08 -07:00
|
|
|
{
|
2009-09-06 13:44:18 -06:00
|
|
|
__GLXDRIdrawable *private = (__GLXDRIdrawable *) drawable;
|
2008-11-02 08:26:08 -07:00
|
|
|
|
2014-09-27 11:52:59 -06:00
|
|
|
copy_box(drawable, DRI2BufferFrontLeft, DRI2BufferFakeFrontLeft,
|
|
|
|
0, 0, private->width, private->height);
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
static void
|
|
|
|
__glXdriSwapEvent(ClientPtr client, void *data, int type, CARD64 ust,
|
2012-06-10 07:21:05 -06:00
|
|
|
CARD64 msc, CARD32 sbc)
|
2010-07-27 13:02:24 -06:00
|
|
|
{
|
|
|
|
__GLXdrawable *drawable = data;
|
2014-05-02 13:27:46 -06:00
|
|
|
int glx_type;
|
2010-07-27 13:02:24 -06:00
|
|
|
switch (type) {
|
|
|
|
case DRI2_EXCHANGE_COMPLETE:
|
2014-05-02 13:27:46 -06:00
|
|
|
glx_type = GLX_EXCHANGE_COMPLETE_INTEL;
|
2012-06-10 07:21:05 -06:00
|
|
|
break;
|
2014-05-02 13:27:46 -06:00
|
|
|
default:
|
|
|
|
/* unknown swap completion type,
|
|
|
|
* BLIT is a reasonable default, so
|
|
|
|
* fall through ...
|
|
|
|
*/
|
2010-07-27 13:02:24 -06:00
|
|
|
case DRI2_BLIT_COMPLETE:
|
2014-05-02 13:27:46 -06:00
|
|
|
glx_type = GLX_BLIT_COMPLETE_INTEL;
|
2012-06-10 07:21:05 -06:00
|
|
|
break;
|
2010-07-27 13:02:24 -06:00
|
|
|
case DRI2_FLIP_COMPLETE:
|
2014-05-02 13:27:46 -06:00
|
|
|
glx_type = GLX_FLIP_COMPLETE_INTEL;
|
2012-06-10 07:21:05 -06:00
|
|
|
break;
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|
2015-09-16 13:10:19 -06:00
|
|
|
|
2014-05-02 13:27:46 -06:00
|
|
|
__glXsendSwapEvent(drawable, glx_type, ust, msc, sbc);
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copy or flip back to front, honoring the swap interval if possible.
|
|
|
|
*
|
|
|
|
* If the kernel supports it, we request an event for the frame when the
|
|
|
|
* swap should happen, then perform the copy when we receive it.
|
|
|
|
*/
|
|
|
|
static GLboolean
|
2012-06-10 07:21:05 -06:00
|
|
|
__glXDRIdrawableSwapBuffers(ClientPtr client, __GLXdrawable * drawable)
|
2010-07-27 13:02:24 -06:00
|
|
|
{
|
|
|
|
__GLXDRIdrawable *priv = (__GLXDRIdrawable *) drawable;
|
|
|
|
__GLXDRIscreen *screen = priv->screen;
|
|
|
|
CARD64 unused;
|
2014-09-27 11:52:59 -06:00
|
|
|
__GLXcontext *cx = lastGLContext;
|
|
|
|
int status;
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
if (screen->flush) {
|
2012-06-10 07:21:05 -06:00
|
|
|
(*screen->flush->flush) (priv->driDrawable);
|
|
|
|
(*screen->flush->invalidate) (priv->driDrawable);
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|
|
|
|
|
2014-09-27 11:52:59 -06:00
|
|
|
status = DRI2SwapBuffers(client, drawable->pDraw, 0, 0, 0, &unused,
|
|
|
|
__glXdriSwapEvent, drawable);
|
|
|
|
if (cx != lastGLContext) {
|
|
|
|
lastGLContext = cx;
|
|
|
|
cx->makeCurrent(cx);
|
|
|
|
}
|
2010-07-27 13:02:24 -06:00
|
|
|
|
2014-09-27 11:52:59 -06:00
|
|
|
return status == Success;
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
static int
|
2012-06-10 07:21:05 -06:00
|
|
|
__glXDRIdrawableSwapInterval(__GLXdrawable * drawable, int interval)
|
2009-09-06 13:44:18 -06:00
|
|
|
{
|
2014-09-27 11:52:59 -06:00
|
|
|
__GLXcontext *cx = lastGLContext;
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (interval <= 0) /* || interval > BIGNUM? */
|
|
|
|
return GLX_BAD_VALUE;
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
DRI2SwapInterval(drawable->pDraw, interval);
|
2014-09-27 11:52:59 -06:00
|
|
|
if (cx != lastGLContext) {
|
|
|
|
lastGLContext = cx;
|
|
|
|
cx->makeCurrent(cx);
|
|
|
|
}
|
2010-07-27 13:02:24 -06:00
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
return 0;
|
2008-11-02 08:26:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-06-10 07:21:05 -06:00
|
|
|
__glXDRIcontextDestroy(__GLXcontext * baseContext)
|
2008-11-02 08:26:08 -07:00
|
|
|
{
|
|
|
|
__GLXDRIcontext *context = (__GLXDRIcontext *) baseContext;
|
|
|
|
__GLXDRIscreen *screen = (__GLXDRIscreen *) context->base.pGlxScreen;
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
(*screen->core->destroyContext) (context->driContext);
|
2008-11-02 08:26:08 -07:00
|
|
|
__glXContextDestroy(&context->base);
|
2010-12-05 08:36:02 -07:00
|
|
|
free(context);
|
2008-11-02 08:26:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2012-06-10 07:21:05 -06:00
|
|
|
__glXDRIcontextMakeCurrent(__GLXcontext * baseContext)
|
2008-11-02 08:26:08 -07:00
|
|
|
{
|
|
|
|
__GLXDRIcontext *context = (__GLXDRIcontext *) baseContext;
|
|
|
|
__GLXDRIdrawable *draw = (__GLXDRIdrawable *) baseContext->drawPriv;
|
|
|
|
__GLXDRIdrawable *read = (__GLXDRIdrawable *) baseContext->readPriv;
|
|
|
|
__GLXDRIscreen *screen = (__GLXDRIscreen *) context->base.pGlxScreen;
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
return (*screen->core->bindContext) (context->driContext,
|
|
|
|
draw->driDrawable, read->driDrawable);
|
|
|
|
}
|
2008-11-02 08:26:08 -07:00
|
|
|
|
|
|
|
static int
|
2012-06-10 07:21:05 -06:00
|
|
|
__glXDRIcontextLoseCurrent(__GLXcontext * baseContext)
|
2008-11-02 08:26:08 -07:00
|
|
|
{
|
|
|
|
__GLXDRIcontext *context = (__GLXDRIcontext *) baseContext;
|
|
|
|
__GLXDRIscreen *screen = (__GLXDRIscreen *) context->base.pGlxScreen;
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
return (*screen->core->unbindContext) (context->driContext);
|
2008-11-02 08:26:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2012-06-10 07:21:05 -06:00
|
|
|
__glXDRIcontextCopy(__GLXcontext * baseDst, __GLXcontext * baseSrc,
|
|
|
|
unsigned long mask)
|
2008-11-02 08:26:08 -07:00
|
|
|
{
|
|
|
|
__GLXDRIcontext *dst = (__GLXDRIcontext *) baseDst;
|
|
|
|
__GLXDRIcontext *src = (__GLXDRIcontext *) baseSrc;
|
|
|
|
__GLXDRIscreen *screen = (__GLXDRIscreen *) dst->base.pGlxScreen;
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
return (*screen->core->copyContext) (dst->driContext,
|
|
|
|
src->driContext, mask);
|
2008-11-02 08:26:08 -07:00
|
|
|
}
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
static Bool
|
2012-06-10 07:21:05 -06:00
|
|
|
__glXDRIcontextWait(__GLXcontext * baseContext,
|
|
|
|
__GLXclientState * cl, int *error)
|
2010-07-27 13:02:24 -06:00
|
|
|
{
|
2014-09-27 11:52:59 -06:00
|
|
|
__GLXcontext *cx = lastGLContext;
|
|
|
|
Bool ret;
|
|
|
|
|
|
|
|
ret = DRI2WaitSwap(cl->client, baseContext->drawPriv->pDraw);
|
|
|
|
if (cx != lastGLContext) {
|
|
|
|
lastGLContext = cx;
|
|
|
|
cx->makeCurrent(cx);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret) {
|
2012-06-10 07:21:05 -06:00
|
|
|
*error = cl->client->noClientException;
|
|
|
|
return TRUE;
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
static int
|
2012-06-10 07:21:05 -06:00
|
|
|
__glXDRIbindTexImage(__GLXcontext * baseContext,
|
|
|
|
int buffer, __GLXdrawable * glxPixmap)
|
2008-11-02 08:26:08 -07:00
|
|
|
{
|
|
|
|
__GLXDRIdrawable *drawable = (__GLXDRIdrawable *) glxPixmap;
|
|
|
|
const __DRItexBufferExtension *texBuffer = drawable->screen->texBuffer;
|
|
|
|
__GLXDRIcontext *context = (__GLXDRIcontext *) baseContext;
|
|
|
|
|
|
|
|
if (texBuffer == NULL)
|
|
|
|
return Success;
|
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
if (texBuffer->base.version >= 2 && texBuffer->setTexBuffer2 != NULL) {
|
2012-06-10 07:21:05 -06:00
|
|
|
(*texBuffer->setTexBuffer2) (context->driContext,
|
|
|
|
glxPixmap->target,
|
|
|
|
glxPixmap->format, drawable->driDrawable);
|
|
|
|
}
|
|
|
|
else
|
2009-09-06 13:44:18 -06:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
texBuffer->setTexBuffer(context->driContext,
|
|
|
|
glxPixmap->target, drawable->driDrawable);
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
2008-11-02 08:26:08 -07:00
|
|
|
|
|
|
|
return Success;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2012-06-10 07:21:05 -06:00
|
|
|
__glXDRIreleaseTexImage(__GLXcontext * baseContext,
|
|
|
|
int buffer, __GLXdrawable * pixmap)
|
2008-11-02 08:26:08 -07:00
|
|
|
{
|
|
|
|
/* FIXME: Just unbind the texture? */
|
|
|
|
return Success;
|
|
|
|
}
|
|
|
|
|
|
|
|
static __GLXtextureFromPixmap __glXDRItextureFromPixmap = {
|
|
|
|
__glXDRIbindTexImage,
|
|
|
|
__glXDRIreleaseTexImage
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2012-06-10 07:21:05 -06:00
|
|
|
__glXDRIscreenDestroy(__GLXscreen * baseScreen)
|
2008-11-02 08:26:08 -07:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
int i;
|
|
|
|
|
2014-05-02 13:27:46 -06:00
|
|
|
ScrnInfoPtr pScrn = xf86ScreenToScrn(baseScreen->pScreen);
|
2008-11-02 08:26:08 -07:00
|
|
|
__GLXDRIscreen *screen = (__GLXDRIscreen *) baseScreen;
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
(*screen->core->destroyScreen) (screen->driScreen);
|
2008-11-02 08:26:08 -07:00
|
|
|
|
|
|
|
dlclose(screen->driver);
|
|
|
|
|
|
|
|
__glXScreenDestroy(baseScreen);
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (screen->driConfigs) {
|
|
|
|
for (i = 0; screen->driConfigs[i] != NULL; i++)
|
|
|
|
free((__DRIconfig **) screen->driConfigs[i]);
|
|
|
|
free(screen->driConfigs);
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:27:46 -06:00
|
|
|
pScrn->EnterVT = screen->enterVT;
|
|
|
|
pScrn->LeaveVT = screen->leaveVT;
|
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
free(screen);
|
2008-11-02 08:26:08 -07:00
|
|
|
}
|
|
|
|
|
2013-06-07 11:28:45 -06:00
|
|
|
static Bool
|
|
|
|
dri2_convert_glx_attribs(__GLXDRIscreen *screen, unsigned num_attribs,
|
|
|
|
const uint32_t *attribs,
|
|
|
|
unsigned *major_ver, unsigned *minor_ver,
|
|
|
|
uint32_t *flags, int *api, int *reset, unsigned *error)
|
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
if (num_attribs == 0)
|
|
|
|
return True;
|
|
|
|
|
|
|
|
if (attribs == NULL) {
|
|
|
|
*error = BadImplementation;
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
|
|
|
|
*major_ver = 1;
|
|
|
|
*minor_ver = 0;
|
|
|
|
*reset = __DRI_CTX_RESET_NO_NOTIFICATION;
|
|
|
|
|
|
|
|
for (i = 0; i < num_attribs; i++) {
|
|
|
|
switch (attribs[i * 2]) {
|
|
|
|
case GLX_CONTEXT_MAJOR_VERSION_ARB:
|
|
|
|
*major_ver = attribs[i * 2 + 1];
|
|
|
|
break;
|
|
|
|
case GLX_CONTEXT_MINOR_VERSION_ARB:
|
|
|
|
*minor_ver = attribs[i * 2 + 1];
|
|
|
|
break;
|
|
|
|
case GLX_CONTEXT_FLAGS_ARB:
|
|
|
|
*flags = attribs[i * 2 + 1];
|
|
|
|
break;
|
|
|
|
case GLX_RENDER_TYPE:
|
|
|
|
break;
|
|
|
|
case GLX_CONTEXT_PROFILE_MASK_ARB:
|
|
|
|
switch (attribs[i * 2 + 1]) {
|
|
|
|
case GLX_CONTEXT_CORE_PROFILE_BIT_ARB:
|
|
|
|
*api = __DRI_API_OPENGL_CORE;
|
|
|
|
break;
|
|
|
|
case GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB:
|
|
|
|
*api = __DRI_API_OPENGL;
|
|
|
|
break;
|
|
|
|
case GLX_CONTEXT_ES2_PROFILE_BIT_EXT:
|
|
|
|
*api = __DRI_API_GLES2;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
*error = __glXError(GLXBadProfileARB);
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GLX_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB:
|
|
|
|
if (screen->dri2->base.version >= 4) {
|
|
|
|
*error = BadValue;
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (attribs[i * 2 + 1]) {
|
|
|
|
case GLX_NO_RESET_NOTIFICATION_ARB:
|
|
|
|
*reset = __DRI_CTX_RESET_NO_NOTIFICATION;
|
|
|
|
break;
|
|
|
|
case GLX_LOSE_CONTEXT_ON_RESET_ARB:
|
|
|
|
*reset = __DRI_CTX_RESET_LOSE_CONTEXT;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
*error = BadValue;
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* If an unknown attribute is received, fail.
|
|
|
|
*/
|
|
|
|
*error = BadValue;
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Unknown flag value.
|
|
|
|
*/
|
|
|
|
if ((*flags & ~ALL_DRI_CTX_FLAGS) != 0) {
|
|
|
|
*error = BadValue;
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If the core profile is requested for a GL version is less than 3.2,
|
|
|
|
* request the non-core profile from the DRI driver. The core profile
|
|
|
|
* only makes sense for GL versions >= 3.2, and many DRI drivers that
|
|
|
|
* don't support OpenGL 3.2 may fail the request for a core profile.
|
|
|
|
*/
|
|
|
|
if (*api == __DRI_API_OPENGL_CORE
|
|
|
|
&& (*major_ver < 3 || (*major_ver == 3 && *minor_ver < 2))) {
|
|
|
|
*api = __DRI_API_OPENGL;
|
|
|
|
}
|
|
|
|
|
|
|
|
*error = Success;
|
|
|
|
return True;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
create_driver_context(__GLXDRIcontext * context,
|
|
|
|
__GLXDRIscreen * screen,
|
|
|
|
__GLXDRIconfig * config,
|
|
|
|
__DRIcontext * driShare,
|
|
|
|
unsigned num_attribs,
|
|
|
|
const uint32_t *attribs,
|
|
|
|
int *error)
|
|
|
|
{
|
|
|
|
context->driContext = NULL;
|
|
|
|
|
|
|
|
if (screen->dri2->base.version >= 3) {
|
2015-09-16 13:10:19 -06:00
|
|
|
uint32_t ctx_attribs[4 * 2];
|
2013-06-07 11:28:45 -06:00
|
|
|
unsigned num_ctx_attribs = 0;
|
|
|
|
unsigned dri_err = 0;
|
|
|
|
unsigned major_ver;
|
|
|
|
unsigned minor_ver;
|
2014-09-27 11:52:59 -06:00
|
|
|
uint32_t flags = 0;
|
2013-06-07 11:28:45 -06:00
|
|
|
int reset;
|
|
|
|
int api = __DRI_API_OPENGL;
|
|
|
|
|
|
|
|
if (num_attribs != 0) {
|
|
|
|
if (!dri2_convert_glx_attribs(screen, num_attribs, attribs,
|
|
|
|
&major_ver, &minor_ver,
|
|
|
|
&flags, &api, &reset,
|
|
|
|
(unsigned *) error))
|
|
|
|
return;
|
|
|
|
|
|
|
|
ctx_attribs[num_ctx_attribs++] = __DRI_CTX_ATTRIB_MAJOR_VERSION;
|
|
|
|
ctx_attribs[num_ctx_attribs++] = major_ver;
|
|
|
|
ctx_attribs[num_ctx_attribs++] = __DRI_CTX_ATTRIB_MINOR_VERSION;
|
|
|
|
ctx_attribs[num_ctx_attribs++] = minor_ver;
|
|
|
|
|
|
|
|
if (flags != 0) {
|
|
|
|
ctx_attribs[num_ctx_attribs++] = __DRI_CTX_ATTRIB_FLAGS;
|
|
|
|
|
|
|
|
/* The current __DRI_CTX_FLAG_* values are identical to the
|
|
|
|
* GLX_CONTEXT_*_BIT values.
|
|
|
|
*/
|
|
|
|
ctx_attribs[num_ctx_attribs++] = flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (reset != __DRI_CTX_RESET_NO_NOTIFICATION) {
|
|
|
|
ctx_attribs[num_ctx_attribs++] =
|
|
|
|
__DRI_CTX_ATTRIB_RESET_STRATEGY;
|
|
|
|
ctx_attribs[num_ctx_attribs++] = reset;
|
|
|
|
}
|
2015-09-16 13:10:19 -06:00
|
|
|
|
|
|
|
assert(num_ctx_attribs <= ARRAY_SIZE(ctx_attribs));
|
2013-06-07 11:28:45 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
context->driContext =
|
|
|
|
(*screen->dri2->createContextAttribs)(screen->driScreen,
|
|
|
|
api,
|
|
|
|
config->driConfig,
|
|
|
|
driShare,
|
|
|
|
num_ctx_attribs / 2,
|
|
|
|
ctx_attribs,
|
|
|
|
&dri_err,
|
|
|
|
context);
|
|
|
|
|
|
|
|
switch (dri_err) {
|
|
|
|
case __DRI_CTX_ERROR_SUCCESS:
|
|
|
|
*error = Success;
|
|
|
|
break;
|
|
|
|
case __DRI_CTX_ERROR_NO_MEMORY:
|
|
|
|
*error = BadAlloc;
|
|
|
|
break;
|
|
|
|
case __DRI_CTX_ERROR_BAD_API:
|
|
|
|
*error = __glXError(GLXBadProfileARB);
|
|
|
|
break;
|
|
|
|
case __DRI_CTX_ERROR_BAD_VERSION:
|
|
|
|
case __DRI_CTX_ERROR_BAD_FLAG:
|
|
|
|
*error = __glXError(GLXBadFBConfig);
|
|
|
|
break;
|
|
|
|
case __DRI_CTX_ERROR_UNKNOWN_ATTRIBUTE:
|
|
|
|
case __DRI_CTX_ERROR_UNKNOWN_FLAG:
|
|
|
|
default:
|
|
|
|
*error = BadValue;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (num_attribs != 0) {
|
|
|
|
*error = BadValue;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
context->driContext =
|
|
|
|
(*screen->dri2->createNewContext) (screen->driScreen,
|
|
|
|
config->driConfig,
|
|
|
|
driShare, context);
|
|
|
|
}
|
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
static __GLXcontext *
|
2012-06-10 07:21:05 -06:00
|
|
|
__glXDRIscreenCreateContext(__GLXscreen * baseScreen,
|
|
|
|
__GLXconfig * glxConfig,
|
2013-06-07 11:28:45 -06:00
|
|
|
__GLXcontext * baseShareContext,
|
|
|
|
unsigned num_attribs,
|
|
|
|
const uint32_t *attribs,
|
|
|
|
int *error)
|
2008-11-02 08:26:08 -07:00
|
|
|
{
|
|
|
|
__GLXDRIscreen *screen = (__GLXDRIscreen *) baseScreen;
|
|
|
|
__GLXDRIcontext *context, *shareContext;
|
|
|
|
__GLXDRIconfig *config = (__GLXDRIconfig *) glxConfig;
|
|
|
|
__DRIcontext *driShare;
|
|
|
|
|
|
|
|
shareContext = (__GLXDRIcontext *) baseShareContext;
|
|
|
|
if (shareContext)
|
2012-06-10 07:21:05 -06:00
|
|
|
driShare = shareContext->driContext;
|
2008-11-02 08:26:08 -07:00
|
|
|
else
|
2012-06-10 07:21:05 -06:00
|
|
|
driShare = NULL;
|
2008-11-02 08:26:08 -07:00
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
context = calloc(1, sizeof *context);
|
2013-06-07 11:28:45 -06:00
|
|
|
if (context == NULL) {
|
|
|
|
*error = BadAlloc;
|
2012-06-10 07:21:05 -06:00
|
|
|
return NULL;
|
2013-06-07 11:28:45 -06:00
|
|
|
}
|
2008-11-02 08:26:08 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
context->base.destroy = __glXDRIcontextDestroy;
|
|
|
|
context->base.makeCurrent = __glXDRIcontextMakeCurrent;
|
|
|
|
context->base.loseCurrent = __glXDRIcontextLoseCurrent;
|
|
|
|
context->base.copy = __glXDRIcontextCopy;
|
2008-11-02 08:26:08 -07:00
|
|
|
context->base.textureFromPixmap = &__glXDRItextureFromPixmap;
|
2012-06-10 07:21:05 -06:00
|
|
|
context->base.wait = __glXDRIcontextWait;
|
2008-11-02 08:26:08 -07:00
|
|
|
|
2013-06-07 11:28:45 -06:00
|
|
|
create_driver_context(context, screen, config, driShare, num_attribs,
|
|
|
|
attribs, error);
|
2009-09-06 13:44:18 -06:00
|
|
|
if (context->driContext == NULL) {
|
2012-06-10 07:21:05 -06:00
|
|
|
free(context);
|
2009-09-06 13:44:18 -06:00
|
|
|
return NULL;
|
|
|
|
}
|
2008-11-02 08:26:08 -07:00
|
|
|
|
|
|
|
return &context->base;
|
|
|
|
}
|
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
static void
|
2012-06-10 07:21:05 -06:00
|
|
|
__glXDRIinvalidateBuffers(DrawablePtr pDraw, void *priv, XID id)
|
2010-12-05 08:36:02 -07:00
|
|
|
{
|
|
|
|
__GLXDRIdrawable *private = priv;
|
|
|
|
__GLXDRIscreen *screen = private->screen;
|
|
|
|
|
|
|
|
if (screen->flush)
|
2012-06-10 07:21:05 -06:00
|
|
|
(*screen->flush->invalidate) (private->driDrawable);
|
2010-12-05 08:36:02 -07:00
|
|
|
}
|
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
static __GLXdrawable *
|
2010-07-27 13:02:24 -06:00
|
|
|
__glXDRIscreenCreateDrawable(ClientPtr client,
|
2012-06-10 07:21:05 -06:00
|
|
|
__GLXscreen * screen,
|
|
|
|
DrawablePtr pDraw,
|
|
|
|
XID drawId,
|
|
|
|
int type, XID glxDrawId, __GLXconfig * glxConfig)
|
2008-11-02 08:26:08 -07:00
|
|
|
{
|
|
|
|
__GLXDRIscreen *driScreen = (__GLXDRIscreen *) screen;
|
|
|
|
__GLXDRIconfig *config = (__GLXDRIconfig *) glxConfig;
|
|
|
|
__GLXDRIdrawable *private;
|
2014-09-27 11:52:59 -06:00
|
|
|
__GLXcontext *cx = lastGLContext;
|
|
|
|
Bool ret;
|
2008-11-02 08:26:08 -07:00
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
private = calloc(1, sizeof *private);
|
2008-11-02 08:26:08 -07:00
|
|
|
if (private == NULL)
|
2012-06-10 07:21:05 -06:00
|
|
|
return NULL;
|
2008-11-02 08:26:08 -07:00
|
|
|
|
|
|
|
private->screen = driScreen;
|
|
|
|
if (!__glXDrawableInit(&private->base, screen,
|
2012-06-10 07:21:05 -06:00
|
|
|
pDraw, type, glxDrawId, glxConfig)) {
|
2010-12-05 08:36:02 -07:00
|
|
|
free(private);
|
2012-06-10 07:21:05 -06:00
|
|
|
return NULL;
|
2008-11-02 08:26:08 -07:00
|
|
|
}
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
private->base.destroy = __glXDRIdrawableDestroy;
|
|
|
|
private->base.swapBuffers = __glXDRIdrawableSwapBuffers;
|
2008-11-02 08:26:08 -07:00
|
|
|
private->base.copySubBuffer = __glXDRIdrawableCopySubBuffer;
|
2012-06-10 07:21:05 -06:00
|
|
|
private->base.waitGL = __glXDRIdrawableWaitGL;
|
|
|
|
private->base.waitX = __glXDRIdrawableWaitX;
|
2008-11-02 08:26:08 -07:00
|
|
|
|
2014-09-27 11:52:59 -06:00
|
|
|
ret = DRI2CreateDrawable2(client, pDraw, drawId,
|
|
|
|
__glXDRIinvalidateBuffers, private,
|
|
|
|
&private->dri2_id);
|
|
|
|
if (cx != lastGLContext) {
|
|
|
|
lastGLContext = cx;
|
|
|
|
cx->makeCurrent(cx);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret) {
|
2012-06-10 07:21:05 -06:00
|
|
|
free(private);
|
|
|
|
return NULL;
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
2008-11-02 08:26:08 -07:00
|
|
|
|
|
|
|
private->driDrawable =
|
2012-06-10 07:21:05 -06:00
|
|
|
(*driScreen->dri2->createNewDrawable) (driScreen->driScreen,
|
|
|
|
config->driConfig, private);
|
2008-11-02 08:26:08 -07:00
|
|
|
|
|
|
|
return &private->base;
|
|
|
|
}
|
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
static __DRIbuffer *
|
2012-06-10 07:21:05 -06:00
|
|
|
dri2GetBuffers(__DRIdrawable * driDrawable,
|
|
|
|
int *width, int *height,
|
|
|
|
unsigned int *attachments, int count,
|
|
|
|
int *out_count, void *loaderPrivate)
|
2008-11-02 08:26:08 -07:00
|
|
|
{
|
2009-09-06 13:44:18 -06:00
|
|
|
__GLXDRIdrawable *private = loaderPrivate;
|
|
|
|
DRI2BufferPtr *buffers;
|
|
|
|
int i;
|
|
|
|
int j;
|
2014-09-27 11:52:59 -06:00
|
|
|
__GLXcontext *cx = lastGLContext;
|
2009-09-06 13:44:18 -06:00
|
|
|
|
|
|
|
buffers = DRI2GetBuffers(private->base.pDraw,
|
2012-06-10 07:21:05 -06:00
|
|
|
width, height, attachments, count, out_count);
|
2014-09-27 11:52:59 -06:00
|
|
|
if (cx != lastGLContext) {
|
|
|
|
lastGLContext = cx;
|
|
|
|
cx->makeCurrent(cx);
|
|
|
|
|
|
|
|
/* If DRI2GetBuffers() changed the GL context, it may also have
|
|
|
|
* invalidated the DRI2 buffers, so let's get them again
|
|
|
|
*/
|
|
|
|
buffers = DRI2GetBuffers(private->base.pDraw,
|
|
|
|
width, height, attachments, count, out_count);
|
|
|
|
assert(lastGLContext == cx);
|
|
|
|
}
|
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
if (*out_count > MAX_DRAWABLE_BUFFERS) {
|
2012-06-10 07:21:05 -06:00
|
|
|
*out_count = 0;
|
|
|
|
return NULL;
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
private->width = *width;
|
|
|
|
private->height = *height;
|
|
|
|
|
|
|
|
/* This assumes the DRI2 buffer attachment tokens matches the
|
|
|
|
* __DRIbuffer tokens. */
|
|
|
|
j = 0;
|
|
|
|
for (i = 0; i < *out_count; i++) {
|
2012-06-10 07:21:05 -06:00
|
|
|
/* Do not send the real front buffer of a window to the client.
|
|
|
|
*/
|
|
|
|
if ((private->base.pDraw->type == DRAWABLE_WINDOW)
|
|
|
|
&& (buffers[i]->attachment == DRI2BufferFrontLeft)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
private->buffers[j].attachment = buffers[i]->attachment;
|
|
|
|
private->buffers[j].name = buffers[i]->name;
|
|
|
|
private->buffers[j].pitch = buffers[i]->pitch;
|
|
|
|
private->buffers[j].cpp = buffers[i]->cpp;
|
|
|
|
private->buffers[j].flags = buffers[i]->flags;
|
|
|
|
j++;
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
*out_count = j;
|
|
|
|
return private->buffers;
|
2008-11-02 08:26:08 -07:00
|
|
|
}
|
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
static __DRIbuffer *
|
2012-06-10 07:21:05 -06:00
|
|
|
dri2GetBuffersWithFormat(__DRIdrawable * driDrawable,
|
|
|
|
int *width, int *height,
|
|
|
|
unsigned int *attachments, int count,
|
|
|
|
int *out_count, void *loaderPrivate)
|
2009-09-06 13:44:18 -06:00
|
|
|
{
|
|
|
|
__GLXDRIdrawable *private = loaderPrivate;
|
|
|
|
DRI2BufferPtr *buffers;
|
|
|
|
int i;
|
|
|
|
int j = 0;
|
2014-09-27 11:52:59 -06:00
|
|
|
__GLXcontext *cx = lastGLContext;
|
2009-09-06 13:44:18 -06:00
|
|
|
|
|
|
|
buffers = DRI2GetBuffersWithFormat(private->base.pDraw,
|
2012-06-10 07:21:05 -06:00
|
|
|
width, height, attachments, count,
|
|
|
|
out_count);
|
2014-09-27 11:52:59 -06:00
|
|
|
if (cx != lastGLContext) {
|
|
|
|
lastGLContext = cx;
|
|
|
|
cx->makeCurrent(cx);
|
|
|
|
|
|
|
|
/* If DRI2GetBuffersWithFormat() changed the GL context, it may also have
|
|
|
|
* invalidated the DRI2 buffers, so let's get them again
|
|
|
|
*/
|
|
|
|
buffers = DRI2GetBuffersWithFormat(private->base.pDraw,
|
|
|
|
width, height, attachments, count,
|
|
|
|
out_count);
|
|
|
|
assert(lastGLContext == cx);
|
|
|
|
}
|
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
if (*out_count > MAX_DRAWABLE_BUFFERS) {
|
2012-06-10 07:21:05 -06:00
|
|
|
*out_count = 0;
|
|
|
|
return NULL;
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
2008-11-02 08:26:08 -07:00
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
private->width = *width;
|
|
|
|
private->height = *height;
|
|
|
|
|
|
|
|
/* This assumes the DRI2 buffer attachment tokens matches the
|
|
|
|
* __DRIbuffer tokens. */
|
|
|
|
for (i = 0; i < *out_count; i++) {
|
2012-06-10 07:21:05 -06:00
|
|
|
/* Do not send the real front buffer of a window to the client.
|
|
|
|
*/
|
|
|
|
if ((private->base.pDraw->type == DRAWABLE_WINDOW)
|
|
|
|
&& (buffers[i]->attachment == DRI2BufferFrontLeft)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
private->buffers[j].attachment = buffers[i]->attachment;
|
|
|
|
private->buffers[j].name = buffers[i]->name;
|
|
|
|
private->buffers[j].pitch = buffers[i]->pitch;
|
|
|
|
private->buffers[j].cpp = buffers[i]->cpp;
|
|
|
|
private->buffers[j].flags = buffers[i]->flags;
|
|
|
|
j++;
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
*out_count = j;
|
|
|
|
return private->buffers;
|
|
|
|
}
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
static void
|
|
|
|
dri2FlushFrontBuffer(__DRIdrawable * driDrawable, void *loaderPrivate)
|
2009-09-06 13:44:18 -06:00
|
|
|
{
|
|
|
|
(void) driDrawable;
|
|
|
|
__glXDRIdrawableWaitGL((__GLXdrawable *) loaderPrivate);
|
2008-11-02 08:26:08 -07:00
|
|
|
}
|
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
static const __DRIdri2LoaderExtension loaderExtension = {
|
2014-05-02 13:27:46 -06:00
|
|
|
{__DRI_DRI2_LOADER, 3},
|
2009-09-06 13:44:18 -06:00
|
|
|
dri2GetBuffers,
|
|
|
|
dri2FlushFrontBuffer,
|
|
|
|
dri2GetBuffersWithFormat,
|
2008-11-02 08:26:08 -07:00
|
|
|
};
|
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
static const __DRIuseInvalidateExtension dri2UseInvalidate = {
|
2014-05-02 13:27:46 -06:00
|
|
|
{__DRI_USE_INVALIDATE, 1}
|
2010-12-05 08:36:02 -07:00
|
|
|
};
|
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
static const __DRIextension *loader_extensions[] = {
|
|
|
|
&systemTimeExtension.base,
|
|
|
|
&loaderExtension.base,
|
2011-11-05 07:32:40 -06:00
|
|
|
&dri2UseInvalidate.base,
|
2008-11-02 08:26:08 -07:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static Bool
|
2013-06-07 11:28:45 -06:00
|
|
|
glxDRIEnterVT(ScrnInfoPtr scrn)
|
2008-11-02 08:26:08 -07:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
Bool ret;
|
|
|
|
__GLXDRIscreen *screen = (__GLXDRIscreen *)
|
2013-06-07 11:28:45 -06:00
|
|
|
glxGetScreen(xf86ScrnToScreen(scrn));
|
2008-11-02 08:26:08 -07:00
|
|
|
|
|
|
|
LogMessage(X_INFO, "AIGLX: Resuming AIGLX clients after VT switch\n");
|
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
scrn->EnterVT = screen->enterVT;
|
|
|
|
|
2013-06-07 11:28:45 -06:00
|
|
|
ret = scrn->EnterVT(scrn);
|
2010-12-05 08:36:02 -07:00
|
|
|
|
|
|
|
screen->enterVT = scrn->EnterVT;
|
|
|
|
scrn->EnterVT = glxDRIEnterVT;
|
|
|
|
|
|
|
|
if (!ret)
|
2012-06-10 07:21:05 -06:00
|
|
|
return FALSE;
|
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
glxResumeClients();
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-06-07 11:28:45 -06:00
|
|
|
glxDRILeaveVT(ScrnInfoPtr scrn)
|
2008-11-02 08:26:08 -07:00
|
|
|
{
|
|
|
|
__GLXDRIscreen *screen = (__GLXDRIscreen *)
|
2013-06-07 11:28:45 -06:00
|
|
|
glxGetScreen(xf86ScrnToScreen(scrn));
|
2008-11-02 08:26:08 -07:00
|
|
|
|
2013-08-24 13:44:25 -06:00
|
|
|
LogMessageVerbSigSafe(X_INFO, -1, "AIGLX: Suspending AIGLX clients for VT switch\n");
|
2008-11-02 08:26:08 -07:00
|
|
|
|
|
|
|
glxSuspendClients();
|
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
scrn->LeaveVT = screen->leaveVT;
|
2013-06-07 11:28:45 -06:00
|
|
|
(*screen->leaveVT) (scrn);
|
2010-12-05 08:36:02 -07:00
|
|
|
screen->leaveVT = scrn->LeaveVT;
|
|
|
|
scrn->LeaveVT = glxDRILeaveVT;
|
2008-11-02 08:26:08 -07:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:27:46 -06:00
|
|
|
/**
|
|
|
|
* Initialize extension flags in glx_enable_bits when a new screen is created
|
|
|
|
*
|
|
|
|
* @param screen The screen where glx_enable_bits are to be set.
|
|
|
|
*/
|
2008-11-02 08:26:08 -07:00
|
|
|
static void
|
2012-06-10 07:21:05 -06:00
|
|
|
initializeExtensions(__GLXDRIscreen * screen)
|
2008-11-02 08:26:08 -07:00
|
|
|
{
|
2010-07-27 13:02:24 -06:00
|
|
|
ScreenPtr pScreen = screen->base.pScreen;
|
2008-11-02 08:26:08 -07:00
|
|
|
const __DRIextension **extensions;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
extensions = screen->core->getExtensions(screen->driScreen);
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
__glXEnableExtension(screen->glx_enable_bits, "GLX_MESA_copy_sub_buffer");
|
2009-09-06 13:44:18 -06:00
|
|
|
LogMessage(X_INFO, "AIGLX: enabled GLX_MESA_copy_sub_buffer\n");
|
2008-11-02 08:26:08 -07:00
|
|
|
|
2013-06-07 11:28:45 -06:00
|
|
|
if (screen->dri2->base.version >= 3) {
|
|
|
|
__glXEnableExtension(screen->glx_enable_bits,
|
|
|
|
"GLX_ARB_create_context");
|
|
|
|
__glXEnableExtension(screen->glx_enable_bits,
|
|
|
|
"GLX_ARB_create_context_profile");
|
2016-05-29 06:02:34 -06:00
|
|
|
__glXEnableExtension(screen->glx_enable_bits,
|
|
|
|
"GLX_EXT_create_context_es_profile");
|
2013-06-07 11:28:45 -06:00
|
|
|
__glXEnableExtension(screen->glx_enable_bits,
|
|
|
|
"GLX_EXT_create_context_es2_profile");
|
|
|
|
LogMessage(X_INFO, "AIGLX: enabled GLX_ARB_create_context\n");
|
|
|
|
LogMessage(X_INFO, "AIGLX: enabled GLX_ARB_create_context_profile\n");
|
|
|
|
LogMessage(X_INFO,
|
2016-05-29 06:02:34 -06:00
|
|
|
"AIGLX: enabled GLX_EXT_create_context_es{,2}_profile\n");
|
2013-06-07 11:28:45 -06:00
|
|
|
}
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
if (DRI2HasSwapControl(pScreen)) {
|
2014-05-02 13:27:46 -06:00
|
|
|
__glXEnableExtension(screen->glx_enable_bits, "GLX_INTEL_swap_event");
|
2012-06-10 07:21:05 -06:00
|
|
|
__glXEnableExtension(screen->glx_enable_bits, "GLX_SGI_swap_control");
|
|
|
|
__glXEnableExtension(screen->glx_enable_bits, "GLX_MESA_swap_control");
|
2014-05-02 13:27:46 -06:00
|
|
|
LogMessage(X_INFO, "AIGLX: enabled GLX_INTEL_swap_event\n");
|
2012-06-10 07:21:05 -06:00
|
|
|
LogMessage(X_INFO,
|
|
|
|
"AIGLX: enabled GLX_SGI_swap_control and GLX_MESA_swap_control\n");
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:27:46 -06:00
|
|
|
/* enable EXT_framebuffer_sRGB extension (even if there are no sRGB capable fbconfigs) */
|
|
|
|
{
|
|
|
|
__glXEnableExtension(screen->glx_enable_bits,
|
|
|
|
"GLX_EXT_framebuffer_sRGB");
|
|
|
|
LogMessage(X_INFO, "AIGLX: enabled GLX_EXT_framebuffer_sRGB\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* enable ARB_fbconfig_float extension (even if there are no float fbconfigs) */
|
|
|
|
{
|
|
|
|
__glXEnableExtension(screen->glx_enable_bits, "GLX_ARB_fbconfig_float");
|
|
|
|
LogMessage(X_INFO, "AIGLX: enabled GLX_ARB_fbconfig_float\n");
|
|
|
|
}
|
|
|
|
|
2016-05-29 06:02:34 -06:00
|
|
|
/* enable EXT_fbconfig_packed_float (even if there are no packed float fbconfigs) */
|
|
|
|
{
|
|
|
|
__glXEnableExtension(screen->glx_enable_bits, "GLX_EXT_fbconfig_packed_float");
|
|
|
|
LogMessage(X_INFO, "AIGLX: enabled GLX_EXT_fbconfig_packed_float\n");
|
|
|
|
}
|
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
for (i = 0; extensions[i]; i++) {
|
2012-06-10 07:21:05 -06:00
|
|
|
if (strcmp(extensions[i]->name, __DRI_READ_DRAWABLE) == 0) {
|
|
|
|
__glXEnableExtension(screen->glx_enable_bits,
|
|
|
|
"GLX_SGI_make_current_read");
|
2010-07-27 13:02:24 -06:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
LogMessage(X_INFO, "AIGLX: enabled GLX_SGI_make_current_read\n");
|
|
|
|
}
|
2008-11-02 08:26:08 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (strcmp(extensions[i]->name, __DRI_TEX_BUFFER) == 0) {
|
|
|
|
screen->texBuffer = (const __DRItexBufferExtension *) extensions[i];
|
|
|
|
/* GLX_EXT_texture_from_pixmap is always enabled. */
|
|
|
|
LogMessage(X_INFO,
|
|
|
|
"AIGLX: GLX_EXT_texture_from_pixmap backed by buffer objects\n");
|
|
|
|
}
|
2010-07-27 13:02:24 -06:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (strcmp(extensions[i]->name, __DRI2_FLUSH) == 0 &&
|
|
|
|
extensions[i]->version >= 3) {
|
|
|
|
screen->flush = (__DRI2flushExtension *) extensions[i];
|
|
|
|
}
|
2010-07-27 13:02:24 -06:00
|
|
|
|
2013-06-07 11:28:45 -06:00
|
|
|
if (strcmp(extensions[i]->name, __DRI2_ROBUSTNESS) == 0 &&
|
|
|
|
screen->dri2->base.version >= 3) {
|
|
|
|
__glXEnableExtension(screen->glx_enable_bits,
|
|
|
|
"GLX_ARB_create_context_robustness");
|
|
|
|
LogMessage(X_INFO,
|
|
|
|
"AIGLX: enabled GLX_ARB_create_context_robustness\n");
|
|
|
|
}
|
|
|
|
|
2015-11-07 09:48:51 -07:00
|
|
|
#ifdef __DRI2_FLUSH_CONTROL
|
|
|
|
if (strcmp(extensions[i]->name, __DRI2_FLUSH_CONTROL) == 0) {
|
|
|
|
__glXEnableExtension(screen->glx_enable_bits,
|
|
|
|
"GLX_ARB_context_flush_control\n");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
/* Ignore unknown extensions */
|
2008-11-02 08:26:08 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:27:46 -06:00
|
|
|
/* white lie */
|
|
|
|
extern glx_func_ptr glXGetProcAddressARB(const char *);
|
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
static __GLXscreen *
|
|
|
|
__glXDRIscreenProbe(ScreenPtr pScreen)
|
|
|
|
{
|
2009-09-06 13:44:18 -06:00
|
|
|
const char *driverName, *deviceName;
|
2008-11-02 08:26:08 -07:00
|
|
|
__GLXDRIscreen *screen;
|
|
|
|
size_t buffer_size;
|
2013-06-07 11:28:45 -06:00
|
|
|
ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
|
2008-11-02 08:26:08 -07:00
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
screen = calloc(1, sizeof *screen);
|
2008-11-02 08:26:08 -07:00
|
|
|
if (screen == NULL)
|
2012-06-10 07:21:05 -06:00
|
|
|
return NULL;
|
2008-11-02 08:26:08 -07:00
|
|
|
|
2014-05-02 13:27:46 -06:00
|
|
|
if (!DRI2Connect(serverClient, pScreen, DRI2DriverDRI,
|
2012-06-10 07:21:05 -06:00
|
|
|
&screen->fd, &driverName, &deviceName)) {
|
|
|
|
LogMessage(X_INFO,
|
|
|
|
"AIGLX: Screen %d is not DRI2 capable\n", pScreen->myNum);
|
2014-05-02 13:27:46 -06:00
|
|
|
goto handle_error;
|
2008-11-02 08:26:08 -07:00
|
|
|
}
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
screen->base.destroy = __glXDRIscreenDestroy;
|
|
|
|
screen->base.createContext = __glXDRIscreenCreateContext;
|
2008-11-02 08:26:08 -07:00
|
|
|
screen->base.createDrawable = __glXDRIscreenCreateDrawable;
|
2012-06-10 07:21:05 -06:00
|
|
|
screen->base.swapInterval = __glXDRIdrawableSwapInterval;
|
|
|
|
screen->base.pScreen = pScreen;
|
2008-11-02 08:26:08 -07:00
|
|
|
|
|
|
|
__glXInitExtensionEnableBits(screen->glx_enable_bits);
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
screen->driver =
|
|
|
|
glxProbeDriver(driverName, (void **) &screen->core, __DRI_CORE, 1,
|
|
|
|
(void **) &screen->dri2, __DRI_DRI2, 1);
|
2008-11-02 08:26:08 -07:00
|
|
|
if (screen->driver == NULL) {
|
|
|
|
goto handle_error;
|
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
screen->driScreen =
|
2012-06-10 07:21:05 -06:00
|
|
|
(*screen->dri2->createNewScreen) (pScreen->myNum,
|
|
|
|
screen->fd,
|
|
|
|
loader_extensions,
|
|
|
|
&screen->driConfigs, screen);
|
2008-11-02 08:26:08 -07:00
|
|
|
|
|
|
|
if (screen->driScreen == NULL) {
|
2012-06-10 07:21:05 -06:00
|
|
|
LogMessage(X_ERROR, "AIGLX error: Calling driver entry point failed\n");
|
|
|
|
goto handle_error;
|
2008-11-02 08:26:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
initializeExtensions(screen);
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
screen->base.fbconfigs = glxConvertConfigs(screen->core, screen->driConfigs,
|
|
|
|
GLX_WINDOW_BIT |
|
|
|
|
GLX_PIXMAP_BIT |
|
|
|
|
GLX_PBUFFER_BIT);
|
2008-11-02 08:26:08 -07:00
|
|
|
|
|
|
|
__glXScreenInit(&screen->base, pScreen);
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
/* The first call simply determines the length of the extension string.
|
|
|
|
* This allows us to allocate some memory to hold the extension string,
|
|
|
|
* but it requires that we call __glXGetExtensionString a second time.
|
|
|
|
*/
|
2008-11-02 08:26:08 -07:00
|
|
|
buffer_size = __glXGetExtensionString(screen->glx_enable_bits, NULL);
|
|
|
|
if (buffer_size > 0) {
|
2012-06-10 07:21:05 -06:00
|
|
|
free(screen->base.GLXextensions);
|
2008-11-02 08:26:08 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
screen->base.GLXextensions = xnfalloc(buffer_size);
|
|
|
|
(void) __glXGetExtensionString(screen->glx_enable_bits,
|
|
|
|
screen->base.GLXextensions);
|
2008-11-02 08:26:08 -07:00
|
|
|
}
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
/* We're going to assume (perhaps incorrectly?) that all DRI2-enabled
|
|
|
|
* drivers support the required extensions for GLX 1.4. The extensions
|
|
|
|
* we're assuming are:
|
|
|
|
*
|
|
|
|
* - GLX_SGI_make_current_read (1.3)
|
|
|
|
* - GLX_SGIX_fbconfig (1.3)
|
|
|
|
* - GLX_SGIX_pbuffer (1.3)
|
|
|
|
* - GLX_ARB_multisample (1.4)
|
|
|
|
*/
|
|
|
|
screen->base.GLXmajor = 1;
|
|
|
|
screen->base.GLXminor = 4;
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
screen->enterVT = pScrn->EnterVT;
|
2012-06-10 07:21:05 -06:00
|
|
|
pScrn->EnterVT = glxDRIEnterVT;
|
2008-11-02 08:26:08 -07:00
|
|
|
screen->leaveVT = pScrn->LeaveVT;
|
|
|
|
pScrn->LeaveVT = glxDRILeaveVT;
|
|
|
|
|
2014-05-02 13:27:46 -06:00
|
|
|
__glXsetGetProcAddress(glXGetProcAddressARB);
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
LogMessage(X_INFO, "AIGLX: Loaded and initialized %s\n", driverName);
|
2008-11-02 08:26:08 -07:00
|
|
|
|
|
|
|
return &screen->base;
|
|
|
|
|
|
|
|
handle_error:
|
|
|
|
if (screen->driver)
|
|
|
|
dlclose(screen->driver);
|
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
free(screen);
|
2008-11-02 08:26:08 -07:00
|
|
|
|
|
|
|
LogMessage(X_ERROR, "AIGLX: reverting to software rendering\n");
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
_X_EXPORT __GLXprovider __glXDRI2Provider = {
|
2008-11-02 08:26:08 -07:00
|
|
|
__glXDRIscreenProbe,
|
|
|
|
"DRI2",
|
|
|
|
NULL
|
|
|
|
};
|