blob: 02f768b34039b97d2d3abeebeba6e8126ee1678f [file] [log] [blame]
Derek Sollenberger08581f12009-09-08 18:36:29 -04001/*
2 * Copyright (C) 2009 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#include <string.h>
18#include <jni.h>
19#include <JNIHelp.h>
20#include <utils/Log.h>
21
22#include "PluginObject.h"
23
24#define EXPORT __attribute__((visibility("default")))
25
26static SurfaceSubPlugin* getPluginObject(int npp) {
27 NPP instance = (NPP)npp;
28 PluginObject* obj = static_cast<PluginObject*>(instance->pdata);
29 if (obj && obj->activePlugin
30 && obj->activePlugin->supportsDrawingModel(kSurface_ANPDrawingModel)) {
31 return static_cast<SurfaceSubPlugin*>(obj->activePlugin);
32 }
33 return NULL;
34}
35
Derek Sollenberger51cce582009-12-01 08:26:20 -050036static jboolean javaInit(JNIEnv* env, jobject thiz, jint npp) {
37 SurfaceSubPlugin* obj = getPluginObject(npp);
38
39 if (obj) {
40 jobject globalObject = env->NewGlobalRef(thiz);
41 obj->setJavaInterface(globalObject);
42 return true;
43 } else {
44 return false;
45 }
46}
47
Derek Sollenberger08581f12009-09-08 18:36:29 -040048static void surfaceCreated(JNIEnv* env, jobject thiz, jint npp, jobject surface) {
49 SurfaceSubPlugin* obj = getPluginObject(npp);
Derek Sollenbergerb8947ee2009-10-05 14:40:18 -040050 jobject globalSurface = env->NewGlobalRef(surface);
51 obj->surfaceCreated(globalSurface);
Derek Sollenberger08581f12009-09-08 18:36:29 -040052}
53
54static void surfaceChanged(JNIEnv* env, jobject thiz, jint npp, jint format, jint width, jint height) {
55 SurfaceSubPlugin* obj = getPluginObject(npp);
56 obj->surfaceChanged(format, width, height);
57}
58
59static void surfaceDestroyed(JNIEnv* env, jobject thiz, jint npp) {
60 SurfaceSubPlugin* obj = getPluginObject(npp);
61 if (obj) {
62 obj->surfaceDestroyed();
63 }
64}
65
Derek Sollenbergerbb660dd2009-10-13 11:43:48 -040066static jint getSurfaceWidth(JNIEnv* env, jobject thiz, jint npp) {
67 SurfaceSubPlugin* obj = getPluginObject(npp);
68 return obj->getPluginWidth();
69}
70
71static jint getSurfaceHeight(JNIEnv* env, jobject thiz, jint npp) {
72 SurfaceSubPlugin* obj = getPluginObject(npp);
73 return obj->getPluginHeight();
74}
75
Derek Sollenberger08581f12009-09-08 18:36:29 -040076static jboolean isFixedSurface(JNIEnv* env, jobject thiz, jint npp) {
77 SurfaceSubPlugin* obj = getPluginObject(npp);
78 return obj->isFixedSurface();
79}
80
81/*
82 * JNI registration.
83 */
Derek Sollenberger04b3e9a2009-11-24 14:50:55 -050084static JNINativeMethod gJavaSamplePluginMethods[] = {
Derek Sollenberger51cce582009-12-01 08:26:20 -050085 { "nativeJavaInit", "(I)Z", (void*) javaInit },
Derek Sollenberger08581f12009-09-08 18:36:29 -040086 { "nativeSurfaceCreated", "(ILandroid/view/View;)V", (void*) surfaceCreated },
87 { "nativeSurfaceChanged", "(IIII)V", (void*) surfaceChanged },
88 { "nativeSurfaceDestroyed", "(I)V", (void*) surfaceDestroyed },
Derek Sollenbergerbb660dd2009-10-13 11:43:48 -040089 { "nativeGetSurfaceWidth", "(I)I", (void*) getSurfaceWidth },
90 { "nativeGetSurfaceHeight", "(I)I", (void*) getSurfaceHeight },
Derek Sollenberger08581f12009-09-08 18:36:29 -040091 { "nativeIsFixedSurface", "(I)Z", (void*) isFixedSurface },
92};
93
94EXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) {
95
96 JNIEnv* env = NULL;
97
98 if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) {
99 return -1;
100 }
101
Derek Sollenberger04b3e9a2009-11-24 14:50:55 -0500102 jniRegisterNativeMethods(env, "com/android/sampleplugin/SamplePlugin",
103 gJavaSamplePluginMethods, NELEM(gJavaSamplePluginMethods));
Derek Sollenberger08581f12009-09-08 18:36:29 -0400104
105 return JNI_VERSION_1_4;
106}