Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/solaris/native/sun/java2d/opengl/OGLFuncs_md.h
32288 views
/*1* Copyright (c) 2004, 2012, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425#ifndef OGLFuncs_md_h_Included26#define OGLFuncs_md_h_Included2728#include <stdlib.h>29#ifndef MACOSX30#include <dlfcn.h>31#endif32#include "jvm_md.h"33#include "J2D_GL/glx.h"34#include "OGLFuncMacros.h"3536/**37* GLX 1.2 functions38*/39typedef void (GLAPIENTRY *glXDestroyContextType)(Display *dpy, GLXContext ctx);40typedef GLXContext (GLAPIENTRY *glXGetCurrentContextType)(void);41typedef GLXDrawable (GLAPIENTRY *glXGetCurrentDrawableType)(void);42typedef Bool (GLAPIENTRY *glXIsDirectType)(Display *dpy, GLXContext ctx);43typedef Bool (GLAPIENTRY *glXQueryExtensionType)(Display *dpy, int *errorBase, int *eventBase);44typedef Bool (GLAPIENTRY *glXQueryVersionType)(Display *dpy, int *major, int *minor);45typedef void (GLAPIENTRY *glXSwapBuffersType)(Display *dpy, GLXDrawable drawable);46typedef const char * (GLAPIENTRY *glXGetClientStringType)(Display *dpy, int name);47typedef const char * (GLAPIENTRY *glXQueryServerStringType)(Display *dpy, int screen, int name);48typedef const char * (GLAPIENTRY *glXQueryExtensionsStringType)(Display *dpy, int screen);49typedef void (GLAPIENTRY *glXWaitGLType)(void);5051/**52* GLX 1.3 functions53*/54typedef GLXFBConfig * (GLAPIENTRY *glXGetFBConfigsType)(Display *dpy, int screen, int *nelements);55typedef GLXFBConfig * (GLAPIENTRY *glXChooseFBConfigType)(Display *dpy, int screen, const int *attrib_list, int *nelements);56typedef int (GLAPIENTRY *glXGetFBConfigAttribType)(Display *dpy, GLXFBConfig config, int attribute, int *value);57typedef XVisualInfo * (GLAPIENTRY *glXGetVisualFromFBConfigType)(Display *dpy, GLXFBConfig config);58typedef GLXWindow (GLAPIENTRY *glXCreateWindowType)(Display *dpy, GLXFBConfig config, Window win, const int *attrib_list);59typedef void (GLAPIENTRY *glXDestroyWindowType)(Display *dpy, GLXWindow win);60typedef GLXPbuffer (GLAPIENTRY *glXCreatePbufferType)(Display *dpy, GLXFBConfig config, const int *attrib_list);61typedef void (GLAPIENTRY *glXDestroyPbufferType)(Display *dpy, GLXPbuffer pbuffer);62typedef void (GLAPIENTRY *glXQueryDrawableType)(Display *dpy, GLXDrawable draw, int attribute, unsigned int *value);63typedef GLXContext (GLAPIENTRY *glXCreateNewContextType)(Display *dpy, GLXFBConfig config, int render_type, GLXContext share_list, Bool direct);64typedef Bool (GLAPIENTRY *glXMakeContextCurrentType)(Display *dpy, GLXDrawable draw, GLXDrawable read, GLXContext ctx);65typedef GLXDrawable (GLAPIENTRY *glXGetCurrentReadDrawableType)(void);66typedef int (GLAPIENTRY *glXQueryContextType)(Display *dpy, GLXContext ctx, int attribute, int *value);67typedef void (GLAPIENTRY *glXSelectEventType)(Display *dpy, GLXDrawable draw, unsigned long event_mask);68typedef void (GLAPIENTRY *glXGetSelectedEventType)(Display *dpy, GLXDrawable draw, unsigned long *event_mask);6970/**71* GLX extension functions72*/73typedef void * (GLAPIENTRY *glXGetProcAddressType)(const char *);7475/*76* Note: Historically we have used dlopen/dlsym() to load function pointers77* from libgl.so, and things have worked fine. However, we have run into at78* least one case (on ATI's Linux drivers) where dlsym() will return NULL79* when trying to load functions from the GL_ARB_fragment_shader extension.80* Plausibly this is a bug in their drivers (other extension functions load81* just fine on those same drivers), but for a number of years there has been82* a glXGetProcAddressARB() extension available that is intended to be the83* primary means for an application to load extension functions in a reliable84* manner. So while dlsym() will return NULL for those shader-related85* functions, glXGetProcAddressARB() works just fine.86*87* I haven't used the glXGetProcAddress() approach in the past because it88* seemed unnecessary (i.e. dlsym() was working fine), but upon further89* reading I think we should use glXGetProcAddress() in favor of dlsym(),90* not only to work around this "bug", but also to be safer going forward.91*92* Just to complicate matters, glXGetProcAddress() was proposed to be added93* into the GLX 1.4 spec, which is still (as yet) unfinalized. Sun's OGL 1.394* implementation reports its GLX version as 1.4, and therefore includes95* the glXGetProcAddress() entrypoint, but does not include96* GLX_ARB_get_proc_address in its extension string nor does it export the97* glXGetProcAddressARB() entrypoint. On the other hand, ATI's Linux drivers98* (as well as Nvidia's Linux and Solaris drivers) currently report their99* GLX version as 1.3, but they do export the glXGetProcAddressARB()100* entrypoint and its associated extension string. So to make this work101* everywhere, we first try to load the glXGetProcAddress() entrypoint,102* failing that we try the glXGetProcAddressARB() entrypoint, and if that103* fails too, then we close libGL.so and do not bother trying to initialize104* the rest of the OGL pipeline.105*/106107#define OGL_LIB_HANDLE pLibGL108#define OGL_DECLARE_LIB_HANDLE() \109static glXGetProcAddressType j2d_glXGetProcAddress; \110static void *OGL_LIB_HANDLE = NULL111#define OGL_LIB_IS_UNINITIALIZED() \112(OGL_LIB_HANDLE == NULL)113#define OGL_OPEN_LIB() \114do { \115{ \116char *libGLPath = getenv("J2D_ALT_LIBGL_PATH"); \117if (libGLPath == NULL) { \118libGLPath = VERSIONED_JNI_LIB_NAME("GL", "1"); \119} \120OGL_LIB_HANDLE = dlopen(libGLPath, RTLD_LAZY | RTLD_LOCAL); \121} \122if (OGL_LIB_HANDLE) { \123j2d_glXGetProcAddress = (glXGetProcAddressType) \124dlsym(OGL_LIB_HANDLE, "glXGetProcAddress"); \125if (j2d_glXGetProcAddress == NULL) { \126j2d_glXGetProcAddress = (glXGetProcAddressType) \127dlsym(OGL_LIB_HANDLE, "glXGetProcAddressARB"); \128if (j2d_glXGetProcAddress == NULL) { \129dlclose(OGL_LIB_HANDLE); \130OGL_LIB_HANDLE = NULL; \131} \132} \133} \134} while (0)135#define OGL_CLOSE_LIB() \136dlclose(OGL_LIB_HANDLE)137#define OGL_GET_PROC_ADDRESS(f) \138j2d_glXGetProcAddress(#f)139#define OGL_GET_EXT_PROC_ADDRESS(f) \140OGL_GET_PROC_ADDRESS(f)141142#define OGL_EXPRESS_PLATFORM_FUNCS(action) \143OGL_##action##_FUNC(glXDestroyContext); \144OGL_##action##_FUNC(glXGetCurrentContext); \145OGL_##action##_FUNC(glXGetCurrentDrawable); \146OGL_##action##_FUNC(glXIsDirect); \147OGL_##action##_FUNC(glXQueryExtension); \148OGL_##action##_FUNC(glXQueryVersion); \149OGL_##action##_FUNC(glXSwapBuffers); \150OGL_##action##_FUNC(glXGetClientString); \151OGL_##action##_FUNC(glXQueryServerString); \152OGL_##action##_FUNC(glXQueryExtensionsString); \153OGL_##action##_FUNC(glXWaitGL); \154OGL_##action##_FUNC(glXGetFBConfigs); \155OGL_##action##_FUNC(glXChooseFBConfig); \156OGL_##action##_FUNC(glXGetFBConfigAttrib); \157OGL_##action##_FUNC(glXGetVisualFromFBConfig); \158OGL_##action##_FUNC(glXCreateWindow); \159OGL_##action##_FUNC(glXDestroyWindow); \160OGL_##action##_FUNC(glXCreatePbuffer); \161OGL_##action##_FUNC(glXDestroyPbuffer); \162OGL_##action##_FUNC(glXQueryDrawable); \163OGL_##action##_FUNC(glXCreateNewContext); \164OGL_##action##_FUNC(glXMakeContextCurrent); \165OGL_##action##_FUNC(glXGetCurrentReadDrawable); \166OGL_##action##_FUNC(glXQueryContext); \167OGL_##action##_FUNC(glXSelectEvent); \168OGL_##action##_FUNC(glXGetSelectedEvent);169170#define OGL_EXPRESS_PLATFORM_EXT_FUNCS(action)171172#endif /* OGLFuncs_md_h_Included */173174175