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 extern ANPEventInterfaceV0 gEventI; 27 28 static void surfaceCreated(JNIEnv* env, jobject thiz, jint npp, jobject surface) { 29 30 // send custom event 31 ANPEvent event; 32 event.inSize = sizeof(ANPEvent); 33 event.eventType = kCustom_ANPEventType; 34 event.data.other[0] = kSurfaceCreated_CustomEvent; 35 36 gEventI.postEvent((NPP)npp, &event); 37 } 38 39 static void surfaceChanged(JNIEnv* env, jobject thiz, jint npp, jint format, jint width, jint height) { 40 // send custom event 41 ANPEvent event; 42 event.inSize = sizeof(ANPEvent); 43 event.eventType = kCustom_ANPEventType; 44 event.data.other[0] = kSurfaceChanged_CustomEvent; 45 event.data.other[1] = width; 46 event.data.other[2] = height; 47 48 gEventI.postEvent((NPP)npp, &event); 49 } 50 51 static void surfaceDestroyed(JNIEnv* env, jobject thiz, jint npp) { 52 // send custom event 53 ANPEvent event; 54 event.inSize = sizeof(ANPEvent); 55 event.eventType = kCustom_ANPEventType; 56 event.data.other[0] = kSurfaceDestroyed_CustomEvent; 57 58 gEventI.postEvent((NPP)npp, &event); 59 } 60 61 /* 62 * JNI registration. 63 */ 64 static JNINativeMethod gPaintSurfaceMethods[] = { 65 { "nativeSurfaceCreated", "(I)V", (void*) surfaceCreated }, 66 { "nativeSurfaceChanged", "(IIII)V", (void*) surfaceChanged }, 67 { "nativeSurfaceDestroyed", "(I)V", (void*) surfaceDestroyed }, 68 }; 69 70 EXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) { 71 72 JNIEnv* env = NULL; 73 74 if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) { 75 return -1; 76 } 77 78 jniRegisterNativeMethods(env, "com/android/sampleplugin/PaintSurface", 79 gPaintSurfaceMethods, NELEM(gPaintSurfaceMethods)); 80 81 return JNI_VERSION_1_4; 82 } 83