(追記:このデモは サイケデリック デモとして公開しました。)
作ったゼ!!!!
http://sites.google.com/site/koyamakannon/Home/android-plasma.zip
描画のために C側でintの配列を操作するわけだけど,一番オーバーヘッドが少なさそうなのがこの関数だ.
こんな感じで使った:
JNIEXPORT void JNICALL Java_jp_keigoi_androidanime_MyView_drawsquare (JNIEnv * env, jobject self, jintArray arr, jint x, jint y, jint w, jint h, jint bw, jint bh, jint color) { jint * const a = (jint*)(*env)->GetPrimitiveArrayCritical(env, arr, 0); jint *p = a; for(; p < a + y * bw; p++) { *p = 0; } for(int i = 0; i < h; i++) { for(int j = 0; j < x; j++) { *p = 0; p++; } for(int j = x; j < x+w; j++) { *p = color; p++; } for(int j = x+w; j < bw; j++) { *p = 0; p++; } } for(; p < a + bw*bh; p++) { *p = 0; } (*env)->ReleasePrimitiveArrayCritical(env, arr, a, 0); }
昨日のしょうもないアプリの画面描画をJNIで書き直してみた。 ちゃんとパフォーマンス計測していないので何を言ってもアレだけど体感で5倍以上にはなってる気がする(FPSとか表示するのは今後の課題)。そりゃー JITも何もないVMと比べたら当然だよなぁと思いつつ、一気に Androidメガデモ計画が現実的になってきたことはやや嬉しい。
LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_CFLAGS := -std=c99 LOCAL_MODULE := androidanime LOCAL_SRC_FILES := animetest-jni.c include $(BUILD_SHARED_LIBRARY)
public native void drawsquare(int[] bitmap, int x, int y, int w, int h, int bw, int bh, int color);
static { System.loadLibrary("androidanime"); }
(eclipseが勝手に bin/ 以下に .class ファイルを作ってくれる)
cd bin javah -classpath . (native宣言したクラスのQN, たとえば jp.keigoi.androidanime.MyView)
$ make APP=androidanime -B Android NDK: Building for application 'androidanime' Compile thumb : androidanime <= sources/keigoi/androidanime/animetest-jni.c SharedLibrary : libandroidanime.so Install : libandroidanime.so => apps/androidanime/project/libs/armeabi
実行.
Marty2012/02/15 02:06My hat is off to your astute comnmad over this topic-bravo!
znxlgvfyyk2012/02/15 22:08vVrbZm , [url=http://temroksyiipy.com/]temroksyiipy[/url], [link=http://ucydznjsetmj.com/]ucydznjsetmj[/link], http://cnaiovexhhwq.com/
owvsgkgme2012/02/17 21:339oMws1 <a href="http://nwzmbrndgcin.com/">nwzmbrndgcin</a>