From fd7e0afdbfd7816f5b54421fbc169dca9910883b Mon Sep 17 00:00:00 2001 From: Bobby Holley Date: Tue, 11 Dec 2018 14:38:31 -0800 Subject: [PATCH] Bug 1513308 - Lazily initialize DirectX devices for WebRender. r=mattwoodrow --- dom/canvas/CanvasRenderingContext2D.cpp | 2 ++ gfx/thebes/gfxPlatform.cpp | 7 +++++++ gfx/thebes/gfxPlatform.h | 2 ++ gfx/thebes/gfxWindowsPlatform.cpp | 15 +++++++++++++-- gfx/thebes/gfxWindowsPlatform.h | 3 +++ 5 files changed, 27 insertions(+), 2 deletions(-) diff --git a/dom/canvas/CanvasRenderingContext2D.cpp b/dom/canvas/CanvasRenderingContext2D.cpp index f5b75835765fc..a74c6e4f6f6b6 100644 --- a/dom/canvas/CanvasRenderingContext2D.cpp +++ b/dom/canvas/CanvasRenderingContext2D.cpp @@ -1495,6 +1495,8 @@ CanvasRenderingContext2D::RenderingMode CanvasRenderingContext2D::EnsureTarget( return aRenderingMode; } + gfxPlatform::GetPlatform()->EnsureDevicesInitialized(); + // This would make no sense, so make sure we don't get ourselves in a mess MOZ_ASSERT(mRenderingMode != RenderingMode::DefaultBackendMode); diff --git a/gfx/thebes/gfxPlatform.cpp b/gfx/thebes/gfxPlatform.cpp index 2f9d4e2a79547..e1f62c2f4c229 100644 --- a/gfx/thebes/gfxPlatform.cpp +++ b/gfx/thebes/gfxPlatform.cpp @@ -911,6 +911,13 @@ void gfxPlatform::Init() { #endif gPlatform->InitAcceleration(); gPlatform->InitWebRenderConfig(); + // When using WebRender, we defer initialization of the D3D11 devices until + // the (rare) cases where they're used. Note that the GPU process where WebRender + // runs doesn't initialize gfxPlatform and performs explicit initialization of + // the bits it needs. + if (!gfxVars::UseWebRender()) { + gPlatform->EnsureDevicesInitialized(); + } gPlatform->InitOMTPConfig(); if (gfxConfig::IsEnabled(Feature::GPU_PROCESS)) { diff --git a/gfx/thebes/gfxPlatform.h b/gfx/thebes/gfxPlatform.h index 7e6cfd5a52743..49baa1d6ba063 100644 --- a/gfx/thebes/gfxPlatform.h +++ b/gfx/thebes/gfxPlatform.h @@ -738,6 +738,8 @@ class gfxPlatform : public mozilla::layers::MemoryPressureListener { virtual void OnMemoryPressure( mozilla::layers::MemoryPressureReason aWhy) override; + virtual void EnsureDevicesInitialized() {}; + protected: gfxPlatform(); virtual ~gfxPlatform(); diff --git a/gfx/thebes/gfxWindowsPlatform.cpp b/gfx/thebes/gfxWindowsPlatform.cpp index 22d4c688d14f1..f299bcd979803 100644 --- a/gfx/thebes/gfxWindowsPlatform.cpp +++ b/gfx/thebes/gfxWindowsPlatform.cpp @@ -424,7 +424,6 @@ void gfxWindowsPlatform::InitAcceleration() { DeviceManagerDx::Init(); InitializeConfig(); - InitializeDevices(); UpdateANGLEConfig(); UpdateRenderMode(); @@ -497,7 +496,9 @@ bool gfxWindowsPlatform::HandleDeviceReset() { gfxConfig::Reset(Feature::DIRECT2D); InitializeConfig(); - InitializeDevices(); + if (mInitializedDevices) { + InitializeDevices(); + } UpdateANGLEConfig(); return true; } @@ -1470,6 +1471,16 @@ void gfxWindowsPlatform::InitializeD3D11Config() { uint32_t(aDevice)); } +// Supports lazy device initialization on Windows, so that WebRender can avoid +// initializing GPU state and allocating swap chains for most non-GPU processes. +void gfxWindowsPlatform::EnsureDevicesInitialized() { + if (!mInitializedDevices) { + InitializeDevices(); + UpdateBackendPrefs(); + mInitializedDevices = true; + } +} + void gfxWindowsPlatform::InitializeDevices() { if (XRE_IsParentProcess()) { // If we're the UI process, and the GPU process is enabled, then we don't diff --git a/gfx/thebes/gfxWindowsPlatform.h b/gfx/thebes/gfxWindowsPlatform.h index b3e8d10ae956f..20ee1eb092918 100644 --- a/gfx/thebes/gfxWindowsPlatform.h +++ b/gfx/thebes/gfxWindowsPlatform.h @@ -105,6 +105,8 @@ class gfxWindowsPlatform : public gfxPlatform { return (gfxWindowsPlatform*)gfxPlatform::GetPlatform(); } + virtual void EnsureDevicesInitialized() override; + virtual gfxPlatformFontList* CreatePlatformFontList() override; virtual already_AddRefed CreateOffscreenSurface( @@ -259,6 +261,7 @@ class gfxWindowsPlatform : public gfxPlatform { DWRITE_MEASURING_MODE mMeasuringMode; RefPtr mD3D11ReadbackManager; + bool mInitializedDevices = false; }; #endif /* GFX_WINDOWS_PLATFORM_H */