Game Development Reference
In-Depth Information
{
JNIEnv *env;
if ( !g_VM) {
printf("No JNI VM available.\n");
return;
}
(*g_VM)->AttachCurrentThread (g_VM, (void **) &env, NULL);
iSize = width * height;
// Create a new int[] used by jni_send_pixels
jImage = (*env)-> NewIntArray(env, iSize);
// Call doom.util.Natives.OnInitGraphics(w, h);
jmethodID mid = (*env)->GetStaticMethodID(env, jNativesCls
, CB_CLASS_IG_CB
, CB_CLASS_IG_SIG);
if (mid) {
(*env)->CallStaticVoidMethod(env, jNativesCls
, mid
, width, height);
}
}
Video Buffer Callback
The video buffer callback is critical, and it must be lean and mean. It gets called continuously and must
not create any objects (see Listing 7-16). Like the previous callback, it attaches to the current thread. It
also calls the static void method doom.jni.Natives.OnImageUpdate(int[] pixels) . But before calling this
method, it must set the pixels into the Java array ( jImage ):
(*env)->SetIntArrayRegion(env, jImage, 0, iSize, (jint *) data)
data is an array of integers already formatted as 32-bit ARGB pixels, as required by Android, and
iSize is the size of the display calculated in the previous callback.
Listing 7-16. Sending Video Pixels
/**
* Image update Java callback. Gets called many times per sec.
* It must not look up JNI classes/methods or create any objects; otherwise
* the local JNI ref table will overflow & the app will crash
*/
void jni_send_pixels(int * data)
{
JNIEnv *env;
Search WWH ::




Custom Search