1 /*
2 * Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
455 * met, the native GLXGraphicsConfigInfo structure is initialized for this
456 * GraphicsConfig with the necessary information (GLXFBConfig, etc.)
457 * and a pointer to this structure is returned as a jlong. If
458 * initialization fails at any point, zero is returned, indicating that GLX
459 * cannot be used for this GraphicsConfig (we should fallback on the existing
460 * X11 pipeline).
461 */
462 JNIEXPORT jlong JNICALL
463 Java_sun_java2d_opengl_GLXGraphicsConfig_getGLXConfigInfo(JNIEnv *env,
464 jclass glxgc,
465 jint screennum,
466 jint visnum)
467 {
468 #ifndef HEADLESS
469 OGLContext *oglc;
470 GLXFBConfig fbconfig;
471 GLXContext context;
472 GLXPbuffer scratch;
473 GLXGraphicsConfigInfo *glxinfo;
474 jint caps = CAPS_EMPTY;
475 int db, alpha;
476 const unsigned char *versionstr;
477
478 J2dRlsTraceLn(J2D_TRACE_INFO, "GLXGraphicsConfig_getGLXConfigInfo");
479
480 if (usingXinerama) {
481 // when Xinerama is enabled, the screen ID needs to be 0
482 screennum = 0;
483 }
484
485 fbconfig = GLXGC_InitFBConfig(env, screennum, (VisualID)visnum);
486 if (fbconfig == 0) {
487 J2dRlsTraceLn(J2D_TRACE_ERROR,
488 "GLXGraphicsConfig_getGLXConfigInfo: could not create fbconfig");
489 return 0L;
490 }
491
492 if (sharedContext == 0) {
493 // create the one shared context
494 sharedContext = j2d_glXCreateNewContext(awt_display, fbconfig,
495 GLX_RGBA_TYPE, 0, GL_TRUE);
566 // destroy the temporary resources
567 j2d_glXMakeContextCurrent(awt_display, None, None, NULL);
568
569 J2dRlsTraceLn1(J2D_TRACE_INFO,
570 "GLXGraphicsConfig_getGLXConfigInfo: OpenGL version=%s",
571 (versionstr == NULL) ? "null" : (char *)versionstr);
572
573 if (!OGLContext_IsVersionSupported(versionstr)) {
574 J2dRlsTraceLn(J2D_TRACE_ERROR,
575 "GLXGraphicsConfig_getGLXConfigInfo: OpenGL 1.2 is required");
576 j2d_glXDestroyPbuffer(awt_display, scratch);
577 j2d_glXDestroyContext(awt_display, context);
578 return 0L;
579 }
580
581 // get config-specific capabilities
582 j2d_glXGetFBConfigAttrib(awt_display, fbconfig, GLX_DOUBLEBUFFER, &db);
583 if (db) {
584 caps |= CAPS_DOUBLEBUFFERED;
585 }
586 j2d_glXGetFBConfigAttrib(awt_display, fbconfig, GLX_ALPHA_SIZE, &alpha);
587 if (alpha > 0) {
588 caps |= CAPS_STORED_ALPHA;
589 }
590
591 // initialize the OGLContext, which wraps the GLXFBConfig and GLXContext
592 oglc = GLXGC_InitOGLContext(fbconfig, context, scratch, caps);
593 if (oglc == NULL) {
594 J2dRlsTraceLn(J2D_TRACE_ERROR,
595 "GLXGraphicsConfig_getGLXConfigInfo: could not create oglc");
596 j2d_glXDestroyPbuffer(awt_display, scratch);
597 j2d_glXDestroyContext(awt_display, context);
598 return 0L;
599 }
600
601 J2dTraceLn(J2D_TRACE_VERBOSE,
602 "GLXGraphicsConfig_getGLXConfigInfo: finished checking dependencies");
603
604 // create the GLXGraphicsConfigInfo record for this config
605 glxinfo = (GLXGraphicsConfigInfo *)malloc(sizeof(GLXGraphicsConfigInfo));
606 if (glxinfo == NULL) {
607 J2dRlsTraceLn(J2D_TRACE_ERROR,
608 "GLXGraphicsConfig_getGLXConfigInfo: could not allocate memory for glxinfo");
609 GLXGC_DestroyOGLContext(oglc);
|
1 /*
2 * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
455 * met, the native GLXGraphicsConfigInfo structure is initialized for this
456 * GraphicsConfig with the necessary information (GLXFBConfig, etc.)
457 * and a pointer to this structure is returned as a jlong. If
458 * initialization fails at any point, zero is returned, indicating that GLX
459 * cannot be used for this GraphicsConfig (we should fallback on the existing
460 * X11 pipeline).
461 */
462 JNIEXPORT jlong JNICALL
463 Java_sun_java2d_opengl_GLXGraphicsConfig_getGLXConfigInfo(JNIEnv *env,
464 jclass glxgc,
465 jint screennum,
466 jint visnum)
467 {
468 #ifndef HEADLESS
469 OGLContext *oglc;
470 GLXFBConfig fbconfig;
471 GLXContext context;
472 GLXPbuffer scratch;
473 GLXGraphicsConfigInfo *glxinfo;
474 jint caps = CAPS_EMPTY;
475 int db;
476 const unsigned char *versionstr;
477
478 J2dRlsTraceLn(J2D_TRACE_INFO, "GLXGraphicsConfig_getGLXConfigInfo");
479
480 if (usingXinerama) {
481 // when Xinerama is enabled, the screen ID needs to be 0
482 screennum = 0;
483 }
484
485 fbconfig = GLXGC_InitFBConfig(env, screennum, (VisualID)visnum);
486 if (fbconfig == 0) {
487 J2dRlsTraceLn(J2D_TRACE_ERROR,
488 "GLXGraphicsConfig_getGLXConfigInfo: could not create fbconfig");
489 return 0L;
490 }
491
492 if (sharedContext == 0) {
493 // create the one shared context
494 sharedContext = j2d_glXCreateNewContext(awt_display, fbconfig,
495 GLX_RGBA_TYPE, 0, GL_TRUE);
566 // destroy the temporary resources
567 j2d_glXMakeContextCurrent(awt_display, None, None, NULL);
568
569 J2dRlsTraceLn1(J2D_TRACE_INFO,
570 "GLXGraphicsConfig_getGLXConfigInfo: OpenGL version=%s",
571 (versionstr == NULL) ? "null" : (char *)versionstr);
572
573 if (!OGLContext_IsVersionSupported(versionstr)) {
574 J2dRlsTraceLn(J2D_TRACE_ERROR,
575 "GLXGraphicsConfig_getGLXConfigInfo: OpenGL 1.2 is required");
576 j2d_glXDestroyPbuffer(awt_display, scratch);
577 j2d_glXDestroyContext(awt_display, context);
578 return 0L;
579 }
580
581 // get config-specific capabilities
582 j2d_glXGetFBConfigAttrib(awt_display, fbconfig, GLX_DOUBLEBUFFER, &db);
583 if (db) {
584 caps |= CAPS_DOUBLEBUFFERED;
585 }
586
587 // initialize the OGLContext, which wraps the GLXFBConfig and GLXContext
588 oglc = GLXGC_InitOGLContext(fbconfig, context, scratch, caps);
589 if (oglc == NULL) {
590 J2dRlsTraceLn(J2D_TRACE_ERROR,
591 "GLXGraphicsConfig_getGLXConfigInfo: could not create oglc");
592 j2d_glXDestroyPbuffer(awt_display, scratch);
593 j2d_glXDestroyContext(awt_display, context);
594 return 0L;
595 }
596
597 J2dTraceLn(J2D_TRACE_VERBOSE,
598 "GLXGraphicsConfig_getGLXConfigInfo: finished checking dependencies");
599
600 // create the GLXGraphicsConfigInfo record for this config
601 glxinfo = (GLXGraphicsConfigInfo *)malloc(sizeof(GLXGraphicsConfigInfo));
602 if (glxinfo == NULL) {
603 J2dRlsTraceLn(J2D_TRACE_ERROR,
604 "GLXGraphicsConfig_getGLXConfigInfo: could not allocate memory for glxinfo");
605 GLXGC_DestroyOGLContext(oglc);
|