diff options
author | Billy Biggs <bbiggs> | 2005-09-13 22:05:42 +0000 |
---|---|---|
committer | Billy Biggs <bbiggs> | 2005-09-13 22:05:42 +0000 |
commit | c6c7d103c019b64f4457445f6bdabf9714193318 (patch) | |
tree | 85608eb2d45c274db4c26ac9ce7094f14b282562 /bundles/org.eclipse.swt.opengl | |
parent | c431bd63ec880481e753baecadfb2eeffcc18820 (diff) | |
download | eclipse.platform.swt-c6c7d103c019b64f4457445f6bdabf9714193318.tar.gz eclipse.platform.swt-c6c7d103c019b64f4457445f6bdabf9714193318.tar.xz eclipse.platform.swt-c6c7d103c019b64f4457445f6bdabf9714193318.zip |
First attempt at the new API for GTK+.
Diffstat (limited to 'bundles/org.eclipse.swt.opengl')
13 files changed, 525 insertions, 608 deletions
diff --git a/bundles/org.eclipse.swt.opengl/gtk/library/glx.c b/bundles/org.eclipse.swt.opengl/gtk/library/glx.c index 4bb4fbb2a4..e3615ca3e1 100644 --- a/bundles/org.eclipse.swt.opengl/gtk/library/glx.c +++ b/bundles/org.eclipse.swt.opengl/gtk/library/glx.c @@ -1,232 +1,290 @@ /******************************************************************************* - * Copyright (c) 2000, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -#include <GL/glx.h> +* Copyright (c) 2000, 2005 IBM Corporation and others. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* IBM Corporation - initial API and implementation +*******************************************************************************/ + #include "swt.h" -#include "structs.h" +#include "glx_structs.h" +#include "glx_stats.h" -#define XGL_NATIVE(func) Java_org_eclipse_swt_opengl_internal_gtk_XGL_##func +#define GLX_NATIVE(func) Java_org_eclipse_swt_internal_opengl_gtk_GLX_##func -JNIEXPORT jint JNICALL XGL_NATIVE(glXChooseVisual) +#ifndef NO_glXChooseVisual +JNIEXPORT jint JNICALL GLX_NATIVE(glXChooseVisual) (JNIEnv *env, jclass that, jint arg0, jint arg1, jintArray arg2) { jint *lparg2=NULL; - jint rc; - - DEBUG_CALL("glXChooseVisual\n") - - if (arg2) lparg2 = (*env)->GetIntArrayElements(env, arg2, NULL); - rc = (jint)glXChooseVisual((Display *)arg0, arg1, (int *)lparg2); - if (arg2) (*env)->ReleaseIntArrayElements(env, arg2, lparg2, 0); + jint rc = 0; + GLX_NATIVE_ENTER(env, that, glXChooseVisual_FUNC); + if (arg2) if ((lparg2 = (*env)->GetIntArrayElements(env, arg2, NULL)) == NULL) goto fail; + rc = (jint)glXChooseVisual(arg0, arg1, lparg2); +fail: + if (arg2 && lparg2) (*env)->ReleaseIntArrayElements(env, arg2, lparg2, 0); + GLX_NATIVE_EXIT(env, that, glXChooseVisual_FUNC); return rc; } +#endif -JNIEXPORT void JNICALL XGL_NATIVE(glXCopyContext) +#ifndef NO_glXCopyContext +JNIEXPORT void JNICALL GLX_NATIVE(glXCopyContext) (JNIEnv *env, jclass that, jint arg0, jint arg1, jint arg2, jint arg3) { - DEBUG_CALL("glXCopyContext\n") - - glXCopyContext((Display *)arg0, (GLXContext)arg1, (GLXContext)arg2, arg3); + GLX_NATIVE_ENTER(env, that, glXCopyContext_FUNC); + glXCopyContext(arg0, arg1, arg2, arg3); + GLX_NATIVE_EXIT(env, that, glXCopyContext_FUNC); } +#endif -JNIEXPORT jint JNICALL XGL_NATIVE(glXCreateContext) +#ifndef NO_glXCreateContext +JNIEXPORT jint JNICALL GLX_NATIVE(glXCreateContext) (JNIEnv *env, jclass that, jint arg0, jobject arg1, jint arg2, jboolean arg3) { XVisualInfo _arg1, *lparg1=NULL; - jint rc; - - DEBUG_CALL("glXCreateContext\n") - - if (arg1) lparg1 = getXVisualInfoFields(env, arg1, &_arg1); - rc = (jint)glXCreateContext((Display *)arg0, lparg1, (GLXContext)arg2, arg3); - if (arg1) setXVisualInfoFields(env, arg1, lparg1); + jint rc = 0; + GLX_NATIVE_ENTER(env, that, glXCreateContext_FUNC); + if (arg1) if ((lparg1 = getXVisualInfoFields(env, arg1, &_arg1)) == NULL) goto fail; + rc = (jint)glXCreateContext(arg0, lparg1, arg2, arg3); +fail: + if (arg1 && lparg1) setXVisualInfoFields(env, arg1, lparg1); + GLX_NATIVE_EXIT(env, that, glXCreateContext_FUNC); return rc; } +#endif -JNIEXPORT jint JNICALL XGL_NATIVE(glXCreateGLXPixmap) +#ifndef NO_glXCreateGLXPixmap +JNIEXPORT jint JNICALL GLX_NATIVE(glXCreateGLXPixmap) (JNIEnv *env, jclass that, jint arg0, jobject arg1, jint arg2) { XVisualInfo _arg1, *lparg1=NULL; - jint rc; - - DEBUG_CALL("glXCreateGLXPixmap\n") - - if (arg1) lparg1 = getXVisualInfoFields(env, arg1, &_arg1); - rc = (jint)glXCreateGLXPixmap((Display *)arg0, lparg1, arg2); - if (arg1) setXVisualInfoFields(env, arg1, lparg1); + jint rc = 0; + GLX_NATIVE_ENTER(env, that, glXCreateGLXPixmap_FUNC); + if (arg1) if ((lparg1 = getXVisualInfoFields(env, arg1, &_arg1)) == NULL) goto fail; + rc = (jint)glXCreateGLXPixmap(arg0, lparg1, arg2); +fail: + if (arg1 && lparg1) setXVisualInfoFields(env, arg1, lparg1); + GLX_NATIVE_EXIT(env, that, glXCreateGLXPixmap_FUNC); return rc; } +#endif -JNIEXPORT void JNICALL XGL_NATIVE(glXDestroyContext) +#ifndef NO_glXDestroyContext +JNIEXPORT void JNICALL GLX_NATIVE(glXDestroyContext) (JNIEnv *env, jclass that, jint arg0, jint arg1) { - DEBUG_CALL("glXDestroyContext\n") - - glXDestroyContext((Display *)arg0, (GLXContext)arg1); + GLX_NATIVE_ENTER(env, that, glXDestroyContext_FUNC); + glXDestroyContext(arg0, arg1); + GLX_NATIVE_EXIT(env, that, glXDestroyContext_FUNC); } +#endif -JNIEXPORT void JNICALL XGL_NATIVE(glXDestroyGLXPixmap) +#ifndef NO_glXDestroyGLXPixmap +JNIEXPORT void JNICALL GLX_NATIVE(glXDestroyGLXPixmap) (JNIEnv *env, jclass that, jint arg0, jint arg1) { - DEBUG_CALL("glXDestroyGLXPixmap\n") - - glXDestroyGLXPixmap((Display *)arg0, arg1); + GLX_NATIVE_ENTER(env, that, glXDestroyGLXPixmap_FUNC); + glXDestroyGLXPixmap(arg0, arg1); + GLX_NATIVE_EXIT(env, that, glXDestroyGLXPixmap_FUNC); } +#endif -JNIEXPORT jint JNICALL XGL_NATIVE(glXGetClientString) +#ifndef NO_glXGetClientString +JNIEXPORT jint JNICALL GLX_NATIVE(glXGetClientString) (JNIEnv *env, jclass that, jint arg0, jint arg1) { - DEBUG_CALL("glXGetClientString\n") - - return (jint)glXGetClientString((Display *)arg0, arg1); + jint rc = 0; + GLX_NATIVE_ENTER(env, that, glXGetClientString_FUNC); + rc = (jint)glXGetClientString(arg0, arg1); + GLX_NATIVE_EXIT(env, that, glXGetClientString_FUNC); + return rc; } +#endif -JNIEXPORT jint JNICALL XGL_NATIVE(glXGetConfig) +#ifndef NO_glXGetConfig +JNIEXPORT jint JNICALL GLX_NATIVE(glXGetConfig) (JNIEnv *env, jclass that, jint arg0, jobject arg1, jint arg2, jintArray arg3) { XVisualInfo _arg1, *lparg1=NULL; jint *lparg3=NULL; - jint rc; - - DEBUG_CALL("glXGetConfig\n") - - if (arg1) lparg1 = getXVisualInfoFields(env, arg1, &_arg1); - if (arg3) lparg3 = (*env)->GetIntArrayElements(env, arg3, NULL); - rc = (jint)glXGetConfig((Display *)arg0, lparg1, arg2, (int *)lparg3); - if (arg1) setXVisualInfoFields(env, arg1, lparg1); - if (arg3) (*env)->ReleaseIntArrayElements(env, arg3, lparg3, 0); + jint rc = 0; + GLX_NATIVE_ENTER(env, that, glXGetConfig_FUNC); + if (arg1) if ((lparg1 = getXVisualInfoFields(env, arg1, &_arg1)) == NULL) goto fail; + if (arg3) if ((lparg3 = (*env)->GetIntArrayElements(env, arg3, NULL)) == NULL) goto fail; + rc = (jint)glXGetConfig(arg0, lparg1, arg2, lparg3); +fail: + if (arg3 && lparg3) (*env)->ReleaseIntArrayElements(env, arg3, lparg3, 0); + if (arg1 && lparg1) setXVisualInfoFields(env, arg1, lparg1); + GLX_NATIVE_EXIT(env, that, glXGetConfig_FUNC); return rc; } +#endif -JNIEXPORT jint JNICALL XGL_NATIVE(glXGetCurrentContext) +#ifndef NO_glXGetCurrentContext +JNIEXPORT jint JNICALL GLX_NATIVE(glXGetCurrentContext) (JNIEnv *env, jclass that) { - DEBUG_CALL("glXGetCurrentContext\n") - - return (jint)glXGetCurrentContext(); + jint rc = 0; + GLX_NATIVE_ENTER(env, that, glXGetCurrentContext_FUNC); + rc = (jint)glXGetCurrentContext(); + GLX_NATIVE_EXIT(env, that, glXGetCurrentContext_FUNC); + return rc; } +#endif -JNIEXPORT jint JNICALL XGL_NATIVE(glXGetCurrentDrawable) +#ifndef NO_glXGetCurrentDrawable +JNIEXPORT jint JNICALL GLX_NATIVE(glXGetCurrentDrawable) (JNIEnv *env, jclass that) { - DEBUG_CALL("glXGetCurrentDrawable\n") - - return (jint)glXGetCurrentDrawable(); + jint rc = 0; + GLX_NATIVE_ENTER(env, that, glXGetCurrentDrawable_FUNC); + rc = (jint)glXGetCurrentDrawable(); + GLX_NATIVE_EXIT(env, that, glXGetCurrentDrawable_FUNC); + return rc; } +#endif -JNIEXPORT jboolean JNICALL XGL_NATIVE(glXIsDirect) +#ifndef NO_glXIsDirect +JNIEXPORT jboolean JNICALL GLX_NATIVE(glXIsDirect) (JNIEnv *env, jclass that, jint arg0, jint arg1) { - DEBUG_CALL("glXIsDirect\n") - - return (jboolean)glXIsDirect((Display *)arg0, (GLXContext)arg1); + jboolean rc = 0; + GLX_NATIVE_ENTER(env, that, glXIsDirect_FUNC); + rc = (jboolean)glXIsDirect(arg0, arg1); + GLX_NATIVE_EXIT(env, that, glXIsDirect_FUNC); + return rc; } +#endif -JNIEXPORT jboolean JNICALL XGL_NATIVE(glXMakeCurrent) +#ifndef NO_glXMakeCurrent +JNIEXPORT jboolean JNICALL GLX_NATIVE(glXMakeCurrent) (JNIEnv *env, jclass that, jint arg0, jint arg1, jint arg2) { - DEBUG_CALL("glXMakeCurrent\n") - - return (jboolean)glXMakeCurrent((Display *)arg0, (GLXDrawable)arg1, (GLXContext)arg2); + jboolean rc = 0; + GLX_NATIVE_ENTER(env, that, glXMakeCurrent_FUNC); + rc = (jboolean)glXMakeCurrent(arg0, arg1, arg2); + GLX_NATIVE_EXIT(env, that, glXMakeCurrent_FUNC); + return rc; } +#endif -JNIEXPORT jboolean JNICALL XGL_NATIVE(glXQueryExtension) +#ifndef NO_glXQueryExtension +JNIEXPORT jboolean JNICALL GLX_NATIVE(glXQueryExtension) (JNIEnv *env, jclass that, jint arg0, jintArray arg1, jintArray arg2) { jint *lparg1=NULL; jint *lparg2=NULL; - jboolean rc; - - DEBUG_CALL("glXQueryExtension\n") - - if (arg1) lparg1 = (*env)->GetIntArrayElements(env, arg1, NULL); - if (arg2) lparg2 = (*env)->GetIntArrayElements(env, arg2, NULL); - rc = (jboolean)glXQueryExtension((Display *)arg0, (int *)lparg1, (int *)lparg2); - if (arg1) (*env)->ReleaseIntArrayElements(env, arg1, lparg1, 0); - if (arg2) (*env)->ReleaseIntArrayElements(env, arg2, lparg2, 0); + jboolean rc = 0; + GLX_NATIVE_ENTER(env, that, glXQueryExtension_FUNC); + if (arg1) if ((lparg1 = (*env)->GetIntArrayElements(env, arg1, NULL)) == NULL) goto fail; + if (arg2) if ((lparg2 = (*env)->GetIntArrayElements(env, arg2, NULL)) == NULL) goto fail; + rc = (jboolean)glXQueryExtension(arg0, lparg1, lparg2); +fail: + if (arg2 && lparg2) (*env)->ReleaseIntArrayElements(env, arg2, lparg2, 0); + if (arg1 && lparg1) (*env)->ReleaseIntArrayElements(env, arg1, lparg1, 0); + GLX_NATIVE_EXIT(env, that, glXQueryExtension_FUNC); return rc; } +#endif -JNIEXPORT jint JNICALL XGL_NATIVE(glXQueryExtensionsString) +#ifndef NO_glXQueryExtensionsString +JNIEXPORT jint JNICALL GLX_NATIVE(glXQueryExtensionsString) (JNIEnv *env, jclass that, jint arg0, jint arg1) { - DEBUG_CALL("glXQueryExtensionsString\n") - - return (jint)glXQueryExtensionsString((Display *)arg0, arg1); + jint rc = 0; + GLX_NATIVE_ENTER(env, that, glXQueryExtensionsString_FUNC); + rc = (jint)glXQueryExtensionsString(arg0, arg1); + GLX_NATIVE_EXIT(env, that, glXQueryExtensionsString_FUNC); + return rc; } +#endif -JNIEXPORT jint JNICALL XGL_NATIVE(glXQueryServerString) +#ifndef NO_glXQueryServerString +JNIEXPORT jint JNICALL GLX_NATIVE(glXQueryServerString) (JNIEnv *env, jclass that, jint arg0, jint arg1, jint arg2) { - DEBUG_CALL("glXQueryServerString\n") - - return (jint)glXQueryServerString((Display *)arg0, arg1, arg2); + jint rc = 0; + GLX_NATIVE_ENTER(env, that, glXQueryServerString_FUNC); + rc = (jint)glXQueryServerString(arg0, arg1, arg2); + GLX_NATIVE_EXIT(env, that, glXQueryServerString_FUNC); + return rc; } +#endif -JNIEXPORT jboolean JNICALL XGL_NATIVE(glXQueryVersion) +#ifndef NO_glXQueryVersion +JNIEXPORT jboolean JNICALL GLX_NATIVE(glXQueryVersion) (JNIEnv *env, jclass that, jint arg0, jintArray arg1, jintArray arg2) { jint *lparg1=NULL; jint *lparg2=NULL; - jboolean rc; - - DEBUG_CALL("glXQueryVersion\n") - - if (arg1) lparg1 = (*env)->GetIntArrayElements(env, arg1, NULL); - if (arg2) lparg2 = (*env)->GetIntArrayElements(env, arg2, NULL); - rc = (jboolean)glXQueryVersion((Display *)arg0, (int *)lparg1, (int *)lparg2); - if (arg1) (*env)->ReleaseIntArrayElements(env, arg1, lparg1, 0); - if (arg2) (*env)->ReleaseIntArrayElements(env, arg2, lparg2, 0); + jboolean rc = 0; + GLX_NATIVE_ENTER(env, that, glXQueryVersion_FUNC); + if (arg1) if ((lparg1 = (*env)->GetIntArrayElements(env, arg1, NULL)) == NULL) goto fail; + if (arg2) if ((lparg2 = (*env)->GetIntArrayElements(env, arg2, NULL)) == NULL) goto fail; + rc = (jboolean)glXQueryVersion(arg0, lparg1, lparg2); +fail: + if (arg2 && lparg2) (*env)->ReleaseIntArrayElements(env, arg2, lparg2, 0); + if (arg1 && lparg1) (*env)->ReleaseIntArrayElements(env, arg1, lparg1, 0); + GLX_NATIVE_EXIT(env, that, glXQueryVersion_FUNC); return rc; } +#endif -JNIEXPORT void JNICALL XGL_NATIVE(glXSwapBuffers) +#ifndef NO_glXSwapBuffers +JNIEXPORT void JNICALL GLX_NATIVE(glXSwapBuffers) (JNIEnv *env, jclass that, jint arg0, jint arg1) { - DEBUG_CALL("glXSwapBuffers\n") - - glXSwapBuffers((Display *)arg0, (GLXDrawable)arg1); + GLX_NATIVE_ENTER(env, that, glXSwapBuffers_FUNC); + glXSwapBuffers(arg0, arg1); + GLX_NATIVE_EXIT(env, that, glXSwapBuffers_FUNC); } +#endif -JNIEXPORT void JNICALL XGL_NATIVE(glXUseXFont) +#ifndef NO_glXUseXFont +JNIEXPORT void JNICALL GLX_NATIVE(glXUseXFont) (JNIEnv *env, jclass that, jint arg0, jint arg1, jint arg2, jint arg3) { - DEBUG_CALL("glXUseXFont\n") - + GLX_NATIVE_ENTER(env, that, glXUseXFont_FUNC); glXUseXFont(arg0, arg1, arg2, arg3); + GLX_NATIVE_EXIT(env, that, glXUseXFont_FUNC); } +#endif -JNIEXPORT void JNICALL XGL_NATIVE(glXWaitGL) +#ifndef NO_glXWaitGL +JNIEXPORT void JNICALL GLX_NATIVE(glXWaitGL) (JNIEnv *env, jclass that) { - DEBUG_CALL("glXWaitGL\n") - + GLX_NATIVE_ENTER(env, that, glXWaitGL_FUNC); glXWaitGL(); + GLX_NATIVE_EXIT(env, that, glXWaitGL_FUNC); } +#endif -JNIEXPORT void JNICALL XGL_NATIVE(glXWaitX) +#ifndef NO_glXWaitX +JNIEXPORT void JNICALL GLX_NATIVE(glXWaitX) (JNIEnv *env, jclass that) { - DEBUG_CALL("glXWaitX\n") - + GLX_NATIVE_ENTER(env, that, glXWaitX_FUNC); glXWaitX(); + GLX_NATIVE_EXIT(env, that, glXWaitX_FUNC); } +#endif -JNIEXPORT void JNICALL XGL_NATIVE(memmove__Lorg_eclipse_swt_opengl_internal_gtk_XVisualInfo_2II) +#ifndef NO_memmove +JNIEXPORT void JNICALL GLX_NATIVE(memmove) (JNIEnv *env, jclass that, jobject arg0, jint arg1, jint arg2) { XVisualInfo _arg0, *lparg0=NULL; - - DEBUG_CALL("memmove__Lorg_eclipse_swt_opengl_internal_gtk_XVisualInfo_2II\n") - - if (arg0) lparg0 = &_arg0; - memmove((void *)lparg0, (const void *)arg1, (size_t)arg2); - if (arg0) setXVisualInfoFields(env, arg0, lparg0); + GLX_NATIVE_ENTER(env, that, memmove_FUNC); + if (arg0) if ((lparg0 = getXVisualInfoFields(env, arg0, &_arg0)) == NULL) goto fail; + memmove(lparg0, arg1, arg2); +fail: + if (arg0 && lparg0) setXVisualInfoFields(env, arg0, lparg0); + GLX_NATIVE_EXIT(env, that, memmove_FUNC); } +#endif + diff --git a/bundles/org.eclipse.swt.opengl/gtk/library/glx.h b/bundles/org.eclipse.swt.opengl/gtk/library/glx.h new file mode 100644 index 0000000000..4129ee597c --- /dev/null +++ b/bundles/org.eclipse.swt.opengl/gtk/library/glx.h @@ -0,0 +1,2 @@ + +#include <GL/glx.h> diff --git a/bundles/org.eclipse.swt.opengl/gtk/library/glx_stats.c b/bundles/org.eclipse.swt.opengl/gtk/library/glx_stats.c new file mode 100644 index 0000000000..111d1870b8 --- /dev/null +++ b/bundles/org.eclipse.swt.opengl/gtk/library/glx_stats.c @@ -0,0 +1,63 @@ +/******************************************************************************* +* Copyright (c) 2000, 2005 IBM Corporation and others. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* IBM Corporation - initial API and implementation +*******************************************************************************/ + +#include "swt.h" +#include "glx_stats.h" + +#ifdef NATIVE_STATS + +int GLX_nativeFunctionCount = 21; +int GLX_nativeFunctionCallCount[21]; +char * GLX_nativeFunctionNames[] = { + "glXChooseVisual", + "glXCopyContext", + "glXCreateContext", + "glXCreateGLXPixmap", + "glXDestroyContext", + "glXDestroyGLXPixmap", + "glXGetClientString", + "glXGetConfig", + "glXGetCurrentContext", + "glXGetCurrentDrawable", + "glXIsDirect", + "glXMakeCurrent", + "glXQueryExtension", + "glXQueryExtensionsString", + "glXQueryServerString", + "glXQueryVersion", + "glXSwapBuffers", + "glXUseXFont", + "glXWaitGL", + "glXWaitX", + "memmove", +}; + +#define STATS_NATIVE(func) Java_org_eclipse_swt_tools_internal_NativeStats_##func + +JNIEXPORT jint JNICALL STATS_NATIVE(GLX_1GetFunctionCount) + (JNIEnv *env, jclass that) +{ + return GLX_nativeFunctionCount; +} + +JNIEXPORT jstring JNICALL STATS_NATIVE(GLX_1GetFunctionName) + (JNIEnv *env, jclass that, jint index) +{ + return (*env)->NewStringUTF(env, GLX_nativeFunctionNames[index]); +} + +JNIEXPORT jint JNICALL STATS_NATIVE(GLX_1GetFunctionCallCount) + (JNIEnv *env, jclass that, jint index) +{ + return GLX_nativeFunctionCallCount[index]; +} + +#endif diff --git a/bundles/org.eclipse.swt.opengl/gtk/library/glx_stats.h b/bundles/org.eclipse.swt.opengl/gtk/library/glx_stats.h new file mode 100644 index 0000000000..8ec1695e48 --- /dev/null +++ b/bundles/org.eclipse.swt.opengl/gtk/library/glx_stats.h @@ -0,0 +1,45 @@ +/******************************************************************************* +* Copyright (c) 2000, 2005 IBM Corporation and others. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* IBM Corporation - initial API and implementation +*******************************************************************************/ + +#ifdef NATIVE_STATS +extern int GLX_nativeFunctionCount; +extern int GLX_nativeFunctionCallCount[]; +extern char* GLX_nativeFunctionNames[]; +#define GLX_NATIVE_ENTER(env, that, func) GLX_nativeFunctionCallCount[func]++; +#define GLX_NATIVE_EXIT(env, that, func) +#else +#define GLX_NATIVE_ENTER(env, that, func) +#define GLX_NATIVE_EXIT(env, that, func) +#endif + +typedef enum { + glXChooseVisual_FUNC, + glXCopyContext_FUNC, + glXCreateContext_FUNC, + glXCreateGLXPixmap_FUNC, + glXDestroyContext_FUNC, + glXDestroyGLXPixmap_FUNC, + glXGetClientString_FUNC, + glXGetConfig_FUNC, + glXGetCurrentContext_FUNC, + glXGetCurrentDrawable_FUNC, + glXIsDirect_FUNC, + glXMakeCurrent_FUNC, + glXQueryExtension_FUNC, + glXQueryExtensionsString_FUNC, + glXQueryServerString_FUNC, + glXQueryVersion_FUNC, + glXSwapBuffers_FUNC, + glXUseXFont_FUNC, + glXWaitGL_FUNC, + glXWaitX_FUNC, + memmove_FUNC, +} GLX_FUNCS; diff --git a/bundles/org.eclipse.swt.opengl/gtk/library/glx_structs.c b/bundles/org.eclipse.swt.opengl/gtk/library/glx_structs.c new file mode 100644 index 0000000000..b873c1dfa8 --- /dev/null +++ b/bundles/org.eclipse.swt.opengl/gtk/library/glx_structs.c @@ -0,0 +1,72 @@ +/******************************************************************************* +* Copyright (c) 2000, 2005 IBM Corporation and others. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* IBM Corporation - initial API and implementation +*******************************************************************************/ + +#include "swt.h" +#include "glx_structs.h" + +#ifndef NO_XVisualInfo +typedef struct XVisualInfo_FID_CACHE { + int cached; + jclass clazz; + jfieldID visual, visualid, screen, depth, cclass, red_mask, green_mask, blue_mask, colormap_size, bits_per_rgb; +} XVisualInfo_FID_CACHE; + +XVisualInfo_FID_CACHE XVisualInfoFc; + +void cacheXVisualInfoFields(JNIEnv *env, jobject lpObject) +{ + if (XVisualInfoFc.cached) return; + XVisualInfoFc.clazz = (*env)->GetObjectClass(env, lpObject); + XVisualInfoFc.visual = (*env)->GetFieldID(env, XVisualInfoFc.clazz, "visual", "I"); + XVisualInfoFc.visualid = (*env)->GetFieldID(env, XVisualInfoFc.clazz, "visualid", "I"); + XVisualInfoFc.screen = (*env)->GetFieldID(env, XVisualInfoFc.clazz, "screen", "I"); + XVisualInfoFc.depth = (*env)->GetFieldID(env, XVisualInfoFc.clazz, "depth", "I"); + XVisualInfoFc.cclass = (*env)->GetFieldID(env, XVisualInfoFc.clazz, "cclass", "I"); + XVisualInfoFc.red_mask = (*env)->GetFieldID(env, XVisualInfoFc.clazz, "red_mask", "I"); + XVisualInfoFc.green_mask = (*env)->GetFieldID(env, XVisualInfoFc.clazz, "green_mask", "I"); + XVisualInfoFc.blue_mask = (*env)->GetFieldID(env, XVisualInfoFc.clazz, "blue_mask", "I"); + XVisualInfoFc.colormap_size = (*env)->GetFieldID(env, XVisualInfoFc.clazz, "colormap_size", "I"); + XVisualInfoFc.bits_per_rgb = (*env)->GetFieldID(env, XVisualInfoFc.clazz, "bits_per_rgb", "I"); + XVisualInfoFc.cached = 1; +} + +XVisualInfo *getXVisualInfoFields(JNIEnv *env, jobject lpObject, XVisualInfo *lpStruct) +{ + if (!XVisualInfoFc.cached) cacheXVisualInfoFields(env, lpObject); + lpStruct->visual = (*env)->GetIntField(env, lpObject, XVisualInfoFc.visual); + lpStruct->visualid = (*env)->GetIntField(env, lpObject, XVisualInfoFc.visualid); + lpStruct->screen = (*env)->GetIntField(env, lpObject, XVisualInfoFc.screen); + lpStruct->depth = (*env)->GetIntField(env, lpObject, XVisualInfoFc.depth); + lpStruct->cclass = (*env)->GetIntField(env, lpObject, XVisualInfoFc.cclass); + lpStruct->red_mask = (*env)->GetIntField(env, lpObject, XVisualInfoFc.red_mask); + lpStruct->green_mask = (*env)->GetIntField(env, lpObject, XVisualInfoFc.green_mask); + lpStruct->blue_mask = (*env)->GetIntField(env, lpObject, XVisualInfoFc.blue_mask); + lpStruct->colormap_size = (*env)->GetIntField(env, lpObject, XVisualInfoFc.colormap_size); + lpStruct->bits_per_rgb = (*env)->GetIntField(env, lpObject, XVisualInfoFc.bits_per_rgb); + return lpStruct; +} + +void setXVisualInfoFields(JNIEnv *env, jobject lpObject, XVisualInfo *lpStruct) +{ + if (!XVisualInfoFc.cached) cacheXVisualInfoFields(env, lpObject); + (*env)->SetIntField(env, lpObject, XVisualInfoFc.visual, (jint)lpStruct->visual); + (*env)->SetIntField(env, lpObject, XVisualInfoFc.visualid, (jint)lpStruct->visualid); + (*env)->SetIntField(env, lpObject, XVisualInfoFc.screen, (jint)lpStruct->screen); + (*env)->SetIntField(env, lpObject, XVisualInfoFc.depth, (jint)lpStruct->depth); + (*env)->SetIntField(env, lpObject, XVisualInfoFc.cclass, (jint)lpStruct->cclass); + (*env)->SetIntField(env, lpObject, XVisualInfoFc.red_mask, (jint)lpStruct->red_mask); + (*env)->SetIntField(env, lpObject, XVisualInfoFc.green_mask, (jint)lpStruct->green_mask); + (*env)->SetIntField(env, lpObject, XVisualInfoFc.blue_mask, (jint)lpStruct->blue_mask); + (*env)->SetIntField(env, lpObject, XVisualInfoFc.colormap_size, (jint)lpStruct->colormap_size); + (*env)->SetIntField(env, lpObject, XVisualInfoFc.bits_per_rgb, (jint)lpStruct->bits_per_rgb); +} +#endif + diff --git a/bundles/org.eclipse.swt.opengl/gtk/library/glx_structs.h b/bundles/org.eclipse.swt.opengl/gtk/library/glx_structs.h new file mode 100644 index 0000000000..c04f09282b --- /dev/null +++ b/bundles/org.eclipse.swt.opengl/gtk/library/glx_structs.h @@ -0,0 +1,25 @@ +/******************************************************************************* +* Copyright (c) 2000, 2005 IBM Corporation and others. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* IBM Corporation - initial API and implementation +*******************************************************************************/ + +#include "glx.h" + +#ifndef NO_XVisualInfo +void cacheXVisualInfoFields(JNIEnv *env, jobject lpObject); +XVisualInfo *getXVisualInfoFields(JNIEnv *env, jobject lpObject, XVisualInfo *lpStruct); +void setXVisualInfoFields(JNIEnv *env, jobject lpObject, XVisualInfo *lpStruct); +#define XVisualInfo_sizeof() sizeof(XVisualInfo) +#else +#define cacheXVisualInfoFields(a,b) +#define getXVisualInfoFields(a,b,c) NULL +#define setXVisualInfoFields(a,b,c) +#define XVisualInfo_sizeof() 0 +#endif + diff --git a/bundles/org.eclipse.swt.opengl/gtk/library/make_linux.mak b/bundles/org.eclipse.swt.opengl/gtk/library/make_linux.mak index 7bc593b53e..f2e954c66c 100644 --- a/bundles/org.eclipse.swt.opengl/gtk/library/make_linux.mak +++ b/bundles/org.eclipse.swt.opengl/gtk/library/make_linux.mak @@ -12,28 +12,17 @@ # Define the installation directories for various products. CC=gcc LD=gcc -JAVA_HOME = /bluebird/teamswt/swt-builddir/ive/bin # Define the various shared libraries to be made. -WS_PREFIX = gtk +WS_PREFIX = gtk GL_PREFIX = gl GL_DLL = lib$(GL_PREFIX)-$(WS_PREFIX).so GL_OBJ = swt.o gl.o glu.o structs.o glx.o GL_LIB = -shared -L/usr/X11R6/lib -lGL -lGLU -lm -XGTK_PREFIX = xgtk -XGTK_DLL = lib$(XGTK_PREFIX)-$(WS_PREFIX).so -XGTK_OBJ = xgtk.o -XGTK_LIB = -shared `pkg-config --libs gtk+-2.0 gthread-2.0` -# -# The following CFLAGS are for compiling the SWT OpenGL libraries. -# -CFLAGS = -O -Wall \ - -I./ \ - -I$(JAVA_HOME)/include \ - `pkg-config --cflags gtk+-2.0` +CFLAGS = -O2 -Wall -I. -all: make_gl make_xgtk +all: make_gl make_gl: $(GL_DLL) $(LD) $(GL_LIB) -o $(GL_DLL) $(GL_OBJ) @@ -41,11 +30,5 @@ make_gl: $(GL_DLL) $(GL_DLL): $(GL_OBJ) $(CC) $(CFLAGS) -c glx.c -make_xgtk: $(XGTK_DLL) - $(LD) $(XGTK_LIB) -o $(XGTK_DLL) $(XGTK_OBJ) - -$(XGTK_DLL): $(XGTK_OBJ) - $(CC) $(CFLAGS) -c xgtk.c - clean: rm -f *.so *.o diff --git a/bundles/org.eclipse.swt.opengl/gtk/library/xgtk.c b/bundles/org.eclipse.swt.opengl/gtk/library/xgtk.c deleted file mode 100644 index b2230e0fca..0000000000 --- a/bundles/org.eclipse.swt.opengl/gtk/library/xgtk.c +++ /dev/null @@ -1,109 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -#include "swt.h" -#include <gdk/gdkx.h> -#include <stdlib.h> - -#define XGTK_NATIVE(func) Java_org_eclipse_swt_opengl_internal_gtk_XGTK_##func - -#ifndef NO_free -JNIEXPORT void JNICALL XGTK_NATIVE(free) - (JNIEnv *env, jclass that, jint arg0) -{ - NATIVE_ENTER(env, that, "free\n") - free((char *)arg0); - NATIVE_EXIT(env, that, "free\n") -} -#endif - -#ifndef NO_malloc -JNIEXPORT jint JNICALL XGTK_NATIVE(malloc) - (JNIEnv *env, jclass that, jint arg0) -{ - jint rc; - NATIVE_ENTER(env, that, "malloc\n") - rc = (jint)malloc(arg0); - NATIVE_EXIT(env, that, "malloc\n") - return rc; -} -#endif - -#ifndef NO_gdk_1x11_1gc_1get_1xdisplay -JNIEXPORT int JNICALL XGTK_NATIVE(gdk_1x11_1gc_1get_1xdisplay) - (JNIEnv *env, jclass that, jint arg0) -{ - jint rc; - NATIVE_ENTER(env, that, "gdk_1x11_1gc_1get_1xdisplay\n") - rc = (jint)gdk_x11_gc_get_xdisplay((GdkGC *)arg0); - NATIVE_EXIT(env, that, "gdk_1x11_1gc_1get_1xdisplay\n") - return rc; -} -#endif - -#ifndef NO_gdk_1x11_1drawable_1get_1xid -JNIEXPORT int JNICALL XGTK_NATIVE(gdk_1x11_1drawable_1get_1xid) - (JNIEnv *env, jclass that, jint arg0) -{ - jint rc; - NATIVE_ENTER(env, that, "gdk_1x11_1drawable_1get_1xid\n") - rc = (jint)gdk_x11_drawable_get_xid((GdkDrawable *)arg0); - NATIVE_EXIT(env, that, "gdk_1x11_1drawable_1get_1xid\n") - return rc; -} -#endif - -#ifndef NO_XDefaultScreen -JNIEXPORT jint JNICALL XGTK_NATIVE(XDefaultScreen) - (JNIEnv *env, jclass that, jint arg0) -{ - jint rc; - NATIVE_ENTER(env, that, "XDefaultScreen\n") - rc = (jint)XDefaultScreen((Display *)arg0); - NATIVE_EXIT(env, that, "XDefaultScreen\n") - return rc; -} -#endif - -#ifndef NO_XDefaultScreenOfDisplay -JNIEXPORT jint JNICALL XGTK_NATIVE(XDefaultScreenOfDisplay) - (JNIEnv *env, jclass that, jint arg0) -{ - jint rc; - NATIVE_ENTER(env, that, "XDefaultScreenOfDisplay\n") - rc = (jint)XDefaultScreenOfDisplay((Display *)arg0); - NATIVE_EXIT(env, that, "XDefaultScreenOfDisplay\n") - return rc; -} -#endif - -#ifndef NO_XDefaultDepthOfScreen -JNIEXPORT jint JNICALL XGTK_NATIVE(XDefaultDepthOfScreen) - (JNIEnv *env, jclass that, jint arg0) -{ - jint rc; - NATIVE_ENTER(env, that, "XDefaultDepthOfScreen\n") - rc = (jint)XDefaultDepthOfScreen((Screen *)arg0); - NATIVE_EXIT(env, that, "XDefaultDepthOfScreen\n") - return rc; -} -#endif - -#ifndef NO_XFree -JNIEXPORT jint JNICALL XGTK_NATIVE(XFree) - (JNIEnv *env, jclass that, jint arg0) -{ - jint rc; - NATIVE_ENTER(env, that, "XFree\n") - rc = (jint)XFree((char *)arg0); - NATIVE_EXIT(env, that, "XFree\n") - return rc; -} -#endif diff --git a/bundles/org.eclipse.swt.opengl/gtk/org/eclipse/swt/opengl/internal/gtk/XGL.java b/bundles/org.eclipse.swt.opengl/gtk/org/eclipse/swt/internal/opengl/gtk/GLX.java index b84f002283..5a2b3db1eb 100644..100755 --- a/bundles/org.eclipse.swt.opengl/gtk/org/eclipse/swt/opengl/internal/gtk/XGL.java +++ b/bundles/org.eclipse.swt.opengl/gtk/org/eclipse/swt/internal/opengl/gtk/GLX.java @@ -8,20 +8,16 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.swt.opengl.internal.gtk; +package org.eclipse.swt.internal.opengl.gtk; import org.eclipse.swt.opengl.Library; -public class XGL { +public class GLX { static { Library.loadLibrary("gl"); } -public static final int GLX_VERSION_1_1 = 1; -public static final int GLX_VERSION_1_2 = 1; -public static final int GLX_VERSION_1_3 = 1; - /* ** Visual Config Attributes (glXGetConfig, glXGetFBConfigAttrib) */ @@ -195,15 +191,14 @@ public static final int GLX_SHARE_CONTEXT_EXT = 0x800A; /* id of share context * public static final int GLX_VISUAL_ID_EXT = 0x800B; /* id of context's visual */ public static final int GLX_SCREEN_EXT = 0x800C; /* screen number */ -/* GLX Extension Strings */ -public static final int GLX_EXT_import_context = 1; -public static final int GLX_EXT_visual_info = 1; -public static final int GLX_EXT_visual_rating = 1; -public static final int GLX_ARB_get_proc_address = 1; +/* +* GLX 1.4 +*/ +public static final int GLX_SAMPLE_BUFFERS = 100000; +public static final int GLX_SAMPLES = 100001; public static final native int glXChooseVisual(int dpy, int screen, int[] attribList); public static final native void glXCopyContext(int dpy, int src, int dst, int mask); -//public static final native int glXCreateContext(int dpy, int vis, int shareList, boolean direct); public static final native int glXCreateContext(int dpy, XVisualInfo vis, int shareList, boolean direct); public static final native int glXCreateGLXPixmap(int dpy, XVisualInfo vis, int pixmap); public static final native void glXDestroyContext(int dpy, int ctx); diff --git a/bundles/org.eclipse.swt.opengl/gtk/org/eclipse/swt/opengl/internal/gtk/XVisualInfo.java b/bundles/org.eclipse.swt.opengl/gtk/org/eclipse/swt/internal/opengl/gtk/XVisualInfo.java index da0be5d70e..8f396967d4 100644..100755 --- a/bundles/org.eclipse.swt.opengl/gtk/org/eclipse/swt/opengl/internal/gtk/XVisualInfo.java +++ b/bundles/org.eclipse.swt.opengl/gtk/org/eclipse/swt/internal/opengl/gtk/XVisualInfo.java @@ -8,7 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.swt.opengl.internal.gtk; +package org.eclipse.swt.internal.opengl.gtk; public class XVisualInfo { diff --git a/bundles/org.eclipse.swt.opengl/gtk/org/eclipse/swt/opengl/GLCanvas.java b/bundles/org.eclipse.swt.opengl/gtk/org/eclipse/swt/opengl/GLCanvas.java new file mode 100644 index 0000000000..912435f02d --- /dev/null +++ b/bundles/org.eclipse.swt.opengl/gtk/org/eclipse/swt/opengl/GLCanvas.java @@ -0,0 +1,123 @@ +package org.eclipse.swt.opengl; + +import org.eclipse.swt.*; +import org.eclipse.swt.widgets.*; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.internal.gtk.*; +import org.eclipse.swt.internal.opengl.gtk.*; + +public class GLCanvas extends Canvas { + private int /*long*/ xdisplay; + private int /*long*/ xid; + private int /*long*/ context; + private int /*long*/ glWindow; + + private static final int MAX_ATTRIBUTES = 32; + +public GLCanvas (Composite parent, int style, GLFormatData data) { + super (parent, style); + if (data == null) SWT.error (SWT.ERROR_NULL_ARGUMENT); + int glxAttrib [] = new int [MAX_ATTRIBUTES]; + int pos = 0; + + int /*long*/ window = OS.GTK_WIDGET_WINDOW (handle); + xdisplay = OS.gdk_x11_drawable_get_xdisplay (window); + int xscreen = OS.XDefaultScreen (xdisplay); + + glxAttrib [pos++] = GLX.GLX_LEVEL; + glxAttrib [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.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++] = GLX.GLX_NONE; + int infoPtr = GLX.glXChooseVisual (xdisplay, xscreen, glxAttrib); + if (infoPtr == 0) SWT.error (SWT.ERROR_UNSUPPORTED_DEPTH); + XVisualInfo info = new XVisualInfo (); + GLX.memmove (info, infoPtr, XVisualInfo.sizeof); + OS.XFree (infoPtr); + int /*long*/ screen = OS.gdk_screen_get_default (); + int /*long*/ gdkvisual = OS.gdk_x11_screen_lookup_visual (screen, info.visualid); + context = GLX.glXCreateContext (xdisplay, info, 0, true); + if (context == 0) SWT.error (SWT.ERROR_NO_HANDLES); + GdkWindowAttr attrs = new GdkWindowAttr (); + attrs.width = 1; + attrs.height = 1; + attrs.window_type = OS.GDK_WINDOW_CHILD; + attrs.visual = gdkvisual; + glWindow = OS.gdk_window_new (window, attrs, OS.GDK_WA_VISUAL); + xid = OS.gdk_x11_drawable_get_xid (glWindow); + OS.gdk_window_show (glWindow); + + Listener listener = new Listener () { + public void handleEvent (Event event) { + switch (event.type) { + case SWT.Resize: handleResize (event); break; + } + } + }; + addListener (SWT.Resize, listener); +} + +void handleResize (Event event) { + Rectangle bounds = getBounds (); + GL.glViewport (0, 0, bounds.width, bounds.height); + OS.gdk_window_resize (glWindow, bounds.width, bounds.height); +} + +public boolean isCurrent () { + return GLX.glXGetCurrentContext () == context; +} + +public void setCurrent () { + if (GLX.glXGetCurrentContext () == context) return; + GLX.glXMakeCurrent (xdisplay, xid, context); +} + +public void swapBuffers () { + GLX.glXSwapBuffers (xdisplay, xid); +} +} diff --git a/bundles/org.eclipse.swt.opengl/gtk/org/eclipse/swt/opengl/GLContext.java b/bundles/org.eclipse.swt.opengl/gtk/org/eclipse/swt/opengl/GLContext.java deleted file mode 100644 index 339d5255bb..0000000000 --- a/bundles/org.eclipse.swt.opengl/gtk/org/eclipse/swt/opengl/GLContext.java +++ /dev/null @@ -1,311 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.opengl; - - -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.internal.gtk.*; -import org.eclipse.swt.opengl.internal.gtk.*; - -/** - * Instances of <code>GLContext</code> are used to draw on swt <code>Drawable</code>s - * through invocations of provided OpenGL functions. - * <p> - * Application code must explicitly invoke the <code>GLContext.dispose ()</code> - * method to release the operating system resources managed by each instance - * when those instances are no longer required. This is <em>particularly</em> - * important on Windows95 and Windows98 where the operating system has a limited - * number of device contexts available. - * </p> - */ -public class GLContext { - int handle; - int gc; - GCData data; - Drawable drawable; - int selectBufferPtr = 0; - - static final int MSB_FIRST = 1; - static final int LSB_FIRST = 2; - - /** - * Constructs a new instance of this class which has been - * configured to draw on the specified drawable. - * <p> - * You must dispose the <code>GLContext</code> when it is no longer required. - * </p> - * - * @param drawable the drawable to draw on - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the drawable is null</li> - * </ul> - * @exception SWTError <ul> - * <li>ERROR_NO_HANDLES if a handle could not be obtained for gc creation</li> - * <li>ERROR_UNSUPPORTED_DEPTH - if the current display depth is not supported</li> - * </ul> - */ - public GLContext (Drawable drawable) { - if (drawable == null) SWT.error (SWT.ERROR_NULL_ARGUMENT); - this.drawable = drawable; - data = new GCData (); - gc = drawable.internal_new_GC (data); - if (gc == 0) SWT.error (SWT.ERROR_NO_HANDLES); - int xDisplay = XGTK.gdk_x11_gc_get_xdisplay (gc); - int screen = XGTK.XDefaultScreen (xDisplay); - int depth = XGTK.XDefaultDepthOfScreen (XGTK.XDefaultScreenOfDisplay (xDisplay)); - int attrib [] = { - XGL.GLX_LEVEL, - 0, - XGL.GLX_RGBA, - XGL.GLX_DOUBLEBUFFER, - XGL.GLX_STENCIL_BUFFER_BIT, - 1, -// XGL.GLX_STENCIL_SIZE, -// 8, -// XGL.GLX_DEPTH_SIZE, -// depth, - 0 - }; - int infoPtr = XGL.glXChooseVisual (xDisplay, screen, attrib); - if (infoPtr == 0) SWT.error (SWT.ERROR_UNSUPPORTED_DEPTH); - XVisualInfo info = new XVisualInfo (); - XGL.memmove (info, infoPtr, XVisualInfo.sizeof); - XGTK.XFree (infoPtr); - handle = XGL.glXCreateContext (xDisplay, info, 0, true); - if (handle == 0) SWT.error (SWT.ERROR_NO_HANDLES); - } - - public ImageData convertImageData (ImageData source) { - PaletteData palette = new PaletteData (0xff0000, 0xff00, 0xff); - ImageData newSource = new ImageData (source.width, source.height, 24, palette); - ImageDataUtil.blit ( - 1, - source.data, - source.depth, - source.bytesPerLine, - (source.depth != 16) ? MSB_FIRST : LSB_FIRST, - 0, - 0, - source.width, - source.height, - source.palette.redMask, - source.palette.greenMask, - source.palette.blueMask, - 255, - null, - 0, - 0, - 0, - newSource.data, - newSource.depth, - newSource.bytesPerLine, - (newSource.depth != 16) ? MSB_FIRST : LSB_FIRST, - 0, - 0, - newSource.width, - newSource.height, - newSource.palette.redMask, - newSource.palette.greenMask, - newSource.palette.blueMask, - false, - true); - - return newSource; - } - - /** - * Disposes of the operating system resources associated with - * the receiver. Applications must dispose of all <code>GLContext</code>s - * that they allocate. - */ - public void dispose () { - if (handle == 0) return; - int xDisplay = XGTK.gdk_x11_gc_get_xdisplay (gc); - if (XGL.glXGetCurrentContext () == handle) { - int display = XGTK.gdk_x11_gc_get_xdisplay (gc); - XGL.glXMakeCurrent (display, 0, 0); - } - if (selectBufferPtr != 0) XGTK.free (selectBufferPtr); - XGL.glXDestroyContext (xDisplay, handle); - handle = 0; - // drawable may be disposed - try { - drawable.internal_dispose_GC (gc, data); - } catch (SWTException e) { - } - gc = 0; - data.clipRgn = data.context = data.drawable = 0; - data.font = data.layout = data.style = 0; - drawable = null; - data.device = null; - data.image = null; - data = null; - } - - public int[] getSelectBuffer (int selectBufferPtr, int[] selectBuffer) { - OS.memmove (selectBuffer, selectBufferPtr, selectBuffer.length * 4); - return selectBuffer; - } - - public int getSelectBufferPtr (int[] selectBuffer) { - if (selectBufferPtr == 0) { - selectBufferPtr = XGTK.malloc (selectBuffer.length * 4); - } - OS.memmove (selectBufferPtr, selectBuffer, selectBuffer.length * 4); - return selectBufferPtr; - } - - /** - * Returns a boolean indicating whether the receiver is the current - * <code>GLContext</code>. - * - * @return true if the receiver is the current <code>GLContext</code>, - * false otherwise - * @exception SWTError <ul> - * <li>ERROR_GRAPHIC_DISPOSED if the receiver is disposed</li> - * </ul> - */ - public boolean isCurrent () { - if (isDisposed ()) SWT.error (SWT.ERROR_GRAPHIC_DISPOSED); - return XGL.glXGetCurrentContext () == handle; - } - - /** - * Returns a boolean indicating whether the <code>GLContext</code> has been - * disposed. - * <p> - * This method gets the dispose state for the <code>GLContext</code>. - * When a <code>GLContext</code> has been disposed, it is an error to - * invoke any other method using the <code>GLContext</code>. - * - * @return true if the <code>GLContext</code> is disposed, false otherwise - */ - public boolean isDisposed () { - return handle == 0; - } - - /** - * Loads the specified bitmap font. - * - * @param fdata - * @param device - * @param base - * @param first - * @param count - */ - public void loadBitmapFont (FontData fdata, Device device, int base, int startIndex, int length) { - /* Temporary code, due some problems when running on UTF-8 loadBitmapFont () - * is restrict to works only for ascii. - * Note: en_US.ISO8859-1 also code be used. - */ -// fdata.setLocale ("C"); -// Font font = new Font (device, fdata); -// int fontList = font.handle; -// int[] buffer = new int [1]; -// if (!OS.XmFontListInitFontContext (buffer, fontList)) return; -// int context = buffer [0]; -// XFontStruct fontStruct = new XFontStruct (); -// int fontListEntry; -// int[] fontStructPtr = new int [1]; -// int[] fontNamePtr = new int [1]; -// int xfont = 0; -// // go through each entry in the font list -// while ((fontListEntry = OS.XmFontListNextEntry (context)) != 0) { -// int fontPtr = OS.XmFontListEntryGetFont (fontListEntry, buffer); -// if (buffer [0] == OS.XmFONT_IS_FONT) { -// // FontList contains a single font -// OS.memmove (fontStruct, fontPtr, 20 * 4); -// xfont = fontStruct.fid; -// } else { -// // FontList contains a fontSet -// int nFonts = OS.XFontsOfFontSet (fontPtr, fontStructPtr, fontNamePtr); -// int[] fontStructs = new int [nFonts]; -// OS.memmove (fontStructs, fontStructPtr [0], nFonts * 4); -// // Go through each fontStruct in the font set. -// for (int i = 0; i < nFonts; i++) { -// OS.memmove (fontStruct, fontStructs [i], XFontStruct.sizeof); -// xfont = fontStruct.fid; -// } -// } -// } -// if (xfont != 0) { -// XGL.glXUseXFont (xfont, startIndex, length, base); -// } -// font.dispose (); -// OS.XmFontListFreeFontContext (context); - } - - /** - * Loads the specified outline font. - * - * @param fdata - * @param device - * @param base - * @param first - * @param count - * @param deviation - * @param extrusion - * @param format - * @param lpgmf - */ - public void loadOutlineFont (FontData fdata, Device device, int base, int first, - int count, float deviation, float extrusion, int format, GLYPHMETRICSFLOAT[] lpgmf) { - // stub - } - - /** - * Resizes the receiver. - * - * @param x - * @param y - * @param width - * @param height - */ - public void resize (int x, int y, int width, int height) { - if (height == 0) height = 1; - GL.glViewport (x, y, width, height); - GL.glMatrixMode (GL.GL_PROJECTION); - GL.glLoadIdentity (); - GLU.gluPerspective (45.0f, (float) width / (float) height, 0.1f, 100.0f); - GL.glMatrixMode (GL.GL_MODELVIEW); - GL.glLoadIdentity (); - } - - /** - * Sets the receiver to be the current <code>GLContext</code>. - * - * @exception SWTError <ul> - * <li>ERROR_GRAPHIC_DISPOSED if the receiver is disposed</li> - * </ul> - */ - public void setCurrent () { - if (isDisposed ()) SWT.error (SWT.ERROR_GRAPHIC_DISPOSED); - if (XGL.glXGetCurrentContext () == handle) return; - int display = XGTK.gdk_x11_gc_get_xdisplay (gc); - int drawable = XGTK.gdk_x11_drawable_get_xid (data.drawable); - XGL.glXMakeCurrent (display, drawable, handle); - } - - /** - * Swaps the receiver's buffers. - * - * @exception SWTError <ul> - * <li>ERROR_GRAPHIC_DISPOSED if the receiver is disposed</li> - * </ul> - */ - public void swapBuffers () { - if (isDisposed ()) SWT.error (SWT.ERROR_GRAPHIC_DISPOSED); - int display = XGTK.gdk_x11_gc_get_xdisplay (gc); - int drawable = XGTK.gdk_x11_drawable_get_xid(data.drawable); - XGL.glXSwapBuffers (display, drawable); - } -} diff --git a/bundles/org.eclipse.swt.opengl/gtk/org/eclipse/swt/opengl/internal/gtk/XGTK.java b/bundles/org.eclipse.swt.opengl/gtk/org/eclipse/swt/opengl/internal/gtk/XGTK.java deleted file mode 100644 index 86101786ab..0000000000 --- a/bundles/org.eclipse.swt.opengl/gtk/org/eclipse/swt/opengl/internal/gtk/XGTK.java +++ /dev/null @@ -1,29 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2003 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.opengl.internal.gtk; - -import org.eclipse.swt.opengl.Library; - -public class XGTK { - - static { - Library.loadLibrary("xgtk"); - } - - public static final synchronized native int gdk_x11_gc_get_xdisplay(int gc); - public static final synchronized native int gdk_x11_drawable_get_xid(int gc); - public static final synchronized native int XDefaultScreen(int display); - public static final synchronized native int XDefaultScreenOfDisplay(int display); - public static final synchronized native int XDefaultDepthOfScreen(int screen); - public static final synchronized native int XFree(int address); - public static final synchronized native void free(int ptr); - public static final synchronized native int malloc(int size); -} |