Robert Carr | 48ec4e0 | 2019-07-16 14:28:47 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2019 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 "BLASTBufferQueue" |
| 18 | |
| 19 | #include <nativehelper/JNIHelp.h> |
| 20 | |
| 21 | #include <android_runtime/AndroidRuntime.h> |
| 22 | #include <android_runtime/android_view_Surface.h> |
| 23 | #include <utils/Log.h> |
| 24 | #include <utils/RefBase.h> |
| 25 | |
| 26 | #include <gui/BLASTBufferQueue.h> |
| 27 | #include <gui/Surface.h> |
| 28 | #include <gui/SurfaceComposerClient.h> |
| 29 | |
| 30 | namespace android { |
| 31 | |
| 32 | static jlong nativeCreate(JNIEnv* env, jclass clazz, jlong surfaceControl, jlong width, jlong height) { |
| 33 | sp<BLASTBufferQueue> queue = new BLASTBufferQueue( |
| 34 | reinterpret_cast<SurfaceControl*>(surfaceControl), width, height); |
| 35 | queue->incStrong((void*)nativeCreate); |
| 36 | return reinterpret_cast<jlong>(queue.get()); |
| 37 | } |
| 38 | |
| 39 | static void nativeDestroy(JNIEnv* env, jclass clazz, jlong ptr) { |
| 40 | sp<BLASTBufferQueue> queue = reinterpret_cast<BLASTBufferQueue*>(ptr); |
| 41 | queue->decStrong((void*)nativeCreate); |
| 42 | } |
| 43 | |
| 44 | static jobject nativeGetSurface(JNIEnv* env, jclass clazz, jlong ptr) { |
| 45 | sp<BLASTBufferQueue> queue = reinterpret_cast<BLASTBufferQueue*>(ptr); |
| 46 | return android_view_Surface_createFromIGraphicBufferProducer(env, queue->getIGraphicBufferProducer()); |
| 47 | } |
| 48 | |
| 49 | static void nativeSetNextTransaction(JNIEnv* env, jclass clazz, jlong ptr, jlong transactionPtr) { |
| 50 | sp<BLASTBufferQueue> queue = reinterpret_cast<BLASTBufferQueue*>(ptr); |
| 51 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionPtr); |
| 52 | queue->setNextTransaction(transaction); |
| 53 | } |
| 54 | |
| 55 | static void nativeUpdate(JNIEnv*env, jclass clazz, jlong ptr, jlong surfaceControl, jlong width, jlong height) { |
| 56 | sp<BLASTBufferQueue> queue = reinterpret_cast<BLASTBufferQueue*>(ptr); |
| 57 | queue->update(reinterpret_cast<SurfaceControl*>(surfaceControl), width, height); |
| 58 | } |
| 59 | |
| 60 | static const JNINativeMethod gMethods[] = { |
| 61 | /* name, signature, funcPtr */ |
| 62 | { "nativeCreate", "(JJJ)J", |
| 63 | (void*)nativeCreate }, |
| 64 | { "nativeGetSurface", "(J)Landroid/view/Surface;", |
| 65 | (void*)nativeGetSurface }, |
| 66 | { "nativeDestroy", "(J)V", |
| 67 | (void*)nativeDestroy }, |
| 68 | { "nativeSetNextTransaction", "(JJ)V", |
| 69 | (void*)nativeSetNextTransaction }, |
| 70 | { "nativeUpdate", "(JJJJ)V", |
| 71 | (void*)nativeUpdate } |
| 72 | }; |
| 73 | |
| 74 | int register_android_graphics_BLASTBufferQueue(JNIEnv* env) { |
| 75 | int res = jniRegisterNativeMethods(env, "android/graphics/BLASTBufferQueue", |
| 76 | gMethods, NELEM(gMethods)); |
| 77 | LOG_ALWAYS_FATAL_IF(res < 0, "Unable to register native methods."); |
| 78 | |
| 79 | return 0; |
| 80 | } |
| 81 | |
| 82 | } // namespace android |