Bug 1328752 - part 2, Update Android nsWindow to use UiCompositorControllerChild in place of CompositorBridgeParent r=jchen
authorRandall Barker <rbarker@mozilla.com>
Thu, 05 Jan 2017 11:11:41 -0800
changeset 377728 8aa58e6577516d8bde4ff9d4555e59d6a511fc4f
parent 377727 7ceb7d18b5e090f6283fbe7062bfd194f5863783
child 377729 5a62757abb0eee86e09b434d6007988b4c5d4b66
push id1419
push userjlund@mozilla.com
push dateMon, 10 Apr 2017 20:44:07 +0000
treeherdermozilla-release@5e6801b73ef6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjchen
bugs1328752
milestone53.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1328752 - part 2, Update Android nsWindow to use UiCompositorControllerChild in place of CompositorBridgeParent r=jchen
widget/android/nsWindow.cpp
widget/android/nsWindow.h
--- a/widget/android/nsWindow.cpp
+++ b/widget/android/nsWindow.cpp
@@ -91,19 +91,19 @@ using namespace mozilla;
 using namespace mozilla::dom;
 using namespace mozilla::layers;
 using namespace mozilla::java;
 using namespace mozilla::widget;
 
 NS_IMPL_ISUPPORTS_INHERITED0(nsWindow, nsBaseWidget)
 
 #include "mozilla/layers/CompositorBridgeChild.h"
-#include "mozilla/layers/CompositorBridgeParent.h"
 #include "mozilla/layers/CompositorSession.h"
 #include "mozilla/layers/LayerTransactionParent.h"
+#include "mozilla/layers/UiCompositorControllerChild.h"
 #include "mozilla/Services.h"
 #include "nsThreadUtils.h"
 
 // All the toplevel windows that have been created; these are in
 // stacking order, so the window at gTopLevelWindows[0] is the topmost
 // one.
 static nsTArray<nsWindow*> gTopLevelWindows;
 
@@ -1078,18 +1078,18 @@ public:
                 jni::GetGeckoThreadEnv(),
                 NativePanZoomController::Ref::From(aNPZC));
         mWindow->mNPZCSupport.Attach(npzc, mWindow, npzc);
 
         mLayerClient->OnGeckoReady();
 
         // Set the first-paint flag so that we (re-)link any new Java objects
         // to Gecko, co-ordinate viewports, etc.
-        if (RefPtr<CompositorBridgeParent> bridge = mWindow->GetCompositorBridgeParent()) {
-            bridge->ForceIsFirstPaint();
+        if (RefPtr<CompositorBridgeChild> bridge = mWindow->GetCompositorBridgeChild()) {
+            bridge->SendForceIsFirstPaint();
         }
     }
 
     void OnSizeChanged(int32_t aWindowWidth, int32_t aWindowHeight,
                        int32_t aScreenWidth, int32_t aScreenHeight)
     {
         MOZ_ASSERT(NS_IsMainThread());
         if (!mWindow) {
@@ -1115,62 +1115,77 @@ public:
         mCompositorPaused = false;
         OnResumedCompositor();
     }
 
     void SyncPauseCompositor()
     {
         MOZ_ASSERT(AndroidBridge::IsJavaUiThread());
 
-        RefPtr<CompositorBridgeParent> bridge;
-
+        int64_t id = 0;
         if (LockedWindowPtr window{mWindow}) {
-            bridge = window->GetCompositorBridgeParent();
+            id = window->GetRootLayerId();
         }
 
-        if (bridge) {
-            mCompositorPaused = true;
-            bridge->SchedulePauseOnCompositorThread();
+        if (id == 0) {
+            return;
+        }
+
+        RefPtr<UiCompositorControllerChild> child = UiCompositorControllerChild::Get();
+        if (child) {
+          mCompositorPaused = true;
+          child->SendPause(id);
         }
     }
 
     void SyncResumeCompositor()
     {
         MOZ_ASSERT(AndroidBridge::IsJavaUiThread());
 
-        RefPtr<CompositorBridgeParent> bridge;
-
+        int64_t id = 0;
         if (LockedWindowPtr window{mWindow}) {
-            bridge = window->GetCompositorBridgeParent();
+            id = window->GetRootLayerId();
+        }
+
+        if (id == 0) {
+            return;
         }
 
-        if (bridge && bridge->ScheduleResumeOnCompositorThread()) {
-            mCompositorPaused = false;
+        RefPtr<UiCompositorControllerChild> child = UiCompositorControllerChild::Get();
+        if (child) {
+          mCompositorPaused = false;
+          child->SendResume(id);
         }
     }
 
     void SyncResumeResizeCompositor(const LayerView::Compositor::LocalRef& aObj,
                                     int32_t aWidth, int32_t aHeight,
                                     jni::Object::Param aSurface)
     {
         MOZ_ASSERT(AndroidBridge::IsJavaUiThread());
 
-        RefPtr<CompositorBridgeParent> bridge;
-
+        mSurface = aSurface;
+
+        int64_t id = 0;
         if (LockedWindowPtr window{mWindow}) {
-            bridge = window->GetCompositorBridgeParent();
+            id = window->GetRootLayerId();
         }
 
-        mSurface = aSurface;
-
-        if (!bridge || !bridge->ScheduleResumeOnCompositorThread(aWidth,
-                                                                 aHeight)) {
+        if (id == 0) {
             return;
         }
 
+        RefPtr<UiCompositorControllerChild> child = UiCompositorControllerChild::Get();
+
+        if (!child) {
+            return;
+        }
+
+        child->SendResumeAndResize(id, aWidth, aHeight);
+
         mCompositorPaused = false;
 
         class OnResumedEvent : public nsAppShell::Event
         {
             LayerView::Compositor::GlobalRef mCompositor;
 
         public:
             OnResumedEvent(LayerView::Compositor::GlobalRef&& aCompositor)
@@ -1191,26 +1206,44 @@ public:
         };
 
         nsAppShell::PostEvent(MakeUnique<LayerViewEvent>(
                 MakeUnique<OnResumedEvent>(aObj)));
     }
 
     void SyncInvalidateAndScheduleComposite()
     {
-        RefPtr<CompositorBridgeParent> bridge;
-
+        RefPtr<UiCompositorControllerChild> child = UiCompositorControllerChild::Get();
+
+        if (!child) {
+            return;
+        }
+
+        int64_t id = 0;
         if (LockedWindowPtr window{mWindow}) {
-            bridge = window->GetCompositorBridgeParent();
+            id = window->GetRootLayerId();
+        }
+
+        if (id == 0) {
+            return;
         }
 
-        if (bridge) {
-            bridge->InvalidateOnCompositorThread();
-            bridge->ScheduleRenderOnCompositorThread();
+        if (!AndroidBridge::IsJavaUiThread()) {
+            RefPtr<nsThread> uiThread = GetAndroidUiThread();
+            if (uiThread) {
+                uiThread->Dispatch(NewRunnableMethod<const int64_t&>(child,
+                                                                     &UiCompositorControllerChild::SendInvalidateAndRender,
+                                                                     id),
+                                   nsIThread::DISPATCH_NORMAL);
+            }
+            return;
         }
+
+        MOZ_ASSERT(AndroidBridge::IsJavaUiThread());
+        child->SendInvalidateAndRender(id);
     }
 };
 
 template<> const char
 nsWindow::NativePtr<nsWindow::LayerViewSupport>::sName[] = "LayerViewSupport";
 
 /* PresentationMediaPlayerManager native calls access inner nsWindow functionality so PMPMSupport is a child class of nsWindow */
 class nsWindow::PMPMSupport final
@@ -1631,16 +1664,22 @@ nsWindow::RedrawAll()
 {
     if (mAttachedWidgetListener) {
         mAttachedWidgetListener->RequestRepaint();
     } else if (mWidgetListener) {
         mWidgetListener->RequestRepaint();
     }
 }
 
+int64_t
+nsWindow::GetRootLayerId() const
+{
+    return mCompositorSession ? mCompositorSession->RootLayerTreeId() : 0;
+}
+
 void
 nsWindow::SetParent(nsIWidget *aNewParent)
 {
     if ((nsIWidget*)mParent == aNewParent)
         return;
 
     // If we had a parent before, remove ourselves from its list of
     // children.
@@ -3603,20 +3642,20 @@ nsWindow::GetMaxTouchPoints() const
 void
 nsWindow::UpdateZoomConstraints(const uint32_t& aPresShellId,
                                 const FrameMetrics::ViewID& aViewId,
                                 const mozilla::Maybe<ZoomConstraints>& aConstraints)
 {
     nsBaseWidget::UpdateZoomConstraints(aPresShellId, aViewId, aConstraints);
 }
 
-CompositorBridgeParent*
-nsWindow::GetCompositorBridgeParent() const
+CompositorBridgeChild*
+nsWindow::GetCompositorBridgeChild() const
 {
-    return mCompositorSession ? mCompositorSession->GetInProcessBridge() : nullptr;
+    return mCompositorSession ? mCompositorSession->GetCompositorBridgeChild() : nullptr;
 }
 
 already_AddRefed<nsIScreen>
 nsWindow::GetWidgetScreen()
 {
     nsCOMPtr<nsIScreenManager> screenMgr =
         do_GetService("@mozilla.org/gfx/screenmanager;1");
     MOZ_ASSERT(screenMgr, "Failed to get nsIScreenManager");
--- a/widget/android/nsWindow.h
+++ b/widget/android/nsWindow.h
@@ -22,17 +22,16 @@
 
 struct ANPEvent;
 
 namespace mozilla {
     class TextComposition;
     class WidgetTouchEvent;
 
     namespace layers {
-        class CompositorBridgeParent;
         class CompositorBridgeChild;
         class LayerManager;
         class APZCTreeManager;
     }
 }
 
 class nsWindow : public nsBaseWidget
 {
@@ -234,17 +233,17 @@ public:
                                         nsIObserver* aObserver) override;
     nsresult SynthesizeNativeMouseEvent(LayoutDeviceIntPoint aPoint,
                                         uint32_t aNativeMessage,
                                         uint32_t aModifierFlags,
                                         nsIObserver* aObserver) override;
     nsresult SynthesizeNativeMouseMove(LayoutDeviceIntPoint aPoint,
                                        nsIObserver* aObserver) override;
 
-    CompositorBridgeParent* GetCompositorBridgeParent() const;
+    CompositorBridgeChild* GetCompositorBridgeChild() const;
 
     mozilla::jni::DependentRef<mozilla::java::GeckoLayerClient> GetLayerClient();
 
 protected:
     void BringToFront();
     nsWindow *FindTopLevel();
     bool IsTopLevel();
 
@@ -287,11 +286,13 @@ protected:
     static void DumpWindows(const nsTArray<nsWindow*>& wins, int indent = 0);
     static void LogWindow(nsWindow *win, int index, int indent);
 
 private:
     void CreateLayerManager(int aCompositorWidth, int aCompositorHeight);
     void RedrawAll();
 
     mozilla::java::LayerRenderer::Frame::GlobalRef mLayerRendererFrame;
+
+    int64_t GetRootLayerId() const;
 };
 
 #endif /* NSWINDOW_H_ */