diff --git a/gfx/ipc/CompositorSession.cpp b/gfx/ipc/CompositorSession.cpp index a12f9ceee077..be70f56dc6ec 100644 --- a/gfx/ipc/CompositorSession.cpp +++ b/gfx/ipc/CompositorSession.cpp @@ -33,12 +33,12 @@ private: }; already_AddRefed -CompositorSession::CreateTopLevel(widget::CompositorWidgetProxy* aWidgetProxy, - ClientLayerManager* aLayerManager, - CSSToLayoutDeviceScale aScale, - bool aUseAPZ, - bool aUseExternalSurfaceSize, - int aSurfaceWidth, int aSurfaceHeight) +CompositorSession::CreateInProcess(widget::CompositorWidgetProxy* aWidgetProxy, + ClientLayerManager* aLayerManager, + CSSToLayoutDeviceScale aScale, + bool aUseAPZ, + bool aUseExternalSurfaceSize, + int aSurfaceWidth, int aSurfaceHeight) { RefPtr session = new InProcessCompositorSession( aWidgetProxy, diff --git a/gfx/ipc/CompositorSession.h b/gfx/ipc/CompositorSession.h index 0e203349b022..e592142695c4 100644 --- a/gfx/ipc/CompositorSession.h +++ b/gfx/ipc/CompositorSession.h @@ -14,6 +14,9 @@ namespace mozilla { namespace widget { class CompositorWidgetProxy; } // namespace widget +namespace gfx { +class GPUProcessManager; +} // namespace gfx namespace layers { class GeckoContentController; @@ -26,17 +29,11 @@ class ClientLayerManager; // or not it's in-process or out-of-process. class CompositorSession { + friend class gfx::GPUProcessManager; + public: NS_INLINE_DECL_THREADSAFE_REFCOUNTING(CompositorSession) - static already_AddRefed CreateTopLevel( - widget::CompositorWidgetProxy* aWidgetProxy, - ClientLayerManager* aLayerManager, - CSSToLayoutDeviceScale aScale, - bool aUseAPZ, - bool aUseExternalSurfaceSize, - int aSurfaceWidth, int aSurfaceHeight); - virtual void Shutdown() = 0; // This returns a CompositorBridgeParent if the compositor resides in the same process. @@ -58,6 +55,14 @@ protected: CompositorSession(); virtual ~CompositorSession(); + static already_AddRefed CreateInProcess( + widget::CompositorWidgetProxy* aWidgetProxy, + ClientLayerManager* aLayerManager, + CSSToLayoutDeviceScale aScale, + bool aUseAPZ, + bool aUseExternalSurfaceSize, + int aSurfaceWidth, int aSurfaceHeight); + protected: RefPtr mCompositorBridgeChild; diff --git a/gfx/ipc/GPUProcessManager.cpp b/gfx/ipc/GPUProcessManager.cpp new file mode 100644 index 000000000000..fbc2f6040eca --- /dev/null +++ b/gfx/ipc/GPUProcessManager.cpp @@ -0,0 +1,64 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=99: */ +/* 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 "GPUProcessManager.h" +#include "mozilla/layers/CompositorSession.h" +#include "mozilla/StaticPtr.h" + +namespace mozilla { +namespace gfx { + +using namespace mozilla::layers; + +static StaticAutoPtr sSingleton; + +GPUProcessManager* +GPUProcessManager::Get() +{ + MOZ_ASSERT(sSingleton); + return sSingleton; +} + +void +GPUProcessManager::Initialize() +{ + sSingleton = new GPUProcessManager(); +} + +void +GPUProcessManager::Shutdown() +{ + sSingleton = nullptr; +} + +GPUProcessManager::GPUProcessManager() +{ +} + +GPUProcessManager::~GPUProcessManager() +{ +} + +already_AddRefed +GPUProcessManager::CreateTopLevelCompositor(widget::CompositorWidgetProxy* aProxy, + ClientLayerManager* aLayerManager, + CSSToLayoutDeviceScale aScale, + bool aUseAPZ, + bool aUseExternalSurfaceSize, + int aSurfaceWidth, + int aSurfaceHeight) +{ + return CompositorSession::CreateInProcess( + aProxy, + aLayerManager, + aScale, + aUseAPZ, + aUseExternalSurfaceSize, + aSurfaceWidth, + aSurfaceHeight); +} + +} // namespace gfx +} // namespace mozilla diff --git a/gfx/ipc/GPUProcessManager.h b/gfx/ipc/GPUProcessManager.h new file mode 100644 index 000000000000..709fc5d0a6a0 --- /dev/null +++ b/gfx/ipc/GPUProcessManager.h @@ -0,0 +1,52 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=99: */ +/* 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 _include_mozilla_gfx_ipc_GPUProcessManager_h_ +#define _include_mozilla_gfx_ipc_GPUProcessManager_h_ + +#include "base/basictypes.h" +#include "Units.h" + +namespace mozilla { +namespace layers { +class CompositorSession; +class ClientLayerManager; +} // namespace layers +namespace widget { +class CompositorWidgetProxy; +} // namespace widget +namespace gfx { + +// The GPUProcessManager is a singleton responsible for creating GPU-bound +// objects that may live in another process. Currently, it provides access +// to the compositor via CompositorBridgeParent. +class GPUProcessManager final +{ +public: + static void Initialize(); + static void Shutdown(); + static GPUProcessManager* Get(); + + ~GPUProcessManager(); + + already_AddRefed CreateTopLevelCompositor( + widget::CompositorWidgetProxy* aProxy, + layers::ClientLayerManager* aLayerManager, + CSSToLayoutDeviceScale aScale, + bool aUseAPZ, + bool aUseExternalSurfaceSize, + int aSurfaceWidth, + int aSurfaceHeight); + +private: + GPUProcessManager(); + + DISALLOW_COPY_AND_ASSIGN(GPUProcessManager); +}; + +} // namespace gfx +} // namespace mozilla + +#endif // _include_mozilla_gfx_ipc_GPUProcessManager_h_ diff --git a/gfx/ipc/moz.build b/gfx/ipc/moz.build index 2172003967e7..9c3ed5ffb267 100644 --- a/gfx/ipc/moz.build +++ b/gfx/ipc/moz.build @@ -10,6 +10,7 @@ EXPORTS.mozilla += [ ] EXPORTS.mozilla.gfx += [ + 'GPUProcessManager.h', 'SharedDIB.h', ] @@ -30,6 +31,7 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'windows': UNIFIED_SOURCES += [ 'CompositorSession.cpp', 'D3DMessageUtils.cpp', + 'GPUProcessManager.cpp', 'SharedDIB.cpp', ] diff --git a/gfx/thebes/gfxPlatform.cpp b/gfx/thebes/gfxPlatform.cpp index dd1baab73d35..a9d543b094fc 100644 --- a/gfx/thebes/gfxPlatform.cpp +++ b/gfx/thebes/gfxPlatform.cpp @@ -9,6 +9,7 @@ #include "mozilla/layers/ImageBridgeChild.h" #include "mozilla/layers/SharedBufferManagerChild.h" #include "mozilla/layers/ISurfaceAllocator.h" // for GfxMemoryImageReporter +#include "mozilla/gfx/GPUProcessManager.h" #include "mozilla/ClearOnShutdown.h" #include "mozilla/Telemetry.h" #include "mozilla/TimeStamp.h" @@ -591,6 +592,8 @@ gfxPlatform::Init() gfxPrefs::GetSingleton(); MediaPrefs::GetSingleton(); + GPUProcessManager::Initialize(); + auto fwd = new CrashStatsLogForwarder("GraphicsCriticalError"); fwd->SetCircularBufferSize(gfxPrefs::GfxLoggingCrashLength()); @@ -839,6 +842,8 @@ gfxPlatform::Shutdown() GLContextProviderEGL::Shutdown(); #endif + GPUProcessManager::Shutdown(); + // This is a bit iffy - we're assuming that we were the ones that set the // log forwarder in the Factory, so that it's our responsibility to // delete it. diff --git a/widget/nsBaseWidget.cpp b/widget/nsBaseWidget.cpp index 08fab47eeb93..1dac6a2b4a6d 100644 --- a/widget/nsBaseWidget.cpp +++ b/widget/nsBaseWidget.cpp @@ -58,6 +58,7 @@ #include "mozilla/layers/APZCCallbackHelper.h" #include "mozilla/dom/ContentChild.h" #include "mozilla/dom/TabParent.h" +#include "mozilla/gfx/GPUProcessManager.h" #include "mozilla/Move.h" #include "mozilla/Services.h" #include "mozilla/Snprintf.h" @@ -1284,7 +1285,8 @@ void nsBaseWidget::CreateCompositor(int aWidth, int aHeight) RefPtr lm = new ClientLayerManager(this); - mCompositorSession = CompositorSession::CreateTopLevel( + gfx::GPUProcessManager* gpu = gfx::GPUProcessManager::Get(); + mCompositorSession = gpu->CreateTopLevelCompositor( mCompositorWidgetProxy, lm, GetDefaultScale(),