1 /*
2 * Copyright 2022 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 #define LOG_TAG "PublicFormatUtils_JNI"
18
19 #include <utils/misc.h>
20 #include <ui/PublicFormat.h>
21 #include <android_runtime/AndroidRuntime.h>
22 #include <jni.h>
23
24 using namespace android;
25
android_media_PublicFormatUtils_getHalFormat(JNIEnv *,jobject,jint imageFormat)26 static jint android_media_PublicFormatUtils_getHalFormat(JNIEnv* /*env*/, jobject /*thiz*/,
27 jint imageFormat) {
28 PublicFormat publicFormat = static_cast<PublicFormat>(imageFormat);
29 int nativeFormat = mapPublicFormatToHalFormat(publicFormat);
30 return static_cast<jint>(nativeFormat);
31 }
32
android_media_PublicFormatUtils_getHalDataspace(JNIEnv *,jobject,jint imageFormat)33 static jint android_media_PublicFormatUtils_getHalDataspace(JNIEnv* /*env*/, jobject /*thiz*/,
34 jint imageFormat) {
35 PublicFormat publicFormat = static_cast<PublicFormat>(imageFormat);
36 android_dataspace
37 nativeDataspace = mapPublicFormatToHalDataspace(publicFormat);
38 return static_cast<jint>(nativeDataspace);
39 }
40
android_media_PublicFormatUtils_getPublicFormat(JNIEnv *,jobject,jint hardwareBufferFormat,jint dataspace)41 static jint android_media_PublicFormatUtils_getPublicFormat(JNIEnv* /*env*/, jobject /*thiz*/,
42 jint hardwareBufferFormat,
43 jint dataspace) {
44 PublicFormat nativeFormat = mapHalFormatDataspaceToPublicFormat(
45 hardwareBufferFormat, static_cast<android_dataspace>(dataspace));
46 return static_cast<jint>(nativeFormat);
47 }
48
49 static const JNINativeMethod gMethods[] = {
50 {"nativeGetHalFormat", "(I)I", (void*)android_media_PublicFormatUtils_getHalFormat},
51 {"nativeGetHalDataspace", "(I)I", (void*)android_media_PublicFormatUtils_getHalDataspace},
52 {"nativeGetPublicFormat", "(II)I",(void*)android_media_PublicFormatUtils_getPublicFormat}
53 };
54
register_android_media_PublicFormatUtils(JNIEnv * env)55 int register_android_media_PublicFormatUtils(JNIEnv *env) {
56 return AndroidRuntime::registerNativeMethods(env,
57 "android/media/PublicFormatUtils", gMethods, NELEM(gMethods));
58 }
59
60