Make sure set GL state properly

when taking a screenshot, in particular, we could end up
with stale GL state when drawing LayerDim which resulted
in incortect rendering.

Bug: 5467587
Change-Id: Id9fbed2843481d31063620f3662b364c7e3ac781
diff --git a/services/surfaceflinger/LayerDim.cpp b/services/surfaceflinger/LayerDim.cpp
index 654817d..e665d7a 100644
--- a/services/surfaceflinger/LayerDim.cpp
+++ b/services/surfaceflinger/LayerDim.cpp
@@ -49,7 +49,8 @@
         const DisplayHardware& hw(graphicPlane(0).displayHardware());
         const GLfloat alpha = s.alpha/255.0f;
         const uint32_t fbHeight = hw.getHeight();
-        glDisable(GL_DITHER);
+        glDisable(GL_TEXTURE_EXTERNAL_OES);
+        glDisable(GL_TEXTURE_2D);
 
         if (s.alpha == 0xFF) {
             glDisable(GL_BLEND);
@@ -60,11 +61,6 @@
 
         glColor4f(0, 0, 0, alpha);
 
-#if defined(GL_OES_EGL_image_external)
-        if (GLExtensions::getInstance().haveTextureExternal()) {
-            glDisable(GL_TEXTURE_EXTERNAL_OES);
-        }
-#endif
         glVertexPointer(2, GL_FLOAT, 0, mVertices);
 
         while (it != end) {
@@ -73,8 +69,9 @@
             glScissor(r.left, sy, r.width(), r.height());
             glDrawArrays(GL_TRIANGLE_FAN, 0, 4); 
         }
+        glDisable(GL_BLEND);
+        glDisableClientState(GL_TEXTURE_COORD_ARRAY);
     }
-    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
 }
 
 // ---------------------------------------------------------------------------