Bug 944069 - Remove unnecessary wait during GPU Composition. r=dwilson
authorSushil Chauhan <sushilchauhan@codeaurora.org>
Wed, 27 Nov 2013 17:38:42 -0800
changeset 158195 cea5ec120ed778acf7eff36135e8dd67cbd25425
parent 158194 a1628c9ba4afc35ea428176e2c2adaa5ba5f4f11
child 158196 0815ba262621ab757aebde197c4422dc771fd1b7
push id2913
push userryanvm@gmail.com
push dateMon, 02 Dec 2013 15:29:38 +0000
treeherderb2g-inbound@bc50783a4cf7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdwilson
bugs944069
milestone28.0a1
Bug 944069 - Remove unnecessary wait during GPU Composition. r=dwilson
widget/gonk/HwcComposer2D.cpp
widget/gonk/HwcComposer2D.h
--- a/widget/gonk/HwcComposer2D.cpp
+++ b/widget/gonk/HwcComposer2D.cpp
@@ -58,16 +58,17 @@ namespace mozilla {
 static StaticRefPtr<HwcComposer2D> sInstance;
 
 HwcComposer2D::HwcComposer2D()
     : mMaxLayerCount(0)
     , mList(nullptr)
     , mHwc(nullptr)
     , mColorFill(false)
     , mRBSwapSupport(false)
+    , mPrevRetireFence(-1)
 {
 }
 
 HwcComposer2D::~HwcComposer2D() {
     free(mList);
 }
 
 int
@@ -487,17 +488,16 @@ HwcComposer2D::TryHwComposition()
         return false;
     }
 
     // Full HWC Composition
     Commit();
 
     // No composition on FB layer, so closing releaseFenceFd
     close(mList->hwLayers[idx].releaseFenceFd);
-    mList->hwLayers[idx].releaseFenceFd = -1;
     mList->numHwLayers = 0;
     return true;
 }
 
 bool
 HwcComposer2D::Render(EGLDisplay dpy, EGLSurface sur)
 {
     if (!mList) {
@@ -568,41 +568,48 @@ HwcComposer2D::Prepare(buffer_handle_t f
 bool
 HwcComposer2D::Commit()
 {
     hwc_display_contents_1_t *displays[HWC_NUM_DISPLAY_TYPES] = { nullptr };
     displays[HWC_DISPLAY_PRIMARY] = mList;
 
     int err = mHwc->set(mHwc, HWC_NUM_DISPLAY_TYPES, displays);
 
+    // To avoid tearing, workaround for missing releaseFenceFd
+    // waits in Gecko layers, see Bug 925444.
     if (!mPrevReleaseFds.IsEmpty()) {
         // Wait for previous retire Fence to signal.
         // Denotes contents on display have been replaced.
         // For buffer-sync, framework should not over-write
         // prev buffers until we close prev releaseFenceFds
-        sp<Fence> fence = new Fence(mPrevReleaseFds[0]);
+        sp<Fence> fence = new Fence(mPrevRetireFence);
         if (fence->wait(1000) == -ETIME) {
-            LOGE("Wait timed-out for retireFenceFd %d", mPrevReleaseFds[0]);
+            LOGE("Wait timed-out for retireFenceFd %d", mPrevRetireFence);
         }
-
         for (int i = 0; i < mPrevReleaseFds.Length(); i++) {
             close(mPrevReleaseFds[i]);
         }
+        close(mPrevRetireFence);
         mPrevReleaseFds.Clear();
     }
 
-    mPrevReleaseFds.AppendElement(mList->retireFenceFd);
     for (uint32_t j=0; j < (mList->numHwLayers - 1); j++) {
-        if (mList->hwLayers[j].compositionType == HWC_OVERLAY) {
+        if (mList->hwLayers[j].releaseFenceFd >= 0) {
             mPrevReleaseFds.AppendElement(mList->hwLayers[j].releaseFenceFd);
-            mList->hwLayers[j].releaseFenceFd = -1;
         }
     }
 
-    mList->retireFenceFd = -1;
+    if (mList->retireFenceFd >= 0) {
+        if (!mPrevReleaseFds.IsEmpty()) {
+            mPrevRetireFence = mList->retireFenceFd;
+        } else { // GPU Composition
+            close(mList->retireFenceFd);
+        }
+    }
+
     return !err;
 }
 #else
 bool
 HwcComposer2D::TryHwComposition()
 {
     return !mHwc->set(mHwc, mDpy, mSur, mList);
 }
--- a/widget/gonk/HwcComposer2D.h
+++ b/widget/gonk/HwcComposer2D.h
@@ -77,14 +77,15 @@ private:
     nsIntRect               mScreenRect;
     int                     mMaxLayerCount;
     bool                    mColorFill;
     bool                    mRBSwapSupport;
     //Holds all the dynamically allocated RectVectors needed
     //to render the current frame
     std::list<RectVector>   mVisibleRegions;
     nsTArray<int>           mPrevReleaseFds;
+    int                     mPrevRetireFence;
     nsTArray<layers::LayerComposite*> mHwcLayerMap;
 };
 
 } // namespace mozilla
 
 #endif // mozilla_HwcComposer2D