System.out.println("parent " + handle); System.out.println("disposing " + context);
public GLCanvas (Composite parent, int style, GLData data) {	super (parent, style);		if (data == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);	int glxAttrib [] = new int [MAX_ATTRIBUTES];	int pos = 0;	glxAttrib [pos++] = GLX.GLX_RGBA;	if (data.doubleBuffer) glxAttrib [pos++] = GLX.GLX_DOUBLEBUFFER;	if (data.stereo) glxAttrib [pos++] = GLX.GLX_STEREO;	if (data.redSize > 0) {		glxAttrib [pos++] = GLX.GLX_RED_SIZE;		glxAttrib [pos++] = data.redSize;	}	if (data.greenSize > 0) {		glxAttrib [pos++] = GLX.GLX_GREEN_SIZE;		glxAttrib [pos++] = data.greenSize;	}	if (data.blueSize > 0) {		glxAttrib [pos++] = GLX.GLX_BLUE_SIZE;		glxAttrib [pos++] = data.blueSize;	}	if (data.alphaSize > 0) {		glxAttrib [pos++] = GLX.GLX_ALPHA_SIZE;		glxAttrib [pos++] = data.alphaSize;	}	if (data.depthSize > 0) {		glxAttrib [pos++] = GLX.GLX_DEPTH_SIZE;		glxAttrib [pos++] = data.depthSize;	}	if (data.stencilSize > 0) {		glxAttrib [pos++] = GLX.GLX_STENCIL_SIZE;		glxAttrib [pos++] = data.stencilSize;	}	if (data.accumRedSize > 0) {		glxAttrib [pos++] = GLX.GLX_ACCUM_RED_SIZE;		glxAttrib [pos++] = data.accumRedSize;	}	if (data.accumGreenSize > 0) {		glxAttrib [pos++] = GLX.GLX_ACCUM_GREEN_SIZE;		glxAttrib [pos++] = data.accumGreenSize;	}	if (data.accumBlueSize > 0) {		glxAttrib [pos++] = GLX.GLX_ACCUM_BLUE_SIZE;		glxAttrib [pos++] = data.accumBlueSize;	}	if (data.accumAlphaSize > 0) {		glxAttrib [pos++] = GLX.GLX_ACCUM_ALPHA_SIZE;		glxAttrib [pos++] = data.accumAlphaSize;	}	if (data.sampleBuffers > 0) {		glxAttrib [pos++] = GLX.GLX_SAMPLE_BUFFERS;		glxAttrib [pos++] = data.sampleBuffers;	}	if (data.samples > 0) {		glxAttrib [pos++] = GLX.GLX_SAMPLES;		glxAttrib [pos++] = data.samples;	}	glxAttrib [pos++] = 0;	//FIXME - need to ensure the widget is realized at this point	new GC(this).dispose();	int xDisplay = OS.XtDisplay (handle);	int xScreen = OS.XDefaultScreen (xDisplay);	int infoPtr = GLX.glXChooseVisual (xDisplay, xScreen, glxAttrib);	if (infoPtr == 0) SWT.error (SWT.ERROR_UNSUPPORTED_DEPTH);	vinfo = new XVisualInfo ();	GLX.memmove (vinfo, infoPtr, XVisualInfo.sizeof);	OS.XFree (infoPtr);	//FIXME- share lists	//context = GLX.glXCreateContext (xdisplay, info, share == null ? 0 : share.context, true);	context = GLX.glXCreateContext (xDisplay, vinfo, 0, true);	if (context == 0) SWT.error (SWT.ERROR_NO_HANDLES);	int xParent = OS.XtWindow (handle);	XSetWindowAttributes attributes = new XSetWindowAttributes ();	int mask = OS.CWDontPropagate | OS.CWEventMask | OS.CWColormap;	colormap = OS.XCreateColormap(xDisplay, xParent, vinfo.visual, OS.AllocNone);	attributes.colormap = colormap;	xWindow = OS.XCreateWindow (xDisplay, xParent, 0, 0, 1, 1, 0,			vinfo.depth, 1, vinfo.visual, mask, attributes);	int event_mask = OS.XtBuildEventMask (handle);	/*	* Attempting to propogate EnterWindowMask and LeaveWindowMask	* causes an X error so these must be specially cleared out from	* the event mask, not included in the propogate mask.	*/	//FIXME - check this	//event_mask = event_mask | ~(OS.EnterWindowMask | OS.LeaveWindowMask);	OS.XSelectInput (xDisplay, xWindow, event_mask);	OS.XMapWindow (xDisplay, xWindow);	OS.XtRegisterDrawable (xDisplay, xWindow, handle);	Listener listener = new Listener () {		public void handleEvent (Event event) {			int xDisplay = OS.XtDisplay (handle);			switch (event.type) {			case SWT.Paint:				/**				* Bug in MESA.  MESA does some nasty sort of polling to try				* and ensure that their buffer sizes match the current X state.				* This state can be updated using glViewport().				* FIXME: There has to be a better way of doing this.				*/				int [] viewport = new int [4];				GLX.glGetIntegerv (GLX.GL_VIEWPORT, viewport);				GLX.glViewport (viewport [0],viewport [1],viewport [2],viewport [3]);				break;			case SWT.KeyDown:				break;			case SWT.Resize:				Rectangle clientArea = getClientArea();				OS.XMoveResizeWindow (xDisplay, xWindow, clientArea.x, clientArea.y, clientArea.width, clientArea.height);				break;			case SWT.Dispose:				System.out.println("parent " + handle);				System.out.println("disposing " + context);				if (context != 0) {					if (GLX.glXGetCurrentContext () == context) {						GLX.glXMakeCurrent (xDisplay, 0, 0);					}					GLX.glXDestroyContext (xDisplay, context);					context = 0;				}				if (xWindow != 0) {					OS.XtUnregisterDrawable (xDisplay, xWindow);					OS.XDestroyWindow (xDisplay, xWindow);					xWindow = 0;				}				if (colormap != 0) {					OS.XFreeColormap (xDisplay, colormap);					colormap = 0;				}				break;			}		}	};	addListener (SWT.KeyDown, listener);	addListener (SWT.Resize, listener);	addListener (SWT.Paint, listener);	addListener (SWT.Dispose, listener);}