forked from joejulian/gio
app: [Android] re-introduce Choreographer for frame pacing
According to #375, change b86928ceec
increased frame pacing jitter. This change effectively reverts it
by re-introducing Choreographer for pacing.
References: https://todo.sr.ht/~eliasnaur/gio/375
Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+8
-2
@@ -25,6 +25,7 @@ import android.text.Selection;
|
||||
import android.text.SpannableStringBuilder;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.TypedValue;
|
||||
import android.view.Choreographer;
|
||||
import android.view.KeyCharacterMap;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.MotionEvent;
|
||||
@@ -55,7 +56,7 @@ import android.view.accessibility.AccessibilityManager;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
public final class GioView extends SurfaceView {
|
||||
public final class GioView extends SurfaceView implements Choreographer.FrameCallback {
|
||||
private static boolean jniLoaded;
|
||||
|
||||
private final SurfaceHolder.Callback surfCallbacks;
|
||||
@@ -380,7 +381,12 @@ public final class GioView extends SurfaceView {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override protected void onDraw(Canvas canvas) {
|
||||
void postFrameCallback() {
|
||||
Choreographer.getInstance().removeFrameCallback(this);
|
||||
Choreographer.getInstance().postFrameCallback(this);
|
||||
}
|
||||
|
||||
@Override public void doFrame(long nanos) {
|
||||
if (nhandle != 0) {
|
||||
onFrameCallback(nhandle);
|
||||
}
|
||||
|
||||
+4
-6
@@ -179,7 +179,7 @@ var gioView struct {
|
||||
showTextInput C.jmethodID
|
||||
hideTextInput C.jmethodID
|
||||
setInputHint C.jmethodID
|
||||
postInvalidate C.jmethodID // requests draw, called from non-UI thread
|
||||
postFrameCallback C.jmethodID
|
||||
invalidate C.jmethodID // requests draw, called from UI thread
|
||||
setCursor C.jmethodID
|
||||
setOrientation C.jmethodID
|
||||
@@ -462,7 +462,7 @@ func Java_org_gioui_GioView_onCreateView(env *C.JNIEnv, class C.jclass, view C.j
|
||||
m.showTextInput = getMethodID(env, class, "showTextInput", "()V")
|
||||
m.hideTextInput = getMethodID(env, class, "hideTextInput", "()V")
|
||||
m.setInputHint = getMethodID(env, class, "setInputHint", "(I)V")
|
||||
m.postInvalidate = getMethodID(env, class, "postInvalidate", "()V")
|
||||
m.postFrameCallback = getMethodID(env, class, "postFrameCallback", "()V")
|
||||
m.invalidate = getMethodID(env, class, "invalidate", "()V")
|
||||
m.setCursor = getMethodID(env, class, "setCursor", "(I)V")
|
||||
m.setOrientation = getMethodID(env, class, "setOrientation", "(II)V")
|
||||
@@ -564,9 +564,7 @@ func Java_org_gioui_GioView_onFrameCallback(env *C.JNIEnv, class C.jclass, view
|
||||
}
|
||||
if w.animating {
|
||||
w.draw(env, false)
|
||||
// Schedule the next draw immediately after this one. Since onFrameCallback runs
|
||||
// on the UI thread, View.invalidate can be used here instead of postInvalidate.
|
||||
callVoidMethod(env, w.view, gioView.invalidate)
|
||||
callVoidMethod(env, w.view, gioView.postFrameCallback)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -818,7 +816,7 @@ func (w *window) SetAnimating(anim bool) {
|
||||
w.animating = anim
|
||||
if anim {
|
||||
runInJVM(javaVM(), func(env *C.JNIEnv) {
|
||||
callVoidMethod(env, w.view, gioView.postInvalidate)
|
||||
callVoidMethod(env, w.view, gioView.postFrameCallback)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user