Panda3D
 All Classes Functions Variables Enumerations
config_android.cxx
1 // Filename: config_android.cxx
2 // Created by: rdb (12Jan13)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #include "config_android.h"
16 #include "pnmFileTypeAndroid.h"
17 #include "pnmFileTypeRegistry.h"
18 #include "dconfig.h"
19 #include "pandaSystem.h"
20 
21 NotifyCategoryDef(android, "");
22 
23 struct android_app *panda_android_app = NULL;
24 
25 jclass jni_PandaActivity;
26 jmethodID jni_PandaActivity_readBitmapSize;
27 jmethodID jni_PandaActivity_readBitmap;
28 
29 jclass jni_BitmapFactory_Options;
30 jfieldID jni_BitmapFactory_Options_outWidth;
31 jfieldID jni_BitmapFactory_Options_outHeight;
32 
33 ////////////////////////////////////////////////////////////////////
34 // Function: init_libandroid
35 // Description: Initializes the library. This must be called at
36 // least once before any of the functions or classes
37 // in this library can be used. Normally, this is
38 // called by JNI_OnLoad.
39 ////////////////////////////////////////////////////////////////////
40 void
41 init_libandroid() {
43  PNMFileTypeAndroid::init_type();
44  PNMFileTypeAndroid::register_with_read_factory();
45  tr->register_type(new PNMFileTypeAndroid);
46 }
47 
48 ////////////////////////////////////////////////////////////////////
49 // Function: JNI_OnLoad
50 // Description: Called by Java when loading this library.
51 // Initializes the global class references and the
52 // method IDs.
53 ////////////////////////////////////////////////////////////////////
54 jint JNI_OnLoad(JavaVM *jvm, void *reserved) {
55  init_libandroid();
56 
57  JNIEnv *env = get_jni_env();
58  assert(env != NULL);
59 
60  jni_PandaActivity = env->FindClass("org/panda3d/android/PandaActivity");
61  jni_PandaActivity = (jclass) env->NewGlobalRef(jni_PandaActivity);
62 
63  jni_PandaActivity_readBitmapSize = env->GetStaticMethodID(jni_PandaActivity,
64  "readBitmapSize", "(J)Landroid/graphics/BitmapFactory$Options;");
65 
66  jni_PandaActivity_readBitmap = env->GetStaticMethodID(jni_PandaActivity,
67  "readBitmap", "(JI)Landroid/graphics/Bitmap;");
68 
69  jni_BitmapFactory_Options = env->FindClass("android/graphics/BitmapFactory$Options");
70  jni_BitmapFactory_Options = (jclass) env->NewGlobalRef(jni_BitmapFactory_Options);
71 
72  jni_BitmapFactory_Options_outWidth = env->GetFieldID(jni_BitmapFactory_Options, "outWidth", "I");
73  jni_BitmapFactory_Options_outHeight = env->GetFieldID(jni_BitmapFactory_Options, "outHeight", "I");
74 
75  return JNI_VERSION_1_4;
76 }
77 
78 ////////////////////////////////////////////////////////////////////
79 // Function: JNI_OnUnload
80 // Description: Called by Java when unloading this library.
81 // Destroys the global class references.
82 ////////////////////////////////////////////////////////////////////
83 void JNI_OnUnload(JavaVM *jvm, void *reserved) {
84  JNIEnv *env = get_jni_env();
85 
86  env->DeleteGlobalRef(jni_PandaActivity);
87  env->DeleteGlobalRef(jni_BitmapFactory_Options);
88 }
static PNMFileTypeRegistry * get_global_ptr()
Returns a pointer to the global PNMFileTypeRegistry object.
This class maintains the set of all known PNMFileTypes in the universe.
void register_type(PNMFileType *type)
Defines a new PNMFileType in the universe.