javauis/m3g_qt/src/jni/group.inl
changeset 35 85266cc22c7f
equal deleted inserted replaced
26:dc7c549001d5 35:85266cc22c7f
       
     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 
       
    18 #include "javax_microedition_m3g_Group.h"
       
    19 
       
    20 JNIEXPORT void JNICALL Java_javax_microedition_m3g_Group__1addChild
       
    21 (JNIEnv* aEnv, jclass, jint aHandle, jint aHNode)
       
    22 {
       
    23     M3G_DO_LOCK
       
    24     m3gAddChild((M3GGroup)aHandle, (M3GNode)aHNode);
       
    25     M3G_DO_UNLOCK(aEnv)
       
    26 }
       
    27 
       
    28 JNIEXPORT jint JNICALL Java_javax_microedition_m3g_Group__1ctor
       
    29 (JNIEnv* aEnv, jclass, jint aM3g)
       
    30 {
       
    31     M3G_DO_LOCK
       
    32     jint handle = (jint)m3gCreateGroup((M3GInterface)aM3g);
       
    33     M3G_DO_UNLOCK(aEnv)
       
    34     return handle;
       
    35 }
       
    36 
       
    37 JNIEXPORT jint JNICALL Java_javax_microedition_m3g_Group__1pick2D
       
    38 (JNIEnv* aEnv, jclass, jint aHandle, jint aMask, jfloat aX, jfloat aY, jint aHCamera, jfloatArray aResult)
       
    39 {
       
    40     jfloat* elems = NULL;
       
    41     if (aResult)
       
    42     {
       
    43         elems = aEnv->GetFloatArrayElements(aResult, NULL);
       
    44         if (elems == NULL)
       
    45         {
       
    46             M3G_RAISE_EXCEPTION(aEnv, "java/lang/OutOfMemoryError");
       
    47             return 0;
       
    48         }
       
    49     }
       
    50 
       
    51     M3G_BEGIN_PROFILE(M3G_PROFILE_PICK);
       
    52     M3G_DO_LOCK
       
    53     jint ret = (jint)m3gPick2D((M3GGroup)aHandle, aMask, aX, aY, (M3GCamera)aHCamera, (jfloat*)elems);
       
    54     M3G_DO_UNLOCK(aEnv)
       
    55     M3G_END_PROFILE(M3G_PROFILE_PICK);
       
    56 
       
    57     if (aResult)
       
    58         aEnv->ReleaseFloatArrayElements(aResult, elems, 0);
       
    59     return ret;
       
    60 }
       
    61 
       
    62 JNIEXPORT jint JNICALL Java_javax_microedition_m3g_Group__1getChild
       
    63 (JNIEnv* aEnv, jclass, jint aHandle, jint aIndex)
       
    64 {
       
    65     M3G_DO_LOCK
       
    66     jint child = (jint)m3gGetChild((M3GGroup)aHandle, aIndex);
       
    67     M3G_DO_UNLOCK(aEnv)
       
    68     return child;
       
    69 }
       
    70 
       
    71 JNIEXPORT jint JNICALL Java_javax_microedition_m3g_Group__1pick3D
       
    72 (JNIEnv* aEnv, jclass, jint aHandle, jint aMask, jfloatArray aRay, jfloatArray aResult)
       
    73 {
       
    74     jfloat* rayElems = NULL;
       
    75     if (aRay)
       
    76     {
       
    77         rayElems = aEnv->GetFloatArrayElements(aRay, NULL);
       
    78         if (rayElems == NULL)
       
    79         {
       
    80             M3G_RAISE_EXCEPTION(aEnv, "java/lang/OutOfMemoryError");
       
    81             return 0;
       
    82         }
       
    83     }
       
    84 
       
    85     jfloat* resultElems = NULL;
       
    86     if (aResult)
       
    87     {
       
    88         resultElems = aEnv->GetFloatArrayElements(aResult, NULL);
       
    89         if (resultElems == NULL)
       
    90         {
       
    91             if (rayElems)
       
    92                 aEnv->ReleaseFloatArrayElements(aRay, rayElems, JNI_ABORT);
       
    93             M3G_RAISE_EXCEPTION(aEnv, "java/lang/OutOfMemoryError");
       
    94             return 0;
       
    95         }
       
    96     }
       
    97 
       
    98     M3G_BEGIN_PROFILE(M3G_PROFILE_PICK);
       
    99     M3G_DO_LOCK
       
   100     jint ret = (jint)m3gPick3D((M3GGroup)aHandle, aMask, (jfloat*)rayElems, (jfloat*)resultElems);
       
   101     M3G_DO_UNLOCK(aEnv)
       
   102     M3G_END_PROFILE(M3G_PROFILE_PICK);
       
   103 
       
   104     if (resultElems)
       
   105         aEnv->ReleaseFloatArrayElements(aResult, resultElems, 0);
       
   106     if (rayElems)
       
   107         aEnv->ReleaseFloatArrayElements(aRay, rayElems, 0);
       
   108     return ret;
       
   109 }
       
   110 
       
   111 JNIEXPORT jint JNICALL Java_javax_microedition_m3g_Group__1getChildCount
       
   112 (JNIEnv* aEnv, jclass, jint aHandle)
       
   113 {
       
   114     M3G_DO_LOCK
       
   115     jint count =(jint)m3gGetChildCount((M3GGroup)aHandle);
       
   116     M3G_DO_UNLOCK(aEnv)
       
   117     return count;
       
   118 }
       
   119 
       
   120 JNIEXPORT void JNICALL Java_javax_microedition_m3g_Group__1removeChild
       
   121 (JNIEnv* aEnv, jclass, jint aHandle, jint aHNode)
       
   122 {
       
   123     M3G_DO_LOCK
       
   124     m3gRemoveChild((M3GGroup)aHandle, (M3GNode)aHNode);
       
   125     M3G_DO_UNLOCK(aEnv)
       
   126 }