blob: bcca7d0dd48f07c34c1a9a2da665651d5c5a40c8 [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
36static void surfaceCreated(JNIEnv* env, jobject thiz, jint npp, jobject surface) {
37 SurfaceSubPlugin* obj = getPluginObject(npp);
Derek Sollenbergerb8947ee2009-10-05 14:40:18 -040038 jobject globalSurface = env->NewGlobalRef(surface);
39 obj->surfaceCreated(globalSurface);
Derek Sollenberger08581f12009-09-08 18:36:29 -040040}
41
42static void surfaceChanged(JNIEnv* env, jobject thiz, jint npp, jint format, jint width, jint height) {
43 SurfaceSubPlugin* obj = getPluginObject(npp);
44 obj->surfaceChanged(format, width, height);
45}
46
47static void surfaceDestroyed(JNIEnv* env, jobject thiz, jint npp) {
48 SurfaceSubPlugin* obj = getPluginObject(npp);
49 if (obj) {
50 obj->surfaceDestroyed();
51 }
52}
53
Derek Sollenbergerbb660dd2009-10-13 11:43:48 -040054static jint getSurfaceWidth(JNIEnv* env, jobject thiz, jint npp) {
55 SurfaceSubPlugin* obj = getPluginObject(npp);
56 return obj->getPluginWidth();
57}
58
59static jint getSurfaceHeight(JNIEnv* env, jobject thiz, jint npp) {
60 SurfaceSubPlugin* obj = getPluginObject(npp);
61 return obj->getPluginHeight();
62}
63
Derek Sollenberger08581f12009-09-08 18:36:29 -040064static jboolean isFixedSurface(JNIEnv* env, jobject thiz, jint npp) {
65 SurfaceSubPlugin* obj = getPluginObject(npp);
66 return obj->isFixedSurface();
67}
68
69/*
70 * JNI registration.
71 */
Derek Sollenberger04b3e9a2009-11-24 14:50:55 -050072static JNINativeMethod gJavaSamplePluginMethods[] = {
Derek Sollenberger08581f12009-09-08 18:36:29 -040073 { "nativeSurfaceCreated", "(ILandroid/view/View;)V", (void*) surfaceCreated },
74 { "nativeSurfaceChanged", "(IIII)V", (void*) surfaceChanged },
75 { "nativeSurfaceDestroyed", "(I)V", (void*) surfaceDestroyed },
Derek Sollenbergerbb660dd2009-10-13 11:43:48 -040076 { "nativeGetSurfaceWidth", "(I)I", (void*) getSurfaceWidth },
77 { "nativeGetSurfaceHeight", "(I)I", (void*) getSurfaceHeight },
Derek Sollenberger08581f12009-09-08 18:36:29 -040078 { "nativeIsFixedSurface", "(I)Z", (void*) isFixedSurface },
79};
80
81EXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) {
82
83 JNIEnv* env = NULL;
84
85 if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) {
86 return -1;
87 }
88
Derek Sollenberger04b3e9a2009-11-24 14:50:55 -050089 jniRegisterNativeMethods(env, "com/android/sampleplugin/SamplePlugin",
90 gJavaSamplePluginMethods, NELEM(gJavaSamplePluginMethods));
Derek Sollenberger08581f12009-09-08 18:36:29 -040091
92 return JNI_VERSION_1_4;
93}