Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 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 "SurfaceSession" |
| 18 | |
Steven Moreland | 2279b25 | 2017-07-19 09:50:45 -0700 | [diff] [blame] | 19 | #include <nativehelper/JNIHelp.h> |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 20 | |
| 21 | #include <android_runtime/AndroidRuntime.h> |
| 22 | #include <android_runtime/android_view_SurfaceSession.h> |
| 23 | #include <utils/Log.h> |
| 24 | #include <utils/RefBase.h> |
| 25 | |
| 26 | #include <gui/SurfaceComposerClient.h> |
Robert Carr | d5c7dd6 | 2017-03-08 10:39:30 -0800 | [diff] [blame] | 27 | #include <gui/Surface.h> |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 28 | |
| 29 | namespace android { |
| 30 | |
| 31 | static struct { |
| 32 | jfieldID mNativeClient; |
| 33 | } gSurfaceSessionClassInfo; |
| 34 | |
| 35 | |
| 36 | sp<SurfaceComposerClient> android_view_SurfaceSession_getClient( |
| 37 | JNIEnv* env, jobject surfaceSessionObj) { |
| 38 | return reinterpret_cast<SurfaceComposerClient*>( |
Ashok Bhat | a3850d8 | 2014-01-08 15:34:15 +0000 | [diff] [blame] | 39 | env->GetLongField(surfaceSessionObj, gSurfaceSessionClassInfo.mNativeClient)); |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | |
Ashok Bhat | a3850d8 | 2014-01-08 15:34:15 +0000 | [diff] [blame] | 43 | static jlong nativeCreate(JNIEnv* env, jclass clazz) { |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 44 | SurfaceComposerClient* client = new SurfaceComposerClient(); |
Mathias Agopian | b1d90c8 | 2013-03-06 17:45:42 -0800 | [diff] [blame] | 45 | client->incStrong((void*)nativeCreate); |
Ashok Bhat | a3850d8 | 2014-01-08 15:34:15 +0000 | [diff] [blame] | 46 | return reinterpret_cast<jlong>(client); |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 47 | } |
| 48 | |
Robert Carr | d5c7dd6 | 2017-03-08 10:39:30 -0800 | [diff] [blame] | 49 | static jlong nativeCreateScoped(JNIEnv* env, jclass clazz, jlong surfaceObject) { |
| 50 | Surface *parent = reinterpret_cast<Surface*>(surfaceObject); |
| 51 | SurfaceComposerClient* client = new SurfaceComposerClient(parent->getIGraphicBufferProducer()); |
| 52 | client->incStrong((void*)nativeCreate); |
| 53 | return reinterpret_cast<jlong>(client); |
| 54 | } |
| 55 | |
Ashok Bhat | a3850d8 | 2014-01-08 15:34:15 +0000 | [diff] [blame] | 56 | static void nativeDestroy(JNIEnv* env, jclass clazz, jlong ptr) { |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 57 | SurfaceComposerClient* client = reinterpret_cast<SurfaceComposerClient*>(ptr); |
Mathias Agopian | b1d90c8 | 2013-03-06 17:45:42 -0800 | [diff] [blame] | 58 | client->decStrong((void*)nativeCreate); |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 59 | } |
| 60 | |
Ashok Bhat | a3850d8 | 2014-01-08 15:34:15 +0000 | [diff] [blame] | 61 | static void nativeKill(JNIEnv* env, jclass clazz, jlong ptr) { |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 62 | SurfaceComposerClient* client = reinterpret_cast<SurfaceComposerClient*>(ptr); |
| 63 | client->dispose(); |
| 64 | } |
| 65 | |
Daniel Micay | 76f6a86 | 2015-09-19 17:31:01 -0400 | [diff] [blame] | 66 | static const JNINativeMethod gMethods[] = { |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 67 | /* name, signature, funcPtr */ |
Ashok Bhat | a3850d8 | 2014-01-08 15:34:15 +0000 | [diff] [blame] | 68 | { "nativeCreate", "()J", |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 69 | (void*)nativeCreate }, |
Robert Carr | d5c7dd6 | 2017-03-08 10:39:30 -0800 | [diff] [blame] | 70 | { "nativeCreateScoped", "(J)J", |
| 71 | (void*)nativeCreateScoped }, |
Ashok Bhat | a3850d8 | 2014-01-08 15:34:15 +0000 | [diff] [blame] | 72 | { "nativeDestroy", "(J)V", |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 73 | (void*)nativeDestroy }, |
Ashok Bhat | a3850d8 | 2014-01-08 15:34:15 +0000 | [diff] [blame] | 74 | { "nativeKill", "(J)V", |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 75 | (void*)nativeKill } |
| 76 | }; |
| 77 | |
| 78 | int register_android_view_SurfaceSession(JNIEnv* env) { |
| 79 | int res = jniRegisterNativeMethods(env, "android/view/SurfaceSession", |
| 80 | gMethods, NELEM(gMethods)); |
| 81 | LOG_ALWAYS_FATAL_IF(res < 0, "Unable to register native methods."); |
| 82 | |
| 83 | jclass clazz = env->FindClass("android/view/SurfaceSession"); |
Ashok Bhat | a3850d8 | 2014-01-08 15:34:15 +0000 | [diff] [blame] | 84 | gSurfaceSessionClassInfo.mNativeClient = env->GetFieldID(clazz, "mNativeClient", "J"); |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 85 | return 0; |
| 86 | } |
| 87 | |
| 88 | } // namespace android |