Skip to content

Commit

Permalink
Bug 1513308 - Lazily initialize DirectX devices for WebRender. r=matt…
Browse files Browse the repository at this point in the history
…woodrow
  • Loading branch information
bholley committed Dec 12, 2018
1 parent 10fdbf6 commit fd7e0af
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 2 deletions.
2 changes: 2 additions & 0 deletions dom/canvas/CanvasRenderingContext2D.cpp
Expand Up @@ -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);

Expand Down
7 changes: 7 additions & 0 deletions gfx/thebes/gfxPlatform.cpp
Expand Up @@ -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)) {
Expand Down
2 changes: 2 additions & 0 deletions gfx/thebes/gfxPlatform.h
Expand Up @@ -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();
Expand Down
15 changes: 13 additions & 2 deletions gfx/thebes/gfxWindowsPlatform.cpp
Expand Up @@ -424,7 +424,6 @@ void gfxWindowsPlatform::InitAcceleration() {
DeviceManagerDx::Init();

InitializeConfig();
InitializeDevices();
UpdateANGLEConfig();
UpdateRenderMode();

Expand Down Expand Up @@ -497,7 +496,9 @@ bool gfxWindowsPlatform::HandleDeviceReset() {
gfxConfig::Reset(Feature::DIRECT2D);

InitializeConfig();
InitializeDevices();
if (mInitializedDevices) {
InitializeDevices();
}
UpdateANGLEConfig();
return true;
}
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions gfx/thebes/gfxWindowsPlatform.h
Expand Up @@ -105,6 +105,8 @@ class gfxWindowsPlatform : public gfxPlatform {
return (gfxWindowsPlatform*)gfxPlatform::GetPlatform();
}

virtual void EnsureDevicesInitialized() override;

virtual gfxPlatformFontList* CreatePlatformFontList() override;

virtual already_AddRefed<gfxASurface> CreateOffscreenSurface(
Expand Down Expand Up @@ -259,6 +261,7 @@ class gfxWindowsPlatform : public gfxPlatform {
DWRITE_MEASURING_MODE mMeasuringMode;

RefPtr<mozilla::layers::ReadbackManagerD3D11> mD3D11ReadbackManager;
bool mInitializedDevices = false;
};

#endif /* GFX_WINDOWS_PLATFORM_H */

0 comments on commit fd7e0af

Please sign in to comment.