blob: 191f748d80bf920ca48fe8d38fb177bb53c9915a [file] [log] [blame]
Jeff Brown64a55af2012-08-26 02:47:39 -07001/*
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 Moreland2279b252017-07-19 09:50:45 -070019#include <nativehelper/JNIHelp.h>
Jeff Brown64a55af2012-08-26 02:47:39 -070020
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 Carrd5c7dd62017-03-08 10:39:30 -080027#include <gui/Surface.h>
Jeff Brown64a55af2012-08-26 02:47:39 -070028
29namespace android {
30
31static struct {
32 jfieldID mNativeClient;
33} gSurfaceSessionClassInfo;
34
35
36sp<SurfaceComposerClient> android_view_SurfaceSession_getClient(
37 JNIEnv* env, jobject surfaceSessionObj) {
38 return reinterpret_cast<SurfaceComposerClient*>(
Ashok Bhata3850d82014-01-08 15:34:15 +000039 env->GetLongField(surfaceSessionObj, gSurfaceSessionClassInfo.mNativeClient));
Jeff Brown64a55af2012-08-26 02:47:39 -070040}
41
42
Ashok Bhata3850d82014-01-08 15:34:15 +000043static jlong nativeCreate(JNIEnv* env, jclass clazz) {
Jeff Brown64a55af2012-08-26 02:47:39 -070044 SurfaceComposerClient* client = new SurfaceComposerClient();
Mathias Agopianb1d90c82013-03-06 17:45:42 -080045 client->incStrong((void*)nativeCreate);
Ashok Bhata3850d82014-01-08 15:34:15 +000046 return reinterpret_cast<jlong>(client);
Jeff Brown64a55af2012-08-26 02:47:39 -070047}
48
Ashok Bhata3850d82014-01-08 15:34:15 +000049static void nativeDestroy(JNIEnv* env, jclass clazz, jlong ptr) {
Jeff Brown64a55af2012-08-26 02:47:39 -070050 SurfaceComposerClient* client = reinterpret_cast<SurfaceComposerClient*>(ptr);
Mathias Agopianb1d90c82013-03-06 17:45:42 -080051 client->decStrong((void*)nativeCreate);
Jeff Brown64a55af2012-08-26 02:47:39 -070052}
53
Ashok Bhata3850d82014-01-08 15:34:15 +000054static void nativeKill(JNIEnv* env, jclass clazz, jlong ptr) {
Jeff Brown64a55af2012-08-26 02:47:39 -070055 SurfaceComposerClient* client = reinterpret_cast<SurfaceComposerClient*>(ptr);
56 client->dispose();
57}
58
Daniel Micay76f6a862015-09-19 17:31:01 -040059static const JNINativeMethod gMethods[] = {
Jeff Brown64a55af2012-08-26 02:47:39 -070060 /* name, signature, funcPtr */
Ashok Bhata3850d82014-01-08 15:34:15 +000061 { "nativeCreate", "()J",
Jeff Brown64a55af2012-08-26 02:47:39 -070062 (void*)nativeCreate },
Ashok Bhata3850d82014-01-08 15:34:15 +000063 { "nativeDestroy", "(J)V",
Jeff Brown64a55af2012-08-26 02:47:39 -070064 (void*)nativeDestroy },
Ashok Bhata3850d82014-01-08 15:34:15 +000065 { "nativeKill", "(J)V",
Jeff Brown64a55af2012-08-26 02:47:39 -070066 (void*)nativeKill }
67};
68
69int 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");
Ashok Bhata3850d82014-01-08 15:34:15 +000075 gSurfaceSessionClassInfo.mNativeClient = env->GetFieldID(clazz, "mNativeClient", "J");
Jeff Brown64a55af2012-08-26 02:47:39 -070076 return 0;
77}
78
79} // namespace android