Derek Sollenberger | 08581f1 | 2009-09-08 18:36:29 -0400 | [diff] [blame] | 1 | /* |
| 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 | |
| 26 | static 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 | |
| 36 | static void surfaceCreated(JNIEnv* env, jobject thiz, jint npp, jobject surface) { |
| 37 | SurfaceSubPlugin* obj = getPluginObject(npp); |
| 38 | |
| 39 | //TODO why is this VM different from the one in NP_INIT... |
| 40 | JavaVM* vm = NULL; |
| 41 | env->GetJavaVM(&vm); |
| 42 | |
| 43 | obj->surfaceCreated(env, surface); |
| 44 | } |
| 45 | |
| 46 | static void surfaceChanged(JNIEnv* env, jobject thiz, jint npp, jint format, jint width, jint height) { |
| 47 | SurfaceSubPlugin* obj = getPluginObject(npp); |
| 48 | obj->surfaceChanged(format, width, height); |
| 49 | } |
| 50 | |
| 51 | static void surfaceDestroyed(JNIEnv* env, jobject thiz, jint npp) { |
| 52 | SurfaceSubPlugin* obj = getPluginObject(npp); |
| 53 | if (obj) { |
| 54 | obj->surfaceDestroyed(); |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | static jboolean isFixedSurface(JNIEnv* env, jobject thiz, jint npp) { |
| 59 | SurfaceSubPlugin* obj = getPluginObject(npp); |
| 60 | return obj->isFixedSurface(); |
| 61 | } |
| 62 | |
| 63 | /* |
| 64 | * JNI registration. |
| 65 | */ |
| 66 | static JNINativeMethod gJavaSamplePluginStubMethods[] = { |
| 67 | { "nativeSurfaceCreated", "(ILandroid/view/View;)V", (void*) surfaceCreated }, |
| 68 | { "nativeSurfaceChanged", "(IIII)V", (void*) surfaceChanged }, |
| 69 | { "nativeSurfaceDestroyed", "(I)V", (void*) surfaceDestroyed }, |
| 70 | { "nativeIsFixedSurface", "(I)Z", (void*) isFixedSurface }, |
| 71 | }; |
| 72 | |
| 73 | EXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) { |
| 74 | |
| 75 | JNIEnv* env = NULL; |
| 76 | |
| 77 | if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) { |
| 78 | return -1; |
| 79 | } |
| 80 | |
| 81 | jniRegisterNativeMethods(env, "com/android/sampleplugin/SamplePluginStub", |
| 82 | gJavaSamplePluginStubMethods, NELEM(gJavaSamplePluginStubMethods)); |
| 83 | |
| 84 | return JNI_VERSION_1_4; |
| 85 | } |