|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 #include "javax_microedition_m3g_Interface.h" |
|
18 |
|
19 |
|
20 /*! |
|
21 * \brief Error handler for the Java interface |
|
22 * |
|
23 * Converts M3G errors to exceptions and throws them automatically. |
|
24 */ |
|
25 static void errorHandler(M3Genum errorCode, M3GInterface /*m3g*/) |
|
26 { |
|
27 CSynchronization::InstanceL()->SetErrorCode(errorCode); |
|
28 } |
|
29 |
|
30 /* |
|
31 static int createInterface(M3Gparams* aCs) |
|
32 { |
|
33 return ((unsigned) m3gCreateInterface(aCs)); |
|
34 } |
|
35 */ |
|
36 |
|
37 /* |
|
38 * Must be executed in UI thread |
|
39 */ |
|
40 JNIEXPORT jint JNICALL Java_javax_microedition_m3g_Interface__1ctor(JNIEnv* aEnv, jclass) |
|
41 { |
|
42 EGLDisplay oldDisplay = eglGetCurrentDisplay(); |
|
43 EGLSurface oldDrawSurface = eglGetCurrentSurface(EGL_DRAW); |
|
44 EGLSurface oldReadSurface = eglGetCurrentSurface(EGL_READ); |
|
45 EGLContext oldContext = eglGetCurrentContext(); |
|
46 EGLenum oldAPI = eglQueryAPI(); |
|
47 eglMakeCurrent( EGL_DEFAULT_DISPLAY, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT ); |
|
48 eglBindAPI( EGL_OPENGL_ES_API ); |
|
49 |
|
50 M3Gparams cs; |
|
51 memset(&cs, 0, sizeof(cs)); |
|
52 cs.mallocFunc = malloc; |
|
53 cs.freeFunc = free; |
|
54 cs.errorFunc = errorHandler; |
|
55 |
|
56 M3G_DO_LOCK |
|
57 /* Call to the Eventserver side */ |
|
58 //CJavaM3GEventSource* eventSource = JavaUnhand<CJavaM3GEventSource>(aEventSourceHandle); |
|
59 //jint handle = eventSource->Execute(&createInterface, &cs); |
|
60 jint handle = (unsigned)m3gCreateInterface(&cs); |
|
61 M3G_DO_UNLOCK(aEnv); |
|
62 |
|
63 eglMakeCurrent( EGL_DEFAULT_DISPLAY, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT ); |
|
64 eglBindAPI( oldAPI ); |
|
65 eglMakeCurrent( oldDisplay, oldDrawSurface, oldReadSurface, oldContext ); |
|
66 return handle; |
|
67 } |
|
68 |
|
69 JNIEXPORT jint JNICALL Java_javax_microedition_m3g_Interface__1getClassID |
|
70 (JNIEnv* aEnv, jclass, jint aHObject) |
|
71 { |
|
72 M3G_DO_LOCK |
|
73 jint handle = m3gGetClass((M3GObject)aHObject); |
|
74 M3G_DO_UNLOCK(aEnv); |
|
75 return handle; |
|
76 } |