Bug 912657 - Add support for APZC in the B2G parent process (without turning it on everywhere). r=ajones
authorBotond Ballo <botond@mozilla.com>
Mon, 16 Sep 2013 17:45:31 -0400
changeset 156968 c67f5daf8e21a90609a712a2ac78dcec7fbfb287
parent 156967 e83df1f175cf796cc1c73904c2df1b17fab3b199
child 156969 1aca1af993ac4f34c68e5cb9633a439f74092c97
push id2675
push userbballo@mozilla.com
push dateFri, 22 Nov 2013 17:41:27 +0000
treeherderb2g-inbound@c67f5daf8e21 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersajones
bugs912657
milestone28.0a1
Bug 912657 - Add support for APZC in the B2G parent process (without turning it on everywhere). r=ajones
widget/gonk/ParentProcessController.cpp
widget/gonk/ParentProcessController.h
widget/gonk/moz.build
widget/gonk/nsWindow.cpp
new file mode 100644
--- /dev/null
+++ b/widget/gonk/ParentProcessController.cpp
@@ -0,0 +1,60 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "ParentProcessController.h"
+#include "nsIContent.h"
+#include "nsLayoutUtils.h"
+#include "APZCCallbackHelper.h"
+#include "base/message_loop.h"
+
+namespace mozilla {
+namespace widget {
+
+class RequestContentRepaintEvent : public nsRunnable
+{
+    typedef mozilla::layers::FrameMetrics FrameMetrics;
+
+public:
+    RequestContentRepaintEvent(const FrameMetrics& aFrameMetrics)
+        : mFrameMetrics(aFrameMetrics)
+    {
+    }
+
+    NS_IMETHOD Run() {
+        MOZ_ASSERT(NS_IsMainThread());
+        nsCOMPtr<nsIContent> content = nsLayoutUtils::FindContentFor(mFrameMetrics.mScrollId);
+        if (content) {
+            APZCCallbackHelper::UpdateSubFrame(content, mFrameMetrics);
+        }
+        return NS_OK;
+    }
+
+protected:
+    const FrameMetrics mFrameMetrics;
+};
+
+void
+ParentProcessController::RequestContentRepaint(const FrameMetrics& aFrameMetrics)
+{
+    if (aFrameMetrics.mScrollId == FrameMetrics::NULL_SCROLL_ID) {
+        return;
+    }
+
+    nsCOMPtr<nsIRunnable> r = new RequestContentRepaintEvent(aFrameMetrics);
+    if (!NS_IsMainThread()) {
+        NS_DispatchToMainThread(r);
+    } else {
+        r->Run();
+    }
+}
+
+void
+ParentProcessController::PostDelayedTask(Task* aTask, int aDelayMs)
+{
+    MessageLoop::current()->PostDelayedTask(FROM_HERE, aTask, aDelayMs);
+}
+
+}
+}
new file mode 100644
--- /dev/null
+++ b/widget/gonk/ParentProcessController.h
@@ -0,0 +1,34 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef __mozilla_widget_DynamicToolbarController_h__
+#define __mozilla_widget_DynamicToolbarController_h__
+
+#include "mozilla/layers/GeckoContentController.h"
+
+namespace mozilla {
+namespace widget {
+
+class ParentProcessController : public mozilla::layers::GeckoContentController
+{
+    typedef mozilla::layers::FrameMetrics FrameMetrics;
+
+public:
+    virtual void RequestContentRepaint(const FrameMetrics& aFrameMetrics) MOZ_OVERRIDE;
+    virtual void PostDelayedTask(Task* aTask, int aDelayMs) MOZ_OVERRIDE;
+
+    // No-ops
+    virtual void HandleDoubleTap(const CSSIntPoint& aPoint) MOZ_OVERRIDE {}
+    virtual void HandleSingleTap(const CSSIntPoint& aPoint) MOZ_OVERRIDE {}
+    virtual void HandleLongTap(const CSSIntPoint& aPoint) MOZ_OVERRIDE {}
+    virtual void SendAsyncScrollDOMEvent(bool aIsRoot,
+                                         const CSSRect &aContentRect,
+                                         const CSSSize &aScrollableSize) MOZ_OVERRIDE {}
+};
+
+}
+}
+
+#endif /*__mozilla_widget_DynamicToolbarController_h__ */
--- a/widget/gonk/moz.build
+++ b/widget/gonk/moz.build
@@ -49,16 +49,17 @@ SOURCES += [
     'HwcComposer2D.cpp',
     'HwcUtils.cpp',
     'nsAppShell.cpp',
     'nsIdleServiceGonk.cpp',
     'nsLookAndFeel.cpp',
     'nsWidgetFactory.cpp',
     'nsWindow.cpp',
     'OrientationObserver.cpp',
+    'ParentProcessController.cpp',
     'ProcessOrientation.cpp'
 ]
 
 LIBRARY_NAME = 'widget_gonk'
 
 include('/ipc/chromium/chromium-config.mozbuild')
 
 FINAL_LIBRARY = 'xul'
--- a/widget/gonk/nsWindow.cpp
+++ b/widget/gonk/nsWindow.cpp
@@ -39,16 +39,18 @@
 #include "nsWindow.h"
 #include "nsIWidgetListener.h"
 #include "cutils/properties.h"
 #include "ClientLayerManager.h"
 #include "BasicLayers.h"
 #include "libdisplay/GonkDisplay.h"
 #include "pixelflinger/format.h"
 #include "mozilla/BasicEvents.h"
+#include "mozilla/layers/CompositorParent.h"
+#include "ParentProcessController.h"
 
 #include "HwcComposer2D.h"
 
 #define LOG(args...)  __android_log_print(ANDROID_LOG_INFO, "Gonk" , ## args)
 #define LOGW(args...) __android_log_print(ANDROID_LOG_WARN, "Gonk", ## args)
 #define LOGE(args...) __android_log_print(ANDROID_LOG_ERROR, "Gonk", ## args)
 
 #define IS_TOPLEVEL() (mWindowType == eWindowType_toplevel || mWindowType == eWindowType_dialog)
@@ -584,16 +586,20 @@ nsWindow::GetLayerManager(PLayerTransact
 
     if (!topWindow) {
         LOGW(" -- no topwindow\n");
         return nullptr;
     }
 
     if (sUsingOMTC) {
         CreateCompositor();
+        if (mCompositorParent) {
+            uint64_t rootLayerTreeId = mCompositorParent->RootLayerTreeId();
+            CompositorParent::SetControllerForLayerTree(rootLayerTreeId, new ParentProcessController());
+        }
         if (mLayerManager)
             return mLayerManager;
     }
 
     if (mUseLayersAcceleration) {
         DebugOnly<nsIntRect> fbBounds = gScreenBounds;
         if (!sGLContext) {
             sGLContext = GLContextProvider::CreateForWindow(this);