From 52876bbefd774e8647910f73a2e4c17ac4e6bf5c Mon Sep 17 00:00:00 2001
From: Ken Wakasa <kwakasa@google.com>
Date: Fri, 2 Aug 2013 00:25:05 +0900
Subject: [PATCH] Remove unnecessary setLayerType() calls

Calling up setLayerType(LAYER_TYPE_HARDWARE, ..) on non-HW accelerated
devices was ending up with having a drawing cache in View that is not
quite needed for PreviewPlacerView.

bug: 8967766

Change-Id: Ic8e6eeaf536530ff5f23eb353b0a8e5ba96fa0e2
---
 .../com/android/inputmethod/keyboard/KeyboardSwitcher.java  | 5 +----
 java/src/com/android/inputmethod/keyboard/KeyboardView.java | 6 ++++++
 .../com/android/inputmethod/keyboard/MainKeyboardView.java  | 6 ++++++
 .../inputmethod/keyboard/internal/PreviewPlacerView.java    | 3 +++
 4 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
index 166be817f8..8880af48cf 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
@@ -314,10 +314,7 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
                 R.layout.input_view, null);
 
         mKeyboardView = (MainKeyboardView) mCurrentInputView.findViewById(R.id.keyboard_view);
-        if (isHardwareAcceleratedDrawingEnabled) {
-            mKeyboardView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
-            // TODO: Should use LAYER_TYPE_SOFTWARE when hardware acceleration is off?
-        }
+        mKeyboardView.setHardwareAcceleratedDrawingEnabled(isHardwareAcceleratedDrawingEnabled);
         mKeyboardView.setKeyboardActionListener(mLatinIME);
 
         // This always needs to be set since the accessibility state can
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java
index 2a02682e5b..96286559db 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java
@@ -154,6 +154,12 @@ public class KeyboardView extends View {
                 Color.red(color), Color.green(color), Color.blue(color));
     }
 
+    public void setHardwareAcceleratedDrawingEnabled(final boolean enabled) {
+        if (!enabled) return;
+        // TODO: Should use LAYER_TYPE_SOFTWARE when hardware acceleration is off?
+        setLayerType(View.LAYER_TYPE_HARDWARE, null);
+    }
+
     /**
      * Attaches a keyboard to this view. The keyboard can be switched at any time and the
      * view will re-layout itself to accommodate the keyboard.
diff --git a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java
index e00e4b5c2e..6782317d03 100644
--- a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java
+++ b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java
@@ -512,6 +512,12 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
         mKeyboardActionListener = KeyboardActionListener.EMPTY_LISTENER;
     }
 
+    @Override
+    public void setHardwareAcceleratedDrawingEnabled(final boolean enabled) {
+        super.setHardwareAcceleratedDrawingEnabled(enabled);
+        mPreviewPlacerView.setHardwareAcceleratedDrawingEnabled(enabled);
+    }
+
     private ObjectAnimator loadObjectAnimator(final int resId, final Object target) {
         if (resId == 0) {
             // TODO: Stop returning null.
diff --git a/java/src/com/android/inputmethod/keyboard/internal/PreviewPlacerView.java b/java/src/com/android/inputmethod/keyboard/internal/PreviewPlacerView.java
index 3388c57011..4c8607da8e 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/PreviewPlacerView.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/PreviewPlacerView.java
@@ -37,7 +37,10 @@ public final class PreviewPlacerView extends RelativeLayout {
     public PreviewPlacerView(final Context context, final AttributeSet attrs) {
         super(context, attrs);
         setWillNotDraw(false);
+    }
 
+    public void setHardwareAcceleratedDrawingEnabled(final boolean enabled) {
+        if (!enabled) return;
         final Paint layerPaint = new Paint();
         layerPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER));
         setLayerType(LAYER_TYPE_HARDWARE, layerPaint);
-- 
GitLab