glx: indent -br -i3 -npcs --no-tabs dri2_glx.c

This commit is contained in:
RALOVICH, Kristóf 2008-10-13 13:17:32 +02:00 committed by Brian Paul
parent 66cc150770
commit bca6e79a45
1 changed files with 222 additions and 211 deletions

View File

@ -51,292 +51,302 @@ typedef struct __GLXDRIdisplayPrivateRec __GLXDRIdisplayPrivate;
typedef struct __GLXDRIcontextPrivateRec __GLXDRIcontextPrivate; typedef struct __GLXDRIcontextPrivateRec __GLXDRIcontextPrivate;
typedef struct __GLXDRIdrawablePrivateRec __GLXDRIdrawablePrivate; typedef struct __GLXDRIdrawablePrivateRec __GLXDRIdrawablePrivate;
struct __GLXDRIdisplayPrivateRec { struct __GLXDRIdisplayPrivateRec
__GLXDRIdisplay base; {
__GLXDRIdisplay base;
/* /*
** XFree86-DRI version information ** XFree86-DRI version information
*/ */
int driMajor; int driMajor;
int driMinor; int driMinor;
int driPatch; int driPatch;
}; };
struct __GLXDRIcontextPrivateRec { struct __GLXDRIcontextPrivateRec
__GLXDRIcontext base; {
__DRIcontext *driContext; __GLXDRIcontext base;
__GLXscreenConfigs *psc; __DRIcontext *driContext;
__GLXscreenConfigs *psc;
}; };
struct __GLXDRIdrawablePrivateRec { struct __GLXDRIdrawablePrivateRec
__GLXDRIdrawable base; {
__DRIbuffer buffers[5]; __GLXDRIdrawable base;
int bufferCount; __DRIbuffer buffers[5];
int width, height; int bufferCount;
int width, height;
}; };
static void dri2DestroyContext(__GLXDRIcontext *context, static void
__GLXscreenConfigs *psc, Display *dpy) dri2DestroyContext(__GLXDRIcontext * context,
__GLXscreenConfigs * psc, Display * dpy)
{ {
__GLXDRIcontextPrivate *pcp = (__GLXDRIcontextPrivate *) context; __GLXDRIcontextPrivate *pcp = (__GLXDRIcontextPrivate *) context;
const __DRIcoreExtension *core = pcp->psc->core; const __DRIcoreExtension *core = pcp->psc->core;
(*core->destroyContext)(pcp->driContext); (*core->destroyContext) (pcp->driContext);
Xfree(pcp); Xfree(pcp);
} }
static Bool dri2BindContext(__GLXDRIcontext *context, static Bool
__GLXDRIdrawable *draw, __GLXDRIdrawable *read) dri2BindContext(__GLXDRIcontext * context,
__GLXDRIdrawable * draw, __GLXDRIdrawable * read)
{ {
__GLXDRIcontextPrivate *pcp = (__GLXDRIcontextPrivate *) context; __GLXDRIcontextPrivate *pcp = (__GLXDRIcontextPrivate *) context;
const __DRIcoreExtension *core = pcp->psc->core; const __DRIcoreExtension *core = pcp->psc->core;
return (*core->bindContext)(pcp->driContext, return (*core->bindContext) (pcp->driContext,
draw->driDrawable, draw->driDrawable, read->driDrawable);
read->driDrawable);
} }
static void dri2UnbindContext(__GLXDRIcontext *context) static void
dri2UnbindContext(__GLXDRIcontext * context)
{ {
__GLXDRIcontextPrivate *pcp = (__GLXDRIcontextPrivate *) context; __GLXDRIcontextPrivate *pcp = (__GLXDRIcontextPrivate *) context;
const __DRIcoreExtension *core = pcp->psc->core; const __DRIcoreExtension *core = pcp->psc->core;
(*core->unbindContext)(pcp->driContext); (*core->unbindContext) (pcp->driContext);
} }
static __GLXDRIcontext *dri2CreateContext(__GLXscreenConfigs *psc, static __GLXDRIcontext *
const __GLcontextModes *mode, dri2CreateContext(__GLXscreenConfigs * psc,
GLXContext gc, const __GLcontextModes * mode,
GLXContext shareList, int renderType) GLXContext gc, GLXContext shareList, int renderType)
{ {
__GLXDRIcontextPrivate *pcp, *pcp_shared; __GLXDRIcontextPrivate *pcp, *pcp_shared;
__GLXDRIconfigPrivate *config = (__GLXDRIconfigPrivate *) mode; __GLXDRIconfigPrivate *config = (__GLXDRIconfigPrivate *) mode;
__DRIcontext *shared = NULL; __DRIcontext *shared = NULL;
if (shareList) { if (shareList) {
pcp_shared = (__GLXDRIcontextPrivate *) shareList->driContext; pcp_shared = (__GLXDRIcontextPrivate *) shareList->driContext;
shared = pcp_shared->driContext; shared = pcp_shared->driContext;
} }
pcp = Xmalloc(sizeof *pcp); pcp = Xmalloc(sizeof *pcp);
if (pcp == NULL) if (pcp == NULL)
return NULL; return NULL;
pcp->psc = psc; pcp->psc = psc;
pcp->driContext = pcp->driContext =
(*psc->dri2->createNewContext)(psc->__driScreen, (*psc->dri2->createNewContext) (psc->__driScreen,
config->driConfig, shared, pcp); config->driConfig, shared, pcp);
gc->__driContext = pcp->driContext; gc->__driContext = pcp->driContext;
if (pcp->driContext == NULL) { if (pcp->driContext == NULL) {
Xfree(pcp); Xfree(pcp);
return NULL; return NULL;
} }
pcp->base.destroyContext = dri2DestroyContext; pcp->base.destroyContext = dri2DestroyContext;
pcp->base.bindContext = dri2BindContext; pcp->base.bindContext = dri2BindContext;
pcp->base.unbindContext = dri2UnbindContext; pcp->base.unbindContext = dri2UnbindContext;
return &pcp->base; return &pcp->base;
} }
static void dri2DestroyDrawable(__GLXDRIdrawable *pdraw) static void
dri2DestroyDrawable(__GLXDRIdrawable * pdraw)
{ {
const __DRIcoreExtension *core = pdraw->psc->core; const __DRIcoreExtension *core = pdraw->psc->core;
(*core->destroyDrawable)(pdraw->driDrawable); (*core->destroyDrawable) (pdraw->driDrawable);
DRI2DestroyDrawable(pdraw->psc->dpy, pdraw->drawable); DRI2DestroyDrawable(pdraw->psc->dpy, pdraw->drawable);
Xfree(pdraw); Xfree(pdraw);
} }
static __GLXDRIdrawable *dri2CreateDrawable(__GLXscreenConfigs *psc, static __GLXDRIdrawable *
XID xDrawable, dri2CreateDrawable(__GLXscreenConfigs * psc,
GLXDrawable drawable, XID xDrawable,
const __GLcontextModes *modes) GLXDrawable drawable, const __GLcontextModes * modes)
{ {
__GLXDRIdrawablePrivate *pdraw; __GLXDRIdrawablePrivate *pdraw;
__GLXDRIconfigPrivate *config = (__GLXDRIconfigPrivate *) modes; __GLXDRIconfigPrivate *config = (__GLXDRIconfigPrivate *) modes;
pdraw = Xmalloc(sizeof(*pdraw)); pdraw = Xmalloc(sizeof(*pdraw));
if (!pdraw) if (!pdraw)
return NULL; return NULL;
pdraw->base.destroyDrawable = dri2DestroyDrawable; pdraw->base.destroyDrawable = dri2DestroyDrawable;
pdraw->base.xDrawable = xDrawable; pdraw->base.xDrawable = xDrawable;
pdraw->base.drawable = drawable; pdraw->base.drawable = drawable;
pdraw->base.psc = psc; pdraw->base.psc = psc;
DRI2CreateDrawable(psc->dpy, xDrawable); DRI2CreateDrawable(psc->dpy, xDrawable);
/* Create a new drawable */ /* Create a new drawable */
pdraw->base.driDrawable = pdraw->base.driDrawable =
(*psc->dri2->createNewDrawable)(psc->__driScreen, (*psc->dri2->createNewDrawable) (psc->__driScreen,
config->driConfig, pdraw); config->driConfig, pdraw);
if (!pdraw->base.driDrawable) { if (!pdraw->base.driDrawable) {
DRI2DestroyDrawable(psc->dpy, drawable); DRI2DestroyDrawable(psc->dpy, drawable);
Xfree(pdraw); Xfree(pdraw);
return NULL; return NULL;
} }
return &pdraw->base; return &pdraw->base;
} }
static void dri2SwapBuffers(__GLXDRIdrawable *pdraw) static void
dri2SwapBuffers(__GLXDRIdrawable * pdraw)
{ {
__GLXDRIdrawablePrivate *priv = (__GLXDRIdrawablePrivate *) pdraw; __GLXDRIdrawablePrivate *priv = (__GLXDRIdrawablePrivate *) pdraw;
DRI2SwapBuffers(pdraw->psc->dpy, pdraw->drawable, DRI2SwapBuffers(pdraw->psc->dpy, pdraw->drawable,
0, 0, priv->width, priv->height); 0, 0, priv->width, priv->height);
} }
static void dri2DestroyScreen(__GLXscreenConfigs *psc) static void
dri2DestroyScreen(__GLXscreenConfigs * psc)
{ {
/* Free the direct rendering per screen data */ /* Free the direct rendering per screen data */
(*psc->core->destroyScreen)(psc->__driScreen); (*psc->core->destroyScreen) (psc->__driScreen);
drmClose(psc->fd); drmClose(psc->fd);
psc->__driScreen = NULL; psc->__driScreen = NULL;
} }
static __DRIbuffer * static __DRIbuffer *
dri2GetBuffers(__DRIdrawable *driDrawable, dri2GetBuffers(__DRIdrawable * driDrawable,
int *width, int *height, int *width, int *height,
unsigned int *attachments, int count, unsigned int *attachments, int count,
int *out_count, void *loaderPrivate) int *out_count, void *loaderPrivate)
{ {
__GLXDRIdrawablePrivate *pdraw = loaderPrivate; __GLXDRIdrawablePrivate *pdraw = loaderPrivate;
DRI2Buffer *buffers; DRI2Buffer *buffers;
int i; int i;
buffers = DRI2GetBuffers(pdraw->base.psc->dpy, pdraw->base.xDrawable, buffers = DRI2GetBuffers(pdraw->base.psc->dpy, pdraw->base.xDrawable,
width, height, attachments, count, out_count); width, height, attachments, count, out_count);
if (buffers == NULL) if (buffers == NULL)
return NULL; return NULL;
pdraw->width = *width; pdraw->width = *width;
pdraw->height = *height; pdraw->height = *height;
/* This assumes the DRI2 buffer attachment tokens matches the /* This assumes the DRI2 buffer attachment tokens matches the
* __DRIbuffer tokens. */ * __DRIbuffer tokens. */
for (i = 0; i < *out_count; i++) { for (i = 0; i < *out_count; i++) {
pdraw->buffers[i].attachment = buffers[i].attachment; pdraw->buffers[i].attachment = buffers[i].attachment;
pdraw->buffers[i].name = buffers[i].name; pdraw->buffers[i].name = buffers[i].name;
pdraw->buffers[i].pitch = buffers[i].pitch; pdraw->buffers[i].pitch = buffers[i].pitch;
pdraw->buffers[i].cpp = buffers[i].cpp; pdraw->buffers[i].cpp = buffers[i].cpp;
pdraw->buffers[i].flags = buffers[i].flags; pdraw->buffers[i].flags = buffers[i].flags;
} }
Xfree(buffers); Xfree(buffers);
return pdraw->buffers; return pdraw->buffers;
} }
static const __DRIdri2LoaderExtension dri2LoaderExtension = { static const __DRIdri2LoaderExtension dri2LoaderExtension = {
{ __DRI_DRI2_LOADER, __DRI_DRI2_LOADER_VERSION }, {__DRI_DRI2_LOADER, __DRI_DRI2_LOADER_VERSION},
dri2GetBuffers, dri2GetBuffers,
}; };
static const __DRIextension *loader_extensions[] = { static const __DRIextension *loader_extensions[] = {
&dri2LoaderExtension.base, &dri2LoaderExtension.base,
&systemTimeExtension.base, &systemTimeExtension.base,
NULL NULL
}; };
static __GLXDRIscreen *dri2CreateScreen(__GLXscreenConfigs *psc, int screen, static __GLXDRIscreen *
__GLXdisplayPrivate *priv) dri2CreateScreen(__GLXscreenConfigs * psc, int screen,
__GLXdisplayPrivate * priv)
{ {
const __DRIconfig **driver_configs; const __DRIconfig **driver_configs;
const __DRIextension **extensions; const __DRIextension **extensions;
__GLXDRIscreen *psp; __GLXDRIscreen *psp;
unsigned int sareaHandle; unsigned int sareaHandle;
char *driverName, *busID; char *driverName, *busID;
drm_magic_t magic; drm_magic_t magic;
int i; int i;
psp = Xmalloc(sizeof *psp); psp = Xmalloc(sizeof *psp);
if (psp == NULL) if (psp == NULL)
return NULL; return NULL;
/* Initialize per screen dynamic client GLX extensions */ /* Initialize per screen dynamic client GLX extensions */
psc->ext_list_first_time = GL_TRUE; psc->ext_list_first_time = GL_TRUE;
if (!DRI2Connect(psc->dpy, screen, &driverName, &busID, &sareaHandle)) if (!DRI2Connect(psc->dpy, screen, &driverName, &busID, &sareaHandle))
return NULL; return NULL;
psc->driver = driOpenDriver(driverName); psc->driver = driOpenDriver(driverName);
if (psc->driver == NULL) if (psc->driver == NULL)
goto handle_error; goto handle_error;
extensions = dlsym(psc->driver, __DRI_DRIVER_EXTENSIONS); extensions = dlsym(psc->driver, __DRI_DRIVER_EXTENSIONS);
if (extensions == NULL) { if (extensions == NULL) {
ErrorMessageF("driver exports no extensions (%s)\n", dlerror()); ErrorMessageF("driver exports no extensions (%s)\n", dlerror());
goto handle_error; goto handle_error;
} }
for (i = 0; extensions[i]; i++) { for (i = 0; extensions[i]; i++) {
if (strcmp(extensions[i]->name, __DRI_CORE) == 0) if (strcmp(extensions[i]->name, __DRI_CORE) == 0)
psc->core = (__DRIcoreExtension *) extensions[i]; psc->core = (__DRIcoreExtension *) extensions[i];
if (strcmp(extensions[i]->name, __DRI_DRI2) == 0) if (strcmp(extensions[i]->name, __DRI_DRI2) == 0)
psc->dri2 = (__DRIdri2Extension *) extensions[i]; psc->dri2 = (__DRIdri2Extension *) extensions[i];
} }
if (psc->core == NULL || psc->dri2 == NULL) { if (psc->core == NULL || psc->dri2 == NULL) {
ErrorMessageF("core dri or dri2 extension not found\n"); ErrorMessageF("core dri or dri2 extension not found\n");
goto handle_error; goto handle_error;
} }
psc->fd = drmOpen(NULL, busID); psc->fd = drmOpen(NULL, busID);
if (psc->fd < 0) { if (psc->fd < 0) {
ErrorMessageF("failed to open drm device: %s\n", strerror(errno)); ErrorMessageF("failed to open drm device: %s\n", strerror(errno));
return NULL; return NULL;
} }
if (drmGetMagic(psc->fd, &magic)) if (drmGetMagic(psc->fd, &magic))
return NULL; return NULL;
if (!DRI2AuthConnection(psc->dpy, screen, magic)) { if (!DRI2AuthConnection(psc->dpy, screen, magic)) {
ErrorMessageF("failed to authenticate drm access\n"); ErrorMessageF("failed to authenticate drm access\n");
return NULL; return NULL;
} }
psc->__driScreen = psc->__driScreen =
psc->dri2->createNewScreen(screen, psc->fd, psc->dri2->createNewScreen(screen, psc->fd,
loader_extensions, &driver_configs, psc); loader_extensions, &driver_configs, psc);
if (psc->__driScreen == NULL) { if (psc->__driScreen == NULL) {
ErrorMessageF("failed to create dri screen\n"); ErrorMessageF("failed to create dri screen\n");
return NULL; return NULL;
} }
driBindExtensions(psc, 1); driBindExtensions(psc, 1);
psc->configs = driConvertConfigs(psc->core, psc->configs, driver_configs); psc->configs = driConvertConfigs(psc->core, psc->configs, driver_configs);
psc->visuals = driConvertConfigs(psc->core, psc->visuals, driver_configs); psc->visuals = driConvertConfigs(psc->core, psc->visuals, driver_configs);
psp->destroyScreen = dri2DestroyScreen; psp->destroyScreen = dri2DestroyScreen;
psp->createContext = dri2CreateContext; psp->createContext = dri2CreateContext;
psp->createDrawable = dri2CreateDrawable; psp->createDrawable = dri2CreateDrawable;
psp->swapBuffers = dri2SwapBuffers; psp->swapBuffers = dri2SwapBuffers;
Xfree(driverName); Xfree(driverName);
Xfree(busID); Xfree(busID);
return psp; return psp;
handle_error: handle_error:
Xfree(driverName); Xfree(driverName);
Xfree(busID); Xfree(busID);
/* FIXME: clean up here */ /* FIXME: clean up here */
return NULL; return NULL;
} }
/* Called from __glXFreeDisplayPrivate. /* Called from __glXFreeDisplayPrivate.
*/ */
static void dri2DestroyDisplay(__GLXDRIdisplay *dpy) static void
dri2DestroyDisplay(__GLXDRIdisplay * dpy)
{ {
Xfree(dpy); Xfree(dpy);
} }
/* /*
@ -344,29 +354,30 @@ static void dri2DestroyDisplay(__GLXDRIdisplay *dpy)
* This is called from __glXInitialize() when we are given a new * This is called from __glXInitialize() when we are given a new
* display pointer. * display pointer.
*/ */
_X_HIDDEN __GLXDRIdisplay *dri2CreateDisplay(Display *dpy) _X_HIDDEN __GLXDRIdisplay *
dri2CreateDisplay(Display * dpy)
{ {
__GLXDRIdisplayPrivate *pdp; __GLXDRIdisplayPrivate *pdp;
int eventBase, errorBase; int eventBase, errorBase;
if (!DRI2QueryExtension(dpy, &eventBase, &errorBase)) if (!DRI2QueryExtension(dpy, &eventBase, &errorBase))
return NULL; return NULL;
pdp = Xmalloc(sizeof *pdp); pdp = Xmalloc(sizeof *pdp);
if (pdp == NULL) if (pdp == NULL)
return NULL; return NULL;
if (!DRI2QueryVersion(dpy, &pdp->driMajor, &pdp->driMinor)) { if (!DRI2QueryVersion(dpy, &pdp->driMajor, &pdp->driMinor)) {
Xfree(pdp); Xfree(pdp);
return NULL; return NULL;
} }
pdp->driPatch = 0; pdp->driPatch = 0;
pdp->base.destroyDisplay = dri2DestroyDisplay; pdp->base.destroyDisplay = dri2DestroyDisplay;
pdp->base.createScreen = dri2CreateScreen; pdp->base.createScreen = dri2CreateScreen;
return &pdp->base; return &pdp->base;
} }
#endif /* GLX_DIRECT_RENDERING */ #endif /* GLX_DIRECT_RENDERING */