summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Martitz <kugel@rockbox.org>2010-08-04 01:03:25 +0000
committerThomas Martitz <kugel@rockbox.org>2010-08-04 01:03:25 +0000
commit594110e962831b0d8ae2ded7efc49d48e4a6c3eb (patch)
treeb167636938ed249fb61ccd62e9873ef5481ee8af
parentf66a233bdbbf5c772903a744938d7333da1b53bf (diff)
downloadrockbox-594110e962831b0d8ae2ded7efc49d48e4a6c3eb.tar.gz
rockbox-594110e962831b0d8ae2ded7efc49d48e4a6c3eb.zip
Implement HAVE_LCD_ENABLE and lcd_update_rect(). When Rockbox runs in the background
this greatly reduces CPU load. lcd_update_rect shoves a bit as well. CPU usage with Rockbox in background is between 3% (with a 200kbps vbr mp3) and 12% (320kbps cbr mp3), so it's low but still dependent on codecs and even particular files. Driving a WPS with peakmeter, e.g. the builtin one, adds about 30% cpu usage. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27689 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--android/src/org/rockbox/RockboxActivity.java23
-rw-r--r--android/src/org/rockbox/RockboxFramebuffer.java35
-rw-r--r--firmware/export/config/application.h4
-rw-r--r--firmware/target/hosted/android/lcd-android.c60
4 files changed, 98 insertions, 24 deletions
diff --git a/android/src/org/rockbox/RockboxActivity.java b/android/src/org/rockbox/RockboxActivity.java
index 38bfec16ef..2bafb6688d 100644
--- a/android/src/org/rockbox/RockboxActivity.java
+++ b/android/src/org/rockbox/RockboxActivity.java
@@ -78,6 +78,7 @@ public class RockboxActivity extends Activity {
78 public void onResume() 78 public void onResume()
79 { 79 {
80 super.onResume(); 80 super.onResume();
81
81 if (RockboxService.fb != null) 82 if (RockboxService.fb != null)
82 { 83 {
83 try { 84 try {
@@ -91,8 +92,30 @@ public class RockboxActivity extends Activity {
91 } catch (Exception e) { 92 } catch (Exception e) {
92 LOG(e.toString()); 93 LOG(e.toString());
93 } 94 }
95 RockboxService.fb.resume();
94 } 96 }
95 } 97 }
98
99 /* this is also called when the backlight goes off,
100 * which is nice
101 */
102 @Override
103 protected void onPause() {
104 super.onPause();
105 RockboxService.fb.suspend();
106 }
107
108 @Override
109 protected void onStop() {
110 super.onStop();
111 RockboxService.fb.suspend();
112 }
113
114 @Override
115 protected void onDestroy() {
116 super.onDestroy();
117 RockboxService.fb.suspend();
118 }
96 119
97 private void LOG(CharSequence text) 120 private void LOG(CharSequence text)
98 { 121 {
diff --git a/android/src/org/rockbox/RockboxFramebuffer.java b/android/src/org/rockbox/RockboxFramebuffer.java
index f947806bb4..ca11de090c 100644
--- a/android/src/org/rockbox/RockboxFramebuffer.java
+++ b/android/src/org/rockbox/RockboxFramebuffer.java
@@ -34,21 +34,11 @@ public class RockboxFramebuffer extends View
34{ 34{
35 private Bitmap btm; 35 private Bitmap btm;
36 private ByteBuffer native_buf; 36 private ByteBuffer native_buf;
37 private Handler update_handler;
38 private Runnable cb;
39 37
40 38
41 public RockboxFramebuffer(Context c) 39 public RockboxFramebuffer(Context c)
42 { 40 {
43 super(c); 41 super(c);
44 update_handler = new Handler();
45 cb = new Runnable() {
46 public void run()
47 {
48 btm.copyPixelsFromBuffer(native_buf);
49 invalidate();
50 }
51 };
52 btm = null; 42 btm = null;
53 } 43 }
54 44
@@ -66,12 +56,21 @@ public class RockboxFramebuffer extends View
66 56
67 public void java_lcd_update() 57 public void java_lcd_update()
68 { 58 {
69 update_handler.post(cb); 59
60 btm.copyPixelsFromBuffer(native_buf);
61 postInvalidate();
62 }
63
64 public void java_lcd_update_rect(int x, int y, int w, int h)
65 {
66 /* can't copy a partial buffer */
67 btm.copyPixelsFromBuffer(native_buf);
68 postInvalidate(x, y, x+w, y+h);
70 } 69 }
71 70
72 private void LOG(CharSequence text) 71 private void LOG(CharSequence text)
73 { 72 {
74 Log.d("RockboxBootloader", (String) text); 73 Log.d("RockboxBootloader", (String) text);
75 } 74 }
76 75
77 public boolean onTouchEvent(MotionEvent me) 76 public boolean onTouchEvent(MotionEvent me)
@@ -93,6 +92,18 @@ public class RockboxFramebuffer extends View
93 return true; 92 return true;
94 } 93 }
95 94
95 /* the two below should only be called from the activity thread */
96 public void suspend()
97 { /* suspend, Rockbox will not make any lcd updates */
98 set_lcd_active(0);
99 }
100 public void resume()
101 { /* make updates again, the underlying function will
102 * send an event */
103 set_lcd_active(1);
104 }
105
106 public native void set_lcd_active(int active);
96 public native void pixelHandler(int x, int y); 107 public native void pixelHandler(int x, int y);
97 public native void touchHandler(int down); 108 public native void touchHandler(int down);
98} 109}
diff --git a/firmware/export/config/application.h b/firmware/export/config/application.h
index 988f0d51ac..71ee62356b 100644
--- a/firmware/export/config/application.h
+++ b/firmware/export/config/application.h
@@ -53,6 +53,10 @@
53#define LCD_DEPTH 16 53#define LCD_DEPTH 16
54#define LCD_PIXELFORMAT 565 54#define LCD_PIXELFORMAT 565
55 55
56#if (CONFIG_PLATFORM & PLATFORM_ANDROID)
57#define HAVE_LCD_ENABLE
58#endif
59
56/* define this to indicate your device's keypad */ 60/* define this to indicate your device's keypad */
57#define HAVE_TOUCHSCREEN 61#define HAVE_TOUCHSCREEN
58#define HAVE_BUTTON_DATA 62#define HAVE_BUTTON_DATA
diff --git a/firmware/target/hosted/android/lcd-android.c b/firmware/target/hosted/android/lcd-android.c
index efe68cdd71..1043dfa35c 100644
--- a/firmware/target/hosted/android/lcd-android.c
+++ b/firmware/target/hosted/android/lcd-android.c
@@ -31,6 +31,9 @@ extern jobject RockboxService_instance;
31 31
32static jobject Framebuffer_instance; 32static jobject Framebuffer_instance;
33static jmethodID java_lcd_update; 33static jmethodID java_lcd_update;
34static jmethodID java_lcd_update_rect;
35
36static bool display_on;
34 37
35void lcd_init_device(void) 38void lcd_init_device(void)
36{ 39{
@@ -52,13 +55,17 @@ void lcd_init_device(void)
52 * our framebuffer */ 55 * our framebuffer */
53 56
54 jmethodID java_init_lcd = (*env_ptr)->GetMethodID(env_ptr, 57 jmethodID java_init_lcd = (*env_ptr)->GetMethodID(env_ptr,
55 Framebuffer_class, 58 Framebuffer_class,
56 "java_lcd_init", 59 "java_lcd_init",
57 "(IILjava/nio/ByteBuffer;)V"); 60 "(IILjava/nio/ByteBuffer;)V");
58 java_lcd_update = (*env_ptr)->GetMethodID(env_ptr, 61 java_lcd_update = (*env_ptr)->GetMethodID(env_ptr,
59 Framebuffer_class, 62 Framebuffer_class,
60 "java_lcd_update", 63 "java_lcd_update",
61 "()V"); 64 "()V");
65 java_lcd_update_rect = (*env_ptr)->GetMethodID(env_ptr,
66 Framebuffer_class,
67 "java_lcd_update_rect",
68 "(IIII)V");
62 69
63 /* map the framebuffer to a ByteBuffer, this way lcd updates will 70 /* map the framebuffer to a ByteBuffer, this way lcd updates will
64 * be directly feched from the framebuffer */ 71 * be directly feched from the framebuffer */
@@ -70,21 +77,50 @@ void lcd_init_device(void)
70 Framebuffer_instance, 77 Framebuffer_instance,
71 java_init_lcd, 78 java_init_lcd,
72 LCD_WIDTH, LCD_HEIGHT, buf); 79 LCD_WIDTH, LCD_HEIGHT, buf);
80 display_on = true;
73} 81}
74 82
75void lcd_update() 83void lcd_update(void)
76{ 84{
77 /* tell the system we're ready for drawing */ 85 /* tell the system we're ready for drawing */
78 (*env_ptr)->CallVoidMethod(env_ptr, Framebuffer_instance, java_lcd_update); 86 if (display_on)
87 (*env_ptr)->CallVoidMethod(env_ptr, Framebuffer_instance, java_lcd_update);
79} 88}
80 89
81void lcd_update_rect(int x, int y, int height, int width) 90void lcd_update_rect(int x, int y, int height, int width)
82{ 91{
83 /* can't do partial updates yet */ 92 if (display_on)
84 (void)x; (void)y; (void)height; (void)width; 93 {
85 lcd_update(); 94 (*env_ptr)->CallVoidMethod(env_ptr, Framebuffer_instance, java_lcd_update_rect,
95 x, y, height, width);
96 }
97}
98
99bool lcd_active(void)
100{
101 return display_on;
86} 102}
87 103
104/*
105 * (un)block lcd updates.
106 *
107 * Notice: This is called from the activity thread, so take it
108 * as interrupt context and take care what the event callback does
109 * (it shouldn't block in particular
110 *
111 * the 1s are needed due to strange naming conventions...
112 **/
113JNIEXPORT void JNICALL
114Java_org_rockbox_RockboxFramebuffer_set_1lcd_1active(JNIEnv *e,
115 jobject this,
116 jint active)
117{
118 (void)e;
119 (void)this;
120 display_on = active != 0;
121 if (active)
122 send_event(LCD_EVENT_ACTIVATION, NULL);
123}
88/* below is a plain copy from lcd-sdl.c */ 124/* below is a plain copy from lcd-sdl.c */
89 125
90/** 126/**