summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJeff Sharkey <jsharkey@android.com>2013-02-20 21:41:29 -0800
committerJeff Sharkey <jsharkey@android.com>2013-02-20 22:34:42 -0800
commit9cae0a9616b1b71eac7e762d198fe1da47fea901 (patch)
tree8638176e3aa644eb7a274387b91cd9fc985e0d16 /src
parentd439bacee510759728accb29ba93687a4e380eb6 (diff)
downloadandroid_packages_apps_Terminal-9cae0a9616b1b71eac7e762d198fe1da47fea901.tar.gz
android_packages_apps_Terminal-9cae0a9616b1b71eac7e762d198fe1da47fea901.tar.bz2
android_packages_apps_Terminal-9cae0a9616b1b71eac7e762d198fe1da47fea901.zip
Add CellRun to speed up cell rendering.
Change to using CellRun class, and ask JNI to fill it until text style changes. Switch to drawPosText(), which paints an entire run at once. Together these changes improve screen rendering times from 170ms to only 7ms! Change-Id: I62f12ffbb746c0c54191a15f395bbb80229cc959
Diffstat (limited to 'src')
-rw-r--r--src/com/android/terminal/Terminal.java17
-rw-r--r--src/com/android/terminal/TerminalView.java42
2 files changed, 43 insertions, 16 deletions
diff --git a/src/com/android/terminal/Terminal.java b/src/com/android/terminal/Terminal.java
index 7d4197c..dfd370b 100644
--- a/src/com/android/terminal/Terminal.java
+++ b/src/com/android/terminal/Terminal.java
@@ -26,9 +26,14 @@ public class Terminal {
System.loadLibrary("jni_terminal");
}
- public static class Cell {
- char[] chars = new char[2];
- int width = 1;
+ /**
+ * Represents a run of one or more {@code VTermScreenCell} which all have
+ * the same formatting.
+ */
+ public static class CellRun {
+ char[] data;
+ int dataSize;
+ int colSize;
boolean bold;
int underline;
@@ -97,8 +102,8 @@ public class Terminal {
return nativeGetCols(mNativePtr);
}
- public void getCell(int row, int col, Cell cell) {
- if (nativeGetCell(mNativePtr, row, col, cell) != 0) {
+ public void getCellRun(int row, int col, CellRun run) {
+ if (nativeGetCellRun(mNativePtr, row, col, run) != 0) {
throw new IllegalStateException("getCell failed");
}
}
@@ -106,7 +111,7 @@ public class Terminal {
private static native int nativeInit(TerminalCallbacks callbacks, int rows, int cols);
private static native int nativeReadLoop(int ptr);
private static native int nativeResize(int ptr, int rows, int cols);
- private static native int nativeGetCell(int ptr, int row, int col, Cell cell);
+ private static native int nativeGetCellRun(int ptr, int row, int col, CellRun run);
private static native int nativeGetRows(int ptr);
private static native int nativeGetCols(int ptr);
}
diff --git a/src/com/android/terminal/TerminalView.java b/src/com/android/terminal/TerminalView.java
index adbb0a7..33b651b 100644
--- a/src/com/android/terminal/TerminalView.java
+++ b/src/com/android/terminal/TerminalView.java
@@ -20,6 +20,7 @@ import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
+import android.graphics.Typeface;
import android.graphics.Paint.FontMetrics;
import android.graphics.Rect;
import android.view.View;
@@ -93,6 +94,7 @@ public class TerminalView extends View {
}
public void setTextSize(float textSize) {
+ mTextPaint.setTypeface(Typeface.MONOSPACE);
mTextPaint.setTextSize(textSize);
// Read metrics to get exact pixel dimensions
@@ -126,6 +128,8 @@ public class TerminalView extends View {
updateTerminalSize();
}
}
+
+ private static final int MAX_RUN_LENGTH = 128;
@Override
protected void onDraw(Canvas canvas) {
@@ -136,28 +140,46 @@ public class TerminalView extends View {
// Only draw dirty region of console
final Rect dirty = canvas.getClipBounds();
+ final int rows = mTerm.getRows();
+ final int cols = mTerm.getCols();
+
final int startRow = dirty.top / mCharHeight;
- final int endRow = dirty.bottom / mCharHeight;
+ final int endRow = Math.min(dirty.bottom / mCharHeight, rows - 1);
final int startCol = dirty.left / mCharWidth;
- final int endCol = dirty.right / 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];
- final Terminal.Cell cell = new Terminal.Cell();
+ // 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;
+ }
for (int row = startRow; row <= endRow; row++) {
for (int col = startCol; col <= endCol;) {
- mTerm.getCell(row, col, cell);
+ mTerm.getCellRun(row, col, run);
- mBgPaint.setColor(cell.bgColor);
- mTextPaint.setColor(cell.fgColor);
+ mBgPaint.setColor(run.bgColor);
+ mTextPaint.setColor(run.fgColor);
final int y = row * mCharHeight;
final int x = col * mCharWidth;
- final int xEnd = x + (cell.width * mCharWidth);
+ final int xEnd = x + (run.colSize * mCharWidth);
+
+ canvas.save(Canvas.MATRIX_SAVE_FLAG | Canvas.CLIP_SAVE_FLAG);
+ canvas.translate(x, y);
+ canvas.clipRect(0, 0, run.colSize * mCharWidth, mCharHeight);
+
+ canvas.drawPaint(mBgPaint);
+ canvas.drawPosText(run.data, 0, run.dataSize, pos, mTextPaint);
- canvas.drawRect(x, y, xEnd, y + mCharHeight, mBgPaint);
- canvas.drawText(cell.chars, 0, cell.chars.length, x, y - mCharTop, mTextPaint);
+ canvas.restore();
- col += cell.width;
+ col += run.colSize;
}
}