Bug 1127066 - Implement proper sending of target-apzc notification and creation of displayport in the root process. r=kats
authorBotond Ballo <botond@mozilla.com>
Fri, 06 Feb 2015 18:11:30 -0500
changeset 257573 c55657471570a3a4d8afe11768d5e74670b1f6bd
parent 257572 4bd0d2b7b41db99880fe56e306711fe594bdcce7
child 257574 135a4238353508358d7403da886e88df7bdd17ce
push id721
push userjlund@mozilla.com
push dateTue, 21 Apr 2015 23:03:33 +0000
treeherdermozilla-release@d27c9211ebb3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskats
bugs1127066
milestone38.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 1127066 - Implement proper sending of target-apzc notification and creation of displayport in the root process. r=kats
widget/nsBaseWidget.cpp
widget/nsBaseWidget.h
--- a/widget/nsBaseWidget.cpp
+++ b/widget/nsBaseWidget.cpp
@@ -47,16 +47,17 @@
 #include "mozilla/VsyncDispatcher.h"
 #include "mozilla/layers/APZCTreeManager.h"
 #include "mozilla/layers/APZThreadUtils.h"
 #include "mozilla/layers/ChromeProcessController.h"
 #include "mozilla/layers/InputAPZContext.h"
 #include "mozilla/layers/APZCCallbackHelper.h"
 #include "mozilla/dom/TabParent.h"
 #include "nsRefPtrHashtable.h"
+#include "TouchEvents.h"
 #ifdef ACCESSIBILITY
 #include "nsAccessibilityService.h"
 #endif
 
 #ifdef DEBUG
 #include "nsIObserver.h"
 
 static void debug_RegisterPrefCallbacks();
@@ -911,23 +912,43 @@ void nsBaseWidget::CreateCompositor()
 
 already_AddRefed<GeckoContentController>
 nsBaseWidget::CreateRootContentController()
 {
   nsRefPtr<GeckoContentController> controller = new ChromeProcessController(this);
   return controller.forget();
 }
 
+class ChromeProcessSetTargetAPZCCallback : public SetTargetAPZCCallback {
+public:
+  explicit ChromeProcessSetTargetAPZCCallback(APZCTreeManager* aTreeManager)
+    : mTreeManager(aTreeManager)
+  {}
+
+  void Run(uint64_t aInputBlockId, const nsTArray<ScrollableLayerGuid>& aTargets) const MOZ_OVERRIDE {
+    MOZ_ASSERT(NS_IsMainThread());
+    // need a local var to disambiguate between the SetTargetAPZC overloads.
+    void (APZCTreeManager::*setTargetApzcFunc)(uint64_t, const nsTArray<ScrollableLayerGuid>&)
+        = &APZCTreeManager::SetTargetAPZC;
+    APZThreadUtils::RunOnControllerThread(NewRunnableMethod(
+        mTreeManager.get(), setTargetApzcFunc, aInputBlockId, aTargets));
+  }
+
+private:
+  nsRefPtr<APZCTreeManager> mTreeManager;
+};
+
 void nsBaseWidget::ConfigureAPZCTreeManager()
 {
   uint64_t rootLayerTreeId = mCompositorParent->RootLayerTreeId();
   mAPZC = CompositorParent::GetAPZCTreeManager(rootLayerTreeId);
   MOZ_ASSERT(mAPZC);
 
   mAPZC->SetDPI(GetDPI());
+  mSetTargetAPZCCallback = new ChromeProcessSetTargetAPZCCallback(mAPZC);
 
   nsRefPtr<GeckoContentController> controller = CreateRootContentController();
   if (controller) {
     CompositorParent::SetControllerForLayerTree(rootLayerTreeId, controller);
   }
 }
 
 nsEventStatus
@@ -948,25 +969,22 @@ nsBaseWidget::DispatchEventForAPZ(Widget
     APZCCallbackHelper::ApplyCallbackTransform(*aEvent->AsTouchEvent(), aGuid,
         GetDefaultScale(), 1.0f);
   }
 
   nsEventStatus status;
   DispatchEvent(aEvent, status);
 
   if (mAPZC && !context.WasRoutedToChildProcess()) {
-    // APZ did not find a dispatch-to-content region in the child process,
-    // and EventStateManager did not route the event into the child process.
+    // EventStateManager did not route the event into the child process.
     // It's safe to communicate to APZ that the event has been processed.
-
-    // need a local var to disambiguate between the SetTargetAPZC overloads.
-    void (APZCTreeManager::*setTargetApzcFunc)(uint64_t, const ScrollableLayerGuid&)
-        = &APZCTreeManager::SetTargetAPZC;
-    APZThreadUtils::RunOnControllerThread(NewRunnableMethod(
-        mAPZC.get(), setTargetApzcFunc, aInputBlockId, aGuid));
+    if (aEvent->AsWheelEvent() || (aEvent->AsTouchEvent() && aEvent->AsTouchEvent()->message == NS_TOUCH_START)) {
+      APZCCallbackHelper::SendSetTargetAPZCNotification(this, GetDocument(), *aEvent,
+          aGuid, aInputBlockId, mSetTargetAPZCCallback);
+    }
     bool defaultPrevented = aEvent->AsTouchEvent()
       ? (nsIPresShell::gPreventMouseEvents || aEvent->mFlags.mMultipleActionsPrevented)
       : aEvent->mFlags.mDefaultPrevented;
     APZThreadUtils::RunOnControllerThread(NewRunnableMethod(
         mAPZC.get(), &APZCTreeManager::ContentReceivedInputBlock, aInputBlockId,
         defaultPrevented));
   }
 
@@ -978,16 +996,27 @@ nsBaseWidget::GetPreferredCompositorBack
 {
   if (mUseLayersAcceleration) {
     aHints.AppendElement(LayersBackend::LAYERS_OPENGL);
   }
 
   aHints.AppendElement(LayersBackend::LAYERS_BASIC);
 }
 
+nsIDocument*
+nsBaseWidget::GetDocument() const
+{
+  if (mWidgetListener) {
+    if (nsIPresShell* presShell = mWidgetListener->GetPresShell()) {
+      return presShell->GetDocument();
+    }
+  }
+  return nullptr;
+}
+
 void nsBaseWidget::CreateCompositorVsyncDispatcher()
 {
   if (gfxPrefs::HardwareVsyncEnabled()) {
     // Parent directly listens to the vsync source whereas
     // child process communicate via IPC
     // Should be called AFTER gfxPlatform is initialized
     if (XRE_IsParentProcess()) {
       mCompositorVsyncDispatcher = new CompositorVsyncDispatcher();
@@ -1557,25 +1586,17 @@ nsBaseWidget::NotifyThemeChanged()
     presShell->ThemeChanged();
   }
 }
 
 void
 nsBaseWidget::NotifyUIStateChanged(UIStateChangeType aShowAccelerators,
                                    UIStateChangeType aShowFocusRings)
 {
-  if (!mWidgetListener)
-    return;
-
-  nsIPresShell* presShell = mWidgetListener->GetPresShell();
-  if (!presShell)
-    return;
-
-  nsIDocument* doc = presShell->GetDocument();
-  if (doc) {
+  if (nsIDocument* doc = GetDocument()) {
     nsPIDOMWindow* win = doc->GetWindow();
     if (win) {
       win->SetKeyboardIndicators(aShowAccelerators, aShowFocusRings);
     }
   }
 }
 
 NS_IMETHODIMP
--- a/widget/nsBaseWidget.h
+++ b/widget/nsBaseWidget.h
@@ -32,16 +32,17 @@ class Accessible;
 
 namespace layers {
 class BasicLayerManager;
 class CompositorChild;
 class CompositorParent;
 class APZCTreeManager;
 class GeckoContentController;
 struct ScrollableLayerGuid;
+struct SetTargetAPZCCallback;
 }
 
 class CompositorVsyncDispatcher;
 }
 
 namespace base {
 class Thread;
 }
@@ -85,16 +86,17 @@ protected:
   typedef base::Thread Thread;
   typedef mozilla::layers::BasicLayerManager BasicLayerManager;
   typedef mozilla::layers::BufferMode BufferMode;
   typedef mozilla::layers::CompositorChild CompositorChild;
   typedef mozilla::layers::CompositorParent CompositorParent;
   typedef mozilla::layers::APZCTreeManager APZCTreeManager;
   typedef mozilla::layers::GeckoContentController GeckoContentController;
   typedef mozilla::layers::ScrollableLayerGuid ScrollableLayerGuid;
+  typedef mozilla::layers::SetTargetAPZCCallback SetTargetAPZCCallback;
   typedef mozilla::ScreenRotation ScreenRotation;
 
   virtual ~nsBaseWidget();
 
 public:
   nsBaseWidget();
 
   NS_DECL_ISUPPORTS
@@ -411,16 +413,18 @@ protected:
 
   virtual void GetPreferredCompositorBackends(nsTArray<mozilla::layers::LayersBackend>& aHints);
 
   /**
    * Notify the widget that this window is being used with OMTC.
    */
   virtual void WindowUsesOMTC() {}
 
+  nsIDocument* GetDocument() const;
+
 protected:
   /**
    * Starts the OMTC compositor destruction sequence.
    *
    * When this function returns, the compositor should not be 
    * able to access the opengl context anymore.
    * It is safe to call it several times if platform implementations
    * require the compositor to be destroyed before ~nsBaseWidget is
@@ -431,16 +435,17 @@ protected:
   nsIWidgetListener* mWidgetListener;
   nsIWidgetListener* mAttachedWidgetListener;
   nsRefPtr<LayerManager> mLayerManager;
   nsRefPtr<LayerManager> mBasicLayerManager;
   nsRefPtr<CompositorChild> mCompositorChild;
   nsRefPtr<CompositorParent> mCompositorParent;
   nsRefPtr<mozilla::CompositorVsyncDispatcher> mCompositorVsyncDispatcher;
   nsRefPtr<APZCTreeManager> mAPZC;
+  nsRefPtr<SetTargetAPZCCallback> mSetTargetAPZCCallback;
   nsRefPtr<WidgetShutdownObserver> mShutdownObserver;
   nsRefPtr<TextEventDispatcher> mTextEventDispatcher;
   nsCursor          mCursor;
   bool              mUpdateCursor;
   nsBorderStyle     mBorderStyle;
   bool              mUseLayersAcceleration;
   bool              mForceLayersAcceleration;
   bool              mTemporarilyUseBasicLayerManager;