/*
* Given a display pointer and screen number, determine the name of
- * the DRI driver for the screen. (I.e. "r128", "tdfx", etc).
+ * the DRI driver for the screen (i.e., "i965", "radeon", "nouveau", etc).
* Return True for success, False for failure.
*/
static Bool
Bool ret = DRI2Connect(dpy, RootWindow(dpy, scrNum), driverName, &dev);
if (ret)
- Xfree(dev);
+ free(dev);
return ret;
}
if (len >= 31)
return NULL;
memcpy(ret, driverName, len + 1);
- Xfree(driverName);
+ free(driverName);
return ret;
}
return NULL;
drm_handle_t hFB;
int junk;
const __DRIconfig **driver_configs;
- struct glx_config *visual;
+ struct glx_config *visual, *configs = NULL, *visuals = NULL;
/* DRI protocol version. */
dri_version.major = driDpy->driMajor;
fd = drmOpenOnce(NULL, BusID, &newlyopened);
- Xfree(BusID); /* No longer needed */
+ free(BusID); /* No longer needed */
if (fd < 0) {
ErrorMessageF("drmOpenOnce failed (%s)\n", strerror(-fd));
goto handle_error;
}
- /* Get device name (like "tdfx") and the ddx version numbers.
+ /* Get device name (like "radeon") and the ddx version numbers.
* We'll check the version in each DRI driver's "createNewScreen"
* function. */
if (!XF86DRIGetClientDriverName(dpy, scrn,
goto handle_error;
}
- Xfree(driverName); /* No longer needed. */
+ free(driverName); /* No longer needed. */
/*
* Get device-specific info. pDevPriv will point to a struct
goto handle_error;
}
- 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;
if (num_visuals > 0 && visuals->depth != DefaultDepth(dpy, scrn))
visual->visualRating = GLX_NON_CONFORMANT_CONFIG;
- XFree(visuals);
+ free(visuals);
}
}
return psp;
handle_error:
+ if (configs)
+ glx_config_destroy_list(configs);
+ if (visuals)
+ glx_config_destroy_list(visuals);
+
if (pSAREA != MAP_FAILED)
drmUnmap(pSAREA, SAREA_MAX);
if (framebuffer.base != MAP_FAILED)
drmUnmap((drmAddress) framebuffer.base, framebuffer.size);
- if (framebuffer.dev_priv != NULL)
- Xfree(framebuffer.dev_priv);
+ free(framebuffer.dev_priv);
if (fd >= 0)
drmCloseOnce(fd);
struct dri_context *pcp = (struct dri_context *) context;
struct dri_screen *psc = (struct dri_screen *) context->psc;
- if (context->xid)
- glx_send_destroy_context(psc->base.dpy, context->xid);
+ driReleaseDrawables(&pcp->base);
- if (context->extensions)
- XFree((char *) context->extensions);
+ free((char *) context->extensions);
(*psc->core->destroyContext) (pcp->driContext);
XF86DRIDestroyContext(psc->base.dpy, psc->base.scr, pcp->hwContextID);
- Xfree(pcp);
+ free(pcp);
}
static int
pdraw = (struct dri_drawable *) driFetchDrawable(context, draw);
pread = (struct dri_drawable *) driFetchDrawable(context, read);
+ driReleaseDrawables(&pcp->base);
+
if (pdraw == NULL || pread == NULL)
return GLXBadDrawable;
struct dri_screen *psc = (struct dri_screen *) pcp->base.psc;
(*psc->core->unbindContext) (pcp->driContext);
-
- driReleaseDrawables(&pcp->base);
}
static const struct glx_context_vtable dri_context_vtable = {
DRI_glXUseXFont,
NULL,
NULL,
+ NULL, /* get_proc_address */
};
static struct glx_context *
return NULL;
if (shareList) {
+ /* If the shareList context is not a DRI context, we cannot possibly
+ * create a DRI context that shares it.
+ */
+ if (shareList->vtable->destroy != dri_destroy_context) {
+ return NULL;
+ }
+
pcp_shared = (struct dri_context *) shareList;
shared = pcp_shared->driContext;
}
- pcp = Xmalloc(sizeof *pcp);
+ pcp = calloc(1, sizeof *pcp);
if (pcp == NULL)
return NULL;
- memset(pcp, 0, sizeof *pcp);
if (!glx_context_init(&pcp->base, &psc->base, &config->base)) {
- Xfree(pcp);
+ free(pcp);
return NULL;
}
if (!XF86DRICreateContextWithConfig(psc->base.dpy, psc->base.scr,
config->base.visualID,
&pcp->hwContextID, &hwContext)) {
- Xfree(pcp);
+ free(pcp);
return NULL;
}
renderType, shared, hwContext, pcp);
if (pcp->driContext == NULL) {
XF86DRIDestroyContext(psc->base.dpy, psc->base.scr, pcp->hwContextID);
- Xfree(pcp);
+ free(pcp);
return NULL;
}
(*psc->core->destroyDrawable) (pdp->driDrawable);
XF86DRIDestroyDrawable(psc->base.dpy, psc->base.scr, pdraw->drawable);
- Xfree(pdraw);
+ free(pdraw);
}
static __GLXDRIdrawable *
if (xDrawable != drawable)
return NULL;
- pdp = Xmalloc(sizeof *pdp);
+ pdp = calloc(1, sizeof *pdp);
if (!pdp)
return NULL;
- memset(pdp, 0, sizeof *pdp);
pdp->base.drawable = drawable;
pdp->base.psc = &psc->base;
if (!XF86DRICreateDrawable(psc->base.dpy, psc->base.scr,
drawable, &hwDrawable)) {
- Xfree(pdp);
+ free(pdp);
return NULL;
}
if (!pdp->driDrawable) {
XF86DRIDestroyDrawable(psc->base.dpy, psc->base.scr, drawable);
- Xfree(pdp);
+ free(pdp);
return NULL;
}
static int64_t
driSwapBuffers(__GLXDRIdrawable * pdraw, int64_t unused1, int64_t unused2,
- int64_t unused3)
+ int64_t unused3, Bool flush)
{
struct dri_screen *psc = (struct dri_screen *) pdraw->psc;
struct dri_drawable *pdp = (struct dri_drawable *) pdraw;
+ if (flush) {
+ glFlush();
+ }
+
(*psc->core->swapBuffers) (pdp->driDrawable);
return 0;
}
static void
driCopySubBuffer(__GLXDRIdrawable * pdraw,
- int x, int y, int width, int height)
+ int x, int y, int width, int height, Bool flush)
{
struct dri_drawable *pdp = (struct dri_drawable *) pdraw;
struct dri_screen *psc = (struct dri_screen *) pdp->base.psc;
+ if (flush) {
+ glFlush();
+ }
+
(*psc->driCopySubBuffer->copySubBuffer) (pdp->driDrawable,
x, y, width, height);
}
dlclose(psc->driver);
}
-#ifdef __DRI_SWAP_BUFFER_COUNTER
-
-static int
-driDrawableGetMSC(struct glx_screen *base, __GLXDRIdrawable *pdraw,
- int64_t *ust, int64_t *msc, int64_t *sbc)
-{
- struct dri_screen *psc = (struct dri_screen *) base;
- struct dri_drawable *pdp = (struct dri_drawable *) pdraw;
-
- if (pdp && psc->sbc && psc->msc)
- return ( (*psc->msc->getMSC)(psc->driScreen, msc) == 0 &&
- (*psc->sbc->getSBC)(pdp->driDrawable, sbc) == 0 &&
- __glXGetUST(ust) == 0 );
-}
-
-static int
-driWaitForMSC(__GLXDRIdrawable *pdraw, int64_t target_msc, int64_t divisor,
- int64_t remainder, int64_t *ust, int64_t *msc, int64_t *sbc)
-{
- struct dri_screen *psc = (struct dri_screen *) pdraw->psc;
- struct dri_drawable *pdp = (struct dri_drawable *) pdraw;
-
- if (pdp != NULL && psc->msc != NULL) {
- ret = (*psc->msc->waitForMSC) (pdp->driDrawable, target_msc,
- divisor, remainder, msc, sbc);
-
- /* __glXGetUST returns zero on success and non-zero on failure.
- * This function returns True on success and False on failure.
- */
- return ret == 0 && __glXGetUST(ust) == 0;
- }
-}
-
-static int
-driWaitForSBC(__GLXDRIdrawable *pdraw, int64_t target_sbc, int64_t *ust,
- int64_t *msc, int64_t *sbc)
-{
- struct dri_drawable *pdp = (struct dri_drawable *) pdraw;
-
- if (pdp != NULL && psc->sbc != NULL) {
- ret =
- (*psc->sbc->waitForSBC) (pdp->driDrawable, target_sbc, msc, sbc);
-
- /* __glXGetUST returns zero on success and non-zero on failure.
- * This function returns True on success and False on failure.
- */
- return ((ret == 0) && (__glXGetUST(ust) == 0));
- }
-
- return DRI2WaitSBC(pdp->base.psc->dpy,
- pdp->base.xDrawable, target_sbc, ust, msc, sbc);
-}
-
-#endif
-
static int
driSetSwapInterval(__GLXDRIdrawable *pdraw, int interval)
{
}
static const struct glx_screen_vtable dri_screen_vtable = {
- dri_create_context
+ dri_create_context,
+ NULL
};
static struct glx_screen *
char *driverName;
int i;
- psc = Xcalloc(1, sizeof *psc);
+ psc = calloc(1, sizeof *psc);
if (psc == NULL)
return NULL;
- memset(psc, 0, sizeof *psc);
- if (!glx_screen_init(&psc->base, screen, priv))
- return NULL;
+ if (!glx_screen_init(&psc->base, screen, priv)) {
+ free(psc);
+ return NULL;
+ }
if (!driGetDriverName(priv->dpy, screen, &driverName)) {
- Xfree(psc);
- return NULL;
+ goto cleanup;
}
psc->driver = driOpenDriver(driverName);
- Xfree(driverName);
- if (psc->driver == NULL) {
- Xfree(psc);
- return NULL;
- }
+ if (psc->driver == NULL)
+ goto cleanup;
extensions = dlsym(psc->driver, __DRI_DRIVER_EXTENSIONS);
if (extensions == NULL) {
ErrorMessageF("driver exports no extensions (%s)\n", dlerror());
- Xfree(psc);
- return NULL;
+ goto cleanup;
}
for (i = 0; extensions[i]; i++) {
psc->legacy = (__DRIlegacyExtension *) extensions[i];
}
- if (psc->core == NULL || psc->legacy == NULL) {
- Xfree(psc);
- return NULL;
- }
+ if (psc->core == NULL || psc->legacy == NULL)
+ goto cleanup;
pdp = (struct dri_display *) priv->driDisplay;
psc->driScreen =
CallCreateNewScreen(psc->base.dpy, screen, psc, pdp);
- if (psc->driScreen == NULL) {
- dlclose(psc->driver);
- Xfree(psc);
- return NULL;
- }
+ if (psc->driScreen == NULL)
+ goto cleanup;
extensions = psc->core->getExtensions(psc->driScreen);
driBindExtensions(psc, extensions);
psp->createDrawable = driCreateDrawable;
psp->swapBuffers = driSwapBuffers;
-#ifdef __DRI_SWAP_BUFFER_COUNTER
- psp->getDrawableMSC = driDrawableGetMSC;
- psp->waitForMSC = driWaitForMSC;
- psp->waitForSBC = driWaitForSBC;
-#endif
-
psp->setSwapInterval = driSetSwapInterval;
psp->getSwapInterval = driGetSwapInterval;
+ free(driverName);
+
return &psc->base;
+
+cleanup:
+ CriticalErrorMessageF("failed to load driver: %s\n", driverName);
+
+ free(driverName);
+
+ if (psc->driver)
+ dlclose(psc->driver);
+ glx_screen_cleanup(&psc->base);
+ free(psc);
+
+ return NULL;
}
/* Called from __glXFreeDisplayPrivate.
static void
driDestroyDisplay(__GLXDRIdisplay * dpy)
{
- Xfree(dpy);
+ free(dpy);
}
/*
return NULL;
}
- pdpyp = Xmalloc(sizeof *pdpyp);
+ pdpyp = malloc(sizeof *pdpyp);
if (!pdpyp) {
return NULL;
}