diff options
author | Jeff Sharkey <jsharkey@android.com> | 2013-02-21 19:09:55 -0800 |
---|---|---|
committer | Jeff Sharkey <jsharkey@android.com> | 2013-02-21 19:11:41 -0800 |
commit | a76e33884c55bbd5db7e512b7687210cc3f635cf (patch) | |
tree | 8dd2f597d2a5779e9edba26fe660617ff92130f2 | |
parent | 479bd643981271fb0edf756ae5915e44a7352c4d (diff) | |
download | Terminal-a76e33884c55bbd5db7e512b7687210cc3f635cf.tar.gz |
Start hooking up damage, shell script to test.
It's still pretty broken and I need to grok how damage and moveRect
play together. Avoid allocations inside onDraw().
Change-Id: I0fca467439178d902c4d11ff1523a0ec25c2dd39
-rw-r--r-- | jni/com_android_terminal_Terminal.cpp | 23 | ||||
-rw-r--r-- | src/com/android/terminal/Terminal.java | 21 | ||||
-rw-r--r-- | src/com/android/terminal/TerminalView.java | 41 |
3 files changed, 72 insertions, 13 deletions
diff --git a/jni/com_android_terminal_Terminal.cpp b/jni/com_android_terminal_Terminal.cpp index 7545a35..e195913 100644 --- a/jni/com_android_terminal_Terminal.cpp +++ b/jni/com_android_terminal_Terminal.cpp @@ -34,6 +34,8 @@ #include <string.h> +#define USE_TEST_SHELL true + namespace android { /* @@ -79,7 +81,9 @@ public: size_t write(const char *bytes, size_t len); + int flushDamage(); int resize(short unsigned int rows, short unsigned int cols); + int getCell(VTermPos pos, VTermScreenCell* cell); int getRows() const; @@ -245,7 +249,8 @@ Terminal::Terminal(jobject callbacks, int rows, int cols) : mVts = vterm_obtain_screen(mVt); vterm_screen_enable_altscreen(mVts, 1); vterm_screen_set_callbacks(mVts, &cb, this); - vterm_screen_set_damage_merge(mVts, VTERM_DAMAGE_SCROLL); + // TODO: switch back to VTERM_DAMAGE_SCROLL? + vterm_screen_set_damage_merge(mVts, VTERM_DAMAGE_CELL); vterm_screen_reset(mVts, 1); } @@ -304,7 +309,12 @@ int Terminal::run() { } char *shell = "/system/bin/sh"; //getenv("SHELL"); +#ifdef USE_TEST_SHELL + char *args[4] = {shell, "-c", "x=1; while true; do echo \"stop echoing yourself! ($x)\"; x=$(( $x + 1 )); sleep 0.5; done", NULL}; +#else char *args[2] = {shell, NULL}; +#endif + execvp(shell, args); fprintf(stderr_save, "Cannot exec(%s) - %s\n", shell, strerror(errno)); _exit(1); @@ -334,6 +344,11 @@ size_t Terminal::write(const char *bytes, size_t len) { return ::write(mMasterFd, bytes, len); } +int Terminal::flushDamage() { + vterm_screen_flush_damage(mVts); + return 0; +} + int Terminal::resize(short unsigned int rows, short unsigned int cols) { ALOGD("resize(%d, %d)", rows, cols); // TODO: wait for resize event to propegate back from shell? @@ -375,6 +390,11 @@ static jint com_android_terminal_Terminal_nativeRun(JNIEnv* env, jclass clazz, j return term->run(); } +static jint com_android_terminal_Terminal_nativeFlushDamage(JNIEnv* env, jclass clazz, jint ptr) { + Terminal* term = reinterpret_cast<Terminal*>(ptr); + return term->flushDamage(); +} + static jint com_android_terminal_Terminal_nativeResize(JNIEnv* env, jclass clazz, jint ptr, jint rows, jint cols) { Terminal* term = reinterpret_cast<Terminal*>(ptr); @@ -445,6 +465,7 @@ static jint com_android_terminal_Terminal_nativeGetCols(JNIEnv* env, jclass claz static JNINativeMethod gMethods[] = { { "nativeInit", "(Lcom/android/terminal/TerminalCallbacks;II)I", (void*)com_android_terminal_Terminal_nativeInit }, { "nativeRun", "(I)I", (void*)com_android_terminal_Terminal_nativeRun }, + { "nativeFlushDamage", "(I)I", (void*)com_android_terminal_Terminal_nativeFlushDamage }, { "nativeResize", "(III)I", (void*)com_android_terminal_Terminal_nativeResize }, { "nativeGetCellRun", "(IIILcom/android/terminal/Terminal$CellRun;)I", (void*)com_android_terminal_Terminal_nativeGetCellRun }, { "nativeGetRows", "(I)I", (void*)com_android_terminal_Terminal_nativeGetRows }, diff --git a/src/com/android/terminal/Terminal.java b/src/com/android/terminal/Terminal.java index c2e9749..9701fab 100644 --- a/src/com/android/terminal/Terminal.java +++ b/src/com/android/terminal/Terminal.java @@ -68,6 +68,20 @@ public class Terminal { } @Override + public int moveRect(int destStartRow, int destEndRow, int destStartCol, int destEndCol, + int srcStartRow, int srcEndRow, int srcStartCol, int srcEndCol) { + // TODO: arg, this isn't right + if (mClient != null) { + final int startRow = Math.min(destStartRow, srcStartRow); + final int endRow = Math.max(destEndRow, srcEndRow); + final int startCol = Math.min(destStartCol, srcStartCol); + final int endCol = Math.max(destEndCol, srcEndCol); + mClient.damage(startRow, endRow, startCol, endCol); + } + return 1; + } + + @Override public int bell() { if (mClient != null) { mClient.bell(); @@ -97,6 +111,12 @@ public class Terminal { mClient = client; } + public void flushDamage() { + if (nativeFlushDamage(mNativePtr) != 0) { + throw new IllegalStateException("flushDamage failed"); + } + } + public void resize(int rows, int cols) { if (nativeResize(mNativePtr, rows, cols) != 0) { throw new IllegalStateException("resize failed"); @@ -120,6 +140,7 @@ public class Terminal { private static native int nativeInit(TerminalCallbacks callbacks, int rows, int cols); private static native int nativeRun(int ptr); + private static native int nativeFlushDamage(int ptr); private static native int nativeResize(int ptr, int rows, int cols); private static native int nativeGetCellRun(int ptr, int row, int col, CellRun run); private static native int nativeGetRows(int ptr); diff --git a/src/com/android/terminal/TerminalView.java b/src/com/android/terminal/TerminalView.java index eb4f063..ea5e1b1 100644 --- a/src/com/android/terminal/TerminalView.java +++ b/src/com/android/terminal/TerminalView.java @@ -27,6 +27,7 @@ import android.os.SystemClock; import android.util.Log; import android.view.View; +import com.android.terminal.Terminal.CellRun; import com.android.terminal.Terminal.TerminalClient; /** @@ -35,16 +36,26 @@ import com.android.terminal.Terminal.TerminalClient; public class TerminalView extends View { private static final String TAG = "Terminal"; + private static final int MAX_RUN_LENGTH = 128; + private final Context mContext; private final Terminal mTerm; private final Paint mBgPaint = new Paint(); private final Paint mTextPaint = new Paint(); + /** Run of cells used when drawing */ + private final CellRun mRun; + /** Screen coordinates to draw chars into */ + private final float[] mPos; + private int mCharTop; private int mCharWidth; private int mCharHeight; + // TODO: for atomicity we might need to snapshot runs when processing + // callbacks driven by vterm thread + private TerminalClient mClient = new TerminalClient() { @Override public void damage(int startRow, int endRow, int startCol, int endCol) { @@ -68,6 +79,13 @@ public class TerminalView extends View { mContext = context; mTerm = term; + mRun = new Terminal.CellRun(); + mRun.data = new char[MAX_RUN_LENGTH]; + + // Positions of each possible cell + // TODO: make sure this works with surrogate pairs + mPos = new float[MAX_RUN_LENGTH * 2]; + setBackgroundColor(Color.BLACK); setTextSize(20); @@ -105,6 +123,12 @@ public class TerminalView extends View { mCharWidth = (int) Math.ceil(widths[0]); mCharHeight = (int) Math.ceil(fm.descent - fm.top); + // Update drawing positions + for (int i = 0; i < MAX_RUN_LENGTH; i++) { + mPos[i * 2] = i * mCharWidth; + mPos[(i * 2) + 1] = -mCharTop; + } + updateTerminalSize(); } @@ -117,6 +141,7 @@ public class TerminalView extends View { final int rows = getHeight() / mCharHeight; final int cols = getWidth() / mCharWidth; mTerm.resize(rows, cols); + mTerm.flushDamage(); } } @@ -127,8 +152,6 @@ public class TerminalView extends View { updateTerminalSize(); } } - - private static final int MAX_RUN_LENGTH = 128; @Override protected void onDraw(Canvas canvas) { @@ -147,16 +170,8 @@ public class TerminalView extends View { final int startCol = dirty.left / mCharWidth; final int endCol = Math.min(dirty.right / mCharWidth, cols - 1); - final Terminal.CellRun run = new Terminal.CellRun(); - run.data = new char[MAX_RUN_LENGTH]; - - // Positions of each possible cell - // TODO: make sure this works with surrogate pairs - final float[] pos = new float[MAX_RUN_LENGTH * 2]; - for (int i = 0; i < MAX_RUN_LENGTH; i++) { - pos[i * 2] = i * mCharWidth; - pos[(i * 2) + 1] = -mCharTop; - } + final CellRun run = mRun; + final float[] pos = mPos; for (int row = startRow; row <= endRow; row++) { for (int col = startCol; col <= endCol;) { @@ -182,6 +197,8 @@ public class TerminalView extends View { } } + mTerm.flushDamage(); + final long delta = SystemClock.elapsedRealtime() - start; Log.d(TAG, "onDraw() took " + delta + "ms"); } |