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 /src | |
parent | 479bd643981271fb0edf756ae5915e44a7352c4d (diff) | |
download | android_packages_apps_Terminal-a76e33884c55bbd5db7e512b7687210cc3f635cf.tar.gz android_packages_apps_Terminal-a76e33884c55bbd5db7e512b7687210cc3f635cf.tar.bz2 android_packages_apps_Terminal-a76e33884c55bbd5db7e512b7687210cc3f635cf.zip |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/terminal/Terminal.java | 21 | ||||
-rw-r--r-- | src/com/android/terminal/TerminalView.java | 41 |
2 files changed, 50 insertions, 12 deletions
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"); } |