0N/A/*
2362N/A * Copyright (c) 2004, 2006, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A#ifndef OGLFuncs_md_h_Included
0N/A#define OGLFuncs_md_h_Included
0N/A
0N/A#include <stdlib.h>
5306N/A#ifndef MACOSX
5306N/A#include <dlfcn.h>
5306N/A#endif
4632N/A#include "jvm_md.h"
0N/A#include "J2D_GL/glx.h"
0N/A#include "OGLFuncMacros.h"
0N/A
0N/A/**
0N/A * GLX 1.2 functions
0N/A */
0N/Atypedef void (GLAPIENTRY *glXDestroyContextType)(Display *dpy, GLXContext ctx);
0N/Atypedef GLXContext (GLAPIENTRY *glXGetCurrentContextType)(void);
0N/Atypedef GLXDrawable (GLAPIENTRY *glXGetCurrentDrawableType)(void);
0N/Atypedef Bool (GLAPIENTRY *glXIsDirectType)(Display *dpy, GLXContext ctx);
0N/Atypedef Bool (GLAPIENTRY *glXQueryExtensionType)(Display *dpy, int *errorBase, int *eventBase);
0N/Atypedef Bool (GLAPIENTRY *glXQueryVersionType)(Display *dpy, int *major, int *minor);
0N/Atypedef void (GLAPIENTRY *glXSwapBuffersType)(Display *dpy, GLXDrawable drawable);
0N/Atypedef const char * (GLAPIENTRY *glXGetClientStringType)(Display *dpy, int name);
0N/Atypedef const char * (GLAPIENTRY *glXQueryServerStringType)(Display *dpy, int screen, int name);
0N/Atypedef const char * (GLAPIENTRY *glXQueryExtensionsStringType)(Display *dpy, int screen);
0N/Atypedef void (GLAPIENTRY *glXWaitGLType)(void);
0N/A
0N/A/**
0N/A * GLX 1.3 functions
0N/A */
0N/Atypedef GLXFBConfig * (GLAPIENTRY *glXGetFBConfigsType)(Display *dpy, int screen, int *nelements);
0N/Atypedef GLXFBConfig * (GLAPIENTRY *glXChooseFBConfigType)(Display *dpy, int screen, const int *attrib_list, int *nelements);
0N/Atypedef int (GLAPIENTRY *glXGetFBConfigAttribType)(Display *dpy, GLXFBConfig config, int attribute, int *value);
0N/Atypedef XVisualInfo * (GLAPIENTRY *glXGetVisualFromFBConfigType)(Display *dpy, GLXFBConfig config);
0N/Atypedef GLXWindow (GLAPIENTRY *glXCreateWindowType)(Display *dpy, GLXFBConfig config, Window win, const int *attrib_list);
0N/Atypedef void (GLAPIENTRY *glXDestroyWindowType)(Display *dpy, GLXWindow win);
0N/Atypedef GLXPbuffer (GLAPIENTRY *glXCreatePbufferType)(Display *dpy, GLXFBConfig config, const int *attrib_list);
0N/Atypedef void (GLAPIENTRY *glXDestroyPbufferType)(Display *dpy, GLXPbuffer pbuffer);
0N/Atypedef void (GLAPIENTRY *glXQueryDrawableType)(Display *dpy, GLXDrawable draw, int attribute, unsigned int *value);
0N/Atypedef GLXContext (GLAPIENTRY *glXCreateNewContextType)(Display *dpy, GLXFBConfig config, int render_type, GLXContext share_list, Bool direct);
0N/Atypedef Bool (GLAPIENTRY *glXMakeContextCurrentType)(Display *dpy, GLXDrawable draw, GLXDrawable read, GLXContext ctx);
0N/Atypedef GLXDrawable (GLAPIENTRY *glXGetCurrentReadDrawableType)(void);
0N/Atypedef int (GLAPIENTRY *glXQueryContextType)(Display *dpy, GLXContext ctx, int attribute, int *value);
0N/Atypedef void (GLAPIENTRY *glXSelectEventType)(Display *dpy, GLXDrawable draw, unsigned long event_mask);
0N/Atypedef void (GLAPIENTRY *glXGetSelectedEventType)(Display *dpy, GLXDrawable draw, unsigned long *event_mask);
0N/A
0N/A/**
0N/A * GLX extension functions
0N/A */
0N/Atypedef void * (GLAPIENTRY *glXGetProcAddressType)(const char *);
0N/A
0N/A/*
0N/A * Note: Historically we have used dlopen/dlsym() to load function pointers
0N/A * from libgl.so, and things have worked fine. However, we have run into at
0N/A * least one case (on ATI's Linux drivers) where dlsym() will return NULL
0N/A * when trying to load functions from the GL_ARB_fragment_shader extension.
0N/A * Plausibly this is a bug in their drivers (other extension functions load
0N/A * just fine on those same drivers), but for a number of years there has been
0N/A * a glXGetProcAddressARB() extension available that is intended to be the
0N/A * primary means for an application to load extension functions in a reliable
0N/A * manner. So while dlsym() will return NULL for those shader-related
0N/A * functions, glXGetProcAddressARB() works just fine.
0N/A *
0N/A * I haven't used the glXGetProcAddress() approach in the past because it
0N/A * seemed unnecessary (i.e. dlsym() was working fine), but upon further
0N/A * reading I think we should use glXGetProcAddress() in favor of dlsym(),
0N/A * not only to work around this "bug", but also to be safer going forward.
0N/A *
0N/A * Just to complicate matters, glXGetProcAddress() was proposed to be added
0N/A * into the GLX 1.4 spec, which is still (as yet) unfinalized. Sun's OGL 1.3
0N/A * implementation reports its GLX version as 1.4, and therefore includes
0N/A * the glXGetProcAddress() entrypoint, but does not include
0N/A * GLX_ARB_get_proc_address in its extension string nor does it export the
0N/A * glXGetProcAddressARB() entrypoint. On the other hand, ATI's Linux drivers
0N/A * (as well as Nvidia's Linux and Solaris drivers) currently report their
0N/A * GLX version as 1.3, but they do export the glXGetProcAddressARB()
0N/A * entrypoint and its associated extension string. So to make this work
0N/A * everywhere, we first try to load the glXGetProcAddress() entrypoint,
0N/A * failing that we try the glXGetProcAddressARB() entrypoint, and if that
0N/A * fails too, then we close libGL.so and do not bother trying to initialize
0N/A * the rest of the OGL pipeline.
0N/A */
0N/A
0N/A#define OGL_LIB_HANDLE pLibGL
0N/A#define OGL_DECLARE_LIB_HANDLE() \
0N/A static glXGetProcAddressType j2d_glXGetProcAddress; \
0N/A static void *OGL_LIB_HANDLE = NULL
0N/A#define OGL_LIB_IS_UNINITIALIZED() \
0N/A (OGL_LIB_HANDLE == NULL)
0N/A#define OGL_OPEN_LIB() \
0N/Ado { \
0N/A { \
0N/A char *libGLPath = getenv("J2D_ALT_LIBGL_PATH"); \
0N/A if (libGLPath == NULL) { \
4632N/A libGLPath = VERSIONED_JNI_LIB_NAME("GL", "1"); \
0N/A } \
0N/A OGL_LIB_HANDLE = dlopen(libGLPath, RTLD_LAZY | RTLD_LOCAL); \
0N/A } \
0N/A if (OGL_LIB_HANDLE) { \
0N/A j2d_glXGetProcAddress = (glXGetProcAddressType) \
0N/A dlsym(OGL_LIB_HANDLE, "glXGetProcAddress"); \
0N/A if (j2d_glXGetProcAddress == NULL) { \
0N/A j2d_glXGetProcAddress = (glXGetProcAddressType) \
0N/A dlsym(OGL_LIB_HANDLE, "glXGetProcAddressARB"); \
0N/A if (j2d_glXGetProcAddress == NULL) { \
0N/A dlclose(OGL_LIB_HANDLE); \
0N/A OGL_LIB_HANDLE = NULL; \
0N/A } \
0N/A } \
0N/A } \
0N/A} while (0)
0N/A#define OGL_CLOSE_LIB() \
0N/A dlclose(OGL_LIB_HANDLE)
0N/A#define OGL_GET_PROC_ADDRESS(f) \
0N/A j2d_glXGetProcAddress(#f)
0N/A#define OGL_GET_EXT_PROC_ADDRESS(f) \
0N/A OGL_GET_PROC_ADDRESS(f)
0N/A
0N/A#define OGL_EXPRESS_PLATFORM_FUNCS(action) \
0N/A OGL_##action##_FUNC(glXDestroyContext); \
0N/A OGL_##action##_FUNC(glXGetCurrentContext); \
0N/A OGL_##action##_FUNC(glXGetCurrentDrawable); \
0N/A OGL_##action##_FUNC(glXIsDirect); \
0N/A OGL_##action##_FUNC(glXQueryExtension); \
0N/A OGL_##action##_FUNC(glXQueryVersion); \
0N/A OGL_##action##_FUNC(glXSwapBuffers); \
0N/A OGL_##action##_FUNC(glXGetClientString); \
0N/A OGL_##action##_FUNC(glXQueryServerString); \
0N/A OGL_##action##_FUNC(glXQueryExtensionsString); \
0N/A OGL_##action##_FUNC(glXWaitGL); \
0N/A OGL_##action##_FUNC(glXGetFBConfigs); \
0N/A OGL_##action##_FUNC(glXChooseFBConfig); \
0N/A OGL_##action##_FUNC(glXGetFBConfigAttrib); \
0N/A OGL_##action##_FUNC(glXGetVisualFromFBConfig); \
0N/A OGL_##action##_FUNC(glXCreateWindow); \
0N/A OGL_##action##_FUNC(glXDestroyWindow); \
0N/A OGL_##action##_FUNC(glXCreatePbuffer); \
0N/A OGL_##action##_FUNC(glXDestroyPbuffer); \
0N/A OGL_##action##_FUNC(glXQueryDrawable); \
0N/A OGL_##action##_FUNC(glXCreateNewContext); \
0N/A OGL_##action##_FUNC(glXMakeContextCurrent); \
0N/A OGL_##action##_FUNC(glXGetCurrentReadDrawable); \
0N/A OGL_##action##_FUNC(glXQueryContext); \
0N/A OGL_##action##_FUNC(glXSelectEvent); \
0N/A OGL_##action##_FUNC(glXGetSelectedEvent);
0N/A
0N/A#define OGL_EXPRESS_PLATFORM_EXT_FUNCS(action)
0N/A
0N/A#endif /* OGLFuncs_md_h_Included */