diff options
author | 2012-08-09 15:25:01 +0900 | |
---|---|---|
committer | 2012-08-09 16:44:11 +0900 | |
commit | 877157e1f5ed44d6490eaf8fab430f9a73caf34d (patch) | |
tree | a6fdef975a2bfaba8e3eaaa92dd9beea570b655d /java/src | |
parent | f40a666902719fac076231b655444b8168cfb755 (diff) | |
download | latinime-877157e1f5ed44d6490eaf8fab430f9a73caf34d.tar.gz latinime-877157e1f5ed44d6490eaf8fab430f9a73caf34d.tar.xz latinime-877157e1f5ed44d6490eaf8fab430f9a73caf34d.zip |
Optimize keyboard drawing code a bit
* Remove useless boolean flag.
* Use invalidate(int,int,int,int).
* Don't draw background when hardware acceleration is enabled.
Change-Id: Id560ac84f33b5151437a42a4ff22736284d71e2d
Diffstat (limited to 'java/src')
-rw-r--r-- | java/src/com/android/inputmethod/keyboard/KeyboardView.java | 25 |
1 files changed, 10 insertions, 15 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java index b8eb9ec96..fcf97b99c 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java @@ -111,8 +111,6 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy { // Drawing /** True if the entire keyboard needs to be dimmed. */ private boolean mNeedsToDimEntireKeyboard; - /** Whether the keyboard bitmap buffer needs to be redrawn before it's blitted. **/ - private boolean mBufferNeedsUpdate; /** True if all keys should be drawn */ private boolean mInvalidateAllKeys; /** The keys that should be drawn */ @@ -459,8 +457,9 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy { onDrawKeyboard(canvas); return; } - if (mBufferNeedsUpdate || mOffscreenBuffer == null) { - mBufferNeedsUpdate = false; + + final boolean bufferNeedsUpdates = mInvalidateAllKeys || !mInvalidatedKeys.isEmpty(); + if (bufferNeedsUpdates || mOffscreenBuffer == null) { if (maybeAllocateOffscreenBuffer()) { mInvalidateAllKeys = true; // TODO: Stop using the offscreen canvas even when in software rendering @@ -524,13 +523,12 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy { } if (!isHardwareAccelerated) { canvas.clipRegion(mClipRegion, Region.Op.REPLACE); - } - - // Draw keyboard background. - canvas.drawColor(Color.BLACK, PorterDuff.Mode.CLEAR); - final Drawable background = getBackground(); - if (background != null) { - background.draw(canvas); + // Draw keyboard background. + canvas.drawColor(Color.BLACK, PorterDuff.Mode.CLEAR); + final Drawable background = getBackground(); + if (background != null) { + background.draw(canvas); + } } // TODO: Confirm if it's really required to draw all keys when hardware acceleration is on. @@ -1048,7 +1046,6 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy { public void invalidateAllKeys() { mInvalidatedKeys.clear(); mInvalidateAllKeys = true; - mBufferNeedsUpdate = true; invalidate(); } @@ -1066,9 +1063,7 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy { mInvalidatedKeys.add(key); final int x = key.mX + getPaddingLeft(); final int y = key.mY + getPaddingTop(); - mWorkingRect.set(x, y, x + key.mWidth, y + key.mHeight); - mBufferNeedsUpdate = true; - invalidate(mWorkingRect); + invalidate(x, y, x + key.mWidth, y + key.mHeight); } public void closing() { |