javauis/m3g_qt/src/jni/interface.inl
author William Roberts <williamr@symbian.org>
Thu, 22 Jul 2010 16:31:34 +0100
branchGCC_SURGE
changeset 55 d93ef1df440d
parent 40 c6043ea9b06a
parent 47 f40128debb5d
permissions -rw-r--r--
Catchup to latest Symbian^4

/*
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description:
*
*/
#include "javax_microedition_m3g_Interface.h"


/*!
 * \brief Error handler for the Java interface
 *
 * Converts M3G errors to exceptions and throws them automatically.
 */
static void errorHandler(M3Genum errorCode, M3GInterface /*m3g*/)
{
    CSynchronization::InstanceL()->SetErrorCode(errorCode);
}

/*
static int createInterface(M3Gparams* aCs)
{
    return ((unsigned) m3gCreateInterface(aCs));
}
*/

/*
 * Must be executed in UI thread
 */
JNIEXPORT jint JNICALL Java_javax_microedition_m3g_Interface__1ctor(JNIEnv* aEnv, jclass)
{
    EGLDisplay oldDisplay = eglGetCurrentDisplay();
    EGLSurface oldDrawSurface = eglGetCurrentSurface(EGL_DRAW);
    EGLSurface oldReadSurface = eglGetCurrentSurface(EGL_READ);
    EGLContext oldContext = eglGetCurrentContext();
    EGLenum oldAPI = eglQueryAPI();
    eglMakeCurrent( EGL_DEFAULT_DISPLAY, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT );
    eglBindAPI( EGL_OPENGL_ES_API );
    
    M3Gparams cs;
    memset(&cs, 0, sizeof(cs));
    cs.mallocFunc = malloc;
    cs.freeFunc   = free;
    cs.errorFunc = errorHandler;

    M3G_DO_LOCK
    /* Call to the Eventserver side */
    //CJavaM3GEventSource* eventSource = JavaUnhand<CJavaM3GEventSource>(aEventSourceHandle);
    //jint handle = eventSource->Execute(&createInterface, &cs);
    jint handle = (unsigned)m3gCreateInterface(&cs);
    M3G_DO_UNLOCK(aEnv);
    
    eglMakeCurrent( EGL_DEFAULT_DISPLAY, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT );
    eglBindAPI( oldAPI );
    eglMakeCurrent( oldDisplay, oldDrawSurface, oldReadSurface, oldContext );
    return handle;
}

JNIEXPORT jint JNICALL Java_javax_microedition_m3g_Interface__1getClassID
(JNIEnv* aEnv, jclass, jint aHObject)
{
    M3G_DO_LOCK
    jint handle = m3gGetClass((M3GObject)aHObject);
    M3G_DO_UNLOCK(aEnv);
    return handle;
}