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 <nativehelper/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 #include <gui/Surface.h>
28
29 namespace android {
30
31 static struct {
32 jfieldID mNativeClient;
33 } gSurfaceSessionClassInfo;
34
35
android_view_SurfaceSession_getClient(JNIEnv * env,jobject surfaceSessionObj)36 sp<SurfaceComposerClient> android_view_SurfaceSession_getClient(
37 JNIEnv* env, jobject surfaceSessionObj) {
38 return reinterpret_cast<SurfaceComposerClient*>(
39 env->GetLongField(surfaceSessionObj, gSurfaceSessionClassInfo.mNativeClient));
40 }
41
42
nativeCreate(JNIEnv * env,jclass clazz)43 static jlong nativeCreate(JNIEnv* env, jclass clazz) {
44 SurfaceComposerClient* client = new SurfaceComposerClient();
45 client->incStrong((void*)nativeCreate);
46 return reinterpret_cast<jlong>(client);
47 }
48
nativeDestroy(JNIEnv * env,jclass clazz,jlong ptr)49 static void nativeDestroy(JNIEnv* env, jclass clazz, jlong ptr) {
50 SurfaceComposerClient* client = reinterpret_cast<SurfaceComposerClient*>(ptr);
51 client->decStrong((void*)nativeCreate);
52 }
53
54 static const JNINativeMethod gMethods[] = {
55 /* name, signature, funcPtr */
56 { "nativeCreate", "()J",
57 (void*)nativeCreate },
58 { "nativeDestroy", "(J)V",
59 (void*)nativeDestroy },
60 };
61
register_android_view_SurfaceSession(JNIEnv * env)62 int register_android_view_SurfaceSession(JNIEnv* env) {
63 int res = jniRegisterNativeMethods(env, "android/view/SurfaceSession",
64 gMethods, NELEM(gMethods));
65 LOG_ALWAYS_FATAL_IF(res < 0, "Unable to register native methods.");
66
67 jclass clazz = env->FindClass("android/view/SurfaceSession");
68 gSurfaceSessionClassInfo.mNativeClient = env->GetFieldID(clazz, "mNativeClient", "J");
69 return 0;
70 }
71
72 } // namespace android
73