Home | History | Annotate | Download | only in jni
      1 /*
      2  * Copyright (C) 2011 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #include "jni/jni_vertex_frame.h"
     18 #include "jni/jni_util.h"
     19 
     20 #include "native/core/vertex_frame.h"
     21 
     22 using android::filterfw::VertexFrame;
     23 
     24 jboolean Java_android_filterfw_core_VertexFrame_nativeAllocate(JNIEnv* env,
     25                                                                jobject thiz,
     26                                                                jint size) {
     27   return ToJBool(WrapObjectInJava(new VertexFrame(size), env, thiz, true));
     28 }
     29 
     30 jboolean Java_android_filterfw_core_VertexFrame_nativeDeallocate(JNIEnv* env, jobject thiz) {
     31   return ToJBool(DeleteNativeObject<VertexFrame>(env, thiz));
     32 }
     33 
     34 jboolean Java_android_filterfw_core_VertexFrame_setNativeInts(JNIEnv* env,
     35                                                               jobject thiz,
     36                                                               jintArray ints) {
     37 
     38   VertexFrame* frame = ConvertFromJava<VertexFrame>(env, thiz);
     39   if (frame && ints) {
     40     jint* int_ptr = env->GetIntArrayElements(ints, NULL);
     41     const int length = env->GetArrayLength(ints);
     42     if (int_ptr) {
     43       const bool success = frame->WriteData(reinterpret_cast<const uint8_t*>(int_ptr),
     44                                             length * sizeof(jint));
     45       env->ReleaseIntArrayElements(ints, int_ptr, JNI_ABORT);
     46       return ToJBool(success);
     47     }
     48   }
     49   return JNI_FALSE;
     50 }
     51 
     52 jboolean Java_android_filterfw_core_VertexFrame_setNativeFloats(JNIEnv* env,
     53                                                                 jobject thiz,
     54                                                                 jfloatArray floats) {
     55   VertexFrame* frame = ConvertFromJava<VertexFrame>(env, thiz);
     56   if (frame && floats) {
     57     jfloat* float_ptr = env->GetFloatArrayElements(floats, NULL);
     58     const int length = env->GetArrayLength(floats);
     59     if (float_ptr) {
     60       const bool success = frame->WriteData(reinterpret_cast<const uint8_t*>(float_ptr),
     61                                             length * sizeof(jfloat));
     62       env->ReleaseFloatArrayElements(floats, float_ptr, JNI_ABORT);
     63       return ToJBool(success);
     64     }
     65   }
     66   return JNI_FALSE;
     67 }
     68 
     69 jboolean Java_android_filterfw_core_VertexFrame_setNativeData(JNIEnv* env,
     70                                                               jobject thiz,
     71                                                               jbyteArray data,
     72                                                               jint offset,
     73                                                               jint length) {
     74   VertexFrame* frame = ConvertFromJava<VertexFrame>(env, thiz);
     75   if (frame && data) {
     76     jbyte* bytes = env->GetByteArrayElements(data, NULL);
     77     if (bytes) {
     78       const bool success = frame->WriteData(reinterpret_cast<const uint8_t*>(bytes + offset),
     79                                             length);
     80       env->ReleaseByteArrayElements(data, bytes, JNI_ABORT);
     81       return ToJBool(success);
     82     }
     83   }
     84   return JNI_FALSE;
     85 }
     86 
     87 jint Java_android_filterfw_core_VertexFrame_getNativeVboId(JNIEnv* env, jobject thiz) {
     88   VertexFrame* frame = ConvertFromJava<VertexFrame>(env, thiz);
     89   return frame ? frame->GetVboId() : -1;
     90 }
     91