Refactor SF. Move all GL operations in their own class.

this is the first step to add support for GLES 2.x, this
change breaks the dependency of SF on GLES 1.x by moving
all operation into their own class.

Bug: 8679321

Change-Id: I0d2741eca2cefe67dfd9cf837cac10c4d126928b
diff --git a/services/surfaceflinger/LayerDim.cpp b/services/surfaceflinger/LayerDim.cpp
index f4adeeb..062ad46 100644
--- a/services/surfaceflinger/LayerDim.cpp
+++ b/services/surfaceflinger/LayerDim.cpp
@@ -18,9 +18,6 @@
 #include <stdint.h>
 #include <sys/types.h>
 
-#include <GLES/gl.h>
-#include <GLES/glext.h>
-
 #include <utils/Errors.h>
 #include <utils/Log.h>
 
@@ -29,6 +26,7 @@
 #include "LayerDim.h"
 #include "SurfaceFlinger.h"
 #include "DisplayDevice.h"
+#include "RenderEngine/RenderEngine.h"
 
 namespace android {
 // ---------------------------------------------------------------------------
@@ -45,28 +43,12 @@
 {
     const State& s(getDrawingState());
     if (s.alpha>0) {
-        const GLfloat alpha = s.alpha/255.0f;
-        const uint32_t fbHeight = hw->getHeight();
-        glDisable(GL_TEXTURE_EXTERNAL_OES);
-        glDisable(GL_TEXTURE_2D);
-
-        if (s.alpha == 0xFF) {
-            glDisable(GL_BLEND);
-        } else {
-            glEnable(GL_BLEND);
-            glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
-        }
-
-        glColor4f(0, 0, 0, alpha);
-
         LayerMesh mesh;
         computeGeometry(hw, &mesh);
-
-        glVertexPointer(2, GL_FLOAT, 0, mesh.getVertices());
-        glDrawArrays(GL_TRIANGLE_FAN, 0, mesh.getVertexCount());
-
-        glDisable(GL_BLEND);
-        glDisableClientState(GL_TEXTURE_COORD_ARRAY);
+        RenderEngine& engine(mFlinger->getRenderEngine());
+        engine.setupDimLayerBlending(s.alpha);
+        engine.drawMesh2D(mesh.getVertices(), NULL, mesh.getVertexCount());
+        engine.disableBlending();
     }
 }