1
0
Fork 0
forked from len0rd/rockbox

Initialize (instantiate) RockboxFramebuffer from the C code like with the othe java objects.

Remove some @Override annotations to make the Java code build with certain javac versions.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@28386 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Thomas Martitz 2010-10-29 23:12:08 +00:00
parent 669a327a2e
commit 6bb7522852
5 changed files with 59 additions and 59 deletions

View file

@ -52,7 +52,7 @@ public class RockboxActivity extends Activity
/* Now it gets a bit tricky: /* Now it gets a bit tricky:
* The service is started in the same thread as we are now, * The service is started in the same thread as we are now,
* but the service also initializes the framebuffer * but the service also initializes the framebuffer
* Unforunately, this happens *after* any of the default * Unfortunately, this happens *after* any of the default
* startup methods of an activity, so we need to poll for it * startup methods of an activity, so we need to poll for it
* *
* In order to get the fb, we need to let the Service start up * In order to get the fb, we need to let the Service start up
@ -71,7 +71,7 @@ public class RockboxActivity extends Activity
} }
/* drawing needs to happen in ui thread */ /* drawing needs to happen in ui thread */
runOnUiThread(new Runnable() runOnUiThread(new Runnable()
{ @Override {
public void run() { public void run() {
loadingdialog.dismiss(); loadingdialog.dismiss();
setContentView(RockboxService.fb); setContentView(RockboxService.fb);

View file

@ -36,37 +36,34 @@ public class RockboxFramebuffer extends View
private Bitmap btm; private Bitmap btm;
private ByteBuffer native_buf; private ByteBuffer native_buf;
public RockboxFramebuffer(Context c) public RockboxFramebuffer(Context c, int lcd_width,
int lcd_height, ByteBuffer native_fb)
{ {
super(c); super(c);
btm = null;
/* Needed so we can catch KeyEvents */ /* Needed so we can catch KeyEvents */
setFocusable(true); setFocusable(true);
setFocusableInTouchMode(true); setFocusableInTouchMode(true);
setClickable(true); setClickable(true);
btm = Bitmap.createBitmap(lcd_width, lcd_height, Bitmap.Config.RGB_565);
native_buf = native_fb;
requestFocus(); requestFocus();
} }
public void onDraw(Canvas c) public void onDraw(Canvas c)
{ {
if (btm != null) c.drawBitmap(btm, 0.0f, 0.0f, null);
c.drawBitmap(btm, 0.0f, 0.0f, null);
} }
public void java_lcd_init(int lcd_width, int lcd_height, ByteBuffer native_fb) @SuppressWarnings("unused")
{ private void java_lcd_update()
btm = Bitmap.createBitmap(lcd_width, lcd_height, Bitmap.Config.RGB_565);
native_buf = native_fb;
}
public void java_lcd_update()
{ {
btm.copyPixelsFromBuffer(native_buf); btm.copyPixelsFromBuffer(native_buf);
postInvalidate(); postInvalidate();
} }
public void java_lcd_update_rect(int x, int y, int w, int h) @SuppressWarnings("unused")
private void java_lcd_update_rect(int x, int y, int w, int h)
{ {
/* can't copy a partial buffer */ /* can't copy a partial buffer */
btm.copyPixelsFromBuffer(native_buf); btm.copyPixelsFromBuffer(native_buf);

View file

@ -148,7 +148,7 @@ public class RockboxPCM extends AudioTrack
buf = new byte[max_len*3/4]; buf = new byte[max_len*3/4];
refill_mark = max_len - buf.length; refill_mark = max_len - buf.length;
} }
@Override
public void onMarkerReached(AudioTrack track) public void onMarkerReached(AudioTrack track)
{ {
/* push new data to the hardware */ /* push new data to the hardware */
@ -186,7 +186,6 @@ public class RockboxPCM extends AudioTrack
} }
} }
@Override
public void onPeriodicNotification(AudioTrack track) public void onPeriodicNotification(AudioTrack track)
{ {
} }

View file

@ -64,6 +64,7 @@ public class RockboxService extends Service
private Object[] mStopForegroundArgs = new Object[1]; private Object[] mStopForegroundArgs = new Object[1];
private IntentFilter itf; private IntentFilter itf;
private BroadcastReceiver batt_monitor; private BroadcastReceiver batt_monitor;
@SuppressWarnings("unused")
private int battery_level; private int battery_level;
@Override @Override
@ -118,7 +119,6 @@ public class RockboxService extends Service
private void startservice() private void startservice()
{ {
final int BUFFER = 8*1024; final int BUFFER = 8*1024;
final Context me = this;
Thread rb = new Thread(new Runnable() Thread rb = new Thread(new Runnable()
{ {
public void run() public void run()
@ -135,7 +135,7 @@ public class RockboxService extends Service
ZipEntry entry; ZipEntry entry;
File file = new File("/data/data/org.rockbox/" + File file = new File("/data/data/org.rockbox/" +
"lib/libmisc.so"); "lib/libmisc.so");
/* use arbitary file to determine whether extracting is needed */ /* use arbitrary file to determine whether extracting is needed */
File file2 = new File("/data/data/org.rockbox/" + File file2 = new File("/data/data/org.rockbox/" +
"app_rockbox/rockbox/codecs/mpa.codec"); "app_rockbox/rockbox/codecs/mpa.codec");
if (!file2.exists() || (file.lastModified() > file2.lastModified())) if (!file2.exists() || (file.lastModified() > file2.lastModified()))
@ -184,8 +184,6 @@ public class RockboxService extends Service
} }
System.loadLibrary("rockbox"); System.loadLibrary("rockbox");
fb = new RockboxFramebuffer(me);
main(); main();
} }
},"Rockbox thread"); },"Rockbox thread");

View file

@ -29,7 +29,8 @@ extern JNIEnv *env_ptr;
extern jclass RockboxService_class; extern jclass RockboxService_class;
extern jobject RockboxService_instance; extern jobject RockboxService_instance;
static jobject Framebuffer_instance; static jclass RockboxFramebuffer_class;
static jobject RockboxFramebuffer_instance;
static jmethodID java_lcd_update; static jmethodID java_lcd_update;
static jmethodID java_lcd_update_rect; static jmethodID java_lcd_update_rect;
@ -37,46 +38,51 @@ static bool display_on;
void lcd_init_device(void) void lcd_init_device(void)
{ {
/* get the RockboxFramebuffer instance allocated by the activity */ JNIEnv e = *env_ptr;
jfieldID id = (*env_ptr)->GetStaticFieldID(env_ptr, RockboxFramebuffer_class = e->FindClass(env_ptr,
RockboxService_class, "org/rockbox/RockboxFramebuffer");
"fb", /* instantiate a RockboxFramebuffer instance
"Lorg/rockbox/RockboxFramebuffer;"); *
* Pass lcd width and height and our framebuffer so the java layer
Framebuffer_instance = (*env_ptr)->GetStaticObjectField(env_ptr, * can create a Bitmap which directly maps to it
RockboxService_class, **/
id);
jclass Framebuffer_class = (*env_ptr)->GetObjectClass(env_ptr,
Framebuffer_instance);
/* get the java init function and call it. it'll set up a bitmap
* based on LCD_WIDTH, LCD_HEIGHT and the ByteBuffer which directly maps
* our framebuffer */
jmethodID java_init_lcd = (*env_ptr)->GetMethodID(env_ptr,
Framebuffer_class,
"java_lcd_init",
"(IILjava/nio/ByteBuffer;)V");
java_lcd_update = (*env_ptr)->GetMethodID(env_ptr,
Framebuffer_class,
"java_lcd_update",
"()V");
java_lcd_update_rect = (*env_ptr)->GetMethodID(env_ptr,
Framebuffer_class,
"java_lcd_update_rect",
"(IIII)V");
/* map the framebuffer to a ByteBuffer, this way lcd updates will /* map the framebuffer to a ByteBuffer, this way lcd updates will
* be directly feched from the framebuffer */ * be directly feched from the framebuffer */
jobject buf = (*env_ptr)->NewDirectByteBuffer(env_ptr, jobject buf = e->NewDirectByteBuffer(env_ptr,
lcd_framebuffer, lcd_framebuffer,
sizeof(lcd_framebuffer)); (jlong)sizeof(lcd_framebuffer));
(*env_ptr)->CallVoidMethod(env_ptr, jmethodID constructor = e->GetMethodID(env_ptr,
Framebuffer_instance, RockboxFramebuffer_class,
java_init_lcd, "<init>",
LCD_WIDTH, LCD_HEIGHT, buf); "(Landroid/content/Context;" /* Service */
"II" /* lcd width/height */
"Ljava/nio/ByteBuffer;)V"); /* ByteBuffer */
RockboxFramebuffer_instance = e->NewObject(env_ptr,
RockboxFramebuffer_class,
constructor,
RockboxService_instance,
(jint)LCD_WIDTH,
(jint)LCD_HEIGHT,
buf);
/* cache update functions */
java_lcd_update = (*env_ptr)->GetMethodID(env_ptr,
RockboxFramebuffer_class,
"java_lcd_update",
"()V");
java_lcd_update_rect = (*env_ptr)->GetMethodID(env_ptr,
RockboxFramebuffer_class,
"java_lcd_update_rect",
"(IIII)V");
/* at last, give RockboxService the Framebuffer instance */
jfieldID id = e->GetStaticFieldID(env_ptr, RockboxService_class,
"fb", "Lorg/rockbox/RockboxFramebuffer;");
e->SetStaticObjectField(env_ptr, RockboxService_class,
id, RockboxFramebuffer_instance);
display_on = true; display_on = true;
} }
@ -84,14 +90,14 @@ void lcd_update(void)
{ {
/* tell the system we're ready for drawing */ /* tell the system we're ready for drawing */
if (display_on) if (display_on)
(*env_ptr)->CallVoidMethod(env_ptr, Framebuffer_instance, java_lcd_update); (*env_ptr)->CallVoidMethod(env_ptr, RockboxFramebuffer_instance, java_lcd_update);
} }
void lcd_update_rect(int x, int y, int height, int width) void lcd_update_rect(int x, int y, int height, int width)
{ {
if (display_on) if (display_on)
{ {
(*env_ptr)->CallVoidMethod(env_ptr, Framebuffer_instance, java_lcd_update_rect, (*env_ptr)->CallVoidMethod(env_ptr, RockboxFramebuffer_instance, java_lcd_update_rect,
x, y, height, width); x, y, height, width);
} }
} }