< prev index next >

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

Print this page


   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


  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;
  73     }









  74 
  75     J2dTraceLn(J2D_TRACE_INFO, "GLXSurfaceData_initOps");
  76 
  77     oglsdo->privOps = glxsdo;
  78 
  79     oglsdo->sdOps.Lock       = OGLSD_Lock;
  80     oglsdo->sdOps.GetRasInfo = OGLSD_GetRasInfo;
  81     oglsdo->sdOps.Unlock     = OGLSD_Unlock;
  82     oglsdo->sdOps.Dispose    = OGLSD_Dispose;
  83 
  84     oglsdo->drawableType = OGLSD_UNDEFINED;
  85     oglsdo->activeBuffer = GL_FRONT;
  86     oglsdo->needsInit = JNI_TRUE;
  87 
  88     if (peer != NULL) {
  89         glxsdo->window = JNU_CallMethodByName(env, NULL, peer,
  90                                               "getContentWindow", "()J").j;
  91     } else {
  92         glxsdo->window = 0;
  93     }


 136         J2dRlsTraceLn(J2D_TRACE_ERROR,
 137                       "GLXSD_MakeCurrentToScratch: context is null");
 138         return JNI_FALSE;
 139     }
 140 
 141     ctxInfo = (GLXCtxInfo *)oglc->ctxInfo;
 142     if (!j2d_glXMakeContextCurrent(awt_display,
 143                                    ctxInfo->scratchSurface,
 144                                    ctxInfo->scratchSurface,
 145                                    ctxInfo->context))
 146     {
 147         J2dRlsTraceLn(J2D_TRACE_ERROR,
 148                       "GLXSD_MakeCurrentToScratch: could not make current");
 149         return JNI_FALSE;
 150     }
 151 
 152     return JNI_TRUE;
 153 }
 154 
 155 /**
 156  * Returns a pointer (as a jlong) to the native GLXGraphicsConfigInfo
 157  * associated with the given OGLSDOps.  This method can be called from
 158  * shared code to retrieve the native GraphicsConfig data in a platform-
 159  * independent manner.
 160  */
 161 jlong
 162 OGLSD_GetNativeConfigInfo(OGLSDOps *oglsdo)
 163 {
 164     GLXSDOps *glxsdo;
 165 
 166     if (oglsdo == NULL) {
 167         J2dRlsTraceLn(J2D_TRACE_ERROR,
 168                       "OGLSD_GetNativeConfigInfo: ops are null");
 169         return 0L;
 170     }
 171 
 172     glxsdo = (GLXSDOps *)oglsdo->privOps;
 173     if (glxsdo == NULL) {
 174         J2dRlsTraceLn(J2D_TRACE_ERROR,
 175                       "OGLSD_GetNativeConfigInfo: glx ops are null");
 176         return 0L;
 177     }
 178 
 179     if (glxsdo->configData == NULL) {
 180         J2dRlsTraceLn(J2D_TRACE_ERROR,
 181                       "OGLSD_GetNativeConfigInfo: config data is null");
 182         return 0L;
 183     }
 184 
 185     return ptr_to_jlong(glxsdo->configData->glxInfo);
 186 }
 187 
 188 /**
 189  * Makes the given GraphicsConfig's context current to its associated
 190  * "scratch" surface.  If there is a problem making the context current,
 191  * this method will return NULL; otherwise, returns a pointer to the
 192  * OGLContext that is associated with the given GraphicsConfig.
 193  */
 194 OGLContext *
 195 OGLSD_SetScratchSurface(JNIEnv *env, jlong pConfigInfo)
 196 {
 197     GLXGraphicsConfigInfo *glxInfo =
 198         (GLXGraphicsConfigInfo *)jlong_to_ptr(pConfigInfo);
 199     OGLContext *oglc;
 200 
 201     J2dTraceLn(J2D_TRACE_INFO, "OGLSD_SetScratchContext");
 202 
 203     if (glxInfo == NULL) {
 204         J2dRlsTraceLn(J2D_TRACE_ERROR,
 205                       "OGLSD_SetScratchContext: glx config info is null");
 206         return NULL;
 207     }
 208 


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


  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 gc,
  58                                               jobject peer, jlong aData)
  59 {
  60 #ifndef HEADLESS
  61     gc = (*env)->NewGlobalRef(env, gc);
  62     if (gc == NULL) {
  63         JNU_ThrowOutOfMemoryError(env, "Initialization of SurfaceData failed.");

  64         return;
  65     }
  66 
  67     OGLSDOps *oglsdo = (OGLSDOps *)SurfaceData_InitOps(env, glxsd,
  68                                                        sizeof(OGLSDOps));
  69     if (oglsdo == NULL) {
  70         (*env)->DeleteGlobalRef(env, gc);
  71         JNU_ThrowOutOfMemoryError(env, "Initialization of SurfaceData failed.");
  72         return;
  73     }
  74     // later the graphicsConfig will be used for deallocation of oglsdo
  75     oglsdo->graphicsConfig = gc;
  76 
  77     GLXSDOps *glxsdo = (GLXSDOps *)malloc(sizeof(GLXSDOps));
  78 
  79     if (glxsdo == NULL) {
  80         JNU_ThrowOutOfMemoryError(env, "creating native GLX ops");
  81         return;
  82     }
  83 
  84     J2dTraceLn(J2D_TRACE_INFO, "GLXSurfaceData_initOps");
  85 
  86     oglsdo->privOps = glxsdo;
  87 
  88     oglsdo->sdOps.Lock       = OGLSD_Lock;
  89     oglsdo->sdOps.GetRasInfo = OGLSD_GetRasInfo;
  90     oglsdo->sdOps.Unlock     = OGLSD_Unlock;
  91     oglsdo->sdOps.Dispose    = OGLSD_Dispose;
  92 
  93     oglsdo->drawableType = OGLSD_UNDEFINED;
  94     oglsdo->activeBuffer = GL_FRONT;
  95     oglsdo->needsInit = JNI_TRUE;
  96 
  97     if (peer != NULL) {
  98         glxsdo->window = JNU_CallMethodByName(env, NULL, peer,
  99                                               "getContentWindow", "()J").j;
 100     } else {
 101         glxsdo->window = 0;
 102     }


 145         J2dRlsTraceLn(J2D_TRACE_ERROR,
 146                       "GLXSD_MakeCurrentToScratch: context is null");
 147         return JNI_FALSE;
 148     }
 149 
 150     ctxInfo = (GLXCtxInfo *)oglc->ctxInfo;
 151     if (!j2d_glXMakeContextCurrent(awt_display,
 152                                    ctxInfo->scratchSurface,
 153                                    ctxInfo->scratchSurface,
 154                                    ctxInfo->context))
 155     {
 156         J2dRlsTraceLn(J2D_TRACE_ERROR,
 157                       "GLXSD_MakeCurrentToScratch: could not make current");
 158         return JNI_FALSE;
 159     }
 160 
 161     return JNI_TRUE;
 162 }
 163 
 164 /**

































 165  * Makes the given GraphicsConfig's context current to its associated
 166  * "scratch" surface.  If there is a problem making the context current,
 167  * this method will return NULL; otherwise, returns a pointer to the
 168  * OGLContext that is associated with the given GraphicsConfig.
 169  */
 170 OGLContext *
 171 OGLSD_SetScratchSurface(JNIEnv *env, jlong pConfigInfo)
 172 {
 173     GLXGraphicsConfigInfo *glxInfo =
 174         (GLXGraphicsConfigInfo *)jlong_to_ptr(pConfigInfo);
 175     OGLContext *oglc;
 176 
 177     J2dTraceLn(J2D_TRACE_INFO, "OGLSD_SetScratchContext");
 178 
 179     if (glxInfo == NULL) {
 180         J2dRlsTraceLn(J2D_TRACE_ERROR,
 181                       "OGLSD_SetScratchContext: glx config info is null");
 182         return NULL;
 183     }
 184 


< prev index next >