Merge "Force async behavior for the virtual display output BufferQueue" into klp-dev
diff --git a/opengl/libs/Android.mk b/opengl/libs/Android.mk
index b4756dd..528b983 100644
--- a/opengl/libs/Android.mk
+++ b/opengl/libs/Android.mk
@@ -48,16 +48,9 @@
 ifeq ($(BOARD_ALLOW_EGL_HIBERNATION),true)
   LOCAL_CFLAGS += -DBOARD_ALLOW_EGL_HIBERNATION
 endif
-
-ifeq ($(TARGET_BOARD_PLATFORM),msm7k)
-  LOCAL_CFLAGS += -DADRENO130=1
+ifeq ($(TARGET_BOARD_PLATFORM), omap4)
+  LOCAL_CFLAGS += -DWORKAROUND_BUG_10194508=1
 endif
-
-ifeq ($(TARGET_BOARD_PLATFORM), s5pc110)
-  # see Loader.cpp for details
-  LOCAL_CFLAGS += -DSYSTEMUI_PBSIZE_HACK=1
-endif
-
 ifneq ($(MAX_EGL_CACHE_ENTRY_SIZE),)
   LOCAL_CFLAGS += -DMAX_EGL_CACHE_ENTRY_SIZE=$(MAX_EGL_CACHE_ENTRY_SIZE)
 endif
diff --git a/opengl/libs/EGL/Loader.cpp b/opengl/libs/EGL/Loader.cpp
index beaa560..02914a0 100644
--- a/opengl/libs/EGL/Loader.cpp
+++ b/opengl/libs/EGL/Loader.cpp
@@ -374,35 +374,6 @@
         ALOGE_IF(!getProcAddress,
                 "can't find eglGetProcAddress() in %s", driver_absolute_path);
 
-#ifdef SYSTEMUI_PBSIZE_HACK
-#warning "SYSTEMUI_PBSIZE_HACK enabled"
-        /*
-         * TODO: replace SYSTEMUI_PBSIZE_HACK by something less hackish
-         *
-         * Here we adjust the PB size from its default value to 512KB which
-         * is the minimum acceptable for the systemui process.
-         * We do this on low-end devices only because it allows us to enable
-         * h/w acceleration in the systemui process while keeping the
-         * memory usage down.
-         *
-         * Obviously, this is the wrong place and wrong way to make this
-         * adjustment, but at the time of this writing this was the safest
-         * solution.
-         */
-        const char *cmdline = getProcessCmdline();
-        if (strstr(cmdline, "systemui")) {
-            void *imgegl = dlopen("/vendor/lib/libIMGegl.so", RTLD_LAZY);
-            if (imgegl) {
-                unsigned int *PVRDefaultPBS =
-                        (unsigned int *)dlsym(imgegl, "PVRDefaultPBS");
-                if (PVRDefaultPBS) {
-                    ALOGD("setting default PBS to 512KB, was %d KB", *PVRDefaultPBS / 1024);
-                    *PVRDefaultPBS = 512*1024;
-                }
-            }
-        }
-#endif
-
         egl_t* egl = &cnx->egl;
         __eglMustCastToProperFunctionPointerType* curr =
             (__eglMustCastToProperFunctionPointerType*)egl;
diff --git a/opengl/libs/EGL/eglApi.cpp b/opengl/libs/EGL/eglApi.cpp
index 7410c12..9d792fb 100644
--- a/opengl/libs/EGL/eglApi.cpp
+++ b/opengl/libs/EGL/eglApi.cpp
@@ -413,7 +413,25 @@
         // of our native format. So if sRGB gamma is requested, we have to
         // modify the EGLconfig's format before setting the native window's
         // format.
-
+#if WORKAROUND_BUG_10194508
+#warning "WORKAROUND_10194508 enabled"
+        EGLint format;
+        if (!cnx->egl.eglGetConfigAttrib(iDpy, config, EGL_NATIVE_VISUAL_ID,
+                &format)) {
+            ALOGE("eglGetConfigAttrib(EGL_NATIVE_VISUAL_ID) failed: %#x",
+                    eglGetError());
+            format = 0;
+        }
+        if (attrib_list) {
+            for (const EGLint* attr = attrib_list; *attr != EGL_NONE;
+                    attr += 2) {
+                if (*attr == EGL_GL_COLORSPACE_KHR &&
+                        dp->haveExtension("EGL_KHR_gl_colorspace")) {
+                    format = modifyFormatColorspace(format, *(attr+1));
+                }
+            }
+        }
+#else
         // by default, just pick RGBA_8888
         EGLint format = HAL_PIXEL_FORMAT_RGBA_8888;
 
@@ -444,6 +462,7 @@
                 }
             }
         }
+#endif
         if (format != 0) {
             int err = native_window_set_buffers_format(window, format);
             if (err != 0) {
diff --git a/opengl/libs/EGL/egl_display.cpp b/opengl/libs/EGL/egl_display.cpp
index 0380521..26240f1 100644
--- a/opengl/libs/EGL/egl_display.cpp
+++ b/opengl/libs/EGL/egl_display.cpp
@@ -150,21 +150,6 @@
     cnx->major = -1;
     cnx->minor = -1;
     if (cnx->dso) {
-
-#if defined(ADRENO130)
-#warning "Adreno-130 eglInitialize() workaround"
-        /*
-         * The ADRENO 130 driver returns a different EGLDisplay each time
-         * eglGetDisplay() is called, but also makes the EGLDisplay invalid
-         * after eglTerminate() has been called, so that eglInitialize()
-         * cannot be called again. Therefore, we need to make sure to call
-         * eglGetDisplay() before calling eglInitialize();
-         */
-        if (i == IMPL_HARDWARE) {
-            disp[i].dpy = cnx->egl.eglGetDisplay(EGL_DEFAULT_DISPLAY);
-        }
-#endif
-
         EGLDisplay idpy = disp.dpy;
         if (cnx->egl.eglInitialize(idpy, &cnx->major, &cnx->minor)) {
             //ALOGD("initialized dpy=%p, ver=%d.%d, cnx=%p",
diff --git a/services/surfaceflinger/DisplayDevice.cpp b/services/surfaceflinger/DisplayDevice.cpp
index 9708ee3..61a9361 100644
--- a/services/surfaceflinger/DisplayDevice.cpp
+++ b/services/surfaceflinger/DisplayDevice.cpp
@@ -271,9 +271,9 @@
         if (result == EGL_TRUE) {
             if (mType >= DisplayDevice::DISPLAY_VIRTUAL)
                 eglSwapInterval(dpy, 0);
-            setViewportAndProjection();
         }
     }
+    setViewportAndProjection();
     return result;
 }
 
diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp
index f867e86..56bddd6 100644
--- a/services/surfaceflinger/Layer.cpp
+++ b/services/surfaceflinger/Layer.cpp
@@ -506,8 +506,10 @@
 void Layer::clearWithOpenGL(const sp<const DisplayDevice>& hw, const Region& clip,
         float red, float green, float blue, float alpha) const
 {
+    RenderEngine& engine(mFlinger->getRenderEngine());
     computeGeometry(hw, mMesh);
-    mFlinger->getRenderEngine().fillWithColor(mMesh, red, green, blue, alpha);
+    engine.setupFillWithColor(red, green, blue, alpha);
+    engine.drawMesh(mMesh);
 }
 
 void Layer::clearWithOpenGL(
diff --git a/services/surfaceflinger/RenderEngine/GLES11RenderEngine.cpp b/services/surfaceflinger/RenderEngine/GLES11RenderEngine.cpp
index 06125b0..610061a 100644
--- a/services/surfaceflinger/RenderEngine/GLES11RenderEngine.cpp
+++ b/services/surfaceflinger/RenderEngine/GLES11RenderEngine.cpp
@@ -209,18 +209,11 @@
     glDeleteTextures(1, &texName);
 }
 
-void GLES11RenderEngine::fillWithColor(const Mesh& mesh, float r, float g, float b, float a) {
+void GLES11RenderEngine::setupFillWithColor(float r, float g, float b, float a) {
     glColor4f(r, g, b, a);
     glDisable(GL_TEXTURE_EXTERNAL_OES);
     glDisable(GL_TEXTURE_2D);
     glDisable(GL_BLEND);
-
-    glVertexPointer(mesh.getVertexSize(),
-            GL_FLOAT,
-            mesh.getByteStride(),
-            mesh.getPositions());
-
-    glDrawArrays(mesh.getPrimitive(), 0, mesh.getVertexCount());
 }
 
 void GLES11RenderEngine::drawMesh(const Mesh& mesh) {
diff --git a/services/surfaceflinger/RenderEngine/GLES11RenderEngine.h b/services/surfaceflinger/RenderEngine/GLES11RenderEngine.h
index 90fc82f..1de0443 100644
--- a/services/surfaceflinger/RenderEngine/GLES11RenderEngine.h
+++ b/services/surfaceflinger/RenderEngine/GLES11RenderEngine.h
@@ -54,10 +54,10 @@
     virtual void setupDimLayerBlending(int alpha);
     virtual void setupLayerTexturing(const Texture& texture);
     virtual void setupLayerBlackedOut();
+    virtual void setupFillWithColor(float r, float g, float b, float a) ;
     virtual void disableTexturing();
     virtual void disableBlending();
 
-    virtual void fillWithColor(const Mesh& mesh, float r, float g, float b, float a) ;
     virtual void drawMesh(const Mesh& mesh);
 
     virtual size_t getMaxTextureSize() const;
diff --git a/services/surfaceflinger/RenderEngine/GLES20RenderEngine.cpp b/services/surfaceflinger/RenderEngine/GLES20RenderEngine.cpp
index cde1e3a..56c6e56 100644
--- a/services/surfaceflinger/RenderEngine/GLES20RenderEngine.cpp
+++ b/services/surfaceflinger/RenderEngine/GLES20RenderEngine.cpp
@@ -186,20 +186,13 @@
     glDeleteTextures(1, &texName);
 }
 
-void GLES20RenderEngine::fillWithColor(const Mesh& mesh, float r, float g, float b, float a) {
+void GLES20RenderEngine::setupFillWithColor(float r, float g, float b, float a) {
+    mState.setPlaneAlpha(1.0f);
+    mState.setPremultipliedAlpha(true);
+    mState.setOpaque(false);
     mState.setColor(r, g, b, a);
-    disableTexturing();
+    mState.disableTexture();
     glDisable(GL_BLEND);
-
-    ProgramCache::getInstance().useProgram(mState);
-
-    glVertexAttribPointer(Program::position,
-            mesh.getVertexSize(),
-            GL_FLOAT, GL_FALSE,
-            mesh.getByteStride(),
-            mesh.getPositions());
-
-    glDrawArrays(mesh.getPrimitive(), 0, mesh.getVertexCount());
 }
 
 void GLES20RenderEngine::drawMesh(const Mesh& mesh) {
diff --git a/services/surfaceflinger/RenderEngine/GLES20RenderEngine.h b/services/surfaceflinger/RenderEngine/GLES20RenderEngine.h
index 3ff6d9f..eb8f31a 100644
--- a/services/surfaceflinger/RenderEngine/GLES20RenderEngine.h
+++ b/services/surfaceflinger/RenderEngine/GLES20RenderEngine.h
@@ -58,10 +58,10 @@
     virtual void setupDimLayerBlending(int alpha);
     virtual void setupLayerTexturing(const Texture& texture);
     virtual void setupLayerBlackedOut();
+    virtual void setupFillWithColor(float r, float g, float b, float a);
     virtual void disableTexturing();
     virtual void disableBlending();
 
-    virtual void fillWithColor(const Mesh& mesh, float r, float g, float b, float a);
     virtual void drawMesh(const Mesh& mesh);
 
     virtual size_t getMaxTextureSize() const;
diff --git a/services/surfaceflinger/RenderEngine/RenderEngine.cpp b/services/surfaceflinger/RenderEngine/RenderEngine.cpp
index 063be2e..2abda82 100644
--- a/services/surfaceflinger/RenderEngine/RenderEngine.cpp
+++ b/services/surfaceflinger/RenderEngine/RenderEngine.cpp
@@ -164,7 +164,8 @@
         position[i*6 + 5].x = r->right;
         position[i*6 + 5].y = height - r->top;
     }
-    fillWithColor(mesh, red, green, blue, alpha);
+    setupFillWithColor(red, green, blue, alpha);
+    drawMesh(mesh);
 }
 
 void RenderEngine::clearWithColor(float red, float green, float blue, float alpha) {
diff --git a/services/surfaceflinger/RenderEngine/RenderEngine.h b/services/surfaceflinger/RenderEngine/RenderEngine.h
index 82765c7..bc88b69 100644
--- a/services/surfaceflinger/RenderEngine/RenderEngine.h
+++ b/services/surfaceflinger/RenderEngine/RenderEngine.h
@@ -87,12 +87,12 @@
     virtual void setupDimLayerBlending(int alpha) = 0;
     virtual void setupLayerTexturing(const Texture& texture) = 0;
     virtual void setupLayerBlackedOut() = 0;
+    virtual void setupFillWithColor(float r, float g, float b, float a) = 0;
 
     virtual void disableTexturing() = 0;
     virtual void disableBlending() = 0;
 
     // drawing
-    virtual void fillWithColor(const Mesh& mesh, float r, float g, float b, float a) = 0;
     virtual void drawMesh(const Mesh& mesh) = 0;
 
     // queries
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index 9fd3f25..0323cb7 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -2726,6 +2726,7 @@
 
     // compositionComplete is needed for older driver
     hw->compositionComplete();
+    hw->setViewportAndProjection();
 }
 
 
@@ -2805,8 +2806,6 @@
         native_window_api_disconnect(window, NATIVE_WINDOW_API_EGL);
     }
 
-    hw->setViewportAndProjection();
-
     return result;
 }