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: Id560ac84f33b5151437a42a4ff22736284d71e2dmain
parent
f40a666902
commit
877157e1f5
|
@ -111,8 +111,6 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
|
||||||
// Drawing
|
// Drawing
|
||||||
/** True if the entire keyboard needs to be dimmed. */
|
/** True if the entire keyboard needs to be dimmed. */
|
||||||
private boolean mNeedsToDimEntireKeyboard;
|
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 */
|
/** True if all keys should be drawn */
|
||||||
private boolean mInvalidateAllKeys;
|
private boolean mInvalidateAllKeys;
|
||||||
/** The keys that should be drawn */
|
/** The keys that should be drawn */
|
||||||
|
@ -459,8 +457,9 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
|
||||||
onDrawKeyboard(canvas);
|
onDrawKeyboard(canvas);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (mBufferNeedsUpdate || mOffscreenBuffer == null) {
|
|
||||||
mBufferNeedsUpdate = false;
|
final boolean bufferNeedsUpdates = mInvalidateAllKeys || !mInvalidatedKeys.isEmpty();
|
||||||
|
if (bufferNeedsUpdates || mOffscreenBuffer == null) {
|
||||||
if (maybeAllocateOffscreenBuffer()) {
|
if (maybeAllocateOffscreenBuffer()) {
|
||||||
mInvalidateAllKeys = true;
|
mInvalidateAllKeys = true;
|
||||||
// TODO: Stop using the offscreen canvas even when in software rendering
|
// 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) {
|
if (!isHardwareAccelerated) {
|
||||||
canvas.clipRegion(mClipRegion, Region.Op.REPLACE);
|
canvas.clipRegion(mClipRegion, Region.Op.REPLACE);
|
||||||
}
|
// Draw keyboard background.
|
||||||
|
canvas.drawColor(Color.BLACK, PorterDuff.Mode.CLEAR);
|
||||||
// Draw keyboard background.
|
final Drawable background = getBackground();
|
||||||
canvas.drawColor(Color.BLACK, PorterDuff.Mode.CLEAR);
|
if (background != null) {
|
||||||
final Drawable background = getBackground();
|
background.draw(canvas);
|
||||||
if (background != null) {
|
}
|
||||||
background.draw(canvas);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Confirm if it's really required to draw all keys when hardware acceleration is on.
|
// 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() {
|
public void invalidateAllKeys() {
|
||||||
mInvalidatedKeys.clear();
|
mInvalidatedKeys.clear();
|
||||||
mInvalidateAllKeys = true;
|
mInvalidateAllKeys = true;
|
||||||
mBufferNeedsUpdate = true;
|
|
||||||
invalidate();
|
invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1066,9 +1063,7 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
|
||||||
mInvalidatedKeys.add(key);
|
mInvalidatedKeys.add(key);
|
||||||
final int x = key.mX + getPaddingLeft();
|
final int x = key.mX + getPaddingLeft();
|
||||||
final int y = key.mY + getPaddingTop();
|
final int y = key.mY + getPaddingTop();
|
||||||
mWorkingRect.set(x, y, x + key.mWidth, y + key.mHeight);
|
invalidate(x, y, x + key.mWidth, y + key.mHeight);
|
||||||
mBufferNeedsUpdate = true;
|
|
||||||
invalidate(mWorkingRect);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void closing() {
|
public void closing() {
|
||||||
|
|
Loading…
Reference in New Issue