/*  private native int _eglInitialize ( int display , int [ ] major_minor ) ; */
KNIEXPORT KNI_RETURNTYPE_INT
Java_javax_microedition_khronos_egl_EGL10Impl__1eglInitialize() {

    jint display = KNI_GetParameterAsInt(1);
    EGLint major, minor;

    jint returnValue;

    KNI_StartHandles(1);
    KNI_DeclareHandle(major_minorHandle);

    KNI_GetParameterAsObject(2, major_minorHandle);

    returnValue = (jint) eglInitialize((EGLDisplay)display, &major, &minor);
#ifdef DEBUG
    printf("eglInitialize(0x%x, major<-%d, minor<-%d) = %d\n",
	   display, major, minor, returnValue);
#endif
    if ((returnValue == EGL_TRUE) && !KNI_IsNullHandle(major_minorHandle)) {
        KNI_SetIntArrayElement(major_minorHandle, 0, major);
        KNI_SetIntArrayElement(major_minorHandle, 1, minor);
    }

    KNI_EndHandles();
    KNI_ReturnInt(returnValue);
}
/*  private native int _eglQueryContext ( int display , int ctx , int attribute , int [ ] value ) ; */
KNIEXPORT KNI_RETURNTYPE_INT
Java_javax_microedition_khronos_egl_EGL10Impl__1eglQueryContext() {

    jint display = KNI_GetParameterAsInt(1);
    jint ctx = KNI_GetParameterAsInt(2);
    jint attribute = KNI_GetParameterAsInt(3);
    EGLint value;

    jint returnValue = EGL_FALSE;

    KNI_StartHandles(1);
    KNI_DeclareHandle(valueHandle);

    KNI_GetParameterAsObject(4, valueHandle);

    returnValue = (jint)eglQueryContext((EGLDisplay)display,
					(EGLContext)ctx,
					attribute,
					&value);
#ifdef DEBUG
    printf("eglQueryContext(0x%x, 0x%x, %d, value<-%d) = %d\n",
	   display, ctx, attribute, value, returnValue);
#endif
    if ((returnValue == EGL_TRUE) && !KNI_IsNullHandle(valueHandle)) {
        KNI_SetIntArrayElement(valueHandle, 0, value);
    }

    KNI_EndHandles();
    KNI_ReturnInt(returnValue);
}
示例#3
0
/**
 * public static native int[] getFreedRendezvousPoints();
 *
 * Returns an array of freed rendezvous points. Resets the list to empty after
 * it's called.
 */
KNIEXPORT KNI_RETURNTYPE_OBJECT
Java_com_sun_midp_links_Utils_getFreedRendezvousPoints(void)
{
    int i;
    KNI_StartHandles(1);
    KNI_DeclareHandle(arrayReturn);

    SNI_NewArray(SNI_INT_ARRAY, freeptr, arrayReturn);

    /*
     * Use SetRawArrayRegion? Maybe assumes too many things about
     * int sizes.
     */
    for (i = 0; i < freeptr; i++) {
        KNI_SetIntArrayElement(arrayReturn, i, (jint)freelog[i]);
    }
    freeptr = 0;

    KNI_EndHandlesAndReturnObject(arrayReturn);
}
/*  private native int _eglGetConfigAttrib ( int display , int config , int attribute , int [ ] value ) ; */
KNIEXPORT KNI_RETURNTYPE_INT
Java_javax_microedition_khronos_egl_EGL10Impl__1eglGetConfigAttrib() {

    jint display = KNI_GetParameterAsInt(1);
    jint config = KNI_GetParameterAsInt(2);
    jint attribute = KNI_GetParameterAsInt(3);
    EGLint value;

    jint returnValue = EGL_FALSE;

    KNI_StartHandles(1);
    KNI_DeclareHandle(valueHandle);

    KNI_GetParameterAsObject(4, valueHandle);

    returnValue = (jint)eglGetConfigAttrib((EGLDisplay)display,
                                           (EGLConfig)config,
                                           (EGLint)attribute,
                                           &value);
#ifdef DEBUG
    printf("eglGetConfigAttrib(0x%x, 0x%x, %d, value<-%d) = %d\n",
	   display, config, attribute, value, returnValue);
#endif

#ifdef ALL_WINDOWS_ARE_PIXMAPS
    // If all windows are being backed by pixmaps, mark all
    // configs that are pixmap compatible as being window compatible
    if ((attribute == EGL_SURFACE_TYPE) &&
        ((value & EGL_PIXMAP_BIT) != 0)) {
        value |= EGL_WINDOW_BIT;
    }
#endif
    
    /* Set output parameter via valueHandle only if the call was successful */
    if ((returnValue == EGL_TRUE) && !KNI_IsNullHandle(valueHandle)) {
        KNI_SetIntArrayElement(valueHandle, 0, value);
    }

    KNI_EndHandles();
    KNI_ReturnInt(returnValue);
}
/*  private native int _eglChooseConfig ( int display , int [ ] attrib_list , int [ ] configs , int config_size , int [ ] num_config ) ; */
KNIEXPORT KNI_RETURNTYPE_INT
Java_javax_microedition_khronos_egl_EGL10Impl__1eglChooseConfig() {
    
    jint display = KNI_GetParameterAsInt(1);
    jint config_size = KNI_GetParameterAsInt(4);
    EGLint *attrib_list = (EGLint *)0;
    EGLConfig *configs = (EGLConfig *)0;
    EGLint num_config;

    jint returnValue = EGL_FALSE;

    KNI_StartHandles(3);
    KNI_DeclareHandle(attrib_listHandle);
    KNI_DeclareHandle(configsHandle);
    KNI_DeclareHandle(num_configHandle);

    KNI_GetParameterAsObject(2, attrib_listHandle);
    KNI_GetParameterAsObject(3, configsHandle);
    KNI_GetParameterAsObject(5, num_configHandle);

    if (!KNI_IsNullHandle(attrib_listHandle)) {
        jint attrib_list_length, attrib_list_size;
        /* Construct attrib_list as a copy of attrib_listHandle */
        attrib_list_length = KNI_GetArrayLength(attrib_listHandle);
        attrib_list_size = (attrib_list_length + 2)*sizeof(jint);
        attrib_list = (EGLint *)JSR239_malloc(attrib_list_size);
        if (!attrib_list) {
            KNI_ThrowNew("java.lang.OutOfMemoryException", "eglChooseConfig");
            goto exit;
        }
        KNI_GetRawArrayRegion(attrib_listHandle, 0, attrib_list_size,
                              (jbyte *)attrib_list);
    }

#ifdef ALL_WINDOWS_ARE_PIXMAPS
    // Force queries with SURFACE_TYPE == WINDOW to actually query pixmap
    if (attrib_list) {
        jint attr, val, idx;

        idx = 0;
        while (1) {
            attr = attrib_list[idx];
#ifdef DEBUG
            printf("attr[%d] = %d\n", idx, attr);
#endif
            if (attr == EGL_NONE) {
#ifdef DEBUG
                printf("attr = EGL_NONE, done\n");
#endif
                break;
            }
            if (attr == EGL_SURFACE_TYPE) {
#ifdef DEBUG
                printf("attr = EGL_SURFACE_TYPE\n");
#endif
                val = attrib_list[idx + 1];
                if ((val & EGL_WINDOW_BIT) != 0) {
#ifdef DEBUG
                    printf("Switching WINDOW_BIT to PIXMAP_BIT\n");
#endif
                    val |= EGL_PIXMAP_BIT;
                    val &= ~EGL_WINDOW_BIT;
                }   
            }
            idx += 2;
        }
    }
#endif

    /* Allocate config_size elements if configsHandle is non-null */
    if (!KNI_IsNullHandle(configsHandle)) {
	configs = (EGLConfig *)JSR239_malloc(config_size*sizeof(EGLint));
	if (!configs) {
            KNI_ThrowNew("java.lang.OutOfMemoryException", "eglChooseConfig");
	    goto exit;
	}
    }
    
    returnValue = (jint)eglChooseConfig((EGLDisplay)display, attrib_list,
					configs, config_size, &num_config);
#ifdef DEBUG
    printf("eglChooseConfig(0x%x, attrib_list, configs, %d, num_config<-%d) = %d\n",
	   display, config_size, num_config, returnValue);
#endif

    /* Copy configs back to Java */
    if (returnValue == EGL_TRUE && !KNI_IsNullHandle(configsHandle)) {
	KNI_SetRawArrayRegion(configsHandle, 0, config_size*sizeof(EGLint),
			      (const jbyte *)configs);
    }
    /* Set output parameter via num_configHandle */
    if ((returnValue == EGL_TRUE) && !KNI_IsNullHandle(num_configHandle)) {
        KNI_SetIntArrayElement(num_configHandle, 0, num_config);
    }

 exit:
    if (attrib_list) {
	JSR239_free(attrib_list);
    }
    if (configs) {
	JSR239_free(configs);
    }

    KNI_EndHandles();
    KNI_ReturnInt(returnValue);
}
/*  private native int _eglGetConfigs ( int display , int [ ] configs , int config_size , int [ ] num_config ) ; */
KNIEXPORT KNI_RETURNTYPE_INT
Java_javax_microedition_khronos_egl_EGL10Impl__1eglGetConfigs() {

    jint display = KNI_GetParameterAsInt(1);
    jint config_size = KNI_GetParameterAsInt(3);
    
    EGLConfig *configs = (EGLConfig *)0;
    EGLint num_config = 0;

    jint returnValue = EGL_FALSE;

    KNI_StartHandles(2);
    KNI_DeclareHandle(configsHandle);
    KNI_DeclareHandle(num_configHandle);

    KNI_GetParameterAsObject(2, configsHandle);
    KNI_GetParameterAsObject(4, num_configHandle);

    if (!KNI_IsNullHandle(configsHandle)) {
	configs = (EGLConfig *)JSR239_malloc(config_size*sizeof(EGLint));
	if (!configs) {
            KNI_ThrowNew("java.lang.OutOfMemoryException", "eglGetConfigs");
	    goto exit;
	}
    }

    returnValue = (jint)eglGetConfigs((EGLDisplay)display,
				      configs,
				      (EGLint)config_size,
				      &num_config);

#ifdef DEBUG
    printf("num_config = %d\n", num_config);
#endif

#ifdef ALL_WINDOWS_ARE_PIXMAPS
    {
      EGLBoolean ok;
      EGLint surfaceType;
      int i, j;

        // Remove all configs that are for windows only
        if (returnValue && configs) {
            for (i = 0; i < num_config; i++) {
                ok = eglGetConfigAttrib((EGLDisplay)display, configs[i],
                                        EGL_SURFACE_TYPE, &surfaceType);
                if ((surfaceType & (EGL_PIXMAP_BIT | EGL_PBUFFER_BIT)) == 0) {
                    for (j = i; j < num_config - 1; j++) {
                        configs[j] = configs[j + 1];
                    }
                    configs[--num_config] = 0;
#ifdef DEBUG
                    printf("Deleting a config, num_config = %d\n", num_config);
#endif
                }
            }
        }
    }
#endif

#ifdef DEBUG
    printf("eglGetConfigs(0x%x, configs, %d, num_config<-%d) = %d\n",
	   display, config_size, num_config, returnValue);
#endif
    
    if ((returnValue == EGL_TRUE) && !KNI_IsNullHandle(configsHandle)) {
	KNI_SetRawArrayRegion(configsHandle, 0, config_size*sizeof(EGLint),
			      (const jbyte *)configs);
    }
    if ((returnValue == EGL_TRUE) && !KNI_IsNullHandle(num_configHandle)) {
        KNI_SetIntArrayElement(num_configHandle, 0, num_config);
    }
    
 exit:
    if (configs) {
	JSR239_free(configs);
    }
    KNI_EndHandles();
    KNI_ReturnInt(returnValue);
}