Update layers' opaque property when needed
Before this change, changing a View's opacity would not be reflected
by hardware layers. This could cause layers to retain their previous
opacity.
Change-Id: Iba2c8b4242deca021651df9324cc7c585a64653d
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index c269ea3..22b307c 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -11928,9 +11928,24 @@
mHardwareLayer = mAttachInfo.mHardwareRenderer.createHardwareLayer(
width, height, isOpaque());
mLocalDirtyRect.set(0, 0, width, height);
- } else if (mHardwareLayer.getWidth() != width || mHardwareLayer.getHeight() != height) {
- mHardwareLayer.resize(width, height);
- mLocalDirtyRect.set(0, 0, width, height);
+ } else {
+ if (mHardwareLayer.getWidth() != width || mHardwareLayer.getHeight() != height) {
+ mHardwareLayer.resize(width, height);
+ mLocalDirtyRect.set(0, 0, width, height);
+ }
+
+ // This should not be necessary but applications that change
+ // the parameters of their background drawable without calling
+ // this.setBackground(Drawable) can leave the view in a bad state
+ // (for instance isOpaque() returns true, but the background is
+ // not opaque.)
+ computeOpaqueFlags();
+
+ final boolean opaque = isOpaque();
+ if (mHardwareLayer.isOpaque() != opaque) {
+ mHardwareLayer.setOpaque(opaque);
+ mLocalDirtyRect.set(0, 0, width, height);
+ }
}
// The layer is not valid if the underlying GPU resources cannot be allocated
@@ -13989,6 +14004,8 @@
*/
@Deprecated
public void setBackgroundDrawable(Drawable background) {
+ computeOpaqueFlags();
+
if (background == mBackground) {
return;
}