2004-04-23 20:54:16 +02:00
|
|
|
/* $XFree86: xc/programs/Xserver/GL/glx/glxutil.c,v 1.5 2001/03/21 16:29:37 dawes Exp $ */
|
2003-11-14 17:48:57 +01:00
|
|
|
/*
|
|
|
|
** License Applicability. Except to the extent portions of this file are
|
|
|
|
** made subject to an alternative license as permitted in the SGI Free
|
|
|
|
** Software License B, Version 1.1 (the "License"), the contents of this
|
|
|
|
** file are subject only to the provisions of the License. You may not use
|
|
|
|
** this file except in compliance with the License. You may obtain a copy
|
|
|
|
** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
|
|
|
|
** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
|
|
|
|
**
|
|
|
|
** http://oss.sgi.com/projects/FreeB
|
|
|
|
**
|
|
|
|
** Note that, as provided in the License, the Software is distributed on an
|
|
|
|
** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
|
|
|
|
** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
|
|
|
|
** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
|
|
|
|
** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
|
|
|
|
**
|
|
|
|
** Original Code. The Original Code is: OpenGL Sample Implementation,
|
|
|
|
** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
|
|
|
|
** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
|
|
|
|
** Copyright in any portions created by third parties is as indicated
|
|
|
|
** elsewhere herein. All Rights Reserved.
|
|
|
|
**
|
|
|
|
** Additional Notice Provisions: The application programming interfaces
|
|
|
|
** established by SGI in conjunction with the Original Code are The
|
|
|
|
** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
|
|
|
|
** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
|
|
|
|
** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
|
|
|
|
** Window System(R) (Version 1.3), released October 19, 1998. This software
|
|
|
|
** was created using the OpenGL(R) version 1.2.1 Sample Implementation
|
|
|
|
** published by SGI, but has not been independently verified as being
|
|
|
|
** compliant with the OpenGL(R) version 1.2.1 Specification.
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define NEED_REPLIES
|
|
|
|
#define FONT_PCF
|
2005-07-03 09:02:09 +02:00
|
|
|
#ifdef HAVE_DIX_CONFIG_H
|
|
|
|
#include <dix-config.h>
|
|
|
|
#endif
|
|
|
|
|
2006-02-10 23:00:30 +01:00
|
|
|
#include <string.h>
|
|
|
|
|
2003-11-14 17:48:57 +01:00
|
|
|
#include "glxserver.h"
|
|
|
|
#include <GL/glxtokens.h>
|
|
|
|
#include <unpack.h>
|
|
|
|
#include <pixmapstr.h>
|
|
|
|
#include <windowstr.h>
|
|
|
|
#include "glxutil.h"
|
2004-06-16 11:25:21 +02:00
|
|
|
#include "GL/internal/glcore.h"
|
|
|
|
#include "GL/glxint.h"
|
|
|
|
#include "glcontextmodes.h"
|
2003-11-14 17:48:57 +01:00
|
|
|
|
|
|
|
/************************************************************************/
|
|
|
|
/* Context stuff */
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
** associate a context with a drawable
|
|
|
|
*/
|
|
|
|
void
|
2003-11-25 20:29:01 +01:00
|
|
|
__glXAssociateContext(__GLXcontext *glxc)
|
2003-11-14 17:48:57 +01:00
|
|
|
{
|
2003-11-25 20:29:01 +01:00
|
|
|
glxc->nextDrawPriv = glxc->drawPriv->drawGlxc;
|
|
|
|
glxc->drawPriv->drawGlxc = glxc;
|
2003-11-14 17:48:57 +01:00
|
|
|
|
2006-03-12 01:11:34 +01:00
|
|
|
__glXRefDrawable(glxc->drawPriv);
|
2003-11-25 20:29:01 +01:00
|
|
|
|
|
|
|
|
|
|
|
glxc->nextReadPriv = glxc->readPriv->readGlxc;
|
|
|
|
glxc->readPriv->readGlxc = glxc;
|
|
|
|
|
2006-03-12 01:11:34 +01:00
|
|
|
__glXRefDrawable(glxc->readPriv);
|
2003-11-14 17:48:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Deassociate a context from a drawable
|
|
|
|
*/
|
|
|
|
void
|
2003-11-25 20:29:01 +01:00
|
|
|
__glXDeassociateContext(__GLXcontext *glxc)
|
2003-11-14 17:48:57 +01:00
|
|
|
{
|
2003-11-25 20:29:01 +01:00
|
|
|
__GLXcontext *curr, *prev;
|
2003-11-14 17:48:57 +01:00
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
prev = NULL;
|
|
|
|
for ( curr = glxc->drawPriv->drawGlxc
|
|
|
|
; curr != NULL
|
|
|
|
; prev = curr, curr = curr->nextDrawPriv ) {
|
|
|
|
if (curr == glxc) {
|
2003-11-14 17:48:57 +01:00
|
|
|
/* found context. Deassociate. */
|
2003-11-25 20:29:01 +01:00
|
|
|
if (prev == NULL) {
|
|
|
|
glxc->drawPriv->drawGlxc = curr->nextDrawPriv;
|
2003-11-14 17:48:57 +01:00
|
|
|
} else {
|
2003-11-25 20:29:01 +01:00
|
|
|
prev->nextDrawPriv = curr->nextDrawPriv;
|
2003-11-14 17:48:57 +01:00
|
|
|
}
|
2003-11-25 20:29:01 +01:00
|
|
|
curr->nextDrawPriv = NULL;
|
2006-03-12 01:11:34 +01:00
|
|
|
__glXUnrefDrawable(glxc->drawPriv);
|
2003-11-25 20:29:01 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
prev = NULL;
|
|
|
|
for ( curr = glxc->readPriv->readGlxc
|
|
|
|
; curr != NULL
|
|
|
|
; prev = curr, curr = curr->nextReadPriv ) {
|
|
|
|
if (curr == glxc) {
|
|
|
|
/* found context. Deassociate. */
|
|
|
|
if (prev == NULL) {
|
|
|
|
glxc->readPriv->readGlxc = curr->nextReadPriv;
|
|
|
|
} else {
|
|
|
|
prev->nextReadPriv = curr->nextReadPriv;
|
|
|
|
}
|
|
|
|
curr->nextReadPriv = NULL;
|
2006-03-12 01:11:34 +01:00
|
|
|
__glXUnrefDrawable(glxc->readPriv);
|
2003-11-14 17:48:57 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/* Drawable private stuff */
|
|
|
|
|
|
|
|
void
|
2006-03-12 01:11:34 +01:00
|
|
|
__glXRefDrawable(__GLXdrawable *glxPriv)
|
2003-11-14 17:48:57 +01:00
|
|
|
{
|
|
|
|
glxPriv->refCount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2006-03-12 01:11:34 +01:00
|
|
|
__glXUnrefDrawable(__GLXdrawable *glxPriv)
|
2003-11-14 17:48:57 +01:00
|
|
|
{
|
|
|
|
glxPriv->refCount--;
|
|
|
|
if (glxPriv->refCount == 0) {
|
2006-03-12 01:11:34 +01:00
|
|
|
/* remove the drawable from the drawable list */
|
|
|
|
FreeResourceByType(glxPriv->drawId, __glXDrawableRes, FALSE);
|
|
|
|
glxPriv->destroy(glxPriv);
|
2003-11-14 17:48:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-03-12 01:11:34 +01:00
|
|
|
GLboolean
|
|
|
|
__glXDrawableInit(__GLXdrawable *drawable,
|
|
|
|
__GLXcontext *ctx, DrawablePtr pDraw, XID drawId)
|
2003-11-14 17:48:57 +01:00
|
|
|
{
|
2006-03-12 01:11:34 +01:00
|
|
|
drawable->type = pDraw->type;
|
|
|
|
drawable->pDraw = pDraw;
|
|
|
|
drawable->drawId = drawId;
|
|
|
|
drawable->refCount = 1;
|
2003-11-14 17:48:57 +01:00
|
|
|
|
|
|
|
/* if not a pixmap, lookup will fail, so pGlxPixmap will be NULL */
|
2006-03-12 01:11:34 +01:00
|
|
|
drawable->pGlxPixmap = (__GLXpixmap *)
|
2003-11-14 17:48:57 +01:00
|
|
|
LookupIDByType(drawId, __glXPixmapRes);
|
|
|
|
|
|
|
|
return GL_TRUE;
|
|
|
|
}
|
|
|
|
|
2006-03-12 01:11:34 +01:00
|
|
|
__GLXdrawable *
|
|
|
|
__glXFindDrawable(XID drawId)
|
2003-11-14 17:48:57 +01:00
|
|
|
{
|
2006-03-12 01:11:34 +01:00
|
|
|
__GLXdrawable *glxPriv;
|
2003-11-14 17:48:57 +01:00
|
|
|
|
2006-03-12 01:11:34 +01:00
|
|
|
glxPriv = (__GLXdrawable *)LookupIDByType(drawId, __glXDrawableRes);
|
2003-11-14 17:48:57 +01:00
|
|
|
|
|
|
|
return glxPriv;
|
|
|
|
}
|
|
|
|
|
2006-03-12 01:11:34 +01:00
|
|
|
__GLXdrawable *
|
|
|
|
__glXGetDrawable(__GLXcontext *ctx, DrawablePtr pDraw, XID drawId)
|
2003-11-14 17:48:57 +01:00
|
|
|
{
|
2006-03-12 01:11:34 +01:00
|
|
|
__GLXdrawable *glxPriv;
|
2003-11-14 17:48:57 +01:00
|
|
|
|
2006-03-12 01:11:34 +01:00
|
|
|
glxPriv = __glXFindDrawable(drawId);
|
2003-11-14 17:48:57 +01:00
|
|
|
|
2006-03-12 01:11:34 +01:00
|
|
|
if (glxPriv == NULL)
|
2006-03-13 02:54:59 +01:00
|
|
|
{
|
2006-03-12 01:11:34 +01:00
|
|
|
glxPriv = ctx->createDrawable(ctx, pDraw, drawId);
|
2003-11-14 17:48:57 +01:00
|
|
|
|
2006-03-13 02:54:59 +01:00
|
|
|
/* since we are creating the drawablePrivate, drawId should be new */
|
|
|
|
if (!AddResource(drawId, __glXDrawableRes, glxPriv))
|
|
|
|
{
|
|
|
|
glxPriv->destroy (glxPriv);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-11-14 17:48:57 +01:00
|
|
|
return glxPriv;
|
|
|
|
}
|