From 104a98a38bca1482cf861d1c491c02d4140b220a Mon Sep 17 00:00:00 2001 From: David Anderson Date: Mon, 15 Dec 2014 01:47:15 -0800 Subject: [PATCH] Move APZC initialization into nsBaseWidget. (bug 1110540 part 1, r=kats) --- widget/cocoa/nsChildView.h | 8 +++--- widget/cocoa/nsChildView.mm | 29 ++++++++++------------ widget/gonk/nsWindow.cpp | 10 +++++--- widget/gonk/nsWindow.h | 4 +++ widget/nsBaseWidget.cpp | 25 +++++++++++++++++++ widget/nsBaseWidget.h | 8 ++++++ widget/windows/nsWindow.cpp | 15 +---------- widget/windows/nsWindow.h | 5 ---- widget/windows/winrt/MetroWidget.cpp | 37 +++++++++++++--------------- widget/windows/winrt/MetroWidget.h | 5 +++- 10 files changed, 83 insertions(+), 63 deletions(-) diff --git a/widget/cocoa/nsChildView.h b/widget/cocoa/nsChildView.h index dc62a5faf8f..3af6285d3a8 100644 --- a/widget/cocoa/nsChildView.h +++ b/widget/cocoa/nsChildView.h @@ -473,7 +473,6 @@ public: already_AddRefed GetDocumentAccessible(); #endif - virtual CompositorParent* NewCompositorParent(int aSurfaceWidth, int aSurfaceHeight); virtual void CreateCompositor(); virtual void PrepareWindowEffects() MOZ_OVERRIDE; virtual void CleanupWindowEffects() MOZ_OVERRIDE; @@ -528,7 +527,7 @@ public: void EndRemoteDrawing() MOZ_OVERRIDE; void CleanupRemoteDrawing() MOZ_OVERRIDE; - APZCTreeManager* APZCTM() { return mAPZCTreeManager; } + APZCTreeManager* APZCTM() { return mAPZC ; } protected: virtual ~nsChildView(); @@ -549,6 +548,9 @@ protected: return widget.forget(); } + void ConfigureAPZCTreeManager() MOZ_OVERRIDE; + already_AddRefed CreateRootContentController() MOZ_OVERRIDE; + void DoRemoteComposition(const nsIntRect& aRenderRect); // Overlay drawing functions for OpenGL drawing @@ -629,8 +631,6 @@ protected: // surface to the screen using an OpenGL context. nsAutoPtr mGLPresenter; - nsRefPtr mAPZCTreeManager; - mozilla::UniquePtr mVibrancyManager; static uint32_t sLastInputEventCount; diff --git a/widget/cocoa/nsChildView.mm b/widget/cocoa/nsChildView.mm index 87fe5c21757..0d3a6dcccc8 100644 --- a/widget/cocoa/nsChildView.mm +++ b/widget/cocoa/nsChildView.mm @@ -475,7 +475,7 @@ nsChildView::~nsChildView() DestroyCompositor(); - if (mAPZCTreeManager) { + if (mAPZC) { gNumberOfWidgetsNeedingEventThread--; if (gNumberOfWidgetsNeedingEventThread == 0) { [EventThreadRunner stop]; @@ -1884,25 +1884,22 @@ nsChildView::CreateCompositor() } } -CompositorParent* -nsChildView::NewCompositorParent(int aSurfaceWidth, int aSurfaceHeight) +already_AddRefed +nsChildView::CreateRootContentController() { - CompositorParent *compositor = nsBaseWidget::NewCompositorParent(aSurfaceWidth, aSurfaceHeight); + nsRefPtr controller = new APZCTMController(); + return controller.forget(); +} - if (gfxPrefs::AsyncPanZoomEnabled()) { - uint64_t rootLayerTreeId = compositor->RootLayerTreeId(); - nsRefPtr controller = new APZCTMController(); - CompositorParent::SetControllerForLayerTree(rootLayerTreeId, controller); - mAPZCTreeManager = CompositorParent::GetAPZCTreeManager(rootLayerTreeId); - mAPZCTreeManager->SetDPI(GetDPI()); +void +nsChildView::ConfigureAPZCTreeManager() +{ + nsBaseWidget::ConfigureAPZCTreeManager(); - if (gNumberOfWidgetsNeedingEventThread == 0) { - [EventThreadRunner start]; - } - gNumberOfWidgetsNeedingEventThread++; + if (gNumberOfWidgetsNeedingEventThread == 0) { + [EventThreadRunner start]; } - - return compositor; + gNumberOfWidgetsNeedingEventThread++; } nsIntRect diff --git a/widget/gonk/nsWindow.cpp b/widget/gonk/nsWindow.cpp index b660783ab40..31cd75d53bf 100644 --- a/widget/gonk/nsWindow.cpp +++ b/widget/gonk/nsWindow.cpp @@ -610,15 +610,19 @@ nsWindow::GetLayerManager(PLayerTransactionChild* aShadowManager, 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; } +already_AddRefed +nsWindow::CreateRootContentController() +{ + nsRefPtr controller = new ParentProcessController(); + return controller.forget(); +} + void nsWindow::BringToTop() { diff --git a/widget/gonk/nsWindow.h b/widget/gonk/nsWindow.h index 22aa47287c6..4b55e55c6ae 100644 --- a/widget/gonk/nsWindow.h +++ b/widget/gonk/nsWindow.h @@ -120,6 +120,10 @@ public: virtual Composer2D* GetComposer2D() MOZ_OVERRIDE; +protected: + // nsBaseWidget + already_AddRefed CreateRootContentController() MOZ_OVERRIDE; + protected: nsWindow* mParent; bool mVisible; diff --git a/widget/nsBaseWidget.cpp b/widget/nsBaseWidget.cpp index 0268facedab..5ca2be7f21e 100644 --- a/widget/nsBaseWidget.cpp +++ b/widget/nsBaseWidget.cpp @@ -43,6 +43,7 @@ #include "mozilla/MouseEvents.h" #include "GLConsts.h" #include "mozilla/unused.h" +#include "mozilla/layers/APZCTreeManager.h" #ifdef ACCESSIBILITY #include "nsAccessibilityService.h" @@ -911,6 +912,26 @@ void nsBaseWidget::CreateCompositor() CreateCompositor(rect.width, rect.height); } +already_AddRefed +nsBaseWidget::CreateRootContentController() +{ + return nullptr; +} + +void nsBaseWidget::ConfigureAPZCTreeManager() +{ + uint64_t rootLayerTreeId = mCompositorParent->RootLayerTreeId(); + mAPZC = CompositorParent::GetAPZCTreeManager(rootLayerTreeId); + MOZ_ASSERT(mAPZC); + + mAPZC->SetDPI(GetDPI()); + + nsRefPtr controller = CreateRootContentController(); + if (controller) { + CompositorParent::SetControllerForLayerTree(rootLayerTreeId, controller); + } +} + void nsBaseWidget::GetPreferredCompositorBackends(nsTArray& aHints) { @@ -945,6 +966,10 @@ void nsBaseWidget::CreateCompositor(int aWidth, int aHeight) mCompositorChild = new CompositorChild(lm); mCompositorChild->Open(parentChannel, childMessageLoop, ipc::ChildSide); + if (gfxPrefs::AsyncPanZoomEnabled()) { + ConfigureAPZCTreeManager(); + } + TextureFactoryIdentifier textureFactoryIdentifier; PLayerTransactionChild* shadowManager = nullptr; nsTArray backendHints; diff --git a/widget/nsBaseWidget.h b/widget/nsBaseWidget.h index 882cbca0d30..3a1cb6f4c52 100644 --- a/widget/nsBaseWidget.h +++ b/widget/nsBaseWidget.h @@ -34,6 +34,8 @@ namespace layers { class BasicLayerManager; class CompositorChild; class CompositorParent; +class APZCTreeManager; +class GeckoContentController; } } @@ -82,6 +84,8 @@ protected: 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::ScreenRotation ScreenRotation; virtual ~nsBaseWidget(); @@ -300,6 +304,9 @@ protected: nsDeviceContext *aContext, nsWidgetInitData *aInitData); + virtual void ConfigureAPZCTreeManager(); + virtual already_AddRefed CreateRootContentController(); + const nsIntRegion RegionFromArray(const nsTArray& aRects); void ArrayFromRegion(const nsIntRegion& aRegion, nsTArray& aRects); @@ -407,6 +414,7 @@ protected: nsRefPtr mBasicLayerManager; nsRefPtr mCompositorChild; nsRefPtr mCompositorParent; + nsRefPtr mAPZC; nsRefPtr mShutdownObserver; nsCursor mCursor; bool mUpdateCursor; diff --git a/widget/windows/nsWindow.cpp b/widget/windows/nsWindow.cpp index 2b7eaad66ce..4a117a28e4e 100644 --- a/widget/windows/nsWindow.cpp +++ b/widget/windows/nsWindow.cpp @@ -186,7 +186,7 @@ #define SM_CONVERTIBLESLATEMODE 0x2003 #endif -#include "mozilla/layers/CompositorParent.h" +#include "mozilla/layers/APZCTreeManager.h" using namespace mozilla; using namespace mozilla::dom; @@ -7666,19 +7666,6 @@ void nsWindow::PickerClosed() } } -CompositorParent* nsWindow::NewCompositorParent(int aSurfaceWidth, - int aSurfaceHeight) -{ - CompositorParent *compositor = new CompositorParent(this, false, aSurfaceWidth, aSurfaceHeight); - - if (gfxPrefs::AsyncPanZoomEnabled()) { - mAPZC = CompositorParent::GetAPZCTreeManager(compositor->RootLayerTreeId()); - APZCTreeManager::SetDPI(GetDPI()); - } - - return compositor; -} - /************************************************************** ************************************************************** ** diff --git a/widget/windows/nsWindow.h b/widget/windows/nsWindow.h index b9b36e57de7..31c760e7e89 100644 --- a/widget/windows/nsWindow.h +++ b/widget/windows/nsWindow.h @@ -42,7 +42,6 @@ #include "nsUXThemeData.h" #include "nsIDOMMouseEvent.h" #include "nsIIdleServiceInternal.h" -#include "mozilla/layers/APZCTreeManager.h" /** * Forward class definitions @@ -74,7 +73,6 @@ class nsWindow : public nsWindowBase typedef mozilla::widget::TaskbarWindowPreview TaskbarWindowPreview; typedef mozilla::widget::NativeKey NativeKey; typedef mozilla::widget::MSGResult MSGResult; - typedef mozilla::layers::APZCTreeManager APZCTreeManager; public: nsWindow(); @@ -91,7 +89,6 @@ public: virtual bool DispatchScrollEvent(mozilla::WidgetGUIEvent* aEvent) MOZ_OVERRIDE; virtual nsWindowBase* GetParentWindowBase(bool aIncludeOwner) MOZ_OVERRIDE; virtual bool IsTopLevelWidget() MOZ_OVERRIDE { return mIsTopWidgetWindow; } - virtual CompositorParent* NewCompositorParent(int aSurfaceWidth, int aSurfaceHeight) MOZ_OVERRIDE; // nsIWidget interface NS_IMETHOD Create(nsIWidget *aParent, @@ -593,8 +590,6 @@ protected: static bool sNeedsToInitMouseWheelSettings; static void InitMouseWheelScrollData(); - - nsRefPtr mAPZC; }; /** diff --git a/widget/windows/winrt/MetroWidget.cpp b/widget/windows/winrt/MetroWidget.cpp index 6c8e8a621eb..978f8aa0b3b 100644 --- a/widget/windows/winrt/MetroWidget.cpp +++ b/widget/windows/winrt/MetroWidget.cpp @@ -1032,30 +1032,27 @@ MetroWidget::SetWidgetListener(nsIWidgetListener* aWidgetListener) mWidgetListener = aWidgetListener; } -CompositorParent* MetroWidget::NewCompositorParent(int aSurfaceWidth, int aSurfaceHeight) +void +MetroWidget::ConfigureAPZCTreeManager() { - CompositorParent *compositor = nsBaseWidget::NewCompositorParent(aSurfaceWidth, aSurfaceHeight); + nsBaseWidget::ConfigureAPZCTreeManager(); - if (ShouldUseAPZC()) { - mRootLayerTreeId = compositor->RootLayerTreeId(); - - mController = new APZController(); - - CompositorParent::SetControllerForLayerTree(mRootLayerTreeId, mController); - - APZController::sAPZC = CompositorParent::GetAPZCTreeManager(compositor->RootLayerTreeId()); - APZController::sAPZC->SetDPI(GetDPI()); - - nsresult rv; - nsCOMPtr observerService = do_GetService("@mozilla.org/observer-service;1", &rv); - if (NS_SUCCEEDED(rv)) { - observerService->AddObserver(this, "apzc-scroll-offset-changed", false); - observerService->AddObserver(this, "apzc-zoom-to-rect", false); - observerService->AddObserver(this, "apzc-disable-zoom", false); - } + nsresult rv; + nsCOMPtr observerService = do_GetService("@mozilla.org/observer-service;1", &rv); + if (NS_SUCCEEDED(rv)) { + observerService->AddObserver(this, "apzc-scroll-offset-changed", false); + observerService->AddObserver(this, "apzc-zoom-to-rect", false); + observerService->AddObserver(this, "apzc-disable-zoom", false); } +} - return compositor; +already_AddRefed +MetroWidget::CreateRootContentController() +{ + MOZ_ASSERT(!mController); + + mController = new APZController(); + return mController; } MetroWidget::TouchBehaviorFlags diff --git a/widget/windows/winrt/MetroWidget.h b/widget/windows/winrt/MetroWidget.h index c483097f58d..5ce0dc3ade6 100644 --- a/widget/windows/winrt/MetroWidget.h +++ b/widget/windows/winrt/MetroWidget.h @@ -89,7 +89,6 @@ public: nsIntPoint* aPoint = nullptr) MOZ_OVERRIDE; // nsBaseWidget - virtual CompositorParent* NewCompositorParent(int aSurfaceWidth, int aSurfaceHeight); virtual void SetWidgetListener(nsIWidgetListener* aWidgetListener); // nsIWidget interface @@ -246,6 +245,10 @@ protected: } }; + // nsBaseWidget + void ConfigureAPZCTreeManager() MOZ_OVERRIDE; + already_AddRefed NewRootContentController() MOZ_OVERRIDE; + void SetSubclass(); void RemoveSubclass(); nsIWidgetListener* GetPaintListener();