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 | |
Derek Sollenberger | d53b56d | 2010-01-11 12:31:49 -0500 | [diff] [blame] | 26 | extern ANPEventInterfaceV0 gEventI; |
Derek Sollenberger | 51cce58 | 2009-12-01 08:26:20 -0500 | [diff] [blame] | 27 | |
Derek Sollenberger | 08581f1 | 2009-09-08 18:36:29 -0400 | [diff] [blame] | 28 | static void surfaceCreated(JNIEnv* env, jobject thiz, jint npp, jobject surface) { |
Derek Sollenberger | d53b56d | 2010-01-11 12:31:49 -0500 | [diff] [blame] | 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); |
Derek Sollenberger | 08581f1 | 2009-09-08 18:36:29 -0400 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | static void surfaceChanged(JNIEnv* env, jobject thiz, jint npp, jint format, jint width, jint height) { |
Derek Sollenberger | d53b56d | 2010-01-11 12:31:49 -0500 | [diff] [blame] | 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); |
Derek Sollenberger | 08581f1 | 2009-09-08 18:36:29 -0400 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | static void surfaceDestroyed(JNIEnv* env, jobject thiz, jint npp) { |
Derek Sollenberger | d53b56d | 2010-01-11 12:31:49 -0500 | [diff] [blame] | 52 | // send custom event |
| 53 | ANPEvent event; |
| 54 | event.inSize = sizeof(ANPEvent); |
| 55 | event.eventType = kCustom_ANPEventType; |
| 56 | event.data.other[0] = kSurfaceDestroyed_CustomEvent; |
Derek Sollenberger | 08581f1 | 2009-09-08 18:36:29 -0400 | [diff] [blame] | 57 | |
Derek Sollenberger | d53b56d | 2010-01-11 12:31:49 -0500 | [diff] [blame] | 58 | gEventI.postEvent((NPP)npp, &event); |
Derek Sollenberger | 08581f1 | 2009-09-08 18:36:29 -0400 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | /* |
| 62 | * JNI registration. |
| 63 | */ |
Derek Sollenberger | d53b56d | 2010-01-11 12:31:49 -0500 | [diff] [blame] | 64 | static JNINativeMethod gPaintSurfaceMethods[] = { |
| 65 | { "nativeSurfaceCreated", "(I)V", (void*) surfaceCreated }, |
Derek Sollenberger | 08581f1 | 2009-09-08 18:36:29 -0400 | [diff] [blame] | 66 | { "nativeSurfaceChanged", "(IIII)V", (void*) surfaceChanged }, |
| 67 | { "nativeSurfaceDestroyed", "(I)V", (void*) surfaceDestroyed }, |
Derek Sollenberger | 08581f1 | 2009-09-08 18:36:29 -0400 | [diff] [blame] | 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 | |
Derek Sollenberger | d53b56d | 2010-01-11 12:31:49 -0500 | [diff] [blame] | 78 | jniRegisterNativeMethods(env, "com/android/sampleplugin/PaintSurface", |
| 79 | gPaintSurfaceMethods, NELEM(gPaintSurfaceMethods)); |
Derek Sollenberger | 08581f1 | 2009-09-08 18:36:29 -0400 | [diff] [blame] | 80 | |
| 81 | return JNI_VERSION_1_4; |
| 82 | } |