1 /* 2 * Copyright (c) 2012, 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 23 * questions. 24 */ 25 26 #include <stdlib.h> 27 #include <assert.h> 28 #include <stdio.h> 29 #include <string.h> 30 #include <math.h> 31 32 #include <EGL/egl.h> 33 #include "eglUtils.h" 34 35 #include "../PrismES2Defs.h" 36 #include "com_sun_prism_es2_EGLFBGLContext.h" 37 38 /* 39 * Class: com_sun_prism_es2_EGLFBGLContext 40 * Method: nInitialize 41 * Signature: (JJZ)J 42 */ 43 JNIEXPORT jlong JNICALL Java_com_sun_prism_es2_EGLFBGLContext_nInitialize 44 (JNIEnv *env, jclass jeglfbcontext, jlong nativeDInfo, jlong nativePFInfo, jboolean SyncRequest) { 45 DrawableInfo *dInfo = (DrawableInfo *) jlong_to_ptr(nativeDInfo); 46 PixelFormatInfo *pfInfo = (PixelFormatInfo *) jlong_to_ptr(nativePFInfo); 47 48 if ((dInfo == NULL) || (pfInfo == NULL)) { 49 fprintf(stderr, "EGLFBGLContext_nInitialize: null dInfo pfInfo\n"); 50 return 0; 51 } 52 EGLConfig fbConfig = pfInfo->fbConfig; 53 54 ContextInfo *ctxInfo = eglContextFromConfig(dInfo->egldisplay, fbConfig); 55 return ptr_to_jlong(ctxInfo); 56 } 57 58 /* 59 * Class: com_sun_prism_es2_EGLFBGLContext 60 * Method: nGetNativeHandle 61 * Signature: (J)J 62 */ 63 JNIEXPORT jlong JNICALL Java_com_sun_prism_es2_EGLFBGLContext_nGetNativeHandle 64 (JNIEnv *env, jclass jeglfbcontext, jlong nativeCtxInfo) { 65 ContextInfo *ctxInfo = (ContextInfo *) jlong_to_ptr(nativeCtxInfo); 66 if (ctxInfo == NULL) { 67 fprintf(stderr, " nGetNativeHandle, ContextInfo is null\n"); 68 return 0; 69 } 70 return ptr_to_jlong(ctxInfo->context); 71 } 72 73 /* 74 * Class: com_sun_prism_es2_EGLFBGLContext 75 * Method: nMakeCurrent 76 * Signature: (JJ)V 77 */ 78 JNIEXPORT void JNICALL Java_com_sun_prism_es2_EGLFBGLContext_nMakeCurrent 79 (JNIEnv *env, jclass jeglfbcontext, jlong nativeCtxInfo, jlong nativeDInfo) { 80 81 DrawableInfo *dInfo = (DrawableInfo *) jlong_to_ptr(nativeDInfo); 82 if (dInfo == NULL) { 83 fprintf(stderr, "nMakeCurrent: dIfno is null!!!\n"); 84 return; 85 } 86 87 ContextInfo *ctxInfo = (ContextInfo *) jlong_to_ptr(nativeCtxInfo); 88 if (ctxInfo == NULL) { 89 fprintf(stderr, "nMakeCurrent: ctxInfo is null!!!\n"); 90 return; 91 } 92 int interval; 93 jboolean vSyncNeeded; 94 95 if (!eglMakeCurrent(dInfo->egldisplay, dInfo->eglsurface, dInfo->eglsurface, ctxInfo->context)) { 96 fprintf(stderr, "Failed in eglMakeCurrent for %p %p %d\n", dInfo->eglsurface, ctxInfo->context, eglGetError()); 97 } 98 vSyncNeeded = ctxInfo->vSyncRequested && dInfo->onScreen; 99 if (vSyncNeeded == ctxInfo->state.vSyncEnabled) { 100 return; 101 } 102 103 return; 104 105 } 106