2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
6 #include <android/bitmap.h>
18 #include "bootstrap.h"
22 /* These variables are used by DisplayError() */
25 jmethodID DisplayError_mid
;
26 jmethodID HandleExit_mid
;
28 /* Dynamically loaded libjnigraphics.so functions */
30 static int (*bm_GetInfo
)(JNIEnv
* env
, jobject jbitmap
, AndroidBitmapInfo
* info
);
31 static int (*bm_Lock
)(JNIEnv
* env
, jobject jbitmap
, void** addrPtr
);
32 static int (*bm_Unlock
)(JNIEnv
* env
, jobject jbitmap
);
35 * This is the main bootstrap entry point.
36 * It parses the configuration file, prepares the environment and loads the kickstart.
37 * In Android it returns after that, allowing Java code to execute Kick() method,
38 * which actually runs the loaded kickstart.
39 * Kick() can be executed multiple times, this is how warm reboot works.
41 int Java_org_aros_bootstrap_AROSBootstrap_Load(JNIEnv
* env
, jobject
this, jstring basedir
)
50 Java_Class
= (*env
)->GetObjectClass(env
, this);
52 DisplayError_mid
= (*env
)->GetMethodID(env
, Java_Class
, "DisplayError", "(Ljava/lang/String;)V");
53 HandleExit_mid
= (*env
)->GetMethodID(env
, Java_Class
, "HandleExit", "(I)V");
55 arospath
= (*env
)->GetStringUTFChars(env
, basedir
, &is_copy
);
56 res
= chdir(arospath
);
60 DisplayError("Failed to locate AROS root directory (%s): %s", arospath
, strerror(errno
));
61 (*env
)->ReleaseStringUTFChars(env
, basedir
, arospath
);
65 (*env
)->ReleaseStringUTFChars(env
, basedir
, arospath
);
66 res
= bootstrap(0, NULL
); /* We can't pass any arguments (yet) */
73 * Wrap a given memory region into ByteBuffer object.
74 * Needed for accessing AROS shared RAM.
75 * FIXME: It would be better to pass in longs here, however looks
76 * like Android gcc has a bug and misaligns arguments in this case. I got
77 * wrong values ('size' was actually 'addr' and 'addr' contained some weird garbage.
78 * Since Android is a 32-bit system, i hope ints are ok for now.
80 jobject
Java_org_aros_bootstrap_AROSBootstrap_MapMemory(JNIEnv
* env
, jobject
this, jint addr
, jint size
)
82 D(kprintf("[Bootstrap] Mapping %u bytes at %p\n", size
, addr
));
84 return (*env
)->NewDirectByteBuffer(env
, (void *)addr
, size
);
88 * Retrieve a string at a given memory address as array of bytes.
89 * FIXME: See above why srcAddr is jint.
92 jbyteArray
Java_org_aros_bootstrap_AROSBootstrap_GetString(JNIEnv
* env
, jobject
this, jint addr
)
94 jsize size
= strlen((void *)addr
);
95 jbyteArray ret
= (*env
)->NewByteArray(env
, size
);
97 (*env
)->SetByteArrayRegion(env
, ret
, 0, size
- 1, (const jbyte
*)addr
);
103 * Copy a given region from AROS displayable bitmap to Java bitmap object.
104 * FIXME: See above why srcAddr is jint.
106 jint
Java_org_aros_bootstrap_AROSBootstrap_GetBitmap(JNIEnv
* env
, jobject
this, jobject bitmap
, jint srcAddr
,
107 jint x
, jint y
, jint width
, jint height
, jint bytesPerLine
)
109 void *src
= (void *)srcAddr
;
111 AndroidBitmapInfo bmdata
;
115 rc
= bm_GetInfo(env
, bitmap
, &bmdata
);
118 D(kprintf("[Bootstrap] Failed to obtain information about bitmap %p\n", bitmap
));
122 rc
= bm_Lock(env
, bitmap
, &dest
);
125 D(kprintf("[Bootstrap] Failed to lock bitmap %p\n", bitmap
));
129 /* This is ARGB bitmap, 4 bytes per pixel */
130 src
+= y
* bytesPerLine
+ (x
<< 2);
131 dest
+= y
* bmdata
.stride
+ (x
<< 2);
134 for (yc
= 0; yc
< height
; yc
++)
136 memcpy(dest
, src
, width
);
138 dest
+= bmdata
.stride
;
141 return bm_Unlock(env
, bitmap
);
144 jint
JNI_OnLoad(JavaVM
*vm
, void *reserved
)
146 libjnigraphics
= dlopen("libjnigraphics.so", RTLD_NOW
);
147 D(kprintf("[Bootstrap] libjnigraphics.so handle: %p\n"));
151 bm_GetInfo
= dlsym(libjnigraphics
, "AndroidBitmap_getInfo");
152 bm_Lock
= dlsym(libjnigraphics
, "AndroidBitmap_lockPixels");
153 bm_Unlock
= dlsym(libjnigraphics
, "AndroidBitmap_unlockPixels");
156 /* Dalvik wants a minimum of 1.4. Returning 1.1 causes exception. */
157 return JNI_VERSION_1_4
;
160 jboolean
Java_org_aros_bootstrap_AROSBootstrap_HaveNativeGraphics(JNIEnv
* env
, jobject
this)
162 return libjnigraphics
? JNI_TRUE
: JNI_FALSE
;