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 
  37 #include "com_sun_prism_es2_EGLFBGLContext.h"
  38 
  39 /*
  40  * Class:     com_sun_prism_es2_EGLFBGLFactory
  41  * Method:    nInitialize
  42  * Signature: ([I)J
  43  */
  44 JNIEXPORT jlong JNICALL Java_com_sun_prism_es2_MonocleGLFactory_nInitialize
  45 (JNIEnv *env, jclass jeglfbGLFactory, jintArray attrArr) {
  46     int eglAttrs[MAX_GLX_ATTRS_LENGTH]; /* value, attr pair plus a None */
  47     jint *attrs;
  48 
  49     if (attrArr == NULL) {
  50         return 0;
  51     }
  52     return 0;
  53 /*
  54     attrs = (*env)->GetIntArrayElements(env, attrArr, NULL);
  55     setEGLAttrs(attrs, eglAttrs);
  56     (*env)->ReleaseIntArrayElements(env, attrArr, attrs, JNI_ABORT);
  57 
  58     EGLint surfaceType;
  59     EGLConfig config = 0;
  60     EGLint numconfigs = 0;
  61     EGLint configId = 0;
  62 
  63     EGLDisplay egldisplay = eglGetDisplay(getNativeDisplayType());
  64     if (EGL_NO_DISPLAY == egldisplay) {
  65         fprintf(stderr, "eglGetDisplay returned EGL_NO_DISPLAY");
  66         // cleanup
  67         return 0;
  68     }
  69     EGLint egl_major, egl_minor;
  70     if (!eglInitialize(egldisplay, &egl_major, &egl_minor)) {
  71         fprintf(stderr, "eglInitialize failed!");
  72         // cleanup
  73         return 0;
  74     }
  75 
  76     if (!eglBindAPI(EGL_OPENGL_ES_API)) {
  77         fprintf(stderr, "eglBindAPI failed!");
  78         return 0;
  79     }
  80 
  81 #ifdef DEBUG
  82     // This is the client side
  83     const char *eglVendor  = eglQueryString(egldisplay, EGL_VENDOR);
  84     const char *eglVersion = eglQueryString(egldisplay, EGL_VERSION);
  85     printf("EGL_VENDOR  is %s\n", eglVendor);
  86     printf("EGL_VERSION version is %s\n", eglVersion);
  87     printf("Requested EGL attributes:\n");
  88     printConfigAttrs(eglAttrs);
  89 #endif
  90 
  91     if (!eglChooseConfig(egldisplay, eglAttrs, &config, 1, &numconfigs)) {
  92         fprintf(stderr, "Failed to get a FBconfig with requested attrs\n");
  93         //cleanup
  94         return 0;
  95     }
  96 
  97 #ifdef DEBUG
  98     printf("eglChooseConfig return %d configs\n", numconfigs);
  99 #endif
 100 
 101     if (!eglGetConfigAttrib(egldisplay, config, EGL_CONFIG_ID, &configId)) {
 102         fprintf(stderr, "eglGetConfigAttrib failed!");
 103         return 0;
 104     }
 105 
 106 #ifdef DEBUG
 107     printf("EGL: Using config #%d\n", configId);
 108     printConfig(egldisplay, config);
 109 #endif
 110 
 111     ContextInfo *ctxInfo = eglContextFromConfig(egldisplay, config);
 112     if (!ctxInfo) {
 113         fprintf(stderr, "Failed to create EGLContext");
 114         return 0; // cleanup
 115     }
 116     // Information required by GLass at startup
 117     ctxInfo->display = getNativeDisplayType();
 118     ctxInfo->gl2 = JNI_FALSE;
 119     eglDestroyContext(ctxInfo->egldisplay, ctxInfo->context);
 120     return ptr_to_jlong(ctxInfo);
 121     */
 122 }
 123 
 124 /*
 125  * Class:     com_sun_prism_es2_EGLFBGLFactory
 126  * Method:    nGetAdapterOrdinal
 127  * Signature: (J)I
 128  */
 129 JNIEXPORT jint JNICALL Java_com_sun_prism_es2_EGLFBGLFactory_nGetAdapterOrdinal
 130 (JNIEnv *env, jclass jeglfbGLFactory, jlong nativeScreen) {
 131     return 0;
 132 }
 133 
 134 /*
 135  * Class:     com_sun_prism_es2_EGLFBGLFactory
 136  * Method:    nGetAdapterCount
 137  * Signature: ()I
 138  */
 139 JNIEXPORT jint JNICALL Java_com_sun_prism_es2_EGLFBGLFactory_nGetAdapterCount
 140 (JNIEnv *env, jclass jeglfbGLFactory) {
 141     return 1;
 142 }
 143 
 144 /*
 145  * Class:     com_sun_prism_es2_EGLFBGLFactory
 146  * Method:    nGetDefaultScreen
 147  * Signature: (J)I
 148  */
 149 JNIEXPORT jint JNICALL Java_com_sun_prism_es2_EGLFBGLFactory_nGetDefaultScreen
 150 (JNIEnv *env, jclass jeglfbGLFactory, jlong nativeCtxInfo) {
 151     return 0;
 152 }
 153 
 154 /*
 155  * Class:     com_sun_prism_es2_EGLFBGLFactory
 156  * Method:    nGetDisplay
 157  * Signature: (J)J
 158  */
 159 JNIEXPORT jlong JNICALL Java_com_sun_prism_es2_EGLFBGLFactory_nGetDisplay
 160 (JNIEnv *env, jclass jeglfbGLFactory, jlong nativeCtxInfo) {
 161     return 0;
 162 }
 163 
 164 /*
 165  * Class:     com_sun_prism_es2_EGLFBGLFactory
 166  * Method:    nGetVisualID
 167  * Signature: (J)J
 168  */
 169 JNIEXPORT jlong JNICALL Java_com_sun_prism_es2_EGLFBGLFactory_nGetVisualID
 170 (JNIEnv *env, jclass jeglfbGLFactory, jlong nativeCtxInfo) {
 171     return 0;
 172 }
 173 
 174 /*
 175  * Class:     com_sun_prism_es2_EGLFBGLFactory
 176  * Method:    nGetIsGL2
 177  * Signature: (J)Z
 178  */
 179 JNIEXPORT jboolean JNICALL Java_com_sun_prism_es2_EGLFBGLFactory_nGetIsGL2
 180 (JNIEnv *env, jclass class, jlong nativeCtxInfo) {
 181     return ((ContextInfo *)jlong_to_ptr(nativeCtxInfo))->gl2;
 182 }