#include <X11/Xlib-xcb.h>
#include <xcb/xcb.h>
#include <xcb/dri2.h>
-#include "glapi.h"
#include "glxclient.h"
#include <X11/extensions/dri2proto.h>
-#include "xf86dri.h"
#include <dlfcn.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <sys/time.h>
-#include "xf86drm.h"
#include "dri2.h"
#include "dri_common.h"
#include "dri2_priv.h"
+#include "loader.h"
/* From xmlpool/options.h, user exposed so should be stable */
#define DRI_CONF_VBLANK_NEVER 0
struct dri2_context *pcp = (struct dri2_context *) context;
struct dri2_screen *psc = (struct dri2_screen *) pcp->base.psc;
struct dri2_drawable *pdraw, *pread;
+ __DRIdrawable *dri_draw = NULL, *dri_read = NULL;
+ struct glx_display *dpyPriv = psc->base.display;
struct dri2_display *pdp;
pdraw = (struct dri2_drawable *) driFetchDrawable(context, draw);
driReleaseDrawables(&pcp->base);
- if (pdraw == NULL || pread == NULL)
+ if (pdraw)
+ dri_draw = pdraw->driDrawable;
+ else if (draw != None)
+ return GLXBadDrawable;
+
+ if (pread)
+ dri_read = pread->driDrawable;
+ else if (read != None)
return GLXBadDrawable;
- if (!(*psc->core->bindContext) (pcp->driContext,
- pdraw->driDrawable, pread->driDrawable))
+ if (!(*psc->core->bindContext) (pcp->driContext, dri_draw, dri_read))
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) {
+ pdp = (struct dri2_display *) dpyPriv->dri2Display;
+ if (!pdp->invalidateAvailable && pdraw) {
dri2InvalidateBuffers(psc->base.dpy, pdraw->base.xDrawable);
- if (pread != pdraw)
+ if (pread != pdraw && pread)
dri2InvalidateBuffers(psc->base.dpy, pread->base.xDrawable);
}
}
static const __DRIdri2LoaderExtension dri2LoaderExtension = {
- {__DRI_DRI2_LOADER, __DRI_DRI2_LOADER_VERSION},
- dri2GetBuffers,
- dri2FlushFrontBuffer,
- dri2GetBuffersWithFormat,
+ .base = { __DRI_DRI2_LOADER, 3 },
+
+ .getBuffers = dri2GetBuffers,
+ .flushFrontBuffer = dri2FlushFrontBuffer,
+ .getBuffersWithFormat = dri2GetBuffersWithFormat,
};
static const __DRIdri2LoaderExtension dri2LoaderExtension_old = {
- {__DRI_DRI2_LOADER, __DRI_DRI2_LOADER_VERSION},
- dri2GetBuffers,
- dri2FlushFrontBuffer,
- NULL,
+ .base = { __DRI_DRI2_LOADER, 3 },
+
+ .getBuffers = dri2GetBuffers,
+ .flushFrontBuffer = dri2FlushFrontBuffer,
+ .getBuffersWithFormat = NULL,
};
static const __DRIuseInvalidateExtension dri2UseInvalidate = {
struct dri2_screen *psc;
__GLXDRIscreen *psp;
struct glx_config *configs = NULL, *visuals = NULL;
- char *driverName, *deviceName, *tmp;
+ char *driverName = NULL, *loader_driverName, *deviceName, *tmp;
drm_magic_t magic;
int i;
goto handle_error;
}
+ if (drmGetMagic(psc->fd, &magic)) {
+ ErrorMessageF("failed to get magic\n");
+ goto handle_error;
+ }
+
+ if (!DRI2Authenticate(priv->dpy, RootWindow(priv->dpy, screen), magic)) {
+ ErrorMessageF("failed to authenticate magic %d\n", magic);
+ goto handle_error;
+ }
+
+ /* If Mesa knows about the appropriate driver for this fd, then trust it.
+ * Otherwise, default to the server's value.
+ */
+ loader_driverName = loader_get_driver_for_fd(psc->fd, 0);
+ if (loader_driverName) {
+ free(driverName);
+ driverName = loader_driverName;
+ }
+
psc->driver = driOpenDriver(driverName);
if (psc->driver == NULL) {
ErrorMessageF("driver pointer missing\n");
goto handle_error;
}
- if (drmGetMagic(psc->fd, &magic)) {
- ErrorMessageF("failed to get magic\n");
- goto handle_error;
- }
-
- if (!DRI2Authenticate(priv->dpy, RootWindow(priv->dpy, screen), magic)) {
- ErrorMessageF("failed to authenticate magic %d\n", magic);
- goto handle_error;
- }
-
if (psc->dri2->base.version >= 4) {
psc->driScreen =
psc->dri2->createNewScreen2(screen, psc->fd,
psp->waitForSBC = NULL;
psp->setSwapInterval = NULL;
psp->getSwapInterval = NULL;
+ psp->getBufferAge = NULL;
if (pdp->driMinor >= 2) {
psp->getDrawableMSC = dri2DrawableGetMSC;