< 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     // X Window is free'd later by AWT code...

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


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




































































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