blob: 22e76dab2269dc68220777c6c31eb270a76a880c [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
54static jboolean isFixedSurface(JNIEnv* env, jobject thiz, jint npp) {
55 SurfaceSubPlugin* obj = getPluginObject(npp);
56 return obj->isFixedSurface();
57}
58
59/*
60 * JNI registration.
61 */
62static JNINativeMethod gJavaSamplePluginStubMethods[] = {
63 { "nativeSurfaceCreated", "(ILandroid/view/View;)V", (void*) surfaceCreated },
64 { "nativeSurfaceChanged", "(IIII)V", (void*) surfaceChanged },
65 { "nativeSurfaceDestroyed", "(I)V", (void*) surfaceDestroyed },
66 { "nativeIsFixedSurface", "(I)Z", (void*) isFixedSurface },
67};
68
69EXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) {
70
71 JNIEnv* env = NULL;
72
73 if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) {
74 return -1;
75 }
76
77 jniRegisterNativeMethods(env, "com/android/sampleplugin/SamplePluginStub",
78 gJavaSamplePluginStubMethods, NELEM(gJavaSamplePluginStubMethods));
79
80 return JNI_VERSION_1_4;
81}