Implement glXCreateWindow and glXDestroyWindow.

This commit is contained in:
Kristian Høgsberg 2006-06-29 04:35:45 -04:00
parent ee012588d2
commit fc1a55671d
2 changed files with 85 additions and 53 deletions

View File

@ -1201,81 +1201,82 @@ int __glXGetFBConfigsSGIX(__GLXclientState *cl, GLbyte *pc)
return DoGetFBConfigs( cl, req->screen, GL_FALSE ); return DoGetFBConfigs( cl, req->screen, GL_FALSE );
} }
static int ValidateCreateDrawable(ClientPtr client,
/* int screenNum, XID fbconfigId,
** Create a GLX Pixmap from an X Pixmap. XID drawablId, XID glxDrawableId,
*/ int type, __GLcontextModes **modes,
int DoCreateGLXPixmap(__GLXclientState *cl, VisualID visual, DrawablePtr *ppDraw)
GLuint screenNum, XID pixmapId, XID glxpixmapId)
{ {
ClientPtr client = cl->client;
DrawablePtr pDraw; DrawablePtr pDraw;
ScreenPtr pScreen; ScreenPtr pScreen;
VisualPtr pVisual; VisualPtr pVisual;
__GLXpixmap *pGlxPixmap;
__GLXscreen *pGlxScreen; __GLXscreen *pGlxScreen;
__GLcontextModes *modes;
int i; int i;
LEGAL_NEW_RESOURCE(glxpixmapId, client); LEGAL_NEW_RESOURCE(glxDrawableId, client);
pDraw = (DrawablePtr) LookupDrawable(pixmapId, client); pDraw = (DrawablePtr) LookupDrawable(drawablId, client);
if (!pDraw || pDraw->type != DRAWABLE_PIXMAP) { if (!pDraw || pDraw->type != type) {
client->errorValue = pixmapId; client->errorValue = drawablId;
return BadPixmap; return type == DRAWABLE_WINDOW ? BadWindow : BadPixmap;
} }
/* /* Check if screen of the fbconfig matches screen of drawable. */
** Check if screen of visual matches screen of pixmap.
*/
pScreen = pDraw->pScreen; pScreen = pDraw->pScreen;
if (screenNum != pScreen->myNum) { if (screenNum != pScreen->myNum) {
return BadMatch; return BadMatch;
} }
/* /* If this fbconfig has a corresponding VisualRec the number of
** Find the VisualRec for this visual. * planes must match the drawable depth. */
*/
pVisual = pScreen->visuals; pVisual = pScreen->visuals;
for (i=0; i < pScreen->numVisuals; i++, pVisual++) { for (i = 0; i < pScreen->numVisuals; i++, pVisual++) {
if (pVisual->vid == visual) { if (pVisual->vid == fbconfigId && pVisual->nplanes != pDraw->depth)
break; return BadMatch;
}
}
if (i == pScreen->numVisuals) {
client->errorValue = visual;
return BadValue;
}
/*
** Check if depth of visual matches depth of pixmap.
*/
if (pVisual->nplanes != pDraw->depth) {
return BadMatch;
} }
/* /* Get configuration of the visual. */
** Get configuration of the visual. pGlxScreen = __glXgetActiveScreen(screenNum);
*/ *modes = _gl_context_modes_find_visual(pGlxScreen->modes, fbconfigId);
pGlxScreen = __glXActiveScreens[screenNum]; if (*modes == NULL) {
modes = _gl_context_modes_find_visual( pGlxScreen->modes, visual ); /* Visual not support on this screen by this OpenGL implementation. */
if (modes == NULL) { client->errorValue = fbconfigId;
/*
** Visual not support on this screen by this OpenGL implementation.
*/
client->errorValue = visual;
return BadValue; return BadValue;
} }
*ppDraw = pDraw;
return Success;
}
/*
** Create a GLX Pixmap from an X Pixmap.
*/
int DoCreateGLXPixmap(__GLXclientState *cl, XID fbconfigId,
GLuint screenNum, XID pixmapId, XID glxPixmapId)
{
ClientPtr client = cl->client;
DrawablePtr pDraw;
__GLXpixmap *pGlxPixmap;
__GLcontextModes *modes;
int retval;
retval = ValidateCreateDrawable (client, screenNum, fbconfigId,
pixmapId, glxPixmapId,
DRAWABLE_PIXMAP, &modes, &pDraw);
if (retval != Success)
return retval;
pGlxPixmap = (__GLXpixmap *) xalloc(sizeof(__GLXpixmap)); pGlxPixmap = (__GLXpixmap *) xalloc(sizeof(__GLXpixmap));
if (!pGlxPixmap) { if (!pGlxPixmap) {
return BadAlloc; return BadAlloc;
} }
if (!(AddResource(glxpixmapId, __glXPixmapRes, pGlxPixmap))) { if (!(AddResource(glxPixmapId, __glXPixmapRes, pGlxPixmap))) {
return BadAlloc; return BadAlloc;
} }
pGlxPixmap->pDraw = pDraw; pGlxPixmap->pDraw = pDraw;
pGlxPixmap->pGlxScreen = pGlxScreen; pGlxPixmap->pGlxScreen = __glXgetActiveScreen(screenNum);
pGlxPixmap->pScreen = pScreen; pGlxPixmap->pScreen = pDraw->pScreen;
pGlxPixmap->idExists = True; pGlxPixmap->idExists = True;
pGlxPixmap->pDamage = NULL; pGlxPixmap->pDamage = NULL;
pGlxPixmap->refcnt = 0; pGlxPixmap->refcnt = 0;
@ -1374,19 +1375,50 @@ int __glXChangeDrawableAttributes(__GLXclientState *cl, GLbyte *pc)
int __glXCreateWindow(__GLXclientState *cl, GLbyte *pc) int __glXCreateWindow(__GLXclientState *cl, GLbyte *pc)
{ {
xGLXCreateWindowReq *req = (xGLXCreateWindowReq *) pc; xGLXCreateWindowReq *req = (xGLXCreateWindowReq *) pc;
ClientPtr client = cl->client;
DrawablePtr pDraw;
__GLXdrawable *glxPriv;
__GLXscreen *screen;
__GLcontextModes *modes;
int retval;
(void) req; retval = ValidateCreateDrawable (client, req->screen, req->fbconfig,
req->window, req->glxwindow,
DRAWABLE_WINDOW, &modes, &pDraw);
if (retval != Success)
return retval;
return BadRequest; /* FIXME: We need to check that the window visual is compatible
* with the specified fbconfig. */
screen = __glXgetActiveScreen(req->screen);
glxPriv = screen->createDrawable(screen, pDraw, req->glxwindow, modes);
if (glxPriv == NULL)
return BadAlloc;
if (!AddResource(req->glxwindow, __glXDrawableRes, glxPriv)) {
glxPriv->destroy (glxPriv);
return BadAlloc;
}
return Success;
} }
int __glXDestroyWindow(__GLXclientState *cl, GLbyte *pc) int __glXDestroyWindow(__GLXclientState *cl, GLbyte *pc)
{ {
xGLXDestroyWindowReq *req = (xGLXDestroyWindowReq *) pc; xGLXDestroyWindowReq *req = (xGLXDestroyWindowReq *) pc;
ClientPtr client = cl->client;
(void) req; /*
** Check if it's a valid GLX window.
*/
if (!LookupIDByType(req->glxwindow, __glXDrawableRes)) {
client->errorValue = req->glxwindow;
return __glXError(GLXBadWindow);
}
FreeResource(req->glxwindow, FALSE);
return BadRequest; return Success;
} }

View File

@ -85,7 +85,7 @@ extern int DoGetFBConfigs(__GLXclientState *cl, unsigned screen,
GLboolean do_swap); GLboolean do_swap);
extern int DoCreateContext(__GLXclientState *cl, GLXContextID gcId, extern int DoCreateContext(__GLXclientState *cl, GLXContextID gcId,
GLXContextID shareList, VisualID visual, GLuint screen, GLboolean isDirect); GLXContextID shareList, VisualID visual, GLuint screen, GLboolean isDirect);
extern int DoCreateGLXPixmap(__GLXclientState *cl, VisualID visual, extern int DoCreateGLXPixmap(__GLXclientState *cl, XID fbconfigId,
GLuint screenNum, XID pixmapId, XID glxpixmapId); GLuint screenNum, XID pixmapId, XID glxpixmapId);
extern int DoDestroyPixmap(__GLXclientState *cl, XID glxpixmapId); extern int DoDestroyPixmap(__GLXclientState *cl, XID glxpixmapId);