1
0
Fork 0
forked from len0rd/rockbox

android: lcd_update/_rect() changes

* rename some java methods (to update(), initialize())
* re-create the ByteBuffer object from the framebuffer on every update.
  This is needed now since 2c71aa9 added the possiblity for lcd_framebuffer to change.
* do so, along with the creation of the dirty Rect object, in native code.

Change-Id: Id39ea8e4b6148987c5f216a87e0ff3c8e7babe92
This commit is contained in:
Thomas Martitz 2012-03-22 23:00:53 +01:00
parent 6e6f0c6ef3
commit 901521d6de
2 changed files with 42 additions and 29 deletions

View file

@ -39,7 +39,6 @@ public class RockboxFramebuffer extends SurfaceView
{ {
private final DisplayMetrics metrics; private final DisplayMetrics metrics;
private final ViewConfiguration view_config; private final ViewConfiguration view_config;
private ByteBuffer native_buf;
private Bitmap btm; private Bitmap btm;
/* first stage init; needs to run from a thread that has a Looper /* first stage init; needs to run from a thread that has a Looper
@ -47,7 +46,6 @@ public class RockboxFramebuffer extends SurfaceView
public RockboxFramebuffer(Context c) public RockboxFramebuffer(Context c)
{ {
super(c); super(c);
metrics = c.getResources().getDisplayMetrics(); metrics = c.getResources().getDisplayMetrics();
view_config = ViewConfiguration.get(c); view_config = ViewConfiguration.get(c);
getHolder().addCallback(this); getHolder().addCallback(this);
@ -61,18 +59,17 @@ public class RockboxFramebuffer extends SurfaceView
/* second stage init; called from Rockbox with information about the /* second stage init; called from Rockbox with information about the
* display framebuffer */ * display framebuffer */
private void java_lcd_init(int lcd_width, int lcd_height, ByteBuffer native_fb) private void initialize(int lcd_width, int lcd_height)
{ {
btm = Bitmap.createBitmap(lcd_width, lcd_height, Bitmap.Config.RGB_565); btm = Bitmap.createBitmap(lcd_width, lcd_height, Bitmap.Config.RGB_565);
native_buf = native_fb;
setEnabled(true); setEnabled(true);
} }
private void java_lcd_update() private void update(ByteBuffer framebuffer)
{ {
SurfaceHolder holder = getHolder(); SurfaceHolder holder = getHolder();
Canvas c = holder.lockCanvas(null); Canvas c = holder.lockCanvas();
btm.copyPixelsFromBuffer(native_buf); btm.copyPixelsFromBuffer(framebuffer);
synchronized (holder) synchronized (holder)
{ /* draw */ { /* draw */
c.drawBitmap(btm, 0.0f, 0.0f, null); c.drawBitmap(btm, 0.0f, 0.0f, null);
@ -80,14 +77,12 @@ public class RockboxFramebuffer extends SurfaceView
holder.unlockCanvasAndPost(c); holder.unlockCanvasAndPost(c);
} }
private void java_lcd_update_rect(int x, int y, int width, int height) private void update(ByteBuffer framebuffer, Rect dirty)
{ {
SurfaceHolder holder = getHolder(); SurfaceHolder holder = getHolder();
Rect dirty = new Rect(x, y, x+width, y+height);
Canvas c = holder.lockCanvas(dirty); Canvas c = holder.lockCanvas(dirty);
/* can't copy a partial buffer, /* can't copy a partial buffer, but it doesn't make a noticeable difference anyway */
* but it doesn't make a noticeable difference anyway */ btm.copyPixelsFromBuffer(framebuffer);
btm.copyPixelsFromBuffer(native_buf);
synchronized (holder) synchronized (holder)
{ /* draw */ { /* draw */
c.drawBitmap(btm, dirty, dirty, null); c.drawBitmap(btm, dirty, dirty, null);

View file

@ -36,6 +36,9 @@ static jmethodID java_lcd_update;
static jmethodID java_lcd_update_rect; static jmethodID java_lcd_update_rect;
static jmethodID java_lcd_init; static jmethodID java_lcd_init;
static jclass AndroidRect_class;
static jmethodID AndroidRect_constructor;
static int dpi; static int dpi;
static int scroll_threshold; static int scroll_threshold;
static bool display_on; static bool display_on;
@ -43,7 +46,7 @@ static bool display_on;
/* this might actually be called before lcd_init_device() or even main(), so /* this might actually be called before lcd_init_device() or even main(), so
* be sure to only access static storage initalized at library loading, * be sure to only access static storage initalized at library loading,
* and not more */ * and not more */
void connect_with_java(JNIEnv* env, jobject fb_instance) static void connect_with_java(JNIEnv* env, jobject fb_instance)
{ {
JNIEnv e = *env; JNIEnv e = *env;
static bool have_class; static bool have_class;
@ -53,11 +56,12 @@ void connect_with_java(JNIEnv* env, jobject fb_instance)
jclass fb_class = e->GetObjectClass(env, fb_instance); jclass fb_class = e->GetObjectClass(env, fb_instance);
/* cache update functions */ /* cache update functions */
java_lcd_update = e->GetMethodID(env, fb_class, java_lcd_update = e->GetMethodID(env, fb_class,
"java_lcd_update", "update",
"()V"); "(Ljava/nio/ByteBuffer;)V");
java_lcd_update_rect = e->GetMethodID(env, fb_class, java_lcd_update_rect = e->GetMethodID(env, fb_class,
"java_lcd_update_rect", "update",
"(IIII)V"); "(Ljava/nio/ByteBuffer;"
"Landroid/graphics/Rect;)V");
jmethodID get_dpi = e->GetMethodID(env, fb_class, jmethodID get_dpi = e->GetMethodID(env, fb_class,
"getDpi", "()I"); "getDpi", "()I");
jmethodID thresh = e->GetMethodID(env, fb_class, jmethodID thresh = e->GetMethodID(env, fb_class,
@ -67,19 +71,16 @@ void connect_with_java(JNIEnv* env, jobject fb_instance)
scroll_threshold = e->CallIntMethod(env, fb_instance, thresh); scroll_threshold = e->CallIntMethod(env, fb_instance, thresh);
java_lcd_init = e->GetMethodID(env, fb_class, java_lcd_init = e->GetMethodID(env, fb_class,
"java_lcd_init", "initialize", "(II)V");
"(IILjava/nio/ByteBuffer;)V"); AndroidRect_class = e->FindClass(env, "android/graphics/Rect");
AndroidRect_constructor = e->GetMethodID(env, AndroidRect_class,
"<init>", "(IIII)V");
have_class = true; have_class = true;
} }
/* Create native_buffer */
jobject buffer = (*env)->NewDirectByteBuffer(env, lcd_framebuffer,
(jlong) FRAMEBUFFER_SIZE);
/* we need to setup parts for the java object every time */ /* we need to setup parts for the java object every time */
(*env)->CallVoidMethod(env, fb_instance, java_lcd_init, (*env)->CallVoidMethod(env, fb_instance, java_lcd_init,
(jint)LCD_WIDTH, (jint)LCD_HEIGHT, buffer); (jint)LCD_WIDTH, (jint)LCD_HEIGHT);
} }
/* /*
@ -92,15 +93,32 @@ void lcd_init_device(void)
void lcd_update(void) void lcd_update(void)
{ {
if (display_on) if (display_on)
(*env_ptr)->CallVoidMethod(env_ptr, RockboxFramebuffer_instance, {
java_lcd_update); JNIEnv e = *env_ptr;
jobject buffer = e->NewDirectByteBuffer(env_ptr, lcd_framebuffer,
(jlong) FRAMEBUFFER_SIZE);
e->CallVoidMethod(env_ptr, RockboxFramebuffer_instance,
java_lcd_update, buffer);
e->DeleteLocalRef(env_ptr, buffer);
}
} }
void lcd_update_rect(int x, int y, int width, int height) void lcd_update_rect(int x, int y, int width, int height)
{ {
if (display_on) if (display_on)
(*env_ptr)->CallVoidMethod(env_ptr, RockboxFramebuffer_instance, {
java_lcd_update_rect, x, y, width, height); JNIEnv e = *env_ptr;
jobject buffer = e->NewDirectByteBuffer(env_ptr, lcd_framebuffer,
(jlong) FRAMEBUFFER_SIZE);
jobject rect = e->NewObject(env_ptr, AndroidRect_class, AndroidRect_constructor,
x, y, x + width, y + height);
e->CallVoidMethod(env_ptr, RockboxFramebuffer_instance,
java_lcd_update_rect, buffer, rect);
e->DeleteLocalRef(env_ptr, buffer);
e->DeleteLocalRef(env_ptr, rect);
}
} }
/* /*