src/solaris/native/sun/java2d/opengl/GLXSurfaceData.c

Print this page


   1 /*
   2  * Copyright (c) 2003, 2010, 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


  31 #include "GLXGraphicsConfig.h"
  32 #include "GLXSurfaceData.h"
  33 #include "awt_Component.h"
  34 #include "awt_GraphicsEnv.h"
  35 
  36 /**
  37  * The methods in this file implement the native windowing system specific
  38  * layer (GLX) for the OpenGL-based Java 2D pipeline.
  39  */
  40 
  41 #ifndef HEADLESS
  42 
  43 extern LockFunc       OGLSD_Lock;
  44 extern GetRasInfoFunc OGLSD_GetRasInfo;
  45 extern UnlockFunc     OGLSD_Unlock;
  46 extern DisposeFunc    OGLSD_Dispose;
  47 
  48 extern void
  49     OGLSD_SetNativeDimensions(JNIEnv *env, OGLSDOps *oglsdo, jint w, jint h);
  50 
  51 jboolean surfaceCreationFailed = JNI_FALSE;
  52 
  53 #endif /* !HEADLESS */
  54 
  55 JNIEXPORT void JNICALL
  56 Java_sun_java2d_opengl_GLXSurfaceData_initOps(JNIEnv *env, jobject glxsd,
  57                                               jobject peer, jlong aData)
  58 {
  59 #ifndef HEADLESS
  60     OGLSDOps *oglsdo = (OGLSDOps *)SurfaceData_InitOps(env, glxsd,
  61                                                        sizeof(OGLSDOps));
  62     GLXSDOps *glxsdo = (GLXSDOps *)malloc(sizeof(GLXSDOps));
  63 
  64     J2dTraceLn(J2D_TRACE_INFO, "GLXSurfaceData_initOps");
  65 
  66     if (oglsdo == NULL) {
  67         JNU_ThrowOutOfMemoryError(env, "Initialization of SurfaceData failed.");
  68         return;
  69     }
  70 
  71     if (glxsdo == NULL) {
  72         JNU_ThrowOutOfMemoryError(env, "creating native GLX ops");


 331         return JNI_FALSE;
 332     }
 333 
 334     XGetWindowAttributes(awt_display, window, &attr);
 335     oglsdo->width = attr.width;
 336     oglsdo->height = attr.height;
 337 
 338     oglsdo->drawableType = OGLSD_WINDOW;
 339     oglsdo->isOpaque = JNI_TRUE;
 340     oglsdo->xOffset = 0;
 341     oglsdo->yOffset = 0;
 342     glxsdo->drawable = window;
 343     glxsdo->xdrawable = window;
 344 
 345     J2dTraceLn2(J2D_TRACE_VERBOSE, "  created window: w=%d h=%d",
 346                 oglsdo->width, oglsdo->height);
 347 
 348     return JNI_TRUE;
 349 }
 350 
 351 static int
 352 GLXSD_BadAllocXErrHandler(Display *display, XErrorEvent *xerr)
 353 {
 354     int ret = 0;
 355     if (xerr->error_code == BadAlloc) {
 356         surfaceCreationFailed = JNI_TRUE;
 357     } else {
 358         ret = (*xerror_saved_handler)(display, xerr);
 359     }
 360     return ret;
 361 }
 362 
 363 JNIEXPORT jboolean JNICALL
 364 Java_sun_java2d_opengl_GLXSurfaceData_initPbuffer
 365     (JNIEnv *env, jobject glxsd,
 366      jlong pData, jlong pConfigInfo,
 367      jboolean isOpaque,
 368      jint width, jint height)
 369 {
 370     OGLSDOps *oglsdo = (OGLSDOps *)jlong_to_ptr(pData);
 371     GLXGraphicsConfigInfo *glxinfo =
 372         (GLXGraphicsConfigInfo *)jlong_to_ptr(pConfigInfo);
 373     GLXSDOps *glxsdo;
 374     GLXPbuffer pbuffer;
 375     int attrlist[] = {GLX_PBUFFER_WIDTH, 0,
 376                       GLX_PBUFFER_HEIGHT, 0,
 377                       GLX_PRESERVED_CONTENTS, GL_FALSE, 0};
 378 
 379     J2dTraceLn3(J2D_TRACE_INFO,
 380                 "GLXSurfaceData_initPbuffer: w=%d h=%d opq=%d",
 381                 width, height, isOpaque);
 382 


 385                       "GLXSurfaceData_initPbuffer: ops are null");
 386         return JNI_FALSE;
 387     }
 388 
 389     glxsdo = (GLXSDOps *)oglsdo->privOps;
 390     if (glxsdo == NULL) {
 391         J2dRlsTraceLn(J2D_TRACE_ERROR,
 392                       "GLXSurfaceData_initPbuffer: glx ops are null");
 393         return JNI_FALSE;
 394     }
 395 
 396     if (glxinfo == NULL) {
 397         J2dRlsTraceLn(J2D_TRACE_ERROR,
 398                       "GLXSurfaceData_initPbuffer: glx config info is null");
 399         return JNI_FALSE;
 400     }
 401 
 402     attrlist[1] = width;
 403     attrlist[3] = height;
 404 
 405     surfaceCreationFailed = JNI_FALSE;
 406     EXEC_WITH_XERROR_HANDLER(
 407         GLXSD_BadAllocXErrHandler,
 408         pbuffer = j2d_glXCreatePbuffer(awt_display,
 409                                        glxinfo->fbconfig, attrlist));
 410     if ((pbuffer == 0) || surfaceCreationFailed) {


 411         J2dRlsTraceLn(J2D_TRACE_ERROR,
 412             "GLXSurfaceData_initPbuffer: could not create glx pbuffer");
 413         return JNI_FALSE;
 414     }
 415 
 416     oglsdo->drawableType = OGLSD_PBUFFER;
 417     oglsdo->isOpaque = isOpaque;
 418     oglsdo->width = width;
 419     oglsdo->height = height;
 420     oglsdo->xOffset = 0;
 421     oglsdo->yOffset = 0;
 422 
 423     glxsdo->drawable = pbuffer;
 424     glxsdo->xdrawable = 0;
 425 
 426     OGLSD_SetNativeDimensions(env, oglsdo, width, height);
 427 
 428     return JNI_TRUE;
 429 }
 430 


   1 /*
   2  * Copyright (c) 2003, 2013, 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


  31 #include "GLXGraphicsConfig.h"
  32 #include "GLXSurfaceData.h"
  33 #include "awt_Component.h"
  34 #include "awt_GraphicsEnv.h"
  35 
  36 /**
  37  * The methods in this file implement the native windowing system specific
  38  * layer (GLX) for the OpenGL-based Java 2D pipeline.
  39  */
  40 
  41 #ifndef HEADLESS
  42 
  43 extern LockFunc       OGLSD_Lock;
  44 extern GetRasInfoFunc OGLSD_GetRasInfo;
  45 extern UnlockFunc     OGLSD_Unlock;
  46 extern DisposeFunc    OGLSD_Dispose;
  47 
  48 extern void
  49     OGLSD_SetNativeDimensions(JNIEnv *env, OGLSDOps *oglsdo, jint w, jint h);
  50 


  51 #endif /* !HEADLESS */
  52 
  53 JNIEXPORT void JNICALL
  54 Java_sun_java2d_opengl_GLXSurfaceData_initOps(JNIEnv *env, jobject glxsd,
  55                                               jobject peer, jlong aData)
  56 {
  57 #ifndef HEADLESS
  58     OGLSDOps *oglsdo = (OGLSDOps *)SurfaceData_InitOps(env, glxsd,
  59                                                        sizeof(OGLSDOps));
  60     GLXSDOps *glxsdo = (GLXSDOps *)malloc(sizeof(GLXSDOps));
  61 
  62     J2dTraceLn(J2D_TRACE_INFO, "GLXSurfaceData_initOps");
  63 
  64     if (oglsdo == NULL) {
  65         JNU_ThrowOutOfMemoryError(env, "Initialization of SurfaceData failed.");
  66         return;
  67     }
  68 
  69     if (glxsdo == NULL) {
  70         JNU_ThrowOutOfMemoryError(env, "creating native GLX ops");


 329         return JNI_FALSE;
 330     }
 331 
 332     XGetWindowAttributes(awt_display, window, &attr);
 333     oglsdo->width = attr.width;
 334     oglsdo->height = attr.height;
 335 
 336     oglsdo->drawableType = OGLSD_WINDOW;
 337     oglsdo->isOpaque = JNI_TRUE;
 338     oglsdo->xOffset = 0;
 339     oglsdo->yOffset = 0;
 340     glxsdo->drawable = window;
 341     glxsdo->xdrawable = window;
 342 
 343     J2dTraceLn2(J2D_TRACE_VERBOSE, "  created window: w=%d h=%d",
 344                 oglsdo->width, oglsdo->height);
 345 
 346     return JNI_TRUE;
 347 }
 348 












 349 JNIEXPORT jboolean JNICALL
 350 Java_sun_java2d_opengl_GLXSurfaceData_initPbuffer
 351     (JNIEnv *env, jobject glxsd,
 352      jlong pData, jlong pConfigInfo,
 353      jboolean isOpaque,
 354      jint width, jint height)
 355 {
 356     OGLSDOps *oglsdo = (OGLSDOps *)jlong_to_ptr(pData);
 357     GLXGraphicsConfigInfo *glxinfo =
 358         (GLXGraphicsConfigInfo *)jlong_to_ptr(pConfigInfo);
 359     GLXSDOps *glxsdo;
 360     GLXPbuffer pbuffer;
 361     int attrlist[] = {GLX_PBUFFER_WIDTH, 0,
 362                       GLX_PBUFFER_HEIGHT, 0,
 363                       GLX_PRESERVED_CONTENTS, GL_FALSE, 0};
 364 
 365     J2dTraceLn3(J2D_TRACE_INFO,
 366                 "GLXSurfaceData_initPbuffer: w=%d h=%d opq=%d",
 367                 width, height, isOpaque);
 368 


 371                       "GLXSurfaceData_initPbuffer: ops are null");
 372         return JNI_FALSE;
 373     }
 374 
 375     glxsdo = (GLXSDOps *)oglsdo->privOps;
 376     if (glxsdo == NULL) {
 377         J2dRlsTraceLn(J2D_TRACE_ERROR,
 378                       "GLXSurfaceData_initPbuffer: glx ops are null");
 379         return JNI_FALSE;
 380     }
 381 
 382     if (glxinfo == NULL) {
 383         J2dRlsTraceLn(J2D_TRACE_ERROR,
 384                       "GLXSurfaceData_initPbuffer: glx config info is null");
 385         return JNI_FALSE;
 386     }
 387 
 388     attrlist[1] = width;
 389     attrlist[3] = height;
 390 
 391     AWT_LOCK();
 392     jboolean errorOccurredFlag = JNI_FALSE;
 393     EXEC_WITH_XERROR_HANDLER(env, "sun/awt/X11/XErrorHandler$GLXBadAllocHandler",
 394         "()Lsun/awt/X11/XErrorHandler$GLXBadAllocHandler;", JNI_TRUE, errorOccurredFlag,
 395         pbuffer = j2d_glXCreatePbuffer(awt_display, glxinfo->fbconfig, attrlist));
 396     AWT_UNLOCK();
 397 
 398     if ((pbuffer == 0) || errorOccurredFlag) {
 399         J2dRlsTraceLn(J2D_TRACE_ERROR,
 400             "GLXSurfaceData_initPbuffer: could not create glx pbuffer");
 401         return JNI_FALSE;
 402     }
 403 
 404     oglsdo->drawableType = OGLSD_PBUFFER;
 405     oglsdo->isOpaque = isOpaque;
 406     oglsdo->width = width;
 407     oglsdo->height = height;
 408     oglsdo->xOffset = 0;
 409     oglsdo->yOffset = 0;
 410 
 411     glxsdo->drawable = pbuffer;
 412     glxsdo->xdrawable = 0;
 413 
 414     OGLSD_SetNativeDimensions(env, oglsdo, width, height);
 415 
 416     return JNI_TRUE;
 417 }
 418