Don't set the invisible flag when saving an empty layer.
Bug #3270371

Change-Id: I65e85671c2fb70d74553c91213e5e759e0ac64ee
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index ad96686..da12d46 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -6421,6 +6421,12 @@
             mPrivateFlags &= ~DRAWING_CACHE_VALID;
             final ViewParent p = mParent;
             final AttachInfo ai = mAttachInfo;
+            if (p != null && ai != null && ai.mHardwareAccelerated) {
+                // fast-track for GL-enabled applications; just invalidate the whole hierarchy
+                // with a null dirty rect, which tells the ViewRoot to redraw everything
+                p.invalidateChild(this, null);
+                return;
+            }
             if (p != null && ai != null) {
                 final int scrollX = mScrollX;
                 final int scrollY = mScrollY;
diff --git a/libs/hwui/OpenGLRenderer.cpp b/libs/hwui/OpenGLRenderer.cpp
index b357973..8bfc8d4 100644
--- a/libs/hwui/OpenGLRenderer.cpp
+++ b/libs/hwui/OpenGLRenderer.cpp
@@ -268,7 +268,7 @@
     const GLuint previousFbo = mSnapshot->fbo;
     const int count = saveSnapshot(flags);
 
-    if (!mSnapshot->invisible) {
+    if (!mSnapshot->isIgnored()) {
         int alpha = 255;
         SkXfermode::Mode mode;
 
@@ -385,13 +385,17 @@
 
     if (bounds.isEmpty() || bounds.getWidth() > mCaches.maxTextureSize ||
             bounds.getHeight() > mCaches.maxTextureSize) {
-        snapshot->invisible = true;
+        if (fboLayer) {
+            snapshot->invisible = true;
+        } else {
+            snapshot->empty = true;
+        }
     } else {
         snapshot->invisible = snapshot->invisible || (alpha <= ALPHA_THRESHOLD && fboLayer);
     }
 
     // Bail out if we won't draw in this snapshot
-    if (snapshot->invisible) {
+    if (snapshot->invisible || snapshot->empty) {
         return false;
     }
 
@@ -731,7 +735,7 @@
 }
 
 void OpenGLRenderer::clearLayerRegions() {
-    if (mLayers.size() == 0 || mSnapshot->invisible) return;
+    if (mLayers.size() == 0 || mSnapshot->isIgnored()) return;
 
     Rect clipRect(*mSnapshot->clipRect);
     clipRect.snapToPixelBoundaries();
@@ -809,7 +813,7 @@
 }
 
 bool OpenGLRenderer::quickReject(float left, float top, float right, float bottom) {
-    if (mSnapshot->invisible) {
+    if (mSnapshot->isIgnored()) {
         return true;
     }
 
@@ -988,7 +992,7 @@
 
 void OpenGLRenderer::drawLines(float* points, int count, SkPaint* paint) {
     // TODO: Should do quickReject for each line
-    if (mSnapshot->invisible) return;
+    if (mSnapshot->isIgnored()) return;
 
     const bool isAA = paint->isAntiAlias();
     const float strokeWidth = paint->getStrokeWidth() * 0.5f;
@@ -1112,7 +1116,7 @@
 
 void OpenGLRenderer::drawColor(int color, SkXfermode::Mode mode) {
     // No need to check against the clip, we fill the clip region
-    if (mSnapshot->invisible) return;
+    if (mSnapshot->isIgnored()) return;
 
     Rect& clip(*mSnapshot->clipRect);
     clip.snapToPixelBoundaries();
@@ -1150,7 +1154,7 @@
     if (text == NULL || count == 0 || (paint->getAlpha() == 0 && paint->getXfermode() == NULL)) {
         return;
     }
-    if (mSnapshot->invisible) return;
+    if (mSnapshot->isIgnored()) return;
 
     paint->setAntiAlias(true);
 
@@ -1253,7 +1257,7 @@
 }
 
 void OpenGLRenderer::drawPath(SkPath* path, SkPaint* paint) {
-    if (mSnapshot->invisible) return;
+    if (mSnapshot->isIgnored()) return;
 
     GLuint textureUnit = 0;
     glActiveTexture(gTextureUnits[textureUnit]);
diff --git a/libs/hwui/Snapshot.h b/libs/hwui/Snapshot.h
index 9f78063..9898df4 100644
--- a/libs/hwui/Snapshot.h
+++ b/libs/hwui/Snapshot.h
@@ -43,7 +43,7 @@
  */
 class Snapshot: public LightRefBase<Snapshot> {
 public:
-    Snapshot(): flags(0), previous(NULL), layer(NULL), fbo(0), invisible(false) {
+    Snapshot(): flags(0), previous(NULL), layer(NULL), fbo(0), invisible(false), empty(false) {
         transform = &mTransformRoot;
         clipRect = &mClipRectRoot;
         region = NULL;
@@ -55,7 +55,7 @@
      */
     Snapshot(const sp<Snapshot>& s, int saveFlags):
             flags(0), previous(s), layer(NULL), fbo(s->fbo),
-            invisible(s->invisible), viewport(s->viewport), height(s->height) {
+            invisible(s->invisible), empty(false), viewport(s->viewport), height(s->height) {
         if (saveFlags & SkCanvas::kMatrix_SaveFlag) {
             mTransformRoot.load(*s->transform);
             transform = &mTransformRoot;
@@ -203,6 +203,10 @@
         flags |= Snapshot::kFlagClipSet | Snapshot::kFlagDirtyLocalClip;
     }
 
+    bool isIgnored() const {
+        return invisible || empty;
+    }
+
     /**
      * Dirty flags.
      */
@@ -225,11 +229,18 @@
 
     /**
      * Indicates that this snapshot is invisible and nothing should be drawn
-     * inside it.
+     * inside it. This flag is set only when the layer clips drawing to its
+     * bounds and is passed to subsequent snapshots.
      */
     bool invisible;
 
     /**
+     * If set to true, the layer will not be composited. This is similar to
+     * invisible but this flag is not passed to subsequent snapshots.
+     */
+    bool empty;
+
+    /**
      * Current viewport.
      */
     Rect viewport;