Bug 1029856 - Call glClear() before blit composition. r=Sushil, a=1.4+
authorSotaro Ikeda <sikeda@mozilla.com>
Mon, 30 Jun 2014 13:01:24 -0700
changeset 208608 8ecb4e7dc8b71afb0c2a4d6fdaee13c29b0d7899
parent 208607 547deb189c6fca55f79990c07bd4570f8fd5346c
child 208609 4b5aae0fe6a1a228cee816ed232620ae3b8f6166
push id494
push userraliiev@mozilla.com
push dateMon, 25 Aug 2014 18:42:16 +0000
treeherdermozilla-release@a3cc3e46b571 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersSushil, 1
bugs1029856
milestone32.0a2
Bug 1029856 - Call glClear() before blit composition. r=Sushil, a=1.4+
gfx/gl/GLContextProviderEGL.cpp
widget/gonk/HwcComposer2D.cpp
widget/gonk/HwcComposer2D.h
--- a/gfx/gl/GLContextProviderEGL.cpp
+++ b/gfx/gl/GLContextProviderEGL.cpp
@@ -241,17 +241,17 @@ GLContextEGL::GLContextEGL(
 #ifdef DEBUG
     printf_stderr("Initializing context %p surface %p on display %p\n", mContext, mSurface, EGL_DISPLAY());
 #endif
 #if defined(MOZ_WIDGET_GONK)
     if (!mIsOffscreen) {
         mHwc = HwcComposer2D::GetInstance();
         MOZ_ASSERT(!mHwc->Initialized());
 
-        if (mHwc->Init(EGL_DISPLAY(), mSurface)) {
+        if (mHwc->Init(EGL_DISPLAY(), mSurface, this)) {
             NS_WARNING("HWComposer initialization failed!");
             mHwc = nullptr;
         }
     }
 #endif
 }
 
 GLContextEGL::~GLContextEGL()
--- a/widget/gonk/HwcComposer2D.cpp
+++ b/widget/gonk/HwcComposer2D.cpp
@@ -64,33 +64,34 @@ using namespace mozilla::layers;
 
 namespace mozilla {
 
 static StaticRefPtr<HwcComposer2D> sInstance;
 
 HwcComposer2D::HwcComposer2D()
     : mHwc(nullptr)
     , mList(nullptr)
+    , mGLContext(nullptr)
     , mMaxLayerCount(0)
     , mColorFill(false)
     , mRBSwapSupport(false)
 #if ANDROID_VERSION >= 17
     , mPrevRetireFence(Fence::NO_FENCE)
     , mPrevDisplayFence(Fence::NO_FENCE)
 #endif
     , mPrepared(false)
 {
 }
 
 HwcComposer2D::~HwcComposer2D() {
     free(mList);
 }
 
 int
-HwcComposer2D::Init(hwc_display_t dpy, hwc_surface_t sur)
+HwcComposer2D::Init(hwc_display_t dpy, hwc_surface_t sur, gl::GLContext* aGLContext)
 {
     MOZ_ASSERT(!Initialized());
 
     mHwc = (HwcDevice*)GetGonkDisplay()->GetHWCDevice();
     if (!mHwc) {
         LOGE("Failed to initialize hwc");
         return -1;
     }
@@ -118,16 +119,17 @@ HwcComposer2D::Init(hwc_display_t dpy, h
     char propValue[PROPERTY_VALUE_MAX];
     property_get("ro.display.colorfill", propValue, "0");
     mColorFill = (atoi(propValue) == 1) ? true : false;
     mRBSwapSupport = true;
 #endif
 
     mDpy = dpy;
     mSur = sur;
+    mGLContext = aGLContext;
 
     return 0;
 }
 
 HwcComposer2D*
 HwcComposer2D::GetInstance()
 {
     if (!sInstance) {
@@ -578,16 +580,23 @@ HwcComposer2D::TryHwComposition()
                     break;
             }
         }
 
         if (gpuComposite) {
             // GPU or partial OVERLAY Composition
             return false;
         } else if (blitComposite) {
+            // Some EGLSurface implementations require glClear() on blit composition.
+            // See bug 1029856.
+            if (mGLContext) {
+                mGLContext->MakeCurrent();
+                mGLContext->fClearColor(0.0, 0.0, 0.0, 0.0);
+                mGLContext->fClear(LOCAL_GL_COLOR_BUFFER_BIT);
+            }
             // BLIT Composition, flip FB target
             GetGonkDisplay()->UpdateFBSurface(mDpy, mSur);
             FramebufferSurface* fbsurface = (FramebufferSurface*)(GetGonkDisplay()->GetFBSurface());
             if (!fbsurface) {
                 LOGE("H/W Composition failed. NULL FBSurface.");
                 return false;
             }
             mList->hwLayers[idx].handle = fbsurface->lastHandle;
--- a/widget/gonk/HwcComposer2D.h
+++ b/widget/gonk/HwcComposer2D.h
@@ -24,16 +24,20 @@
 
 #include <hardware/hwcomposer.h>
 #if ANDROID_VERSION >= 17
 #include <ui/Fence.h>
 #endif
 
 namespace mozilla {
 
+namespace gl {
+    class GLContext;
+}
+
 namespace layers {
 class ContainerLayer;
 class Layer;
 }
 
 //Holds a dynamically allocated vector of rectangles
 //used to decribe the complex visible region of a layer
 typedef std::vector<hwc_rect_t> RectVector;
@@ -64,17 +68,17 @@ typedef hwc_layer_t HwcLayer;
  * using the GPU with OpenGL.
  *
  */
 class HwcComposer2D : public mozilla::layers::Composer2D {
 public:
     HwcComposer2D();
     virtual ~HwcComposer2D();
 
-    int Init(hwc_display_t aDisplay, hwc_surface_t aSurface);
+    int Init(hwc_display_t aDisplay, hwc_surface_t aSurface, gl::GLContext* aGLContext);
 
     bool Initialized() const { return mHwc; }
 
     static HwcComposer2D* GetInstance();
 
     // Returns TRUE if the container has been succesfully rendered
     // Returns FALSE if the container cannot be fully rendered
     // by this composer so nothing was rendered at all
@@ -93,16 +97,17 @@ private:
           const gfxMatrix& aParentTransform, const gfxMatrix& aGLWorldTransform);
     void setCrop(HwcLayer* layer, hwc_rect_t srcCrop);
     void setHwcGeometry(bool aGeometryChanged);
 
     HwcDevice*              mHwc;
     HwcList*                mList;
     hwc_display_t           mDpy;
     hwc_surface_t           mSur;
+    gl::GLContext*          mGLContext;
     nsIntRect               mScreenRect;
     int                     mMaxLayerCount;
     bool                    mColorFill;
     bool                    mRBSwapSupport;
     //Holds all the dynamically allocated RectVectors needed
     //to render the current frame
     std::list<RectVector>   mVisibleRegions;
 #if ANDROID_VERSION >= 17