blob: 1b22e62e3a4faa159a52d4ce60ddd3d35c9b0356 [file] [log] [blame]
/*
* Copyright 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#define LOG_TAG "ANativeWindowTest"
#include <array>
#include <android/native_window.h>
#include <android/native_window_jni.h>
#include <jni.h>
namespace {
void pushBufferWithTransform(JNIEnv* env, jclass, jobject jSurface, jint transform) {
auto window = ANativeWindow_fromSurface(env, jSurface);
ANativeWindow_setBuffersTransform(window, transform);
ANativeWindow_Buffer mappedBuffer;
ANativeWindow_lock(window, &mappedBuffer, nullptr);
ANativeWindow_unlockAndPost(window);
ANativeWindow_release(window);
}
jint setBuffersDataSpace(JNIEnv* env, jclass, jobject jSurface, jint dataSpace) {
ANativeWindow* window = nullptr;
if (jSurface) {
window = ANativeWindow_fromSurface(env, jSurface);
}
int error = ANativeWindow_setBuffersDataSpace(window, dataSpace);
if (error != 0) {
return error;
}
ANativeWindow_Buffer mappedBuffer;
ANativeWindow_lock(window, &mappedBuffer, nullptr);
ANativeWindow_unlockAndPost(window);
ANativeWindow_release(window);
return error;
}
jint getBuffersDataSpace(JNIEnv* env, jclass, jobject jSurface) {
ANativeWindow* window = nullptr;
if (jSurface) {
window = ANativeWindow_fromSurface(env, jSurface);
}
return ANativeWindow_getBuffersDataSpace(window);
}
void tryAllocateBuffers(JNIEnv* env, jclass, jobject jSurface) {
ANativeWindow* window = nullptr;
if (jSurface) {
window = ANativeWindow_fromSurface(env, jSurface);
}
ANativeWindow_tryAllocateBuffers(window);
if (window) {
ANativeWindow_release(window);
}
}
const std::array<JNINativeMethod, 4> JNI_METHODS = {{
{"nPushBufferWithTransform", "(Landroid/view/Surface;I)V",
(void*)pushBufferWithTransform},
{"nSetBuffersDataSpace", "(Landroid/view/Surface;I)I",
(void*)setBuffersDataSpace},
{"nGetBuffersDataSpace", "(Landroid/view/Surface;)I",
(void*)getBuffersDataSpace},
{"nTryAllocateBuffers", "(Landroid/view/Surface;)V",
(void*)tryAllocateBuffers},
}};
}
int register_android_graphics_cts_ANativeWindowTest(JNIEnv* env) {
jclass clazz = env->FindClass("android/graphics/cts/ANativeWindowTest");
return env->RegisterNatives(clazz, JNI_METHODS.data(), JNI_METHODS.size());
}