< prev index next >

src/java.desktop/unix/native/common/java2d/opengl/GLXSurfaceData.c

Print this page


   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


  94     glxsdo->configData = (AwtGraphicsConfigDataPtr)jlong_to_ptr(aData);
  95     if (glxsdo->configData == NULL) {
  96         free(glxsdo);
  97         JNU_ThrowNullPointerException(env,
  98                                  "Native GraphicsConfig data block missing");
  99         return;
 100     }
 101 
 102     if (glxsdo->configData->glxInfo == NULL) {
 103         free(glxsdo);
 104         JNU_ThrowNullPointerException(env, "GLXGraphicsConfigInfo missing");
 105         return;
 106     }
 107 #endif /* HEADLESS */
 108 }
 109 
 110 #ifndef HEADLESS
 111 
 112 /**
 113  * This function disposes of any native windowing system resources associated
 114  * with this surface.  For instance, if the given OGLSDOps is of type
 115  * OGLSD_PBUFFER, this method implementation will destroy the actual pbuffer
 116  * surface.
 117  */
 118 void
 119 OGLSD_DestroyOGLSurface(JNIEnv *env, OGLSDOps *oglsdo)
 120 {
 121     GLXSDOps *glxsdo = (GLXSDOps *)oglsdo->privOps;
 122 
 123     J2dTraceLn(J2D_TRACE_INFO, "OGLSD_DestroyOGLSurface");
 124 
 125     if (oglsdo->drawableType == OGLSD_PBUFFER) {
 126         if (glxsdo->drawable != 0) {
 127             j2d_glXDestroyPbuffer(awt_display, glxsdo->drawable);
 128             glxsdo->drawable = 0;
 129         }
 130     } else if (oglsdo->drawableType == OGLSD_WINDOW) {
 131         // X Window is free'd later by AWT code...
 132     }
 133 }
 134 
 135 /**
 136  * Makes the given context current to its associated "scratch" surface.  If
 137  * the operation is successful, this method will return JNI_TRUE; otherwise,
 138  * returns JNI_FALSE.
 139  */
 140 static jboolean
 141 GLXSD_MakeCurrentToScratch(JNIEnv *env, OGLContext *oglc)
 142 {
 143     GLXCtxInfo *ctxInfo;
 144 
 145     J2dTraceLn(J2D_TRACE_INFO, "GLXSD_MakeCurrentToScratch");
 146 
 147     if (oglc == NULL) {
 148         J2dRlsTraceLn(J2D_TRACE_ERROR,
 149                       "GLXSD_MakeCurrentToScratch: context is null");
 150         return JNI_FALSE;
 151     }
 152 


 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     if (xerr->error_code == BadAlloc) {
 356         surfaceCreationFailed = JNI_TRUE;
 357     }
 358     return 0;
 359 }
 360 
 361 JNIEXPORT jboolean JNICALL
 362 Java_sun_java2d_opengl_GLXSurfaceData_initPbuffer
 363     (JNIEnv *env, jobject glxsd,
 364      jlong pData, jlong pConfigInfo,
 365      jboolean isOpaque,
 366      jint width, jint height)
 367 {
 368     OGLSDOps *oglsdo = (OGLSDOps *)jlong_to_ptr(pData);
 369     GLXGraphicsConfigInfo *glxinfo =
 370         (GLXGraphicsConfigInfo *)jlong_to_ptr(pConfigInfo);
 371     GLXSDOps *glxsdo;
 372     GLXPbuffer pbuffer;
 373     int attrlist[] = {GLX_PBUFFER_WIDTH, 0,
 374                       GLX_PBUFFER_HEIGHT, 0,
 375                       GLX_PRESERVED_CONTENTS, GL_FALSE, 0};
 376 
 377     J2dTraceLn3(J2D_TRACE_INFO,
 378                 "GLXSurfaceData_initPbuffer: w=%d h=%d opq=%d",
 379                 width, height, isOpaque);
 380 
 381     if (oglsdo == NULL) {
 382         J2dRlsTraceLn(J2D_TRACE_ERROR,
 383                       "GLXSurfaceData_initPbuffer: ops are null");
 384         return JNI_FALSE;
 385     }
 386 
 387     glxsdo = (GLXSDOps *)oglsdo->privOps;
 388     if (glxsdo == NULL) {
 389         J2dRlsTraceLn(J2D_TRACE_ERROR,
 390                       "GLXSurfaceData_initPbuffer: glx ops are null");
 391         return JNI_FALSE;
 392     }
 393 
 394     if (glxinfo == NULL) {
 395         J2dRlsTraceLn(J2D_TRACE_ERROR,
 396                       "GLXSurfaceData_initPbuffer: glx config info is null");
 397         return JNI_FALSE;
 398     }
 399 
 400     attrlist[1] = width;
 401     attrlist[3] = height;
 402 
 403     surfaceCreationFailed = JNI_FALSE;
 404     EXEC_WITH_XERROR_HANDLER(
 405         GLXSD_BadAllocXErrHandler,
 406         pbuffer = j2d_glXCreatePbuffer(awt_display,
 407                                        glxinfo->fbconfig, attrlist));
 408     if ((pbuffer == 0) || surfaceCreationFailed) {
 409         J2dRlsTraceLn(J2D_TRACE_ERROR,
 410             "GLXSurfaceData_initPbuffer: could not create glx pbuffer");
 411         return JNI_FALSE;
 412     }
 413 
 414     oglsdo->drawableType = OGLSD_PBUFFER;
 415     oglsdo->isOpaque = isOpaque;
 416     oglsdo->width = width;
 417     oglsdo->height = height;
 418     oglsdo->xOffset = 0;
 419     oglsdo->yOffset = 0;
 420 
 421     glxsdo->drawable = pbuffer;
 422     glxsdo->xdrawable = 0;
 423 
 424     OGLSD_SetNativeDimensions(env, oglsdo, width, height);
 425 
 426     return JNI_TRUE;
 427 }
 428 
 429 void
 430 OGLSD_SwapBuffers(JNIEnv *env, jlong window)
 431 {
 432     J2dTraceLn(J2D_TRACE_INFO, "OGLSD_SwapBuffers");
 433 
 434     if (window == 0L) {
 435         J2dRlsTraceLn(J2D_TRACE_ERROR,
 436                       "OGLSD_SwapBuffers: window is null");
 437         return;
 438     }
 439 
 440     j2d_glXSwapBuffers(awt_display, (Window)window);
 441 }
 442 
 443 // needed by Mac OS X port, no-op on other platforms
 444 void
 445 OGLSD_Flush(JNIEnv *env)
 446 {
 447 }
 448 
   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


  94     glxsdo->configData = (AwtGraphicsConfigDataPtr)jlong_to_ptr(aData);
  95     if (glxsdo->configData == NULL) {
  96         free(glxsdo);
  97         JNU_ThrowNullPointerException(env,
  98                                  "Native GraphicsConfig data block missing");
  99         return;
 100     }
 101 
 102     if (glxsdo->configData->glxInfo == NULL) {
 103         free(glxsdo);
 104         JNU_ThrowNullPointerException(env, "GLXGraphicsConfigInfo missing");
 105         return;
 106     }
 107 #endif /* HEADLESS */
 108 }
 109 
 110 #ifndef HEADLESS
 111 
 112 /**
 113  * This function disposes of any native windowing system resources associated
 114  * with this surface.


 115  */
 116 void
 117 OGLSD_DestroyOGLSurface(JNIEnv *env, OGLSDOps *oglsdo)
 118 {


 119     J2dTraceLn(J2D_TRACE_INFO, "OGLSD_DestroyOGLSurface");







 120     // X Window is free'd later by AWT code...

 121 }
 122 
 123 /**
 124  * Makes the given context current to its associated "scratch" surface.  If
 125  * the operation is successful, this method will return JNI_TRUE; otherwise,
 126  * returns JNI_FALSE.
 127  */
 128 static jboolean
 129 GLXSD_MakeCurrentToScratch(JNIEnv *env, OGLContext *oglc)
 130 {
 131     GLXCtxInfo *ctxInfo;
 132 
 133     J2dTraceLn(J2D_TRACE_INFO, "GLXSD_MakeCurrentToScratch");
 134 
 135     if (oglc == NULL) {
 136         J2dRlsTraceLn(J2D_TRACE_ERROR,
 137                       "GLXSD_MakeCurrentToScratch: context is null");
 138         return JNI_FALSE;
 139     }
 140 


 329     oglsdo->xOffset = 0;
 330     oglsdo->yOffset = 0;
 331     glxsdo->drawable = window;
 332     glxsdo->xdrawable = window;
 333 
 334     J2dTraceLn2(J2D_TRACE_VERBOSE, "  created window: w=%d h=%d",
 335                 oglsdo->width, oglsdo->height);
 336 
 337     return JNI_TRUE;
 338 }
 339 
 340 static int
 341 GLXSD_BadAllocXErrHandler(Display *display, XErrorEvent *xerr)
 342 {
 343     if (xerr->error_code == BadAlloc) {
 344         surfaceCreationFailed = JNI_TRUE;
 345     }
 346     return 0;
 347 }
 348 




































































 349 void
 350 OGLSD_SwapBuffers(JNIEnv *env, jlong window)
 351 {
 352     J2dTraceLn(J2D_TRACE_INFO, "OGLSD_SwapBuffers");
 353 
 354     if (window == 0L) {
 355         J2dRlsTraceLn(J2D_TRACE_ERROR,
 356                       "OGLSD_SwapBuffers: window is null");
 357         return;
 358     }
 359 
 360     j2d_glXSwapBuffers(awt_display, (Window)window);
 361 }
 362 
 363 // needed by Mac OS X port, no-op on other platforms
 364 void
 365 OGLSD_Flush(JNIEnv *env)
 366 {
 367 }
 368 
< prev index next >