diff options
author | Kristian Høgsberg <[email protected]> | 2008-03-26 19:26:59 -0400 |
---|---|---|
committer | Kristian Høgsberg <[email protected]> | 2008-03-31 16:51:26 -0400 |
commit | e82dd8c6e1fa2fff5b960de26961080ba5e9651d (patch) | |
tree | 1bd230661a032b1ab539998f947573de1acaf80d /src | |
parent | 63d8a8417d68365cd10c11178516378411c09f87 (diff) |
DRI interface changes and DRI2 direct rendering support.
Add DRI2 direct rendering support to libGL and add DRI2 client side
protocol code. Extend the GLX 1.3 create drawable functions in
glx_pbuffer.c to call into the DRI driver when possible.
Introduce __DRIconfig, opaque struct that represents a DRI driver
configuration. Get's rid of the open coded __GLcontextModes in the
DRI driver interface and the context modes create and destroy
functions that the loader was requires to provide. glcore.h is no
longer part of the DRI driver interface. The DRI config is GL binding
agnostic, that is, not specific to GLX, EGL or other bindings.
The core API is now also an extension, and the driver exports a list
of extensions as the symbol __driDriverExtensions, which the loader
must dlsym() for. The list of extension will always include the DRI
core extension, which allows creating and manipulating DRI screens,
drawables and contexts. The DRI legacy extension, when available,
provides alternative entry points for creating the DRI objects that
work with the XF86DRI infrastructure.
Change DRI2 client code to not use drm drawables or contexts. We
never used drm_drawable_t's and the only use for drm_context_t was as
a unique identifier when taking the lock. We now just allocate a
unique lock ID out of the DRILock sarea block. Once we get rid of the
lock entirely, we can drop this hack.
Change the interface between dri_util.c and the drivers, so that the
drivers now export the DriverAPI struct as driDriverAPI instead of the
InitScreen entry point. This lets us avoid dlsym()'ing for the DRI2
init screen function to see if DRI2 is supported by the driver.
Diffstat (limited to 'src')
34 files changed, 2288 insertions, 1456 deletions
diff --git a/src/glx/x11/Makefile b/src/glx/x11/Makefile index 8fa3700a04c..2d44e8df7a1 100644 --- a/src/glx/x11/Makefile +++ b/src/glx/x11/Makefile @@ -32,7 +32,9 @@ SOURCES = \ glx_texture_compression.c \ dri_glx.c \ XF86dri.c \ - glxhash.c + glxhash.c \ + dri2_glx.c \ + dri2.c include $(TOP)/src/mesa/sources @@ -48,6 +50,7 @@ INCLUDES = -I. \ -I$(TOP)/src/mesa/main \ -I$(TOP)/src/mesa/glapi \ $(LIBDRM_CFLAGS) \ + $(DRI2PROTO_CFLAGS) \ $(X11_INCLUDES) diff --git a/src/glx/x11/dri2.c b/src/glx/x11/dri2.c new file mode 100644 index 00000000000..c3012c4e5fb --- /dev/null +++ b/src/glx/x11/dri2.c @@ -0,0 +1,252 @@ +/* + * Copyright © 2008 Red Hat, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Soft- + * ware"), to deal in the Software without restriction, including without + * limitation the rights to use, copy, modify, merge, publish, distribute, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, provided that the above copyright + * notice(s) and this permission notice appear in all copies of the Soft- + * ware and that both the above copyright notice(s) and this permission + * notice appear in supporting documentation. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL- + * ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY + * RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN + * THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSE- + * QUENTIAL 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 PERFOR- + * MANCE OF THIS SOFTWARE. + * + * Except as contained in this notice, the name of a copyright holder shall + * not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization of + * the copyright holder. + * + * Authors: + * Kristian Høgsberg ([email protected]) + */ + + +#define NEED_REPLIES +#include <X11/Xlibint.h> +#include <X11/extensions/Xext.h> +#include <X11/extensions/extutil.h> +#include "glheader.h" +#include "xf86drm.h" +#include "dri2proto.h" +#include "dri2.h" + +static char dri2ExtensionName[] = DRI2_NAME; +static XExtensionInfo *dri2Info; +static XEXT_GENERATE_CLOSE_DISPLAY (DRI2CloseDisplay, dri2Info) +static /* const */ XExtensionHooks dri2ExtensionHooks = { + NULL, /* create_gc */ + NULL, /* copy_gc */ + NULL, /* flush_gc */ + NULL, /* free_gc */ + NULL, /* create_font */ + NULL, /* free_font */ + DRI2CloseDisplay, /* close_display */ + NULL, /* wire_to_event */ + NULL, /* event_to_wire */ + NULL, /* error */ + NULL, /* error_string */ +}; + +static XEXT_GENERATE_FIND_DISPLAY (DRI2FindDisplay, dri2Info, + dri2ExtensionName, + &dri2ExtensionHooks, + 0, NULL) + +Bool DRI2QueryExtension(Display *dpy, int *eventBase, int *errorBase) +{ + XExtDisplayInfo *info = DRI2FindDisplay(dpy); + + if (XextHasExtension(info)) { + *eventBase = info->codes->first_event; + *errorBase = info->codes->first_error; + return True; + } + + return False; +} + +Bool DRI2QueryVersion(Display *dpy, int *major, int *minor) +{ + XExtDisplayInfo *info = DRI2FindDisplay (dpy); + xDRI2QueryVersionReply rep; + xDRI2QueryVersionReq *req; + + XextCheckExtension (dpy, info, dri2ExtensionName, False); + + LockDisplay(dpy); + GetReq(DRI2QueryVersion, req); + req->reqType = info->codes->major_opcode; + req->dri2ReqType = X_DRI2QueryVersion; + req->majorVersion = DRI2_MAJOR; + req->minorVersion = DRI2_MINOR; + if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { + UnlockDisplay(dpy); + SyncHandle(); + return False; + } + *major = rep.majorVersion; + *minor = rep.minorVersion; + UnlockDisplay(dpy); + SyncHandle(); + + return True; +} + +Bool DRI2Connect(Display *dpy, int screen, + char **driverName, char **busId, unsigned int *sareaHandle) +{ + XExtDisplayInfo *info = DRI2FindDisplay(dpy); + xDRI2ConnectReply rep; + xDRI2ConnectReq *req; + + XextCheckExtension (dpy, info, dri2ExtensionName, False); + + LockDisplay(dpy); + GetReq(DRI2Connect, req); + req->reqType = info->codes->major_opcode; + req->dri2ReqType = X_DRI2Connect; + req->screen = screen; + if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { + UnlockDisplay(dpy); + SyncHandle(); + return False; + } + + *sareaHandle = rep.sareaHandle; + + *driverName = Xmalloc(rep.driverNameLength + 1); + if (*driverName == NULL) { + _XEatData(dpy, + ((rep.driverNameLength + 3) & ~3) + + ((rep.busIdLength + 3) & ~3)); + UnlockDisplay(dpy); + SyncHandle(); + return False; + } + _XReadPad(dpy, *driverName, rep.driverNameLength); + (*driverName)[rep.driverNameLength] = '\0'; + + *busId = Xmalloc(rep.busIdLength + 1); + if (*busId == NULL) { + Xfree(*driverName); + _XEatData(dpy, ((rep.busIdLength + 3) & ~3)); + UnlockDisplay(dpy); + SyncHandle(); + return False; + } + _XReadPad(dpy, *busId, rep.busIdLength); + (*busId)[rep.busIdLength] = '\0'; + + UnlockDisplay(dpy); + SyncHandle(); + + return rep.sareaHandle != 0; +} + +Bool DRI2AuthConnection(Display *dpy, int screen, drm_magic_t magic) +{ + XExtDisplayInfo *info = DRI2FindDisplay(dpy); + xDRI2AuthConnectionReq *req; + xDRI2AuthConnectionReply rep; + + XextCheckExtension (dpy, info, dri2ExtensionName, False); + + LockDisplay(dpy); + GetReq(DRI2AuthConnection, req); + req->reqType = info->codes->major_opcode; + req->dri2ReqType = X_DRI2AuthConnection; + req->screen = screen; + req->magic = magic; + rep.authenticated = 0; + if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { + UnlockDisplay(dpy); + SyncHandle(); + return False; + } + UnlockDisplay(dpy); + SyncHandle(); + + return rep.authenticated; +} + +Bool DRI2CreateDrawable(Display *dpy, XID drawable, + unsigned int *handle, unsigned int *head) +{ + XExtDisplayInfo *info = DRI2FindDisplay(dpy); + xDRI2CreateDrawableReply rep; + xDRI2CreateDrawableReq *req; + + XextCheckExtension (dpy, info, dri2ExtensionName, False); + + LockDisplay(dpy); + GetReq(DRI2CreateDrawable, req); + req->reqType = info->codes->major_opcode; + req->dri2ReqType = X_DRI2CreateDrawable; + req->drawable = drawable; + if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { + UnlockDisplay(dpy); + SyncHandle(); + return False; + } + UnlockDisplay(dpy); + SyncHandle(); + + *handle = rep.handle; + *head = rep.head; + + return True; +} + +void DRI2DestroyDrawable(Display *dpy, XID drawable) +{ + XExtDisplayInfo *info = DRI2FindDisplay(dpy); + xDRI2DestroyDrawableReq *req; + + XextSimpleCheckExtension (dpy, info, dri2ExtensionName); + + XSync(dpy, GL_FALSE); + + LockDisplay(dpy); + GetReq(DRI2DestroyDrawable, req); + req->reqType = info->codes->major_opcode; + req->dri2ReqType = X_DRI2DestroyDrawable; + req->drawable = drawable; + UnlockDisplay(dpy); + SyncHandle(); +} + +Bool DRI2ReemitDrawableInfo(Display *dpy, XID drawable, unsigned int *head) +{ + XExtDisplayInfo *info = DRI2FindDisplay(dpy); + xDRI2ReemitDrawableInfoReply rep; + xDRI2ReemitDrawableInfoReq *req; + + XextCheckExtension (dpy, info, dri2ExtensionName, False); + + LockDisplay(dpy); + GetReq(DRI2ReemitDrawableInfo, req); + req->reqType = info->codes->major_opcode; + req->dri2ReqType = X_DRI2ReemitDrawableInfo; + req->drawable = drawable; + if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { + UnlockDisplay(dpy); + SyncHandle(); + return False; + } + UnlockDisplay(dpy); + SyncHandle(); + + *head = rep.head; + + return True; +} diff --git a/src/glx/x11/dri2.h b/src/glx/x11/dri2.h new file mode 100644 index 00000000000..1dfd0448b2f --- /dev/null +++ b/src/glx/x11/dri2.h @@ -0,0 +1,53 @@ +/* + * Copyright © 2007,2008 Red Hat, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Soft- + * ware"), to deal in the Software without restriction, including without + * limitation the rights to use, copy, modify, merge, publish, distribute, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, provided that the above copyright + * notice(s) and this permission notice appear in all copies of the Soft- + * ware and that both the above copyright notice(s) and this permission + * notice appear in supporting documentation. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL- + * ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY + * RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN + * THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSE- + * QUENTIAL 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 PERFOR- + * MANCE OF THIS SOFTWARE. + * + * Except as contained in this notice, the name of a copyright holder shall + * not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization of + * the copyright holder. + * + * Authors: + * Kristian Høgsberg ([email protected]) + */ + +#ifndef _DRI2_H_ +#define _DRI2_H_ + +extern Bool +DRI2QueryExtension(Display *display, int *eventBase, int *errorBase); +extern Bool +DRI2QueryVersion(Display *display, int *major, int *minor); +extern Bool +DRI2Connect(Display *display, int screen, + char **driverName, char **busId, unsigned int *sareaHandle); +extern Bool +DRI2AuthConnection(Display *display, int screen, drm_magic_t magic); +extern Bool +DRI2CreateDrawable(Display *display, XID drawable, + unsigned int *handle, unsigned int *head); +extern void +DRI2DestroyDrawable(Display *display, XID handle); +extern Bool +DRI2ReemitDrawableInfo(Display *dpy, XID handle, unsigned int *head); + +#endif diff --git a/src/glx/x11/dri2_glx.c b/src/glx/x11/dri2_glx.c new file mode 100644 index 00000000000..1a6abaedab8 --- /dev/null +++ b/src/glx/x11/dri2_glx.c @@ -0,0 +1,471 @@ +/* + * Copyright © 2008 Red Hat, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Soft- + * ware"), to deal in the Software without restriction, including without + * limitation the rights to use, copy, modify, merge, publish, distribute, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, provided that the above copyright + * notice(s) and this permission notice appear in all copies of the Soft- + * ware and that both the above copyright notice(s) and this permission + * notice appear in supporting documentation. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL- + * ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY + * RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN + * THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSE- + * QUENTIAL 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 PERFOR- + * MANCE OF THIS SOFTWARE. + * + * Except as contained in this notice, the name of a copyright holder shall + * not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization of + * the copyright holder. + * + * Authors: + * Kristian Høgsberg ([email protected]) + */ + +#ifdef GLX_DIRECT_RENDERING + +#include <unistd.h> +#include <X11/Xlibint.h> +#include <X11/extensions/Xext.h> +#include <X11/extensions/extutil.h> +#include <X11/extensions/Xfixes.h> +#include <X11/extensions/Xdamage.h> +#include "glheader.h" +#include "glxclient.h" +#include "xf86dri.h" +#include "sarea.h" +#include <stdio.h> +#include <dlfcn.h> +#include <sys/types.h> +#include <stdarg.h> +#include "glcontextmodes.h" +#include <sys/mman.h> +#include "xf86drm.h" +#include "dri2.h" + + +#ifndef RTLD_NOW +#define RTLD_NOW 0 +#endif +#ifndef RTLD_GLOBAL +#define RTLD_GLOBAL 0 +#endif + +typedef struct __GLXDRIdisplayPrivateRec __GLXDRIdisplayPrivate; +typedef struct __GLXDRIcontextPrivateRec __GLXDRIcontextPrivate; +typedef struct __GLXDRIconfigPrivateRec __GLXDRIconfigPrivate; + +struct __GLXDRIdisplayPrivateRec { + __GLXDRIdisplay base; + + /* + ** XFree86-DRI version information + */ + int driMajor; + int driMinor; + int driPatch; +}; + +struct __GLXDRIcontextPrivateRec { + __GLXDRIcontext base; + __DRIcontext *driContext; + __GLXscreenConfigs *psc; +}; + +struct __GLXDRIconfigPrivateRec { + __GLcontextModes modes; + const __DRIconfig *driConfig; +}; + +static void dri2DestroyContext(__GLXDRIcontext *context, + __GLXscreenConfigs *psc, Display *dpy) +{ + __GLXDRIcontextPrivate *pcp = (__GLXDRIcontextPrivate *) context; + const __DRIcoreExtension *core = pcp->psc->core; + + (*core->destroyContext)(pcp->driContext); + + Xfree(pcp); +} + +static Bool dri2BindContext(__GLXDRIcontext *context, + __GLXDRIdrawable *draw, __GLXDRIdrawable *read) +{ + __GLXDRIcontextPrivate *pcp = (__GLXDRIcontextPrivate *) context; + const __DRIcoreExtension *core = pcp->psc->core; + + return (*core->bindContext)(pcp->driContext, + draw->driDrawable, + read->driDrawable); +} + +static void dri2UnbindContext(__GLXDRIcontext *context) +{ + __GLXDRIcontextPrivate *pcp = (__GLXDRIcontextPrivate *) context; + const __DRIcoreExtension *core = pcp->psc->core; + + (*core->unbindContext)(pcp->driContext); +} + +static __GLXDRIcontext *dri2CreateContext(__GLXscreenConfigs *psc, + const __GLcontextModes *mode, + GLXContext gc, + GLXContext shareList, int renderType) +{ + __GLXDRIcontextPrivate *pcp, *pcp_shared; + __GLXDRIconfigPrivate *config = (__GLXDRIconfigPrivate *) mode; + const __DRIcoreExtension *core = psc->core; + __DRIcontext *shared = NULL; + + if (shareList) { + pcp_shared = (__GLXDRIcontextPrivate *) shareList->driContext; + shared = pcp_shared->driContext; + } + + pcp = Xmalloc(sizeof *pcp); + if (pcp == NULL) + return NULL; + + pcp->psc = psc; + pcp->driContext = + (*core->createNewContext)(psc->__driScreen, + config->driConfig, shared, pcp); + gc->__driContext = pcp->driContext; + + if (pcp->driContext == NULL) { + Xfree(pcp); + return NULL; + } + + pcp->base.destroyContext = dri2DestroyContext; + pcp->base.bindContext = dri2BindContext; + pcp->base.unbindContext = dri2UnbindContext; + + return &pcp->base; +} + +static void dri2DestroyDrawable(__GLXDRIdrawable *pdraw) +{ + const __DRIcoreExtension *core = pdraw->psc->core; + + (*core->destroyDrawable)(pdraw->driDrawable); + DRI2DestroyDrawable(pdraw->psc->dpy, pdraw->drawable); + Xfree(pdraw); +} + +static __GLXDRIdrawable *dri2CreateDrawable(__GLXscreenConfigs *psc, + XID xDrawable, + GLXDrawable drawable, + const __GLcontextModes *modes) +{ + __GLXDRIdrawable *pdraw; + __GLXDRIconfigPrivate *config = (__GLXDRIconfigPrivate *) modes; + unsigned int handle, head; + const __DRIcoreExtension *core = psc->core; + + pdraw = Xmalloc(sizeof(*pdraw)); + if (!pdraw) + return NULL; + + pdraw->destroyDrawable = dri2DestroyDrawable; + pdraw->xDrawable = xDrawable; + pdraw->drawable = drawable; + pdraw->psc = psc; + + fprintf(stderr, "calling DRI2CreateDrawable, XID 0x%lx, GLX ID 0x%lx\n", + xDrawable, drawable); + + if (!DRI2CreateDrawable(psc->dpy, xDrawable, &handle, &head)) { + Xfree(pdraw); + return NULL; + } + + fprintf(stderr, "success, head 0x%x, handle 0x%x\n", head, handle); + + /* Create a new drawable */ + pdraw->driDrawable = + (*core->createNewDrawable)(psc->__driScreen, + config->driConfig, + handle, + head, + pdraw); + + if (!pdraw->driDrawable) { + DRI2DestroyDrawable(psc->dpy, drawable); + Xfree(pdraw); + return NULL; + } + + return pdraw; +} + +static void dri2DestroyScreen(__GLXscreenConfigs *psc) +{ + /* Free the direct rendering per screen data */ + (*psc->core->destroyScreen)(psc->__driScreen); + drmClose(psc->fd); + psc->__driScreen = NULL; +} + + +static void dri2ReemitDrawableInfo(__DRIdrawable *draw, unsigned int *tail, + void *loaderPrivate) +{ + __GLXDRIdrawable *pdraw = loaderPrivate; + + DRI2ReemitDrawableInfo(pdraw->psc->dpy, pdraw->drawable, tail); +} + +static void dri2PostDamage(__DRIdrawable *draw, + struct drm_clip_rect *rects, + int numRects, void *loaderPrivate) +{ + XRectangle *xrects; + XserverRegion region; + __GLXDRIdrawable *glxDraw = loaderPrivate; + __GLXscreenConfigs *psc = glxDraw->psc; + Display *dpy = psc->dpy; + int i; + + xrects = malloc(sizeof(XRectangle) * numRects); + if (xrects == NULL) + return; + + for (i = 0; i < numRects; i++) { + xrects[i].x = rects[i].x1; + xrects[i].y = rects[i].y1; + xrects[i].width = rects[i].x2 - rects[i].x1; + xrects[i].height = rects[i].y2 - rects[i].y1; + } + region = XFixesCreateRegion(dpy, xrects, numRects); + free(xrects); + XDamageAdd(dpy, glxDraw->xDrawable, region); + XFixesDestroyRegion(dpy, region); +} + +static const __DRIloaderExtension dri2LoaderExtension = { + { __DRI_LOADER, __DRI_LOADER_VERSION }, + dri2ReemitDrawableInfo, + dri2PostDamage +}; + +_X_HIDDEN const __DRIsystemTimeExtension systemTimeExtension; + +static const __DRIextension *loader_extensions[] = { + &dri2LoaderExtension.base, + &systemTimeExtension.base, + NULL +}; + +/* We need a dri_common.h type-of-thing. */ + +extern void ErrorMessageF(const char *f, ...); + +extern void *driOpenDriver(const char *driverName); + +extern __GLcontextModes * +driConvertConfigs(const __DRIcoreExtension *core, + __GLcontextModes *modes, const __DRIconfig **configs); + +extern void driBindExtensions(__GLXscreenConfigs *psc); + +void +driBindExtensions(__GLXscreenConfigs *psc) +{ + const __DRIextension **extensions; + int i; + + extensions = psc->core->getExtensions(psc->__driScreen); + + for (i = 0; extensions[i]; i++) { +#ifdef __DRI_COPY_SUB_BUFFER + if (strcmp(extensions[i]->name, __DRI_COPY_SUB_BUFFER) == 0) { + psc->copySubBuffer = (__DRIcopySubBufferExtension *) extensions[i]; + __glXEnableDirectExtension(psc, "GLX_MESA_copy_sub_buffer_bit"); + } +#endif + +#ifdef __DRI_SWAP_CONTROL + if (strcmp(extensions[i]->name, __DRI_SWAP_CONTROL) == 0) { + psc->swapControl = (__DRIswapControlExtension *) extensions[i]; + __glXEnableDirectExtension(psc, "GLX_SGI_swap_control"); + __glXEnableDirectExtension(psc, "GLX_MESA_swap_control"); + } +#endif + +#ifdef __DRI_ALLOCATE + if (strcmp(extensions[i]->name, __DRI_ALLOCATE) == 0) { + psc->allocate = (__DRIallocateExtension *) extensions[i]; + __glXEnableDirectExtension(psc, "GLX_MESA_allocate_memory"); + } +#endif + +#ifdef __DRI_FRAME_TRACKING + if (strcmp(extensions[i]->name, __DRI_FRAME_TRACKING) == 0) { + psc->frameTracking = (__DRIframeTrackingExtension *) extensions[i]; + __glXEnableDirectExtension(psc, "GLX_MESA_swap_frame_usage"); + } +#endif + +#ifdef __DRI_MEDIA_STREAM_COUNTER + if (strcmp(extensions[i]->name, __DRI_MEDIA_STREAM_COUNTER) == 0) { + psc->msc = (__DRImediaStreamCounterExtension *) extensions[i]; + __glXEnableDirectExtension(psc, "GLX_SGI_video_sync"); + } +#endif + +#ifdef __DRI_SWAP_BUFFER_COUNTER + /* No driver supports this at this time and the extension is + * not defined in dri_interface.h. Will enable + * GLX_OML_sync_control if implemented. */ +#endif + +#ifdef __DRI_READ_DRAWABLE + if (strcmp(extensions[i]->name, __DRI_READ_DRAWABLE) == 0) { + __glXEnableDirectExtension(psc, "GLX_SGI_make_current_read"); + } +#endif + +#ifdef __DRI_TEX_BUFFER + if (strcmp(extensions[i]->name, __DRI_TEX_BUFFER) == 0) { + psc->texBuffer = (__DRItexBufferExtension *) extensions[i]; + __glXEnableDirectExtension(psc, "GLX_EXT_texture_from_pixmap"); + } +#endif + + /* Ignore unknown extensions */ + } +} + +static __GLXDRIscreen *dri2CreateScreen(__GLXscreenConfigs *psc, int screen, + __GLXdisplayPrivate *priv) +{ + const __DRIconfig **driver_configs; + const __DRIextension **extensions; + __GLXDRIscreen *psp; + unsigned int sareaHandle; + char *driverName, *busID; + drm_magic_t magic; + int i; + + psp = Xmalloc(sizeof *psp); + if (psp == NULL) + return NULL; + + /* Initialize per screen dynamic client GLX extensions */ + psc->ext_list_first_time = GL_TRUE; + + if (!DRI2Connect(psc->dpy, screen, &driverName, &busID, &sareaHandle)) + return NULL; + + psc->driver = driOpenDriver(driverName); + if (psc->driver == NULL) + goto handle_error; + + extensions = dlsym(psc->driver, __DRI_DRIVER_EXTENSIONS); + if (extensions == NULL) { + ErrorMessageF("driver exports no extensions (%s)\n", dlerror()); + goto handle_error; + } + + for (i = 0; extensions[i]; i++) { + if (strcmp(extensions[i]->name, __DRI_CORE) == 0) + psc->core = (__DRIcoreExtension *) extensions[i]; + } + + if (psc->core == NULL) { + ErrorMessageF("core dri extension not found\n"); + goto handle_error; + } + + psc->fd = drmOpen(NULL, busID); + if (psc->fd < 0) { + ErrorMessageF("failed to open drm device: %s\n", strerror(errno)); + return NULL; + } + + if (drmGetMagic(psc->fd, &magic)) + return NULL; + + if (!DRI2AuthConnection(psc->dpy, screen, magic)) { + ErrorMessageF("failed to authenticate drm access\n"); + return NULL; + } + + psc->__driScreen = + psc->core->createNewScreen(screen, psc->fd, sareaHandle, + loader_extensions, &driver_configs, psc); + if (psc->__driScreen == NULL) { + ErrorMessageF("failed to create dri screen\n"); + return NULL; + } + + driBindExtensions(psc); + + psc->configs = driConvertConfigs(psc->core, psc->configs, driver_configs); + psc->visuals = driConvertConfigs(psc->core, psc->visuals, driver_configs); + + psp->destroyScreen = dri2DestroyScreen; + psp->createContext = dri2CreateContext; + psp->createDrawable = dri2CreateDrawable; + + Xfree(driverName); + Xfree(busID); + + return psp; + + handle_error: + Xfree(driverName); + Xfree(busID); + + /* FIXME: clean up here */ + + return NULL; +} + +/* Called from __glXFreeDisplayPrivate. + */ +static void dri2DestroyDisplay(__GLXDRIdisplay *dpy) +{ + Xfree(dpy); +} + +/* + * Allocate, initialize and return a __DRIdisplayPrivate object. + * This is called from __glXInitialize() when we are given a new + * display pointer. + */ +_X_HIDDEN __GLXDRIdisplay *dri2CreateDisplay(Display *dpy) +{ + __GLXDRIdisplayPrivate *pdp; + int eventBase, errorBase; + + if (!DRI2QueryExtension(dpy, &eventBase, &errorBase)) + return NULL; + + pdp = Xmalloc(sizeof *pdp); + if (pdp == NULL) + return NULL; + + if (!DRI2QueryVersion(dpy, &pdp->driMajor, &pdp->driMinor)) { + Xfree(pdp); + return NULL; + } + + pdp->driPatch = 0; + + pdp->base.destroyDisplay = dri2DestroyDisplay; + pdp->base.createScreen = dri2CreateScreen; + + return &pdp->base; +} + +#endif /* GLX_DIRECT_RENDERING */ diff --git a/src/glx/x11/dri_glx.c b/src/glx/x11/dri_glx.c index 514c082f6cd..31ade0da2a3 100644 --- a/src/glx/x11/dri_glx.c +++ b/src/glx/x11/dri_glx.c @@ -52,7 +52,6 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include <sys/mman.h> #include "xf86drm.h" - #ifndef RTLD_NOW #define RTLD_NOW 0 #endif @@ -62,6 +61,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. typedef struct __GLXDRIdisplayPrivateRec __GLXDRIdisplayPrivate; typedef struct __GLXDRIcontextPrivateRec __GLXDRIcontextPrivate; +typedef struct __GLXDRIconfigPrivateRec __GLXDRIconfigPrivate; struct __GLXDRIdisplayPrivateRec { __GLXDRIdisplay base; @@ -76,8 +76,14 @@ struct __GLXDRIdisplayPrivateRec { struct __GLXDRIcontextPrivateRec { __GLXDRIcontext base; - __DRIcontext driContext; + __DRIcontext *driContext; XID hwContextID; + __GLXscreenConfigs *psc; +}; + +struct __GLXDRIconfigPrivateRec { + __GLcontextModes modes; + const __DRIconfig *driConfig; }; #ifndef DEFAULT_DRIVER_DIR @@ -98,10 +104,12 @@ static void InfoMessageF(const char *f, ...) } } +extern void ErrorMessageF(const char *f, ...); + /** * Print error to stderr, unless LIBGL_DEBUG=="quiet". */ -static void ErrorMessageF(const char *f, ...) +_X_HIDDEN void ErrorMessageF(const char *f, ...) { va_list args; const char *env; @@ -114,16 +122,7 @@ static void ErrorMessageF(const char *f, ...) } } - -/** - * Versioned name of the expected \c __driCreateNewScreen function. - * - * The version of the last incompatible loader/driver inteface change is - * appended to the name of the \c __driCreateNewScreen function. This - * prevents loaders from trying to load drivers that are too old. - */ -static const char createNewScreenName[] = __DRI_CREATE_NEW_SCREEN_STRING; - +extern void *driOpenDriver(const char *driverName); /** * Try to \c dlopen the named driver. @@ -137,7 +136,7 @@ static const char createNewScreenName[] = __DRI_CREATE_NEW_SCREEN_STRING; * \returns * A handle from \c dlopen, or \c NULL if driver file not found. */ -static void *OpenDriver(const char *driverName) +_X_HIDDEN void *driOpenDriver(const char *driverName) { void *glhandle, *handle; const char *libPaths, *p, *next; @@ -244,7 +243,7 @@ static void *driGetDriver(Display *dpy, int scrNum) void *ret; if (GetDriverName(dpy, scrNum, &driverName)) { - ret = OpenDriver(driverName); + ret = driOpenDriver(driverName); if (driverName) Xfree(driverName); return ret; @@ -287,17 +286,22 @@ PUBLIC const char *glXGetScreenDriver (Display *dpy, int scrNum) { * * Note: The driver remains opened after this function returns. */ -PUBLIC const char *glXGetDriverConfig (const char *driverName) { - void *handle = OpenDriver (driverName); +PUBLIC const char *glXGetDriverConfig (const char *driverName) +{ + void *handle = driOpenDriver (driverName); if (handle) return dlsym (handle, "__driConfigOptions"); else return NULL; } -static void -filter_modes( __GLcontextModes ** server_modes, - const __GLcontextModes * driver_modes ) +extern void +driFilterModes(__GLcontextModes ** server_modes, + const __GLcontextModes * driver_modes); + +_X_HIDDEN void +driFilterModes(__GLcontextModes ** server_modes, + const __GLcontextModes * driver_modes) { __GLcontextModes * m; __GLcontextModes ** prev_next; @@ -349,6 +353,7 @@ filter_modes( __GLcontextModes ** server_modes, } #ifdef XDAMAGE_1_1_INTERFACE + static GLboolean has_damage_post(Display *dpy) { static GLboolean inited = GL_FALSE; @@ -369,20 +374,18 @@ static GLboolean has_damage_post(Display *dpy) return has_damage; } -#endif /* XDAMAGE_1_1_INTERFACE */ static void __glXReportDamage(__DRIdrawable *driDraw, int x, int y, drm_clip_rect_t *rects, int num_rects, - GLboolean front_buffer) + GLboolean front_buffer, + void *loaderPrivate) { -#ifdef XDAMAGE_1_1_INTERFACE XRectangle *xrects; XserverRegion region; int i; int x_off, y_off; - __GLXDRIdrawable *glxDraw = - containerOf(driDraw, __GLXDRIdrawable, driDrawable); + __GLXDRIdrawable *glxDraw = loaderPrivate; __GLXscreenConfigs *psc = glxDraw->psc; Display *dpy = psc->dpy; Drawable drawable; @@ -397,7 +400,7 @@ static void __glXReportDamage(__DRIdrawable *driDraw, } else{ x_off = 0; y_off = 0; - drawable = glxDraw->drawable; + drawable = glxDraw->xDrawable; } xrects = malloc(sizeof(XRectangle) * num_rects); @@ -414,19 +417,25 @@ static void __glXReportDamage(__DRIdrawable *driDraw, free(xrects); XDamageAdd(dpy, drawable, region); XFixesDestroyRegion(dpy, region); -#endif } +static const __DRIdamageExtension damageExtension = { + { __DRI_DAMAGE, __DRI_DAMAGE_VERSION }, + __glXReportDamage, +}; + +#endif + static GLboolean __glXDRIGetDrawableInfo(__DRIdrawable *drawable, unsigned int *index, unsigned int *stamp, int *X, int *Y, int *W, int *H, int *numClipRects, drm_clip_rect_t ** pClipRects, int *backX, int *backY, - int *numBackClipRects, drm_clip_rect_t **pBackClipRects) + int *numBackClipRects, drm_clip_rect_t **pBackClipRects, + void *loaderPrivate) { - __GLXDRIdrawable *glxDraw = - containerOf(drawable, __GLXDRIdrawable, driDrawable); + __GLXDRIdrawable *glxDraw = loaderPrivate; __GLXscreenConfigs *psc = glxDraw->psc; Display *dpy = psc->dpy; @@ -437,17 +446,7 @@ __glXDRIGetDrawableInfo(__DRIdrawable *drawable, numBackClipRects, pBackClipRects); } - -/** - * Table of functions exported by the loader to the driver. - */ -static const __DRIcontextModesExtension contextModesExtension = { - { __DRI_CONTEXT_MODES, __DRI_CONTEXT_MODES_VERSION }, - _gl_context_modes_create, - _gl_context_modes_destroy, -}; - -static const __DRIsystemTimeExtension systemTimeExtension = { +_X_HIDDEN const __DRIsystemTimeExtension systemTimeExtension = { { __DRI_SYSTEM_TIME, __DRI_SYSTEM_TIME_VERSION }, __glXGetUST, __driGetMscRateOML, @@ -458,19 +457,189 @@ static const __DRIgetDrawableInfoExtension getDrawableInfoExtension = { __glXDRIGetDrawableInfo }; -static const __DRIdamageExtension damageExtension = { - { __DRI_DAMAGE, __DRI_DAMAGE_VERSION }, - __glXReportDamage, -}; - static const __DRIextension *loader_extensions[] = { - &contextModesExtension.base, &systemTimeExtension.base, &getDrawableInfoExtension.base, + +#ifdef XDAMAGE_1_1_INTERFACE &damageExtension.base, +#endif + NULL }; +#define __ATTRIB(attrib, field) \ + { attrib, offsetof(__GLcontextModes, field) } + +static const struct { unsigned int attrib, offset; } attribMap[] = { + __ATTRIB(__DRI_ATTRIB_BUFFER_SIZE, rgbBits), + __ATTRIB(__DRI_ATTRIB_LEVEL, level), + __ATTRIB(__DRI_ATTRIB_RED_SIZE, redBits), + __ATTRIB(__DRI_ATTRIB_GREEN_SIZE, greenBits), + __ATTRIB(__DRI_ATTRIB_BLUE_SIZE, blueBits), + __ATTRIB(__DRI_ATTRIB_ALPHA_SIZE, alphaBits), + __ATTRIB(__DRI_ATTRIB_DEPTH_SIZE, depthBits), + __ATTRIB(__DRI_ATTRIB_STENCIL_SIZE, stencilBits), + __ATTRIB(__DRI_ATTRIB_ACCUM_RED_SIZE, accumRedBits), + __ATTRIB(__DRI_ATTRIB_ACCUM_GREEN_SIZE, accumGreenBits), + __ATTRIB(__DRI_ATTRIB_ACCUM_BLUE_SIZE, accumBlueBits), + __ATTRIB(__DRI_ATTRIB_ACCUM_ALPHA_SIZE, accumAlphaBits), + __ATTRIB(__DRI_ATTRIB_SAMPLE_BUFFERS, sampleBuffers), + __ATTRIB(__DRI_ATTRIB_SAMPLES, samples), + __ATTRIB(__DRI_ATTRIB_DOUBLE_BUFFER, doubleBufferMode), + __ATTRIB(__DRI_ATTRIB_STEREO, stereoMode), + __ATTRIB(__DRI_ATTRIB_AUX_BUFFERS, numAuxBuffers), +#if 0 + __ATTRIB(__DRI_ATTRIB_TRANSPARENT_TYPE, transparentPixel), + __ATTRIB(__DRI_ATTRIB_TRANSPARENT_INDEX_VALUE, transparentIndex), + __ATTRIB(__DRI_ATTRIB_TRANSPARENT_RED_VALUE, transparentRed), + __ATTRIB(__DRI_ATTRIB_TRANSPARENT_GREEN_VALUE, transparentGreen), + __ATTRIB(__DRI_ATTRIB_TRANSPARENT_BLUE_VALUE, transparentBlue), + __ATTRIB(__DRI_ATTRIB_TRANSPARENT_ALPHA_VALUE, transparentAlpha), + __ATTRIB(__DRI_ATTRIB_RED_MASK, redMask), + __ATTRIB(__DRI_ATTRIB_GREEN_MASK, greenMask), + __ATTRIB(__DRI_ATTRIB_BLUE_MASK, blueMask), + __ATTRIB(__DRI_ATTRIB_ALPHA_MASK, alphaMask), +#endif + __ATTRIB(__DRI_ATTRIB_MAX_PBUFFER_WIDTH, maxPbufferWidth), + __ATTRIB(__DRI_ATTRIB_MAX_PBUFFER_HEIGHT, maxPbufferHeight), + __ATTRIB(__DRI_ATTRIB_MAX_PBUFFER_PIXELS, maxPbufferPixels), + __ATTRIB(__DRI_ATTRIB_OPTIMAL_PBUFFER_WIDTH, optimalPbufferWidth), + __ATTRIB(__DRI_ATTRIB_OPTIMAL_PBUFFER_HEIGHT, optimalPbufferHeight), +#if 0 + __ATTRIB(__DRI_ATTRIB_SWAP_METHOD, swapMethod), + __ATTRIB(__DRI_ATTRIB_BIND_TO_TEXTURE_RGB, bindToTextureRgb), + __ATTRIB(__DRI_ATTRIB_BIND_TO_TEXTURE_RGBA, bindToTextureRgba), + __ATTRIB(__DRI_ATTRIB_BIND_TO_MIPMAP_TEXTURE, bindToMipmapTexture), + __ATTRIB(__DRI_ATTRIB_YINVERTED, yInverted), +#endif +}; + +#define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0])) + +static int +scalarEqual(__GLcontextModes *mode, unsigned int attrib, unsigned int value) +{ + unsigned int driValue; + int i; + + for (i = 0; i < ARRAY_SIZE(attribMap); i++) + if (attribMap[i].attrib == attrib) { + driValue = *(unsigned int *) ((char *) mode + attribMap[i].offset); + return driValue == value; + } + + return GL_TRUE; /* Is a non-existing attribute equal to value? */ +} + +static int +driConfigEqual(const __DRIcoreExtension *core, + __GLcontextModes *modes, const __DRIconfig *driConfig) +{ + unsigned int attrib, value, glxValue; + int i; + + i = 0; + while (core->indexConfigAttrib(driConfig, i++, &attrib, &value)) { + switch (attrib) { + case __DRI_ATTRIB_RENDER_TYPE: + glxValue = 0; + if (value & __DRI_ATTRIB_RGBA_BIT) { + glxValue |= GLX_RGBA_BIT; + } else if (value & __DRI_ATTRIB_COLOR_INDEX_BIT) { + glxValue |= GLX_COLOR_INDEX_BIT; + } + if (glxValue != modes->renderType) + return GL_FALSE; + break; + + case __DRI_ATTRIB_CONFIG_CAVEAT: + if (value & __DRI_ATTRIB_NON_CONFORMANT_CONFIG) + glxValue = GLX_NON_CONFORMANT_CONFIG; + else if (value & __DRI_ATTRIB_SLOW_BIT) + glxValue = GLX_SLOW_CONFIG; + else + glxValue = GLX_NONE; + if (glxValue != modes->visualRating) + return GL_FALSE; + break; + +#if 0 + /* The X server doesn't send these, so ignore them for now. */ + case __DRI_ATTRIB_BIND_TO_TEXTURE_TARGETS: + glxValue = 0; + if (value & __DRI_ATTRIB_TEXTURE_1D_BIT) + glxValue |= GLX_TEXTURE_1D_BIT_EXT; + if (value & __DRI_ATTRIB_TEXTURE_2D_BIT) + glxValue |= GLX_TEXTURE_2D_BIT_EXT; + if (value & __DRI_ATTRIB_TEXTURE_RECTANGLE_BIT) + glxValue |= GLX_TEXTURE_RECTANGLE_BIT_EXT; + if (glxValue != modes->bindToTextureTargets) + return GL_FALSE; + break; +#endif + + default: + if (!scalarEqual(modes, attrib, value)) + return GL_FALSE; + } + } + + return GL_TRUE; +} + +static __GLcontextModes * +createDriMode(const __DRIcoreExtension *core, + __GLcontextModes *modes, const __DRIconfig **driConfigs) +{ + __GLXDRIconfigPrivate *config; + int i; + + for (i = 0; driConfigs[i]; i++) { + if (driConfigEqual(core, modes, driConfigs[i])) + break; + } + + if (driConfigs[i] == NULL) + return NULL; + + config = Xmalloc(sizeof *config); + if (config == NULL) + return NULL; + + config->modes = *modes; + config->driConfig = driConfigs[i]; + + return &config->modes; +} + +extern __GLcontextModes * +driConvertConfigs(const __DRIcoreExtension *core, + __GLcontextModes *modes, const __DRIconfig **configs); + +_X_HIDDEN __GLcontextModes * +driConvertConfigs(const __DRIcoreExtension *core, + __GLcontextModes *modes, const __DRIconfig **configs) +{ + __GLcontextModes head, *tail, *m; + + tail = &head; + head.next = NULL; + for (m = modes; m; m = m->next) { + tail->next = createDriMode(core, m, configs); + if (tail->next == NULL) { + /* no matching dri config for m */ + continue; + } + + + tail = tail->next; + } + + _gl_context_modes_destroy(modes); + + return head.next; +} /** * Perform the required libGL-side initialization and call the client-side @@ -491,8 +660,7 @@ static const __DRIextension *loader_extensions[] = { */ static void * CallCreateNewScreen(Display *dpy, int scrn, __GLXscreenConfigs *psc, - __GLXDRIdisplayPrivate * driDpy, - PFNCREATENEWSCREENFUNC createNewScreen) + __GLXDRIdisplayPrivate * driDpy) { void *psp = NULL; #ifndef GLX_USE_APPLEGL @@ -507,12 +675,12 @@ CallCreateNewScreen(Display *dpy, int scrn, __GLXscreenConfigs *psc, int status; const char * err_msg; const char * err_extra; + const __DRIconfig **driver_configs; dri_version.major = driDpy->driMajor; dri_version.minor = driDpy->driMinor; dri_version.patch = driDpy->driPatch; - err_msg = "XF86DRIOpenConnection"; err_extra = NULL; @@ -608,12 +776,9 @@ CallCreateNewScreen(Display *dpy, int scrn, __GLXscreenConfigs *psc, err_extra = strerror( -status ); if ( status == 0 ) { - __GLcontextModes * driver_modes = NULL; - err_msg = "InitDriver"; err_extra = NULL; - psp = (*createNewScreen)(scrn, - &psc->__driScreen, + psp = (*psc->legacy->createNewScreen)(scrn, & ddx_version, & dri_version, & drm_version, @@ -621,11 +786,17 @@ CallCreateNewScreen(Display *dpy, int scrn, __GLXscreenConfigs *psc, pSAREA, fd, loader_extensions, - & driver_modes ); - - filter_modes(&psc->configs, driver_modes); - filter_modes(&psc->visuals, driver_modes); - _gl_context_modes_destroy(driver_modes); + & driver_configs, + psc); + + psc->configs = + driConvertConfigs(psc->core, + psc->configs, + driver_configs); + psc->visuals = + driConvertConfigs(psc->core, + psc->visuals, + driver_configs); } } } @@ -674,7 +845,7 @@ static void driDestroyContext(__GLXDRIcontext *context, { __GLXDRIcontextPrivate *pcp = (__GLXDRIcontextPrivate *) context; - (*pcp->driContext.destroyContext)(&pcp->driContext); + (*psc->core->destroyContext)(pcp->driContext); XF86DRIDestroyContext(psc->dpy, psc->scr, pcp->hwContextID); } @@ -683,17 +854,19 @@ static Bool driBindContext(__GLXDRIcontext *context, __GLXDRIdrawable *draw, __GLXDRIdrawable *read) { __GLXDRIcontextPrivate *pcp = (__GLXDRIcontextPrivate *) context; + const __DRIcoreExtension *core = pcp->psc->core; - return (*pcp->driContext.bindContext)(&pcp->driContext, - &draw->driDrawable, - &read->driDrawable); + return (*core->bindContext)(pcp->driContext, + draw->driDrawable, + read->driDrawable); } static void driUnbindContext(__GLXDRIcontext *context) { __GLXDRIcontextPrivate *pcp = (__GLXDRIcontextPrivate *) context; + const __DRIcoreExtension *core = pcp->psc->core; - (*pcp->driContext.unbindContext)(&pcp->driContext); + (*core->unbindContext)(pcp->driContext); } static __GLXDRIcontext *driCreateContext(__GLXscreenConfigs *psc, @@ -704,17 +877,19 @@ static __GLXDRIcontext *driCreateContext(__GLXscreenConfigs *psc, __GLXDRIcontextPrivate *pcp, *pcp_shared; drm_context_t hwContext; __DRIcontext *shared = NULL; + __GLXDRIconfigPrivate *config = (__GLXDRIconfigPrivate *) mode; if (psc && psc->driScreen) { if (shareList) { pcp_shared = (__GLXDRIcontextPrivate *) shareList->driContext; - shared = &pcp_shared->driContext; + shared = pcp_shared->driContext; } pcp = Xmalloc(sizeof *pcp); if (pcp == NULL) return NULL; + pcp->psc = psc; if (!XF86DRICreateContextWithConfig(psc->dpy, psc->scr, mode->visualID, &pcp->hwContextID, &hwContext)) { @@ -722,13 +897,14 @@ static __GLXDRIcontext *driCreateContext(__GLXscreenConfigs *psc, return NULL; } - pcp->driContext.private = - (*psc->__driScreen.createNewContext)(&psc->__driScreen, - mode, renderType, - shared, - hwContext, - &pcp->driContext); - if (pcp->driContext.private == NULL) { + pcp->driContext = + (*psc->legacy->createNewContext)(psc->__driScreen, + config->driConfig, + renderType, + shared, + hwContext, + pcp); + if (pcp->driContext == NULL) { XF86DRIDestroyContext(psc->dpy, psc->scr, pcp->hwContextID); Xfree(pcp); return NULL; @@ -748,18 +924,24 @@ static void driDestroyDrawable(__GLXDRIdrawable *pdraw) { __GLXscreenConfigs *psc = pdraw->psc; - (*pdraw->driDrawable.destroyDrawable)(&pdraw->driDrawable); + (*psc->core->destroyDrawable)(pdraw->driDrawable); XF86DRIDestroyDrawable(psc->dpy, psc->scr, pdraw->drawable); Xfree(pdraw); } static __GLXDRIdrawable *driCreateDrawable(__GLXscreenConfigs *psc, + XID xDrawable, GLXDrawable drawable, - GLXContext gc) + const __GLcontextModes *modes) { __GLXDRIdrawable *pdraw; drm_drawable_t hwDrawable; void *empty_attribute_list = NULL; + __GLXDRIconfigPrivate *config = (__GLXDRIconfigPrivate *) modes; + + /* Old dri can't handle GLX 1.3+ drawable constructors. */ + if (xDrawable != drawable) + return NULL; pdraw = Xmalloc(sizeof(*pdraw)); if (!pdraw) @@ -772,16 +954,15 @@ static __GLXDRIdrawable *driCreateDrawable(__GLXscreenConfigs *psc, return NULL; /* Create a new drawable */ - pdraw->driDrawable.private = - (*psc->__driScreen.createNewDrawable)(&psc->__driScreen, - gc->mode, - &pdraw->driDrawable, - hwDrawable, - GLX_WINDOW_BIT, - 0, - empty_attribute_list); - - if (!pdraw->driDrawable.private) { + pdraw->driDrawable = + (*psc->legacy->createNewDrawable)(psc->__driScreen, + config->driConfig, + hwDrawable, + GLX_WINDOW_BIT, + empty_attribute_list, + pdraw); + + if (!pdraw->driDrawable) { XF86DRIDestroyDrawable(psc->dpy, psc->scr, drawable); Xfree(pdraw); return NULL; @@ -795,19 +976,23 @@ static __GLXDRIdrawable *driCreateDrawable(__GLXscreenConfigs *psc, static void driDestroyScreen(__GLXscreenConfigs *psc) { /* Free the direct rendering per screen data */ - if (psc->__driScreen.private) - (*psc->__driScreen.destroyScreen)(&psc->__driScreen); - psc->__driScreen.private = NULL; + if (psc->__driScreen) + (*psc->core->destroyScreen)(psc->__driScreen); + psc->__driScreen = NULL; if (psc->driver) dlclose(psc->driver); } +void +driBindExtensions(__GLXscreenConfigs *psc); + static __GLXDRIscreen *driCreateScreen(__GLXscreenConfigs *psc, int screen, __GLXdisplayPrivate *priv) { - PFNCREATENEWSCREENFUNC createNewScreen; __GLXDRIdisplayPrivate *pdp; __GLXDRIscreen *psp; + const __DRIextension **extensions; + int i; psp = Xmalloc(sizeof *psp); if (psp == NULL) @@ -817,15 +1002,40 @@ static __GLXDRIscreen *driCreateScreen(__GLXscreenConfigs *psc, int screen, psc->ext_list_first_time = GL_TRUE; psc->driver = driGetDriver(priv->dpy, screen); - createNewScreen = dlsym(psc->driver, createNewScreenName); - if (createNewScreen == NULL) + if (psc->driver == NULL) { + Xfree(psp); + return NULL; + } + + extensions = dlsym(psc->driver, __DRI_DRIVER_EXTENSIONS); + if (extensions == NULL) { + ErrorMessageF("driver exports no extensions (%s)\n", dlerror()); + Xfree(psp); return NULL; + } + for (i = 0; extensions[i]; i++) { + if (strcmp(extensions[i]->name, __DRI_CORE) == 0) + psc->core = (__DRIcoreExtension *) extensions[i]; + if (strcmp(extensions[i]->name, __DRI_LEGACY) == 0) + psc->legacy = (__DRIlegacyExtension *) extensions[i]; + } + + if (psc->core == NULL || psc->legacy == NULL) { + Xfree(psp); + return NULL; + } + pdp = (__GLXDRIdisplayPrivate *) priv->driDisplay; - psc->__driScreen.private = - CallCreateNewScreen(psc->dpy, screen, psc, pdp, createNewScreen); - if (psc->__driScreen.private != NULL) - __glXScrEnableDRIExtension(psc); + psc->__driScreen = + CallCreateNewScreen(psc->dpy, screen, psc, pdp); + if (psc->__driScreen == NULL) { + dlclose(psc->driver); + Xfree(psp); + return NULL; + } + + driBindExtensions(psc); psp->destroyScreen = driDestroyScreen; psp->createContext = driCreateContext; diff --git a/src/glx/x11/glx_pbuffer.c b/src/glx/x11/glx_pbuffer.c index 52dad65170f..b0a8f71fd4a 100644 --- a/src/glx/x11/glx_pbuffer.c +++ b/src/glx/x11/glx_pbuffer.c @@ -271,6 +271,32 @@ GetDrawableAttribute( Display *dpy, GLXDrawable drawable, return 0; } +#ifdef GLX_DIRECT_RENDERING +extern __GLXDRIdrawable * +GetGLXDRIDrawable(Display *dpy, GLXDrawable drawable, int * const scrn_num); + +static GLenum +determineTextureTarget(const int *attribs, int numAttribs) +{ + GLenum target = 0; + int i; + + for (i = 0; i < numAttribs; i++) { + if (attribs[2 * i] == GLX_TEXTURE_TARGET_EXT) { + switch (attribs[2 * i + 1]) { + case GLX_TEXTURE_2D_EXT: + target = GL_TEXTURE_2D; + break; + case GLX_TEXTURE_RECTANGLE_EXT: + target = GL_TEXTURE_RECTANGLE_ARB; + break; + } + } + } + + return target; +} +#endif /** * Create a non-pbuffer GLX drawable. @@ -306,7 +332,7 @@ CreateDrawable( Display *dpy, const __GLcontextModes * fbconfig, req->glxCode = glxCode; req->screen = (CARD32) fbconfig->screen; req->fbconfig = fbconfig->fbconfigID; - req->window = (GLXPbuffer) drawable; + req->window = (CARD32) drawable; req->glxwindow = (GLXWindow) XAllocID(dpy); req->numAttribs = (CARD32) i; @@ -315,6 +341,34 @@ CreateDrawable( Display *dpy, const __GLcontextModes * fbconfig, UnlockDisplay(dpy); SyncHandle(); +#ifdef GLX_DIRECT_RENDERING + do { + /* FIXME: Maybe delay __DRIdrawable creation until the drawable + * is actually bound to a context... */ + + __GLXdisplayPrivate * const priv = __glXInitialize(dpy); + __GLXDRIdrawable *pdraw; + __GLXscreenConfigs *psc; + + psc = &priv->screenConfigs[fbconfig->screen]; + if (psc->driScreen == NULL) + break; + pdraw = psc->driScreen->createDrawable(psc, drawable, + req->glxwindow, fbconfig); + if (pdraw == NULL) { + fprintf(stderr, "failed to create drawable\n"); + break; + } + + if (__glxHashInsert(psc->drawHash, req->glxwindow, pdraw)) { + (*pdraw->destroyDrawable)(pdraw); + return None; /* FIXME: Check what we're supposed to do here... */ + } + + pdraw->textureTarget = determineTextureTarget(attrib_list, i); + } while (0); +#endif + return (GLXDrawable)req->glxwindow; } @@ -350,6 +404,20 @@ DestroyDrawable( Display * dpy, GLXDrawable drawable, CARD32 glxCode ) UnlockDisplay(dpy); SyncHandle(); +#ifdef GLX_DIRECT_RENDERING + { + int screen; + __GLXdisplayPrivate * const priv = __glXInitialize(dpy); + __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, &screen); + __GLXscreenConfigs *psc = &priv->screenConfigs[screen]; + + if (pdraw != NULL) { + (*pdraw->destroyDrawable)(pdraw); + __glxHashDelete(psc->drawHash, drawable); + } + } +#endif + return; } diff --git a/src/glx/x11/glxclient.h b/src/glx/x11/glxclient.h index ea90282b08f..5fd64209df5 100644 --- a/src/glx/x11/glxclient.h +++ b/src/glx/x11/glxclient.h @@ -59,7 +59,6 @@ #include "GL/glxproto.h" #include "GL/internal/glcore.h" #include "glapitable.h" -#include "glxextensions.h" #include "glxhash.h" #if defined( USE_XTHREADS ) # include <X11/Xthreads.h> @@ -97,6 +96,8 @@ typedef struct __GLXDRIscreenRec __GLXDRIscreen; typedef struct __GLXDRIdrawableRec __GLXDRIdrawable; typedef struct __GLXDRIcontextRec __GLXDRIcontext; +#include "glxextensions.h" + struct __GLXDRIdisplayRec { /** * Method to destroy the private DRI display data. @@ -117,8 +118,9 @@ struct __GLXDRIscreenRec { GLXContext shareList, int renderType); __GLXDRIdrawable *(*createDrawable)(__GLXscreenConfigs *psc, - GLXDrawable drawable, - GLXContext gc); + XID drawable, + GLXDrawable glxDrawable, + const __GLcontextModes *modes); }; struct __GLXDRIcontextRec { @@ -134,9 +136,11 @@ struct __GLXDRIcontextRec { struct __GLXDRIdrawableRec { void (*destroyDrawable)(__GLXDRIdrawable *drawable); + XID xDrawable; XID drawable; __GLXscreenConfigs *psc; - __DRIdrawable driDrawable; + __DRIdrawable *driDrawable; + GLenum textureTarget; }; /* @@ -144,6 +148,7 @@ struct __GLXDRIdrawableRec { ** dependent methods. */ extern __GLXDRIdisplay *driCreateDisplay(Display *dpy); +extern __GLXDRIdisplay *dri2CreateDisplay(Display *dpy); extern void DRI_glXUseXFont( Font font, int first, int count, int listbase ); @@ -364,6 +369,7 @@ struct __GLXcontextRec { #ifdef GLX_DIRECT_RENDERING __GLXDRIcontext *driContext; + __DRIcontext *__driContext; #endif /** @@ -458,32 +464,38 @@ struct __GLXscreenConfigsRec { /** * Per screen direct rendering interface functions and data. */ - __DRIscreen __driScreen; + __DRIscreen *__driScreen; + const __DRIcoreExtension *core; + const __DRIlegacyExtension *legacy; __glxHashTable *drawHash; Display *dpy; - int scr; + int scr, fd; void *driver; __GLXDRIscreen *driScreen; #ifdef __DRI_COPY_SUB_BUFFER - __DRIcopySubBufferExtension *copySubBuffer; + const __DRIcopySubBufferExtension *copySubBuffer; #endif #ifdef __DRI_SWAP_CONTROL - __DRIswapControlExtension *swapControl; + const __DRIswapControlExtension *swapControl; #endif #ifdef __DRI_ALLOCATE - __DRIallocateExtension *allocate; + const __DRIallocateExtension *allocate; #endif #ifdef __DRI_FRAME_TRACKING - __DRIframeTrackingExtension *frameTracking; + const __DRIframeTrackingExtension *frameTracking; #endif #ifdef __DRI_MEDIA_STREAM_COUNTER - __DRImediaStreamCounterExtension *msc; + const __DRImediaStreamCounterExtension *msc; +#endif + +#ifdef __DRI_TEX_BUFFER + const __DRItexBufferExtension *texBuffer; #endif #endif @@ -555,6 +567,7 @@ struct __GLXdisplayPrivateRec { * Per display direct rendering interface functions and data. */ __GLXDRIdisplay *driDisplay; + __GLXDRIdisplay *dri2Display; #endif }; @@ -720,7 +733,8 @@ extern GLboolean __glXGetMscRateOML(Display * dpy, GLXDrawable drawable, #ifdef GLX_DIRECT_RENDERING GLboolean -__driGetMscRateOML(__DRIdrawable *draw, int32_t *numerator, int32_t *denominator); +__driGetMscRateOML(__DRIdrawable *draw, + int32_t *numerator, int32_t *denominator, void *private); #endif #endif /* !__GLX_client_h__ */ diff --git a/src/glx/x11/glxcmds.c b/src/glx/x11/glxcmds.c index 8d0f07fd0a1..ddb006193c2 100644 --- a/src/glx/x11/glxcmds.c +++ b/src/glx/x11/glxcmds.c @@ -109,6 +109,9 @@ static void GarbageCollectDRIDrawables(Display *dpy, __GLXscreenConfigs *sc) XSetErrorHandler(oldXErrorHandler); } +extern __GLXDRIdrawable * +GetGLXDRIDrawable(Display *dpy, GLXDrawable drawable, int * const scrn_num); + /** * Get the __DRIdrawable for the drawable associated with a GLXContext * @@ -118,24 +121,27 @@ static void GarbageCollectDRIDrawables(Display *dpy, __GLXscreenConfigs *sc) * \returns A pointer to the context's __DRIdrawable on success, or NULL if * the drawable is not associated with a direct-rendering context. */ -static __DRIdrawable * -GetDRIDrawable( Display *dpy, GLXDrawable drawable, int * const scrn_num ) +_X_HIDDEN __GLXDRIdrawable * +GetGLXDRIDrawable(Display *dpy, GLXDrawable drawable, int * const scrn_num) { - __GLXdisplayPrivate * const priv = __glXInitialize(dpy); - __GLXDRIdrawable * const pdraw; + __GLXdisplayPrivate *priv = __glXInitialize(dpy); + __GLXDRIdrawable *pdraw; const unsigned screen_count = ScreenCount(dpy); unsigned i; - __GLXscreenConfigs *sc; + __GLXscreenConfigs *psc; - if (priv == NULL || priv->driDisplay == NULL) + if (priv == NULL) return NULL; for (i = 0; i < screen_count; i++) { - sc = &priv->screenConfigs[i]; - if (__glxHashLookup(sc->drawHash, drawable, (void *) &pdraw) == 0) { + psc = &priv->screenConfigs[i]; + if (psc->drawHash == NULL) + continue; + + if (__glxHashLookup(psc->drawHash, drawable, (void *) &pdraw) == 0) { if (scrn_num != NULL) *scrn_num = i; - return &pdraw->driDrawable; + return pdraw; } } @@ -837,10 +843,10 @@ PUBLIC void glXSwapBuffers(Display *dpy, GLXDrawable drawable) GLXContextTag tag; CARD8 opcode; #ifdef GLX_DIRECT_RENDERING - __DRIdrawable *pdraw = GetDRIDrawable( dpy, drawable, NULL ); + __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, NULL); - if ( pdraw != NULL ) { - (*pdraw->swapBuffers)(pdraw); + if (pdraw != NULL) { + (*pdraw->psc->core->swapBuffers)(pdraw->driDrawable); return; } #endif @@ -1721,11 +1727,11 @@ static int __glXSwapIntervalSGI(int interval) if (gc->driContext) { __GLXscreenConfigs * const psc = GetGLXScreenConfigs( gc->currentDpy, gc->screen ); - __DRIdrawable * const pdraw = GetDRIDrawable( gc->currentDpy, - gc->currentDrawable, - NULL ); + __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(gc->currentDpy, + gc->currentDrawable, + NULL); if (psc->swapControl != NULL && pdraw != NULL) { - psc->swapControl->setSwapInterval(pdraw, interval); + psc->swapControl->setSwapInterval(pdraw->driDrawable, interval); return 0; } else { @@ -1775,10 +1781,10 @@ static int __glXSwapIntervalMESA(unsigned int interval) gc->screen ); if ( (psc != NULL) && (psc->driScreen != NULL) ) { - __DRIdrawable * const pdraw = - GetDRIDrawable(gc->currentDpy, gc->currentDrawable, NULL); + __GLXDRIdrawable *pdraw = + GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable, NULL); if (psc->swapControl != NULL && pdraw != NULL) { - psc->swapControl->setSwapInterval(pdraw, interval); + psc->swapControl->setSwapInterval(pdraw->driDrawable, interval); return 0; } } @@ -1801,10 +1807,10 @@ static int __glXGetSwapIntervalMESA(void) gc->screen ); if ( (psc != NULL) && (psc->driScreen != NULL) ) { - __DRIdrawable * const pdraw = - GetDRIDrawable(gc->currentDpy, gc->currentDrawable, NULL); + __GLXDRIdrawable *pdraw = + GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable, NULL); if (psc->swapControl != NULL && pdraw != NULL) { - return psc->swapControl->getSwapInterval(pdraw); + return psc->swapControl->getSwapInterval(pdraw->driDrawable); } } } @@ -1823,11 +1829,11 @@ static GLint __glXBeginFrameTrackingMESA(Display *dpy, GLXDrawable drawable) int status = GLX_BAD_CONTEXT; #ifdef __DRI_FRAME_TRACKING int screen; - __DRIdrawable * const pdraw = GetDRIDrawable(dpy, drawable, & screen); + __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, &screen); __GLXscreenConfigs * const psc = GetGLXScreenConfigs(dpy, screen); if (pdraw != NULL && psc->frameTracking != NULL) - status = psc->frameTracking->frameTracking(pdraw, GL_TRUE); + status = psc->frameTracking->frameTracking(pdraw->driDrawable, GL_TRUE); #else (void) dpy; (void) drawable; @@ -1841,11 +1847,12 @@ static GLint __glXEndFrameTrackingMESA(Display *dpy, GLXDrawable drawable) int status = GLX_BAD_CONTEXT; #ifdef __DRI_FRAME_TRACKING int screen; - __DRIdrawable * const pdraw = GetDRIDrawable(dpy, drawable, & screen); - __GLXscreenConfigs * const psc = GetGLXScreenConfigs(dpy, screen); + __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, & screen); + __GLXscreenConfigs *psc = GetGLXScreenConfigs(dpy, screen); if (pdraw != NULL && psc->frameTracking != NULL) - status = psc->frameTracking->frameTracking(pdraw, GL_FALSE); + status = psc->frameTracking->frameTracking(pdraw->driDrawable, + GL_FALSE); #else (void) dpy; (void) drawable; @@ -1860,14 +1867,15 @@ static GLint __glXGetFrameUsageMESA(Display *dpy, GLXDrawable drawable, int status = GLX_BAD_CONTEXT; #ifdef __DRI_FRAME_TRACKING int screen; - __DRIdrawable * const pdraw = GetDRIDrawable(dpy, drawable, & screen); + __GLXDRIdrawable * const pdraw = GetGLXDRIDrawable(dpy, drawable, & screen); __GLXscreenConfigs * const psc = GetGLXScreenConfigs(dpy, screen); if (pdraw != NULL && psc->frameTracking != NULL) { int64_t sbc, missedFrames; float lastMissedUsage; - status = psc->frameTracking->queryFrameTracking(pdraw, &sbc, + status = psc->frameTracking->queryFrameTracking(pdraw->driDrawable, + &sbc, &missedFrames, &lastMissedUsage, usage); @@ -1888,13 +1896,14 @@ static GLint __glXQueryFrameTrackingMESA(Display *dpy, GLXDrawable drawable, int status = GLX_BAD_CONTEXT; #ifdef __DRI_FRAME_TRACKING int screen; - __DRIdrawable * const pdraw = GetDRIDrawable(dpy, drawable, & screen); + __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, & screen); __GLXscreenConfigs * const psc = GetGLXScreenConfigs(dpy, screen); if (pdraw != NULL && psc->frameTracking != NULL) { float usage; - status = psc->frameTracking->queryFrameTracking(pdraw, sbc, missedFrames, + status = psc->frameTracking->queryFrameTracking(pdraw->driDrawable, + sbc, missedFrames, lastMissedUsage, &usage); } #else @@ -1925,12 +1934,13 @@ static int __glXGetVideoSyncSGI(unsigned int *count) __GLXscreenConfigs * const psc = GetGLXScreenConfigs( gc->currentDpy, gc->screen ); if ( psc->msc && psc->driScreen ) { - __DRIdrawable * const pdraw = - GetDRIDrawable(gc->currentDpy, gc->currentDrawable, NULL); + __GLXDRIdrawable *pdraw = + GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable, NULL); int64_t temp; int ret; - ret = (*psc->msc->getDrawableMSC)(&psc->__driScreen, pdraw, &temp); + ret = (*psc->msc->getDrawableMSC)(psc->__driScreen, + pdraw->driDrawable, &temp); *count = (unsigned) temp; return (ret == 0) ? 0 : GLX_BAD_CONTEXT; @@ -1954,14 +1964,14 @@ static int __glXWaitVideoSyncSGI(int divisor, int remainder, unsigned int *count __GLXscreenConfigs * const psc = GetGLXScreenConfigs( gc->currentDpy, gc->screen ); if (psc->msc != NULL && psc->driScreen ) { - __DRIdrawable * const pdraw = - GetDRIDrawable(gc->currentDpy, gc->currentDrawable, NULL); + __GLXDRIdrawable *pdraw = + GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable, NULL); int ret; int64_t msc; int64_t sbc; - ret = (*psc->msc->waitForMSC)(pdraw, 0, divisor, remainder, &msc, - &sbc); + ret = (*psc->msc->waitForMSC)(pdraw->driDrawable, 0, + divisor, remainder, &msc, &sbc); *count = (unsigned) msc; return (ret == 0) ? 0 : GLX_BAD_CONTEXT; } @@ -2120,13 +2130,13 @@ static Bool __glXGetSyncValuesOML(Display *dpy, GLXDrawable drawable, if ( priv != NULL ) { int i; - __DRIdrawable * const pdraw = GetDRIDrawable( dpy, drawable, & i ); + __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, &i); __GLXscreenConfigs * const psc = &priv->screenConfigs[i]; assert( (pdraw == NULL) || (i != -1) ); return ( (pdraw && psc->sbc && psc->msc) - && ((*psc->msc->getMSC)(&psc->driScreen, msc) == 0) - && ((*psc->sbc->getSBC)(pdraw, sbc) == 0) + && ((*psc->msc->getMSC)(psc->driScreen, msc) == 0) + && ((*psc->sbc->getSBC)(pdraw->driDrawable, sbc) == 0) && (__glXGetUST(ust) == 0) ); } #else @@ -2141,16 +2151,16 @@ static Bool __glXGetSyncValuesOML(Display *dpy, GLXDrawable drawable, #ifdef GLX_DIRECT_RENDERING _X_HIDDEN GLboolean -__driGetMscRateOML(__DRIdrawable *draw, int32_t *numerator, int32_t *denominator) +__driGetMscRateOML(__DRIdrawable *draw, + int32_t *numerator, int32_t *denominator, void *private) { #ifdef XF86VIDMODE __GLXscreenConfigs *psc; XF86VidModeModeLine mode_line; int dot_clock; int i; - __GLXDRIdrawable *glxDraw; + __GLXDRIdrawable *glxDraw = private; - glxDraw = containerOf(draw, __GLXDRIdrawable, driDrawable); psc = glxDraw->psc; if (XF86VidModeQueryVersion(psc->dpy, &i, &i) && XF86VidModeGetModeLine(psc->dpy, psc->scr, &dot_clock, &mode_line) ) { @@ -2223,12 +2233,12 @@ _X_HIDDEN GLboolean __glXGetMscRateOML(Display * dpy, GLXDrawable drawable, int32_t * denominator) { #if defined( GLX_DIRECT_RENDERING ) && defined( XF86VIDMODE ) - __DRIdrawable *driDraw = GetDRIDrawable(dpy, drawable, NULL); + __GLXDRIdrawable *draw = GetGLXDRIDrawable(dpy, drawable, NULL); - if (driDraw == NULL) + if (draw == NULL) return False; - return __driGetMscRateOML(driDraw, numerator, denominator); + return __driGetMscRateOML(draw->driDrawable, numerator, denominator, draw); #else (void) dpy; (void) drawable; @@ -2245,7 +2255,7 @@ static int64_t __glXSwapBuffersMscOML(Display *dpy, GLXDrawable drawable, { #ifdef __DRI_SWAP_BUFFER_COUNTER int screen; - __DRIdrawable *pdraw = GetDRIDrawable( dpy, drawable, & screen ); + __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, &screen); __GLXscreenConfigs * const psc = GetGLXScreenConfigs( dpy, screen ); /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE @@ -2259,7 +2269,7 @@ static int64_t __glXSwapBuffersMscOML(Display *dpy, GLXDrawable drawable, return -1; if (pdraw != NULL && psc->counters != NULL) - return (*psc->sbc->swapBuffersMSC)(pdraw, target_msc, + return (*psc->sbc->swapBuffersMSC)(pdraw->driDrawable, target_msc, divisor, remainder); #else @@ -2280,7 +2290,7 @@ static Bool __glXWaitForMscOML(Display * dpy, GLXDrawable drawable, { #ifdef __DRI_MEDIA_STREAM_COUNTER int screen; - __DRIdrawable *pdraw = GetDRIDrawable( dpy, drawable, & screen ); + __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, &screen); __GLXscreenConfigs * const psc = GetGLXScreenConfigs( dpy, screen ); int ret; @@ -2293,7 +2303,7 @@ static Bool __glXWaitForMscOML(Display * dpy, GLXDrawable drawable, return False; if (pdraw != NULL && psc->msc != NULL) { - ret = (*psc->msc->waitForMSC)(pdraw, target_msc, + ret = (*psc->msc->waitForMSC)(pdraw->driDrawable, target_msc, divisor, remainder, msc, sbc); /* __glXGetUST returns zero on success and non-zero on failure. @@ -2321,7 +2331,7 @@ static Bool __glXWaitForSbcOML(Display * dpy, GLXDrawable drawable, { #ifdef __DRI_SWAP_BUFFER_COUNTER int screen; - __DRIdrawable *pdraw = GetDRIDrawable( dpy, drawable, & screen ); + __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, &screen); __GLXscreenConfigs * const psc = GetGLXScreenConfigs( dpy, screen ); int ret; @@ -2332,7 +2342,7 @@ static Bool __glXWaitForSbcOML(Display * dpy, GLXDrawable drawable, return False; if (pdraw != NULL && psc->sbc != NULL) { - ret = (*psc->sbc->waitForSBC)(pdraw, target_sbc, msc, sbc); + ret = (*psc->sbc->waitForSBC)(pdraw->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. @@ -2364,9 +2374,8 @@ PUBLIC void *glXAllocateMemoryMESA(Display *dpy, int scrn, __GLXscreenConfigs * const psc = GetGLXScreenConfigs( dpy, scrn ); if (psc && psc->allocate) - return (*psc->allocate->allocateMemory)( &psc->__driScreen, size, - readFreq, writeFreq, - priority ); + return (*psc->allocate->allocateMemory)(psc->__driScreen, size, + readFreq, writeFreq, priority); #else (void) dpy; @@ -2387,7 +2396,7 @@ PUBLIC void glXFreeMemoryMESA(Display *dpy, int scrn, void *pointer) __GLXscreenConfigs * const psc = GetGLXScreenConfigs( dpy, scrn ); if (psc && psc->allocate) - (*psc->allocate->freeMemory)( &psc->__driScreen, pointer ); + (*psc->allocate->freeMemory)(psc->__driScreen, pointer); #else (void) dpy; @@ -2404,7 +2413,7 @@ PUBLIC GLuint glXGetMemoryOffsetMESA( Display *dpy, int scrn, __GLXscreenConfigs * const psc = GetGLXScreenConfigs( dpy, scrn ); if (psc && psc->allocate) - return (*psc->allocate->memoryOffset)( &psc->__driScreen, pointer ); + return (*psc->allocate->memoryOffset)(psc->__driScreen, pointer); #else (void) dpy; @@ -2480,11 +2489,12 @@ static void __glXCopySubBufferMESA(Display *dpy, GLXDrawable drawable, #ifdef __DRI_COPY_SUB_BUFFER int screen; - __DRIdrawable *pdraw = GetDRIDrawable( dpy, drawable, & screen ); + __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, &screen); if ( pdraw != NULL ) { __GLXscreenConfigs * const psc = GetGLXScreenConfigs( dpy, screen ); if (psc->copySubBuffer != NULL) { - (*psc->copySubBuffer->copySubBuffer)(pdraw, x, y, width, height); + (*psc->copySubBuffer->copySubBuffer)(pdraw->driDrawable, + x, y, width, height); } return; @@ -2560,8 +2570,16 @@ static void __glXBindTexImageEXT(Display *dpy, } #ifdef GLX_DIRECT_RENDERING - if (gc->driContext) + if (gc->driContext) { + __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, NULL); + + if (pdraw != NULL) + (*pdraw->psc->texBuffer->setTexBuffer)(gc->__driContext, + pdraw->textureTarget, + pdraw->driDrawable); + return; + } #endif opcode = __glXSetupForCommand(dpy); diff --git a/src/glx/x11/glxext.c b/src/glx/x11/glxext.c index 525faab10e9..cd5c3196e36 100644 --- a/src/glx/x11/glxext.c +++ b/src/glx/x11/glxext.c @@ -107,9 +107,6 @@ static int _mesa_sparc_needs_init = 1; #define INIT_MESA_SPARC #endif -static Bool MakeContextCurrent(Display *dpy, GLXDrawable draw, - GLXDrawable read, GLXContext gc); - /* ** We setup some dummy structures here so that the API can be used ** even if no context is current. @@ -348,10 +345,10 @@ static void FreeScreenConfigs(__GLXdisplayPrivate *priv) Xfree((char*) psc->serverGLXexts); #ifdef GLX_DIRECT_RENDERING - if (psc->driScreen) + if (psc->driScreen) { psc->driScreen->destroyScreen(psc); - if (psc->drawHash) __glxHashDestroy(psc->drawHash); + } #endif } XFree((char*) priv->screenConfigs); @@ -381,6 +378,9 @@ static int __glXFreeDisplayPrivate(XExtData *extension) if (priv->driDisplay) (*priv->driDisplay->destroyDisplay)(priv->driDisplay); priv->driDisplay = NULL; + if (priv->dri2Display) + (*priv->dri2Display->destroyDisplay)(priv->dri2Display); + priv->dri2Display = NULL; #endif Xfree((char*) priv); @@ -774,14 +774,16 @@ static Bool AllocAndFetchScreenConfigs(Display *dpy, __GLXdisplayPrivate *priv) psc->scr = i; psc->dpy = dpy; #ifdef GLX_DIRECT_RENDERING - if (priv->driDisplay) { - /* Create drawable hash */ - psc->drawHash = __glxHashCreate(); - if (psc->drawHash == NULL) - continue; + psc->drawHash = __glxHashCreate(); + if (psc->drawHash == NULL) + continue; + if (priv->dri2Display) + psc->driScreen = (*priv->dri2Display->createScreen)(psc, i, priv); + if (psc->driScreen == NULL && priv->driDisplay) psc->driScreen = (*priv->driDisplay->createScreen)(psc, i, priv); - if (psc->driScreen == NULL) - __glxHashDestroy(psc->drawHash); + if (psc->driScreen == NULL) { + __glxHashDestroy(psc->drawHash); + psc->drawHash = NULL; } #endif } @@ -872,7 +874,8 @@ _X_HIDDEN __GLXdisplayPrivate *__glXInitialize(Display* dpy) ** (e.g., those called in AllocAndFetchScreenConfigs). */ if (getenv("LIBGL_ALWAYS_INDIRECT") == NULL) { - dpyPriv->driDisplay = driCreateDisplay(dpy); + dpyPriv->dri2Display = dri2CreateDisplay(dpy); + dpyPriv->driDisplay = driCreateDisplay(dpy); } #endif @@ -1188,21 +1191,35 @@ static Bool SendMakeCurrentRequest(Display *dpy, CARD8 opcode, #ifdef GLX_DIRECT_RENDERING static __GLXDRIdrawable * -FetchDRIDrawable(Display *dpy, GLXDrawable drawable, GLXContext gc) +FetchDRIDrawable(Display *dpy, + GLXDrawable glxDrawable, GLXContext gc, Bool pre13) { __GLXdisplayPrivate * const priv = __glXInitialize(dpy); __GLXDRIdrawable *pdraw; __GLXscreenConfigs *psc; + XID drawable; - if (priv == NULL || priv->driDisplay == NULL) + if (priv == NULL) return NULL; psc = &priv->screenConfigs[gc->screen]; - if (__glxHashLookup(psc->drawHash, drawable, (void *) &pdraw) == 0) + if (psc->drawHash == NULL) + return NULL; + + if (__glxHashLookup(psc->drawHash, glxDrawable, (void *) &pdraw) == 0) return pdraw; - pdraw = psc->driScreen->createDrawable(psc, drawable, gc); - if (__glxHashInsert(psc->drawHash, drawable, pdraw)) { + /* If this is glXMakeCurrent (pre GLX 1.3) we allow creating the + * GLX drawable on the fly. Otherwise we pass None as the X + * drawable */ + if (pre13) + drawable = glxDrawable; + else + drawable = None; + + pdraw = psc->driScreen->createDrawable(psc, drawable, + glxDrawable, gc->mode); + if (__glxHashInsert(psc->drawHash, glxDrawable, pdraw)) { (*pdraw->destroyDrawable)(pdraw); return NULL; } @@ -1218,7 +1235,8 @@ FetchDRIDrawable(Display *dpy, GLXDrawable drawable, GLXContext gc) * \note This is in this file so that it can access dummyContext. */ static Bool MakeContextCurrent(Display *dpy, GLXDrawable draw, - GLXDrawable read, GLXContext gc) + GLXDrawable read, GLXContext gc, + Bool pre13) { xGLXMakeCurrentReply reply; const GLXContext oldGC = __glXGetCurrentContext(); @@ -1245,8 +1263,8 @@ static Bool MakeContextCurrent(Display *dpy, GLXDrawable draw, #ifdef GLX_DIRECT_RENDERING /* Bind the direct rendering context to the drawable */ if (gc && gc->driContext) { - __GLXDRIdrawable *pdraw = FetchDRIDrawable(dpy, draw, gc); - __GLXDRIdrawable *pread = FetchDRIDrawable(dpy, read, gc); + __GLXDRIdrawable *pdraw = FetchDRIDrawable(dpy, draw, gc, pre13); + __GLXDRIdrawable *pread = FetchDRIDrawable(dpy, read, gc, pre13); bindReturnValue = (gc->driContext->bindContext) (gc->driContext, pdraw, pread); @@ -1368,16 +1386,16 @@ static Bool MakeContextCurrent(Display *dpy, GLXDrawable draw, PUBLIC Bool glXMakeCurrent(Display *dpy, GLXDrawable draw, GLXContext gc) { - return MakeContextCurrent( dpy, draw, draw, gc ); + return MakeContextCurrent(dpy, draw, draw, gc, True); } PUBLIC GLX_ALIAS(Bool, glXMakeCurrentReadSGI, (Display *dpy, GLXDrawable d, GLXDrawable r, GLXContext ctx), - (dpy, d, r, ctx), MakeContextCurrent) + (dpy, d, r, ctx, False), MakeContextCurrent) PUBLIC GLX_ALIAS(Bool, glXMakeContextCurrent, (Display *dpy, GLXDrawable d, GLXDrawable r, GLXContext ctx), - (dpy, d, r, ctx), MakeContextCurrent) + (dpy, d, r, ctx, False), MakeContextCurrent) #ifdef DEBUG diff --git a/src/glx/x11/glxextensions.c b/src/glx/x11/glxextensions.c index 6d78c7067d1..e8437184722 100644 --- a/src/glx/x11/glxextensions.c +++ b/src/glx/x11/glxextensions.c @@ -356,72 +356,16 @@ __glXProcessServerString( const struct extension_info * ext, } } -#ifdef GLX_DIRECT_RENDERING - void -__glXScrEnableDRIExtension(__GLXscreenConfigs *psc) +__glXEnableDirectExtension(__GLXscreenConfigs *psc, const char *name) { - const __DRIextension **extensions; - int i; - __glXExtensionsCtr(); __glXExtensionsCtrScreen(psc); - extensions = psc->__driScreen.getExtensions(&psc->__driScreen); - for (i = 0; extensions[i]; i++) { -#ifdef __DRI_COPY_SUB_BUFFER - if (strcmp(extensions[i]->name, __DRI_COPY_SUB_BUFFER) == 0) { - psc->copySubBuffer = (__DRIcopySubBufferExtension *) extensions[i]; - SET_BIT(psc->direct_support, MESA_copy_sub_buffer_bit); - } -#endif - -#ifdef __DRI_SWAP_CONTROL - if (strcmp(extensions[i]->name, __DRI_SWAP_CONTROL) == 0) { - psc->swapControl = (__DRIswapControlExtension *) extensions[i]; - SET_BIT(psc->direct_support, SGI_swap_control_bit); - SET_BIT(psc->direct_support, MESA_swap_control_bit); - } -#endif - -#ifdef __DRI_ALLOCATE - if (strcmp(extensions[i]->name, __DRI_ALLOCATE) == 0) { - psc->allocate = (__DRIallocateExtension *) extensions[i]; - SET_BIT(psc->direct_support, MESA_allocate_memory_bit); - } -#endif - -#ifdef __DRI_FRAME_TRACKING - if (strcmp(extensions[i]->name, __DRI_FRAME_TRACKING) == 0) { - psc->frameTracking = (__DRIframeTrackingExtension *) extensions[i]; - SET_BIT(psc->direct_support, MESA_swap_frame_usage_bit); - } -#endif - -#ifdef __DRI_MEDIA_STREAM_COUNTER - if (strcmp(extensions[i]->name, __DRI_MEDIA_STREAM_COUNTER) == 0) { - psc->msc = (__DRImediaStreamCounterExtension *) extensions[i]; - SET_BIT(psc->direct_support, SGI_video_sync_bit); - } -#endif - -#ifdef __DRI_SWAP_BUFFER_COUNTER - /* No driver supports this at this time and the extension is - * not defined in dri_interface.h. Will enable - * GLX_OML_sync_control if implemented. */ -#endif - -#ifdef __DRI_READ_DRAWABLE - if (strcmp(extensions[i]->name, __DRI_READ_DRAWABLE) == 0) { - SET_BIT(psc->direct_support, SGI_make_current_read_bit); - } -#endif - /* Ignore unknown extensions */ - } + set_glx_extension(known_glx_extensions, + name, strlen(name), GL_TRUE, psc->direct_support); } -#endif - /** * Initialize global extension support tables. */ diff --git a/src/glx/x11/glxextensions.h b/src/glx/x11/glxextensions.h index 144b02ad033..9cdd05ed761 100644 --- a/src/glx/x11/glxextensions.h +++ b/src/glx/x11/glxextensions.h @@ -235,10 +235,6 @@ extern const char * __glXGetClientExtensions( void ); extern void __glXCalculateUsableExtensions( struct __GLXscreenConfigsRec *psc, GLboolean display_is_direct_capable, int server_minor_version ); -#ifdef GLX_DIRECT_RENDERING -extern void __glXScrEnableDRIExtension( struct __GLXscreenConfigsRec *psc ); -#endif - extern void __glXCalculateUsableGLExtensions( struct __GLXcontextRec * gc, const char * server_string, int major_version, int minor_version ); extern void __glXGetGLVersion( int * major_version, int * minor_version ); @@ -247,6 +243,8 @@ extern char * __glXGetClientGLExtensionString( void ); extern GLboolean __glExtensionBitIsEnabled( const struct __GLXcontextRec * gc, unsigned bit ); +extern void +__glXEnableDirectExtension(__GLXscreenConfigs *psc, const char *name); /* Source-level backwards compatibility with old drivers. They won't * find the respective functions, though. diff --git a/src/mesa/drivers/dri/common/dri_util.c b/src/mesa/drivers/dri/common/dri_util.c index 1f5d65265cf..daf1d56feb9 100644 --- a/src/mesa/drivers/dri/common/dri_util.c +++ b/src/mesa/drivers/dri/common/dri_util.c @@ -21,7 +21,6 @@ #include <unistd.h> #include <sys/mman.h> #include <stdio.h> -#include <dlfcn.h> #ifndef MAP_FAILED #define MAP_FAILED ((void *)-1) @@ -45,16 +44,6 @@ const __DRIextension driReadDrawableExtension = { __DRI_READ_DRAWABLE, __DRI_READ_DRAWABLE_VERSION }; -static void *driCreateNewDrawable(__DRIscreen *screen, - const __GLcontextModes *modes, - __DRIdrawable *pdraw, - drm_drawable_t hwDrawable, - unsigned int head, - int renderType, const int *attrs); - -static void driDestroyDrawable(__DRIdrawable *drawable); - - /** * Print message to \c stderr if the \c LIBGL_DEBUG environment variable * is set. @@ -99,25 +88,23 @@ __driUtilMessage(const char *f, ...) * While casting the opaque private pointers associated with the parameters * into their respective real types it also assures they are not \c NULL. */ -static GLboolean driUnbindContext(__DRIcontext *ctx) +static int driUnbindContext(__DRIcontext *pcp) { - __DRIcontextPrivate *pcp; - __DRIscreenPrivate *psp; - __DRIdrawablePrivate *pdp; - __DRIdrawablePrivate *prp; + __DRIscreen *psp; + __DRIdrawable *pdp; + __DRIdrawable *prp; /* ** Assume error checking is done properly in glXMakeCurrent before ** calling driUnbindContext. */ - if (ctx == NULL) + if (pcp == NULL) return GL_FALSE; - pcp = (__DRIcontextPrivate *)ctx->private; - psp = (__DRIscreenPrivate *)pcp->driScreenPriv; - pdp = (__DRIdrawablePrivate *)pcp->driDrawablePriv; - prp = (__DRIdrawablePrivate *)pcp->driReadablePriv; + psp = pcp->driScreenPriv; + pdp = pcp->driDrawablePriv; + prp = pcp->driReadablePriv; /* Let driver unbind drawable from context */ (*psp->DriverAPI.UnbindContext)(pcp); @@ -158,13 +145,10 @@ static GLboolean driUnbindContext(__DRIcontext *ctx) * for \c glXMakeCurrentReadSGI or GLX 1.3's \c glXMakeContextCurrent * function. */ -static GLboolean driBindContext(__DRIcontext * ctx, - __DRIdrawable *pdraw, - __DRIdrawable *pread) +static int driBindContext(__DRIcontext *pcp, + __DRIdrawable *pdp, + __DRIdrawable *prp) { - __DRIdrawablePrivate *pdp; - __DRIdrawablePrivate *prp; - __DRIcontextPrivate * const pcp = ctx->private; __DRIscreenPrivate *psp = pcp->driScreenPriv; /* @@ -172,12 +156,9 @@ static GLboolean driBindContext(__DRIcontext * ctx, ** calling driBindContext. */ - if (ctx == NULL || pdraw == None || pread == None) + if (pcp == NULL || pdp == None || prp == None) return GL_FALSE; - pdp = (__DRIdrawablePrivate *) pdraw->private; - prp = (__DRIdrawablePrivate *) pread->private; - /* Bind the drawable to the context */ pcp->driDrawablePriv = pdp; pcp->driReadablePriv = prp; @@ -261,14 +242,15 @@ __driUtilUpdateDrawableInfo(__DRIdrawablePrivate *pdp) DRM_SPINUNLOCK(&psp->pSAREA->drawable_lock, psp->drawLockID); - if (! (*psp->getDrawableInfo->getDrawableInfo)(pdp->pdraw, + if (! (*psp->getDrawableInfo->getDrawableInfo)(pdp, &pdp->index, &pdp->lastStamp, &pdp->x, &pdp->y, &pdp->w, &pdp->h, &pdp->numClipRects, &pdp->pClipRects, &pdp->backX, &pdp->backY, &pdp->numBackClipRects, - &pdp->pBackClipRects )) { + &pdp->pBackClipRects, + pdp->loaderPrivate)) { /* Error -- eg the window may have been destroyed. Keep going * with no cliprects. */ @@ -301,7 +283,8 @@ __driParseEvents(__DRIcontextPrivate *pcp, __DRIdrawablePrivate *pdp) * server overwrote it and we have to reset our tail * pointer. */ DRM_UNLOCK(psp->fd, psp->lock, pcp->hHWContext); - (*psp->dri2.core->reemitDrawableInfo)(pdp->pdraw, &pdp->dri2.tail); + (*psp->dri2.loader->reemitDrawableInfo)(pdp, &pdp->dri2.tail, + pdp->loaderPrivate); DRM_LIGHT_LOCK(psp->fd, psp->lock, pcp->hHWContext); } @@ -326,13 +309,13 @@ __driParseEvents(__DRIcontextPrivate *pcp, __DRIdrawablePrivate *pdp) switch (DRI2_EVENT_TYPE(*p)) { case DRI2_EVENT_DRAWABLE_CONFIG: dc = (__DRIDrawableConfigEvent *) p; - if (dc->drawable == pdp->hHWDrawable) + if (dc->drawable == pdp->dri2.drawable_id) last_dc = dc; break; case DRI2_EVENT_BUFFER_ATTACH: ba = (__DRIBufferAttachEvent *) p; - if (ba->drawable == pdp->hHWDrawable && + if (ba->drawable == pdp->dri2.drawable_id && ba->buffer.attachment == DRI_DRAWABLE_BUFFER_FRONT_LEFT) last_ba = ba; break; @@ -361,11 +344,12 @@ __driParseEvents(__DRIcontextPrivate *pcp, __DRIdrawablePrivate *pdp) rect_size = last_dc->num_rects * sizeof last_dc->rects[0]; pdp->pClipRects = _mesa_malloc(rect_size); memcpy(pdp->pClipRects, last_dc->rects, rect_size); - - if (changed) - (*psp->DriverAPI.HandleDrawableConfig)(pdp, pcp, last_dc); } + /* We only care about the most recent drawable config. */ + if (last_dc && changed) + (*psp->DriverAPI.HandleDrawableConfig)(pdp, pcp, last_dc); + /* Front buffer attachments are special, they typically mean that * we're rendering to a redirected window (or a child window of a * redirected window) and that it got resized. Resizing the root @@ -382,11 +366,6 @@ __driParseEvents(__DRIcontextPrivate *pcp, __DRIdrawablePrivate *pdp) if (last_ba) (*psp->DriverAPI.HandleBufferAttach)(pdp, pcp, last_ba); - /* Like for buffer attachments, we only care about the most recent - * drawable config. */ - if (last_dc) - (*psp->DriverAPI.HandleDrawableConfig)(pdp, pcp, last_dc); - /* If there was a drawable config event in the buffer and it * changed the size of the window, all buffer auxillary buffer * attachments prior to that are invalid (as opposed to the front @@ -406,21 +385,18 @@ __driParseEvents(__DRIcontextPrivate *pcp, __DRIdrawablePrivate *pdp) if (DRI2_EVENT_TYPE(ba->event_header) != DRI2_EVENT_BUFFER_ATTACH) continue; - if (ba->drawable != pdp->hHWDrawable) + if (ba->drawable != pdp->dri2.drawable_id) continue; if (last_ba == ba) continue; (*psp->DriverAPI.HandleBufferAttach)(pdp, pcp, ba); + changed = 1; } pdp->dri2.tail = tail; - /* FIXME: Return whether we changed anything. This check always - * returns true if we received events, but we could refine the - * check to only return TRUE if the drawable actually changed. */ - - return total > 0; + return changed || last_ba; } /*@}*/ @@ -430,6 +406,30 @@ __driParseEvents(__DRIcontextPrivate *pcp, __DRIdrawablePrivate *pdp) /*****************************************************************/ /*@{*/ +static void driReportDamage(__DRIdrawable *pdp, + struct drm_clip_rect *pClipRects, int numClipRects) +{ + __DRIscreen *psp = pdp->driScreenPriv; + + /* Check that we actually have the new damage report method */ + if (psp->dri2.enabled) { + (*psp->dri2.loader->postDamage)(pdp, + pClipRects, + numClipRects, + pdp->loaderPrivate); + } else if (psp->damage) { + /* Report the damage. Currently, all our drivers draw + * directly to the front buffer, so we report the damage there + * rather than to the backing storein (if any). + */ + (*psp->damage->reportDamage)(pdp, + pdp->x, pdp->y, + pClipRects, numClipRects, + GL_TRUE, pdp->loaderPrivate); + } +} + + /** * Swap buffers. * @@ -440,49 +440,28 @@ __driParseEvents(__DRIcontextPrivate *pcp, __DRIdrawablePrivate *pdp) * * Is called directly from glXSwapBuffers(). */ -static void driSwapBuffers(__DRIdrawable *drawable) +static void driSwapBuffers(__DRIdrawable *dPriv) { - __DRIdrawablePrivate *dPriv = drawable->private; - __DRIscreenPrivate *psp = dPriv->driScreenPriv; - drm_clip_rect_t rect; + __DRIscreen *psp = dPriv->driScreenPriv; if (!dPriv->numClipRects) return; - dPriv->swapBuffers(dPriv); + psp->DriverAPI.SwapBuffers(dPriv); - /* Check that we actually have the new damage report method */ - if (psp->damage == NULL) - return; - - /* Assume it's affecting the whole drawable for now */ - rect.x1 = 0; - rect.y1 = 0; - rect.x2 = rect.x1 + dPriv->w; - rect.y2 = rect.y1 + dPriv->h; - - /* Report the damage. Currently, all our drivers draw directly to the - * front buffer, so we report the damage there rather than to the backing - * store (if any). - */ - (*psp->damage->reportDamage)(dPriv->pdraw, - dPriv->x, dPriv->y, &rect, 1, GL_TRUE); + driReportDamage(dPriv, dPriv->pClipRects, dPriv->numClipRects); } -static int driDrawableGetMSC( __DRIscreen *screen, __DRIdrawable *drawable, +static int driDrawableGetMSC( __DRIscreen *sPriv, __DRIdrawable *dPriv, int64_t *msc ) { - __DRIscreenPrivate *sPriv = screen->private; - __DRIdrawablePrivate *dPriv = drawable->private; - return sPriv->DriverAPI.GetDrawableMSC(sPriv, dPriv, msc); } -static int driWaitForMSC(__DRIdrawable *drawable, int64_t target_msc, +static int driWaitForMSC(__DRIdrawable *dPriv, int64_t target_msc, int64_t divisor, int64_t remainder, int64_t * msc, int64_t * sbc) { - __DRIdrawablePrivate *dPriv = drawable->private; __DRIswapInfo sInfo; int status; @@ -510,11 +489,18 @@ const __DRImediaStreamCounterExtension driMediaStreamCounterExtension = { driDrawableGetMSC, }; -static void driCopySubBuffer(__DRIdrawable *drawable, +static void driCopySubBuffer(__DRIdrawable *dPriv, int x, int y, int w, int h) { - __DRIdrawablePrivate *dPriv = drawable->private; + drm_clip_rect_t rect; + dPriv->driScreenPriv->DriverAPI.CopySubBuffer(dPriv, x, y, w, h); + + rect.x1 = x; + rect.y1 = y; + rect.x2 = x + w; + rect.y2 = y + w; + driReportDamage(dPriv, &rect, 1); } const __DRIcopySubBufferExtension driCopySubBufferExtension = { @@ -522,18 +508,14 @@ const __DRIcopySubBufferExtension driCopySubBufferExtension = { driCopySubBuffer }; -static void driSetSwapInterval(__DRIdrawable *drawable, unsigned int interval) +static void driSetSwapInterval(__DRIdrawable *dPriv, unsigned int interval) { - __DRIdrawablePrivate *dpriv = drawable->private; - - dpriv->swap_interval = interval; + dPriv->swap_interval = interval; } -static unsigned int driGetSwapInterval(__DRIdrawable *drawable) +static unsigned int driGetSwapInterval(__DRIdrawable *dPriv) { - __DRIdrawablePrivate *dpriv = drawable->private; - - return dpriv->swap_interval; + return dPriv->swap_interval; } const __DRIswapControlExtension driSwapControlExtension = { @@ -546,31 +528,25 @@ const __DRIswapControlExtension driSwapControlExtension = { /** * This is called via __DRIscreenRec's createNewDrawable pointer. */ -static void *driCreateNewDrawable(__DRIscreen *screen, - const __GLcontextModes *modes, - __DRIdrawable *pdraw, - drm_drawable_t hwDrawable, - unsigned int head, - int renderType, - const int *attrs) +static __DRIdrawable * +driCreateNewDrawable(__DRIscreen *psp, const __DRIconfig *config, + drm_drawable_t hwDrawable, int renderType, + const int *attrs, void *data) { - __DRIscreenPrivate *psp; - __DRIdrawablePrivate *pdp; - - pdraw->private = NULL; + __DRIdrawable *pdp; /* Since pbuffers are not yet supported, no drawable attributes are * supported either. */ (void) attrs; - pdp = (__DRIdrawablePrivate *)_mesa_malloc(sizeof(__DRIdrawablePrivate)); + pdp = _mesa_malloc(sizeof *pdp); if (!pdp) { return NULL; } + pdp->loaderPrivate = data; pdp->hHWDrawable = hwDrawable; - pdp->pdraw = pdraw; pdp->refcount = 0; pdp->pStamp = NULL; pdp->lastStamp = 0; @@ -586,19 +562,15 @@ static void *driCreateNewDrawable(__DRIscreen *screen, pdp->vblSeq = 0; pdp->vblFlags = 0; - psp = (__DRIscreenPrivate *)screen->private; pdp->driScreenPriv = psp; pdp->driContextPriv = &psp->dummyContextPriv; - if (!(*psp->DriverAPI.CreateBuffer)(psp, pdp, modes, + if (!(*psp->DriverAPI.CreateBuffer)(psp, pdp, &config->modes, renderType == GLX_PIXMAP_BIT)) { _mesa_free(pdp); return NULL; } - pdraw->private = pdp; - pdraw->destroyDrawable = driDestroyDrawable; - pdraw->swapBuffers = driSwapBuffers; /* called by glXSwapBuffers() */ pdp->msc_base = 0; /* This special default value is replaced with the configured @@ -607,20 +579,28 @@ static void *driCreateNewDrawable(__DRIscreen *screen, */ pdp->swap_interval = (unsigned)-1; - pdp->swapBuffers = psp->DriverAPI.SwapBuffers; + return pdp; +} - if (psp->dri2.enabled) { - pdp->dri2.tail = head; - pdp->pBackClipRects = _mesa_malloc(sizeof *pdp->pBackClipRects); - } +static __DRIdrawable * +dri2CreateNewDrawable(__DRIscreen *screen, const __DRIconfig *config, + unsigned int drawable_id, unsigned int head, void *data) +{ + __DRIdrawable *pdraw; - return (void *) pdp; + pdraw = driCreateNewDrawable(screen, config, 0, 0, NULL, data); + + pdraw->dri2.drawable_id = drawable_id; + pdraw->dri2.tail = head; + pdraw->pBackClipRects = _mesa_malloc(sizeof *pdraw->pBackClipRects); + + return pdraw; } + static void -driDestroyDrawable(__DRIdrawable *drawable) +driDestroyDrawable(__DRIdrawable *pdp) { - __DRIdrawablePrivate *pdp = drawable->private; __DRIscreenPrivate *psp; if (pdp) { @@ -656,10 +636,8 @@ driDestroyDrawable(__DRIdrawable *drawable) * drmDestroyContext(), and finally frees \p contextPrivate. */ static void -driDestroyContext(__DRIcontext *context) +driDestroyContext(__DRIcontext *pcp) { - __DRIcontextPrivate *pcp = context->private; - if (pcp) { (*pcp->driScreenPriv->DriverAPI.DestroyContext)(pcp); _mesa_free(pcp); @@ -688,24 +666,18 @@ driDestroyContext(__DRIcontext *context) * context. * */ -static void * -driCreateNewContext(__DRIscreen *screen, const __GLcontextModes *modes, +static __DRIcontext * +driCreateNewContext(__DRIscreen *psp, const __DRIconfig *config, int render_type, __DRIcontext *shared, - drm_context_t hwContext, __DRIcontext *pctx) + drm_context_t hwContext, void *data) { - __DRIcontextPrivate *pcp; - __DRIcontextPrivate *pshare = (shared != NULL) ? shared->private : NULL; - __DRIscreenPrivate *psp; - void * const shareCtx = (pshare != NULL) ? pshare->driverPrivate : NULL; - - psp = (__DRIscreenPrivate *)screen->private; + __DRIcontext *pcp; + void * const shareCtx = (shared != NULL) ? shared->driverPrivate : NULL; - pcp = (__DRIcontextPrivate *)_mesa_malloc(sizeof(__DRIcontextPrivate)); - if (!pcp) { + pcp = _mesa_malloc(sizeof *pcp); + if (!pcp) return NULL; - } - pcp->hHWContext = hwContext; pcp->driScreenPriv = psp; pcp->driDrawablePriv = NULL; @@ -721,28 +693,43 @@ driCreateNewContext(__DRIscreen *screen, const __GLcontextModes *modes, /* No other fields should be used! */ } - pctx->destroyContext = driDestroyContext; - pctx->bindContext = driBindContext; - pctx->unbindContext = driUnbindContext; + pcp->hHWContext = hwContext; - if ( !(*psp->DriverAPI.CreateContext)(modes, pcp, shareCtx) ) { + if ( !(*psp->DriverAPI.CreateContext)(&config->modes, pcp, shareCtx) ) { _mesa_free(pcp); return NULL; } return pcp; } -/*@}*/ - -static const __DRIextension ** -driGetExtensions(__DRIscreen *screen) +static __DRIcontext * +dri2CreateNewContext(__DRIscreen *screen, const __DRIconfig *config, + __DRIcontext *shared, void *data) { - __DRIscreenPrivate *psp = screen->private; + drm_context_t hwContext; + DRM_CAS_RESULT(ret); - return psp->extensions; + /* DRI2 doesn't use kernel with context IDs, we just need an ID that's + * different from the kernel context ID to make drmLock() happy. */ + + do { + hwContext = screen->dri2.lock->next_id; + DRM_CAS(&screen->dri2.lock->next_id, hwContext, hwContext + 1, ret); + } while (ret); + + return driCreateNewContext(screen, config, 0, shared, hwContext, data); } +static int +driCopyContext(__DRIcontext *dest, __DRIcontext *src, unsigned long mask) +{ + return GL_FALSE; +} + +/*@}*/ + + /*****************************************************************/ /** \name Screen handling functions */ /*****************************************************************/ @@ -759,10 +746,8 @@ driGetExtensions(__DRIscreen *screen) * This function calls __DriverAPIRec::DestroyScreen on \p screenPrivate, calls * drmClose(), and finally frees \p screenPrivate. */ -static void driDestroyScreen(__DRIscreen *screen) +static void driDestroyScreen(__DRIscreen *psp) { - __DRIscreenPrivate *psp = screen->private; - if (psp) { /* No interaction with the X-server is possible at this point. This * routine is called after XCloseDisplay, so there is no protocol @@ -786,22 +771,20 @@ static void driDestroyScreen(__DRIscreen *screen) } static void -setupLoaderExtensions(__DRIscreenPrivate *psp, +setupLoaderExtensions(__DRIscreen *psp, const __DRIextension **extensions) { int i; for (i = 0; extensions[i]; i++) { - if (strcmp(extensions[i]->name, __DRI_CONTEXT_MODES) == 0) - psp->contextModes = (__DRIcontextModesExtension *) extensions[i]; if (strcmp(extensions[i]->name, __DRI_GET_DRAWABLE_INFO) == 0) psp->getDrawableInfo = (__DRIgetDrawableInfoExtension *) extensions[i]; if (strcmp(extensions[i]->name, __DRI_DAMAGE) == 0) psp->damage = (__DRIdamageExtension *) extensions[i]; if (strcmp(extensions[i]->name, __DRI_SYSTEM_TIME) == 0) psp->systemTime = (__DRIsystemTimeExtension *) extensions[i]; - if (strcmp(extensions[i]->name, __DRI_CORE_DRI2) == 0) - psp->dri2.core = (__DRIcoreDRI2Extension *) extensions[i]; + if (strcmp(extensions[i]->name, __DRI_LOADER) == 0) + psp->dri2.loader = (__DRIloaderExtension *) extensions[i]; } } @@ -836,26 +819,24 @@ setupLoaderExtensions(__DRIscreenPrivate *psp, * function. Since the name of this function is versioned, it is * impossible for a loader that is too old to even load this driver. */ -PUBLIC -void * __DRI_CREATE_NEW_SCREEN( int scrn, __DRIscreen *psc, - const __DRIversion * ddx_version, - const __DRIversion * dri_version, - const __DRIversion * drm_version, - const __DRIframebuffer * frame_buffer, - drmAddress pSAREA, int fd, - const __DRIextension ** extensions, - __GLcontextModes ** driver_modes ) - +static __DRIscreen * +driCreateNewScreen(int scrn, + const __DRIversion *ddx_version, + const __DRIversion *dri_version, + const __DRIversion *drm_version, + const __DRIframebuffer *frame_buffer, + drmAddress pSAREA, int fd, + const __DRIextension **extensions, + const __DRIconfig ***driver_modes, + void *loaderPrivate) { - __DRIscreenPrivate *psp; static const __DRIextension *emptyExtensionList[] = { NULL }; + __DRIscreen *psp; - psp = _mesa_malloc(sizeof(*psp)); + psp = _mesa_malloc(sizeof *psp); if (!psp) return NULL; - psp->psc = psc; - setupLoaderExtensions(psp, extensions); /* @@ -893,12 +874,9 @@ void * __DRI_CREATE_NEW_SCREEN( int scrn, __DRIscreen *psc, */ psp->dummyContextPriv.driScreenPriv = NULL; - psc->destroyScreen = driDestroyScreen; - psc->getExtensions = driGetExtensions; - psc->createNewDrawable = driCreateNewDrawable; - psc->createNewContext = driCreateNewContext; + psp->DriverAPI = driDriverAPI; - *driver_modes = __driDriverInitScreen(psp); + *driver_modes = driDriverAPI.InitScreen(psp); if (*driver_modes == NULL) { _mesa_free(psp); return NULL; @@ -907,20 +885,18 @@ void * __DRI_CREATE_NEW_SCREEN( int scrn, __DRIscreen *psc, return psp; } -PUBLIC void * -__DRI2_CREATE_NEW_SCREEN(int scrn, __DRIscreen *psc, - int fd, unsigned int sarea_handle, - const __DRIextension **extensions, - __GLcontextModes **driver_modes) + +static __DRIscreen * +dri2CreateNewScreen(int scrn, int fd, unsigned int sarea_handle, + const __DRIextension **extensions, + const __DRIconfig ***driver_configs, void *data) { - __DRIscreenPrivate *psp; static const __DRIextension *emptyExtensionList[] = { NULL }; + __DRIscreen *psp; unsigned int *p; drmVersionPtr version; - __GLcontextModes *(*initScreen)(__DRIscreenPrivate *psc); - initScreen = dlsym(NULL, "__dri2DriverInitScreen"); - if (initScreen == NULL) + if (driDriverAPI.InitScreen2 == NULL) return NULL; psp = _mesa_malloc(sizeof(*psp)); @@ -929,8 +905,6 @@ __DRI2_CREATE_NEW_SCREEN(int scrn, __DRIscreen *psc, setupLoaderExtensions(psp, extensions); - psp->psc = psc; - version = drmGetVersion(fd); if (version) { psp->drm_version.major = version->version_major; @@ -972,22 +946,176 @@ __DRI2_CREATE_NEW_SCREEN(int scrn, __DRIscreen *psc, psp->lock = (drmLock *) &psp->dri2.lock->lock; - psc->destroyScreen = driDestroyScreen; - psc->getExtensions = driGetExtensions; - psc->createNewDrawable = driCreateNewDrawable; - psc->createNewContext = driCreateNewContext; - - *driver_modes = initScreen(psp); - if (*driver_modes == NULL) { + psp->DriverAPI = driDriverAPI; + *driver_configs = driDriverAPI.InitScreen2(psp); + if (*driver_configs == NULL) { drmBOUnmap(psp->fd, &psp->dri2.sareaBO); drmBOUnreference(psp->fd, &psp->dri2.sareaBO); _mesa_free(psp); return NULL; } + psp->DriverAPI = driDriverAPI; + return psp; } +static const __DRIextension **driGetExtensions(__DRIscreen *psp) +{ + return psp->extensions; +} + +#define __ATTRIB(attrib, field) \ + { attrib, offsetof(__GLcontextModes, field) } + +static const struct { unsigned int attrib, offset; } attribMap[] = { + __ATTRIB(__DRI_ATTRIB_BUFFER_SIZE, rgbBits), + __ATTRIB(__DRI_ATTRIB_LEVEL, level), + __ATTRIB(__DRI_ATTRIB_RED_SIZE, redBits), + __ATTRIB(__DRI_ATTRIB_GREEN_SIZE, greenBits), + __ATTRIB(__DRI_ATTRIB_BLUE_SIZE, blueBits), + __ATTRIB(__DRI_ATTRIB_ALPHA_SIZE, alphaBits), + __ATTRIB(__DRI_ATTRIB_DEPTH_SIZE, depthBits), + __ATTRIB(__DRI_ATTRIB_STENCIL_SIZE, stencilBits), + __ATTRIB(__DRI_ATTRIB_ACCUM_RED_SIZE, accumRedBits), + __ATTRIB(__DRI_ATTRIB_ACCUM_GREEN_SIZE, accumGreenBits), + __ATTRIB(__DRI_ATTRIB_ACCUM_BLUE_SIZE, accumBlueBits), + __ATTRIB(__DRI_ATTRIB_ACCUM_ALPHA_SIZE, accumAlphaBits), + __ATTRIB(__DRI_ATTRIB_SAMPLE_BUFFERS, sampleBuffers), + __ATTRIB(__DRI_ATTRIB_SAMPLES, samples), + __ATTRIB(__DRI_ATTRIB_DOUBLE_BUFFER, doubleBufferMode), + __ATTRIB(__DRI_ATTRIB_STEREO, stereoMode), + __ATTRIB(__DRI_ATTRIB_AUX_BUFFERS, numAuxBuffers), + __ATTRIB(__DRI_ATTRIB_TRANSPARENT_TYPE, transparentPixel), + __ATTRIB(__DRI_ATTRIB_TRANSPARENT_INDEX_VALUE, transparentPixel), + __ATTRIB(__DRI_ATTRIB_TRANSPARENT_RED_VALUE, transparentRed), + __ATTRIB(__DRI_ATTRIB_TRANSPARENT_GREEN_VALUE, transparentGreen), + __ATTRIB(__DRI_ATTRIB_TRANSPARENT_BLUE_VALUE, transparentBlue), + __ATTRIB(__DRI_ATTRIB_TRANSPARENT_ALPHA_VALUE, transparentAlpha), + __ATTRIB(__DRI_ATTRIB_FLOAT_MODE, floatMode), + __ATTRIB(__DRI_ATTRIB_RED_MASK, redMask), + __ATTRIB(__DRI_ATTRIB_GREEN_MASK, greenMask), + __ATTRIB(__DRI_ATTRIB_BLUE_MASK, blueMask), + __ATTRIB(__DRI_ATTRIB_ALPHA_MASK, alphaMask), + __ATTRIB(__DRI_ATTRIB_MAX_PBUFFER_WIDTH, maxPbufferWidth), + __ATTRIB(__DRI_ATTRIB_MAX_PBUFFER_HEIGHT, maxPbufferHeight), + __ATTRIB(__DRI_ATTRIB_MAX_PBUFFER_PIXELS, maxPbufferPixels), + __ATTRIB(__DRI_ATTRIB_OPTIMAL_PBUFFER_WIDTH, optimalPbufferWidth), + __ATTRIB(__DRI_ATTRIB_OPTIMAL_PBUFFER_HEIGHT, optimalPbufferHeight), + __ATTRIB(__DRI_ATTRIB_SWAP_METHOD, swapMethod), + __ATTRIB(__DRI_ATTRIB_BIND_TO_TEXTURE_RGB, bindToTextureRgb), + __ATTRIB(__DRI_ATTRIB_BIND_TO_TEXTURE_RGBA, bindToTextureRgba), + __ATTRIB(__DRI_ATTRIB_BIND_TO_MIPMAP_TEXTURE, bindToMipmapTexture), + __ATTRIB(__DRI_ATTRIB_YINVERTED, yInverted), + + /* The struct field doesn't matter here, these are handled by the + * switch in driGetConfigAttribIndex. We need them in the array + * so the iterator includes them though.*/ + __ATTRIB(__DRI_ATTRIB_RENDER_TYPE, level), + __ATTRIB(__DRI_ATTRIB_CONFIG_CAVEAT, level), + __ATTRIB(__DRI_ATTRIB_BIND_TO_TEXTURE_TARGETS, level), + __ATTRIB(__DRI_ATTRIB_SWAP_METHOD, level) +}; + +#define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0])) + +static int +driGetConfigAttribIndex(const __DRIconfig *config, + unsigned int index, unsigned int *value) +{ + switch (attribMap[index].attrib) { + case __DRI_ATTRIB_RENDER_TYPE: + if (config->modes.rgbMode) + *value = __DRI_ATTRIB_RGBA_BIT; + else + *value = __DRI_ATTRIB_COLOR_INDEX_BIT; + break; + case __DRI_ATTRIB_CONFIG_CAVEAT: + if (config->modes.visualRating == GLX_NON_CONFORMANT_CONFIG) + *value = __DRI_ATTRIB_NON_CONFORMANT_CONFIG; + else if (config->modes.visualRating == GLX_SLOW_CONFIG) + *value = __DRI_ATTRIB_SLOW_BIT; + else + *value = 0; + break; + case __DRI_ATTRIB_BIND_TO_TEXTURE_TARGETS: + *value = 0; + if (config->modes.bindToTextureTargets & GLX_TEXTURE_1D_BIT_EXT) + *value |= __DRI_ATTRIB_TEXTURE_1D_BIT; + if (config->modes.bindToTextureTargets & GLX_TEXTURE_2D_BIT_EXT) + *value |= __DRI_ATTRIB_TEXTURE_2D_BIT; + if (config->modes.bindToTextureTargets & GLX_TEXTURE_RECTANGLE_BIT_EXT) + *value |= __DRI_ATTRIB_TEXTURE_RECTANGLE_BIT; + break; + case __DRI_ATTRIB_SWAP_METHOD: + break; + + default: + *value = *(unsigned int *) + ((char *) &config->modes + attribMap[index].offset); + + break; + } + + return GL_TRUE; +} + +static int +driGetConfigAttrib(const __DRIconfig *config, + unsigned int attrib, unsigned int *value) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(attribMap); i++) + if (attribMap[i].attrib == attrib) + return driGetConfigAttribIndex(config, i, value); + + return GL_FALSE; +} + +static int +driIndexConfigAttrib(const __DRIconfig *config, int index, + unsigned int *attrib, unsigned int *value) +{ + if (index >= 0 && index < ARRAY_SIZE(attribMap)) { + *attrib = attribMap[index].attrib; + return driGetConfigAttribIndex(config, index, value); + } + + return GL_FALSE; +} + +const __DRIlegacyExtension driLegacyExtension = { + { __DRI_LEGACY, __DRI_LEGACY_VERSION }, + driCreateNewScreen, + driCreateNewDrawable, + driCreateNewContext +}; + +const __DRIcoreExtension driCoreExtension = { + { __DRI_CORE, __DRI_CORE_VERSION }, + dri2CreateNewScreen, + driDestroyScreen, + driGetExtensions, + driGetConfigAttrib, + driIndexConfigAttrib, + dri2CreateNewDrawable, + driDestroyDrawable, + driSwapBuffers, + dri2CreateNewContext, + driCopyContext, + driDestroyContext, + driBindContext, + driUnbindContext +}; + +/* This is the table of extensions that the loader will dlsym() for. */ +PUBLIC const __DRIextension *__driDriverExtensions[] = { + &driCoreExtension.base, + &driLegacyExtension.base, + NULL +}; + static int driFrameTracking(__DRIdrawable *drawable, GLboolean enable) { @@ -995,14 +1123,13 @@ driFrameTracking(__DRIdrawable *drawable, GLboolean enable) } static int -driQueryFrameTracking(__DRIdrawable *drawable, +driQueryFrameTracking(__DRIdrawable *dpriv, int64_t * sbc, int64_t * missedFrames, float * lastMissedUsage, float * usage) { __DRIswapInfo sInfo; int status; int64_t ust; - __DRIdrawablePrivate * dpriv = drawable->private; __DRIscreenPrivate *psp = dpriv->driScreenPriv; status = dpriv->driScreenPriv->DriverAPI.GetSwapInfo( dpriv, & sInfo ); @@ -1062,7 +1189,7 @@ driCalculateSwapUsage( __DRIdrawablePrivate *dPriv, int64_t last_swap_ust, float usage = 1.0; __DRIscreenPrivate *psp = dPriv->driScreenPriv; - if ( (*psp->systemTime->getMSCRate)(dPriv->pdraw, &n, &d) ) { + if ( (*psp->systemTime->getMSCRate)(dPriv, &n, &d, dPriv->loaderPrivate) ) { interval = (dPriv->swap_interval != 0) ? dPriv->swap_interval : 1; diff --git a/src/mesa/drivers/dri/common/dri_util.h b/src/mesa/drivers/dri/common/dri_util.h index 59c64e4adfe..d4401b407e7 100644 --- a/src/mesa/drivers/dri/common/dri_util.h +++ b/src/mesa/drivers/dri/common/dri_util.h @@ -59,27 +59,19 @@ #define GLX_BAD_CONTEXT 5 -typedef struct __DRIdisplayPrivateRec __DRIdisplayPrivate; -typedef struct __DRIscreenPrivateRec __DRIscreenPrivate; -typedef struct __DRIcontextPrivateRec __DRIcontextPrivate; -typedef struct __DRIdrawablePrivateRec __DRIdrawablePrivate; typedef struct __DRIswapInfoRec __DRIswapInfo; typedef struct __DRIutilversionRec2 __DRIutilversion2; - -/** - * Driver specific entry point. Implemented by the driver. Called - * from the top level createNewScreen entry point to initialize the - * __DRIscreenPrivate struct. - */ -extern __GLcontextModes *__driDriverInitScreen(__DRIscreenPrivate *psp); - -/** Ditto for DRI2 capable drivers. */ -extern __GLcontextModes *__dri2DriverInitScreen(__DRIscreenPrivate *psp); +/* Typedefs to avoid rewriting the world. */ +typedef struct __DRIscreenRec __DRIscreenPrivate; +typedef struct __DRIdrawableRec __DRIdrawablePrivate; +typedef struct __DRIcontextRec __DRIcontextPrivate; /** * Extensions. */ +extern const __DRIlegacyExtension driLegacyExtension; +extern const __DRIcoreExtension driCoreExtension; extern const __DRIextension driReadDrawableExtension; extern const __DRIcopySubBufferExtension driCopySubBufferExtension; extern const __DRIswapControlExtension driSwapControlExtension; @@ -100,7 +92,7 @@ extern const __DRImediaStreamCounterExtension driMediaStreamCounterExtension; /** * Utility macro to validate the drawable information. * - * See __DRIdrawablePrivate::pStamp and __DRIdrawablePrivate::lastStamp. + * See __DRIdrawable::pStamp and __DRIdrawable::lastStamp. */ #define DRI_VALIDATE_DRAWABLE_INFO(psp, pdp) \ do { \ @@ -129,74 +121,76 @@ do { \ * this structure. */ struct __DriverAPIRec { + const __DRIconfig **(*InitScreen) (__DRIscreen * priv); + /** * Screen destruction callback */ - void (*DestroyScreen)(__DRIscreenPrivate *driScrnPriv); + void (*DestroyScreen)(__DRIscreen *driScrnPriv); /** * Context creation callback */ GLboolean (*CreateContext)(const __GLcontextModes *glVis, - __DRIcontextPrivate *driContextPriv, + __DRIcontext *driContextPriv, void *sharedContextPrivate); /** * Context destruction callback */ - void (*DestroyContext)(__DRIcontextPrivate *driContextPriv); + void (*DestroyContext)(__DRIcontext *driContextPriv); /** * Buffer (drawable) creation callback */ - GLboolean (*CreateBuffer)(__DRIscreenPrivate *driScrnPriv, - __DRIdrawablePrivate *driDrawPriv, + GLboolean (*CreateBuffer)(__DRIscreen *driScrnPriv, + __DRIdrawable *driDrawPriv, const __GLcontextModes *glVis, GLboolean pixmapBuffer); /** * Buffer (drawable) destruction callback */ - void (*DestroyBuffer)(__DRIdrawablePrivate *driDrawPriv); + void (*DestroyBuffer)(__DRIdrawable *driDrawPriv); /** * Buffer swapping callback */ - void (*SwapBuffers)(__DRIdrawablePrivate *driDrawPriv); + void (*SwapBuffers)(__DRIdrawable *driDrawPriv); /** * Context activation callback */ - GLboolean (*MakeCurrent)(__DRIcontextPrivate *driContextPriv, - __DRIdrawablePrivate *driDrawPriv, - __DRIdrawablePrivate *driReadPriv); + GLboolean (*MakeCurrent)(__DRIcontext *driContextPriv, + __DRIdrawable *driDrawPriv, + __DRIdrawable *driReadPriv); /** * Context unbinding callback */ - GLboolean (*UnbindContext)(__DRIcontextPrivate *driContextPriv); + GLboolean (*UnbindContext)(__DRIcontext *driContextPriv); /** * Retrieves statistics about buffer swap operations. Required if * GLX_OML_sync_control or GLX_MESA_swap_frame_usage is supported. */ - int (*GetSwapInfo)( __DRIdrawablePrivate *dPriv, __DRIswapInfo * sInfo ); + int (*GetSwapInfo)( __DRIdrawable *dPriv, __DRIswapInfo * sInfo ); /** * These are required if GLX_OML_sync_control is supported. */ /*@{*/ - int (*WaitForMSC)( __DRIdrawablePrivate *priv, int64_t target_msc, + int (*WaitForMSC)( __DRIdrawable *priv, int64_t target_msc, int64_t divisor, int64_t remainder, int64_t * msc ); - int (*WaitForSBC)( __DRIdrawablePrivate *priv, int64_t target_sbc, + int (*WaitForSBC)( __DRIdrawable *priv, int64_t target_sbc, int64_t * msc, int64_t * sbc ); - int64_t (*SwapBuffersMSC)( __DRIdrawablePrivate *priv, int64_t target_msc, + int64_t (*SwapBuffersMSC)( __DRIdrawable *priv, int64_t target_msc, int64_t divisor, int64_t remainder ); /*@}*/ - void (*CopySubBuffer)(__DRIdrawablePrivate *driDrawPriv, + void (*CopySubBuffer)(__DRIdrawable *driDrawPriv, int x, int y, int w, int h); /** @@ -204,21 +198,26 @@ struct __DriverAPIRec { * level DRM driver (e.g. pipe info). Required if * GLX_SGI_video_sync or GLX_OML_sync_control is supported. */ - int (*GetDrawableMSC) ( __DRIscreenPrivate * priv, - __DRIdrawablePrivate *drawablePrivate, + int (*GetDrawableMSC) ( __DRIscreen * priv, + __DRIdrawable *drawablePrivate, int64_t *count); + + /* DRI2 Entry points */ - void (*HandleDrawableConfig)(__DRIdrawablePrivate *dPriv, - __DRIcontextPrivate *pcp, + const __DRIconfig **(*InitScreen2) (__DRIscreen * priv); + void (*HandleDrawableConfig)(__DRIdrawable *dPriv, + __DRIcontext *pcp, __DRIDrawableConfigEvent *event); - void (*HandleBufferAttach)(__DRIdrawablePrivate *dPriv, - __DRIcontextPrivate *pcp, + void (*HandleBufferAttach)(__DRIdrawable *dPriv, + __DRIcontext *pcp, __DRIBufferAttachEvent *ba); }; +extern const struct __DriverAPIRec driDriverAPI; + struct __DRIswapInfoRec { /** @@ -254,7 +253,7 @@ struct __DRIswapInfoRec { /** * Per-drawable private DRI driver information. */ -struct __DRIdrawablePrivateRec { +struct __DRIdrawableRec { /** * Kernel drawable handle */ @@ -268,9 +267,10 @@ struct __DRIdrawablePrivateRec { void *driverPrivate; /** - * X's drawable ID associated with this private drawable. + * Private data from the loader. We just hold on to it and pass + * it back when calling into loader provided functions. */ - __DRIdrawable *pdraw; + void *loaderPrivate; /** * Reference count for number of context's currently bound to this @@ -295,7 +295,7 @@ struct __DRIdrawablePrivateRec { /** * Last value of the stamp. * - * If this differs from the value stored at __DRIdrawablePrivate::pStamp, + * If this differs from the value stored at __DRIdrawable::pStamp, * then the drawable information has been modified by the X server, and the * drawable information (below) should be retrieved from the X server. */ @@ -357,17 +357,12 @@ struct __DRIdrawablePrivateRec { /** * Pointer to context to which this drawable is currently bound. */ - __DRIcontextPrivate *driContextPriv; + __DRIcontext *driContextPriv; /** * Pointer to screen on which this drawable was created. */ - __DRIscreenPrivate *driScreenPriv; - - /** - * Called via glXSwapBuffers(). - */ - void (*swapBuffers)( __DRIdrawablePrivate *dPriv ); + __DRIscreen *driScreenPriv; /** * Controls swap interval as used by GLX_SGI_swap_control and @@ -376,13 +371,14 @@ struct __DRIdrawablePrivateRec { unsigned int swap_interval; struct { unsigned int tail; + unsigned int drawable_id; } dri2; }; /** * Per-context private driver information. */ -struct __DRIcontextPrivateRec { +struct __DRIcontextRec { /** * Kernel context handle used to access the device lock. */ @@ -401,23 +397,23 @@ struct __DRIcontextPrivateRec { /** * Pointer to drawable currently bound to this context for drawing. */ - __DRIdrawablePrivate *driDrawablePriv; + __DRIdrawable *driDrawablePriv; /** * Pointer to drawable currently bound to this context for reading. */ - __DRIdrawablePrivate *driReadablePriv; + __DRIdrawable *driReadablePriv; /** * Pointer to screen on which this context was created. */ - __DRIscreenPrivate *driScreenPriv; + __DRIscreen *driScreenPriv; }; /** * Per-screen private driver information. */ -struct __DRIscreenPrivateRec { +struct __DRIscreenRec { /** * Current screen's number */ @@ -428,6 +424,7 @@ struct __DRIscreenPrivateRec { */ struct __DriverAPIRec DriverAPI; + const __DRIextension **extensions; /** * DDX / 2D driver version information. */ @@ -504,7 +501,7 @@ struct __DRIscreenPrivateRec { * context is created when the first "real" context is created on this * screen. */ - __DRIcontextPrivate dummyContextPriv; + __DRIcontext dummyContextPriv; /** * Device-dependent private information (not stored in the SAREA). @@ -518,13 +515,7 @@ struct __DRIscreenPrivateRec { */ __DRIscreen *psc; - /** - * Extensions provided by this driver. - */ - const __DRIextension **extensions; - /* Extensions provided by the loader. */ - const __DRIcontextModesExtension *contextModes; const __DRIgetDrawableInfoExtension *getDrawableInfo; const __DRIsystemTimeExtension *systemTime; const __DRIdamageExtension *damage; @@ -537,13 +528,16 @@ struct __DRIscreenPrivateRec { void *sarea; __DRIEventBuffer *buffer; __DRILock *lock; - __DRIcoreDRI2Extension *core; + __DRIloaderExtension *loader; } dri2; /* The lock actually in use, old sarea or DRI2 */ drmLock *lock; }; +struct __DRIconfigRec { + __GLcontextModes modes; +}; /** * Used to store a version which includes a major range instead of a single @@ -562,13 +556,13 @@ __driUtilMessage(const char *f, ...); extern void -__driUtilUpdateDrawableInfo(__DRIdrawablePrivate *pdp); +__driUtilUpdateDrawableInfo(__DRIdrawable *pdp); extern int -__driParseEvents(__DRIcontextPrivate *psp, __DRIdrawablePrivate *pdp); +__driParseEvents(__DRIcontext *psp, __DRIdrawable *pdp); extern float -driCalculateSwapUsage( __DRIdrawablePrivate *dPriv, +driCalculateSwapUsage( __DRIdrawable *dPriv, int64_t last_swap_ust, int64_t current_ust ); #endif /* _DRI_UTIL_H_ */ diff --git a/src/mesa/drivers/dri/common/utils.c b/src/mesa/drivers/dri/common/utils.c index 6a189e72858..1839ef935a1 100644 --- a/src/mesa/drivers/dri/common/utils.c +++ b/src/mesa/drivers/dri/common/utils.c @@ -467,8 +467,6 @@ GLboolean driClipRectToFramebuffer( const GLframebuffer *buffer, return GL_TRUE; } - - /** * Creates a set of \c __GLcontextModes that a driver will expose. * @@ -536,13 +534,11 @@ GLboolean driClipRectToFramebuffer( const GLframebuffer *buffer, * \c GL_UNSIGNED_3BYTE_8_8_8, \c GL_4FLOAT_32_32_32_32, * \c GL_4HALF_16_16_16_16, etc. We can cross that bridge when we come to it. */ -GLboolean -driFillInModes( __GLcontextModes ** ptr_to_modes, - GLenum fb_format, GLenum fb_type, - const u_int8_t * depth_bits, const u_int8_t * stencil_bits, - unsigned num_depth_stencil_bits, - const GLenum * db_modes, unsigned num_db_modes, - int visType ) +__DRIconfig ** +driCreateConfigs(GLenum fb_format, GLenum fb_type, + const u_int8_t * depth_bits, const u_int8_t * stencil_bits, + unsigned num_depth_stencil_bits, + const GLenum * db_modes, unsigned num_db_modes) { static const u_int8_t bits_table[3][4] = { /* R G B A */ @@ -606,16 +602,18 @@ driFillInModes( __GLcontextModes ** ptr_to_modes, const u_int8_t * bits; const u_int32_t * masks; const int index = fb_type & 0x07; - __GLcontextModes * modes = *ptr_to_modes; + __DRIconfig **configs, **c; + __GLcontextModes *modes; unsigned i; unsigned j; unsigned k; - + unsigned num_modes; + unsigned num_accum_bits = 2; if ( bytes_per_pixel[ index ] == 0 ) { fprintf( stderr, "[%s:%u] Framebuffer type 0x%04x has 0 bytes per pixel.\n", __FUNCTION__, __LINE__, fb_type ); - return GL_FALSE; + return NULL; } @@ -653,14 +651,23 @@ driFillInModes( __GLcontextModes ** ptr_to_modes, default: fprintf( stderr, "[%s:%u] Framebuffer format 0x%04x is not GL_RGB, GL_RGBA, GL_BGR, or GL_BGRA.\n", __FUNCTION__, __LINE__, fb_format ); - return GL_FALSE; + return NULL; } + num_modes = num_depth_stencil_bits * num_db_modes * num_accum_bits; + configs = _mesa_calloc((num_modes + 1) * sizeof *configs); + if (configs == NULL) + return NULL; + c = configs; for ( k = 0 ; k < num_depth_stencil_bits ; k++ ) { for ( i = 0 ; i < num_db_modes ; i++ ) { - for ( j = 0 ; j < 2 ; j++ ) { + for ( j = 0 ; j < num_accum_bits ; j++ ) { + *c = _mesa_malloc (sizeof **c); + modes = &(*c)->modes; + c++; + memset(modes, 0, sizeof *modes); modes->redBits = bits[0]; modes->greenBits = bits[1]; modes->blueBits = bits[2]; @@ -681,7 +688,13 @@ driFillInModes( __GLcontextModes ** ptr_to_modes, modes->stencilBits = stencil_bits[k]; modes->depthBits = depth_bits[k]; - modes->visualType = visType; + modes->transparentPixel = GLX_NONE; + modes->transparentRed = GLX_DONT_CARE; + modes->transparentGreen = GLX_DONT_CARE; + modes->transparentBlue = GLX_DONT_CARE; + modes->transparentAlpha = GLX_DONT_CARE; + modes->transparentIndex = GLX_DONT_CARE; + modes->visualType = GLX_DONT_CARE; modes->renderType = GLX_RGBA_BIT; modes->drawableType = GLX_WINDOW_BIT; modes->rgbMode = GL_TRUE; @@ -700,12 +713,36 @@ driFillInModes( __GLcontextModes ** ptr_to_modes, modes->accumAlphaBits) > 0); modes->haveDepthBuffer = (modes->depthBits > 0); modes->haveStencilBuffer = (modes->stencilBits > 0); - - modes = modes->next; } } } + *c = NULL; + + return configs; +} - *ptr_to_modes = modes; - return GL_TRUE; +const __DRIconfig **driConcatConfigs(__DRIconfig **a, __DRIconfig **b) +{ + const __DRIconfig **all; + int i, j, index; + + i = 0; + while (a[i] != NULL) + i++; + j = 0; + while (b[j] != NULL) + j++; + + all = _mesa_malloc((i + j + 1) * sizeof *all); + index = 0; + for (i = 0; a[i] != NULL; i++) + all[index++] = a[i]; + for (j = 0; b[j] != NULL; j++) + all[index++] = b[j]; + all[index++] = NULL; + + _mesa_free(a); + _mesa_free(b); + + return all; } diff --git a/src/mesa/drivers/dri/common/utils.h b/src/mesa/drivers/dri/common/utils.h index b2bab86e66c..45a78e5ca5a 100644 --- a/src/mesa/drivers/dri/common/utils.h +++ b/src/mesa/drivers/dri/common/utils.h @@ -112,10 +112,12 @@ extern GLboolean driClipRectToFramebuffer( const GLframebuffer *buffer, GLint *x, GLint *y, GLsizei *width, GLsizei *height ); -extern GLboolean driFillInModes( __GLcontextModes ** modes, - GLenum fb_format, GLenum fb_type, - const u_int8_t * depth_bits, const u_int8_t * stencil_bits, - unsigned num_depth_stencil_bits, - const GLenum * db_modes, unsigned num_db_modes, int visType ); +extern __DRIconfig ** +driCreateConfigs(GLenum fb_format, GLenum fb_type, + const u_int8_t * depth_bits, const u_int8_t * stencil_bits, + unsigned num_depth_stencil_bits, + const GLenum * db_modes, unsigned num_db_modes); + +const __DRIconfig **driConcatConfigs(__DRIconfig **a, __DRIconfig **b); #endif /* DRI_DEBUG_H */ diff --git a/src/mesa/drivers/dri/ffb/ffb_xmesa.c b/src/mesa/drivers/dri/ffb/ffb_xmesa.c index d54c65cda43..7fd4e570d33 100644 --- a/src/mesa/drivers/dri/ffb/ffb_xmesa.c +++ b/src/mesa/drivers/dri/ffb/ffb_xmesa.c @@ -604,35 +604,18 @@ void ffbXMesaUpdateState(ffbContextPtr fmesa) } } -static const struct __DriverAPIRec ffbAPI = { - .DestroyScreen = ffbDestroyScreen, - .CreateContext = ffbCreateContext, - .DestroyContext = ffbDestroyContext, - .CreateBuffer = ffbCreateBuffer, - .DestroyBuffer = ffbDestroyBuffer, - .SwapBuffers = ffbSwapBuffers, - .MakeCurrent = ffbMakeCurrent, - .UnbindContext = ffbUnbindContext, - .GetSwapInfo = NULL, - .GetDrawableMSC = NULL, - .WaitForMSC = NULL, - .WaitForSBC = NULL, - .SwapBuffersMSC = NULL -}; - - -static __GLcontextModes * +static const __DRIconfig ** ffbFillInModes( __DRIscreenPrivate *psp, unsigned pixel_bits, unsigned depth_bits, unsigned stencil_bits, GLboolean have_back_buffer ) { - __GLcontextModes * modes; - __GLcontextModes * m; - unsigned num_modes; + __DRIconfig **configs; + __GLcontextModes *m; unsigned depth_buffer_factor; unsigned back_buffer_factor; GLenum fb_format; GLenum fb_type; + int i; /* GLX_SWAP_COPY_OML is only supported because the FFB driver doesn't * support pageflipping at all. @@ -644,7 +627,6 @@ ffbFillInModes( __DRIscreenPrivate *psp, u_int8_t depth_bits_array[3]; u_int8_t stencil_bits_array[3]; - depth_bits_array[0] = 0; depth_bits_array[1] = depth_bits; depth_bits_array[2] = depth_bits; @@ -660,8 +642,6 @@ ffbFillInModes( __DRIscreenPrivate *psp, depth_buffer_factor = ((depth_bits != 0) || (stencil_bits != 0)) ? 3 : 1; back_buffer_factor = (have_back_buffer) ? 3 : 1; - num_modes = depth_buffer_factor * back_buffer_factor * 4; - if ( pixel_bits == 16 ) { fb_format = GL_RGB; fb_type = GL_UNSIGNED_SHORT_5_6_5; @@ -671,35 +651,26 @@ ffbFillInModes( __DRIscreenPrivate *psp, fb_type = GL_UNSIGNED_INT_8_8_8_8_REV; } - modes = (*psp->contextModes->createContextModes)( num_modes, sizeof( __GLcontextModes ) ); - m = modes; - if ( ! driFillInModes( & m, fb_format, fb_type, - depth_bits_array, stencil_bits_array, depth_buffer_factor, - back_buffer_modes, back_buffer_factor, - GLX_TRUE_COLOR ) ) { - fprintf( stderr, "[%s:%u] Error creating FBConfig!\n", - __func__, __LINE__ ); - return NULL; - } - if ( ! driFillInModes( & m, fb_format, fb_type, - depth_bits_array, stencil_bits_array, depth_buffer_factor, - back_buffer_modes, back_buffer_factor, - GLX_DIRECT_COLOR ) ) { - fprintf( stderr, "[%s:%u] Error creating FBConfig!\n", - __func__, __LINE__ ); - return NULL; + configs = driCreateConfigs(fb_format, fb_type, + depth_bits_array, stencil_bits_array, + depth_buffer_factor, back_buffer_modes, + back_buffer_factor); + if (configs == NULL) { + fprintf(stderr, "[%s:%u] Error creating FBConfig!\n", __func__, + __LINE__); + return NULL; } - /* Mark the visual as slow if there are "fake" stencil bits. */ - for ( m = modes ; m != NULL ; m = m->next ) { - if ( (m->stencilBits != 0) && (m->stencilBits != stencil_bits) ) { - m->visualRating = GLX_SLOW_CONFIG; + for (i = 0; configs[i]; i++) { + m = &configs[i]->modes; + if ((m->stencilBits != 0) && (m->stencilBits != stencil_bits)) { + m->visualRating = GLX_SLOW_CONFIG; } } - return modes; + return (const __DRIconfig **) configs; } @@ -710,7 +681,8 @@ ffbFillInModes( __DRIscreenPrivate *psp, * * \return the __GLcontextModes supported by this driver */ -__GLcontextModes *__driDriverInitScreen(__DRIscreenPrivate *psp) +static const __DRIconfig ** +ffbInitScreen(__DRIscreen *psp) { static const __DRIversion ddx_expected = { 0, 1, 1 }; static const __DRIversion dri_expected = { 4, 0, 0 }; @@ -722,10 +694,25 @@ __GLcontextModes *__driDriverInitScreen(__DRIscreenPrivate *psp) &psp->drm_version, & drm_expected ) ) return NULL; - psp->DriverAPI = ffbAPI; - if (!ffbInitDriver(psp)) return NULL; return ffbFillInModes( psp, 32, 16, 0, GL_TRUE ); } + +const struct __DriverAPIRec driDriverAPI = { + .InitScreen = ffbInitScreen, + .DestroyScreen = ffbDestroyScreen, + .CreateContext = ffbCreateContext, + .DestroyContext = ffbDestroyContext, + .CreateBuffer = ffbCreateBuffer, + .DestroyBuffer = ffbDestroyBuffer, + .SwapBuffers = ffbSwapBuffers, + .MakeCurrent = ffbMakeCurrent, + .UnbindContext = ffbUnbindContext, + .GetSwapInfo = NULL, + .GetDrawableMSC = NULL, + .WaitForMSC = NULL, + .WaitForSBC = NULL, + .SwapBuffersMSC = NULL +}; diff --git a/src/mesa/drivers/dri/gamma/gamma_xmesa.c b/src/mesa/drivers/dri/gamma/gamma_xmesa.c index f41682cea71..62f0bb578c9 100644 --- a/src/mesa/drivers/dri/gamma/gamma_xmesa.c +++ b/src/mesa/drivers/dri/gamma/gamma_xmesa.c @@ -238,7 +238,7 @@ gammaUnbindContext( __DRIcontextPrivate *driContextPriv ) return GL_TRUE; } -static struct __DriverAPIRec gammaAPI = { +const struct __DriverAPIRec driDriverAPI = { gammaInitDriver, gammaDestroyScreen, gammaCreateContext, diff --git a/src/mesa/drivers/dri/i810/i810screen.c b/src/mesa/drivers/dri/i810/i810screen.c index c5c2a0d6fb3..4bfe6f264fa 100644 --- a/src/mesa/drivers/dri/i810/i810screen.c +++ b/src/mesa/drivers/dri/i810/i810screen.c @@ -56,78 +56,13 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. extern const struct dri_extension card_extensions[]; -static __GLcontextModes *fill_in_modes( __GLcontextModes *modes, - unsigned pixel_bits, - unsigned depth_bits, - unsigned stencil_bits, - const GLenum * db_modes, - unsigned num_db_modes, - int visType ) -{ - static const u_int8_t bits[1][4] = { - { 5, 6, 5, 0 } - }; - - static const u_int32_t masks[1][4] = { - { 0x0000F800, 0x000007E0, 0x0000001F, 0x00000000 } - }; - - unsigned i; - unsigned j; - const unsigned index = 0; - - for ( i = 0 ; i < num_db_modes ; i++ ) { - for ( j = 0 ; j < 2 ; j++ ) { - - modes->redBits = bits[index][0]; - modes->greenBits = bits[index][1]; - modes->blueBits = bits[index][2]; - modes->alphaBits = bits[index][3]; - modes->redMask = masks[index][0]; - modes->greenMask = masks[index][1]; - modes->blueMask = masks[index][2]; - modes->alphaMask = masks[index][3]; - modes->rgbBits = modes->redBits + modes->greenBits - + modes->blueBits + modes->alphaBits; - - modes->accumRedBits = 16 * j; - modes->accumGreenBits = 16 * j; - modes->accumBlueBits = 16 * j; - modes->accumAlphaBits = (masks[index][3] != 0) ? 16 * j : 0; - modes->visualRating = (j == 0) ? GLX_NONE : GLX_SLOW_CONFIG; - - modes->stencilBits = stencil_bits; - modes->depthBits = depth_bits; - - modes->visualType = visType; - modes->renderType = GLX_RGBA_BIT; - modes->drawableType = GLX_WINDOW_BIT; - modes->rgbMode = GL_TRUE; - - if ( db_modes[i] == GLX_NONE ) { - modes->doubleBufferMode = GL_FALSE; - } - else { - modes->doubleBufferMode = GL_TRUE; - modes->swapMethod = db_modes[i]; - } - - modes = modes->next; - } - } - - return modes; - -} - - -static __GLcontextModes * +static const __DRIconfig ** i810FillInModes( __DRIscreenPrivate *psp, unsigned pixel_bits, unsigned depth_bits, unsigned stencil_bits, GLboolean have_back_buffer ) -{ __GLcontextModes * modes; +{ + __DRIconfig **configs; __GLcontextModes * m; - unsigned num_modes; unsigned depth_buffer_factor; unsigned back_buffer_factor; unsigned i; @@ -141,50 +76,42 @@ i810FillInModes( __DRIscreenPrivate *psp, GLX_NONE, GLX_SWAP_UNDEFINED_OML /*, GLX_SWAP_COPY_OML */ }; - int depth_buffer_modes[2][2]; - + u_int8_t depth_bits_array[2]; + u_int8_t stencil_bits_array[2]; - depth_buffer_modes[0][0] = depth_bits; - depth_buffer_modes[1][0] = depth_bits; + depth_bits_array[0] = depth_bits; + depth_bits_array[1] = depth_bits; /* Just like with the accumulation buffer, always provide some modes * with a stencil buffer. It will be a sw fallback, but some apps won't * care about that. */ - depth_buffer_modes[0][1] = 0; - depth_buffer_modes[1][1] = (stencil_bits == 0) ? 8 : stencil_bits; + stencil_bits_array[0] = 0; + stencil_bits_array[1] = (stencil_bits == 0) ? 8 : stencil_bits; depth_buffer_factor = ((depth_bits != 0) || (stencil_bits != 0)) ? 2 : 1; back_buffer_factor = (have_back_buffer) ? 2 : 1; - num_modes = depth_buffer_factor * back_buffer_factor * 4; - - modes = (*psp->contextModes->createContextModes)( num_modes, sizeof( __GLcontextModes ) ); - m = modes; - for ( i = 0 ; i < depth_buffer_factor ; i++ ) { - m = fill_in_modes( m, pixel_bits, - depth_buffer_modes[i][0], depth_buffer_modes[i][1], - back_buffer_modes, back_buffer_factor, - GLX_TRUE_COLOR ); - } - - for ( i = 0 ; i < depth_buffer_factor ; i++ ) { - m = fill_in_modes( m, pixel_bits, - depth_buffer_modes[i][0], depth_buffer_modes[i][1], - back_buffer_modes, back_buffer_factor, - GLX_DIRECT_COLOR ); + configs = driCreateConfigs(GL_RGB, GL_UNSIGNED_SHORT_5_6_5, + depth_bits_array, stencil_bits_array, + depth_buffer_factor, + back_buffer_modes, back_buffer_factor); + if (configs == NULL) { + fprintf( stderr, "[%s:%u] Error creating FBConfig!\n", + __func__, __LINE__ ); + return NULL; } /* Mark the visual as slow if there are "fake" stencil bits. */ - for ( m = modes ; m != NULL ; m = m->next ) { - if ( (m->stencilBits != 0) && (m->stencilBits != stencil_bits) ) { + for (i = 0; configs[i]; i++) { + m = &configs[i]->modes; + if ((m->stencilBits != 0) && (m->stencilBits != stencil_bits)) { m->visualRating = GLX_SLOW_CONFIG; } } - return modes; - + return (const __DRIconfig **) configs; } @@ -220,12 +147,24 @@ static drmBufMapPtr i810_create_empty_buffers(void) } -static GLboolean -i810InitDriver(__DRIscreenPrivate *sPriv) +static const __DRIconfig ** +i810InitScreen(__DRIscreen *sPriv) { + static const __DRIversion ddx_expected = { 1, 0, 0 }; + static const __DRIversion dri_expected = { 4, 0, 0 }; + static const __DRIversion drm_expected = { 1, 2, 0 }; i810ScreenPrivate *i810Screen; I810DRIPtr gDRIPriv = (I810DRIPtr)sPriv->pDevPriv; + if ( ! driCheckDriDdxDrmVersions2( "i810", + &sPriv->dri_version, & dri_expected, + &sPriv->ddx_version, & ddx_expected, + &sPriv->drm_version, & drm_expected ) ) { + return NULL; + } + + driInitExtensions( NULL, card_extensions, GL_TRUE ); + if (sPriv->devPrivSize != sizeof(I810DRIRec)) { fprintf(stderr,"\nERROR! sizeof(I810DRIRec) does not match passed size from device driver\n"); return GL_FALSE; @@ -313,7 +252,7 @@ i810InitDriver(__DRIscreenPrivate *sPriv) i810Screen->sarea_priv_offset = gDRIPriv->sarea_priv_offset; - return GL_TRUE; + return i810FillInModes(sPriv, 16, 16, 0, 1); } static void @@ -402,8 +341,8 @@ i810DestroyBuffer(__DRIdrawablePrivate *driDrawPriv) _mesa_unreference_framebuffer((GLframebuffer **)(&(driDrawPriv->driverPrivate))); } - -static const struct __DriverAPIRec i810API = { +const struct __DriverAPIRec driDriverAPI = { + .InitScreen = i810InitScreen, .DestroyScreen = i810DestroyScreen, .CreateContext = i810CreateContext, .DestroyContext = i810DestroyContext, @@ -418,33 +357,3 @@ static const struct __DriverAPIRec i810API = { .WaitForSBC = NULL, .SwapBuffersMSC = NULL }; - - -/** - * This is the driver specific part of the createNewScreen entry point. - * - * \todo maybe fold this into intelInitDriver - * - * \return the __GLcontextModes supported by this driver - */ -PUBLIC __GLcontextModes *__driDriverInitScreen(__DRIscreenPrivate *psp) -{ - static const __DRIversion ddx_expected = { 1, 0, 0 }; - static const __DRIversion dri_expected = { 4, 0, 0 }; - static const __DRIversion drm_expected = { 1, 2, 0 }; - - if ( ! driCheckDriDdxDrmVersions2( "i810", - &psp->dri_version, & dri_expected, - &psp->ddx_version, & ddx_expected, - &psp->drm_version, & drm_expected ) ) { - return NULL; - } - - psp->DriverAPI = i810API; - driInitExtensions( NULL, card_extensions, GL_TRUE ); - - if (!i810InitDriver(psp)) - return NULL; - - return i810FillInModes(psp, 16, 16, 0, 1); -} diff --git a/src/mesa/drivers/dri/intel/intel_context.c b/src/mesa/drivers/dri/intel/intel_context.c index e2388dbb09a..47e7d1afc2c 100644 --- a/src/mesa/drivers/dri/intel/intel_context.c +++ b/src/mesa/drivers/dri/intel/intel_context.c @@ -848,7 +848,6 @@ intelContendedLock(struct intel_context *intel, GLuint flags) __DRIdrawablePrivate *dPriv = intel->driDrawable; __DRIscreenPrivate *sPriv = intel->driScreen; volatile struct drm_i915_sarea *sarea = intel->sarea; - int drawable_changed = 0; int me = intel->hHWContext; drmGetLock(intel->driFd, intel->hHWContext, flags); @@ -862,12 +861,8 @@ intelContendedLock(struct intel_context *intel, GLuint flags) * NOTE: This releases and regains the hw lock, so all state * checking must be done *after* this call: */ - if (dPriv) { - if (sPriv->dri2.enabled) - drawable_changed = __driParseEvents(dPriv->driContextPriv, dPriv); - else - DRI_VALIDATE_DRAWABLE_INFO(sPriv, dPriv); - } + if (dPriv) + DRI_VALIDATE_DRAWABLE_INFO(sPriv, dPriv); if (sarea && sarea->ctxOwner != me) { if (INTEL_DEBUG & DEBUG_BUFMGR) { @@ -892,48 +887,43 @@ intelContendedLock(struct intel_context *intel, GLuint flags) sarea->ctxOwner, intel->hHWContext); } - if (!sPriv->dri2.enabled) { - if (sarea->width != intel->width || sarea->height != intel->height) { - int numClipRects = intel->numClipRects; + if (sarea->width != intel->width || sarea->height != intel->height) { + int numClipRects = intel->numClipRects; - /* - * FIXME: Really only need to do this when drawing to a - * common back- or front buffer. - */ + /* + * FIXME: Really only need to do this when drawing to a + * common back- or front buffer. + */ - /* - * This will essentially drop the outstanding batchbuffer on - * the floor. - */ - intel->numClipRects = 0; + /* + * This will essentially drop the outstanding batchbuffer on + * the floor. + */ + intel->numClipRects = 0; - if (intel->Fallback) - _swrast_flush(&intel->ctx); + if (intel->Fallback) + _swrast_flush(&intel->ctx); - if (!IS_965(intel->intelScreen->deviceID)) - INTEL_FIREVERTICES(intel); + if (!IS_965(intel->intelScreen->deviceID)) + INTEL_FIREVERTICES(intel); - if (intel->batch->map != intel->batch->ptr) - intel_batchbuffer_flush(intel->batch); + if (intel->batch->map != intel->batch->ptr) + intel_batchbuffer_flush(intel->batch); - intel->numClipRects = numClipRects; + intel->numClipRects = numClipRects; - /* force window update */ - intel->lastStamp = 0; + /* force window update */ + intel->lastStamp = 0; - intel->width = sarea->width; - intel->height = sarea->height; - } + intel->width = sarea->width; + intel->height = sarea->height; + } - /* Drawable changed? - */ - if (dPriv && intel->lastStamp != dPriv->lastStamp) { - intelWindowMoved(intel); - intel->lastStamp = dPriv->lastStamp; - } - } else if (drawable_changed) { - intelWindowMoved(intel); - intel_draw_buffer(&intel->ctx, intel->ctx.DrawBuffer); + /* Drawable changed? + */ + if (dPriv && intel->lastStamp != dPriv->lastStamp) { + intelWindowMoved(intel); + intel->lastStamp = dPriv->lastStamp; } } @@ -944,13 +934,15 @@ _glthread_DECLARE_STATIC_MUTEX(lockMutex); */ void LOCK_HARDWARE( struct intel_context *intel ) { - __DRIdrawablePrivate *dPriv = intel->driDrawable; + __DRIdrawable *dPriv = intel->driDrawable; + __DRIscreen *sPriv = intel->driScreen; char __ret = 0; struct intel_framebuffer *intel_fb = NULL; struct intel_renderbuffer *intel_rb = NULL; _glthread_LOCK_MUTEX(lockMutex); assert(!intel->locked); + intel->locked = 1; if (intel->driDrawable) { intel_fb = intel->driDrawable->driverPrivate; @@ -980,10 +972,18 @@ void LOCK_HARDWARE( struct intel_context *intel ) DRM_CAS(intel->driHwLock, intel->hHWContext, (DRM_LOCK_HELD|intel->hHWContext), __ret); - if (__ret) + if (sPriv->dri2.enabled) { + if (__ret) + drmGetLock(intel->driFd, intel->hHWContext, 0); + if (__driParseEvents(dPriv->driContextPriv, dPriv)) { + intelWindowMoved(intel); + intel_draw_buffer(&intel->ctx, intel->ctx.DrawBuffer); + } + } else if (__ret) { intelContendedLock( intel, 0 ); + } + - intel->locked = 1; if (INTEL_DEBUG & DEBUG_LOCK) _mesa_printf("%s - locked\n", __progname); } diff --git a/src/mesa/drivers/dri/intel/intel_screen.c b/src/mesa/drivers/dri/intel/intel_screen.c index 3d46073daad..5aeb2a18f42 100644 --- a/src/mesa/drivers/dri/intel/intel_screen.c +++ b/src/mesa/drivers/dri/intel/intel_screen.c @@ -394,7 +394,7 @@ static const __DRItexBufferExtension intelTexBufferExtension = { intelSetTexBuffer, }; -static const __DRIextension *intelExtensions[] = { +static const __DRIextension *intelScreenExtensions[] = { &driReadDrawableExtension, &driCopySubBufferExtension.base, &driSwapControlExtension.base, @@ -479,7 +479,7 @@ static GLboolean intelInitDriver(__DRIscreenPrivate *sPriv) &intelScreen->allow_batchbuffer)) return GL_FALSE; - sPriv->extensions = intelExtensions; + sPriv->extensions = intelScreenExtensions; return GL_TRUE; } @@ -653,39 +653,18 @@ intelCreateContext(const __GLcontextModes * mesaVis, } -static const struct __DriverAPIRec intelAPI = { - .DestroyScreen = intelDestroyScreen, - .CreateContext = intelCreateContext, - .DestroyContext = intelDestroyContext, - .CreateBuffer = intelCreateBuffer, - .DestroyBuffer = intelDestroyBuffer, - .SwapBuffers = intelSwapBuffers, - .MakeCurrent = intelMakeCurrent, - .UnbindContext = intelUnbindContext, - .GetSwapInfo = intelGetSwapInfo, - .GetDrawableMSC = driDrawableGetMSC32, - .WaitForMSC = driWaitForMSC32, - .WaitForSBC = NULL, - .SwapBuffersMSC = NULL, - .CopySubBuffer = intelCopySubBuffer, - - .HandleDrawableConfig = intelHandleDrawableConfig, - .HandleBufferAttach = intelHandleBufferAttach, -}; - - -static __GLcontextModes * +static __DRIconfig ** intelFillInModes(__DRIscreenPrivate *psp, unsigned pixel_bits, unsigned depth_bits, unsigned stencil_bits, GLboolean have_back_buffer) { - __GLcontextModes *modes; + __DRIconfig **configs; __GLcontextModes *m; - unsigned num_modes; unsigned depth_buffer_factor; unsigned back_buffer_factor; GLenum fb_format; GLenum fb_type; + int i; /* GLX_SWAP_COPY_OML is only supported because the Intel driver doesn't * support pageflipping at all. @@ -697,7 +676,6 @@ intelFillInModes(__DRIscreenPrivate *psp, u_int8_t depth_bits_array[3]; u_int8_t stencil_bits_array[3]; - depth_bits_array[0] = 0; depth_bits_array[1] = depth_bits; depth_bits_array[2] = depth_bits; @@ -716,8 +694,6 @@ intelFillInModes(__DRIscreenPrivate *psp, depth_buffer_factor = ((depth_bits != 0) || (stencil_bits != 0)) ? 3 : 1; back_buffer_factor = (have_back_buffer) ? 3 : 1; - num_modes = depth_buffer_factor * back_buffer_factor * 4; - if (pixel_bits == 16) { fb_format = GL_RGB; fb_type = GL_UNSIGNED_SHORT_5_6_5; @@ -727,36 +703,26 @@ intelFillInModes(__DRIscreenPrivate *psp, fb_type = GL_UNSIGNED_INT_8_8_8_8_REV; } - modes = - (*psp->contextModes->createContextModes) (num_modes, - sizeof(__GLcontextModes)); - m = modes; - if (!driFillInModes(&m, fb_format, fb_type, - depth_bits_array, stencil_bits_array, - depth_buffer_factor, back_buffer_modes, - back_buffer_factor, GLX_TRUE_COLOR)) { - fprintf(stderr, "[%s:%u] Error creating FBConfig!\n", __func__, - __LINE__); - return NULL; - } - if (!driFillInModes(&m, fb_format, fb_type, - depth_bits_array, stencil_bits_array, - depth_buffer_factor, back_buffer_modes, - back_buffer_factor, GLX_DIRECT_COLOR)) { - fprintf(stderr, "[%s:%u] Error creating FBConfig!\n", __func__, + configs = driCreateConfigs(fb_format, fb_type, + depth_bits_array, stencil_bits_array, + depth_buffer_factor, back_buffer_modes, + back_buffer_factor); + if (configs == NULL) { + fprintf(stderr, "[%s:%u] Error creating FBConfig!\n", __func__, __LINE__); return NULL; } /* Mark the visual as slow if there are "fake" stencil bits. */ - for (m = modes; m != NULL; m = m->next) { + for (i = 0; configs[i]; i++) { + m = &configs[i]->modes; if ((m->stencilBits != 0) && (m->stencilBits != stencil_bits)) { m->visualRating = GLX_SLOW_CONFIG; } } - return modes; + return configs; } @@ -767,7 +733,7 @@ intelFillInModes(__DRIscreenPrivate *psp, * * \return the __GLcontextModes supported by this driver */ -PUBLIC __GLcontextModes *__driDriverInitScreen(__DRIscreenPrivate *psp) +static const __DRIconfig **intelInitScreen(__DRIscreenPrivate *psp) { #ifdef I915 static const __DRIversion ddx_expected = { 1, 5, 0 }; @@ -778,8 +744,6 @@ PUBLIC __GLcontextModes *__driDriverInitScreen(__DRIscreenPrivate *psp) static const __DRIversion drm_expected = { 1, 5, 0 }; I830DRIPtr dri_priv = (I830DRIPtr) psp->pDevPriv; - psp->DriverAPI = intelAPI; - if (!driCheckDriDdxDrmVersions2("i915", &psp->dri_version, &dri_expected, &psp->ddx_version, &ddx_expected, @@ -802,9 +766,12 @@ PUBLIC __GLcontextModes *__driDriverInitScreen(__DRIscreenPrivate *psp) if (!intelInitDriver(psp)) return NULL; - return intelFillInModes(psp, dri_priv->cpp * 8, - (dri_priv->cpp == 2) ? 16 : 24, - (dri_priv->cpp == 2) ? 0 : 8, 1); + psp->extensions = intelScreenExtensions; + + return (const __DRIconfig **) + intelFillInModes(psp, dri_priv->cpp * 8, + (dri_priv->cpp == 2) ? 16 : 24, + (dri_priv->cpp == 2) ? 0 : 8, 1); } struct intel_context *intelScreenContext(intelScreenPrivate *intelScreen) @@ -827,12 +794,10 @@ struct intel_context *intelScreenContext(intelScreenPrivate *intelScreen) * * \return the __GLcontextModes supported by this driver */ -PUBLIC __GLcontextModes *__dri2DriverInitScreen(__DRIscreenPrivate *psp) +static const +__DRIconfig **intelInitScreen2(__DRIscreenPrivate *psp) { intelScreenPrivate *intelScreen; - __GLcontextModes *modes, *m; - - psp->DriverAPI = intelAPI; /* Calling driInitExtensions here, with a NULL context pointer, * does not actually enable the extensions. It just makes sure @@ -881,12 +846,28 @@ PUBLIC __GLcontextModes *__dri2DriverInitScreen(__DRIscreenPrivate *psp) return GL_FALSE; } - psp->extensions = intelExtensions; + psp->extensions = intelScreenExtensions; - modes = intelFillInModes(psp, 16, 16, 0, 1); - for (m = modes; m->next != NULL; m = m->next) - ; - m->next = intelFillInModes(psp, 32, 24, 8, 1); - - return modes; + return driConcatConfigs(intelFillInModes(psp, 16, 16, 0, 1), + intelFillInModes(psp, 32, 24, 8, 1)); } + +const struct __DriverAPIRec driDriverAPI = { + .InitScreen = intelInitScreen, + .DestroyScreen = intelDestroyScreen, + .CreateContext = intelCreateContext, + .DestroyContext = intelDestroyContext, + .CreateBuffer = intelCreateBuffer, + .DestroyBuffer = intelDestroyBuffer, + .SwapBuffers = intelSwapBuffers, + .MakeCurrent = intelMakeCurrent, + .UnbindContext = intelUnbindContext, + .GetSwapInfo = intelGetSwapInfo, + .GetDrawableMSC = driDrawableGetMSC32, + .WaitForMSC = driWaitForMSC32, + .CopySubBuffer = intelCopySubBuffer, + + .InitScreen2 = intelInitScreen2, + .HandleDrawableConfig = intelHandleDrawableConfig, + .HandleBufferAttach = intelHandleBufferAttach, +}; diff --git a/src/mesa/drivers/dri/intel/intel_tex_image.c b/src/mesa/drivers/dri/intel/intel_tex_image.c index dd8fbeaa911..a56a3956466 100644 --- a/src/mesa/drivers/dri/intel/intel_tex_image.c +++ b/src/mesa/drivers/dri/intel/intel_tex_image.c @@ -676,8 +676,7 @@ void intelSetTexOffset(__DRIcontext *pDRICtx, GLint texname, unsigned long long offset, GLint depth, GLuint pitch) { - struct intel_context *intel = (struct intel_context*) - ((__DRIcontextPrivate*)pDRICtx->private)->driverPrivate; + struct intel_context *intel = pDRICtx->driverPrivate; struct gl_texture_object *tObj = _mesa_lookup_texture(&intel->ctx, texname); struct intel_texture_object *intelObj = intel_texture_object(tObj); @@ -696,12 +695,10 @@ intelSetTexOffset(__DRIcontext *pDRICtx, GLint texname, } void -intelSetTexBuffer(__DRIcontext *pDRICtx, GLint target, __DRIdrawable *pDraw) +intelSetTexBuffer(__DRIcontext *pDRICtx, GLint target, __DRIdrawable *dPriv) { - __DRIcontextPrivate *driContext = pDRICtx->private; - __DRIdrawablePrivate *dPriv = pDraw->private; struct intel_framebuffer *intel_fb = dPriv->driverPrivate; - struct intel_context *intel = driContext->driverPrivate; + struct intel_context *intel = pDRICtx->driverPrivate; struct intel_texture_object *intelObj; struct intel_texture_image *intelImage; struct intel_mipmap_tree *mt; @@ -718,7 +715,7 @@ intelSetTexBuffer(__DRIcontext *pDRICtx, GLint target, __DRIdrawable *pDraw) if (!intelObj) return; - __driParseEvents(driContext, dPriv); + __driParseEvents(pDRICtx, dPriv); rb = intel_fb->color_rb[0]; type = GL_BGRA; diff --git a/src/mesa/drivers/dri/mach64/mach64_screen.c b/src/mesa/drivers/dri/mach64/mach64_screen.c index 63b9d8077dc..2dba50fc1fa 100644 --- a/src/mesa/drivers/dri/mach64/mach64_screen.c +++ b/src/mesa/drivers/dri/mach64/mach64_screen.c @@ -69,80 +69,15 @@ static const GLuint __driNConfigOptions = 2; extern const struct dri_extension card_extensions[]; -static __GLcontextModes * fill_in_modes( __GLcontextModes * modes, - unsigned pixel_bits, - unsigned depth_bits, - unsigned stencil_bits, - const GLenum * db_modes, - unsigned num_db_modes, - int visType ) -{ - static const u_int8_t bits[2][4] = { - { 5, 6, 5, 0 }, - { 8, 8, 8, 0 } - }; - - static const u_int32_t masks[2][4] = { - { 0x0000F800, 0x000007E0, 0x0000001F, 0x00000000 }, - { 0x00FF0000, 0x0000FF00, 0x000000FF, 0x00000000 } - }; - - unsigned i; - unsigned j; - const unsigned index = ((pixel_bits + 15) / 16) - 1; - - for ( i = 0 ; i < num_db_modes ; i++ ) { - for ( j = 0 ; j < 2 ; j++ ) { - - modes->redBits = bits[index][0]; - modes->greenBits = bits[index][1]; - modes->blueBits = bits[index][2]; - modes->alphaBits = bits[index][3]; - modes->redMask = masks[index][0]; - modes->greenMask = masks[index][1]; - modes->blueMask = masks[index][2]; - modes->alphaMask = masks[index][3]; - modes->rgbBits = modes->redBits + modes->greenBits - + modes->blueBits + modes->alphaBits; - - modes->accumRedBits = 16 * j; - modes->accumGreenBits = 16 * j; - modes->accumBlueBits = 16 * j; - modes->accumAlphaBits = 0; - modes->visualRating = (j == 0) ? GLX_NONE : GLX_SLOW_CONFIG; - modes->drawableType = GLX_WINDOW_BIT | GLX_PIXMAP_BIT; - modes->stencilBits = stencil_bits; - modes->depthBits = depth_bits; - - modes->visualType = visType; - modes->renderType = GLX_RGBA_BIT; - modes->rgbMode = GL_TRUE; - - if ( db_modes[i] == GLX_NONE ) { - - modes->doubleBufferMode = GL_FALSE; - } - else { - modes->doubleBufferMode = GL_TRUE; - modes->swapMethod = db_modes[i]; - } - - modes = modes->next; - } - } - - return modes; -} - - -static __GLcontextModes * +static const __DRIconfig ** mach64FillInModes( __DRIscreenPrivate *psp, unsigned pixel_bits, unsigned depth_bits, unsigned stencil_bits, GLboolean have_back_buffer ) { - __GLcontextModes * modes; + __DRIconfig **configs; __GLcontextModes * m; - unsigned num_modes; + GLenum fb_format; + GLenum fb_type; unsigned depth_buffer_factor; unsigned back_buffer_factor; unsigned i; @@ -156,49 +91,51 @@ mach64FillInModes( __DRIscreenPrivate *psp, GLX_NONE, GLX_SWAP_UNDEFINED_OML /*, GLX_SWAP_COPY_OML */ }; - int depth_buffer_modes[2][2]; - + u_int8_t depth_bits_array[2]; + u_int8_t stencil_bits_array[2]; - depth_buffer_modes[0][0] = depth_bits; - depth_buffer_modes[1][0] = depth_bits; + depth_bits_array[0] = depth_bits; + depth_bits_array[1] = depth_bits; /* Just like with the accumulation buffer, always provide some modes * with a stencil buffer. It will be a sw fallback, but some apps won't * care about that. */ - depth_buffer_modes[0][1] = 0; - depth_buffer_modes[1][1] = (stencil_bits == 0) ? 8 : stencil_bits; + stencil_bits_array[0] = 0; + stencil_bits_array[1] = (stencil_bits == 0) ? 8 : stencil_bits; depth_buffer_factor = ((depth_bits != 0) || (stencil_bits != 0)) ? 2 : 1; back_buffer_factor = (have_back_buffer) ? 2 : 1; - num_modes = depth_buffer_factor * back_buffer_factor * 4; - - modes = (*psp->contextModes->createContextModes)( num_modes, sizeof( __GLcontextModes ) ); - m = modes; - for ( i = 0 ; i < depth_buffer_factor ; i++ ) { - m = fill_in_modes( m, pixel_bits, - depth_buffer_modes[i][0], depth_buffer_modes[i][1], - back_buffer_modes, back_buffer_factor, - GLX_TRUE_COLOR ); + if (pixel_bits == 16) { + fb_format = GL_RGB; + fb_type = GL_UNSIGNED_SHORT_5_6_5; + } + else { + fb_format = GL_BGRA; + fb_type = GL_UNSIGNED_INT_8_8_8_8_REV; } - for ( i = 0 ; i < depth_buffer_factor ; i++ ) { - m = fill_in_modes( m, pixel_bits, - depth_buffer_modes[i][0], depth_buffer_modes[i][1], - back_buffer_modes, back_buffer_factor, - GLX_DIRECT_COLOR ); + configs = driCreateConfigs(fb_format, fb_type, + depth_bits_array, stencil_bits_array, + depth_buffer_factor, back_buffer_modes, + back_buffer_factor); + if (configs == NULL) { + fprintf(stderr, "[%s:%u] Error creating FBConfig!\n", + __func__, __LINE__); + return NULL; } /* Mark the visual as slow if there are "fake" stencil bits. */ - for ( m = modes ; m != NULL ; m = m->next ) { - if ( (m->stencilBits != 0) && (m->stencilBits != stencil_bits) ){ - m->visualRating = GLX_SLOW_CONFIG; - } + for (i = 0; configs[i]; i++) { + m = &configs[i]->modes; + if ((m->stencilBits != 0) && (m->stencilBits != stencil_bits)) { + m->visualRating = GLX_SLOW_CONFIG; + } } - return modes; + return (const __DRIconfig **) configs; } @@ -473,24 +410,6 @@ mach64InitDriver( __DRIscreenPrivate *driScreen ) return GL_TRUE; } - -static struct __DriverAPIRec mach64API = { - .DestroyScreen = mach64DestroyScreen, - .CreateContext = mach64CreateContext, - .DestroyContext = mach64DestroyContext, - .CreateBuffer = mach64CreateBuffer, - .DestroyBuffer = mach64DestroyBuffer, - .SwapBuffers = mach64SwapBuffers, - .MakeCurrent = mach64MakeCurrent, - .UnbindContext = mach64UnbindContext, - .GetSwapInfo = NULL, - .GetDrawableMSC = driDrawableGetMSC32, - .WaitForMSC = driWaitForMSC32, - .WaitForSBC = NULL, - .SwapBuffersMSC = NULL -}; - - /** * This is the driver specific part of the createNewScreen entry point. * @@ -498,14 +417,14 @@ static struct __DriverAPIRec mach64API = { * * \return the __GLcontextModes supported by this driver */ -__GLcontextModes *__driDriverInitScreen(__DRIscreenPrivate *psp) +static const __DRIconfig ** +mach64InitScreen(__DRIscreenPrivate *psp) { static const __DRIversion ddx_expected = { 6, 4, 0 }; static const __DRIversion dri_expected = { 4, 0, 0 }; static const __DRIversion drm_expected = { 2, 0, 0 }; ATIDRIPtr dri_priv = (ATIDRIPtr) psp->pDevPriv; - psp->DriverAPI = mach64API; if ( ! driCheckDriDdxDrmVersions2( "Mach64", &psp->dri_version, & dri_expected, &psp->ddx_version, & ddx_expected, @@ -530,3 +449,21 @@ __GLcontextModes *__driDriverInitScreen(__DRIscreenPrivate *psp) return mach64FillInModes( psp, dri_priv->cpp * 8, 16, 0, 1); } + +const struct __DriverAPIRec driDriverAPI = { + .InitScreen = mach64InitScreen, + .DestroyScreen = mach64DestroyScreen, + .CreateContext = mach64CreateContext, + .DestroyContext = mach64DestroyContext, + .CreateBuffer = mach64CreateBuffer, + .DestroyBuffer = mach64DestroyBuffer, + .SwapBuffers = mach64SwapBuffers, + .MakeCurrent = mach64MakeCurrent, + .UnbindContext = mach64UnbindContext, + .GetSwapInfo = NULL, + .GetDrawableMSC = driDrawableGetMSC32, + .WaitForMSC = driWaitForMSC32, + .WaitForSBC = NULL, + .SwapBuffersMSC = NULL +}; + diff --git a/src/mesa/drivers/dri/mga/mga_xmesa.c b/src/mesa/drivers/dri/mga/mga_xmesa.c index 7f2f71d3094..c271c8ef59d 100644 --- a/src/mesa/drivers/dri/mga/mga_xmesa.c +++ b/src/mesa/drivers/dri/mga/mga_xmesa.c @@ -112,20 +112,18 @@ static const GLuint __driNConfigOptions = 6; int MGA_DEBUG = 0; #endif -static int getSwapInfo( __DRIdrawablePrivate *dPriv, __DRIswapInfo * sInfo ); - -static __GLcontextModes * +static const __DRIconfig ** mgaFillInModes( __DRIscreenPrivate *psp, unsigned pixel_bits, unsigned depth_bits, unsigned stencil_bits, GLboolean have_back_buffer ) { - __GLcontextModes * modes; + __DRIconfig **configs; __GLcontextModes * m; - unsigned num_modes; unsigned depth_buffer_factor; unsigned back_buffer_factor; GLenum fb_format; GLenum fb_type; + int i; /* GLX_SWAP_COPY_OML is only supported because the MGA driver doesn't * support pageflipping at all. @@ -153,8 +151,6 @@ mgaFillInModes( __DRIscreenPrivate *psp, depth_buffer_factor = ((depth_bits != 0) || (stencil_bits != 0)) ? 3 : 1; back_buffer_factor = (have_back_buffer) ? 2 : 1; - num_modes = depth_buffer_factor * back_buffer_factor * 4; - if ( pixel_bits == 16 ) { fb_format = GL_RGB; fb_type = GL_UNSIGNED_SHORT_5_6_5; @@ -164,39 +160,29 @@ mgaFillInModes( __DRIscreenPrivate *psp, fb_type = GL_UNSIGNED_INT_8_8_8_8_REV; } - modes = (*psp->contextModes->createContextModes)( num_modes, sizeof( __GLcontextModes ) ); - m = modes; - if ( ! driFillInModes( & m, fb_format, fb_type, - depth_bits_array, stencil_bits_array, depth_buffer_factor, - back_buffer_modes, back_buffer_factor, - GLX_TRUE_COLOR ) ) { + configs = driCreateConfigs(fb_format, fb_type, + depth_bits_array, stencil_bits_array, + depth_buffer_factor, + back_buffer_modes, back_buffer_factor); + if (configs == NULL) { fprintf( stderr, "[%s:%u] Error creating FBConfig!\n", __func__, __LINE__ ); return NULL; } - if ( ! driFillInModes( & m, fb_format, fb_type, - depth_bits_array, stencil_bits_array, depth_buffer_factor, - back_buffer_modes, back_buffer_factor, - GLX_DIRECT_COLOR ) ) { - fprintf( stderr, "[%s:%u] Error creating FBConfig!\n", - __func__, __LINE__ ); - return NULL; - } - - /* Mark the visual as slow if there are "fake" stencil bits. - */ - for ( m = modes ; m != NULL ; m = m->next ) { - if ( (m->stencilBits != 0) && (m->stencilBits != stencil_bits) ) { - m->visualRating = GLX_SLOW_CONFIG; - } - } + /* Mark the visual as slow if there are "fake" stencil bits. + */ + for (i = 0; configs[i]; i++) { + m = &configs[i]->modes; + if ((m->stencilBits != 0) && (m->stencilBits != stencil_bits)) { + m->visualRating = GLX_SLOW_CONFIG; + } + } - return modes; + return (const __DRIconfig **) configs; } - -static const __DRIextension *mgaExtensions[] = { +const __DRIextension *mgaScreenExtensions[] = { &driReadDrawableExtension, &driSwapControlExtension.base, &driFrameTrackingExtension.base, @@ -243,7 +229,7 @@ mgaInitDriver(__DRIscreenPrivate *sPriv) } } - sPriv->extensions = mgaExtensions; + sPriv->extensions = mgaScreenExtensions; if (serverInfo->chipset != MGA_CARD_TYPE_G200 && serverInfo->chipset != MGA_CARD_TYPE_G400) { @@ -941,23 +927,6 @@ void mgaGetLock( mgaContextPtr mmesa, GLuint flags ) } -static const struct __DriverAPIRec mgaAPI = { - .DestroyScreen = mgaDestroyScreen, - .CreateContext = mgaCreateContext, - .DestroyContext = mgaDestroyContext, - .CreateBuffer = mgaCreateBuffer, - .DestroyBuffer = mgaDestroyBuffer, - .SwapBuffers = mgaSwapBuffers, - .MakeCurrent = mgaMakeCurrent, - .UnbindContext = mgaUnbindContext, - .GetSwapInfo = getSwapInfo, - .GetDrawableMSC = driDrawableGetMSC32, - .WaitForMSC = driWaitForMSC32, - .WaitForSBC = NULL, - .SwapBuffersMSC = NULL -}; - - /** * This is the driver specific part of the createNewScreen entry point. * @@ -965,14 +934,13 @@ static const struct __DriverAPIRec mgaAPI = { * * \return the __GLcontextModes supported by this driver */ -__GLcontextModes *__driDriverInitScreen(__DRIscreenPrivate *psp) +static const __DRIconfig **mgaInitScreen(__DRIscreen *psp) { static const __DRIversion ddx_expected = { 1, 2, 0 }; static const __DRIversion dri_expected = { 4, 0, 0 }; static const __DRIversion drm_expected = { 3, 0, 0 }; MGADRIPtr dri_priv = (MGADRIPtr) psp->pDevPriv; - psp->DriverAPI = mgaAPI; if ( ! driCheckDriDdxDrmVersions2( "MGA", &psp->dri_version, & dri_expected, &psp->ddx_version, & ddx_expected, @@ -1032,3 +1000,20 @@ getSwapInfo( __DRIdrawablePrivate *dPriv, __DRIswapInfo * sInfo ) return 0; } + +const struct __DriverAPIRec driDriverAPI = { + .InitScreen = mgaInitScreen, + .DestroyScreen = mgaDestroyScreen, + .CreateContext = mgaCreateContext, + .DestroyContext = mgaDestroyContext, + .CreateBuffer = mgaCreateBuffer, + .DestroyBuffer = mgaDestroyBuffer, + .SwapBuffers = mgaSwapBuffers, + .MakeCurrent = mgaMakeCurrent, + .UnbindContext = mgaUnbindContext, + .GetSwapInfo = getSwapInfo, + .GetDrawableMSC = driDrawableGetMSC32, + .WaitForMSC = driWaitForMSC32, + .WaitForSBC = NULL, + .SwapBuffersMSC = NULL +}; diff --git a/src/mesa/drivers/dri/nouveau/nouveau_screen.c b/src/mesa/drivers/dri/nouveau/nouveau_screen.c index 53d00e17a12..e4463fb31a1 100644 --- a/src/mesa/drivers/dri/nouveau/nouveau_screen.c +++ b/src/mesa/drivers/dri/nouveau/nouveau_screen.c @@ -195,44 +195,13 @@ nouveauGetSwapInfo(__DRIdrawablePrivate *dpriv, __DRIswapInfo *sInfo) return -1; } -static const struct __DriverAPIRec nouveauAPI = { - .DestroyScreen = nouveauDestroyScreen, - .CreateContext = nouveauCreateContext, - .DestroyContext = nouveauDestroyContext, - .CreateBuffer = nouveauCreateBuffer, - .DestroyBuffer = nouveauDestroyBuffer, - .SwapBuffers = nouveauSwapBuffers, - .MakeCurrent = nouveauMakeCurrent, - .UnbindContext = nouveauUnbindContext, - .GetSwapInfo = nouveauGetSwapInfo, - .GetDrawableMSC = driDrawableGetMSC32, - .WaitForMSC = driWaitForMSC32, - .WaitForSBC = NULL, - .SwapBuffersMSC = NULL, - .CopySubBuffer = nouveauCopySubBuffer -}; - - -static __GLcontextModes * +static __DRIconfig ** nouveauFillInModes( __DRIscreenPrivate *psp, unsigned pixel_bits, unsigned depth_bits, unsigned stencil_bits, GLboolean have_back_buffer ) { - __GLcontextModes * modes; - __GLcontextModes * m; - unsigned num_modes; unsigned depth_buffer_factor; unsigned back_buffer_factor; - int i; - - static const struct { - GLenum format; - GLenum type; - } fb_format_array[] = { - { GL_RGB , GL_UNSIGNED_SHORT_5_6_5 }, - { GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV }, - { GL_BGR , GL_UNSIGNED_INT_8_8_8_8_REV }, - }; /* GLX_SWAP_COPY_OML is only supported because the Intel driver doesn't * support pageflipping at all. @@ -247,41 +216,22 @@ nouveauFillInModes( __DRIscreenPrivate *psp, depth_buffer_factor = 4; back_buffer_factor = (have_back_buffer) ? 3 : 1; - num_modes = ((pixel_bits==16) ? 1 : 2) * - depth_buffer_factor * back_buffer_factor * 4; - modes = (*psp->contextModes->createContextModes)(num_modes, - sizeof(__GLcontextModes)); - m = modes; - - for (i=((pixel_bits==16)?0:1);i<((pixel_bits==16)?1:3);i++) { - if (!driFillInModes(&m, fb_format_array[i].format, - fb_format_array[i].type, - depth_bits_array, - stencil_bits_array, - depth_buffer_factor, - back_buffer_modes, - back_buffer_factor, - GLX_TRUE_COLOR)) { - fprintf( stderr, "[%s:%u] Error creating FBConfig!\n", - __func__, __LINE__ ); - return NULL; - } - - if (!driFillInModes(&m, fb_format_array[i].format, - fb_format_array[i].type, - depth_bits_array, - stencil_bits_array, - depth_buffer_factor, - back_buffer_modes, - back_buffer_factor, - GLX_DIRECT_COLOR)) { - fprintf( stderr, "[%s:%u] Error creating FBConfig!\n", - __func__, __LINE__ ); - return NULL; - } - } - - return modes; + if (pixel_bits == 16) + return driCreateConfigs(GL_RGB, + GL_UNSIGNED_SHORT_5_6_5, + depth_bits_array, + stencil_bits_array, + depth_buffer_factor, + back_buffer_modes, + back_buffer_factor); + else + return driCreateConfigs(GL_RGBA, + GL_UNSIGNED_INT_8_8_8_8_REV, + depth_bits_array, + stencil_bits_array, + depth_buffer_factor, + back_buffer_modes, + back_buffer_factor); } @@ -292,7 +242,8 @@ nouveauFillInModes( __DRIscreenPrivate *psp, * * \return the __GLcontextModes supported by this driver */ -__GLcontextModes *__driDriverInitScreen(__DRIscreenPrivate *psp) +static const __DRIconfig ** +nouveauInitScreen(__DRIscreenPrivate *psp) { static const __DRIversion ddx_expected = { 0, 0, NOUVEAU_DRM_HEADER_PATCHLEVEL }; static const __DRIversion dri_expected = { 4, 0, 0 }; @@ -321,8 +272,6 @@ __GLcontextModes *__driDriverInitScreen(__DRIscreenPrivate *psp) return NULL; } - psp->DriverAPI = nouveauAPI; - /* Calling driInitExtensions here, with a NULL context * pointer, does not actually enable the extensions. It just * makes sure that all the dispatch offsets for all the @@ -343,10 +292,34 @@ __GLcontextModes *__driDriverInitScreen(__DRIscreenPrivate *psp) if (!nouveauInitDriver(psp)) return NULL; - return nouveauFillInModes(psp, - dri_priv->bpp, - (dri_priv->bpp == 16) ? 16 : 24, - (dri_priv->bpp == 16) ? 0 : 8, - 1); + return (const __DRIconfig **) + nouveauFillInModes(psp, + dri_priv->bpp, + (dri_priv->bpp == 16) ? 16 : 24, + (dri_priv->bpp == 16) ? 0 : 8, + 1); } +const struct __DriverAPIRec driDriverAPI = { + .InitScreen = nouveauInitScreen, + .DestroyScreen = nouveauDestroyScreen, + .CreateContext = nouveauCreateContext, + .DestroyContext = nouveauDestroyContext, + .CreateBuffer = nouveauCreateBuffer, + .DestroyBuffer = nouveauDestroyBuffer, + .SwapBuffers = nouveauSwapBuffers, + .MakeCurrent = nouveauMakeCurrent, + .UnbindContext = nouveauUnbindContext, + .GetSwapInfo = nouveauGetSwapInfo, + .GetDrawableMSC = driDrawableGetMSC32, + .WaitForMSC = driWaitForMSC32, + .WaitForSBC = NULL, + .SwapBuffersMSC = NULL, + .CopySubBuffer = nouveauCopySubBuffer +}; + +const __DRIextension *__driDriverExtensions[] = { + &driCoreExtension.base, + &driLegacyExtension.base, + NULL +}; diff --git a/src/mesa/drivers/dri/r128/r128_screen.c b/src/mesa/drivers/dri/r128/r128_screen.c index 335af974cff..7b544acf3b7 100644 --- a/src/mesa/drivers/dri/r128/r128_screen.c +++ b/src/mesa/drivers/dri/r128/r128_screen.c @@ -399,37 +399,18 @@ r128InitDriver( __DRIscreenPrivate *sPriv ) return GL_TRUE; } - -static struct __DriverAPIRec r128API = { - .DestroyScreen = r128DestroyScreen, - .CreateContext = r128CreateContext, - .DestroyContext = r128DestroyContext, - .CreateBuffer = r128CreateBuffer, - .DestroyBuffer = r128DestroyBuffer, - .SwapBuffers = r128SwapBuffers, - .MakeCurrent = r128MakeCurrent, - .UnbindContext = r128UnbindContext, - .GetSwapInfo = NULL, - .GetDrawableMSC = driDrawableGetMSC32, - .WaitForMSC = driWaitForMSC32, - .WaitForSBC = NULL, - .SwapBuffersMSC = NULL - -}; - - -static __GLcontextModes * +static const __DRIconfig ** r128FillInModes( __DRIscreenPrivate *psp, unsigned pixel_bits, unsigned depth_bits, unsigned stencil_bits, GLboolean have_back_buffer ) { - __GLcontextModes * modes; + __DRIconfig **configs; __GLcontextModes * m; - unsigned num_modes; unsigned depth_buffer_factor; unsigned back_buffer_factor; GLenum fb_format; GLenum fb_type; + int i; /* Right now GLX_SWAP_COPY_OML isn't supported, but it would be easy * enough to add support. Basically, if a context is created with an @@ -457,8 +438,6 @@ r128FillInModes( __DRIscreenPrivate *psp, depth_buffer_factor = ((depth_bits != 0) || (stencil_bits != 0)) ? 2 : 1; back_buffer_factor = (have_back_buffer) ? 2 : 1; - num_modes = depth_buffer_factor * back_buffer_factor * 4; - if ( pixel_bits == 16 ) { fb_format = GL_RGB; fb_type = GL_UNSIGNED_SHORT_5_6_5; @@ -468,35 +447,26 @@ r128FillInModes( __DRIscreenPrivate *psp, fb_type = GL_UNSIGNED_INT_8_8_8_8_REV; } - modes = (*psp->contextModes->createContextModes)( num_modes, sizeof( __GLcontextModes ) ); - m = modes; - if ( ! driFillInModes( & m, fb_format, fb_type, - depth_bits_array, stencil_bits_array, depth_buffer_factor, - back_buffer_modes, back_buffer_factor, - GLX_TRUE_COLOR ) ) { - fprintf( stderr, "[%s:%u] Error creating FBConfig!\n", - __func__, __LINE__ ); - return NULL; - } - - if ( ! driFillInModes( & m, fb_format, fb_type, - depth_bits_array, stencil_bits_array, depth_buffer_factor, - back_buffer_modes, back_buffer_factor, - GLX_DIRECT_COLOR ) ) { - fprintf( stderr, "[%s:%u] Error creating FBConfig!\n", - __func__, __LINE__ ); - return NULL; - } + configs = driCreateConfigs(fb_format, fb_type, + depth_bits_array, stencil_bits_array, + depth_buffer_factor, back_buffer_modes, + back_buffer_factor); + if (configs == NULL) { + fprintf(stderr, "[%s:%u] Error creating FBConfig!\n", __func__, + __LINE__); + return NULL; + } - /* Mark the visual as slow if there are "fake" stencil bits. - */ - for ( m = modes ; m != NULL ; m = m->next ) { - if ( (m->stencilBits != 0) && (m->stencilBits != stencil_bits) ) { - m->visualRating = GLX_SLOW_CONFIG; - } - } + /* Mark the visual as slow if there are "fake" stencil bits. + */ + for (i = 0; configs[i]; i++) { + m = &configs[i]->modes; + if ((m->stencilBits != 0) && (m->stencilBits != stencil_bits)) { + m->visualRating = GLX_SLOW_CONFIG; + } + } - return modes; + return (const __DRIconfig **) configs; } @@ -507,14 +477,14 @@ r128FillInModes( __DRIscreenPrivate *psp, * * \return the __GLcontextModes supported by this driver */ -__GLcontextModes *__driDriverInitScreen(__DRIscreenPrivate *psp) +static const __DRIconfig ** +r128InitScreen(__DRIscreenPrivate *psp) { static const __DRIversion ddx_expected = { 4, 0, 0 }; static const __DRIversion dri_expected = { 4, 0, 0 }; static const __DRIversion drm_expected = { 2, 2, 0 }; R128DRIPtr dri_priv = (R128DRIPtr) psp->pDevPriv; - psp->DriverAPI = r128API; if ( ! driCheckDriDdxDrmVersions2( "Rage128", &psp->dri_version, & dri_expected, &psp->ddx_version, & ddx_expected, @@ -542,3 +512,20 @@ __GLcontextModes *__driDriverInitScreen(__DRIscreenPrivate *psp) (dri_priv->bpp == 16) ? 0 : 8, (dri_priv->backOffset != dri_priv->depthOffset) ); } + +const struct __DriverAPIRec driDriverAPI = { + .InitScreen = r128InitScreen, + .DestroyScreen = r128DestroyScreen, + .CreateContext = r128CreateContext, + .DestroyContext = r128DestroyContext, + .CreateBuffer = r128CreateBuffer, + .DestroyBuffer = r128DestroyBuffer, + .SwapBuffers = r128SwapBuffers, + .MakeCurrent = r128MakeCurrent, + .UnbindContext = r128UnbindContext, + .GetSwapInfo = NULL, + .GetDrawableMSC = driDrawableGetMSC32, + .WaitForMSC = driWaitForMSC32, + .WaitForSBC = NULL, + .SwapBuffersMSC = NULL +}; diff --git a/src/mesa/drivers/dri/r200/r200_texstate.c b/src/mesa/drivers/dri/r200/r200_texstate.c index 94701ef1ca4..05ff5952f3e 100644 --- a/src/mesa/drivers/dri/r200/r200_texstate.c +++ b/src/mesa/drivers/dri/r200/r200_texstate.c @@ -979,9 +979,7 @@ static GLboolean r200UpdateTextureEnv( GLcontext *ctx, int unit, int slot, GLuin void r200SetTexOffset(__DRIcontext * pDRICtx, GLint texname, unsigned long long offset, GLint depth, GLuint pitch) { - r200ContextPtr rmesa = - (r200ContextPtr) ((__DRIcontextPrivate *) pDRICtx->private)-> - driverPrivate; + r200ContextPtr rmesa = pDRICtx->driverPrivate; struct gl_texture_object *tObj = _mesa_lookup_texture(rmesa->glCtx, texname); r200TexObjPtr t; diff --git a/src/mesa/drivers/dri/r300/r300_texstate.c b/src/mesa/drivers/dri/r300/r300_texstate.c index efa201a52d5..43d1406da34 100644 --- a/src/mesa/drivers/dri/r300/r300_texstate.c +++ b/src/mesa/drivers/dri/r300/r300_texstate.c @@ -569,9 +569,7 @@ static GLboolean r300UpdateTexture(GLcontext * ctx, int unit) void r300SetTexOffset(__DRIcontext * pDRICtx, GLint texname, unsigned long long offset, GLint depth, GLuint pitch) { - r300ContextPtr rmesa = - (r300ContextPtr) ((__DRIcontextPrivate *) pDRICtx->private)-> - driverPrivate; + r300ContextPtr rmesa = pDRICtx->driverPrivate; struct gl_texture_object *tObj = _mesa_lookup_texture(rmesa->radeon.glCtx, texname); r300TexObjPtr t; diff --git a/src/mesa/drivers/dri/radeon/radeon_screen.c b/src/mesa/drivers/dri/radeon/radeon_screen.c index d6caa2ac897..27d233cc42c 100644 --- a/src/mesa/drivers/dri/radeon/radeon_screen.c +++ b/src/mesa/drivers/dri/radeon/radeon_screen.c @@ -252,18 +252,18 @@ radeonGetParam(int fd, int param, void *value) return ret; } -static __GLcontextModes * +static const __DRIconfig ** radeonFillInModes( __DRIscreenPrivate *psp, unsigned pixel_bits, unsigned depth_bits, unsigned stencil_bits, GLboolean have_back_buffer ) { - __GLcontextModes * modes; - __GLcontextModes * m; - unsigned num_modes; + __DRIconfig **configs; + __GLcontextModes *m; unsigned depth_buffer_factor; unsigned back_buffer_factor; GLenum fb_format; GLenum fb_type; + int i; /* Right now GLX_SWAP_COPY_OML isn't supported, but it would be easy * enough to add support. Basically, if a context is created with an @@ -291,8 +291,6 @@ radeonFillInModes( __DRIscreenPrivate *psp, depth_buffer_factor = ((depth_bits != 0) || (stencil_bits != 0)) ? 2 : 1; back_buffer_factor = (have_back_buffer) ? 2 : 1; - num_modes = depth_buffer_factor * back_buffer_factor * 4; - if ( pixel_bits == 16 ) { fb_format = GL_RGB; fb_type = GL_UNSIGNED_SHORT_5_6_5; @@ -302,21 +300,11 @@ radeonFillInModes( __DRIscreenPrivate *psp, fb_type = GL_UNSIGNED_INT_8_8_8_8_REV; } - modes = (*psp->contextModes->createContextModes)( num_modes, sizeof( __GLcontextModes ) ); - m = modes; - if ( ! driFillInModes( & m, fb_format, fb_type, - depth_bits_array, stencil_bits_array, depth_buffer_factor, - back_buffer_modes, back_buffer_factor, - GLX_TRUE_COLOR ) ) { - fprintf( stderr, "[%s:%u] Error creating FBConfig!\n", - __func__, __LINE__ ); - return NULL; - } - - if ( ! driFillInModes( & m, fb_format, fb_type, - depth_bits_array, stencil_bits_array, depth_buffer_factor, - back_buffer_modes, back_buffer_factor, - GLX_DIRECT_COLOR ) ) { + configs = driCreateConfigs(fb_format, fb_type, + depth_bits_array, stencil_bits_array, + depth_buffer_factor, + back_buffer_modes, back_buffer_factor); + if (configs == NULL) { fprintf( stderr, "[%s:%u] Error creating FBConfig!\n", __func__, __LINE__ ); return NULL; @@ -324,13 +312,14 @@ radeonFillInModes( __DRIscreenPrivate *psp, /* Mark the visual as slow if there are "fake" stencil bits. */ - for ( m = modes ; m != NULL ; m = m->next ) { - if ( (m->stencilBits != 0) && (m->stencilBits != stencil_bits) ) { + for (i = 0; configs[i]; i++) { + m = &configs[i]->modes; + if ((m->stencilBits != 0) && (m->stencilBits != stencil_bits)) { m->visualRating = GLX_SLOW_CONFIG; } } - return modes; + return (const __DRIconfig **) configs; } #if RADEON_COMMON && defined(RADEON_COMMON_FOR_R200) @@ -989,43 +978,6 @@ static void radeonDestroyContext(__DRIcontextPrivate * driContextPriv) #endif -#if !RADEON_COMMON || (RADEON_COMMON && defined(RADEON_COMMON_FOR_R300)) -static struct __DriverAPIRec radeonAPI = { - .DestroyScreen = radeonDestroyScreen, - .CreateContext = radeonCreateContext, - .DestroyContext = radeonDestroyContext, - .CreateBuffer = radeonCreateBuffer, - .DestroyBuffer = radeonDestroyBuffer, - .SwapBuffers = radeonSwapBuffers, - .MakeCurrent = radeonMakeCurrent, - .UnbindContext = radeonUnbindContext, - .GetSwapInfo = getSwapInfo, - .GetDrawableMSC = driDrawableGetMSC32, - .WaitForMSC = driWaitForMSC32, - .WaitForSBC = NULL, - .SwapBuffersMSC = NULL, - .CopySubBuffer = radeonCopySubBuffer, -}; -#else -static const struct __DriverAPIRec r200API = { - .DestroyScreen = radeonDestroyScreen, - .CreateContext = r200CreateContext, - .DestroyContext = r200DestroyContext, - .CreateBuffer = radeonCreateBuffer, - .DestroyBuffer = radeonDestroyBuffer, - .SwapBuffers = r200SwapBuffers, - .MakeCurrent = r200MakeCurrent, - .UnbindContext = r200UnbindContext, - .GetSwapInfo = getSwapInfo, - .GetDrawableMSC = driDrawableGetMSC32, - .WaitForMSC = driWaitForMSC32, - .WaitForSBC = NULL, - .SwapBuffersMSC = NULL, - .CopySubBuffer = r200CopySubBuffer, -}; -#endif - - /** * This is the driver specific part of the createNewScreen entry point. * @@ -1033,7 +985,8 @@ static const struct __DriverAPIRec r200API = { * * \return the __GLcontextModes supported by this driver */ -__GLcontextModes *__driDriverInitScreen(__DRIscreenPrivate *psp) +static const __DRIconfig ** +radeonInitScreen(__DRIscreenPrivate *psp) { #if !RADEON_COMMON static const char *driver_name = "Radeon"; @@ -1059,11 +1012,6 @@ __GLcontextModes *__driDriverInitScreen(__DRIscreenPrivate *psp) &psp->drm_version, & drm_expected ) ) { return NULL; } -#if !RADEON_COMMON || (RADEON_COMMON && defined(RADEON_COMMON_FOR_R300)) - psp->DriverAPI = radeonAPI; -#elif RADEON_COMMON && defined(RADEON_COMMON_FOR_R200) - psp->DriverAPI = r200API; -#endif /* Calling driInitExtensions here, with a NULL context pointer, * does not actually enable the extensions. It just makes sure @@ -1124,3 +1072,41 @@ getSwapInfo( __DRIdrawablePrivate *dPriv, __DRIswapInfo * sInfo ) return 0; } + +#if !RADEON_COMMON || (RADEON_COMMON && defined(RADEON_COMMON_FOR_R300)) +const struct __DriverAPIRec driDriverAPI = { + .InitScreen = radeonInitScreen, + .DestroyScreen = radeonDestroyScreen, + .CreateContext = radeonCreateContext, + .DestroyContext = radeonDestroyContext, + .CreateBuffer = radeonCreateBuffer, + .DestroyBuffer = radeonDestroyBuffer, + .SwapBuffers = radeonSwapBuffers, + .MakeCurrent = radeonMakeCurrent, + .UnbindContext = radeonUnbindContext, + .GetSwapInfo = getSwapInfo, + .GetDrawableMSC = driDrawableGetMSC32, + .WaitForMSC = driWaitForMSC32, + .WaitForSBC = NULL, + .SwapBuffersMSC = NULL, + .CopySubBuffer = radeonCopySubBuffer, +}; +#else +const struct __DriverAPIRec driDriverAPI = { + .InitScreen = radeonInitScreen, + .DestroyScreen = radeonDestroyScreen, + .CreateContext = r200CreateContext, + .DestroyContext = r200DestroyContext, + .CreateBuffer = radeonCreateBuffer, + .DestroyBuffer = radeonDestroyBuffer, + .SwapBuffers = r200SwapBuffers, + .MakeCurrent = r200MakeCurrent, + .UnbindContext = r200UnbindContext, + .GetSwapInfo = getSwapInfo, + .GetDrawableMSC = driDrawableGetMSC32, + .WaitForMSC = driWaitForMSC32, + .WaitForSBC = NULL, + .SwapBuffersMSC = NULL, + .CopySubBuffer = r200CopySubBuffer, +}; +#endif diff --git a/src/mesa/drivers/dri/s3v/s3v_xmesa.c b/src/mesa/drivers/dri/s3v/s3v_xmesa.c index 7b0b006b695..663dabdb914 100644 --- a/src/mesa/drivers/dri/s3v/s3v_xmesa.c +++ b/src/mesa/drivers/dri/s3v/s3v_xmesa.c @@ -17,8 +17,8 @@ /* #define DEBUG(str) printf str */ -static GLboolean -s3vInitDriver(__DRIscreenPrivate *sPriv) +static const __DRIconfig ** +s3vInitScreen(__DRIscreen *sPriv) { sPriv->private = (void *) s3vCreateScreen( sPriv ); @@ -27,7 +27,7 @@ s3vInitDriver(__DRIscreenPrivate *sPriv) return GL_FALSE; } - return GL_TRUE; + return NULL; } static void @@ -327,36 +327,14 @@ s3vUnbindContext( __DRIcontextPrivate *driContextPriv ) return GL_TRUE; } - -static struct __DriverAPIRec s3vAPI = { - s3vDestroyScreen, - s3vCreateContext, - s3vDestroyContext, - s3vCreateBuffer, - s3vDestroyBuffer, - s3vSwapBuffers, - s3vMakeCurrent, - s3vUnbindContext, +const struct __DriverAPIRec driDriverAPI = { + .InitScreen = s3vInitScreen, + .DestroyScreen = s3vDestroyScreen, + .CreateContext = s3vCreateContext, + .DestroyContext = s3vDestroyContext, + .CreateBuffer = s3vCreateBuffer, + .DestroyBuffer = s3vDestroyBuffer, + .SwapBuffers = s3vSwapBuffers, + .MakeCurrent = s3vMakeCurrent, + .UnbindContext = s3vUnbindContext, }; - - -#if 0 -/* - * This is the bootstrap function for the driver. - * The __driCreateScreen name is the symbol that libGL.so fetches. - * Return: pointer to a __DRIscreenPrivate. - */ -void *__driCreateScreen(Display *dpy, int scrn, __DRIscreen *psc, - int numConfigs, __GLXvisualConfig *config) -{ - __DRIscreenPrivate *psp=NULL; - - DEBUG(("__driCreateScreen: psp = %p\n", psp)); - psp = __driUtilCreateScreen(dpy, scrn, psc, numConfigs, config, &s3vAPI); - DEBUG(("__driCreateScreen: psp = %p\n", psp)); - if (!s3vInitDriver(psp)) - return NULLL - - return (void *) psp; -} -#endif diff --git a/src/mesa/drivers/dri/savage/savage_xmesa.c b/src/mesa/drivers/dri/savage/savage_xmesa.c index 0773fa893a4..6f1cbd6951c 100644 --- a/src/mesa/drivers/dri/savage/savage_xmesa.c +++ b/src/mesa/drivers/dri/savage/savage_xmesa.c @@ -168,12 +168,12 @@ static const struct tnl_pipeline_stage *savage_pipeline[] = { }; -static const __DRIextension *savageExtensions[] = { +PUBLIC const __DRIextension *savageScreenExtensions[] = { + &driCoreExtension.base, + &driLegacyExtension.base, &driReadDrawableExtension, }; -/* this is first function called in dirver*/ - static GLboolean savageInitDriver(__DRIscreenPrivate *sPriv) { @@ -266,7 +266,7 @@ savageInitDriver(__DRIscreenPrivate *sPriv) driParseOptionInfo (&savageScreen->optionCache, __driConfigOptions, __driNConfigOptions); - sPriv->extensions = savageExtensions; + sPriv->extensions = savageScreenExtensions; #if 0 savageDDFastPathInit(); @@ -293,34 +293,6 @@ savageDestroyScreen(__DRIscreenPrivate *sPriv) sPriv->private = NULL; } -#if 0 -GLvisual *XMesaCreateVisual(Display *dpy, - __DRIscreenPrivate *driScrnPriv, - const XVisualInfo *visinfo, - const __GLXvisualConfig *config) -{ - /* Drivers may change the args to _mesa_create_visual() in order to - * setup special visuals. - */ - return _mesa_create_visual( config->rgba, - config->doubleBuffer, - config->stereo, - _mesa_bitcount(visinfo->red_mask), - _mesa_bitcount(visinfo->green_mask), - _mesa_bitcount(visinfo->blue_mask), - config->alphaSize, - 0, /* index bits */ - config->depthSize, - config->stencilSize, - config->accumRedSize, - config->accumGreenSize, - config->accumBlueSize, - config->accumAlphaSize, - 0 /* num samples */ ); -} -#endif - - static GLboolean savageCreateContext( const __GLcontextModes *mesaVis, __DRIcontextPrivate *driContextPriv, @@ -915,32 +887,18 @@ void savageGetLock( savageContextPtr imesa, GLuint flags ) } } - - -static const struct __DriverAPIRec savageAPI = { - savageDestroyScreen, - savageCreateContext, - savageDestroyContext, - savageCreateBuffer, - savageDestroyBuffer, - savageSwapBuffers, - savageMakeCurrent, - savageUnbindContext -}; - - -static __GLcontextModes * +static const __DRIconfig ** savageFillInModes( __DRIscreenPrivate *psp, unsigned pixel_bits, unsigned depth_bits, unsigned stencil_bits, GLboolean have_back_buffer ) { - __GLcontextModes * modes; + __DRIconfig **configs; __GLcontextModes * m; - unsigned num_modes; unsigned depth_buffer_factor; unsigned back_buffer_factor; GLenum fb_format; GLenum fb_type; + int i; /* Right now GLX_SWAP_COPY_OML isn't supported, but it would be easy * enough to add support. Basically, if a context is created with an @@ -971,8 +929,6 @@ savageFillInModes( __DRIscreenPrivate *psp, depth_buffer_factor = ((depth_bits != 0) || (stencil_bits != 0)) ? 2 : 1; back_buffer_factor = (have_back_buffer) ? 2 : 1; - num_modes = depth_buffer_factor * back_buffer_factor * 4; - if ( pixel_bits == 16 ) { fb_format = GL_RGB; fb_type = GL_UNSIGNED_SHORT_5_6_5; @@ -982,21 +938,11 @@ savageFillInModes( __DRIscreenPrivate *psp, fb_type = GL_UNSIGNED_INT_8_8_8_8_REV; } - modes = (*psp->contextModes->createContextModes)( num_modes, sizeof( __GLcontextModes ) ); - m = modes; - if ( ! driFillInModes( & m, fb_format, fb_type, - depth_bits_array, stencil_bits_array, depth_buffer_factor, - back_buffer_modes, back_buffer_factor, - GLX_TRUE_COLOR ) ) { - fprintf( stderr, "[%s:%u] Error creating FBConfig!\n", - __func__, __LINE__ ); - return NULL; - } - - if ( ! driFillInModes( & m, fb_format, fb_type, - depth_bits_array, stencil_bits_array, depth_buffer_factor, - back_buffer_modes, back_buffer_factor, - GLX_DIRECT_COLOR ) ) { + configs = driCreateConfigs(fb_format, fb_type, + depth_bits_array, stencil_bits_array, + depth_buffer_factor, + back_buffer_modes, back_buffer_factor); + if (configs == NULL) { fprintf( stderr, "[%s:%u] Error creating FBConfig!\n", __func__, __LINE__ ); return NULL; @@ -1004,13 +950,14 @@ savageFillInModes( __DRIscreenPrivate *psp, /* Mark the visual as slow if there are "fake" stencil bits. */ - for ( m = modes ; m != NULL ; m = m->next ) { - if ( (m->stencilBits != 0) && (m->stencilBits != stencil_bits) ) { + for (i = 0; configs[i]; i++) { + m = &configs[i]->modes; + if ((m->stencilBits != 0) && (m->stencilBits != stencil_bits)) { m->visualRating = GLX_SLOW_CONFIG; } } - return modes; + return (const __DRIconfig **) configs; } @@ -1021,7 +968,8 @@ savageFillInModes( __DRIscreenPrivate *psp, * * \return the __GLcontextModes supported by this driver */ -__GLcontextModes *__driDriverInitScreen(__DRIscreenPrivate *psp) +static const __DRIconfig ** +savageInitScreen(__DRIscreenPrivate *psp) { static const __DRIversion ddx_expected = { 2, 0, 0 }; static const __DRIversion dri_expected = { 4, 0, 0 }; @@ -1034,8 +982,6 @@ __GLcontextModes *__driDriverInitScreen(__DRIscreenPrivate *psp) &psp->drm_version, & drm_expected ) ) return NULL; - psp->DriverAPI = savageAPI; - /* Calling driInitExtensions here, with a NULL context pointer, * does not actually enable the extensions. It just makes sure * that all the dispatch offsets for all the extensions that @@ -1057,3 +1003,15 @@ __GLcontextModes *__driDriverInitScreen(__DRIscreenPrivate *psp) (dri_priv->cpp == 2) ? 0 : 8, (dri_priv->backOffset != dri_priv->depthOffset) ); } + +const struct __DriverAPIRec driDriverAPI = { + savageInitScreen, + savageDestroyScreen, + savageCreateContext, + savageDestroyContext, + savageCreateBuffer, + savageDestroyBuffer, + savageSwapBuffers, + savageMakeCurrent, + savageUnbindContext +}; diff --git a/src/mesa/drivers/dri/sis/sis_screen.c b/src/mesa/drivers/dri/sis/sis_screen.c index ad2fe51e448..bf0b1ce2767 100644 --- a/src/mesa/drivers/dri/sis/sis_screen.c +++ b/src/mesa/drivers/dri/sis/sis_screen.c @@ -65,12 +65,10 @@ static const GLuint __driNConfigOptions = 3; extern const struct dri_extension card_extensions[]; -static __GLcontextModes * +static const __DRIconfig ** sisFillInModes(__DRIscreenPrivate *psp, int bpp) { - __GLcontextModes *modes; - __GLcontextModes *m; - unsigned num_modes; + __DRIconfig **configs; unsigned depth_buffer_factor; unsigned back_buffer_factor; GLenum fb_format; @@ -93,9 +91,6 @@ sisFillInModes(__DRIscreenPrivate *psp, int bpp) depth_buffer_factor = 4; back_buffer_factor = 2; - /* Last 4 is for GLX_TRUE_COLOR & GLX_DIRECT_COLOR, with/without accum */ - num_modes = depth_buffer_factor * back_buffer_factor * 4; - if (bpp == 16) { fb_format = GL_RGB; fb_type = GL_UNSIGNED_SHORT_5_6_5; @@ -104,25 +99,15 @@ sisFillInModes(__DRIscreenPrivate *psp, int bpp) fb_type = GL_UNSIGNED_INT_8_8_8_8_REV; } - modes = (*psp->contextModes->createContextModes)(num_modes, sizeof(__GLcontextModes)); - m = modes; - if (!driFillInModes(&m, fb_format, fb_type, depth_bits_array, - stencil_bits_array, depth_buffer_factor, - back_buffer_modes, back_buffer_factor, - GLX_TRUE_COLOR)) { + configs = driCreateConfigs(fb_format, fb_type, depth_bits_array, + stencil_bits_array, depth_buffer_factor, + back_buffer_modes, back_buffer_factor); + if (configs == NULL) { fprintf(stderr, "[%s:%u] Error creating FBConfig!\n", __func__, __LINE__); return NULL; } - if (!driFillInModes(&m, fb_format, fb_type, depth_bits_array, - stencil_bits_array, depth_buffer_factor, - back_buffer_modes, back_buffer_factor, - GLX_DIRECT_COLOR)) { - fprintf(stderr, "[%s:%u] Error creating FBConfig!\n", __func__, __LINE__); - return NULL; - } - - return modes; + return (const __DRIconfig **) configs; } @@ -288,39 +273,6 @@ sisSwapBuffers(__DRIdrawablePrivate *dPriv) } -/* Initialize the driver specific screen private data. - */ -static GLboolean -sisInitDriver( __DRIscreenPrivate *sPriv ) -{ - sPriv->private = (void *) sisCreateScreen( sPriv ); - - if ( !sPriv->private ) { - sisDestroyScreen( sPriv ); - return GL_FALSE; - } - - return GL_TRUE; -} - -static struct __DriverAPIRec sisAPI = { - .DestroyScreen = sisDestroyScreen, - .CreateContext = sisCreateContext, - .DestroyContext = sisDestroyContext, - .CreateBuffer = sisCreateBuffer, - .DestroyBuffer = sisDestroyBuffer, - .SwapBuffers = sisSwapBuffers, - .MakeCurrent = sisMakeCurrent, - .UnbindContext = sisUnbindContext, - .GetSwapInfo = NULL, - .GetDrawableMSC = NULL, - .WaitForMSC = NULL, - .WaitForSBC = NULL, - .SwapBuffersMSC = NULL - -}; - - /** * This is the driver specific part of the createNewScreen entry point. * @@ -328,7 +280,8 @@ static struct __DriverAPIRec sisAPI = { * * \return the __GLcontextModes supported by this driver */ -__GLcontextModes *__driDriverInitScreen(__DRIscreenPrivate *psp) +static const __DRIconfig ** +sisInitScreen(__DRIscreenPrivate *psp) { static const __DRIversion ddx_expected = {0, 8, 0}; static const __DRIversion dri_expected = {4, 0, 0}; @@ -342,8 +295,6 @@ __GLcontextModes *__driDriverInitScreen(__DRIscreenPrivate *psp) &psp->drm_version, &drm_expected)) return NULL; - psp->DriverAPI = sisAPI; - /* Calling driInitExtensions here, with a NULL context pointer, * does not actually enable the extensions. It just makes sure * that all the dispatch offsets for all the extensions that @@ -356,8 +307,30 @@ __GLcontextModes *__driDriverInitScreen(__DRIscreenPrivate *psp) */ driInitExtensions( NULL, card_extensions, GL_FALSE ); - if (!sisInitDriver(psp)) - return NULL; + psp->private = sisCreateScreen(psp); + + if (!psp->private) { + sisDestroyScreen(psp); + return NULL; + } return sisFillInModes(psp, dri_priv->bytesPerPixel * 8); } + +const struct __DriverAPIRec driDriverAPI = { + .InitScreen = sisInitScreen, + .DestroyScreen = sisDestroyScreen, + .CreateContext = sisCreateContext, + .DestroyContext = sisDestroyContext, + .CreateBuffer = sisCreateBuffer, + .DestroyBuffer = sisDestroyBuffer, + .SwapBuffers = sisSwapBuffers, + .MakeCurrent = sisMakeCurrent, + .UnbindContext = sisUnbindContext, + .GetSwapInfo = NULL, + .GetDrawableMSC = NULL, + .WaitForMSC = NULL, + .WaitForSBC = NULL, + .SwapBuffersMSC = NULL + +}; diff --git a/src/mesa/drivers/dri/tdfx/tdfx_screen.c b/src/mesa/drivers/dri/tdfx/tdfx_screen.c index 9c7ded0180f..fd21d8d51b4 100644 --- a/src/mesa/drivers/dri/tdfx/tdfx_screen.c +++ b/src/mesa/drivers/dri/tdfx/tdfx_screen.c @@ -343,31 +343,14 @@ tdfxSwapBuffers( __DRIdrawablePrivate *driDrawPriv ) } } - -static const struct __DriverAPIRec tdfxAPI = { - .DestroyScreen = tdfxDestroyScreen, - .CreateContext = tdfxCreateContext, - .DestroyContext = tdfxDestroyContext, - .CreateBuffer = tdfxCreateBuffer, - .DestroyBuffer = tdfxDestroyBuffer, - .SwapBuffers = tdfxSwapBuffers, - .MakeCurrent = tdfxMakeCurrent, - .UnbindContext = tdfxUnbindContext, - .GetSwapInfo = NULL, - .GetDrawableMSC = NULL, - .WaitForMSC = NULL, - .WaitForSBC = NULL, - .SwapBuffersMSC = NULL -}; - - -static __GLcontextModes *tdfxFillInModes(__DRIscreenPrivate *psp, - unsigned pixel_bits, - unsigned depth_bits, - unsigned stencil_bits, - GLboolean have_back_buffer) +static const __DRIconfig ** +tdfxFillInModes(__DRIscreenPrivate *psp, + unsigned pixel_bits, + unsigned depth_bits, + unsigned stencil_bits, + GLboolean have_back_buffer) { - __GLcontextModes *modes; + __DRIconfig **configs, **c; __GLcontextModes *m; unsigned num_modes; unsigned vis[2] = { GLX_TRUE_COLOR, GLX_DIRECT_COLOR }; @@ -382,14 +365,16 @@ static __GLcontextModes *tdfxFillInModes(__DRIscreenPrivate *psp, num_modes = (depth_bits == 16) ? 32 : 16; - modes = (*psp->contextModes->createContextModes)(num_modes, sizeof(__GLcontextModes)); - m = modes; + configs = _mesa_malloc(num_modes * sizeof *configs); + c = configs; for (i = 0; i <= 1; i++) { for (db = 0; db <= 1; db++) { for (depth = 0; depth <= 1; depth++) { for (accum = 0; accum <= 1; accum++) { for (stencil = 0; stencil <= !deep; stencil++) { + *c = _mesa_malloc(sizeof **c); + m = &(*c++)->modes; if (deep) stencil = depth; m->redBits = deep ? 8 : 5; m->greenBits = deep ? 8 : 6; @@ -419,7 +404,6 @@ static __GLcontextModes *tdfxFillInModes(__DRIscreenPrivate *psp, m->visualRating = ((stencil && !deep) || accum) ? GLX_SLOW_CONFIG : GLX_NONE; - m = m->next; if (deep) stencil = 0; } } @@ -427,7 +411,7 @@ static __GLcontextModes *tdfxFillInModes(__DRIscreenPrivate *psp, } } - return modes; + return (const __DRIconfig **) configs; } /** @@ -437,7 +421,8 @@ static __GLcontextModes *tdfxFillInModes(__DRIscreenPrivate *psp, * * \return the __GLcontextModes supported by this driver */ -__GLcontextModes *__driDriverInitScreen(__DRIscreenPrivate *psp) +static const __DRIconfig ** +tdfxInitScreen(__DRIscreen *psp) { static const __DRIversion ddx_expected = { 1, 1, 0 }; static const __DRIversion dri_expected = { 4, 0, 0 }; @@ -456,8 +441,6 @@ __GLcontextModes *__driDriverInitScreen(__DRIscreenPrivate *psp) &psp->drm_version, & drm_expected ) ) return NULL; - psp->DriverAPI = tdfxAPI; - /* Calling driInitExtensions here, with a NULL context pointer, * does not actually enable the extensions. It just makes sure * that all the dispatch offsets for all the extensions that @@ -479,3 +462,20 @@ __GLcontextModes *__driDriverInitScreen(__DRIscreenPrivate *psp) (bpp == 16) ? 0 : 8, (dri_priv->backOffset!=dri_priv->depthOffset)); } + +const struct __DriverAPIRec driDriverAPI = { + .InitScreen = tdfxInitScreen, + .DestroyScreen = tdfxDestroyScreen, + .CreateContext = tdfxCreateContext, + .DestroyContext = tdfxDestroyContext, + .CreateBuffer = tdfxCreateBuffer, + .DestroyBuffer = tdfxDestroyBuffer, + .SwapBuffers = tdfxSwapBuffers, + .MakeCurrent = tdfxMakeCurrent, + .UnbindContext = tdfxUnbindContext, + .GetSwapInfo = NULL, + .GetDrawableMSC = NULL, + .WaitForMSC = NULL, + .WaitForSBC = NULL, + .SwapBuffersMSC = NULL +}; diff --git a/src/mesa/drivers/dri/trident/trident_context.c b/src/mesa/drivers/dri/trident/trident_context.c index 81098bc9cdf..2b6d19c4a57 100644 --- a/src/mesa/drivers/dri/trident/trident_context.c +++ b/src/mesa/drivers/dri/trident/trident_context.c @@ -417,18 +417,6 @@ tridentInitDriver(__DRIscreenPrivate *sPriv) return GL_TRUE; } -static struct __DriverAPIRec tridentAPI = { - tridentDestroyScreen, - tridentCreateContext, - tridentDestroyContext, - tridentCreateBuffer, - tridentDestroyBuffer, - tridentSwapBuffers, - tridentMakeCurrent, - tridentUnbindContext, -}; - - /** * This is the driver specific part of the createNewScreen entry point. * @@ -436,7 +424,7 @@ static struct __DriverAPIRec tridentAPI = { * * \return the __GLcontextModes supported by this driver */ -__GLcontextModes *__driDriverInitScreen(__DRIscreenPrivate *psp) +const __DRIconfig **tridentInitScreen(__DRIscreenPrivate *psp) { static const __DRIversion ddx_expected = { 4, 0, 0 }; static const __DRIversion dri_expected = { 3, 1, 0 }; @@ -448,8 +436,6 @@ __GLcontextModes *__driDriverInitScreen(__DRIscreenPrivate *psp) &psp->drm_version, & drm_expected ) ) return NULL; - psp->DriverAPI = tridentAPI; - if (!tridentInitDriver(psp)) return NULL; @@ -462,3 +448,15 @@ __GLcontextModes *__driDriverInitScreen(__DRIscreenPrivate *psp) return NULL; } + +const struct __DriverAPIRec driDriverAPI = { + tridentInitScreen, + tridentDestroyScreen, + tridentCreateContext, + tridentDestroyContext, + tridentCreateBuffer, + tridentDestroyBuffer, + tridentSwapBuffers, + tridentMakeCurrent, + tridentUnbindContext, +}; diff --git a/src/mesa/drivers/dri/unichrome/via_screen.c b/src/mesa/drivers/dri/unichrome/via_screen.c index faf6505bfd9..ca193bfa538 100644 --- a/src/mesa/drivers/dri/unichrome/via_screen.c +++ b/src/mesa/drivers/dri/unichrome/via_screen.c @@ -64,8 +64,6 @@ static const GLuint __driNConfigOptions = 3; extern const struct dri_extension card_extensions[]; -static int getSwapInfo( __DRIdrawablePrivate *dPriv, __DRIswapInfo * sInfo ); - static drmBufMapPtr via_create_empty_buffers(void) { drmBufMapPtr retval; @@ -321,32 +319,11 @@ viaDestroyBuffer(__DRIdrawablePrivate *driDrawPriv) _mesa_unreference_framebuffer((GLframebuffer **)(&(driDrawPriv->driverPrivate))); } - - -static struct __DriverAPIRec viaAPI = { - .DestroyScreen = viaDestroyScreen, - .CreateContext = viaCreateContext, - .DestroyContext = viaDestroyContext, - .CreateBuffer = viaCreateBuffer, - .DestroyBuffer = viaDestroyBuffer, - .SwapBuffers = viaSwapBuffers, - .MakeCurrent = viaMakeCurrent, - .UnbindContext = viaUnbindContext, - .GetSwapInfo = getSwapInfo, - .GetDrawableMSC = driDrawableGetMSC32, - .WaitForMSC = driWaitForMSC32, - .WaitForSBC = NULL, - .SwapBuffersMSC = NULL -}; - - -static __GLcontextModes * +static const __DRIconfig ** viaFillInModes( __DRIscreenPrivate *psp, unsigned pixel_bits, GLboolean have_back_buffer ) { - __GLcontextModes * modes; - __GLcontextModes * m; - unsigned num_modes; + __DRIconfig **configs; const unsigned back_buffer_factor = (have_back_buffer) ? 2 : 1; GLenum fb_format; GLenum fb_type; @@ -367,9 +344,6 @@ viaFillInModes( __DRIscreenPrivate *psp, static const u_int8_t stencil_bits_array[4] = { 0, 0, 8, 0 }; const unsigned depth_buffer_factor = 3; - - num_modes = depth_buffer_factor * back_buffer_factor * 4; - if ( pixel_bits == 16 ) { fb_format = GL_RGB; fb_type = GL_UNSIGNED_SHORT_5_6_5; @@ -379,29 +353,17 @@ viaFillInModes( __DRIscreenPrivate *psp, fb_type = GL_UNSIGNED_INT_8_8_8_8_REV; } - modes = (*psp->contextModes->createContextModes)( num_modes, sizeof( __GLcontextModes ) ); - m = modes; - if ( ! driFillInModes( & m, fb_format, fb_type, - depth_bits_array, stencil_bits_array, - depth_buffer_factor, - back_buffer_modes, back_buffer_factor, - GLX_TRUE_COLOR ) ) { - fprintf( stderr, "[%s:%u] Error creating FBConfig!\n", - __func__, __LINE__ ); + configs = driCreateConfigs(fb_format, fb_type, + depth_bits_array, stencil_bits_array, + depth_buffer_factor, back_buffer_modes, + back_buffer_factor); + if (configs == NULL) { + fprintf(stderr, "[%s:%u] Error creating FBConfig!\n", __func__, + __LINE__); return NULL; } - if ( ! driFillInModes( & m, fb_format, fb_type, - depth_bits_array, stencil_bits_array, - depth_buffer_factor, - back_buffer_modes, back_buffer_factor, - GLX_DIRECT_COLOR ) ) { - fprintf( stderr, "[%s:%u] Error creating FBConfig!\n", - __func__, __LINE__ ); - return NULL; - } - - return modes; + return (const __DRIconfig **) configs; } @@ -412,7 +374,8 @@ viaFillInModes( __DRIscreenPrivate *psp, * * \return the __GLcontextModes supported by this driver */ -__GLcontextModes *__driDriverInitScreen(__DRIscreenPrivate *psp) +static const __DRIconfig ** +viaInitScreen(__DRIscreenPrivate *psp) { static const __DRIversion ddx_expected = { VIA_DRIDDX_VERSION_MAJOR, VIA_DRIDDX_VERSION_MINOR, @@ -428,8 +391,6 @@ __GLcontextModes *__driDriverInitScreen(__DRIscreenPrivate *psp) &psp->drm_version, & drm_expected) ) return NULL; - psp->DriverAPI = viaAPI; - /* Calling driInitExtensions here, with a NULL context pointer, * does not actually enable the extensions. It just makes sure * that all the dispatch offsets for all the extensions that @@ -475,3 +436,20 @@ getSwapInfo( __DRIdrawablePrivate *dPriv, __DRIswapInfo * sInfo ) return 0; } + +const struct __DriverAPIRec driDriverAPI = { + .InitScreen = viaInitScreen, + .DestroyScreen = viaDestroyScreen, + .CreateContext = viaCreateContext, + .DestroyContext = viaDestroyContext, + .CreateBuffer = viaCreateBuffer, + .DestroyBuffer = viaDestroyBuffer, + .SwapBuffers = viaSwapBuffers, + .MakeCurrent = viaMakeCurrent, + .UnbindContext = viaUnbindContext, + .GetSwapInfo = getSwapInfo, + .GetDrawableMSC = driDrawableGetMSC32, + .WaitForMSC = driWaitForMSC32, + .WaitForSBC = NULL, + .SwapBuffersMSC = NULL +}; |