summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--android/src/org/rockbox/RockboxFramebuffer.java19
-rw-r--r--firmware/target/hosted/android/lcd-android.c52
2 files changed, 42 insertions, 29 deletions
diff --git a/android/src/org/rockbox/RockboxFramebuffer.java b/android/src/org/rockbox/RockboxFramebuffer.java
index 66e5991a3e..e1fb99f2a1 100644
--- a/android/src/org/rockbox/RockboxFramebuffer.java
+++ b/android/src/org/rockbox/RockboxFramebuffer.java
@@ -39,7 +39,6 @@ public class RockboxFramebuffer extends SurfaceView
39{ 39{
40 private final DisplayMetrics metrics; 40 private final DisplayMetrics metrics;
41 private final ViewConfiguration view_config; 41 private final ViewConfiguration view_config;
42 private ByteBuffer native_buf;
43 private Bitmap btm; 42 private Bitmap btm;
44 43
45 /* first stage init; needs to run from a thread that has a Looper 44 /* first stage init; needs to run from a thread that has a Looper
@@ -47,7 +46,6 @@ public class RockboxFramebuffer extends SurfaceView
47 public RockboxFramebuffer(Context c) 46 public RockboxFramebuffer(Context c)
48 { 47 {
49 super(c); 48 super(c);
50
51 metrics = c.getResources().getDisplayMetrics(); 49 metrics = c.getResources().getDisplayMetrics();
52 view_config = ViewConfiguration.get(c); 50 view_config = ViewConfiguration.get(c);
53 getHolder().addCallback(this); 51 getHolder().addCallback(this);
@@ -61,18 +59,17 @@ public class RockboxFramebuffer extends SurfaceView
61 59
62 /* second stage init; called from Rockbox with information about the 60 /* second stage init; called from Rockbox with information about the
63 * display framebuffer */ 61 * display framebuffer */
64 private void java_lcd_init(int lcd_width, int lcd_height, ByteBuffer native_fb) 62 private void initialize(int lcd_width, int lcd_height)
65 { 63 {
66 btm = Bitmap.createBitmap(lcd_width, lcd_height, Bitmap.Config.RGB_565); 64 btm = Bitmap.createBitmap(lcd_width, lcd_height, Bitmap.Config.RGB_565);
67 native_buf = native_fb;
68 setEnabled(true); 65 setEnabled(true);
69 } 66 }
70 67
71 private void java_lcd_update() 68 private void update(ByteBuffer framebuffer)
72 { 69 {
73 SurfaceHolder holder = getHolder(); 70 SurfaceHolder holder = getHolder();
74 Canvas c = holder.lockCanvas(null); 71 Canvas c = holder.lockCanvas();
75 btm.copyPixelsFromBuffer(native_buf); 72 btm.copyPixelsFromBuffer(framebuffer);
76 synchronized (holder) 73 synchronized (holder)
77 { /* draw */ 74 { /* draw */
78 c.drawBitmap(btm, 0.0f, 0.0f, null); 75 c.drawBitmap(btm, 0.0f, 0.0f, null);
@@ -80,14 +77,12 @@ public class RockboxFramebuffer extends SurfaceView
80 holder.unlockCanvasAndPost(c); 77 holder.unlockCanvasAndPost(c);
81 } 78 }
82 79
83 private void java_lcd_update_rect(int x, int y, int width, int height) 80 private void update(ByteBuffer framebuffer, Rect dirty)
84 { 81 {
85 SurfaceHolder holder = getHolder(); 82 SurfaceHolder holder = getHolder();
86 Rect dirty = new Rect(x, y, x+width, y+height);
87 Canvas c = holder.lockCanvas(dirty); 83 Canvas c = holder.lockCanvas(dirty);
88 /* can't copy a partial buffer, 84 /* can't copy a partial buffer, but it doesn't make a noticeable difference anyway */
89 * but it doesn't make a noticeable difference anyway */ 85 btm.copyPixelsFromBuffer(framebuffer);
90 btm.copyPixelsFromBuffer(native_buf);
91 synchronized (holder) 86 synchronized (holder)
92 { /* draw */ 87 { /* draw */
93 c.drawBitmap(btm, dirty, dirty, null); 88 c.drawBitmap(btm, dirty, dirty, null);
diff --git a/firmware/target/hosted/android/lcd-android.c b/firmware/target/hosted/android/lcd-android.c
index 15c844bbd6..bb0331db69 100644
--- a/firmware/target/hosted/android/lcd-android.c
+++ b/firmware/target/hosted/android/lcd-android.c
@@ -36,6 +36,9 @@ static jmethodID java_lcd_update;
36static jmethodID java_lcd_update_rect; 36static jmethodID java_lcd_update_rect;
37static jmethodID java_lcd_init; 37static jmethodID java_lcd_init;
38 38
39static jclass AndroidRect_class;
40static jmethodID AndroidRect_constructor;
41
39static int dpi; 42static int dpi;
40static int scroll_threshold; 43static int scroll_threshold;
41static bool display_on; 44static bool display_on;
@@ -43,7 +46,7 @@ static bool display_on;
43/* this might actually be called before lcd_init_device() or even main(), so 46/* this might actually be called before lcd_init_device() or even main(), so
44 * be sure to only access static storage initalized at library loading, 47 * be sure to only access static storage initalized at library loading,
45 * and not more */ 48 * and not more */
46void connect_with_java(JNIEnv* env, jobject fb_instance) 49static void connect_with_java(JNIEnv* env, jobject fb_instance)
47{ 50{
48 JNIEnv e = *env; 51 JNIEnv e = *env;
49 static bool have_class; 52 static bool have_class;
@@ -53,11 +56,12 @@ void connect_with_java(JNIEnv* env, jobject fb_instance)
53 jclass fb_class = e->GetObjectClass(env, fb_instance); 56 jclass fb_class = e->GetObjectClass(env, fb_instance);
54 /* cache update functions */ 57 /* cache update functions */
55 java_lcd_update = e->GetMethodID(env, fb_class, 58 java_lcd_update = e->GetMethodID(env, fb_class,
56 "java_lcd_update", 59 "update",
57 "()V"); 60 "(Ljava/nio/ByteBuffer;)V");
58 java_lcd_update_rect = e->GetMethodID(env, fb_class, 61 java_lcd_update_rect = e->GetMethodID(env, fb_class,
59 "java_lcd_update_rect", 62 "update",
60 "(IIII)V"); 63 "(Ljava/nio/ByteBuffer;"
64 "Landroid/graphics/Rect;)V");
61 jmethodID get_dpi = e->GetMethodID(env, fb_class, 65 jmethodID get_dpi = e->GetMethodID(env, fb_class,
62 "getDpi", "()I"); 66 "getDpi", "()I");
63 jmethodID thresh = e->GetMethodID(env, fb_class, 67 jmethodID thresh = e->GetMethodID(env, fb_class,
@@ -67,19 +71,16 @@ void connect_with_java(JNIEnv* env, jobject fb_instance)
67 scroll_threshold = e->CallIntMethod(env, fb_instance, thresh); 71 scroll_threshold = e->CallIntMethod(env, fb_instance, thresh);
68 72
69 java_lcd_init = e->GetMethodID(env, fb_class, 73 java_lcd_init = e->GetMethodID(env, fb_class,
70 "java_lcd_init", 74 "initialize", "(II)V");
71 "(IILjava/nio/ByteBuffer;)V"); 75 AndroidRect_class = e->FindClass(env, "android/graphics/Rect");
72 76 AndroidRect_constructor = e->GetMethodID(env, AndroidRect_class,
77 "<init>", "(IIII)V");
73 have_class = true; 78 have_class = true;
74 } 79 }
75 80
76 /* Create native_buffer */
77 jobject buffer = (*env)->NewDirectByteBuffer(env, lcd_framebuffer,
78 (jlong) FRAMEBUFFER_SIZE);
79
80 /* we need to setup parts for the java object every time */ 81 /* we need to setup parts for the java object every time */
81 (*env)->CallVoidMethod(env, fb_instance, java_lcd_init, 82 (*env)->CallVoidMethod(env, fb_instance, java_lcd_init,
82 (jint)LCD_WIDTH, (jint)LCD_HEIGHT, buffer); 83 (jint)LCD_WIDTH, (jint)LCD_HEIGHT);
83} 84}
84 85
85/* 86/*
@@ -92,15 +93,32 @@ void lcd_init_device(void)
92void lcd_update(void) 93void lcd_update(void)
93{ 94{
94 if (display_on) 95 if (display_on)
95 (*env_ptr)->CallVoidMethod(env_ptr, RockboxFramebuffer_instance, 96 {
96 java_lcd_update); 97 JNIEnv e = *env_ptr;
98 jobject buffer = e->NewDirectByteBuffer(env_ptr, lcd_framebuffer,
99 (jlong) FRAMEBUFFER_SIZE);
100
101 e->CallVoidMethod(env_ptr, RockboxFramebuffer_instance,
102 java_lcd_update, buffer);
103 e->DeleteLocalRef(env_ptr, buffer);
104 }
97} 105}
98 106
99void lcd_update_rect(int x, int y, int width, int height) 107void lcd_update_rect(int x, int y, int width, int height)
100{ 108{
101 if (display_on) 109 if (display_on)
102 (*env_ptr)->CallVoidMethod(env_ptr, RockboxFramebuffer_instance, 110 {
103 java_lcd_update_rect, x, y, width, height); 111 JNIEnv e = *env_ptr;
112 jobject buffer = e->NewDirectByteBuffer(env_ptr, lcd_framebuffer,
113 (jlong) FRAMEBUFFER_SIZE);
114 jobject rect = e->NewObject(env_ptr, AndroidRect_class, AndroidRect_constructor,
115 x, y, x + width, y + height);
116 e->CallVoidMethod(env_ptr, RockboxFramebuffer_instance,
117 java_lcd_update_rect, buffer, rect);
118
119 e->DeleteLocalRef(env_ptr, buffer);
120 e->DeleteLocalRef(env_ptr, rect);
121 }
104} 122}
105 123
106/* 124/*