diff --git a/gfx/ipc/GPUProcessManager.cpp b/gfx/ipc/GPUProcessManager.cpp index a81a6db220ab..bb354e02f34d 100644 --- a/gfx/ipc/GPUProcessManager.cpp +++ b/gfx/ipc/GPUProcessManager.cpp @@ -13,6 +13,7 @@ #include "mozilla/Sprintf.h" #include "mozilla/StaticPtr.h" #include "mozilla/dom/ContentParent.h" +#include "mozilla/gfx/gfxVars.h" #include "mozilla/layers/APZCTreeManager.h" #include "mozilla/layers/APZCTreeManagerChild.h" #include "mozilla/layers/CompositorBridgeParent.h" @@ -419,6 +420,27 @@ GPUProcessManager::SimulateDeviceReset() } } +void +GPUProcessManager::DisableWebRender() +{ + MOZ_ASSERT(gfx::gfxVars::UseWebRender()); + if (!gfx::gfxVars::UseWebRender()) { + return; + } + // Disable WebRender + gfx::gfxConfig::GetFeature(gfx::Feature::WEBRENDER).ForceDisable( + gfx::FeatureStatus::Unavailable, + "WebRender initialization failed", + NS_LITERAL_CSTRING("FEATURE_FAILURE_WEBRENDER_INITIALIZE")); + gfx::gfxVars::SetUseWebRender(false); + + if (mProcess) { + OnRemoteProcessDeviceReset(mProcess); + } else { + OnInProcessDeviceReset(); + } +} + void GPUProcessManager::OnInProcessDeviceReset() { diff --git a/gfx/ipc/GPUProcessManager.h b/gfx/ipc/GPUProcessManager.h index ab6d732a56ed..55589a409a01 100644 --- a/gfx/ipc/GPUProcessManager.h +++ b/gfx/ipc/GPUProcessManager.h @@ -146,6 +146,7 @@ public: void OnProcessLaunchComplete(GPUProcessHost* aHost) override; void OnProcessUnexpectedShutdown(GPUProcessHost* aHost) override; void SimulateDeviceReset(); + void DisableWebRender(); void OnInProcessDeviceReset(); void OnRemoteProcessDeviceReset(GPUProcessHost* aHost) override; void NotifyListenersOnCompositeDeviceReset(); diff --git a/gfx/layers/composite/CompositableHost.cpp b/gfx/layers/composite/CompositableHost.cpp index c1af7cbc8b03..c47a40c502c2 100644 --- a/gfx/layers/composite/CompositableHost.cpp +++ b/gfx/layers/composite/CompositableHost.cpp @@ -118,7 +118,7 @@ CompositableHost::RemoveMaskEffect() } /* static */ already_AddRefed -CompositableHost::Create(const TextureInfo& aTextureInfo) +CompositableHost::Create(const TextureInfo& aTextureInfo, bool aUseWebRender) { RefPtr result; switch (aTextureInfo.mCompositableType) { @@ -129,21 +129,21 @@ CompositableHost::Create(const TextureInfo& aTextureInfo) result = new TiledContentHost(aTextureInfo); break; case CompositableType::IMAGE: - if (gfxVars::UseWebRender()) { + if (aUseWebRender) { result = new WebRenderImageHost(aTextureInfo); } else { result = new ImageHost(aTextureInfo); } break; case CompositableType::CONTENT_SINGLE: - if (gfxVars::UseWebRender()) { + if (aUseWebRender) { result = new WebRenderImageHost(aTextureInfo); } else { result = new ContentHostSingleBuffered(aTextureInfo); } break; case CompositableType::CONTENT_DOUBLE: - MOZ_ASSERT(!gfxVars::UseWebRender()); + MOZ_ASSERT(!aUseWebRender); result = new ContentHostDoubleBuffered(aTextureInfo); break; default: diff --git a/gfx/layers/composite/CompositableHost.h b/gfx/layers/composite/CompositableHost.h index 6e19b96554e1..99f4118c3294 100644 --- a/gfx/layers/composite/CompositableHost.h +++ b/gfx/layers/composite/CompositableHost.h @@ -89,7 +89,7 @@ public: NS_INLINE_DECL_THREADSAFE_REFCOUNTING(CompositableHost) explicit CompositableHost(const TextureInfo& aTextureInfo); - static already_AddRefed Create(const TextureInfo& aTextureInfo); + static already_AddRefed Create(const TextureInfo& aTextureInfo, bool aUseWebRender); virtual CompositableType GetType() = 0; diff --git a/gfx/layers/composite/TextureHost.cpp b/gfx/layers/composite/TextureHost.cpp index 69ae4afe82f8..3cb8be718ceb 100644 --- a/gfx/layers/composite/TextureHost.cpp +++ b/gfx/layers/composite/TextureHost.cpp @@ -98,8 +98,7 @@ WrapWithWebRenderTextureHost(ISurfaceAllocator* aDeallocator, LayersBackend aBackend, TextureFlags aFlags) { - if (!gfx::gfxVars::UseWebRender() || - (aFlags & TextureFlags::SNAPSHOT) || + if ((aFlags & TextureFlags::SNAPSHOT) || (aBackend != LayersBackend::LAYERS_WR) || (!aDeallocator->UsesImageBridge() && !aDeallocator->AsCompositorBridgeParentBase())) { return false; diff --git a/gfx/layers/ipc/CompositableTransactionParent.cpp b/gfx/layers/ipc/CompositableTransactionParent.cpp index 91e374d9c3a0..ffe1e56c332c 100644 --- a/gfx/layers/ipc/CompositableTransactionParent.cpp +++ b/gfx/layers/ipc/CompositableTransactionParent.cpp @@ -241,7 +241,8 @@ CompositableParentManager::DestroyActor(const OpDestroy& aOp) RefPtr CompositableParentManager::AddCompositable(const CompositableHandle& aHandle, - const TextureInfo& aInfo) + const TextureInfo& aInfo, + bool aUseWebRender) { if (mCompositables.find(aHandle.Value()) != mCompositables.end()) { NS_ERROR("Client should not allocate duplicate handles"); @@ -252,7 +253,7 @@ CompositableParentManager::AddCompositable(const CompositableHandle& aHandle, return nullptr; } - RefPtr host = CompositableHost::Create(aInfo); + RefPtr host = CompositableHost::Create(aInfo, aUseWebRender); if (!host) { return nullptr; } diff --git a/gfx/layers/ipc/CompositableTransactionParent.h b/gfx/layers/ipc/CompositableTransactionParent.h index 47da2456562b..cb9e9af5bde9 100644 --- a/gfx/layers/ipc/CompositableTransactionParent.h +++ b/gfx/layers/ipc/CompositableTransactionParent.h @@ -41,7 +41,8 @@ public: RefPtr AddCompositable( const CompositableHandle& aHandle, - const TextureInfo& aInfo); + const TextureInfo& aInfo, + bool aUseWebRender); RefPtr FindCompositable(const CompositableHandle& aHandle); bool AddReadLocks(ReadLockArray&& aReadLocks); diff --git a/gfx/layers/ipc/CompositorBridgeParent.cpp b/gfx/layers/ipc/CompositorBridgeParent.cpp index 31219e45fed4..db3d032c9ee4 100644 --- a/gfx/layers/ipc/CompositorBridgeParent.cpp +++ b/gfx/layers/ipc/CompositorBridgeParent.cpp @@ -537,7 +537,7 @@ CompositorBridgeParent::RecvWaitOnTransactionProcessed() mozilla::ipc::IPCResult CompositorBridgeParent::RecvFlushRendering() { - if (gfxVars::UseWebRender()) { + if (mOptions.UseWebRender()) { mWrBridge->FlushRendering(/* aIsSync */ true); return IPC_OK(); } @@ -552,7 +552,7 @@ CompositorBridgeParent::RecvFlushRendering() mozilla::ipc::IPCResult CompositorBridgeParent::RecvFlushRenderingAsync() { - if (gfxVars::UseWebRender()) { + if (mOptions.UseWebRender()) { mWrBridge->FlushRendering(/* aIsSync */ false); return IPC_OK(); } @@ -706,7 +706,7 @@ CompositorBridgeParent::PauseComposition() if (!mPaused) { mPaused = true; - if (!gfxVars::UseWebRender()) { + if (!mOptions.UseWebRender()) { mCompositor->Pause(); } else { mWrBridge->Pause(); @@ -727,7 +727,7 @@ CompositorBridgeParent::ResumeComposition() MonitorAutoLock lock(mResumeCompositionMonitor); - bool resumed = gfxVars::UseWebRender() ? mWrBridge->Resume() : mCompositor->Resume(); + bool resumed = mOptions.UseWebRender() ? mWrBridge->Resume() : mCompositor->Resume(); if (!resumed) { #ifdef MOZ_WIDGET_ANDROID // We can't get a surface. This could be because the activity changed between diff --git a/gfx/layers/ipc/ImageBridgeChild.cpp b/gfx/layers/ipc/ImageBridgeChild.cpp index e1e9419fa72c..abd953623070 100644 --- a/gfx/layers/ipc/ImageBridgeChild.cpp +++ b/gfx/layers/ipc/ImageBridgeChild.cpp @@ -328,7 +328,7 @@ ImageBridgeChild::Connect(CompositableClient* aCompositable, CompositableHandle handle(id); aCompositable->InitIPDL(handle); - SendNewCompositable(handle, aCompositable->GetTextureInfo()); + SendNewCompositable(handle, aCompositable->GetTextureInfo(), GetCompositorBackendType()); } void diff --git a/gfx/layers/ipc/ImageBridgeParent.cpp b/gfx/layers/ipc/ImageBridgeParent.cpp index 6553075d37ed..1b28dc3252b5 100644 --- a/gfx/layers/ipc/ImageBridgeParent.cpp +++ b/gfx/layers/ipc/ImageBridgeParent.cpp @@ -248,9 +248,12 @@ mozilla::ipc::IPCResult ImageBridgeParent::RecvWillClose() } mozilla::ipc::IPCResult -ImageBridgeParent::RecvNewCompositable(const CompositableHandle& aHandle, const TextureInfo& aInfo) +ImageBridgeParent::RecvNewCompositable(const CompositableHandle& aHandle, + const TextureInfo& aInfo, + const LayersBackend& aLayersBackend) { - RefPtr host = AddCompositable(aHandle, aInfo); + bool useWebRender = aLayersBackend == LayersBackend::LAYERS_WR; + RefPtr host = AddCompositable(aHandle, aInfo, useWebRender); if (!host) { return IPC_FAIL_NO_REASON(this); } diff --git a/gfx/layers/ipc/ImageBridgeParent.h b/gfx/layers/ipc/ImageBridgeParent.h index b41fdb73ab30..0a73908d7751 100644 --- a/gfx/layers/ipc/ImageBridgeParent.h +++ b/gfx/layers/ipc/ImageBridgeParent.h @@ -87,7 +87,8 @@ public: virtual bool DeallocPTextureParent(PTextureParent* actor) override; virtual mozilla::ipc::IPCResult RecvNewCompositable(const CompositableHandle& aHandle, - const TextureInfo& aInfo) override; + const TextureInfo& aInfo, + const LayersBackend& aLayersBackend) override; virtual mozilla::ipc::IPCResult RecvReleaseCompositable(const CompositableHandle& aHandle) override; PMediaSystemResourceManagerParent* AllocPMediaSystemResourceManagerParent() override; diff --git a/gfx/layers/ipc/LayerTransactionParent.cpp b/gfx/layers/ipc/LayerTransactionParent.cpp index 01bdb1b04e22..2b403d927092 100644 --- a/gfx/layers/ipc/LayerTransactionParent.cpp +++ b/gfx/layers/ipc/LayerTransactionParent.cpp @@ -1003,7 +1003,7 @@ LayerTransactionParent::AsLayer(const LayerHandle& aHandle) mozilla::ipc::IPCResult LayerTransactionParent::RecvNewCompositable(const CompositableHandle& aHandle, const TextureInfo& aInfo) { - if (!AddCompositable(aHandle, aInfo)) { + if (!AddCompositable(aHandle, aInfo, /* aUseWebRender */ false)) { return IPC_FAIL_NO_REASON(this); } return IPC_OK(); diff --git a/gfx/layers/ipc/PImageBridge.ipdl b/gfx/layers/ipc/PImageBridge.ipdl index 7529ae2f826b..c3774a79769d 100644 --- a/gfx/layers/ipc/PImageBridge.ipdl +++ b/gfx/layers/ipc/PImageBridge.ipdl @@ -60,7 +60,7 @@ parent: async PTexture(SurfaceDescriptor aSharedData, LayersBackend aBackend, TextureFlags aTextureFlags, uint64_t aSerial, MaybeExternalImageId aExternalImageId); async PMediaSystemResourceManager(); - sync NewCompositable(CompositableHandle aHandle, TextureInfo aInfo); + sync NewCompositable(CompositableHandle aHandle, TextureInfo aInfo, LayersBackend aBackend); async ReleaseCompositable(CompositableHandle aHandle); }; diff --git a/gfx/layers/wr/WebRenderBridgeParent.cpp b/gfx/layers/wr/WebRenderBridgeParent.cpp index d69d51639804..f158d9845d07 100644 --- a/gfx/layers/wr/WebRenderBridgeParent.cpp +++ b/gfx/layers/wr/WebRenderBridgeParent.cpp @@ -809,7 +809,6 @@ WebRenderBridgeParent::RecvAddExternalImageIdForCompositable(const ExternalImage MOZ_ASSERT(!mExternalImageIds.Get(wr::AsUint64(aImageId)).get()); RefPtr host = FindCompositable(aHandle); - MOZ_ASSERT(host->AsWebRenderImageHost()); WebRenderImageHost* wrHost = host->AsWebRenderImageHost(); if (!wrHost) { return IPC_OK(); @@ -1392,7 +1391,7 @@ WebRenderBridgeParent::RecvNewCompositable(const CompositableHandle& aHandle, if (mDestroyed) { return IPC_OK(); } - if (!AddCompositable(aHandle, aInfo)) { + if (!AddCompositable(aHandle, aInfo, /* aUseWebRender */ true)) { return IPC_FAIL_NO_REASON(this); } return IPC_OK(); diff --git a/gfx/layers/wr/WebRenderImageHost.cpp b/gfx/layers/wr/WebRenderImageHost.cpp index 38cbe679f20d..69e102bcbd58 100644 --- a/gfx/layers/wr/WebRenderImageHost.cpp +++ b/gfx/layers/wr/WebRenderImageHost.cpp @@ -207,7 +207,6 @@ void WebRenderImageHost::Attach(Layer* aLayer, TextureSourceProvider* aProvider, AttachFlags aFlags) { - MOZ_ASSERT_UNREACHABLE("unexpected to be called"); } void diff --git a/widget/nsBaseWidget.cpp b/widget/nsBaseWidget.cpp index 6c6aeeb1939f..42d6ba14e6d7 100644 --- a/widget/nsBaseWidget.cpp +++ b/widget/nsBaseWidget.cpp @@ -1294,12 +1294,7 @@ nsBaseWidget::CreateCompositorSession(int aWidth, if (textureFactoryIdentifier.mParentBackend != LayersBackend::LAYERS_WR) { retry = true; DestroyCompositor(); - // Disable WebRender - gfx::gfxConfig::GetFeature(gfx::Feature::WEBRENDER).ForceDisable( - gfx::FeatureStatus::Unavailable, - "WebRender initialization failed", - NS_LITERAL_CSTRING("FEATURE_FAILURE_WEBRENDER_INITIALIZE")); - gfx::gfxVars::SetUseWebRender(false); + gfx::GPUProcessManager::Get()->DisableWebRender(); } }