javauis/m3g_qt/src/jni/vertexArray.inl
branchRCL_3
changeset 19 04becd199f91
equal deleted inserted replaced
16:f5050f1da672 19:04becd199f91
       
     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_VertexArray.h"
       
    18 
       
    19 JNIEXPORT void JNICALL Java_javax_microedition_m3g_VertexArray__1setShort
       
    20 (JNIEnv* aEnv, jclass, jint aHandle, jint aFirst, jint aCount, jshortArray aSrcArray)
       
    21 {
       
    22     int srcLength = 0;
       
    23     unsigned short *srcData = NULL;
       
    24     if (aSrcArray)
       
    25     {
       
    26         srcData = (unsigned short *)aEnv->GetShortArrayElements(aSrcArray, NULL);
       
    27         if (srcData == NULL)
       
    28         {
       
    29             M3G_RAISE_EXCEPTION(aEnv, "java/lang/OutOfMemoryError");
       
    30             return;
       
    31         }
       
    32     }
       
    33 
       
    34     srcLength = aSrcArray ? aEnv->GetArrayLength(aSrcArray) : 0;
       
    35 
       
    36     M3G_DO_LOCK
       
    37     m3gSetVertexArrayElements(
       
    38         (M3GVertexArray) aHandle, aFirst, aCount, srcLength, M3G_SHORT, srcData);
       
    39     M3G_DO_UNLOCK(aEnv)
       
    40 
       
    41     if (aSrcArray)
       
    42     {
       
    43         aEnv->ReleaseShortArrayElements(aSrcArray, (jshort*)srcData, JNI_ABORT);
       
    44     }
       
    45 }
       
    46 
       
    47 JNIEXPORT jint JNICALL Java_javax_microedition_m3g_VertexArray__1ctor
       
    48 (JNIEnv* aEnv, jclass, jint aM3g, jint aNumVertices, jint aNumComponents, jint aComponentSize)
       
    49 {
       
    50     M3G_DO_LOCK
       
    51     M3GVertexArray va = m3gCreateVertexArray((M3GInterface)aM3g,
       
    52                         aNumVertices,
       
    53                         aNumComponents,
       
    54                         (aComponentSize == 1) ? M3G_BYTE :
       
    55                         (aComponentSize == 2) ? M3G_SHORT :
       
    56                         M3G_INT);
       
    57     M3G_DO_UNLOCK(aEnv)
       
    58     return (M3Guint) va;
       
    59 }
       
    60 
       
    61 JNIEXPORT void JNICALL Java_javax_microedition_m3g_VertexArray__1setByte
       
    62 (JNIEnv* aEnv, jclass, jint aHandle, jint aFirst, jint aCount, jbyteArray aSrcArray)
       
    63 {
       
    64     int srcLength = 0;
       
    65     unsigned char *srcData = NULL;
       
    66     if (aSrcArray)
       
    67     {
       
    68         srcData = (unsigned char *)aEnv->GetByteArrayElements(aSrcArray, NULL);
       
    69         if (srcData == NULL)
       
    70         {
       
    71             M3G_RAISE_EXCEPTION(aEnv, "java/lang/OutOfMemoryError");
       
    72             return;
       
    73         }
       
    74     }
       
    75 
       
    76     srcLength = aSrcArray ? aEnv->GetArrayLength(aSrcArray) : 0;
       
    77 
       
    78     if (validateArray(aEnv, aSrcArray, aCount))
       
    79     {
       
    80         M3G_DO_LOCK
       
    81         m3gSetVertexArrayElements(
       
    82             (M3GVertexArray) aHandle, aFirst, aCount, srcLength, M3G_BYTE, srcData);
       
    83         M3G_DO_UNLOCK(aEnv)
       
    84     }
       
    85 
       
    86     if (aSrcArray)
       
    87     {
       
    88         aEnv->ReleaseByteArrayElements(aSrcArray, (jbyte*)srcData, JNI_ABORT);
       
    89     }
       
    90 }
       
    91 
       
    92 /* M3G 1.1 JNI Calls */
       
    93 
       
    94 JNIEXPORT void JNICALL Java_javax_microedition_m3g_VertexArray__1getByte
       
    95 (JNIEnv* aEnv, jclass, jint aHandle, jint aFirstVertex, jint aNumVertices, jbyteArray aSrcArray)
       
    96 {
       
    97     int dstLength = 0;
       
    98     unsigned char *dstData = NULL;
       
    99     if (aSrcArray)
       
   100     {
       
   101         dstData = (unsigned char *)aEnv->GetByteArrayElements(aSrcArray, NULL);
       
   102         if (dstData == NULL)
       
   103         {
       
   104             M3G_RAISE_EXCEPTION(aEnv, "java/lang/OutOfMemoryError");
       
   105             return;
       
   106         }
       
   107     }
       
   108 
       
   109     dstLength = aSrcArray ? aEnv->GetArrayLength(aSrcArray) : 0;
       
   110 
       
   111     /*
       
   112     * Parameter checking and exception throwing is handled in engine side, thus no
       
   113     * checking / validation is done here.
       
   114     */
       
   115     M3G_DO_LOCK
       
   116     m3gGetVertexArrayElements((M3GVertexArray) aHandle, aFirstVertex, aNumVertices, dstLength, M3G_BYTE, dstData);
       
   117     M3G_DO_UNLOCK(aEnv)
       
   118 
       
   119     if (aSrcArray)
       
   120     {
       
   121         /* copy dstData array to java side and release both arrays */
       
   122         aEnv->ReleaseByteArrayElements(aSrcArray, (jbyte*)dstData, 0);
       
   123     }
       
   124 }
       
   125 
       
   126 JNIEXPORT void JNICALL Java_javax_microedition_m3g_VertexArray__1getShort
       
   127 (JNIEnv* aEnv, jclass, jint aHandle, jint aFirstVertex, jint aNumVertices, jshortArray aSrcArray)
       
   128 {
       
   129     int dstLength = 0;
       
   130     unsigned short *dstData = NULL;
       
   131     if (aSrcArray)
       
   132     {
       
   133         dstData = (unsigned short *)aEnv->GetShortArrayElements(aSrcArray, NULL);
       
   134         if (dstData == NULL)
       
   135         {
       
   136             M3G_RAISE_EXCEPTION(aEnv, "java/lang/OutOfMemoryError");
       
   137             return;
       
   138         }
       
   139     }
       
   140 
       
   141     dstLength = aSrcArray ? aEnv->GetArrayLength(aSrcArray) : 0;
       
   142 
       
   143     /*
       
   144     * Parameter checking and exception throwing is handled in engine side, thus no
       
   145     * checking / validation is done here.
       
   146     */
       
   147     M3G_DO_LOCK
       
   148     m3gGetVertexArrayElements((M3GVertexArray) aHandle, aFirstVertex, aNumVertices, dstLength, M3G_SHORT, dstData);
       
   149     M3G_DO_UNLOCK(aEnv)
       
   150 
       
   151     if (aSrcArray)
       
   152     {
       
   153         /* copy dstData array to java side and release both arrays */
       
   154         aEnv->ReleaseShortArrayElements(aSrcArray, (jshort*)dstData, 0);
       
   155     }
       
   156 }
       
   157 
       
   158 JNIEXPORT jint JNICALL Java_javax_microedition_m3g_VertexArray__1getComponentCount
       
   159 (JNIEnv* aEnv, jclass, jint aHandle)
       
   160 {
       
   161     M3Gsizei size;
       
   162     M3G_DO_LOCK
       
   163     m3gGetVertexArrayParams((M3GVertexArray)aHandle, NULL, &size, NULL, NULL);
       
   164     M3G_DO_UNLOCK(aEnv)
       
   165     return (jint)size;
       
   166 }
       
   167 
       
   168 JNIEXPORT jint JNICALL Java_javax_microedition_m3g_VertexArray__1getComponentType
       
   169 (JNIEnv* aEnv, jclass, jint aHandle)
       
   170 {
       
   171     M3Gdatatype type;
       
   172     M3G_DO_LOCK
       
   173     m3gGetVertexArrayParams((M3GVertexArray)aHandle, NULL, NULL, &type, NULL);
       
   174     M3G_DO_UNLOCK(aEnv)
       
   175     type = (type == M3G_BYTE) ? (M3Gdatatype) 1 : (M3Gdatatype) 2;
       
   176     return (jint)type;
       
   177 }
       
   178 
       
   179 JNIEXPORT jint JNICALL Java_javax_microedition_m3g_VertexArray__1getVertexCount
       
   180 (JNIEnv* aEnv, jclass, jint aHandle)
       
   181 {
       
   182     M3Gsizei count;
       
   183     M3G_DO_LOCK
       
   184     m3gGetVertexArrayParams((M3GVertexArray)aHandle, &count, NULL, NULL, NULL);
       
   185     M3G_DO_UNLOCK(aEnv)
       
   186     return (jint)count;
       
   187 }