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 22using android::filterfw::VertexFrame; 23 24jboolean Java_android_filterfw_core_VertexFrame_nativeAllocate(JNIEnv* env, 25 jobject thiz, 26 jint size) { 27 std::unique_ptr<VertexFrame> frame(new VertexFrame(size)); 28 return ToJBool(WrapOwnedObjectInJava(std::move(frame), env, thiz, true)); 29} 30 31jboolean Java_android_filterfw_core_VertexFrame_nativeDeallocate(JNIEnv* env, jobject thiz) { 32 return ToJBool(DeleteNativeObject<VertexFrame>(env, thiz)); 33} 34 35jboolean Java_android_filterfw_core_VertexFrame_setNativeInts(JNIEnv* env, 36 jobject thiz, 37 jintArray ints) { 38 39 VertexFrame* frame = ConvertFromJava<VertexFrame>(env, thiz); 40 if (frame && ints) { 41 jint* int_ptr = env->GetIntArrayElements(ints, NULL); 42 const int length = env->GetArrayLength(ints); 43 if (int_ptr) { 44 const bool success = frame->WriteData(reinterpret_cast<const uint8_t*>(int_ptr), 45 length * sizeof(jint)); 46 env->ReleaseIntArrayElements(ints, int_ptr, JNI_ABORT); 47 return ToJBool(success); 48 } 49 } 50 return JNI_FALSE; 51} 52 53jboolean Java_android_filterfw_core_VertexFrame_setNativeFloats(JNIEnv* env, 54 jobject thiz, 55 jfloatArray floats) { 56 VertexFrame* frame = ConvertFromJava<VertexFrame>(env, thiz); 57 if (frame && floats) { 58 jfloat* float_ptr = env->GetFloatArrayElements(floats, NULL); 59 const int length = env->GetArrayLength(floats); 60 if (float_ptr) { 61 const bool success = frame->WriteData(reinterpret_cast<const uint8_t*>(float_ptr), 62 length * sizeof(jfloat)); 63 env->ReleaseFloatArrayElements(floats, float_ptr, JNI_ABORT); 64 return ToJBool(success); 65 } 66 } 67 return JNI_FALSE; 68} 69 70jboolean Java_android_filterfw_core_VertexFrame_setNativeData(JNIEnv* env, 71 jobject thiz, 72 jbyteArray data, 73 jint offset, 74 jint length) { 75 VertexFrame* frame = ConvertFromJava<VertexFrame>(env, thiz); 76 if (frame && data) { 77 jbyte* bytes = env->GetByteArrayElements(data, NULL); 78 if (bytes) { 79 const bool success = frame->WriteData(reinterpret_cast<const uint8_t*>(bytes + offset), 80 length); 81 env->ReleaseByteArrayElements(data, bytes, JNI_ABORT); 82 return ToJBool(success); 83 } 84 } 85 return JNI_FALSE; 86} 87 88jint Java_android_filterfw_core_VertexFrame_getNativeVboId(JNIEnv* env, jobject thiz) { 89 VertexFrame* frame = ConvertFromJava<VertexFrame>(env, thiz); 90 return frame ? frame->GetVboId() : -1; 91} 92