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     GLXSDOps *glxsdo = (GLXSDOps *)malloc(sizeof(GLXSDOps));
  61 
  62     if (glxsdo == NULL) {
  63         JNU_ThrowOutOfMemoryError(env, "creating native GLX ops");
  64         return;
  65     }
  66 
  67     OGLSDOps *oglsdo = (OGLSDOps *)SurfaceData_InitOps(env, glxsd,
  68                                                        sizeof(OGLSDOps));
  69     if (oglsdo == NULL) {
  70         free(glxsdo);
  71         JNU_ThrowOutOfMemoryError(env, "Initialization of SurfaceData failed.");
  72         return;


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


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


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


   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     GLXSDOps *glxsdo = (GLXSDOps *)malloc(sizeof(GLXSDOps));
  59 
  60     if (glxsdo == NULL) {
  61         JNU_ThrowOutOfMemoryError(env, "creating native GLX ops");
  62         return;
  63     }
  64 
  65     OGLSDOps *oglsdo = (OGLSDOps *)SurfaceData_InitOps(env, glxsd,
  66                                                        sizeof(OGLSDOps));
  67     if (oglsdo == NULL) {
  68         free(glxsdo);
  69         JNU_ThrowOutOfMemoryError(env, "Initialization of SurfaceData failed.");
  70         return;


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












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


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