javauis/m3g_qt/src/jni/keyframeSequence.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 #include "javax_microedition_m3g_KeyframeSequence.h"
       
    18 
       
    19 JNIEXPORT jint JNICALL Java_javax_microedition_m3g_KeyframeSequence__1getRepeatMode
       
    20 (JNIEnv* aEnv, jclass, jint aHandle)
       
    21 {
       
    22     M3G_DO_LOCK
       
    23     jint mode = (jint)m3gGetRepeatMode((M3GKeyframeSequence)aHandle);
       
    24     M3G_DO_UNLOCK(aEnv)
       
    25     return mode;
       
    26 }
       
    27 
       
    28 JNIEXPORT void JNICALL Java_javax_microedition_m3g_KeyframeSequence__1setKeyframe
       
    29 (JNIEnv* aEnv, jclass, jint aHandle, jint aIndex, jint aTime, jfloatArray aValue)
       
    30 {
       
    31     jfloat* elems = NULL;
       
    32     if (aValue)
       
    33     {
       
    34         elems = aEnv->GetFloatArrayElements(aValue, NULL);
       
    35         if (elems == NULL)
       
    36         {
       
    37             M3G_RAISE_EXCEPTION(aEnv, "java/lang/OutOfMemoryError");
       
    38             return;
       
    39         }
       
    40     }
       
    41 
       
    42     jsize length = aValue ? aEnv->GetArrayLength(aValue) : 0;
       
    43 
       
    44     M3G_DO_LOCK
       
    45     m3gSetKeyframe((M3GKeyframeSequence)aHandle,
       
    46                    aIndex,
       
    47                    aTime,
       
    48                    length,
       
    49                    (const M3Gfloat *)elems);
       
    50     M3G_DO_UNLOCK(aEnv)
       
    51 
       
    52     if (elems)
       
    53         aEnv->ReleaseFloatArrayElements(aValue, elems, 0);
       
    54 }
       
    55 
       
    56 JNIEXPORT void JNICALL Java_javax_microedition_m3g_KeyframeSequence__1setRepeatMode
       
    57 (JNIEnv* aEnv, jclass, jint aHandle, jint aMode)
       
    58 {
       
    59     M3G_DO_LOCK
       
    60     m3gSetRepeatMode((M3GKeyframeSequence)aHandle, (M3Genum)aMode);
       
    61     M3G_DO_UNLOCK(aEnv)
       
    62 }
       
    63 
       
    64 JNIEXPORT void JNICALL Java_javax_microedition_m3g_KeyframeSequence__1setDuration
       
    65 (JNIEnv* aEnv, jclass, jint aHandle, jint aDuration)
       
    66 {
       
    67     M3G_DO_LOCK
       
    68     m3gSetDuration((M3GKeyframeSequence)aHandle, (int)aDuration);
       
    69     M3G_DO_UNLOCK(aEnv)
       
    70 }
       
    71 
       
    72 JNIEXPORT jint JNICALL Java_javax_microedition_m3g_KeyframeSequence__1ctor
       
    73 (JNIEnv* aEnv, jclass, jint aM3g, jint aNumKeyframes, jint aNumComponents, jint aInterpolation)
       
    74 {
       
    75     M3G_DO_LOCK
       
    76     jint handle = (jint)m3gCreateKeyframeSequence((M3GInterface)aM3g, aNumKeyframes,
       
    77                   aNumComponents, aInterpolation);
       
    78     M3G_DO_UNLOCK(aEnv)
       
    79     return handle;
       
    80 }
       
    81 
       
    82 JNIEXPORT void JNICALL Java_javax_microedition_m3g_KeyframeSequence__1setValidRange
       
    83 (JNIEnv* aEnv, jclass, jint aHandle, jint aFirst, jint aLast)
       
    84 {
       
    85     M3G_DO_LOCK
       
    86     m3gSetValidRange((M3GKeyframeSequence)aHandle, aFirst, aLast);
       
    87     M3G_DO_UNLOCK(aEnv)
       
    88 }
       
    89 
       
    90 JNIEXPORT jint JNICALL Java_javax_microedition_m3g_KeyframeSequence__1getDuration
       
    91 (JNIEnv* aEnv, jclass, jint aHandle)
       
    92 {
       
    93     M3G_DO_LOCK
       
    94     jint duration = (jint)m3gGetDuration((M3GKeyframeSequence)aHandle);
       
    95     M3G_DO_UNLOCK(aEnv)
       
    96     return duration;
       
    97 }
       
    98 
       
    99 /* M3G 1.1 JNI Calls */
       
   100 
       
   101 JNIEXPORT jint JNICALL Java_javax_microedition_m3g_KeyframeSequence__1getComponentCount
       
   102 (JNIEnv* aEnv, jclass, jint aHandle)
       
   103 {
       
   104     M3G_DO_LOCK
       
   105     jint count = (jint)m3gGetComponentCount((M3GKeyframeSequence)aHandle);
       
   106     M3G_DO_UNLOCK(aEnv)
       
   107     return count;
       
   108 }
       
   109 
       
   110 JNIEXPORT jint JNICALL Java_javax_microedition_m3g_KeyframeSequence__1getInterpolationType
       
   111 (JNIEnv* aEnv, jclass, jint aHandle)
       
   112 {
       
   113     M3G_DO_LOCK
       
   114     jint type = (jint)m3gGetInterpolationType((M3GKeyframeSequence)aHandle);
       
   115     M3G_DO_UNLOCK(aEnv)
       
   116     return type;
       
   117 }
       
   118 
       
   119 JNIEXPORT jint JNICALL Java_javax_microedition_m3g_KeyframeSequence__1getKeyframe
       
   120 (JNIEnv* aEnv, jclass, jint aHandle, jint aIndex, jfloatArray aValue)
       
   121 {
       
   122     jfloat* elems = NULL;
       
   123     if (aValue)
       
   124     {
       
   125         elems = aEnv->GetFloatArrayElements(aValue, NULL);
       
   126         if (elems == NULL)
       
   127         {
       
   128             M3G_RAISE_EXCEPTION(aEnv, "java/lang/OutOfMemoryError");
       
   129             return 0;
       
   130         }
       
   131     }
       
   132 
       
   133     jsize length = aValue ? aEnv->GetArrayLength(aValue) : 0;
       
   134 
       
   135     if ((length < m3gGetComponentCount((M3GKeyframeSequence)aHandle)) &&
       
   136             (aValue != NULL))
       
   137     {
       
   138         if (elems)
       
   139         {
       
   140             aEnv->ReleaseFloatArrayElements(aValue, elems, JNI_ABORT);
       
   141         }
       
   142         M3G_RAISE_EXCEPTION(aEnv, "java/lang/IllegalArgumentException");
       
   143         return 0;
       
   144     }
       
   145 
       
   146     M3G_DO_LOCK
       
   147     jint keyFrame = m3gGetKeyframe((M3GKeyframeSequence)aHandle, aIndex, elems);
       
   148     M3G_DO_UNLOCK(aEnv)
       
   149 
       
   150     if (elems)
       
   151     {
       
   152         /* copy array to java side and release arrays */
       
   153         aEnv->ReleaseFloatArrayElements(aValue, elems, 0);
       
   154     }
       
   155     return keyFrame;
       
   156 }
       
   157 
       
   158 JNIEXPORT jint JNICALL Java_javax_microedition_m3g_KeyframeSequence__1getKeyframeCount
       
   159 (JNIEnv* aEnv, jclass, jint aHandle)
       
   160 {
       
   161     M3G_DO_LOCK
       
   162     jint count = (jint)m3gGetKeyframeCount((M3GKeyframeSequence)aHandle);
       
   163     M3G_DO_UNLOCK(aEnv)
       
   164     return count;
       
   165 }
       
   166 
       
   167 JNIEXPORT jint JNICALL Java_javax_microedition_m3g_KeyframeSequence__1getValidRangeFirst
       
   168 (JNIEnv* aEnv, jclass, jint aHandle)
       
   169 {
       
   170     int first = 0;
       
   171     int last = 0;
       
   172     M3G_DO_LOCK
       
   173     m3gGetValidRange((M3GKeyframeSequence)aHandle, &first, &last);
       
   174     M3G_DO_UNLOCK(aEnv)
       
   175     return first;
       
   176 }
       
   177 
       
   178 JNIEXPORT jint JNICALL Java_javax_microedition_m3g_KeyframeSequence__1getValidRangeLast
       
   179 (JNIEnv* aEnv, jclass, jint aHandle)
       
   180 {
       
   181     int first = 0;
       
   182     int last = 0;
       
   183     M3G_DO_LOCK
       
   184     m3gGetValidRange((M3GKeyframeSequence)aHandle, &first, &last);
       
   185     M3G_DO_UNLOCK(aEnv)
       
   186     return last;
       
   187 }