#include <X11/Xlib.h>
#include <X11/extensions/Xfixes.h>
-#include <X11/extensions/Xdamage.h>
#include "glapi.h"
#include "glxclient.h"
#include <X11/extensions/dri2proto.h>
};
struct dri2_screen {
- __GLXscreenConfigs base;
+ struct glx_screen base;
__DRIscreen *driScreen;
__GLXDRIscreen vtable;
const __DRI2flushExtension *f;
const __DRI2configQueryExtension *config;
const __DRItexBufferExtension *texBuffer;
+ const __DRI2throttleExtension *throttle;
const __DRIconfig **driver_configs;
void *driver;
struct dri2_context
{
- __GLXcontext base;
- __GLXDRIcontext dri_vtable;
+ struct glx_context base;
__DRIcontext *driContext;
};
static const struct glx_context_vtable dri2_context_vtable;
static void
-dri2_destroy_context(__GLXcontext *context)
+dri2_destroy_context(struct glx_context *context)
{
struct dri2_context *pcp = (struct dri2_context *) context;
struct dri2_screen *psc = (struct dri2_screen *) context->psc;
+ driReleaseDrawables(&pcp->base);
+
if (context->xid)
glx_send_destroy_context(psc->base.dpy, context->xid);
if (context->extensions)
XFree((char *) context->extensions);
- GarbageCollectDRIDrawables(context->psc);
-
(*psc->core->destroyContext) (pcp->driContext);
Xfree(pcp);
}
static Bool
-dri2BindContext(__GLXcontext *context,
- __GLXDRIdrawable *draw, __GLXDRIdrawable *read)
+dri2_bind_context(struct glx_context *context, struct glx_context *old,
+ GLXDrawable draw, GLXDrawable read)
{
struct dri2_context *pcp = (struct dri2_context *) context;
struct dri2_screen *psc = (struct dri2_screen *) pcp->base.psc;
- struct dri2_drawable *pdr = (struct dri2_drawable *) draw;
- struct dri2_drawable *prd = (struct dri2_drawable *) read;
+ struct dri2_drawable *pdraw, *pread;
+ struct dri2_display *pdp;
+
+ pdraw = (struct dri2_drawable *) driFetchDrawable(context, draw);
+ pread = (struct dri2_drawable *) driFetchDrawable(context, read);
+
+ driReleaseDrawables(&pcp->base);
+
+ if (pdraw == NULL || pread == NULL)
+ return GLXBadDrawable;
- return (*psc->core->bindContext) (pcp->driContext,
- pdr->driDrawable, prd->driDrawable);
+ if (!(*psc->core->bindContext) (pcp->driContext,
+ pdraw->driDrawable, pread->driDrawable))
+ return GLXBadContext;
+
+ /* If the server doesn't send invalidate events, we may miss a
+ * resize before the rendering starts. Invalidate the buffers now
+ * so the driver will recheck before rendering starts. */
+ pdp = (struct dri2_display *) psc->base.display;
+ if (!pdp->invalidateAvailable) {
+ dri2InvalidateBuffers(psc->base.dpy, pdraw->base.xDrawable);
+ if (pread != pdraw)
+ dri2InvalidateBuffers(psc->base.dpy, pread->base.xDrawable);
+ }
+
+ return Success;
}
static void
-dri2UnbindContext(__GLXcontext *context)
+dri2_unbind_context(struct glx_context *context, struct glx_context *new)
{
struct dri2_context *pcp = (struct dri2_context *) context;
struct dri2_screen *psc = (struct dri2_screen *) pcp->base.psc;
(*psc->core->unbindContext) (pcp->driContext);
}
-static __GLXcontext *
-dri2_create_context(__GLXscreenConfigs *base,
+static struct glx_context *
+dri2_create_context(struct glx_screen *base,
struct glx_config *config_base,
- GLXContext shareList, int renderType)
+ struct glx_context *shareList, int renderType)
{
struct dri2_context *pcp, *pcp_shared;
struct dri2_screen *psc = (struct dri2_screen *) base;
__DRIcontext *shared = NULL;
if (shareList) {
+ /* If the shareList context is not a DRI2 context, we cannot possibly
+ * create a DRI2 context that shares it.
+ */
+ if (shareList->vtable->destroy != dri2_destroy_context) {
+ return NULL;
+ }
+
pcp_shared = (struct dri2_context *) shareList;
shared = pcp_shared->driContext;
}
}
pcp->base.vtable = &dri2_context_vtable;
- pcp->base.driContext = &pcp->dri_vtable;
- pcp->dri_vtable.bindContext = dri2BindContext;
- pcp->dri_vtable.unbindContext = dri2UnbindContext;
return &pcp->base;
}
{
struct dri2_screen *psc = (struct dri2_screen *) base->psc;
struct dri2_drawable *pdraw = (struct dri2_drawable *) base;
- __GLXdisplayPrivate *dpyPriv = psc->base.display;
+ struct glx_display *dpyPriv = psc->base.display;
struct dri2_display *pdp = (struct dri2_display *)dpyPriv->dri2Display;
__glxHashDelete(pdp->dri2Hash, pdraw->base.xDrawable);
(*psc->core->destroyDrawable) (pdraw->driDrawable);
- DRI2DestroyDrawable(psc->base.dpy, pdraw->base.xDrawable);
+
+ /* If it's a GLX 1.3 drawables, we can destroy the DRI2 drawable
+ * now, as the application explicitly asked to destroy the GLX
+ * drawable. Otherwise, for legacy drawables, we let the DRI2
+ * drawable linger on the server, since there's no good way of
+ * knowing when the application is done with it. The server will
+ * destroy the DRI2 drawable when it destroys the X drawable or the
+ * client exits anyway. */
+ if (pdraw->base.xDrawable != pdraw->base.drawable)
+ DRI2DestroyDrawable(psc->base.dpy, pdraw->base.xDrawable);
+
Xfree(pdraw);
}
static __GLXDRIdrawable *
-dri2CreateDrawable(__GLXscreenConfigs *base, XID xDrawable,
+dri2CreateDrawable(struct glx_screen *base, XID xDrawable,
GLXDrawable drawable, struct glx_config *config_base)
{
struct dri2_drawable *pdraw;
struct dri2_screen *psc = (struct dri2_screen *) base;
__GLXDRIconfigPrivate *config = (__GLXDRIconfigPrivate *) config_base;
- __GLXdisplayPrivate *dpyPriv;
+ struct glx_display *dpyPriv;
struct dri2_display *pdp;
GLint vblank_mode = DRI_CONF_VBLANK_DEF_INTERVAL_1;
#ifdef X_DRI2GetMSC
static int
-dri2DrawableGetMSC(__GLXscreenConfigs *psc, __GLXDRIdrawable *pdraw,
+dri2DrawableGetMSC(struct glx_screen *psc, __GLXDRIdrawable *pdraw,
int64_t *ust, int64_t *msc, int64_t *sbc)
{
CARD64 dri2_ust, dri2_msc, dri2_sbc;
#endif /* X_DRI2WaitMSC */
+/**
+ * dri2Throttle - Request driver throttling
+ *
+ * This function uses the DRI2 throttle extension to give the
+ * driver the opportunity to throttle on flush front, copysubbuffer
+ * and swapbuffers.
+ */
+static void
+dri2Throttle(struct dri2_screen *psc,
+ struct dri2_drawable *draw,
+ enum __DRI2throttleReason reason)
+{
+ if (psc->throttle) {
+ struct glx_context *gc = __glXGetCurrentContext();
+ struct dri2_context *dri2Ctx = (struct dri2_context *)gc;
+ __DRIcontext *ctx =
+ (dri2Ctx) ? dri2Ctx->driContext : NULL;
+
+ psc->throttle->throttle(ctx, draw->driDrawable, reason);
+ }
+}
+
static void
-dri2CopySubBuffer(__GLXDRIdrawable *pdraw, int x, int y, int width, int height)
+__dri2CopySubBuffer(__GLXDRIdrawable *pdraw, int x, int y,
+ int width, int height,
+ enum __DRI2throttleReason reason)
{
struct dri2_drawable *priv = (struct dri2_drawable *) pdraw;
struct dri2_screen *psc = (struct dri2_screen *) pdraw->psc;
(*psc->f->flush) (priv->driDrawable);
#endif
+ dri2Throttle(psc, priv, reason);
+
region = XFixesCreateRegion(psc->base.dpy, &xrect, 1);
DRI2CopyRegion(psc->base.dpy, pdraw->xDrawable, region,
DRI2BufferFrontLeft, DRI2BufferBackLeft);
XFixesDestroyRegion(psc->base.dpy, region);
}
+static void
+dri2CopySubBuffer(__GLXDRIdrawable *pdraw, int x, int y,
+ int width, int height)
+{
+ __dri2CopySubBuffer(pdraw, x, y, width, height,
+ __DRI2_THROTTLE_COPYSUBBUFFER);
+}
+
+
static void
dri2_copy_drawable(struct dri2_drawable *priv, int dest, int src)
{
}
static void
-dri2_wait_x(__GLXcontext *gc)
+dri2_wait_x(struct glx_context *gc)
{
struct dri2_drawable *priv = (struct dri2_drawable *)
GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable);
}
static void
-dri2_wait_gl(__GLXcontext *gc)
+dri2_wait_gl(struct glx_context *gc)
{
struct dri2_drawable *priv = (struct dri2_drawable *)
GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable);
static void
dri2FlushFrontBuffer(__DRIdrawable *driDrawable, void *loaderPrivate)
{
+ struct glx_display *priv;
+ struct dri2_display *pdp;
+ struct glx_context *gc;
struct dri2_drawable *pdraw = loaderPrivate;
- __GLXdisplayPrivate *priv = __glXInitialize(pdraw->base.psc->dpy);
- struct dri2_display *pdp = (struct dri2_display *)priv->dri2Display;
- GLXContext gc = __glXGetCurrentContext();
+ struct dri2_screen *psc;
+
+ if (!pdraw)
+ return;
+
+ if (!pdraw->base.psc)
+ return;
+
+ psc = (struct dri2_screen *) pdraw->base.psc;
+
+ priv = __glXInitialize(psc->base.dpy);
+ pdp = (struct dri2_display *) priv->dri2Display;
+ gc = __glXGetCurrentContext();
+
+ dri2Throttle(psc, pdraw, __DRI2_THROTTLE_FLUSHFRONT);
/* Old servers don't send invalidate events */
if (!pdp->invalidateAvailable)
- dri2InvalidateBuffers(priv->dpy, pdraw->base.drawable);
+ dri2InvalidateBuffers(priv->dpy, pdraw->base.xDrawable);
dri2_wait_gl(gc);
}
static void
-dri2DestroyScreen(__GLXscreenConfigs *base)
+dri2DestroyScreen(struct glx_screen *base)
{
struct dri2_screen *psc = (struct dri2_screen *) base;
}
+unsigned dri2GetSwapEventType(Display* dpy, XID drawable)
+{
+ struct glx_display *glx_dpy = __glXInitialize(dpy);
+ __GLXDRIdrawable *pdraw;
+ pdraw = dri2GetGlxDrawableFromXDrawableId(dpy, drawable);
+ if (!pdraw || !(pdraw->eventMask & GLX_BUFFER_SWAP_COMPLETE_INTEL_MASK))
+ return 0;
+ return glx_dpy->codes->first_event + GLX_BufferSwapComplete;
+}
+
static int64_t
dri2SwapBuffers(__GLXDRIdrawable *pdraw, int64_t target_msc, int64_t divisor,
int64_t remainder)
{
struct dri2_drawable *priv = (struct dri2_drawable *) pdraw;
- __GLXdisplayPrivate *dpyPriv = __glXInitialize(priv->base.psc->dpy);
+ struct glx_display *dpyPriv = __glXInitialize(priv->base.psc->dpy);
struct dri2_screen *psc = (struct dri2_screen *) priv->base.psc;
struct dri2_display *pdp =
(struct dri2_display *)dpyPriv->dri2Display;
CARD64 ret = 0;
-#ifdef __DRI2_FLUSH
- if (psc->f)
- (*psc->f->flush)(priv->driDrawable);
-#endif
-
- /* Old servers don't send invalidate events */
- if (!pdp->invalidateAvailable)
- dri2InvalidateBuffers(dpyPriv->dpy, pdraw->drawable);
+ /* Check we have the right attachments */
+ if (!priv->have_back)
+ return ret;
/* Old servers can't handle swapbuffers */
if (!pdp->swapAvailable) {
- dri2CopySubBuffer(pdraw, 0, 0, priv->width, priv->height);
- return 0;
+ __dri2CopySubBuffer(pdraw, 0, 0, priv->width, priv->height,
+ __DRI2_THROTTLE_SWAPBUFFER);
+ } else {
+#ifdef X_DRI2SwapBuffers
+#ifdef __DRI2_FLUSH
+ if (psc->f) {
+ struct glx_context *gc = __glXGetCurrentContext();
+
+ if (gc) {
+ (*psc->f->flush)(priv->driDrawable);
+ }
}
+#endif
-#ifdef X_DRI2SwapBuffers
- DRI2SwapBuffers(psc->base.dpy, pdraw->xDrawable, target_msc, divisor,
- remainder, &ret);
+ dri2Throttle(psc, priv, __DRI2_THROTTLE_SWAPBUFFER);
+
+ DRI2SwapBuffers(psc->base.dpy, pdraw->xDrawable,
+ target_msc, divisor, remainder, &ret);
#endif
+ }
+
+ /* Old servers don't send invalidate events */
+ if (!pdp->invalidateAvailable)
+ dri2InvalidateBuffers(dpyPriv->dpy, pdraw->xDrawable);
return ret;
}
{
__GLXDRIdrawable *pdraw =
dri2GetGlxDrawableFromXDrawableId(dpy, drawable);
- struct dri2_screen *psc = (struct dri2_screen *) pdraw->psc;
+ struct dri2_screen *psc;
struct dri2_drawable *pdp = (struct dri2_drawable *) pdraw;
+ if (!pdraw)
+ return;
+
+ psc = (struct dri2_screen *) pdraw->psc;
+
#if __DRI2_FLUSH_VERSION >= 3
- if (pdraw && psc->f)
+ if (pdraw && psc->f && psc->f->base.version >= 3 && psc->f->invalidate)
psc->f->invalidate(pdp->driDrawable);
#endif
}
GLXDrawable drawable,
int buffer, const int *attrib_list)
{
- GLXContext gc = __glXGetCurrentContext();
+ struct glx_context *gc = __glXGetCurrentContext();
struct dri2_context *pcp = (struct dri2_context *) gc;
__GLXDRIdrawable *base = GetGLXDRIDrawable(dpy, drawable);
- __GLXdisplayPrivate *dpyPriv = __glXInitialize(dpy);
+ struct glx_display *dpyPriv = __glXInitialize(dpy);
struct dri2_drawable *pdraw = (struct dri2_drawable *) base;
struct dri2_display *pdp =
(struct dri2_display *) dpyPriv->dri2Display;
- struct dri2_screen *psc = (struct dri2_screen *) base->psc;
+ struct dri2_screen *psc;
if (pdraw != NULL) {
+ psc = (struct dri2_screen *) base->psc;
#if __DRI2_FLUSH_VERSION >= 3
- if (!pdp->invalidateAvailable && psc->f)
+ if (!pdp->invalidateAvailable && psc->f &&
+ psc->f->base.version >= 3 && psc->f->invalidate)
psc->f->invalidate(pdraw->driDrawable);
#endif
static void
dri2_release_tex_image(Display * dpy, GLXDrawable drawable, int buffer)
{
+#if __DRI_TEX_BUFFER_VERSION >= 3
+ struct glx_context *gc = __glXGetCurrentContext();
+ struct dri2_context *pcp = (struct dri2_context *) gc;
+ __GLXDRIdrawable *base = GetGLXDRIDrawable(dpy, drawable);
+ struct glx_display *dpyPriv = __glXInitialize(dpy);
+ struct dri2_drawable *pdraw = (struct dri2_drawable *) base;
+ struct dri2_display *pdp =
+ (struct dri2_display *) dpyPriv->dri2Display;
+ struct dri2_screen *psc;
+
+ if (pdraw != NULL) {
+ psc = (struct dri2_screen *) base->psc;
+
+ if (psc->texBuffer->base.version >= 3 &&
+ psc->texBuffer->releaseTexBuffer != NULL) {
+ (*psc->texBuffer->releaseTexBuffer) (pcp->driContext,
+ pdraw->base.textureTarget,
+ pdraw->driDrawable);
+ }
+ }
+#endif
}
static const struct glx_context_vtable dri2_context_vtable = {
dri2_destroy_context,
+ dri2_bind_context,
+ dri2_unbind_context,
dri2_wait_gl,
dri2_wait_x,
DRI_glXUseXFont,
dri2_bind_tex_image,
dri2_release_tex_image,
+ NULL, /* get_proc_address */
};
static void
if ((strcmp(extensions[i]->name, __DRI2_CONFIG_QUERY) == 0))
psc->config = (__DRI2configQueryExtension *) extensions[i];
+
+ if (((strcmp(extensions[i]->name, __DRI2_THROTTLE) == 0)))
+ psc->throttle = (__DRI2throttleExtension *) extensions[i];
}
}
dri2_create_context
};
-static __GLXscreenConfigs *
-dri2CreateScreen(int screen, __GLXdisplayPrivate * priv)
+static struct glx_screen *
+dri2CreateScreen(int screen, struct glx_display * priv)
{
const __DRIconfig **driver_configs;
const __DRIextension **extensions;
priv->dri2Display;
struct dri2_screen *psc;
__GLXDRIscreen *psp;
+ struct glx_config *configs = NULL, *visuals = NULL;
char *driverName, *deviceName;
drm_magic_t magic;
int i;
return NULL;
memset(psc, 0, sizeof *psc);
- if (!glx_screen_init(&psc->base, screen, priv))
- return NULL;
+ psc->fd = -1;
+
+ if (!glx_screen_init(&psc->base, screen, priv)) {
+ Xfree(psc);
+ return NULL;
+ }
if (!DRI2Connect(priv->dpy, RootWindow(priv->dpy, screen),
&driverName, &deviceName)) {
+ glx_screen_cleanup(&psc->base);
XFree(psc);
+ InfoMessageF("screen %d does not appear to be DRI2 capable\n", screen);
return NULL;
}
extensions = psc->core->getExtensions(psc->driScreen);
dri2BindExtensions(psc, extensions);
- psc->base.configs =
- driConvertConfigs(psc->core, psc->base.configs, driver_configs);
- psc->base.visuals =
- driConvertConfigs(psc->core, psc->base.visuals, driver_configs);
+ configs = driConvertConfigs(psc->core, psc->base.configs, driver_configs);
+ visuals = driConvertConfigs(psc->core, psc->base.visuals, driver_configs);
+
+ if (!configs || !visuals)
+ goto handle_error;
+
+ glx_config_destroy_list(psc->base.configs);
+ psc->base.configs = configs;
+ glx_config_destroy_list(psc->base.visuals);
+ psc->base.visuals = visuals;
psc->driver_configs = driver_configs;
return &psc->base;
handle_error:
+ if (configs)
+ glx_config_destroy_list(configs);
+ if (visuals)
+ glx_config_destroy_list(visuals);
+ if (psc->driScreen)
+ psc->core->destroyScreen(psc->driScreen);
+ psc->driScreen = NULL;
+ if (psc->fd >= 0)
+ close(psc->fd);
+ if (psc->driver)
+ dlclose(psc->driver);
+
Xfree(driverName);
Xfree(deviceName);
+ glx_screen_cleanup(&psc->base);
XFree(psc);
- /* FIXME: clean up here */
-
return NULL;
}
static void
dri2DestroyDisplay(__GLXDRIdisplay * dpy)
{
+ struct dri2_display *pdp = (struct dri2_display *) dpy;
+
+ __glxHashDestroy(pdp->dri2Hash);
Xfree(dpy);
}
_X_HIDDEN __GLXDRIdrawable *
dri2GetGlxDrawableFromXDrawableId(Display *dpy, XID id)
{
- __GLXdisplayPrivate *d = __glXInitialize(dpy);
+ struct glx_display *d = __glXInitialize(dpy);
struct dri2_display *pdp = (struct dri2_display *) d->dri2Display;
__GLXDRIdrawable *pdraw;