From 54c54c7a09ec5e62ceaa83a3fad325944b613714 Mon Sep 17 00:00:00 2001 From: Kartikaya Gupta Date: Mon, 7 Nov 2016 21:16:52 -0500 Subject: [PATCH] Bug 1315706 - Pass a wrapper struct to various CompositorWidget functions. r=dvander This is the first step in using these functions without having a LayerManagerComposite at all. MozReview-Commit-ID: 2zkuB7Ox4Ut --HG-- extra : rebase_source : b23988275f5851a2fd30bd3e8a9931107a224c66 --- .../composite/LayerManagerComposite.cpp | 18 ++++++++++++----- widget/CompositorWidget.h | 20 +++++++++++++++---- widget/InProcessCompositorWidget.cpp | 20 +++++++++---------- widget/InProcessCompositorWidget.h | 8 ++++---- widget/android/nsWindow.cpp | 8 ++++---- widget/android/nsWindow.h | 8 +++++--- widget/cocoa/nsChildView.h | 7 ++++--- widget/cocoa/nsChildView.mm | 13 ++++++------ widget/nsBaseWidget.h | 9 +++++---- widget/windows/WinCompositorWidget.cpp | 4 ++-- widget/windows/WinCompositorWidget.h | 4 ++-- 11 files changed, 72 insertions(+), 47 deletions(-) diff --git a/gfx/layers/composite/LayerManagerComposite.cpp b/gfx/layers/composite/LayerManagerComposite.cpp index a55ffff4b8d4..85c82ca503fd 100644 --- a/gfx/layers/composite/LayerManagerComposite.cpp +++ b/gfx/layers/composite/LayerManagerComposite.cpp @@ -42,6 +42,7 @@ #include "mozilla/layers/Effects.h" // for Effect, EffectChain, etc #include "mozilla/layers/LayerMetricsWrapper.h" // for LayerMetricsWrapper #include "mozilla/layers/LayersTypes.h" // for etc +#include "mozilla/widget/CompositorWidget.h" // for WidgetRenderingContext #include "ipc/CompositorBench.h" // for CompositorBench #include "ipc/ShadowLayerUtils.h" #include "mozilla/mozalloc.h" // for operator new, etc @@ -911,11 +912,18 @@ LayerManagerComposite::Render(const nsIntRegion& aInvalidRegion, const nsIntRegi mLastFrameMissedHWC = !!composer2D; } + mozilla::widget::WidgetRenderingContext widgetContext; +#if defined(XP_MACOSX) + widgetContext.mLayerManager = this; +#elif defined(MOZ_WIDGET_ANDROID) + widgetContext.mCompositor = GetCompositor(); +#endif + { PROFILER_LABEL("LayerManagerComposite", "PreRender", js::ProfileEntry::Category::GRAPHICS); - if (!mCompositor->GetWidget()->PreRender(this)) { + if (!mCompositor->GetWidget()->PreRender(&widgetContext)) { return; } } @@ -946,13 +954,13 @@ LayerManagerComposite::Render(const nsIntRegion& aInvalidRegion, const nsIntRegi } if (actualBounds.IsEmpty()) { - mCompositor->GetWidget()->PostRender(this); + mCompositor->GetWidget()->PostRender(&widgetContext); return; } // Allow widget to render a custom background. mCompositor->GetWidget()->DrawWindowUnderlay( - this, LayoutDeviceIntRect::FromUnknownRect(actualBounds)); + &widgetContext, LayoutDeviceIntRect::FromUnknownRect(actualBounds)); RefPtr previousTarget; if (haveLayerEffects) { @@ -980,7 +988,7 @@ LayerManagerComposite::Render(const nsIntRegion& aInvalidRegion, const nsIntRegi // Allow widget to render a custom foreground. mCompositor->GetWidget()->DrawWindowOverlay( - this, LayoutDeviceIntRect::FromUnknownRect(actualBounds)); + &widgetContext, LayoutDeviceIntRect::FromUnknownRect(actualBounds)); // Debugging RenderDebugOverlay(actualBounds); @@ -999,7 +1007,7 @@ LayerManagerComposite::Render(const nsIntRegion& aInvalidRegion, const nsIntRegi composer2D->Render(mCompositor->GetWidget()->RealWidget()); } - mCompositor->GetWidget()->PostRender(this); + mCompositor->GetWidget()->PostRender(&widgetContext); RecordFrame(); } diff --git a/widget/CompositorWidget.h b/widget/CompositorWidget.h index d409faa1f342..93269eac684d 100644 --- a/widget/CompositorWidget.h +++ b/widget/CompositorWidget.h @@ -53,6 +53,18 @@ class CompositorWidgetChild; # define MOZ_WIDGET_SUPPORTS_OOP_COMPOSITING #endif +class WidgetRenderingContext +{ +public: +#if defined(XP_MACOSX) + WidgetRenderingContext() : mLayerManager(nullptr) {} + layers::LayerManagerComposite* mLayerManager; +#elif defined(MOZ_WIDGET_ANDROID) + WidgetRenderingContext() : mCompositor(nullptr) {} + layers::Compositor* mCompositor; +#endif +}; + /** * Access to a widget from the compositor is restricted to these methods. */ @@ -74,7 +86,7 @@ public: * Always called from the compositing thread, which may be the main-thread if * OMTC is not enabled. */ - virtual bool PreRender(layers::LayerManagerComposite* aManager) { + virtual bool PreRender(WidgetRenderingContext* aContext) { return true; } @@ -85,7 +97,7 @@ public: * Always called from the compositing thread, which may be the main-thread if * OMTC is not enabled. */ - virtual void PostRender(layers::LayerManagerComposite* aManager) + virtual void PostRender(WidgetRenderingContext* aContext) {} /** @@ -93,7 +105,7 @@ public: * * Always called from the compositing thread. */ - virtual void DrawWindowUnderlay(layers::LayerManagerComposite* aManager, + virtual void DrawWindowUnderlay(WidgetRenderingContext* aContext, LayoutDeviceIntRect aRect) {} @@ -102,7 +114,7 @@ public: * * Always called from the compositing thread. */ - virtual void DrawWindowOverlay(layers::LayerManagerComposite* aManager, + virtual void DrawWindowOverlay(WidgetRenderingContext* aContext, LayoutDeviceIntRect aRect) {} diff --git a/widget/InProcessCompositorWidget.cpp b/widget/InProcessCompositorWidget.cpp index e67518570fe6..9b301fc48203 100644 --- a/widget/InProcessCompositorWidget.cpp +++ b/widget/InProcessCompositorWidget.cpp @@ -33,29 +33,29 @@ InProcessCompositorWidget::InProcessCompositorWidget(nsBaseWidget* aWidget) } bool -InProcessCompositorWidget::PreRender(layers::LayerManagerComposite* aManager) +InProcessCompositorWidget::PreRender(WidgetRenderingContext* aContext) { - return mWidget->PreRender(aManager); + return mWidget->PreRender(aContext); } void -InProcessCompositorWidget::PostRender(layers::LayerManagerComposite* aManager) +InProcessCompositorWidget::PostRender(WidgetRenderingContext* aContext) { - mWidget->PostRender(aManager); + mWidget->PostRender(aContext); } void -InProcessCompositorWidget::DrawWindowUnderlay(layers::LayerManagerComposite* aManager, - LayoutDeviceIntRect aRect) +InProcessCompositorWidget::DrawWindowUnderlay(WidgetRenderingContext* aContext, + LayoutDeviceIntRect aRect) { - mWidget->DrawWindowUnderlay(aManager, aRect); + mWidget->DrawWindowUnderlay(aContext, aRect); } void -InProcessCompositorWidget::DrawWindowOverlay(layers::LayerManagerComposite* aManager, - LayoutDeviceIntRect aRect) +InProcessCompositorWidget::DrawWindowOverlay(WidgetRenderingContext* aContext, + LayoutDeviceIntRect aRect) { - mWidget->DrawWindowOverlay(aManager, aRect); + mWidget->DrawWindowOverlay(aContext, aRect); } already_AddRefed diff --git a/widget/InProcessCompositorWidget.h b/widget/InProcessCompositorWidget.h index 841045840aa2..ae9e51b3b106 100644 --- a/widget/InProcessCompositorWidget.h +++ b/widget/InProcessCompositorWidget.h @@ -17,11 +17,11 @@ class InProcessCompositorWidget : public CompositorWidget public: explicit InProcessCompositorWidget(nsBaseWidget* aWidget); - virtual bool PreRender(layers::LayerManagerComposite* aManager) override; - virtual void PostRender(layers::LayerManagerComposite* aManager) override; - virtual void DrawWindowUnderlay(layers::LayerManagerComposite* aManager, + virtual bool PreRender(WidgetRenderingContext* aManager) override; + virtual void PostRender(WidgetRenderingContext* aManager) override; + virtual void DrawWindowUnderlay(WidgetRenderingContext* aContext, LayoutDeviceIntRect aRect) override; - virtual void DrawWindowOverlay(layers::LayerManagerComposite* aManager, + virtual void DrawWindowOverlay(WidgetRenderingContext* aContext, LayoutDeviceIntRect aRect) override; virtual already_AddRefed StartRemoteDrawing() override; virtual already_AddRefed diff --git a/widget/android/nsWindow.cpp b/widget/android/nsWindow.cpp index 09f75220ef13..6680d11d8fc7 100644 --- a/widget/android/nsWindow.cpp +++ b/widget/android/nsWindow.cpp @@ -3462,13 +3462,13 @@ nsWindow::SynthesizeNativeMouseMove(LayoutDeviceIntPoint aPoint, } bool -nsWindow::PreRender(LayerManagerComposite* aManager) +nsWindow::PreRender(WidgetRenderingContext* aContext) { if (Destroyed()) { return true; } - layers::Compositor* compositor = aManager->GetCompositor(); + layers::Compositor* compositor = aContext->mCompositor; GeckoLayerClient::LocalRef client; @@ -3484,7 +3484,7 @@ nsWindow::PreRender(LayerManagerComposite* aManager) return true; } void -nsWindow::DrawWindowUnderlay(LayerManagerComposite* aManager, +nsWindow::DrawWindowUnderlay(WidgetRenderingContext* aContext, LayoutDeviceIntRect aRect) { if (Destroyed()) { @@ -3515,7 +3515,7 @@ nsWindow::DrawWindowUnderlay(LayerManagerComposite* aManager, } void -nsWindow::DrawWindowOverlay(LayerManagerComposite* aManager, +nsWindow::DrawWindowOverlay(WidgetRenderingContext* aContext, LayoutDeviceIntRect aRect) { PROFILER_LABEL("nsWindow", "DrawWindowOverlay", diff --git a/widget/android/nsWindow.h b/widget/android/nsWindow.h index fee41026bd2a..f3d7566f76a7 100644 --- a/widget/android/nsWindow.h +++ b/widget/android/nsWindow.h @@ -204,9 +204,11 @@ public: LayerManagerPersistence aPersistence = LAYER_MANAGER_CURRENT) override; virtual bool NeedsPaint() override; - virtual bool PreRender(LayerManagerComposite* aManager) override; - virtual void DrawWindowUnderlay(LayerManagerComposite* aManager, LayoutDeviceIntRect aRect) override; - virtual void DrawWindowOverlay(LayerManagerComposite* aManager, LayoutDeviceIntRect aRect) override; + virtual bool PreRender(mozilla::widget::WidgetRenderingContext* aContext) override; + virtual void DrawWindowUnderlay(mozilla::widget::WidgetRenderingContext* aContext, + LayoutDeviceIntRect aRect) override; + virtual void DrawWindowOverlay(mozilla::widget::WidgetRenderingContext* aContext, + LayoutDeviceIntRect aRect) override; virtual bool WidgetPaintsBackground() override; diff --git a/widget/cocoa/nsChildView.h b/widget/cocoa/nsChildView.h index 94bbc27c7ef3..f0655b129dce 100644 --- a/widget/cocoa/nsChildView.h +++ b/widget/cocoa/nsChildView.h @@ -52,6 +52,7 @@ class IAPZCTreeManager; } // namespace layers namespace widget { class RectTextureImage; +class WidgetRenderingContext; } // namespace widget } // namespace mozilla @@ -441,9 +442,9 @@ public: virtual void CreateCompositor() override; virtual void PrepareWindowEffects() override; virtual void CleanupWindowEffects() override; - virtual bool PreRender(LayerManagerComposite* aManager) override; - virtual void PostRender(LayerManagerComposite* aManager) override; - virtual void DrawWindowOverlay(LayerManagerComposite* aManager, + virtual bool PreRender(mozilla::widget::WidgetRenderingContext* aContext) override; + virtual void PostRender(mozilla::widget::WidgetRenderingContext* aContext) override; + virtual void DrawWindowOverlay(mozilla::widget::WidgetRenderingContext* aManager, LayoutDeviceIntRect aRect) override; virtual void UpdateThemeGeometries(const nsTArray& aThemeGeometries) override; diff --git a/widget/cocoa/nsChildView.mm b/widget/cocoa/nsChildView.mm index 4bb72c47b374..cf5ec0f17110 100644 --- a/widget/cocoa/nsChildView.mm +++ b/widget/cocoa/nsChildView.mm @@ -67,6 +67,7 @@ #include "mozilla/layers/CompositorBridgeParent.h" #include "mozilla/layers/BasicCompositor.h" #include "mozilla/layers/InputAPZContext.h" +#include "mozilla/widget/CompositorWidget.h" #include "gfxUtils.h" #include "gfxPrefs.h" #include "mozilla/gfx/2D.h" @@ -2019,9 +2020,9 @@ nsChildView::CleanupWindowEffects() } bool -nsChildView::PreRender(LayerManagerComposite* aManager) +nsChildView::PreRender(WidgetRenderingContext* aContext) { - UniquePtr manager(GLManager::CreateGLManager(aManager)); + UniquePtr manager(GLManager::CreateGLManager(aContext->mLayerManager)); if (!manager) { return true; } @@ -2041,9 +2042,9 @@ nsChildView::PreRender(LayerManagerComposite* aManager) } void -nsChildView::PostRender(LayerManagerComposite* aManager) +nsChildView::PostRender(WidgetRenderingContext* aContext) { - UniquePtr manager(GLManager::CreateGLManager(aManager)); + UniquePtr manager(GLManager::CreateGLManager(aContext->mLayerManager)); if (!manager) { return; } @@ -2053,10 +2054,10 @@ nsChildView::PostRender(LayerManagerComposite* aManager) } void -nsChildView::DrawWindowOverlay(LayerManagerComposite* aManager, +nsChildView::DrawWindowOverlay(WidgetRenderingContext* aContext, LayoutDeviceIntRect aRect) { - mozilla::UniquePtr manager(GLManager::CreateGLManager(aManager)); + mozilla::UniquePtr manager(GLManager::CreateGLManager(aContext->mLayerManager)); if (manager) { DrawWindowOverlay(manager.get(), aRect); } diff --git a/widget/nsBaseWidget.h b/widget/nsBaseWidget.h index b5bcfe3a774d..15964e4d2310 100644 --- a/widget/nsBaseWidget.h +++ b/widget/nsBaseWidget.h @@ -63,6 +63,7 @@ struct ScrollableLayerGuid; namespace widget { class CompositorWidgetDelegate; class InProcessCompositorWidget; +class WidgetRenderingContext; } // namespace widget class CompositorVsyncDispatcher; @@ -391,15 +392,15 @@ protected: // These are methods for CompositorWidgetWrapper, and should only be // accessed from that class. Derived widgets can choose which methods to // implement, or none if supporting out-of-process compositing. - virtual bool PreRender(mozilla::layers::LayerManagerComposite* aManager) { + virtual bool PreRender(mozilla::widget::WidgetRenderingContext* aContext) { return true; } - virtual void PostRender(mozilla::layers::LayerManagerComposite* aManager) + virtual void PostRender(mozilla::widget::WidgetRenderingContext* aContext) {} - virtual void DrawWindowUnderlay(mozilla::layers::LayerManagerComposite* aManager, + virtual void DrawWindowUnderlay(mozilla::widget::WidgetRenderingContext* aContext, LayoutDeviceIntRect aRect) {} - virtual void DrawWindowOverlay(mozilla::layers::LayerManagerComposite* aManager, + virtual void DrawWindowOverlay(mozilla::widget::WidgetRenderingContext* aContext, LayoutDeviceIntRect aRect) {} virtual already_AddRefed StartRemoteDrawing(); diff --git a/widget/windows/WinCompositorWidget.cpp b/widget/windows/WinCompositorWidget.cpp index aa2f155e87e9..6ac9676fc342 100644 --- a/widget/windows/WinCompositorWidget.cpp +++ b/widget/windows/WinCompositorWidget.cpp @@ -44,7 +44,7 @@ WinCompositorWidget::OnDestroyWindow() } bool -WinCompositorWidget::PreRender(layers::LayerManagerComposite* aManager) +WinCompositorWidget::PreRender(WidgetRenderingContext* aContext) { // This can block waiting for WM_SETTEXT to finish // Using PreRender is unnecessarily pessimistic because @@ -55,7 +55,7 @@ WinCompositorWidget::PreRender(layers::LayerManagerComposite* aManager) } void -WinCompositorWidget::PostRender(layers::LayerManagerComposite* aManager) +WinCompositorWidget::PostRender(WidgetRenderingContext* aContext) { mPresentLock.Leave(); } diff --git a/widget/windows/WinCompositorWidget.h b/widget/windows/WinCompositorWidget.h index f7dd1ae40c1e..9661cab4584d 100644 --- a/widget/windows/WinCompositorWidget.h +++ b/widget/windows/WinCompositorWidget.h @@ -45,8 +45,8 @@ class WinCompositorWidget public: WinCompositorWidget(const CompositorWidgetInitData& aInitData); - bool PreRender(layers::LayerManagerComposite*) override; - void PostRender(layers::LayerManagerComposite*) override; + bool PreRender(WidgetRenderingContext*) override; + void PostRender(WidgetRenderingContext*) override; already_AddRefed StartRemoteDrawing() override; void EndRemoteDrawing() override; bool NeedsToDeferEndRemoteDrawing() override;