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 | |
| 19 | #include "JNIHelp.h" |
| 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> |
| 27 | |
| 28 | namespace android { |
| 29 | |
| 30 | static struct { |
| 31 | jfieldID mNativeClient; |
| 32 | } gSurfaceSessionClassInfo; |
| 33 | |
| 34 | |
| 35 | sp<SurfaceComposerClient> android_view_SurfaceSession_getClient( |
| 36 | JNIEnv* env, jobject surfaceSessionObj) { |
| 37 | return reinterpret_cast<SurfaceComposerClient*>( |
| 38 | env->GetIntField(surfaceSessionObj, gSurfaceSessionClassInfo.mNativeClient)); |
| 39 | } |
| 40 | |
| 41 | |
| 42 | static jint nativeCreate(JNIEnv* env, jclass clazz) { |
| 43 | SurfaceComposerClient* client = new SurfaceComposerClient(); |
Mathias Agopian | b1d90c8 | 2013-03-06 17:45:42 -0800 | [diff] [blame] | 44 | client->incStrong((void*)nativeCreate); |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 45 | return reinterpret_cast<jint>(client); |
| 46 | } |
| 47 | |
| 48 | static void nativeDestroy(JNIEnv* env, jclass clazz, jint ptr) { |
| 49 | SurfaceComposerClient* client = reinterpret_cast<SurfaceComposerClient*>(ptr); |
Mathias Agopian | b1d90c8 | 2013-03-06 17:45:42 -0800 | [diff] [blame] | 50 | client->decStrong((void*)nativeCreate); |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | static void nativeKill(JNIEnv* env, jclass clazz, jint ptr) { |
| 54 | SurfaceComposerClient* client = reinterpret_cast<SurfaceComposerClient*>(ptr); |
| 55 | client->dispose(); |
| 56 | } |
| 57 | |
| 58 | |
| 59 | static JNINativeMethod gMethods[] = { |
| 60 | /* name, signature, funcPtr */ |
| 61 | { "nativeCreate", "()I", |
| 62 | (void*)nativeCreate }, |
| 63 | { "nativeDestroy", "(I)V", |
| 64 | (void*)nativeDestroy }, |
| 65 | { "nativeKill", "(I)V", |
| 66 | (void*)nativeKill } |
| 67 | }; |
| 68 | |
| 69 | int register_android_view_SurfaceSession(JNIEnv* env) { |
| 70 | int res = jniRegisterNativeMethods(env, "android/view/SurfaceSession", |
| 71 | gMethods, NELEM(gMethods)); |
| 72 | LOG_ALWAYS_FATAL_IF(res < 0, "Unable to register native methods."); |
| 73 | |
| 74 | jclass clazz = env->FindClass("android/view/SurfaceSession"); |
| 75 | gSurfaceSessionClassInfo.mNativeClient = env->GetFieldID(clazz, "mNativeClient", "I"); |
| 76 | return 0; |
| 77 | } |
| 78 | |
| 79 | } // namespace android |