Bug 1005322 - Implement invalidate hook for HwcComposer2D. r=Sushil, r=mwu, a=bajaj
authorSotaro Ikeda <sikeda@mozilla.com>
Wed, 24 Sep 2014 06:50:45 -0700
changeset 225127 c7a463892539ab08d0641e8a42844785303fe95a
parent 225126 61a3b1ea8af3474e4648199e507f52730000beb4
child 225128 cb2848634e33f5924889ebe1bf6895a9e50fd36e
push id3979
push userraliiev@mozilla.com
push dateMon, 13 Oct 2014 16:35:44 +0000
treeherdermozilla-beta@30f2cc610691 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersSushil, mwu, bajaj
bugs1005322
milestone34.0a2
Bug 1005322 - Implement invalidate hook for HwcComposer2D. r=Sushil, r=mwu, a=bajaj
widget/gonk/HwcComposer2D.cpp
widget/gonk/HwcComposer2D.h
widget/gonk/nsWindow.cpp
--- a/widget/gonk/HwcComposer2D.cpp
+++ b/widget/gonk/HwcComposer2D.cpp
@@ -16,16 +16,17 @@
 
 #include <android/log.h>
 #include <string.h>
 
 #include "libdisplay/GonkDisplay.h"
 #include "HwcUtils.h"
 #include "HwcComposer2D.h"
 #include "LayerScope.h"
+#include "mozilla/layers/CompositorParent.h"
 #include "mozilla/layers/LayerManagerComposite.h"
 #include "mozilla/layers/PLayerTransaction.h"
 #include "mozilla/layers/ShadowLayerUtilsGralloc.h"
 #include "mozilla/layers/TextureHostOGL.h"  // for TextureHostOGL
 #include "mozilla/StaticPtr.h"
 #include "cutils/properties.h"
 #include "gfx2DGlue.h"
 #include "GeckoTouchDispatcher.h"
@@ -67,17 +68,17 @@ using namespace mozilla::gfx;
 using namespace mozilla::layers;
 
 namespace mozilla {
 
 #if ANDROID_VERSION >= 17
 static void
 HookInvalidate(const struct hwc_procs* aProcs)
 {
-    // no op
+    HwcComposer2D::GetInstance()->Invalidate();
 }
 
 static void
 HookVsync(const struct hwc_procs* aProcs, int aDisplay,
           int64_t aTimestamp)
 {
     HwcComposer2D::GetInstance()->Vsync(aDisplay, aTimestamp);
 }
@@ -106,16 +107,17 @@ HwcComposer2D::HwcComposer2D()
     , mColorFill(false)
     , mRBSwapSupport(false)
 #if ANDROID_VERSION >= 17
     , mPrevRetireFence(Fence::NO_FENCE)
     , mPrevDisplayFence(Fence::NO_FENCE)
 #endif
     , mPrepared(false)
     , mHasHWVsync(false)
+    , mLock("mozilla.HwcComposer2D.mLock")
 {
 }
 
 HwcComposer2D::~HwcComposer2D() {
     free(mList);
 }
 
 int
@@ -226,18 +228,40 @@ HwcComposer2D::RunVsyncEventControl(bool
     }
 }
 
 void
 HwcComposer2D::Vsync(int aDisplay, int64_t aTimestamp)
 {
     GeckoTouchDispatcher::NotifyVsync(aTimestamp);
 }
+
+// Called on the "invalidator" thread (run from HAL).
+void
+HwcComposer2D::Invalidate()
+{
+    if (!Initialized()) {
+        LOGE("HwcComposer2D::Invalidate failed!");
+        return;
+    }
+
+    MutexAutoLock lock(mLock);
+    if (mCompositorParent) {
+        mCompositorParent->ScheduleRenderOnCompositorThread();
+    }
+}
 #endif
 
+void
+HwcComposer2D::SetCompositorParent(CompositorParent* aCompositorParent)
+{
+    MutexAutoLock lock(mLock);
+    mCompositorParent = aCompositorParent;
+}
+
 bool
 HwcComposer2D::ReallocLayerList()
 {
     int size = sizeof(HwcList) +
         ((mMaxLayerCount + LAYER_COUNT_INCREMENTS) * sizeof(HwcLayer));
 
     HwcList* listrealloc = (HwcList*)realloc(mList, size);
 
--- a/widget/gonk/HwcComposer2D.h
+++ b/widget/gonk/HwcComposer2D.h
@@ -14,31 +14,34 @@
  * limitations under the License.
  */
 
 #ifndef mozilla_HwcComposer2D
 #define mozilla_HwcComposer2D
 
 #include "Composer2D.h"
 #include "Layers.h"
+#include "mozilla/Mutex.h"
+
 #include <vector>
 #include <list>
 
 #include <hardware/hwcomposer.h>
 #if ANDROID_VERSION >= 17
 #include <ui/Fence.h>
 #endif
 
 namespace mozilla {
 
 namespace gl {
     class GLContext;
 }
 
 namespace layers {
+class CompositorParent;
 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;
 #if ANDROID_VERSION >= 17
@@ -86,17 +89,19 @@ public:
                    bool aGeometryChanged) MOZ_OVERRIDE;
 
     bool Render(EGLDisplay dpy, EGLSurface sur);
 
     void EnableVsync(bool aEnable);
 #if ANDROID_VERSION >= 17
     bool RegisterHwcEventCallback();
     void Vsync(int aDisplay, int64_t aTimestamp);
+    void Invalidate();
 #endif
+    void SetCompositorParent(layers::CompositorParent* aCompositorParent);
 
 private:
     void Reset();
     void Prepare(buffer_handle_t fbHandle, int fence);
     bool Commit();
     bool TryHwComposition();
     bool ReallocLayerList();
     bool PrepareLayerList(layers::Layer* aContainer, const nsIntRect& aClip,
@@ -123,13 +128,15 @@ private:
     std::list<RectVector>   mVisibleRegions;
 #if ANDROID_VERSION >= 17
     android::sp<android::Fence> mPrevRetireFence;
     android::sp<android::Fence> mPrevDisplayFence;
 #endif
     nsTArray<layers::LayerComposite*> mHwcLayerMap;
     bool                    mPrepared;
     bool                    mHasHWVsync;
+    nsRefPtr<layers::CompositorParent> mCompositorParent;
+    Mutex mLock;
 };
 
 } // namespace mozilla
 
 #endif // mozilla_HwcComposer2D
--- a/widget/gonk/nsWindow.cpp
+++ b/widget/gonk/nsWindow.cpp
@@ -166,16 +166,17 @@ nsWindow::nsWindow()
         MOZ_CRASH("How can we render apps, then?");
     }
     // Update sUsingHwc whenever layers.composer2d.enabled changes
     Preferences::AddBoolVarCache(&sUsingHwc, "layers.composer2d.enabled");
 }
 
 nsWindow::~nsWindow()
 {
+    HwcComposer2D::GetInstance()->SetCompositorParent(nullptr);
 }
 
 void
 nsWindow::DoDraw(void)
 {
     if (!hal::GetScreenEnabled()) {
         gDrawRequest = true;
         return;
@@ -524,16 +525,17 @@ nsWindow::GetLayerManager(PLayerTransact
         return nullptr;
     }
 
     CreateCompositor();
     if (mCompositorParent) {
         uint64_t rootLayerTreeId = mCompositorParent->RootLayerTreeId();
         CompositorParent::SetControllerForLayerTree(rootLayerTreeId, new ParentProcessController());
         CompositorParent::GetAPZCTreeManager(rootLayerTreeId)->SetDPI(GetDPI());
+        HwcComposer2D::GetInstance()->SetCompositorParent(mCompositorParent);
     }
     MOZ_ASSERT(mLayerManager);
     return mLayerManager;
 }
 
 void
 nsWindow::BringToTop()
 {