Ensure we always set the proper blending mode
Bug #6527305

At the beginning of a frame, always set the blending mode that we
think GL is using just in case it was modified by another entity
(for instance a WebView functor.)

Change-Id: I0e1d0abee8a2abb2b8e7622aed28346e89562c06
diff --git a/libs/hwui/DisplayListRenderer.cpp b/libs/hwui/DisplayListRenderer.cpp
index a5f653a..546925e 100644
--- a/libs/hwui/DisplayListRenderer.cpp
+++ b/libs/hwui/DisplayListRenderer.cpp
@@ -296,7 +296,8 @@
         indent[i] = ' ';
     }
     indent[count] = '\0';
-    ALOGD("%sStart display list (%p, %s)", (char*) indent + 2, this, mName.string());
+    ALOGD("%sStart display list (%p, %s, render=%d)", (char*) indent + 2, this,
+            mName.string(), isRenderable());
 
     ALOGD("%s%s %d", indent, "Save", SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag);
     int saveCount = renderer.getSaveCount() - 1;
diff --git a/libs/hwui/OpenGLRenderer.cpp b/libs/hwui/OpenGLRenderer.cpp
index 50f5d57..fa3780d 100644
--- a/libs/hwui/OpenGLRenderer.cpp
+++ b/libs/hwui/OpenGLRenderer.cpp
@@ -177,14 +177,26 @@
     mSnapshot->fbo = getTargetFbo();
     mSaveCount = 1;
 
-    glViewport(0, 0, mWidth, mHeight);
-    mCaches.setScissor(left, mSnapshot->height - bottom, right - left, bottom - top);
-
     mSnapshot->setClip(left, top, right, bottom);
-    mDirtyClip = false;
+    mDirtyClip = opaque;
+
+    syncState();
 
     if (!opaque) {
+        mCaches.setScissor(left, mSnapshot->height - bottom, right - left, bottom - top);
         glClear(GL_COLOR_BUFFER_BIT);
+    } else {
+        mCaches.resetScissor();
+    }
+}
+
+void OpenGLRenderer::syncState() {
+    glViewport(0, 0, mWidth, mHeight);
+
+    if (mCaches.blend) {
+        glEnable(GL_BLEND);
+    } else {
+        glDisable(GL_BLEND);
     }
 }
 
@@ -291,11 +303,6 @@
         }
     }
 
-    // Restore state possibly changed by the functors in process mode
-    GLboolean value;
-    glGetBooleanv(GL_BLEND, &value);
-    mCaches.blend = value;
-
     mCaches.activeTexture(0);
 
     return result;
diff --git a/libs/hwui/OpenGLRenderer.h b/libs/hwui/OpenGLRenderer.h
index bf136ad..ad83b31 100644
--- a/libs/hwui/OpenGLRenderer.h
+++ b/libs/hwui/OpenGLRenderer.h
@@ -215,6 +215,12 @@
 
 private:
     /**
+     * Ensures the state of the renderer is the same as the state of
+     * the GL context.
+     */
+    void syncState();
+
+    /**
      * Saves the current state of the renderer as a new snapshot.
      * The new snapshot is saved in mSnapshot and the previous snapshot
      * is linked from mSnapshot->previous.