• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #undef ANDROID_UTILS_REF_BASE_DISABLE_IMPLICIT_CONSTRUCTION // TODO:remove this and fix code
17 
18 #define LOG_TAG "SurfaceSession"
19 
20 #include <nativehelper/JNIHelp.h>
21 
22 #include <android_runtime/AndroidRuntime.h>
23 #include <android_runtime/android_view_SurfaceSession.h>
24 #include <utils/Log.h>
25 #include <utils/RefBase.h>
26 
27 #include <gui/SurfaceComposerClient.h>
28 #include <gui/Surface.h>
29 
30 namespace android {
31 
32 static struct {
33     jfieldID mNativeClient;
34 } gSurfaceSessionClassInfo;
35 
36 
android_view_SurfaceSession_getClient(JNIEnv * env,jobject surfaceSessionObj)37 sp<SurfaceComposerClient> android_view_SurfaceSession_getClient(
38         JNIEnv* env, jobject surfaceSessionObj) {
39     return reinterpret_cast<SurfaceComposerClient*>(
40             env->GetLongField(surfaceSessionObj, gSurfaceSessionClassInfo.mNativeClient));
41 }
42 
43 
nativeCreate(JNIEnv * env,jclass clazz)44 static jlong nativeCreate(JNIEnv* env, jclass clazz) {
45     // Will be deleted via decStrong() in nativeDestroy.
46     auto client = sp<SurfaceComposerClient>::make();
47     return reinterpret_cast<jlong>(client.release());
48 }
49 
nativeDestroy(JNIEnv * env,jclass clazz,jlong ptr)50 static void nativeDestroy(JNIEnv* env, jclass clazz, jlong ptr) {
51     SurfaceComposerClient* client = reinterpret_cast<SurfaceComposerClient*>(ptr);
52     client->decStrong((void*)client);
53 }
54 
55 static const JNINativeMethod gMethods[] = {
56     /* name, signature, funcPtr */
nativeCreate()57     { "nativeCreate", "()J",
58             (void*)nativeCreate },
nativeDestroy(J)59     { "nativeDestroy", "(J)V",
60             (void*)nativeDestroy },
61 };
62 
register_android_view_SurfaceSession(JNIEnv * env)63 int register_android_view_SurfaceSession(JNIEnv* env) {
64     int res = jniRegisterNativeMethods(env, "android/view/SurfaceSession",
65             gMethods, NELEM(gMethods));
66     LOG_ALWAYS_FATAL_IF(res < 0, "Unable to register native methods.");
67 
68     jclass clazz = env->FindClass("android/view/SurfaceSession");
69     gSurfaceSessionClassInfo.mNativeClient = env->GetFieldID(clazz, "mNativeClient", "J");
70     return 0;
71 }
72 
73 } // namespace android
74