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 #ifndef ANDROID_FILTEFW_JNI_NATIVE_BUFFER_H 18 #define ANDROID_FILTEFW_JNI_NATIVE_BUFFER_H 19 20 #include <jni.h> 21 22 // Internal Buffer Unwrapping functions //////////////////////////////////////////////////////////// 23 /** 24 * Given a Java NativeBuffer instance, get access to the underlying C pointer and its size. The 25 * size argument may be NULL, in which case the object is not queried for its size. 26 **/ 27 char* GetJBufferData(JNIEnv* env, jobject buffer, int* size); 28 29 /** 30 * Attach a given C data buffer and its size to a given allocated Java NativeBuffer instance. After 31 * this call, the java instance will have the given C buffer as its backing. Note, that the Java 32 * instance contains the flag on whether or not it owns the buffer or not, so make sure it is what 33 * you expect. 34 **/ 35 bool AttachDataToJBuffer(JNIEnv* env, jobject buffer, char* data, int size); 36 37 #ifdef __cplusplus 38 extern "C" { 39 #endif 40 41 // JNI Wrappers //////////////////////////////////////////////////////////////////////////////////// 42 JNIEXPORT jboolean JNICALL 43 Java_android_filterfw_core_NativeBuffer_allocate(JNIEnv* env, jobject thiz, jint size); 44 45 JNIEXPORT jboolean JNICALL 46 Java_android_filterfw_core_NativeBuffer_deallocate(JNIEnv* env, jobject thiz, jboolean owns_data); 47 48 JNIEXPORT jboolean JNICALL 49 Java_android_filterfw_core_NativeBuffer_nativeCopyTo(JNIEnv* env, jobject thiz, jobject new_buffer); 50 51 #ifdef __cplusplus 52 } 53 #endif 54 55 #endif // ANDROID_FILTEFW_JNI_NATIVE_BUFFER_H 56