/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
#include <stdlib.h>
#include <string.h>
#include "sun_java2d_opengl_GLXGraphicsConfig.h"
#include "jni.h"
#include "jlong.h"
#include "GLXGraphicsConfig.h"
#include "GLXSurfaceData.h"
#include "awt_GraphicsEnv.h"
#include "awt_util.h"
#ifndef HEADLESS
extern Bool usingXinerama;
/**
* This is a globally shared context used when creating textures. When any
* new contexts are created, they specify this context as the "share list"
* context, which means any texture objects created when this shared context
* is current will be available to any other context.
*/
/**
* Attempts to initialize GLX and the core OpenGL library. For this method
* to return JNI_TRUE, the following must be true:
* - libGL must be loaded successfully (via dlopen)
* - all function symbols from libGL must be available and loaded properly
* - the GLX extension must be available through X11
* - client GLX version must be >= 1.3
* If any of these requirements are not met, this method will return
* GraphicsConfig in the environment.
*/
static jboolean
{
const char *version;
if (!OGLFuncs_OpenLibrary()) {
return JNI_FALSE;
}
if (!OGLFuncs_InitPlatformFuncs() ||
!OGLFuncs_InitBaseFuncs() ||
{
return JNI_FALSE;
}
"GLXGC_InitGLX: GLX extension is not present");
return JNI_FALSE;
}
"GLXGC_InitGLX: could not query GLX version");
return JNI_FALSE;
}
// we now only verify that the client GLX version is >= 1.3 (if the
// server does not support GLX 1.3, then we will find that out later
// when we attempt to create a GLXFBConfig)
"GLXGC_InitGLX: client GLX version=%s", version);
"GLXGC_InitGLX: invalid GLX version; 1.3 is required");
return JNI_FALSE;
}
return JNI_TRUE;
}
/**
* Returns JNI_TRUE if GLX is available for the current display. Note that
* this method will attempt to initialize GLX (and all the necessary function
* symbols) if it has not been already. The AWT_LOCK must be acquired before
* calling this method.
*/
{
if (firstTime) {
}
return glxAvailable;
}
/**
* Disposes all memory and resources allocated for the given OGLContext.
*/
static void
{
"GLXGC_DestroyOGLContext: context is null");
return;
}
// at this point, this context will be current to its scratch surface
// release the current context before we continue
}
if (ctxinfo->scratchSurface != 0) {
}
}
}
/**
* Disposes all memory and resources associated with the given
* GLXGraphicsConfigInfo (including its native OGLContext data).
*/
void
{
"OGLGC_DestroyOGLGraphicsConfig: info is null");
return;
}
}
}
/**
* Attempts to create a new GLXFBConfig for the requested screen and visual.
* If visualid is 0, this method will iterate through all GLXFBConfigs (if
* any) that match the requested attributes and will attempt to find an
* fbconfig with a minimal combined depth+stencil buffer. Note that we
* currently only need depth capabilities (for shape clipping purposes), but
* glXChooseFBConfig() will often return a list of fbconfigs with the largest
* depth buffer (and stencil) sizes at the top of the list. Therefore, we
* scan through the whole list to find the most VRAM-efficient fbconfig.
* If visualid is non-zero, the GLXFBConfig associated with the given visual
* is chosen (assuming it meets the requested attributes). If there are no
* valid GLXFBConfigs available, this method returns 0.
*/
static GLXFBConfig
{
int nconfs, i;
0};
// this is the initial minimum value for the combined depth+stencil size
// (we initialize it to some absurdly high value; realistic values will
// be much less than this number)
// find all fbconfigs for this screen with the provided attributes
"GLXGC_InitFBConfig: could not find any valid fbconfigs");
return 0;
}
// iterate through the list of fbconfigs, looking for the one that matches
// the requested VisualID and supports RGBA rendering as well as the
// creation of windows and pbuffers
for (i = 0; i < nconfs; i++) {
// get VisualID from GLXFBConfig
continue;
}
// get GLX-specific attributes from GLXFBConfig
GLX_RENDER_TYPE, &rtype);
GLX_DEPTH_SIZE, &depth);
// these attributes don't affect our decision, but they are
// interesting for trace logs, so we will query them anyway
GLX_DOUBLEBUFFER, &db);
GLX_ALPHA_SIZE, &alpha);
"[V] id=0x%x db=%d alpha=%d depth=%d stencil=%d valid=",
#ifdef __sparc
/*
* Sun's OpenGL implementation will always
* return at least two GLXFBConfigs (visuals) from
* glXChooseFBConfig(). The first will be a linear (gamma
* corrected) visual; the second will have the same capabilities
* as the first, except it will be a non-linear (non-gamma
* corrected) visual, which is the one we want, otherwise
* everything will look "washed out". So we will reject any
* visuals that have gamma values other than 1.0 (the value
* returned by glXGetFBConfigAttrib() will be scaled
* by 100, so 100 corresponds to a gamma value of 1.0, 220
* corresponds to 2.2, and so on).
*/
if (gamma != 100) {
continue;
}
#endif /* __sparc */
if ((dtype & GLX_WINDOW_BIT) &&
(dtype & GLX_PBUFFER_BIT) &&
(rtype & GLX_RGBA_BIT) &&
(depth >= 16))
{
if (visualid == 0) {
// when visualid == 0, we loop through all configs
// looking for an fbconfig that has the smallest combined
// depth+stencil size (this keeps VRAM usage to a minimum)
chosenConfig = fbc;
} else {
"false (large depth)\n");
}
continue;
} else {
// in this case, visualid == fbvisualid, which means
// we've found a valid fbconfig corresponding to the
// requested VisualID, so break out of the loop
chosenConfig = fbc;
break;
}
} else {
}
}
}
// free the list of fbconfigs
if (chosenConfig == 0) {
"GLXGC_InitFBConfig: could not find an appropriate fbconfig");
return 0;
}
return chosenConfig;
}
/**
* Returns the X11 VisualID that corresponds to the best GLXFBConfig for the
* given screen. If no valid visual could be found, this method returns zero.
* Note that this method will attempt to initialize GLX (and all the
* necessary function symbols) if it has not been already. The AWT_LOCK
* must be acquired before calling this method.
*/
{
if (!GLXGC_IsGLXAvailable()) {
"GLXGC_FindBestVisual: could not initialize GLX");
return 0;
}
if (fbc == 0) {
"GLXGC_FindBestVisual: could not find best visual");
return 0;
}
"GLXGC_FindBestVisual: could not get visual for fbconfig");
return 0;
}
"GLXGC_FindBestVisual: chose 0x%x as the best visual for screen %d",
return visualid;
}
/**
* Creates a scratch pbuffer, which can be used to make a context current
* for extension queries, etc.
*/
static GLXPbuffer
{
0};
}
/**
* Initializes a new OGLContext, which includes the native GLXContext handle
* and some other important information such as the associated GLXFBConfig.
*/
static OGLContext *
{
"GLXGC_InitOGLContext: could not allocate memory for oglc");
return NULL;
}
"GLXGC_InitOGLContext: could not allocate memory for ctxinfo");
return NULL;
}
return oglc;
}
#endif /* !HEADLESS */
/**
* Determines whether the GLX pipeline can be used for a given GraphicsConfig
* provided its screen number and visual ID. If the minimum requirements are
* met, the native GLXGraphicsConfigInfo structure is initialized for this
* GraphicsConfig with the necessary information (GLXFBConfig, etc.)
* and a pointer to this structure is returned as a jlong. If
* initialization fails at any point, zero is returned, indicating that GLX
* cannot be used for this GraphicsConfig (we should fallback on the existing
* X11 pipeline).
*/
{
#ifndef HEADLESS
const unsigned char *versionstr;
if (usingXinerama) {
// when Xinerama is enabled, the screen ID needs to be 0
screennum = 0;
}
if (fbconfig == 0) {
"GLXGraphicsConfig_getGLXConfigInfo: could not create fbconfig");
return 0L;
}
if (sharedContext == 0) {
// create the one shared context
GLX_RGBA_TYPE, 0, GL_TRUE);
if (sharedContext == 0) {
"GLXGraphicsConfig_getGLXConfigInfo: could not create shared context");
return 0L;
}
}
// create the GLXContext for this GLXGraphicsConfig
GL_TRUE);
if (context == 0) {
"GLXGraphicsConfig_getGLXConfigInfo: could not create GLX context");
return 0L;
}
// this is pretty sketchy, but it seems to be the easiest way to create
// some form of GLXDrawable using only the display and a GLXFBConfig
// (in order to make the context current for checking the version,
// extensions, etc)...
if (scratch == 0) {
"GLXGraphicsConfig_getGLXConfigInfo: could not create scratch pbuffer");
return 0L;
}
// the context must be made current before we can query the
// version and extension strings
#ifdef __sparc
/*
* 6438225: The software rasterizer used by Sun's OpenGL libraries
* for certain boards has quality issues, and besides, performance
* of these boards is not high enough to justify the use of the
* OpenGL-based Java 2D pipeline. If we detect one of the following
* boards via the GL_RENDERER string, just give up:
* - FFB[2[+]] ("Creator[3D]")
* - PGX-series ("m64")
* - AFB ("Elite3D")
*/
{
"GLXGraphicsConfig_getGLXConfigInfo: detected renderer (%s)",
{
"GLXGraphicsConfig_getGLXConfigInfo: unsupported board (%s)",
return 0L;
}
}
#endif /* __sparc */
// destroy the temporary resources
"GLXGraphicsConfig_getGLXConfigInfo: OpenGL version=%s",
if (!OGLContext_IsVersionSupported(versionstr)) {
"GLXGraphicsConfig_getGLXConfigInfo: OpenGL 1.2 is required");
return 0L;
}
// get config-specific capabilities
if (db) {
}
if (alpha > 0) {
}
// initialize the OGLContext, which wraps the GLXFBConfig and GLXContext
"GLXGraphicsConfig_getGLXConfigInfo: could not create oglc");
return 0L;
}
"GLXGraphicsConfig_getGLXConfigInfo: finished checking dependencies");
// create the GLXGraphicsConfigInfo record for this config
"GLXGraphicsConfig_getGLXConfigInfo: could not allocate memory for glxinfo");
return 0L;
}
return ptr_to_jlong(glxinfo);
#else
return 0L;
#endif /* !HEADLESS */
}
{
#ifndef HEADLESS
if (configData == NULL) {
return;
}
"GLXGraphicsConfigInfo data missing");
return;
}
#endif /* !HEADLESS */
}
{
#ifndef HEADLESS
return CAPS_EMPTY;
}
#else
return CAPS_EMPTY;
#endif /* !HEADLESS */
}